Example #1
0
 public function log_json($level, $msg, $json)
 {
     if ($level > $this->loglevel) {
         return;
     }
     $this->log($level, $msg, Feediron_Json::format($json));
 }
Example #2
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);
     }
 }