示例#1
0
 public static function get()
 {
     if (self::$logger === FALSE) {
         self::$logger = new Feediron_Logger();
     }
     return self::$logger;
 }
 public function getRecipe($recipeurl)
 {
     $content = fetch_file_contents($recipeurl);
     Feediron_Logger::get()->log(Feediron_Logger::LOG_TTRSS, "Recipe url: {$recipeurl}");
     $filedata = json_decode($content, true);
     Feediron_Logger::get()->log(Feediron_Logger::LOG_TTRSS, "Recipe content: {$content}");
     if (isset($filedata['message'])) {
         return $filedata;
     }
     $data = preg_replace('/\\n/', '', $filedata['content']);
     Feediron_Logger::get()->log(Feediron_Logger::LOG_TTRSS, "Recipe content: {$data}");
     Feediron_Logger::get()->log(Feediron_Logger::LOG_TTRSS, base64_decode($data));
     $data = preg_replace('/\\\\./', '.', base64_decode($data));
     $obj = json_decode($data, true);
     Feediron_Logger::get()->log(Feediron_Logger::LOG_TTRSS, 'last error: ' . json_last_error());
     return $obj;
 }
示例#3
0
 function test()
 {
     Feediron_Logger::get()->set_log_level($_POST['verbose'] ? Feediron_Logger::LOG_VERBOSE : Feediron_Logger::LOG_TEST);
     $test_url = $_POST['test_url'];
     Feediron_Logger::get()->log(Feediron_Logger::LOG_TTRSS, "Test url: {$test_url}");
     if (isset($_POST['test_conf']) && trim($_POST['test_conf']) != '') {
         $json_conf = $_POST['test_conf'];
         $json_reply = array();
         Feediron_Json::format($json_conf);
         header('Content-Type: application/json');
         if (is_null(json_decode($json_conf))) {
             $json_reply['success'] = false;
             $json_reply['errormessage'] = __('Invalid JSON! ') . json_last_error_msg();
             $json_reply['json_error'] = Feediron_Json::get_error();
             echo json_encode($json_reply);
             return false;
         }
         $config = $this->getConfigSection($test_url);
         Feediron_Logger::get()->log_object(Feediron_Logger::LOG_TEST, "config found: ", $config);
         $newconfig = json_decode($_POST['test_conf'], true);
         Feediron_Logger::get()->log_object(Feediron_Logger::LOG_TEST, "config posted: ", $newconfig);
         Feediron_Logger::get()->log_object(Feediron_Logger::LOG_TEST, "config diff", $this->arrayRecursiveDiff($config, $newconfig));
         if (count($this->arrayRecursiveDiff($newconfig, $config)) != 0) {
             Feediron_Logger::get()->log(Feediron_Logger::LOG_TEST, "Save test config");
             $this->host->set($this, 'test_conf', Feediron_Json::format(json_encode($config)));
         }
         $config = json_decode($_POST['test_conf'], true);
     } else {
         $config = $this->getConfigSection($test_url);
     }
     Feediron_Logger::get()->log_object(Feediron_Logger::LOG_TEST, "Using config", $config);
     $test_url = $this->reformatUrl($test_url, $config);
     Feediron_Logger::get()->log(Feediron_Logger::LOG_TTRSS, "Url after reformat: {$test_url}");
     header('Content-Type: application/json');
     $reply = array();
     if ($config === FALSE) {
         $reply['success'] = false;
         $reply['errormessage'] = "URL did not match";
         $reply['log'] = Feediron_Logger::get()->get_testlog();
         echo json_encode($reply);
         return false;
     } else {
         $reply['success'] = true;
         $reply['url'] = $test_url;
         $reply['content'] = $this->getNewContent($test_url, $config);
         $reply['config'] = Feediron_Json::format(json_encode($config));
         if ($reply['config'] == null) {
             $reply['config'] = $_POST['test_conf'];
         }
         $reply['log'] = Feediron_Logger::get()->get_testlog();
         echo json_encode($reply);
     }
 }