function readRss() { global $serendipity; $comment_url = $_REQUEST['coment_url']; $this->log("readRss for {$comment_url}"); $comment_email = $_REQUEST['coment_email']; $this->log("email={$comment_email}"); $entryId = $_REQUEST['entryid']; $this->log("entryid={$entryId}"); $result = array("url" => $comment_url, "email" => $comment_email, "articles" => array()); if (empty($comment_url)) { echo json_encode($result); return; } $allow = $this->checkRules($comment_email, null, false); if (!$allow['allow_announce']) { $this->log("Announce not allowed by email. result: " . print_r($result, TRUE)); echo json_encode($result); return; } // First try to read from cache $result = $this->cacheReadRss($comment_url); if (empty($result)) { $result = $this->readRssRemote($comment_url); $this->log("Fetched array: " . print_r($result, true)); if (!empty($result) && $result['articles']) { $this->cacheWriteRss($comment_url, $result); } } $result['email'] = $comment_email; if (empty($result) || !$result['articles'] || count($result['articles']) == 0) { echo json_encode($result); return; } // If per article each remote article should be announced only once, filter the result if (serendipity_db_bool($this->get_config('announceonce', true))) { // filter $entrySpices = DbSpice::loadCommentSpiceByEntry($entryId); if (is_array($entrySpices)) { $urlHash = array(); foreach ($entrySpices as $entrySpice) { $urlHash[$entrySpice['promo_url']] = "used"; } // Now that we have all urls of this article, remove matching urls from rss. if (count($urlHash) > 0) { $newArticles = array(); foreach ($result['articles'] as $article) { if (empty($urlHash[$article['nohashUrl']])) { $newArticles[] = $article; } } $result['articles'] = $newArticles; } } } // Add Chooser to the array, if something's to choose if (count($result['articles']) > 0) { $article = array(); $article['title'] = PLUGIN_EVENT_COMMENTSPICE_PROMOTE_ARTICLE_CHOOSE; $article['url'] = ""; $result['articles'] = array_merge(array($article), $result['articles']); } echo json_encode($result); }