get_image_url() public method

RSS 0.9.0, 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to have a "feed logo" URL. This points directly to the image itself. Uses , , , </span> or <span class='highlight'><image><dc:title></span> </div> </div> <div class="row doc-tags"> <div class="col-md-12"> <div class="tag-block tag-summary"> </div> <div class="tag-block tag-remarks"> </div> <div class="tag-block tag-exception"> </div> <div class="tag-block tag-see"> </div> <div class="tag-block tag-link"> </div> <div class="tag-block tag-deprecated"> </div> <div class="tag-block tag-since"> </div> <div class="tag-block tag-author"> </div> </div> </div> <div class="row"> <div class="col-md-12" style="overflow: auto"> <table class="table table-striped"> <tr> <td colspan="3" class="rendered"> <span class="modifier">public</span > <span class="method-name"><a class="method-link" href="https://doc.hotexamples.com/zh/class/-/SimplePie#method-get_image_url">get_image_url</a></span> ( ) : <span class="return-type"><a href="http://php.net/manual/en/language.types.string.php">string</a> | <a href="http://php.net/manual/en/language.types.null.php">null</a></span> </td> </tr> <tr> <td class="field-return">return</td> <td class="field-return-type"><a href="http://php.net/manual/en/language.types.string.php">string</a> | <a href="http://php.net/manual/en/language.types.null.php">null</a></td> <td></td> </tr> </table> </div> </div> </div> </div> </div> <div class="row" style="margin-bottom: 15px"> <div class="col-md-12"> <a class="btn btn-default" href="https://doc.hotexamples.com/zh/class/-/SimplePie"> SimplePie Class Documentation </a> </div> </div> </div> <div id="ezoic-pub-ad-placeholder-106"> </div> <div class="example-item" id="0x98b48626b02cd4d293dadee22e0a3d19298c89fb1d77bebd829e560a648f35a8-68,,130,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#1</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_1" data-hash="0x98b48626b02cd4d293dadee22e0a3d19298c89fb1d77bebd829e560a648f35a8" data-area="68,,130,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '1')" class="rating-up btn btn-success" data-id="rating_1"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'1')" class="rating-down btn btn-danger" data-id="rating_1"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x98b48626b02cd4d293dadee22e0a3d19298c89fb1d77bebd829e560a648f35a8-68,,130,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x98b48626b02cd4d293dadee22e0a3d19298c89fb1d77bebd829e560a648f35a8&fullName=src%2FResources%2Fcontao%2FModuleRssReader.php&project=contao%2Fcore-bundle')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fcontao%2Fcore-bundle%2Fblob%2Fmaster%2Fsrc%2FResources%2Fcontao%2FModuleRssReader.php">ModuleRssReader.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fcontao%2Fcore-bundle">contao/core-bundle</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="1"> <pre class="line-numbers language-php" data-end="130" data-start="69" data-highlight="25,89,91"> /** * Generate the module */ protected function compile() { /** @var PageModel $objPage */ global $objPage; if ($this->rss_template != 'rss_default') { $this->strTemplate = $this->rss_template; /** @var FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->strTemplate); $this->Template = $objTemplate; $this->Template->setData($this->arrData); } $this->Template->link = $this->objFeed->get_link(); $this->Template->title = $this->objFeed->get_title(); $this->Template->language = $this->objFeed->get_language(); $this->Template->description = $this->objFeed->get_description(); $this->Template->copyright = $this->objFeed->get_copyright(); // Add image if ($this->objFeed->get_image_url()) { $this->Template->image = true; $this->Template->src = $this->objFeed->get_image_url(); $this->Template->alt = $this->objFeed->get_image_title(); $this->Template->href = $this->objFeed->get_image_link(); $this->Template->height = $this->objFeed->get_image_height(); $this->Template->width = $this->objFeed->get_image_width(); } // Get the items (see #6107) $arrItems = array_slice($this->objFeed->get_items(0, intval($this->numberOfItems) + intval($this->skipFirst)), intval($this->skipFirst), intval($this->numberOfItems) ?: null); $limit = count($arrItems); $offset = 0; // Split pages if ($this->perPage > 0) { // Get the current page $id = 'page_r' . $this->id; $page = \Input::get($id) !== null ? \Input::get($id) : 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil(count($arrItems) / $this->perPage), 1)) { throw new PageNotFoundException('Page not found: ' . \Environment::get('uri')); } // Set limit and offset $offset = ($page - 1) * $this->perPage; $limit = $this->perPage + $offset; $objPagination = new \Pagination(count($arrItems), $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } $items = array(); $last = min($limit, count($arrItems)) - 1; /** @var \SimplePie_Item[] $arrItems */ for ($i = $offset, $c = count($arrItems); $i < $limit && $i < $c; $i++) { $items[$i] = array('link' => $arrItems[$i]->get_link(), 'title' => $arrItems[$i]->get_title(), 'permalink' => $arrItems[$i]->get_permalink(), 'description' => str_replace(array('<?', '?>'), array('&lt;?', '?&gt;'), $arrItems[$i]->get_description()), 'class' => ($i == 0 ? ' first' : '') . ($i == $last ? ' last' : '') . ($i % 2 == 0 ? ' even' : ' odd'), 'pubdate' => \Date::parse($objPage->datimFormat, $arrItems[$i]->get_date('U')), 'category' => $arrItems[$i]->get_category(0), 'object' => $arrItems[$i]); // Add author if (($objAuthor = $arrItems[$i]->get_author(0)) != false) { $items[$i]['author'] = trim($objAuthor->name . ' ' . $objAuthor->email); } // Add enclosure if (($objEnclosure = $arrItems[$i]->get_enclosure(0)) != false) { $items[$i]['enclosure'] = $objEnclosure->get_link(); } } $this->Template->items = array_values($items); }</pre> </div> </figure> </div> <div id="ezoic-pub-ad-placeholder-107"> <div style="text-align: center;margin-bottom: 10px"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- after-example-1 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="4981531786" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="example-item" id="0x92d9931b8470f7a17e3770d9d23783bb03ca7f4f0f54b0e116145bb64a94a05b-22,,66,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#2</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_2" data-hash="0x92d9931b8470f7a17e3770d9d23783bb03ca7f4f0f54b0e116145bb64a94a05b" data-area="22,,66,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '2')" class="rating-up btn btn-success" data-id="rating_2"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'2')" class="rating-down btn btn-danger" data-id="rating_2"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x92d9931b8470f7a17e3770d9d23783bb03ca7f4f0f54b0e116145bb64a94a05b-22,,66,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x92d9931b8470f7a17e3770d9d23783bb03ca7f4f0f54b0e116145bb64a94a05b&fullName=sportnet%2Fapplication%2Fcron_model.php&project=robdmat%2Fsport.net')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Frobdmat%2Fsport.net%2Fblob%2Fmaster%2Fsportnet%2Fapplication%2Fcron_model.php">cron_model.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Frobdmat%2Fsport.net">robdmat/sport.net</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="2"> <pre class="line-numbers language-php" data-end="66" data-start="23" data-highlight="61"> public function setCron() { $getUnique = $this->getAllFeedUrls(); if (!empty($getUnique)) { foreach ($getUnique as $feedTableData) { $feed_user_title = $feedTableData->feed_user_title; $feed_url = $feedTableData->feed_admin_url; $usercat = $feedTableData->feed_user_category; $feed_filter_type = $feedTableData->feed_filter_type; $favicon_icon = $feedTableData->feed_favicon; $feed = new SimplePie(); $feed->set_feed_url($feed_url); $feed->set_cache_location(APPPATH . '/cache'); $feed->set_output_encoding('ISO-8859-1'); $feed->init(); $feed->handle_content_type(); // Language $lang = $feed->get_language(); $language = isset($lang) ? $lang : 'en-us'; if ($feed->get_type() & SIMPLEPIE_TYPE_NONE) { $feed_type = 'Unknown'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_RSS_ALL) { $feed_type = 'RSS'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ATOM_ALL) { $feed_type = 'Atom'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ALL) { $feed_type = 'Supported'; } // Author if ($author = $feed->get_author()) { $feedAuthor = $author->get_name(); } else { $feedAuthor = ''; } if ($feed->error()) { die; } else { $feed_image_link = $feed->get_image_link(); $feed_image_url = $feed->get_image_url(); $feed_image_title = $feed->get_image_title(); $this->addFeeds($feed->get_items(0, 500), $feed_image_link, $feed_image_url, $feed_image_title, $usercat, $feed_url, $language, $feed_type, $feedAuthor, $feed_filter_type, $feed_user_title, $favicon_icon); } } } }</pre> </div> </figure> </div> <div id="ezoic-pub-ad-placeholder-108"> <div style="text-align: center;"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- after-example-2 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="7155150962" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="example-item" id="0x8d29438bab1253ea23feb5be308f7e70a9ec36f76803308e4cda2146f3e44c3f-21,,59,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#3</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_3" data-hash="0x8d29438bab1253ea23feb5be308f7e70a9ec36f76803308e4cda2146f3e44c3f" data-area="21,,59,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '3')" class="rating-up btn btn-success" data-id="rating_3"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'3')" class="rating-down btn btn-danger" data-id="rating_3"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x8d29438bab1253ea23feb5be308f7e70a9ec36f76803308e4cda2146f3e44c3f-21,,59,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x8d29438bab1253ea23feb5be308f7e70a9ec36f76803308e4cda2146f3e44c3f&fullName=controllers%2Fsimplepie.php&project=vad%2Ftaolin')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvad%2Ftaolin%2Fblob%2Fmaster%2Fcontrollers%2Fsimplepie.php">simplepie.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvad%2Ftaolin">vad/taolin</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="3"> <pre class="line-numbers language-php" data-end="59" data-start="22" data-highlight="39"> function feed_paginate($feed_url, $start = 0, $limit = 5) { //make the cache dir if it doesn't exist if (!file_exists($this->cache)) { $folder = new Folder($this->cache, true); } //include the vendor class App::import('Vendor', 'simplepie/simplepie'); //setup SimplePie $feed = new SimplePie(); $feed->set_feed_url($feed_url); $feed->set_cache_location($this->cache); //retrieve the feed $feed->init(); //limits $max = $start + $limit; $items['title'] = $feed->get_title(); $items['image_url'] = $feed->get_image_url(); $items['image_height'] = $feed->get_image_height(); $items['image_width'] = $feed->get_image_width(); //$items['title'] = $feed->get_title(); //get the feed items $items['quantity'] = $feed->get_item_quantity(); if ($items['quantity'] < $start) { $items['items'] = false; return $items; } elseif ($items['quantity'] < $max) { $max = $items['quantity']; } for ($i = $start; $i < $max; $i++) { $items['items'][] = $feed->get_item($i); } //return if ($items) { return $items; } else { return false; } }</pre> </div> </figure> </div> <div id="ezoic-pub-ad-placeholder-109"> <div style="text-align: center;"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- after-example-3 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="8699811701" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="example-item" id="0xdca3105445c848533858660ef29d6b6abae6c175f8a6863e3715e688216a673b-109,,139,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#4</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_4" data-hash="0xdca3105445c848533858660ef29d6b6abae6c175f8a6863e3715e688216a673b" data-area="109,,139,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '4')" class="rating-up btn btn-success" data-id="rating_4"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'4')" class="rating-down btn btn-danger" data-id="rating_4"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0xdca3105445c848533858660ef29d6b6abae6c175f8a6863e3715e688216a673b-109,,139,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0xdca3105445c848533858660ef29d6b6abae6c175f8a6863e3715e688216a673b&fullName=poller.php&project=vishalp%2FMistparkPE-Remix')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvishalp%2FMistparkPE-Remix%2Fblob%2Fmaster%2Fpoller.php">poller.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvishalp%2FMistparkPE-Remix">vishalp/MistparkPE-Remix</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="4"> <pre class="line-numbers language-php" data-end="139" data-start="110" data-highlight="125"> if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if ($elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']) { $name_updated = $elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']; $new_name = $elems['name'][0]['data']; } if ($elems['link'][0]['attribs']['']['rel'] == 'photo' && $elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']) { $photo_timestamp = datetime_convert('UTC', 'UTC', $elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']); $photo_url = $elems['link'][0]['attribs']['']['href']; } } if (!$photo_timestamp) { $photo_rawupdate = $feed->get_feed_tags(NAMESPACE_DFRN, 'icon-updated'); if ($photo_rawupdate) { $photo_timestamp = datetime_convert('UTC', 'UTC', $photo_rawupdate[0]['data']); $photo_url = $feed->get_image_url(); } } if ($photo_timestamp && strlen($photo_url) && $photo_timestamp > $contact['avatar-date']) { require_once "Photo.php"; $photo_failure = false; $r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d LIMIT 1", intval($contact['id'])); if (count($r)) { $resource_id = $r[0]['resource-id']; $img_str = fetch_url($photo_url, true); $img = new Photo($img_str); if ($img) { q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND contact-id` = %d ", dbesc($resource_id), intval($contact['id'])); $img->scaleImageSquare(175); $hash = $resource_id; $r = $img->store($contact['id'], $hash, basename($photo_url), t('Contact Photos'), 4);</pre> </div> </figure> </div> <div id="ezoic-pub-ad-placeholder-110"> </div> <div class="example-item" id="0xd9d3e52a6fde5590374f7eaaca751d133d3e21bdf66f804fe881a2e46b3088eb-42,,103,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#5</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_5" data-hash="0xd9d3e52a6fde5590374f7eaaca751d133d3e21bdf66f804fe881a2e46b3088eb" data-area="42,,103,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '5')" class="rating-up btn btn-success" data-id="rating_5"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'5')" class="rating-down btn btn-danger" data-id="rating_5"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0xd9d3e52a6fde5590374f7eaaca751d133d3e21bdf66f804fe881a2e46b3088eb-42,,103,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0xd9d3e52a6fde5590374f7eaaca751d133d3e21bdf66f804fe881a2e46b3088eb&fullName=sportnet%2Fapplication%2Ffeeds.php&project=robdmat%2Fsport.net')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Frobdmat%2Fsport.net%2Fblob%2Fmaster%2Fsportnet%2Fapplication%2Ffeeds.php">feeds.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Frobdmat%2Fsport.net">robdmat/sport.net</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="5"> <pre class="line-numbers language-php" data-end="103" data-start="43" data-highlight="94"> /** */ public function add() { $feed_user_title = $this->input->post('feed_title', TRUE); $feed_url = $this->input->post('feed_url'); $usercat = $this->input->post('category'); $feed_filter_type = $this->input->post('feed_type'); $_icon = $this->input->post('favicon_icon'); $favicon_icon = $_icon; if (!isset($feed_url) || $feed_url == '') { $this->stencil->title('Feeds'); $this->stencil->layout('admin_layout'); $this->stencil->css(array('admin_css/bootstrap.min', 'admin_css/bootstrap-responsive.min', 'admin_css/styles')); $this->stencil->js(array('vendors/datatables/js/jquery.dataTables.min.js', 'DT_bootstrap')); $this->stencil->paint('admin/feeds/add'); } else { $check = $this->validateUrl($feed_url); if ($check == FALSE) { echo json_encode(array('result' => 'fail', 'msg' => '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>Url Already exists in the database!</div>')); die; } $feed = new SimplePie(); $feed->set_feed_url($feed_url); $feed->set_cache_location(APPPATH . '/cache'); $feed->set_output_encoding('ISO-8859-1'); $feed->init(); $feed->handle_content_type(); // Language $lang = $feed->get_language(); $language = isset($lang) ? $lang : 'en-us'; if ($feed->get_type() & SIMPLEPIE_TYPE_NONE) { $feed_type = 'Unknown'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_RSS_ALL) { $feed_type = 'RSS'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ATOM_ALL) { $feed_type = 'Atom'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ALL) { $feed_type = 'Supported'; } // Author if ($author = $feed->get_author()) { $feedAuthor = $author->get_name(); } else { $feedAuthor = ''; } if ($feed->error()) { echo json_encode(array('result' => 'fail', 'msg' => '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>Found error while making request</div>')); } else { // $return = $this->feed_model->addFeeds($feed->get_items(0, 500)); $feed_image_link = $feed->get_image_link(); $feed_image_url = $feed->get_image_url(); $feed_image_title = $feed->get_image_title(); $return = $this->feedModel->addFeeds($feed->get_items(0, 500), $feed_image_link, $feed_image_url, $feed_image_title, $usercat, $feed_url, $language, $feed_type, $feedAuthor, $feed_filter_type, $feed_user_title, $favicon_icon); if ($return) { echo json_encode(array('result' => 'success', 'msg' => '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button>Blog is added successfully</div>')); } else { echo json_encode(array('result' => 'fail', 'msg' => '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>Found error while making request</div>')); } } } }</pre> </div> </figure> </div> <div id="ezoic-pub-ad-placeholder-111"> </div> <div class="example-item" id="0xcdb0978f3f953c34dd9d05fcddf3dd99b638d64d664b445eaba0f030f17a0360-122,,283,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#6</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_6" data-hash="0xcdb0978f3f953c34dd9d05fcddf3dd99b638d64d664b445eaba0f030f17a0360" data-area="122,,283,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '6')" class="rating-up btn btn-success" data-id="rating_6"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'6')" class="rating-down btn btn-danger" data-id="rating_6"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0xcdb0978f3f953c34dd9d05fcddf3dd99b638d64d664b445eaba0f030f17a0360-122,,283,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0xcdb0978f3f953c34dd9d05fcddf3dd99b638d64d664b445eaba0f030f17a0360&fullName=application%2Frefresh.php&project=esironal%2Freaderself')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fesironal%2Freaderself%2Fblob%2Fmaster%2Fapplication%2Frefresh.php">refresh.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fesironal%2Freaderself">esironal/readerself</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="6"> <pre class="line-numbers language-php" data-end="283" data-start="123" data-highlight="237,238"> public function items() { if ($this->input->is_ajax_request()) { $this->readerself_library->set_template('_json'); $this->readerself_library->set_content_type('application/json'); $content = array(); } else { $this->readerself_library->set_template('_plain'); $this->readerself_library->set_content_type('text/plain'); $content = ''; } if ($this->input->is_cli_request() && !$this->config->item('refresh_by_cron')) { $content .= 'Refresh by cron disabled' . "\n"; } else { include_once 'thirdparty/simplepie/autoloader.php'; include_once 'thirdparty/simplepie/idn/idna_convert.class.php'; if ($this->config->item('facebook/enabled')) { include_once 'thirdparty/facebook/autoload.php'; $fb = new Facebook\Facebook(array('app_id' => $this->config->item('facebook/id'), 'app_secret' => $this->config->item('facebook/secret'))); $fbApp = $fb->getApp(); $accessToken = $fbApp->getAccessToken(); } $query = $this->db->query('SELECT fed.* FROM ' . $this->db->dbprefix('feeds') . ' AS fed WHERE fed.fed_nextcrawl IS NULL OR fed.fed_nextcrawl <= ? GROUP BY fed.fed_id HAVING (SELECT COUNT(DISTINCT(sub.mbr_id)) FROM ' . $this->db->dbprefix('subscriptions') . ' AS sub WHERE sub.fed_id = fed.fed_id) > 0', array(date('Y-m-d H:i:s'))); if ($query->num_rows() > 0) { $microtime_start = microtime(1); $errors = 0; foreach ($query->result() as $fed) { $parse_url = parse_url($fed->fed_link); if (isset($parse_url['host']) == 1 && $parse_url['host'] == 'www.facebook.com' && $this->config->item('facebook/enabled')) { try { $parts = explode('/', $parse_url['path']); $total_parts = count($parts); $last_part = $parts[$total_parts - 1]; $request = new Facebook\FacebookRequest($fbApp, $accessToken, 'GET', $last_part . '?fields=link,name,about'); $response = $fb->getClient()->sendRequest($request); $result = $response->getDecodedBody(); $request = new Facebook\FacebookRequest($fbApp, $accessToken, 'GET', $last_part . '?fields=feed{created_time,id,message,story,full_picture,place,type,status_type,link}'); $response = $fb->getClient()->sendRequest($request); $posts = $response->getDecodedBody(); $this->readerself_library->crawl_items_facebook($fed->fed_id, $posts['feed']['data']); $lastitem = $this->db->query('SELECT itm.itm_datecreated FROM ' . $this->db->dbprefix('items') . ' AS itm WHERE itm.fed_id = ? GROUP BY itm.itm_id ORDER BY itm.itm_id DESC LIMIT 0,1', array($fed->fed_id))->row(); $this->db->set('fed_title', $result['name']); $this->db->set('fed_url', $result['link']); $this->db->set('fed_link', $result['link']); if (isset($parse_url['host']) == 1) { $this->db->set('fed_host', $parse_url['host']); } $this->db->set('fed_description', $result['about']); $this->db->set('fed_lasterror', ''); $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); if ($lastitem) { $nextcrawl = ''; //older than 96 hours, next crawl in 12 hours if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 24 * 96)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 12); //older than 48 hours, next crawl in 6 hours } else { if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 48)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 6); //older than 24 hours, next crawl in 3 hours } else { if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 24)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 3); } } } $this->db->set('fed_nextcrawl', $nextcrawl); } $this->db->where('fed_id', $fed->fed_id); $this->db->update('feeds'); } catch (Facebook\Exceptions\FacebookResponseException $e) { $errors++; $this->db->set('fed_lasterror', 'Graph returned an error: ' . $e->getMessage()); $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); $this->db->where('fed_id', $fed->fed_id); $this->db->update('feeds'); } catch (Facebook\Exceptions\FacebookSDKException $e) { $errors++; $this->db->set('fed_lasterror', 'Facebook SDK returned an error: ' . $e->getMessage()); $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); $this->db->where('fed_id', $fed->fed_id); $this->db->update('feeds'); } } else { $sp_feed = new SimplePie(); $sp_feed->set_feed_url(convert_to_ascii($fed->fed_link)); $sp_feed->enable_cache(false); $sp_feed->set_timeout(5); $sp_feed->force_feed(true); $sp_feed->init(); $sp_feed->handle_content_type(); if ($sp_feed->error()) { $errors++; $this->db->set('fed_lasterror', $sp_feed->error()); $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); $this->db->where('fed_id', $fed->fed_id); $this->db->update('feeds'); } else { $this->readerself_library->crawl_items($fed->fed_id, $sp_feed->get_items()); $lastitem = $this->db->query('SELECT itm.itm_datecreated FROM ' . $this->db->dbprefix('items') . ' AS itm WHERE itm.fed_id = ? GROUP BY itm.itm_id ORDER BY itm.itm_id DESC LIMIT 0,1', array($fed->fed_id))->row(); $parse_url = parse_url($sp_feed->get_link()); $this->db->set('fed_title', $sp_feed->get_title()); $this->db->set('fed_url', $sp_feed->get_link()); $this->db->set('fed_link', $sp_feed->subscribe_url()); if (isset($parse_url['host']) == 1) { $this->db->set('fed_host', $parse_url['host']); } if ($sp_feed->get_type() & SIMPLEPIE_TYPE_RSS_ALL) { $this->db->set('fed_type', 'rss'); } else { if ($sp_feed->get_type() & SIMPLEPIE_TYPE_ATOM_ALL) { $this->db->set('fed_type', 'atom'); } } if ($sp_feed->get_image_url()) { $this->db->set('fed_image', $sp_feed->get_image_url()); } $this->db->set('fed_description', $sp_feed->get_description()); $this->db->set('fed_lasterror', ''); $this->db->set('fed_lastcrawl', date('Y-m-d H:i:s')); if ($lastitem) { $nextcrawl = ''; //older than 96 hours, next crawl in 12 hours if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 24 * 96)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 12); //older than 48 hours, next crawl in 6 hours } else { if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 48)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 6); //older than 24 hours, next crawl in 3 hours } else { if ($lastitem->itm_datecreated < date('Y-m-d H:i:s', time() - 3600 * 24)) { $nextcrawl = date('Y-m-d H:i:s', time() + 3600 * 3); } } } $this->db->set('fed_nextcrawl', $nextcrawl); } $this->db->where('fed_id', $fed->fed_id); $this->db->update('feeds'); } $sp_feed->__destruct(); unset($sp_feed); } } $this->db->set('crr_time', microtime(1) - $microtime_start); if (function_exists('memory_get_peak_usage')) { $this->db->set('crr_memory', memory_get_peak_usage()); } $this->db->set('crr_feeds', $query->num_rows()); if ($errors > 0) { $this->db->set('crr_errors', $errors); } $this->db->set('crr_datecreated', date('Y-m-d H:i:s')); $this->db->insert('crawler'); if ($this->db->dbdriver == 'mysqli') { $this->db->query('OPTIMIZE TABLE categories, connections, enclosures, favorites, feeds, folders, history, items, members, share, subscriptions'); } } } $this->readerself_library->set_content($content); }</pre> </div> </figure> </div> <div class="example-item" id="0xc90165cf5da3db2cdeb156eb08ffdee2d0b5b9aa5029894b88caadfa90131142-340,,416,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#7</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_7" data-hash="0xc90165cf5da3db2cdeb156eb08ffdee2d0b5b9aa5029894b88caadfa90131142" data-area="340,,416,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '7')" class="rating-up btn btn-success" data-id="rating_7"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'7')" class="rating-down btn btn-danger" data-id="rating_7"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0xc90165cf5da3db2cdeb156eb08ffdee2d0b5b9aa5029894b88caadfa90131142-340,,416,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0xc90165cf5da3db2cdeb156eb08ffdee2d0b5b9aa5029894b88caadfa90131142&fullName=king-rss.php&project=schorsch%2Fwordpress-king')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fschorsch%2Fwordpress-king%2Fblob%2Fmaster%2Fking-rss.php">king-rss.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fschorsch%2Fwordpress-king">schorsch/wordpress-king</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="7"> <pre class="line-numbers language-php" data-end="416" data-start="341" data-highlight="368">function kingRssOutput($data) { $feed = new SimplePie(); $feed->feed_url($data['rss_url']); $path = explode($_SERVER["SERVER_NAME"], get_bloginfo('wpurl')); $feed->cache_location($_SERVER['DOCUMENT_ROOT'] . $path[1] . "/wp-content/cache"); if (!empty($data['cache_time'])) { $feed->max_minutes = $data['cache_time']; } if (!empty($data['nosort'])) { $feed->order_by_date = false; } if (!empty($data['stripads'])) { $feed->strip_ads(1); } $feed->bypass_image_hotlink(); $feed->bypass_image_hotlink_page($path[1] . "/index.php"); #if images in feed are protected $success = $feed->init(); if ($success && $feed->data) { $output = ''; $replace_title_vars[0] = $feed->get_feed_link(); $replace_title_vars[1] = $feed->get_feed_title(); $replace_title_vars[2] = $feed->get_feed_description(); $replace_title_vars[3] = $data['rss_url']; $replace_title_vars[4] = get_settings('siteurl') . '/wp-content/plugins/king-framework/images/rss.png'; if ($feed->get_image_exist() == true) { $replace_title_vars[5] = $feed->get_image_url(); } $search_title_vars = array('%link%', '%title%', '%descr%', '%rssurl%', '%rssicon%', '%feedimg%'); #parse template placeholders $output .= str_replace($search_title_vars, $replace_title_vars, $data['titlehtml']); $max = $feed->get_item_quantity(); if (!empty($data['max_items'])) { $max = min($data['max_items'], $feed->get_item_quantity()); } for ($x = 0; $x < $max; $x++) { $item = $feed->get_item($x); $replace_vars[0] = stupifyEntities($item->get_title()); $replace_vars[1] = $item->get_permalink(); $replace_vars[2] = $item->get_date($data['showdate']); $replace_vars[3] = stupifyEntities($item->get_description()); if ($item->get_categories() != false) { $categories = $item->get_categories(); $replace_vars[4] = implode(" | ", $categories); } if ($item->get_author(0) != false) { $author = $item->get_author(0); $replace_vars[5] = $author->get_name(); } # cut article text to length ... do the butcher if (!empty($data['shortdesc'])) { $suffix = '...'; $short_desc = trim(str_replace("\n", ' ', str_replace("\r", ' ', strip_tags(stupifyEntities($item->get_description()))))); $desc = substr($short_desc, 0, $data['shortdesc']); $lastchar = substr($desc, -1, 1); if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') { $suffix = ''; } $desc .= $suffix; $replace_vars[3] = $desc; } $search_vars = array('%title%', '%link%', '%date%', '%text%', '%category%', '%author%'); #parse template placeholders $output .= str_replace($search_vars, $replace_vars, $data['rsshtml']); } } else { if (!empty($data['error'])) { $output = $data['error']; } else { if (isset($feed->error)) { $output = $feed->error; } } } return $output; }</pre> </div> </figure> </div> <div class="example-item" id="0xb38109967bef0519245cac73dee8f2c320a2d99710efd30767dcc720ce957f35-125,,917,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#8</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_8" data-hash="0xb38109967bef0519245cac73dee8f2c320a2d99710efd30767dcc720ce957f35" data-area="125,,917,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '8')" class="rating-up btn btn-success" data-id="rating_8"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'8')" class="rating-down btn btn-danger" data-id="rating_8"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0xb38109967bef0519245cac73dee8f2c320a2d99710efd30767dcc720ce957f35-125,,917,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0xb38109967bef0519245cac73dee8f2c320a2d99710efd30767dcc720ce957f35&fullName=rssfuncs.php&project=nvdnkpr%2FTiny-Tiny-RSS')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fnvdnkpr%2FTiny-Tiny-RSS%2Fblob%2Fmaster%2Frssfuncs.php">rssfuncs.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fnvdnkpr%2FTiny-Tiny-RSS">nvdnkpr/Tiny-Tiny-RSS</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="8"> <pre class="line-numbers language-php" data-end="917" data-start="126" data-highlight="294">function update_rss_feed($link, $feed, $ignore_daemon = false, $no_cache = false, $override_url = false) { require_once "lib/simplepie/simplepie.inc"; require_once "lib/magpierss/rss_fetch.inc"; require_once 'lib/magpierss/rss_utils.inc'; $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']; if (!$_REQUEST["daemon"] && !$ignore_daemon) { return false; } if ($debug_enabled) { _debug("update_rss_feed: start"); } if (!$ignore_daemon) { if (DB_TYPE == "pgsql") { $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')"; } else { $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))"; } $result = db_query($link, "SELECT id,update_interval,auth_login,\n\t\t\t\tauth_pass,cache_images,update_method,last_updated\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}' AND {$updstart_thresh_qpart}"); } else { $result = db_query($link, "SELECT id,update_interval,auth_login,\n\t\t\t\tfeed_url,auth_pass,cache_images,update_method,last_updated,\n\t\t\t\tmark_unread_on_update, owner_uid, update_on_checksum_change,\n\t\t\t\tpubsub_state\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'"); } if (db_num_rows($result) == 0) { if ($debug_enabled) { _debug("update_rss_feed: feed {$feed} NOT FOUND/SKIPPED"); } return false; } $update_method = db_fetch_result($result, 0, "update_method"); $last_updated = db_fetch_result($result, 0, "last_updated"); $owner_uid = db_fetch_result($result, 0, "owner_uid"); $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update")); $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result, 0, "update_on_checksum_change")); $pubsub_state = db_fetch_result($result, 0, "pubsub_state"); db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW()\n\t\t\tWHERE id = '{$feed}'"); $auth_login = db_fetch_result($result, 0, "auth_login"); $auth_pass = db_fetch_result($result, 0, "auth_pass"); if ($update_method == 0) { $update_method = DEFAULT_UPDATE_METHOD + 1; } // 1 - Magpie // 2 - SimplePie // 3 - Twitter OAuth if ($update_method == 2) { $use_simplepie = true; } else { $use_simplepie = false; } if ($debug_enabled) { _debug("update method: {$update_method} (feed setting: {$update_method}) (use simplepie: {$use_simplepie})\n"); } if ($update_method == 1) { $auth_login = urlencode($auth_login); $auth_pass = urlencode($auth_pass); } $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); $fetch_url = db_fetch_result($result, 0, "feed_url"); $feed = db_escape_string($feed); if ($auth_login && $auth_pass) { $url_parts = array(); preg_match("/(^[^:]*):\\/\\/(.*)/", $fetch_url, $url_parts); if ($url_parts[1] && $url_parts[2]) { $fetch_url = $url_parts[1] . "://{$auth_login}:{$auth_pass}@" . $url_parts[2]; } } if ($override_url) { $fetch_url = $override_url; } if ($debug_enabled) { _debug("update_rss_feed: fetching [{$fetch_url}]..."); } // Ignore cache if new feed or manual update. $cache_age = is_null($last_updated) || $last_updated == '1970-01-01 00:00:00' ? -1 : get_feed_update_interval($link, $feed) * 60; if ($update_method == 3) { $rss = fetch_twitter_rss($link, $fetch_url, $owner_uid); } else { if ($update_method == 1) { define('MAGPIE_CACHE_AGE', $cache_age); define('MAGPIE_CACHE_ON', !$no_cache); define('MAGPIE_FETCH_TIME_OUT', 60); define('MAGPIE_CACHE_DIR', CACHE_DIR . "/magpie"); $rss = @fetch_rss($fetch_url); } else { $simplepie_cache_dir = CACHE_DIR . "/simplepie"; if (!is_dir($simplepie_cache_dir)) { mkdir($simplepie_cache_dir); } $rss = new SimplePie(); $rss->set_useragent(SELF_USER_AGENT); # $rss->set_timeout(10); $rss->set_feed_url($fetch_url); $rss->set_output_encoding('UTF-8'); //$rss->force_feed(true); if ($debug_enabled) { _debug("feed update interval (sec): " . get_feed_update_interval($link, $feed) * 60); } $rss->enable_cache(!$no_cache); if (!$no_cache) { $rss->set_cache_location($simplepie_cache_dir); $rss->set_cache_duration($cache_age); } $rss->init(); } } // print_r($rss); if ($debug_enabled) { _debug("update_rss_feed: fetch done, parsing..."); } $feed = db_escape_string($feed); if ($update_method == 2) { $fetch_ok = !$rss->error(); } else { $fetch_ok = !!$rss; } if ($fetch_ok) { if ($debug_enabled) { _debug("update_rss_feed: processing feed data..."); } // db_query($link, "BEGIN"); if (DB_TYPE == "pgsql") { $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'"; } else { $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)"; } $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid,\n\t\t\t\t(favicon_last_checked IS NULL OR {$favicon_interval_qpart}) AS\n\t\t\t\t\t\tfavicon_needs_check\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'"); $registered_title = db_fetch_result($result, 0, "title"); $orig_icon_url = db_fetch_result($result, 0, "icon_url"); $orig_site_url = db_fetch_result($result, 0, "site_url"); $favicon_needs_check = sql_bool_to_bool(db_fetch_result($result, 0, "favicon_needs_check")); $owner_uid = db_fetch_result($result, 0, "owner_uid"); if ($use_simplepie) { $site_url = db_escape_string(trim($rss->get_link())); } else { $site_url = db_escape_string(trim($rss->channel["link"])); } // weird, weird Magpie if (!$use_simplepie) { if (!$site_url) { $site_url = db_escape_string($rss->channel["link_"]); } } $site_url = rewrite_relative_url($fetch_url, $site_url); $site_url = substr($site_url, 0, 250); if ($debug_enabled) { _debug("update_rss_feed: checking favicon..."); } if ($favicon_needs_check) { check_feed_favicon($site_url, $feed, $link); db_query($link, "UPDATE ttrss_feeds SET favicon_last_checked = NOW()\n\t\t\t\t\tWHERE id = '{$feed}'"); } if (!$registered_title || $registered_title == "[Unknown]") { if ($use_simplepie) { $feed_title = db_escape_string($rss->get_title()); } else { $feed_title = db_escape_string($rss->channel["title"]); } if ($debug_enabled) { _debug("update_rss_feed: registering title: {$feed_title}"); } db_query($link, "UPDATE ttrss_feeds SET\n\t\t\t\t\ttitle = '{$feed_title}' WHERE id = '{$feed}'"); } if ($site_url && $orig_site_url != $site_url) { db_query($link, "UPDATE ttrss_feeds SET\n\t\t\t\t\tsite_url = '{$site_url}' WHERE id = '{$feed}'"); } // print "I: " . $rss->channel["image"]["url"]; if (!$use_simplepie) { $icon_url = db_escape_string(trim($rss->image["url"])); } else { $icon_url = db_escape_string(trim($rss->get_image_url())); } $icon_url = rewrite_relative_url($fetch_url, $icon_url); $icon_url = substr($icon_url, 0, 250); if ($icon_url && $orig_icon_url != $icon_url) { db_query($link, "UPDATE ttrss_feeds SET icon_url = '{$icon_url}' WHERE id = '{$feed}'"); } if ($debug_enabled) { _debug("update_rss_feed: loading filters..."); } $filters = load_filters($link, $feed, $owner_uid); // if ($debug_enabled) { // print_r($filters); // } if ($use_simplepie) { $iterator = $rss->get_items(); } else { $iterator = $rss->items; if (!$iterator || !is_array($iterator)) { $iterator = $rss->entries; } if (!$iterator || !is_array($iterator)) { $iterator = $rss; } } if (!is_array($iterator)) { /* db_query($link, "UPDATE ttrss_feeds SET last_error = 'Parse error: can\'t find any articles.' WHERE id = '$feed'"); */ // clear any errors and mark feed as updated if fetched okay // even if it's blank if ($debug_enabled) { _debug("update_rss_feed: entry iterator is not an array, no articles?"); } db_query($link, "UPDATE ttrss_feeds\n\t\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'"); return; // no articles } if ($pubsub_state != 2 && PUBSUBHUBBUB_ENABLED) { if ($debug_enabled) { _debug("update_rss_feed: checking for PUSH hub..."); } $feed_hub_url = false; if ($use_simplepie) { $links = $rss->get_links('hub'); if ($links && is_array($links)) { foreach ($links as $l) { $feed_hub_url = $l; break; } } } else { $atom = $rss->channel['atom']; if ($atom) { if ($atom['link@rel'] == 'hub') { $feed_hub_url = $atom['link@href']; } if (!$feed_hub_url && $atom['link#'] > 1) { for ($i = 2; $i <= $atom['link#']; $i++) { if ($atom["link#{$i}@rel"] == 'hub') { $feed_hub_url = $atom["link#{$i}@href"]; break; } } } } else { $feed_hub_url = $rss->channel['link_hub']; } } if ($debug_enabled) { _debug("update_rss_feed: feed hub url: {$feed_hub_url}"); } if ($feed_hub_url && function_exists('curl_init') && !ini_get("open_basedir")) { require_once 'lib/pubsubhubbub/subscriber.php'; $callback_url = get_self_url_prefix() . "/public.php?op=pubsub&id={$feed}"; $s = new Subscriber($feed_hub_url, $callback_url); $rc = $s->subscribe($fetch_url); if ($debug_enabled) { _debug("update_rss_feed: feed hub url found, subscribe request sent."); } db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 1\n\t\t\t\t\t\tWHERE id = '{$feed}'"); } } if ($debug_enabled) { _debug("update_rss_feed: processing articles..."); } foreach ($iterator as $item) { if ($_REQUEST['xdebug'] == 2) { print_r($item); } if ($use_simplepie) { $entry_guid = $item->get_id(); if (!$entry_guid) { $entry_guid = $item->get_link(); } if (!$entry_guid) { $entry_guid = make_guid_from_title($item->get_title()); } } else { $entry_guid = $item["id"]; if (!$entry_guid) { $entry_guid = $item["guid"]; } if (!$entry_guid) { $entry_guid = $item["about"]; } if (!$entry_guid) { $entry_guid = $item["link"]; } if (!$entry_guid) { $entry_guid = make_guid_from_title($item["title"]); } } if ($debug_enabled) { _debug("update_rss_feed: guid {$entry_guid}"); } if (!$entry_guid) { continue; } $entry_timestamp = ""; if ($use_simplepie) { $entry_timestamp = strtotime($item->get_date()); } else { $rss_2_date = $item['pubdate']; $rss_1_date = $item['dc']['date']; $atom_date = $item['issued']; if (!$atom_date) { $atom_date = $item['updated']; } if ($atom_date != "") { $entry_timestamp = parse_w3cdtf($atom_date); } if ($rss_1_date != "") { $entry_timestamp = parse_w3cdtf($rss_1_date); } if ($rss_2_date != "") { $entry_timestamp = strtotime($rss_2_date); } } if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) { $entry_timestamp = time(); $no_orig_date = 'true'; } else { $no_orig_date = 'false'; } $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); if ($debug_enabled) { _debug("update_rss_feed: date {$entry_timestamp} [{$entry_timestamp_fmt}]"); } if ($use_simplepie) { $entry_title = $item->get_title(); } else { $entry_title = trim(strip_tags($item["title"])); } if ($use_simplepie) { $entry_link = $item->get_link(); } else { // strange Magpie workaround $entry_link = $item["link_"]; if (!$entry_link) { $entry_link = $item["link"]; } } $entry_link = rewrite_relative_url($site_url, $entry_link); if ($debug_enabled) { _debug("update_rss_feed: title {$entry_title}"); _debug("update_rss_feed: link {$entry_link}"); } if (!$entry_title) { $entry_title = date("Y-m-d H:i:s", $entry_timestamp); } $entry_link = strip_tags($entry_link); if ($use_simplepie) { $entry_content = $item->get_content(); if (!$entry_content) { $entry_content = $item->get_description(); } } else { $entry_content = $item["content:escaped"]; if (!$entry_content) { $entry_content = $item["content:encoded"]; } if (!$entry_content && is_array($entry_content)) { $entry_content = $item["content"]["encoded"]; } if (!$entry_content) { $entry_content = $item["content"]; } if (is_array($entry_content)) { $entry_content = $entry_content[0]; } // Magpie bugs are getting ridiculous if (trim($entry_content) == "Array") { $entry_content = false; } if (!$entry_content) { $entry_content = $item["atom_content"]; } if (!$entry_content) { $entry_content = $item["summary"]; } if (!$entry_content || strlen($entry_content) < strlen($item["description"])) { $entry_content = $item["description"]; } // WTF if (is_array($entry_content)) { $entry_content = $entry_content["encoded"]; if (!$entry_content) { $entry_content = $entry_content["escaped"]; } } } if ($cache_images && is_writable(CACHE_DIR . '/images')) { $entry_content = cache_images($entry_content, $site_url, $debug_enabled); } if ($_REQUEST["xdebug"] == 2) { print "update_rss_feed: content: "; print $entry_content; print "\n"; } $entry_content_unescaped = $entry_content; if ($use_simplepie) { $entry_comments = strip_tags($item->data["comments"]); if ($item->get_author()) { $entry_author_item = $item->get_author(); $entry_author = $entry_author_item->get_name(); if (!$entry_author) { $entry_author = $entry_author_item->get_email(); } $entry_author = db_escape_string($entry_author); } } else { $entry_comments = strip_tags($item["comments"]); $entry_author = db_escape_string(strip_tags($item['dc']['creator'])); if ($item['author']) { if (is_array($item['author'])) { if (!$entry_author) { $entry_author = db_escape_string(strip_tags($item['author']['name'])); } if (!$entry_author) { $entry_author = db_escape_string(strip_tags($item['author']['email'])); } } if (!$entry_author) { $entry_author = db_escape_string(strip_tags($item['author'])); } } } if (preg_match('/^[\\t\\n\\r ]*$/', $entry_author)) { $entry_author = ''; } $entry_guid = db_escape_string(strip_tags($entry_guid)); $entry_guid = mb_substr($entry_guid, 0, 250); $result = db_query($link, "SELECT id FROM\tttrss_entries\n\t\t\t\t\tWHERE guid = '{$entry_guid}'"); $entry_content = db_escape_string($entry_content, false); $content_hash = "SHA1:" . sha1(strip_tags($entry_content)); $entry_title = db_escape_string($entry_title); $entry_link = db_escape_string($entry_link); $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250); $entry_author = mb_substr($entry_author, 0, 250); if ($use_simplepie) { $num_comments = 0; #FIXME# } else { $num_comments = db_escape_string($item["slash"]["comments"]); } if (!$num_comments) { $num_comments = 0; } if ($debug_enabled) { _debug("update_rss_feed: looking for tags [1]..."); } // parse <category> entries into tags $additional_tags = array(); if ($use_simplepie) { $additional_tags_src = $item->get_categories(); if (is_array($additional_tags_src)) { foreach ($additional_tags_src as $tobj) { array_push($additional_tags, $tobj->get_term()); } } if ($debug_enabled) { _debug("update_rss_feed: category tags:"); print_r($additional_tags); } } else { $t_ctr = $item['category#']; if ($t_ctr == 0) { $additional_tags = array(); } else { if ($t_ctr > 0) { $additional_tags = array($item['category']); if ($item['category@term']) { array_push($additional_tags, $item['category@term']); } for ($i = 0; $i <= $t_ctr; $i++) { if ($item["category#{$i}"]) { array_push($additional_tags, $item["category#{$i}"]); } if ($item["category#{$i}@term"]) { array_push($additional_tags, $item["category#{$i}@term"]); } } } } // parse <dc:subject> elements $t_ctr = $item['dc']['subject#']; if ($t_ctr > 0) { array_push($additional_tags, $item['dc']['subject']); for ($i = 0; $i <= $t_ctr; $i++) { if ($item['dc']["subject#{$i}"]) { array_push($additional_tags, $item['dc']["subject#{$i}"]); } } } } if ($debug_enabled) { _debug("update_rss_feed: looking for tags [2]..."); } /* taaaags */ // <a href="..." rel="tag">Xorg</a>, // $entry_tags = null; preg_match_all("/<a.*?rel=['\"]tag['\"].*?\\>([^<]+)<\\/a>/i", $entry_content_unescaped, $entry_tags); $entry_tags = $entry_tags[1]; $entry_tags = array_merge($entry_tags, $additional_tags); $entry_tags = array_unique($entry_tags); for ($i = 0; $i < count($entry_tags); $i++) { $entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8'); } if ($debug_enabled) { //_debug("update_rss_feed: unfiltered tags found:"); //print_r($entry_tags); } # sanitize content $entry_content = sanitize_article_content($entry_content); $entry_title = sanitize_article_content($entry_title); if ($debug_enabled) { _debug("update_rss_feed: done collecting data [TITLE:{$entry_title}]"); } db_query($link, "BEGIN"); if (db_num_rows($result) == 0) { if ($debug_enabled) { _debug("update_rss_feed: base guid not found"); } // base post entry does not exist, create it $result = db_query($link, "INSERT INTO ttrss_entries\n\t\t\t\t\t\t\t(title,\n\t\t\t\t\t\t\tguid,\n\t\t\t\t\t\t\tlink,\n\t\t\t\t\t\t\tupdated,\n\t\t\t\t\t\t\tcontent,\n\t\t\t\t\t\t\tcontent_hash,\n\t\t\t\t\t\t\tno_orig_date,\n\t\t\t\t\t\t\tdate_updated,\n\t\t\t\t\t\t\tdate_entered,\n\t\t\t\t\t\t\tcomments,\n\t\t\t\t\t\t\tnum_comments,\n\t\t\t\t\t\t\tauthor)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('{$entry_title}',\n\t\t\t\t\t\t\t'{$entry_guid}',\n\t\t\t\t\t\t\t'{$entry_link}',\n\t\t\t\t\t\t\t'{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t'{$entry_content}',\n\t\t\t\t\t\t\t'{$content_hash}',\n\t\t\t\t\t\t\t{$no_orig_date},\n\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t'{$entry_comments}',\n\t\t\t\t\t\t\t'{$num_comments}',\n\t\t\t\t\t\t\t'{$entry_author}')"); } else { // we keep encountering the entry in feeds, so we need to // update date_updated column so that we don't get horrible // dupes when the entry gets purged and reinserted again e.g. // in the case of SLOW SLOW OMG SLOW updating feeds $base_entry_id = db_fetch_result($result, 0, "id"); db_query($link, "UPDATE ttrss_entries SET date_updated = NOW()\n\t\t\t\t\t\tWHERE id = '{$base_entry_id}'"); } // now it should exist, if not - bad luck then $result = db_query($link, "SELECT\n\t\t\t\t\t\tid,content_hash,no_orig_date,title,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(date_updated,1,19) as date_updated,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(updated,1,19) as updated,\n\t\t\t\t\t\tnum_comments\n\t\t\t\t\tFROM\n\t\t\t\t\t\tttrss_entries\n\t\t\t\t\tWHERE guid = '{$entry_guid}'"); $entry_ref_id = 0; $entry_int_id = 0; if (db_num_rows($result) == 1) { if ($debug_enabled) { _debug("update_rss_feed: base guid found, checking for user record"); } // this will be used below in update handler $orig_content_hash = db_fetch_result($result, 0, "content_hash"); $orig_title = db_fetch_result($result, 0, "title"); $orig_num_comments = db_fetch_result($result, 0, "num_comments"); $orig_date_updated = strtotime(db_fetch_result($result, 0, "date_updated")); $ref_id = db_fetch_result($result, 0, "id"); $entry_ref_id = $ref_id; // check for user post link to main table // do we allow duplicate posts with same GUID in different feeds? if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) { $dupcheck_qpart = "AND (feed_id = '{$feed}' OR feed_id IS NULL)"; } else { $dupcheck_qpart = ""; } /* Collect article tags here so we could filter by them: */ $article_filters = get_article_filters($filters, $entry_title, $entry_content, $entry_link, $entry_timestamp, $entry_author, $entry_tags); if ($debug_enabled) { _debug("update_rss_feed: article filters: "); if (count($article_filters) != 0) { print_r($article_filters); } } if (find_article_filter($article_filters, "filter")) { db_query($link, "COMMIT"); // close transaction in progress continue; } $score = calculate_article_score($article_filters); if ($debug_enabled) { _debug("update_rss_feed: initial score: {$score}"); } $query = "SELECT ref_id, int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}'\n\t\t\t\t\t\t\t{$dupcheck_qpart}"; // if ($_REQUEST["xdebug"]) print "$query\n"; $result = db_query($link, $query); // okay it doesn't exist - create user entry if (db_num_rows($result) == 0) { if ($debug_enabled) { _debug("update_rss_feed: user record not found, creating..."); } if ($score >= -500 && !find_article_filter($article_filters, 'catchup')) { $unread = 'true'; $last_read_qpart = 'NULL'; } else { $unread = 'false'; $last_read_qpart = 'NOW()'; } if (find_article_filter($article_filters, 'mark') || $score > 1000) { $marked = 'true'; } else { $marked = 'false'; } if (find_article_filter($article_filters, 'publish')) { $published = 'true'; } else { $published = 'false'; } // N-grams if (DB_TYPE == "pgsql" and defined('_NGRAM_TITLE_DUPLICATE_THRESHOLD')) { $result = db_query($link, "SELECT COUNT(*) AS similar FROM\n\t\t\t\t\t\t\t\t\tttrss_entries,ttrss_user_entries\n\t\t\t\t\t\t\t\tWHERE ref_id = id AND updated >= NOW() - INTERVAL '7 day'\n\t\t\t\t\t\t\t\t\tAND similarity(title, '{$entry_title}') >= " . _NGRAM_TITLE_DUPLICATE_THRESHOLD . "\n\t\t\t\t\t\t\t\t\tAND owner_uid = {$owner_uid}"); $ngram_similar = db_fetch_result($result, 0, "similar"); if ($debug_enabled) { _debug("update_rss_feed: N-gram similar results: {$ngram_similar}"); } if ($ngram_similar > 0) { $unread = 'false'; } } $result = db_query($link, "INSERT INTO ttrss_user_entries\n\t\t\t\t\t\t\t\t(ref_id, owner_uid, feed_id, unread, last_read, marked,\n\t\t\t\t\t\t\t\t\tpublished, score, tag_cache, label_cache, uuid)\n\t\t\t\t\t\t\tVALUES ('{$ref_id}', '{$owner_uid}', '{$feed}', {$unread},\n\t\t\t\t\t\t\t\t{$last_read_qpart}, {$marked}, {$published}, '{$score}', '', '', '')"); if (PUBSUBHUBBUB_HUB && $published == 'true') { $rss_link = get_self_url_prefix() . "/public.php?op=rss&id=-2&key=" . get_feed_access_key($link, -2, false, $owner_uid); $p = new Publisher(PUBSUBHUBBUB_HUB); $pubsub_result = $p->publish_update($rss_link); } $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}' AND\n\t\t\t\t\t\t\t\tfeed_id = '{$feed}' LIMIT 1"); if (db_num_rows($result) == 1) { $entry_int_id = db_fetch_result($result, 0, "int_id"); } } else { if ($debug_enabled) { _debug("update_rss_feed: user record FOUND"); } $entry_ref_id = db_fetch_result($result, 0, "ref_id"); $entry_int_id = db_fetch_result($result, 0, "int_id"); } if ($debug_enabled) { _debug("update_rss_feed: RID: {$entry_ref_id}, IID: {$entry_int_id}"); } $post_needs_update = false; $update_insignificant = false; if ($orig_num_comments != $num_comments) { $post_needs_update = true; $update_insignificant = true; } if ($content_hash != $orig_content_hash) { $post_needs_update = true; $update_insignificant = false; } if (db_escape_string($orig_title) != $entry_title) { $post_needs_update = true; $update_insignificant = false; } // if post needs update, update it and mark all user entries // linking to this post as updated if ($post_needs_update) { if (defined('DAEMON_EXTENDED_DEBUG')) { _debug("update_rss_feed: post {$entry_guid} needs update..."); } // print "<!-- post $orig_title needs update : $post_needs_update -->"; db_query($link, "UPDATE ttrss_entries\n\t\t\t\t\t\t\tSET title = '{$entry_title}', content = '{$entry_content}',\n\t\t\t\t\t\t\t\tcontent_hash = '{$content_hash}',\n\t\t\t\t\t\t\t\tupdated = '{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t\tnum_comments = '{$num_comments}'\n\t\t\t\t\t\t\tWHERE id = '{$ref_id}'"); if (!$update_insignificant) { if ($mark_unread_on_update) { db_query($link, "UPDATE ttrss_user_entries\n\t\t\t\t\t\t\t\t\tSET last_read = null, unread = true WHERE ref_id = '{$ref_id}'"); } else { if ($update_on_checksum_change) { db_query($link, "UPDATE ttrss_user_entries\n\t\t\t\t\t\t\t\t\tSET last_read = null WHERE ref_id = '{$ref_id}'\n\t\t\t\t\t\t\t\t\t\tAND unread = false"); } } } } } db_query($link, "COMMIT"); if ($debug_enabled) { _debug("update_rss_feed: assigning labels..."); } assign_article_to_labels($link, $entry_ref_id, $article_filters, $owner_uid); if ($debug_enabled) { _debug("update_rss_feed: looking for enclosures..."); } // enclosures $enclosures = array(); if ($use_simplepie) { $encs = $item->get_enclosures(); if (is_array($encs)) { foreach ($encs as $e) { $e_item = array($e->link, $e->type, $e->length); array_push($enclosures, $e_item); } } } else { // <enclosure> $e_ctr = $item['enclosure#']; if ($e_ctr > 0) { $e_item = array($item['enclosure@url'], $item['enclosure@type'], $item['enclosure@length']); array_push($enclosures, $e_item); for ($i = 0; $i <= $e_ctr; $i++) { if ($item["enclosure#{$i}@url"]) { $e_item = array($item["enclosure#{$i}@url"], $item["enclosure#{$i}@type"], $item["enclosure#{$i}@length"]); array_push($enclosures, $e_item); } } } // <media:content> // can there be many of those? yes -fox $m_ctr = $item['media']['content#']; if ($m_ctr > 0) { $e_item = array($item['media']['content@url'], $item['media']['content@medium'], $item['media']['content@length']); array_push($enclosures, $e_item); for ($i = 0; $i <= $m_ctr; $i++) { if ($item["media"]["content#{$i}@url"]) { $e_item = array($item["media"]["content#{$i}@url"], $item["media"]["content#{$i}@medium"], $item["media"]["content#{$i}@length"]); array_push($enclosures, $e_item); } } } } if ($debug_enabled) { _debug("update_rss_feed: article enclosures:"); print_r($enclosures); } db_query($link, "BEGIN"); foreach ($enclosures as $enc) { $enc_url = db_escape_string($enc[0]); $enc_type = db_escape_string($enc[1]); $enc_dur = db_escape_string($enc[2]); $result = db_query($link, "SELECT id FROM ttrss_enclosures\n\t\t\t\t\t\tWHERE content_url = '{$enc_url}' AND post_id = '{$entry_ref_id}'"); if (db_num_rows($result) == 0) { db_query($link, "INSERT INTO ttrss_enclosures\n\t\t\t\t\t\t\t(content_url, content_type, title, duration, post_id) VALUES\n\t\t\t\t\t\t\t('{$enc_url}', '{$enc_type}', '', '{$enc_dur}', '{$entry_ref_id}')"); } } db_query($link, "COMMIT"); // check for manual tags (we have to do it here since they're loaded from filters) foreach ($article_filters as $f) { if ($f["type"] == "tag") { $manual_tags = trim_array(explode(",", $f["param"])); foreach ($manual_tags as $tag) { if (tag_is_valid($tag)) { array_push($entry_tags, $tag); } } } } // Skip boring tags $boring_tags = trim_array(explode(",", mb_strtolower(get_pref($link, 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8'))); $filtered_tags = array(); $tags_to_cache = array(); if ($entry_tags && is_array($entry_tags)) { foreach ($entry_tags as $tag) { if (array_search($tag, $boring_tags) === false) { array_push($filtered_tags, $tag); } } } $filtered_tags = array_unique($filtered_tags); if ($debug_enabled) { _debug("update_rss_feed: filtered article tags:"); print_r($filtered_tags); } // Save article tags in the database if (count($filtered_tags) > 0) { db_query($link, "BEGIN"); foreach ($filtered_tags as $tag) { $tag = sanitize_tag($tag); $tag = db_escape_string($tag); if (!tag_is_valid($tag)) { continue; } $result = db_query($link, "SELECT id FROM ttrss_tags\n\t\t\t\t\t\t\tWHERE tag_name = '{$tag}' AND post_int_id = '{$entry_int_id}' AND\n\t\t\t\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1"); if ($result && db_num_rows($result) == 0) { db_query($link, "INSERT INTO ttrss_tags\n\t\t\t\t\t\t\t\t\t(owner_uid,tag_name,post_int_id)\n\t\t\t\t\t\t\t\t\tVALUES ('{$owner_uid}','{$tag}', '{$entry_int_id}')"); } array_push($tags_to_cache, $tag); } /* update the cache */ $tags_to_cache = array_unique($tags_to_cache); $tags_str = db_escape_string(join(",", $tags_to_cache)); db_query($link, "UPDATE ttrss_user_entries\n\t\t\t\t\t\tSET tag_cache = '{$tags_str}' WHERE ref_id = '{$entry_ref_id}'\n\t\t\t\t\t\tAND owner_uid = {$owner_uid}"); db_query($link, "COMMIT"); } if ($debug_enabled) { _debug("update_rss_feed: article processed"); } } if (!$last_updated) { if ($debug_enabled) { _debug("update_rss_feed: new feed, catching it up..."); } catchup_feed($link, $feed, false, $owner_uid); } if ($debug_enabled) { _debug("purging feed..."); } purge_feed($link, $feed, 0, $debug_enabled); db_query($link, "UPDATE ttrss_feeds\n\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'"); // db_query($link, "COMMIT"); } else { if ($use_simplepie) { $error_msg = mb_substr($rss->error(), 0, 250); } else { $error_msg = mb_substr(magpie_error(), 0, 250); } if ($debug_enabled) { _debug("update_rss_feed: error fetching feed: {$error_msg}"); } $error_msg = db_escape_string($error_msg); db_query($link, "UPDATE ttrss_feeds SET last_error = '{$error_msg}',\n\t\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'"); } if ($use_simplepie) { unset($rss); } if ($debug_enabled) { _debug("update_rss_feed: done"); } }</pre> </div> </figure> </div> <div class="example-item" id="0xa3aac1ab34693121f6b0b4fb4c0944b62376235ee1ed37969b8d5d6f120c3c95-13,,210,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#9</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_9" data-hash="0xa3aac1ab34693121f6b0b4fb4c0944b62376235ee1ed37969b8d5d6f120c3c95" data-area="13,,210,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '9')" class="rating-up btn btn-success" data-id="rating_9"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'9')" class="rating-down btn btn-danger" data-id="rating_9"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0xa3aac1ab34693121f6b0b4fb4c0944b62376235ee1ed37969b8d5d6f120c3c95-13,,210,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0xa3aac1ab34693121f6b0b4fb4c0944b62376235ee1ed37969b8d5d6f120c3c95&fullName=modules%2Fhelper.php&project=bizanto%2FHooked')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fbizanto%2FHooked%2Fblob%2Fmaster%2Fmodules%2Fhelper.php">helper.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fbizanto%2FHooked">bizanto/Hooked</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="9"> <pre class="line-numbers language-php" data-end="210" data-start="14" data-highlight="99,100"> function getFeed(&$params) { //global $mainframe; $slick_rss = array(); //init feed array if (!class_exists('SimplePie')) { //include Simple Pie processor class require_once JPATH_SITE . DS . 'libraries' . DS . 'simplepie' . DS . 'simplepie.php'; } // check if cache directory exists and is writeable $cacheDir = JPATH_BASE . DS . 'cache'; if (!is_writable($cacheDir)) { $slick_rss['error'][] = 'Cache folder is unwriteable. Solution: chmod 777 ' . $cacheDir; $cache_exists = false; } else { $cache_exists = true; } //get local module parameters from xml file module config settings $rssurl = $params->get('rssurl', NULL); $rssitems = $params->get('rssitems', 5); $rssdesc = $params->get('rssdesc', 1); $rssimage = $params->get('rssimage', 1); $rssitemtitle_words = $params->get('rssitemtitle_words', 0); $rssitemdesc = $params->get('rssitemdesc', 0); $rssitemdesc_images = $params->get('rssitemdesc_images', 1); $rssitemdesc_words = $params->get('rssitemdesc_words', 0); $rsstitle = $params->get('rsstitle', 1); $rsscache = $params->get('rsscache', 3600); $link_target = $params->get('link_target', 1); $no_follow = $params->get('no_follow', 0); $enable_tooltip = $params->get('enable_tooltip', 'yes'); $tooltip_desc_words = $params->get('t_word_count_desc', 25); $tooltip_desc_images = $params->get('tooltip_desc_images', 1); $tooltip_title_words = $params->get('t_word_count_title', 25); if (!$rssurl) { $slick_rss['error'][] = 'Invalid feed url. Please enter a valid url in the module settings.'; return $slick_rss; //halt if no valid feed url supplied } switch ($link_target) { //open links in current or new window case 1: $link_target = '_blank'; break; case 0: $link_target = '_self'; break; default: $link_target = '_blank'; break; } $slick_rss['target'] = $link_target; if ($no_follow) { $slick_rss['nofollow'] = 'rel="nofollow"'; } //Load and build the feed array $feed = new SimplePie(); $feed->set_feed_url($rssurl); //check and set caching if ($cache_exists) { $feed->set_cache_location($cacheDir); $feed->enable_cache(); $cache_time = intval($rsscache); $feed->set_cache_duration($cache_time); } else { $feed->enable_cache('false'); } $feed->init(); //process the loaded feed $feed->handle_content_type(); //store any error message if (isset($feed->error)) { $slick_rss['error'][] = $feed->error; } //start building the feed meta-info (title, desc and image) // feed title if ($feed->get_title() && $rsstitle) { $slick_rss['title']['link'] = $feed->get_link(); $slick_rss['title']['title'] = $feed->get_title(); } // feed description if ($rssdesc) { $slick_rss['description'] = $feed->get_description(); } // feed image if ($rssimage && $feed->get_image_url()) { $slick_rss['image']['url'] = $feed->get_image_url(); $slick_rss['image']['title'] = $feed->get_image_title(); } //end feed meta-info //start processing feed items //if there are items in the feed if ($feed->get_item_quantity()) { //start looping through the feed items $slick_rss_item = 0; //item counter for array indexing in the loop foreach ($feed->get_items(0, $rssitems) as $currItem) { // item title $item_title = trim($currItem->get_title()); // item title word limit check if ($rssitemtitle_words) { $item_titles = explode(' ', $item_title); $count = count($item_titles); if ($count > $rssitemtitle_words) { $item_title = ''; for ($i = 0; $i < $rssitemtitle_words; $i++) { $item_title .= ' ' . $item_titles[$i]; } $item_title .= '...'; } } $slick_rss['items'][$slick_rss_item]['title'] = $item_title; // Item Title $slick_rss['items'][$slick_rss_item]['link'] = $currItem->get_permalink(); // item description if ($rssitemdesc) { $desc = trim($currItem->get_description()); if (!$rssitemdesc_images) { $desc = preg_replace("/<img[^>]+\\>/i", "", $desc); //strip image tags } //item description word limit check if ($rssitemdesc_words) { $texts = explode(' ', $desc); $count = count($texts); if ($count > $rssitemdesc_words) { $desc = ''; for ($i = 0; $i < $rssitemdesc_words; $i++) { $desc .= ' ' . $texts[$i]; //build words } $desc .= '...'; } } $slick_rss['items'][$slick_rss_item]['description'] = $desc; //Item Description } // tooltip text if ($enable_tooltip == 'yes') { //tooltip item title $t_item_title = trim($currItem->get_title()); // tooltip title word limit check if ($tooltip_title_words) { $t_item_titles = explode(' ', $t_item_title); $count = count($t_item_titles); if ($count > $tooltip_title_words) { $tooltip_title = ''; for ($i = 0; $i < $tooltip_title_words; $i++) { $tooltip_title .= ' ' . $t_item_titles[$i]; } $tooltip_title .= '...'; } else { $tooltip_title = $t_item_title; } } else { $tooltip_title = $t_item_title; } $tooltip_title = preg_replace("/(\r\n|\n|\r)/", " ", $tooltip_title); //replace new line characters in tooltip title, important! $tooltip_title = htmlspecialchars(html_entity_decode($tooltip_title), ENT_QUOTES); //format text for tooltip $slick_rss['items'][$slick_rss_item]['tooltip']['title'] = $tooltip_title; //Tooltip Title //tooltip item description $text = trim($currItem->get_description()); if (!$tooltip_desc_images) { $text = preg_replace("/<img[^>]+\\>/i", "", $text); } // tooltip desc word limit check if ($tooltip_desc_words) { $texts = explode(' ', $text); $count = count($texts); if ($count > $tooltip_desc_words) { $text = ''; for ($i = 0; $i < $tooltip_desc_words; $i++) { $text .= ' ' . $texts[$i]; } $text .= '...'; } } $text = preg_replace("/(\r\n|\n|\r)/", " ", $text); //replace new line characters in tooltip, important! $text = htmlspecialchars(html_entity_decode($text), ENT_QUOTES); //format text for tooltip $slick_rss['items'][$slick_rss_item]['tooltip']['description'] = $text; //Tooltip Body } else { $slick_rss['items'][$slick_rss_item]['tooltip'] = array(); //blank } $slick_rss_item++; //increment item counter } } //end item quantity check if statement //return the feed data structure for the template return $slick_rss; }</pre> </div> </figure> </div> <div class="example-item" id="0x9ad7a44a68ca84c264076e718b6cd6ea9d257b77b5c008b11599705da19e4642-291,,799,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#10</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_10" data-hash="0x9ad7a44a68ca84c264076e718b6cd6ea9d257b77b5c008b11599705da19e4642" data-area="291,,799,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '10')" class="rating-up btn btn-success" data-id="rating_10"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'10')" class="rating-down btn btn-danger" data-id="rating_10"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x9ad7a44a68ca84c264076e718b6cd6ea9d257b77b5c008b11599705da19e4642-291,,799,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x9ad7a44a68ca84c264076e718b6cd6ea9d257b77b5c008b11599705da19e4642&fullName=Scrape.php&project=vinzv%2Ffriendica')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvinzv%2Ffriendica%2Fblob%2Fmaster%2FScrape.php">Scrape.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fvinzv%2Ffriendica">vinzv/friendica</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="10"> <pre class="line-numbers language-php" data-end="799" data-start="292" data-highlight="591">function probe_url($url, $mode = PROBE_NORMAL, $level = 1) { require_once 'include/email.php'; $result = array(); if (!$url) { return $result; } $result = Cache::get("probe_url:" . $mode . ":" . $url); if (!is_null($result)) { $result = unserialize($result); return $result; } $network = null; $diaspora = false; $diaspora_base = ''; $diaspora_guid = ''; $diaspora_key = ''; $has_lrdd = false; $email_conversant = false; $connectornetworks = false; $appnet = false; if (strpos($url, 'twitter.com')) { $connectornetworks = true; $network = NETWORK_TWITTER; } // Twitter is deactivated since twitter closed its old API //$twitter = ((strpos($url,'twitter.com') !== false) ? true : false); $lastfm = strpos($url, 'last.fm/user') !== false ? true : false; $at_addr = strpos($url, '@') !== false ? true : false; if (!$appnet && !$lastfm && !$connectornetworks) { if (strpos($url, 'mailto:') !== false && $at_addr) { $url = str_replace('mailto:', '', $url); $links = array(); } else { $links = lrdd($url); } if (count($links)) { $has_lrdd = true; logger('probe_url: found lrdd links: ' . print_r($links, true), LOGGER_DATA); foreach ($links as $link) { if ($link['@attributes']['rel'] === NAMESPACE_ZOT) { $zot = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === NAMESPACE_DFRN) { $dfrn = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'salmon') { $notify = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === NAMESPACE_FEED) { $poll = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') { $hcard = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') { $profile = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') { $poco = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') { $diaspora_base = unamp($link['@attributes']['href']); $diaspora = true; } if ($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') { $diaspora_guid = unamp($link['@attributes']['href']); $diaspora = true; } if ($link['@attributes']['rel'] === 'diaspora-public-key') { $diaspora_key = base64_decode(unamp($link['@attributes']['href'])); if (strstr($diaspora_key, 'RSA ')) { $pubkey = rsatopem($diaspora_key); } else { $pubkey = $diaspora_key; } $diaspora = true; } if ($link['@attributes']['rel'] === 'http://ostatus.org/schema/1.0/subscribe' and $mode == PROBE_NORMAL) { $diaspora = false; } } // Status.Net can have more than one profile URL. We need to match the profile URL // to a contact on incoming messages to prevent spam, and we won't know which one // to match. So in case of two, one of them is stored as an alias. Only store URL's // and not webfinger user@host aliases. If they've got more than two non-email style // aliases, let's hope we're lucky and get one that matches the feed author-uri because // otherwise we're screwed. foreach ($links as $link) { if ($link['@attributes']['rel'] === 'alias') { if (strpos($link['@attributes']['href'], '@') === false) { if (isset($profile)) { if ($link['@attributes']['href'] !== $profile) { $alias = unamp($link['@attributes']['href']); } } else { $profile = unamp($link['@attributes']['href']); } } } } // If the profile is different from the url then the url is abviously an alias if ($alias == "" and $profile != "" and !$at_addr and normalise_link($profile) != normalise_link($url)) { $alias = $url; } } elseif ($mode == PROBE_NORMAL) { // Check email $orig_url = $url; if (strpos($orig_url, '@') && validate_email($orig_url)) { $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user())); $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user())); if (count($x) && count($r)) { $mailbox = construct_mailbox_name($r[0]); $password = ''; openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']); $mbox = email_connect($mailbox, $r[0]['user'], $password); if (!$mbox) { logger('probe_url: email_connect failed.'); } unset($password); } if ($mbox) { $msgs = email_poll($mbox, $orig_url); logger('probe_url: searching ' . $orig_url . ', ' . count($msgs) . ' messages found.', LOGGER_DEBUG); if (count($msgs)) { $addr = $orig_url; $network = NETWORK_MAIL; $name = substr($url, 0, strpos($url, '@')); $phost = substr($url, strpos($url, '@') + 1); $profile = 'http://' . $phost; // fix nick character range $vcard = array('fn' => $name, 'nick' => $name, 'photo' => avatar_img($url)); $notify = 'smtp ' . random_string(); $poll = 'email ' . random_string(); $priority = 0; $x = email_msg_meta($mbox, $msgs[0]); if (stristr($x[0]->from, $orig_url)) { $adr = imap_rfc822_parse_adrlist($x[0]->from, ''); } elseif (stristr($x[0]->to, $orig_url)) { $adr = imap_rfc822_parse_adrlist($x[0]->to, ''); } if (isset($adr)) { foreach ($adr as $feadr) { if (strcasecmp($feadr->mailbox, $name) == 0 && strcasecmp($feadr->host, $phost) == 0 && strlen($feadr->personal)) { $personal = imap_mime_header_decode($feadr->personal); $vcard['fn'] = ""; foreach ($personal as $perspart) { if ($perspart->charset != "default") { $vcard['fn'] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text); } else { $vcard['fn'] .= $perspart->text; } } $vcard['fn'] = notags($vcard['fn']); } } } } imap_close($mbox); } } } } if ($mode == PROBE_NORMAL) { if (strlen($zot)) { $s = fetch_url($zot); if ($s) { $j = json_decode($s); if ($j) { $network = NETWORK_ZOT; $vcard = array('fn' => $j->fullname, 'nick' => $j->nickname, 'photo' => $j->photo); $profile = $j->url; $notify = $j->post; $pubkey = $j->pubkey; $poll = 'N/A'; } } } if (strlen($dfrn)) { $ret = scrape_dfrn($hcard ? $hcard : $dfrn, true); if (is_array($ret) && x($ret, 'dfrn-request')) { $network = NETWORK_DFRN; $request = $ret['dfrn-request']; $confirm = $ret['dfrn-confirm']; $notify = $ret['dfrn-notify']; $poll = $ret['dfrn-poll']; $vcard = array(); $vcard['fn'] = $ret['fn']; $vcard['nick'] = $ret['nick']; $vcard['photo'] = $ret['photo']; } } } if ($diaspora && $diaspora_base && $diaspora_guid) { if ($mode == PROBE_DIASPORA || !$notify) { $notify = $diaspora_base . 'receive/users/' . $diaspora_guid; $batch = $diaspora_base . 'receive/public'; } if (strpos($url, '@')) { $addr = str_replace('acct:', '', $url); } } if ($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) { if ($diaspora) { $network = NETWORK_DIASPORA; } elseif ($has_lrdd and $notify) { $network = NETWORK_OSTATUS; } if (strpos($url, '@')) { $addr = str_replace('acct:', '', $url); } $priority = 0; if ($hcard && !$vcard) { $vcard = scrape_vcard($hcard); // Google doesn't use absolute url in profile photos if (x($vcard, 'photo') && substr($vcard['photo'], 0, 1) == '/') { $h = @parse_url($hcard); if ($h) { $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo']; } } logger('probe_url: scrape_vcard: ' . print_r($vcard, true), LOGGER_DATA); } if ($diaspora && $addr) { // Diaspora returns the name as the nick. As the nick will never be updated, // let's use the Diaspora nickname (the first part of the handle) as the nick instead $addr_parts = explode('@', $addr); $vcard['nick'] = $addr_parts[0]; } /* if($twitter) { logger('twitter: setup'); $tid = basename($url); $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss'; if(intval($tid)) $poll = $tapi . '?user_id=' . $tid; else $poll = $tapi . '?screen_name=' . $tid; $profile = 'http://twitter.com/#!/' . $tid; //$vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid; $vcard['photo'] = 'https://api.twitter.com/1/users/profile_image?screen_name=' . $tid . '&size=bigger'; $vcard['nick'] = $tid; $vcard['fn'] = $tid; } */ if ($lastfm) { $profile = $url; $poll = str_replace(array('www.', 'last.fm/'), array('', 'ws.audioscrobbler.com/1.0/'), $url) . '/recenttracks.rss'; $vcard['nick'] = basename($url); $vcard['fn'] = $vcard['nick'] . t(' on Last.fm'); $network = NETWORK_FEED; } if (!x($vcard, 'fn')) { if (x($vcard, 'nick')) { $vcard['fn'] = $vcard['nick']; } } $check_feed = false; if (stristr($url, 'tumblr.com') && !stristr($url, '/rss')) { $poll = $url . '/rss'; $check_feed = true; // Will leave it to others to figure out how to grab the avatar, which is on the $url page in the open graph meta links } if ($appnet || !$poll) { $check_feed = true; } if (!isset($vcard) || !x($vcard, 'fn') || !$profile) { $check_feed = true; } if ($at_addr && !count($links)) { $check_feed = false; } if ($connectornetworks) { $check_feed = false; } if ($check_feed) { $feedret = scrape_feed($poll ? $poll : $url); logger('probe_url: scrape_feed ' . ($poll ? $poll : $url) . ' returns: ' . print_r($feedret, true), LOGGER_DATA); if (count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) { $poll = x($feedret, 'feed_atom') ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']); if (!x($vcard)) { $vcard = array(); } } if (x($feedret, 'photo') && !x($vcard, 'photo')) { $vcard['photo'] = $feedret['photo']; } require_once 'library/simplepie/simplepie.inc'; $feed = new SimplePie(); $xml = fetch_url($poll); logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA); $a = get_app(); logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), LOGGER_DATA); // Don't try and parse an empty string $feed->set_raw_data($xml ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>'); $feed->init(); if ($feed->error()) { logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error()); $network = NETWORK_PHANTOM; } if (!x($vcard, 'photo')) { $vcard['photo'] = $feed->get_image_url(); } $author = $feed->get_author(); if ($author) { $vcard['fn'] = unxmlify(trim($author->get_name())); if (!$vcard['fn']) { $vcard['fn'] = trim(unxmlify($author->get_email())); } if (strpos($vcard['fn'], '@') !== false) { $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@')); } $email = unxmlify($author->get_email()); if (!$profile && $author->get_link()) { $profile = trim(unxmlify($author->get_link())); } if (!$vcard['photo']) { $rawtags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') { $vcard['photo'] = $elems['link'][0]['attribs']['']['href']; } } } // Fetch fullname via poco:displayName $pocotags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($pocotags) { $elems = $pocotags[0]['child']['http://portablecontacts.net/spec/1.0']; if (isset($elems["displayName"])) { $vcard['fn'] = $elems["displayName"][0]["data"]; } if (isset($elems["preferredUsername"])) { $vcard['nick'] = $elems["preferredUsername"][0]["data"]; } } } else { $item = $feed->get_item(0); if ($item) { $author = $item->get_author(); if ($author) { $vcard['fn'] = trim(unxmlify($author->get_name())); if (!$vcard['fn']) { $vcard['fn'] = trim(unxmlify($author->get_email())); } if (strpos($vcard['fn'], '@') !== false) { $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@')); } $email = unxmlify($author->get_email()); if (!$profile && $author->get_link()) { $profile = trim(unxmlify($author->get_link())); } } if (!$vcard['photo']) { $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/', 'thumbnail'); if ($rawmedia && $rawmedia[0]['attribs']['']['url']) { $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']); } } if (!$vcard['photo']) { $rawtags = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') { $vcard['photo'] = $elems['link'][0]['attribs']['']['href']; } } } } } // Workaround for misconfigured Friendica servers if ($network == "" and strstr($url, "/profile/")) { $noscrape = str_replace("/profile/", "/noscrape/", $url); $noscrapejson = fetch_url($noscrape); if ($noscrapejson) { $network = NETWORK_DFRN; $poco = str_replace("/profile/", "/poco/", $url); $noscrapedata = json_decode($noscrapejson, true); if (isset($noscrapedata["addr"])) { $addr = $noscrapedata["addr"]; } if (isset($noscrapedata["fn"])) { $vcard["fn"] = $noscrapedata["fn"]; } if (isset($noscrapedata["key"])) { $pubkey = $noscrapedata["key"]; } if (isset($noscrapedata["photo"])) { $vcard["photo"] = $noscrapedata["photo"]; } if (isset($noscrapedata["dfrn-request"])) { $request = $noscrapedata["dfrn-request"]; } if (isset($noscrapedata["dfrn-confirm"])) { $confirm = $noscrapedata["dfrn-confirm"]; } if (isset($noscrapedata["dfrn-notify"])) { $notify = $noscrapedata["dfrn-notify"]; } if (isset($noscrapedata["dfrn-poll"])) { $poll = $noscrapedata["dfrn-poll"]; } } } if (!$vcard['photo'] && strlen($email)) { $vcard['photo'] = avatar_img($email); } if ($poll === $profile) { $lnk = $feed->get_permalink(); } if (isset($lnk) && strlen($lnk)) { $profile = $lnk; } if (!$network) { $network = NETWORK_FEED; // If it is a feed, don't take the author name as feed name unset($vcard['fn']); } if (!x($vcard, 'fn')) { $vcard['fn'] = notags($feed->get_title()); } if (!x($vcard, 'fn')) { $vcard['fn'] = notags($feed->get_description()); } if (strpos($vcard['fn'], 'Twitter / ') !== false) { $vcard['fn'] = substr($vcard['fn'], strpos($vcard['fn'], '/') + 1); $vcard['fn'] = trim($vcard['fn']); } if (!x($vcard, 'nick')) { $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn']))); if (strpos($vcard['nick'], ' ')) { $vcard['nick'] = trim(substr($vcard['nick'], 0, strpos($vcard['nick'], ' '))); } } if (!$priority) { $priority = 2; } } } if (!x($vcard, 'photo')) { $a = get_app(); $vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg'; } if (!$profile) { $profile = $url; } // No human could be associated with this link, use the URL as the contact name if ($network === NETWORK_FEED && $poll && !x($vcard, 'fn')) { $vcard['fn'] = $url; } if ($notify != "" and $poll != "") { $baseurl = matching(normalise_link($notify), normalise_link($poll)); $baseurl2 = matching($baseurl, normalise_link($profile)); if ($baseurl2 != "") { $baseurl = $baseurl2; } } if ($baseurl == "" and $notify != "") { $baseurl = matching(normalise_link($profile), normalise_link($notify)); } if ($baseurl == "" and $poll != "") { $baseurl = matching(normalise_link($profile), normalise_link($poll)); } $baseurl = rtrim($baseurl, "/"); if (strpos($url, '@') and $addr == "" and $network == NETWORK_DFRN) { $addr = str_replace('acct:', '', $url); } $vcard['fn'] = notags($vcard['fn']); $vcard['nick'] = str_replace(' ', '', notags($vcard['nick'])); $result['name'] = $vcard['fn']; $result['nick'] = $vcard['nick']; $result['url'] = $profile; $result['addr'] = $addr; $result['batch'] = $batch; $result['notify'] = $notify; $result['poll'] = $poll; $result['request'] = $request; $result['confirm'] = $confirm; $result['poco'] = $poco; $result['photo'] = $vcard['photo']; $result['priority'] = $priority; $result['network'] = $network; $result['alias'] = $alias; $result['pubkey'] = $pubkey; $result['baseurl'] = $baseurl; logger('probe_url: ' . print_r($result, true), LOGGER_DEBUG); if ($level == 1) { // Trying if it maybe a diaspora account if ($result['network'] == NETWORK_FEED or $result['addr'] == "") { require_once 'include/bbcode.php'; $address = GetProfileUsername($url, "", true); $result2 = probe_url($address, $mode, ++$level); if ($result2['network'] != "") { $result = $result2; } } // Maybe it's some non standard GNU Social installation (Single user, subfolder or no uri rewrite) if ($result['network'] == NETWORK_FEED and $result['baseurl'] != "" and $result['nick'] != "") { $addr = $result['nick'] . '@' . str_replace("http://", "", $result['baseurl']); $result2 = probe_url($addr, $mode, ++$level); if ($result2['network'] != "" and $result2['network'] != NETWORK_FEED) { $result = $result2; } } } // Only store into the cache if the value seems to be valid if ($result['network'] != NETWORK_PHANTOM) { Cache::set("probe_url:" . $mode . ":" . $url, serialize($result), CACHE_DAY); } return $result; }</pre> </div> </figure> </div> <div class="example-item" id="0x2001a72c66b569cd26e5d4bd01728a933504fdfef6282bbb56ef78677feee178-20,,116,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#11</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_11" data-hash="0x2001a72c66b569cd26e5d4bd01728a933504fdfef6282bbb56ef78677feee178" data-area="20,,116,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '11')" class="rating-up btn btn-success" data-id="rating_11"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'11')" class="rating-down btn btn-danger" data-id="rating_11"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x2001a72c66b569cd26e5d4bd01728a933504fdfef6282bbb56ef78677feee178-20,,116,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x2001a72c66b569cd26e5d4bd01728a933504fdfef6282bbb56ef78677feee178&fullName=Rss.class.php&project=jorgefuertes%2FqPlanet')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjorgefuertes%2FqPlanet%2Fblob%2Fmaster%2FRss.class.php">Rss.class.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjorgefuertes%2FqPlanet">jorgefuertes/qPlanet</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="11"> <pre class="line-numbers language-php" data-end="116" data-start="21" data-highlight="104"> /** * * Get posts from feeds: * @param array $feeds Array with the feeds. * @return array Array with the posts. */ public function getPosts($feeds) { $posts = array(); foreach ($feeds as $name => $feed) { Debug::info("Getting posts from " . $feed['url']); $rss = new SimplePie($feed['url']); $rss->handle_content_type(); $rss->force_feed(true); $counter = 1; foreach ($rss->get_items() as $item) { Debug::info(" post {$counter} of " . MAXPOSTS . "."); if (!is_object($item)) { Debug::error("Parsing item (" . $item . ")."); } else { if (strstr($item->get_title(), "[minipost]")) { Debug::say("Minipost...passing."); } else { $counter++; $timestamp = strtotime($item->get_date()); # Post: $posts[$timestamp]['id'] = "p" . $timestamp . "-" . $counter; $posts[$timestamp]['pubdate'] = $item->get_date('r'); $posts[$timestamp]['date'] = $item->get_local_date(); $posts[$timestamp]['time'] = $item->get_local_date("%T"); $posts[$timestamp]['permalink'] = $item->get_permalink(); $posts[$timestamp]['title'] = $item->get_title(); $posts[$timestamp]['description'] = $item->get_description(); $posts[$timestamp]['content'] = $item->get_content(); if ($posts[$timestamp]['description'] == $posts[$timestamp]['content'] and strlen($posts[$timestamp]['content']) < 400) { $posts[$timestamp]['description'] = Html::Cut(Html::BurnerClean($item->get_description())); $posts[$timestamp]['content'] = ""; $posts[$timestamp]['toggle'] = ""; } else { $posts[$timestamp]['description'] = Html::Cut(Html::BurnerClean($item->get_description())); $posts[$timestamp]['content'] = Html::Clean($item->get_content()); $posts[$timestamp]['toggle'] = "<a onclick='ToggleContent(\"" . $posts[$timestamp]['id'] . "\"); return false;' href=\"#\">&dArr; Read more</a>"; } // Microblogging posts have same description as title if (FALSE !== strpos($posts[$timestamp]['title'], $posts[$timestamp]['description'])) { $posts[$timestamp]['description'] = ""; $posts[$timestamp]['content'] = ""; $posts[$timestamp]['toggle'] = ""; } # Rss: $posts[$timestamp]['description_rss'] = $posts[$timestamp]['description']; $posts[$timestamp]['content_rss'] = $posts[$timestamp]['content']; # author: if (method_exists($item, 'get_author') and is_object($item->get_author())) { # The feed ones: $posts[$timestamp]['author'] = $item->get_author()->get_name(); $posts[$timestamp]['author_link'] = $item->get_author()->get_link(); } else { Debug::say("No author data feed " . $name); $posts[$timestamp]['author'] = $name; $posts[$timestamp]['author_link'] = $rss->get_permalink(); } # Si han quedado vacíos pese a todo: if (empty($posts[$timestamp]['author'])) { $posts[$timestamp]['author'] = $name; } if (empty($posts[$timestamp]['author_link'])) { $posts[$timestamp]['author_link'] = $feed['url']; } $posts[$timestamp]['author_email'] = $feed['email']; # Gravatar: if (strlen($feed['avatar'])) { $posts[$timestamp]['author_avatar'] = "http://www.gravatar.com/avatar.php?gravatar_id=" . md5($feed['avatar']) . "&amp;size=40&amp;default=" . urlencode(DEFAULT_AVATAR); } else { if (strlen($feed['avatar_url'])) { $posts[$timestamp]['author_avatar'] = $feed['avatar_url']; } } # Blog: $posts[$timestamp]['blog_title'] = $rss->get_title(); $posts[$timestamp]['blog_url'] = $rss->get_permalink(); $posts[$timestamp]['blog_desc'] = $rss->get_description(); # Logo: $posts[$timestamp]['logo_url'] = $rss->get_image_url(); $posts[$timestamp]['logo_link'] = $rss->get_image_link(); $posts[$timestamp]['logo_title'] = $rss->get_image_title(); } } if ($counter > MAXPOSTS) { break; } } } krsort($posts); #Debug::dump($posts); return $posts; }</pre> </div> </figure> </div> <div class="example-item" id="0xf38cf8215b77c662ef3936a1ba4c2b891b75ab8f3d3f7c9c5b99899f729b579c-290,,660,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#12</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_12" data-hash="0xf38cf8215b77c662ef3936a1ba4c2b891b75ab8f3d3f7c9c5b99899f729b579c" data-area="290,,660,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '12')" class="rating-up btn btn-success" data-id="rating_12"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'12')" class="rating-down btn btn-danger" data-id="rating_12"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0xf38cf8215b77c662ef3936a1ba4c2b891b75ab8f3d3f7c9c5b99899f729b579c-290,,660,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0xf38cf8215b77c662ef3936a1ba4c2b891b75ab8f3d3f7c9c5b99899f729b579c&fullName=Scrape.php&project=robhell%2Ffriendica')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Frobhell%2Ffriendica%2Fblob%2Fmaster%2FScrape.php">Scrape.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Frobhell%2Ffriendica">robhell/friendica</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="12"> <pre class="line-numbers language-php" data-end="660" data-start="291" data-highlight="540">function probe_url($url, $mode = PROBE_NORMAL) { require_once 'include/email.php'; $result = array(); if (!$url) { return $result; } $network = null; $diaspora = false; $diaspora_base = ''; $diaspora_guid = ''; $diaspora_key = ''; $has_lrdd = false; $email_conversant = false; $twitter = strpos($url, 'twitter.com') !== false ? true : false; $at_addr = strpos($url, '@') !== false ? true : false; if (!$twitter) { if (strpos($url, 'mailto:') !== false && $at_addr) { $url = str_replace('mailto:', '', $url); $links = array(); } else { $links = lrdd($url); } if (count($links)) { $has_lrdd = true; logger('probe_url: found lrdd links: ' . print_r($links, true), LOGGER_DATA); foreach ($links as $link) { if ($link['@attributes']['rel'] === NAMESPACE_ZOT) { $zot = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === NAMESPACE_DFRN) { $dfrn = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'salmon') { $notify = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === NAMESPACE_FEED) { $poll = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') { $hcard = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') { $profile = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') { $poco = unamp($link['@attributes']['href']); } if ($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') { $diaspora_base = unamp($link['@attributes']['href']); $diaspora = true; } if ($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') { $diaspora_guid = unamp($link['@attributes']['href']); $diaspora = true; } if ($link['@attributes']['rel'] === 'diaspora-public-key') { $diaspora_key = base64_decode(unamp($link['@attributes']['href'])); $pubkey = rsatopem($diaspora_key); $diaspora = true; } } // Status.Net can have more than one profile URL. We need to match the profile URL // to a contact on incoming messages to prevent spam, and we won't know which one // to match. So in case of two, one of them is stored as an alias. Only store URL's // and not webfinger user@host aliases. If they've got more than two non-email style // aliases, let's hope we're lucky and get one that matches the feed author-uri because // otherwise we're screwed. foreach ($links as $link) { if ($link['@attributes']['rel'] === 'alias') { if (strpos($link['@attributes']['href'], '@') === false) { if (isset($profile)) { if ($link['@attributes']['href'] !== $profile) { $alias = unamp($link['@attributes']['href']); } } else { $profile = unamp($link['@attributes']['href']); } } } } } elseif ($mode == PROBE_NORMAL) { // Check email $orig_url = $url; if (strpos($orig_url, '@') && validate_email($orig_url)) { $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user())); $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user())); if (count($x) && count($r)) { $mailbox = construct_mailbox_name($r[0]); $password = ''; openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']); $mbox = email_connect($mailbox, $r[0]['user'], $password); if (!$mbox) { logger('probe_url: email_connect failed.'); } unset($password); } if ($mbox) { $msgs = email_poll($mbox, $orig_url); logger('probe_url: searching ' . $orig_url . ', ' . count($msgs) . ' messages found.', LOGGER_DEBUG); if (count($msgs)) { $addr = $orig_url; $network = NETWORK_MAIL; $name = substr($url, 0, strpos($url, '@')); $phost = substr($url, strpos($url, '@') + 1); $profile = 'http://' . $phost; // fix nick character range $vcard = array('fn' => $name, 'nick' => $name, 'photo' => avatar_img($url)); $notify = 'smtp ' . random_string(); $poll = 'email ' . random_string(); $priority = 0; $x = email_msg_meta($mbox, $msgs[0]); if (stristr($x->from, $orig_url)) { $adr = imap_rfc822_parse_adrlist($x->from, ''); } elseif (stristr($x->to, $orig_url)) { $adr = imap_rfc822_parse_adrlist($x->to, ''); } if (isset($adr)) { foreach ($adr as $feadr) { if (strcasecmp($feadr->mailbox, $name) == 0 && strcasecmp($feadr->host, $phost) == 0 && strlen($feadr->personal)) { $personal = imap_mime_header_decode($feadr->personal); $vcard['fn'] = ""; foreach ($personal as $perspart) { if ($perspart->charset != "default") { $vcard['fn'] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text); } else { $vcard['fn'] .= $perspart->text; } } $vcard['fn'] = notags($vcard['fn']); } } } } imap_close($mbox); } } } } if ($mode == PROBE_NORMAL) { if (strlen($zot)) { $s = fetch_url($zot); if ($s) { $j = json_decode($s); if ($j) { $network = NETWORK_ZOT; $vcard = array('fn' => $j->fullname, 'nick' => $j->nickname, 'photo' => $j->photo); $profile = $j->url; $notify = $j->post; $pubkey = $j->pubkey; $poll = 'N/A'; } } } if (strlen($dfrn)) { $ret = scrape_dfrn($hcard ? $hcard : $dfrn); if (is_array($ret) && x($ret, 'dfrn-request')) { $network = NETWORK_DFRN; $request = $ret['dfrn-request']; $confirm = $ret['dfrn-confirm']; $notify = $ret['dfrn-notify']; $poll = $ret['dfrn-poll']; $vcard = array(); $vcard['fn'] = $ret['fn']; $vcard['nick'] = $ret['nick']; $vcard['photo'] = $ret['photo']; } } } if ($diaspora && $diaspora_base && $diaspora_guid) { if ($mode == PROBE_DIASPORA || !$notify) { $notify = $diaspora_base . 'receive/users/' . $diaspora_guid; $batch = $diaspora_base . 'receive/public'; } if (strpos($url, '@')) { $addr = str_replace('acct:', '', $url); } } if ($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) { if ($diaspora) { $network = NETWORK_DIASPORA; } elseif ($has_lrdd) { $network = NETWORK_OSTATUS; } $priority = 0; if ($hcard && !$vcard) { $vcard = scrape_vcard($hcard); // Google doesn't use absolute url in profile photos if (x($vcard, 'photo') && substr($vcard['photo'], 0, 1) == '/') { $h = @parse_url($hcard); if ($h) { $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo']; } } logger('probe_url: scrape_vcard: ' . print_r($vcard, true), LOGGER_DATA); } if ($twitter) { logger('twitter: setup'); $tid = basename($url); $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss'; if (intval($tid)) { $poll = $tapi . '?user_id=' . $tid; } else { $poll = $tapi . '?screen_name=' . $tid; } $profile = 'http://twitter.com/#!/' . $tid; $vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid; $vcard['nick'] = $tid; $vcard['fn'] = $tid . '@twitter'; } if (!x($vcard, 'fn')) { if (x($vcard, 'nick')) { $vcard['fn'] = $vcard['nick']; } } $check_feed = false; if ($twitter || !$poll) { $check_feed = true; } if (!isset($vcard) || !x($vcard, 'fn') || !$profile) { $check_feed = true; } if ($at_addr && !count($links)) { $check_feed = false; } if ($check_feed) { $feedret = scrape_feed($poll ? $poll : $url); logger('probe_url: scrape_feed ' . ($poll ? $poll : $url) . ' returns: ' . print_r($feedret, true), LOGGER_DATA); if (count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) { $poll = x($feedret, 'feed_atom') ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']); if (!x($vcard)) { $vcard = array(); } } if (x($feedret, 'photo') && !x($vcard, 'photo')) { $vcard['photo'] = $feedret['photo']; } require_once 'library/simplepie/simplepie.inc'; $feed = new SimplePie(); $xml = fetch_url($poll); logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA); $a = get_app(); logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), LOGGER_DATA); $feed->set_raw_data($xml); $feed->init(); if ($feed->error()) { logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error()); } if (!x($vcard, 'photo')) { $vcard['photo'] = $feed->get_image_url(); } $author = $feed->get_author(); if ($author) { $vcard['fn'] = unxmlify(trim($author->get_name())); if (!$vcard['fn']) { $vcard['fn'] = trim(unxmlify($author->get_email())); } if (strpos($vcard['fn'], '@') !== false) { $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@')); } $email = unxmlify($author->get_email()); if (!$profile && $author->get_link()) { $profile = trim(unxmlify($author->get_link())); } if (!$vcard['photo']) { $rawtags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') { $vcard['photo'] = $elems['link'][0]['attribs']['']['href']; } } } } else { $item = $feed->get_item(0); if ($item) { $author = $item->get_author(); if ($author) { $vcard['fn'] = trim(unxmlify($author->get_name())); if (!$vcard['fn']) { $vcard['fn'] = trim(unxmlify($author->get_email())); } if (strpos($vcard['fn'], '@') !== false) { $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@')); } $email = unxmlify($author->get_email()); if (!$profile && $author->get_link()) { $profile = trim(unxmlify($author->get_link())); } } if (!$vcard['photo']) { $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/', 'thumbnail'); if ($rawmedia && $rawmedia[0]['attribs']['']['url']) { $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']); } } if (!$vcard['photo']) { $rawtags = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') { $vcard['photo'] = $elems['link'][0]['attribs']['']['href']; } } } } } if (!$vcard['photo'] && strlen($email)) { $vcard['photo'] = avatar_img($email); } if ($poll === $profile) { $lnk = $feed->get_permalink(); } if (isset($lnk) && strlen($lnk)) { $profile = $lnk; } if (!x($vcard, 'fn')) { $vcard['fn'] = notags($feed->get_title()); } if (!x($vcard, 'fn')) { $vcard['fn'] = notags($feed->get_description()); } if (strpos($vcard['fn'], 'Twitter / ') !== false) { $vcard['fn'] = substr($vcard['fn'], strpos($vcard['fn'], '/') + 1); $vcard['fn'] = trim($vcard['fn']); } if (!x($vcard, 'nick')) { $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn']))); if (strpos($vcard['nick'], ' ')) { $vcard['nick'] = trim(substr($vcard['nick'], 0, strpos($vcard['nick'], ' '))); } } if (!$network) { $network = NETWORK_FEED; } if (!$priority) { $priority = 2; } } } if (!x($vcard, 'photo')) { $a = get_app(); $vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg'; } if (!$profile) { $profile = $url; } // No human could be associated with this link, use the URL as the contact name if ($network === NETWORK_FEED && $poll && !x($vcard, 'fn')) { $vcard['fn'] = $url; } $vcard['fn'] = notags($vcard['fn']); $vcard['nick'] = str_replace(' ', '', notags($vcard['nick'])); $result['name'] = $vcard['fn']; $result['nick'] = $vcard['nick']; $result['url'] = $profile; $result['addr'] = $addr; $result['batch'] = $batch; $result['notify'] = $notify; $result['poll'] = $poll; $result['request'] = $request; $result['confirm'] = $confirm; $result['poco'] = $poco; $result['photo'] = $vcard['photo']; $result['priority'] = $priority; $result['network'] = $network; $result['alias'] = $alias; $result['pubkey'] = $pubkey; logger('probe_url: ' . print_r($result, true), LOGGER_DEBUG); return $result; }</pre> </div> </figure> </div> <div class="example-item" id="0x7f180b277d986e215af7f5b4d0c8edde1ad2b7cfdc0ea893b861c4f3f42e5ace-66,,96,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#13</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_13" data-hash="0x7f180b277d986e215af7f5b4d0c8edde1ad2b7cfdc0ea893b861c4f3f42e5ace" data-area="66,,96,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '13')" class="rating-up btn btn-success" data-id="rating_13"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'13')" class="rating-down btn btn-danger" data-id="rating_13"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x7f180b277d986e215af7f5b4d0c8edde1ad2b7cfdc0ea893b861c4f3f42e5ace-66,,96,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x7f180b277d986e215af7f5b4d0c8edde1ad2b7cfdc0ea893b861c4f3f42e5ace&fullName=include%2Finc_front%2Fcnt22.article.inc.php&project=EDVLanger%2Fphpwcms')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2FEDVLanger%2Fphpwcms%2Fblob%2Fmaster%2Finclude%2Finc_front%2Fcnt22.article.inc.php">cnt22.article.inc.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2FEDVLanger%2Fphpwcms">EDVLanger/phpwcms</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="13"> <pre class="line-numbers language-php" data-end="96" data-start="67" data-highlight="82,84"> } else { $rss_obj->enable_cache(false); } // Remove surrounding DIV $rss_obj->remove_div(true); // Strip all HTML Tags $rss_obj->strip_htmltags(true); // Limit items if ($rssfeed["item"]) { $rss_obj->set_item_limit($rssfeed["item"]); } // Init Feed $rss_obj->init(); if ($rss_obj->data) { // check RSS image if ($rss_obj->get_image_url()) { $rss['temp_feedinfo'] = '<a href="' . ($rss_obj->get_image_link() ? $rss_obj->get_image_link() : $rss_obj->get_permalink()) . '" target="_blank">'; $rss['temp_feedinfo'] .= '<img src="' . $rss_obj->get_image_url() . '" alt="' . $rss_obj->get_image_title() . '" />'; $rss['temp_feedinfo'] .= '</a>'; $rss['template_FEEDINFO'] = render_cnt_template($rss['template_FEEDINFO'], 'IMAGE', $rss['temp_feedinfo']); } else { $rss['template_FEEDINFO'] = render_cnt_template($rss['template_FEEDINFO'], 'IMAGE', ''); } $rss['template_FEEDINFO'] = render_cnt_template($rss['template_FEEDINFO'], 'TITLE', $rss_obj->get_title()); $rss['template_FEEDINFO'] = render_cnt_template($rss['template_FEEDINFO'], 'DESCRIPTION', $rss_obj->get_description()); $c = 0; $rss['items'] = array(); foreach ($rss_obj->get_items() as $rssvalue) { // general item info $rss['items'][$c] = render_cnt_template($rss['template_ITEM'], 'LINK', $rssvalue->get_permalink()); $rss['items'][$c] = render_cnt_template($rss['items'][$c], 'TITLE', $rssvalue->get_title());</pre> </div> </figure> </div> <div class="example-item" id="0x5621c0c652a468d0d91d3a250b21bc523f5004e6f8e875dc29f6638ca6282f1d-873,,1717,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#14</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_14" data-hash="0x5621c0c652a468d0d91d3a250b21bc523f5004e6f8e875dc29f6638ca6282f1d" data-area="873,,1717,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '14')" class="rating-up btn btn-success" data-id="rating_14"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'14')" class="rating-down btn btn-danger" data-id="rating_14"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x5621c0c652a468d0d91d3a250b21bc523f5004e6f8e875dc29f6638ca6282f1d-873,,1717,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x5621c0c652a468d0d91d3a250b21bc523f5004e6f8e875dc29f6638ca6282f1d&fullName=simplepie_wordpress_2.php&project=simplepie%2Fwordpress')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fsimplepie%2Fwordpress%2Fblob%2Fmaster%2Fsimplepie_wordpress_2.php">simplepie_wordpress_2.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fsimplepie%2Fwordpress">simplepie/wordpress</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="14"> <pre class="line-numbers language-php" data-end="1717" data-start="874" data-highlight="1074">/** * The actual function that can be called on webpages. */ function SimplePieWP($feed_url, $options = null) { // Quit if the SimplePie class isn't loaded. if (!class_exists('SimplePie')) { die('<p style="font-size:16px; line-height:1.5em; background-color:#c00; color:#fff; padding:10px; border:3px solid #f00; text-align:left;"><img src="' . SIMPLEPIE_PLUGINDIR_WEB . '/images/error.png" /> There is a problem with the SimplePie Plugin for WordPress. Check your <a href="' . WP_CPANEL . '" style="color:#ff0; text-decoration:underline;">Installation Status</a> for more information.</p>'); } if (isset($locale) && !empty($locale) && $locale != 'auto') { setlocale(LC_TIME, $locale); } // Default general settings $template = get_option('simplepie_template'); $items = get_option('simplepie_items'); $items_per_feed = get_option('simplepie_items_per_feed'); $date_format = get_option('simplepie_date_format'); $enable_cache = get_option('simplepie_enable_cache'); $set_cache_location = get_option('simplepie_set_cache_location'); $set_cache_duration = get_option('simplepie_set_cache_duration'); $enable_order_by_date = get_option('simplepie_enable_order_by_date'); $set_timeout = get_option('simplepie_set_timeout'); // Default text-shortening settings $truncate_feed_title = get_option('simplepie_truncate_feed_title'); $truncate_feed_description = get_option('simplepie_truncate_feed_description'); $truncate_item_title = get_option('simplepie_truncate_item_title'); $truncate_item_description = get_option('simplepie_truncate_item_description'); // Default advanced settings $processing = get_option('simplepie_processing'); $locale = get_option('simplepie_locale'); $local_date_format = get_option('simplepie_local_date_format'); $strip_htmltags = get_option('simplepie_strip_htmltags'); $strip_attributes = get_option('simplepie_strip_attributes'); $set_max_checked_feeds = get_option('simplepie_set_max_checked_feeds'); // Overridden settings if ($options) { // Fix the template location if one was passed in. if (isset($options['template']) && !empty($options['template'])) { $options['template'] = SIMPLEPIE_PLUGINDIR . '/templates/' . strtolower(str_replace(' ', '_', $options['template'])) . '.tmpl'; } // Fix the processing location if one was passed in. if (isset($options['processing']) && !empty($options['processing'])) { $options['processing'] = SIMPLEPIE_PLUGINDIR . '/processing/' . strtolower(str_replace(' ', '_', $options['processing'])) . '.php'; } extract($options); } // Load post-processing file. if ($processing && $processing != '') { include_once $processing; } // If template doesn't exist, die. if (!file_exists($template) || !is_readable($template)) { die('<p style="font-size:16px; line-height:1.5em; background-color:#c00; color:#fff; padding:10px; border:3px solid #f00; text-align:left;"><img src="' . SIMPLEPIE_PLUGINDIR_WEB . '/images/error.png" /> The SimplePie template file is not readable by WordPress. Check the <a href="' . WP_CPANEL . '" style="color:#ff0; text-decoration:underline;">WordPress Control Panel</a> for more information.</p>'); } // Initialize SimplePie $feed = new SimplePie(); $feed->set_feed_url($feed_url); $feed->enable_cache($enable_cache); $feed->set_item_limit($items_per_feed); $feed->set_cache_location($set_cache_location); $feed->set_cache_duration($set_cache_duration); $feed->enable_order_by_date($enable_order_by_date); $feed->set_timeout($set_timeout); $feed->strip_htmltags(explode(' ', $strip_htmltags)); $feed->strip_attributes(explode(' ', $strip_attributes)); $feed->set_max_checked_feeds($set_max_checked_feeds); $feed->init(); // Load up the selected template file $handle = fopen($template, 'r'); $tmpl = fread($handle, filesize($template)); fclose($handle); /**************************************************************************************************************/ // ERRORS // I'm absolutely sure that there is a better way to do this. // Define what we're looking for $error_start_tag = '{IF_ERROR_BEGIN}'; $error_end_tag = '{IF_ERROR_END}'; $error_start_length = strlen($error_start_tag); $error_end_length = strlen($error_end_tag); // Find what we're looking for $error_start_pos = strpos($tmpl, $error_start_tag); $error_end_pos = strpos($tmpl, $error_end_tag); $error_length_pos = $error_end_pos - $error_start_pos; // Grab what we're looking for $error_string = substr($tmpl, $error_start_pos + $error_start_length, $error_length_pos - $error_start_length); $replacable_string = $error_start_tag . $error_string . $error_end_tag; if ($error_message = $feed->error()) { $tmpl = str_replace($replacable_string, $error_string, $tmpl); $tmpl = str_replace('{ERROR_MESSAGE}', SimplePie_WordPress::post_process('ERROR_MESSAGE', $error_message), $tmpl); } elseif ($feed->get_item_quantity() == 0) { $tmpl = str_replace($replacable_string, $error_string, $tmpl); $tmpl = str_replace('{ERROR_MESSAGE}', SimplePie_WordPress::post_process('ERROR_MESSAGE', 'There are no items in this feed.'), $tmpl); } else { $tmpl = str_replace($replacable_string, '', $tmpl); } /**************************************************************************************************************/ // FEED // FEED_AUTHOR_EMAIL if ($author = $feed->get_author()) { if ($email = $author->get_email()) { $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('FEED_AUTHOR_EMAIL', $email), $tmpl); } else { $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', '', $tmpl); } // FEED_AUTHOR_LINK if ($author = $feed->get_author()) { if ($link = $author->get_link()) { $tmpl = str_replace('{FEED_AUTHOR_LINK}', SimplePie_WordPress::post_process('FEED_AUTHOR_LINK', $link), $tmpl); } else { $tmpl = str_replace('{FEED_AUTHOR_LINK}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_AUTHOR_LINK}', '', $tmpl); } // FEED_AUTHOR_NAME if ($author = $feed->get_author()) { if ($name = $author->get_name()) { $tmpl = str_replace('{FEED_AUTHOR_NAME}', SimplePie_WordPress::post_process('FEED_AUTHOR_NAME', $name), $tmpl); } else { $tmpl = str_replace('{FEED_AUTHOR_NAME}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_AUTHOR_NAME}', '', $tmpl); } // FEED_CONTRIBUTOR_EMAIL if ($contributor = $feed->get_contributor()) { if ($email = $contributor->get_email()) { $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_EMAIL', $email), $tmpl); } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', '', $tmpl); } // FEED_CONTRIBUTOR_LINK if ($contributor = $feed->get_contributor()) { if ($link = $contributor->get_link()) { $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_LINK', $link), $tmpl); } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', '', $tmpl); } // FEED_CONTRIBUTOR_NAME if ($contributor = $feed->get_contributor()) { if ($name = $contributor->get_name()) { $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_NAME', $name), $tmpl); } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', '', $tmpl); } } else { $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', '', $tmpl); } // FEED_COPYRIGHT if ($copyright = $feed->get_copyright()) { $tmpl = str_replace('{FEED_COPYRIGHT}', SimplePie_WordPress::post_process('FEED_COPYRIGHT', $copyright), $tmpl); } else { $tmpl = str_replace('{FEED_COPYRIGHT}', '', $tmpl); } // FEED_DESCRIPTION if ($description = $feed->get_description()) { $tmpl = str_replace('{FEED_DESCRIPTION}', SimplePie_WordPress::post_process('FEED_DESCRIPTION', $description), $tmpl); } else { $tmpl = str_replace('{FEED_DESCRIPTION}', '', $tmpl); } // FEED_ENCODING if ($encoding = $feed->get_encoding()) { $tmpl = str_replace('{FEED_ENCODING}', SimplePie_WordPress::post_process('FEED_ENCODING', $encoding), $tmpl); } else { $tmpl = str_replace('{FEED_ENCODING}', '', $tmpl); } // FEED_FAVICON if ($favicon = $feed->get_favicon()) { $tmpl = str_replace('{FEED_FAVICON}', SimplePie_WordPress::post_process('FEED_FAVICON', $favicon), $tmpl); } else { $tmpl = str_replace('{FEED_FAVICON}', '', $tmpl); } // FEED_IMAGE_HEIGHT if ($image_height = $feed->get_image_height()) { $tmpl = str_replace('{FEED_IMAGE_HEIGHT}', SimplePie_WordPress::post_process('FEED_IMAGE_HEIGHT', $image_height), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_HEIGHT}', '', $tmpl); } // FEED_IMAGE_LINK if ($image_link = $feed->get_image_link()) { $tmpl = str_replace('{FEED_IMAGE_LINK}', SimplePie_WordPress::post_process('FEED_IMAGE_LINK', $image_link), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_LINK}', '', $tmpl); } // FEED_IMAGE_TITLE if ($image_title = $feed->get_image_title()) { $tmpl = str_replace('{FEED_IMAGE_TITLE}', SimplePie_WordPress::post_process('FEED_IMAGE_TITLE', $image_title), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_TITLE}', '', $tmpl); } // FEED_IMAGE_URL if ($image_url = $feed->get_image_url()) { $tmpl = str_replace('{FEED_IMAGE_URL}', SimplePie_WordPress::post_process('FEED_IMAGE_URL', $image_url), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_URL}', '', $tmpl); } // FEED_IMAGE_WIDTH if ($image_width = $feed->get_image_width()) { $tmpl = str_replace('{FEED_IMAGE_WIDTH}', SimplePie_WordPress::post_process('FEED_IMAGE_WIDTH', $image_width), $tmpl); } else { $tmpl = str_replace('{FEED_IMAGE_WIDTH}', '', $tmpl); } // FEED_LANGUAGE if ($language = $feed->get_language()) { $tmpl = str_replace('{FEED_LANGUAGE}', SimplePie_WordPress::post_process('FEED_LANGUAGE', $language), $tmpl); } else { $tmpl = str_replace('{FEED_LANGUAGE}', '', $tmpl); } // FEED_LATITUDE if ($latitude = $feed->get_latitude()) { $tmpl = str_replace('{FEED_LATITUDE}', SimplePie_WordPress::post_process('FEED_LATITUDE', $latitude), $tmpl); } else { $tmpl = str_replace('{FEED_LATITUDE}', '', $tmpl); } // FEED_LONGITUDE if ($longitude = $feed->get_longitude()) { $tmpl = str_replace('{FEED_LONGITUDE}', SimplePie_WordPress::post_process('FEED_LONGITUDE', $longitude), $tmpl); } else { $tmpl = str_replace('{FEED_LONGITUDE}', '', $tmpl); } // FEED_PERMALINK if ($permalink = $feed->get_permalink()) { $tmpl = str_replace('{FEED_PERMALINK}', SimplePie_WordPress::post_process('FEED_PERMALINK', $permalink), $tmpl); } else { $tmpl = str_replace('{FEED_PERMALINK}', '', $tmpl); } // FEED_TITLE if ($title = $feed->get_title()) { $tmpl = str_replace('{FEED_TITLE}', SimplePie_WordPress::post_process('FEED_TITLE', $title), $tmpl); } else { $tmpl = str_replace('{FEED_TITLE}', '', $tmpl); } // SUBSCRIBE_URL if ($subscribe_url = $feed->subscribe_url()) { $tmpl = str_replace('{SUBSCRIBE_URL}', SimplePie_WordPress::post_process('SUBSCRIBE_URL', $subscribe_url), $tmpl); } else { $tmpl = str_replace('{SUBSCRIBE_URL}', '', $tmpl); } // TRUNCATE_FEED_DESCRIPTION if ($description = $feed->get_description()) { $tmpl = str_replace('{TRUNCATE_FEED_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_FEED_DESCRIPTION', $description), $truncate_feed_description), $tmpl); } else { $tmpl = str_replace('{TRUNCATE_FEED_DESCRIPTION}', '', $tmpl); } // TRUNCATE_FEED_TITLE if ($title = $feed->get_title()) { $tmpl = str_replace('{TRUNCATE_FEED_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_FEED_TITLE', $title), $truncate_feed_title), $tmpl); } else { $tmpl = str_replace('{TRUNCATE_FEED_TITLE}', '', $tmpl); } /**************************************************************************************************************/ // ITEMS // Separate out the pre-item template $tmpl = explode('{ITEM_LOOP_BEGIN}', $tmpl); $pre_tmpl = $tmpl[0]; // Separate out the item template $tmpl = explode('{ITEM_LOOP_END}', $tmpl[1]); $item_tmpl = $tmpl[0]; // Separate out the post-item template $post_tmpl = $tmpl[1]; // Clear out the variable unset($tmpl); // Start putting the output string together. $tmpl = $pre_tmpl; // Loop through all of the items that we're supposed to. foreach ($feed->get_items(0, $items) as $item) { // Get a reference to the parent $feed object. $parent = $item->get_feed(); // Get a working copy of the item template. We don't want to edit the original. $working_item = $item_tmpl; // ITEM_CONTRIBUTOR_EMAIL if ($contributor = $item->get_contributor()) { if ($email = $contributor->get_email()) { $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', '', $working_item); } // ITEM_CONTRIBUTOR_LINK if ($contributor = $item->get_contributor()) { if ($link = $contributor->get_link()) { $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', '', $working_item); } // ITEM_CONTRIBUTOR_NAME if ($contributor = $item->get_contributor()) { if ($name = $contributor->get_name()) { $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', '', $working_item); } // ITEM_COPYRIGHT if ($copyright = $item->get_copyright()) { $working_item = str_replace('{ITEM_COPYRIGHT}', SimplePie_WordPress::post_process('ITEM_COPYRIGHT', $copyright), $working_item); } else { $working_item = str_replace('{ITEM_COPYRIGHT}', '', $working_item); } // ITEM_PARENT_AUTHOR_EMAIL if ($author = $parent->get_author()) { if ($email = $author->get_email()) { $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', '', $working_item); } // ITEM_PARENT_AUTHOR_LINK if ($author = $parent->get_author()) { if ($link = $author->get_link()) { $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', '', $working_item); } // ITEM_PARENT_AUTHOR_NAME if ($author = $parent->get_author()) { if ($name = $author->get_name()) { $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', '', $working_item); } // ITEM_PARENT_CONTRIBUTOR_EMAIL if ($contributor = $parent->get_contributor()) { if ($email = $contributor->get_email()) { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', '', $working_item); } // ITEM_PARENT_CONTRIBUTOR_LINK if ($contributor = $parent->get_contributor()) { if ($link = $contributor->get_link()) { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', '', $working_item); } // ITEM_PARENT_CONTRIBUTOR_NAME if ($contributor = $parent->get_contributor()) { if ($name = $contributor->get_name()) { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', '', $working_item); } // ITEM_AUTHOR_EMAIL if ($author = $item->get_author()) { if ($email = $author->get_email()) { $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_AUTHOR_EMAIL', $email), $working_item); } else { $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', '', $working_item); } // ITEM_AUTHOR_LINK if ($author = $item->get_author()) { if ($link = $author->get_link()) { $working_item = str_replace('{ITEM_AUTHOR_LINK}', SimplePie_WordPress::post_process('ITEM_AUTHOR_LINK', $link), $working_item); } else { $working_item = str_replace('{ITEM_AUTHOR_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_AUTHOR_LINK}', '', $working_item); } // ITEM_AUTHOR_NAME if ($author = $item->get_author()) { if ($name = $author->get_name()) { $working_item = str_replace('{ITEM_AUTHOR_NAME}', SimplePie_WordPress::post_process('ITEM_AUTHOR_NAME', $name), $working_item); } else { $working_item = str_replace('{ITEM_AUTHOR_NAME}', '', $working_item); } } else { $working_item = str_replace('{ITEM_AUTHOR_NAME}', '', $working_item); } // ITEM_CATEGORY if ($category = $item->get_category()) { if ($label = $category->get_label()) { $working_item = str_replace('{ITEM_CATEGORY}', SimplePie_WordPress::post_process('ITEM_CATEGORY', $label), $working_item); } else { $working_item = str_replace('{ITEM_CATEGORY}', '', $working_item); } } else { $working_item = str_replace('{ITEM_CATEGORY}', '', $working_item); } // ITEM_CONTENT if ($content = $item->get_content()) { $working_item = str_replace('{ITEM_CONTENT}', SimplePie_WordPress::post_process('ITEM_CONTENT', $content), $working_item); } else { $working_item = str_replace('{ITEM_CONTENT}', '', $working_item); } // ITEM_DATE if ($date = $item->get_date($date_format)) { $working_item = str_replace('{ITEM_DATE}', SimplePie_WordPress::post_process('ITEM_DATE', $date), $working_item); } else { $working_item = str_replace('{ITEM_DATE}', '', $working_item); } // ITEM_DATE_UTC if ($date = $item->get_date('U')) { $date = gmdate($date_format, $date); $working_item = str_replace('{ITEM_DATE_UTC}', SimplePie_WordPress::post_process('ITEM_DATE_UTC', $date), $working_item); } else { $working_item = str_replace('{ITEM_DATE_UTC}', '', $working_item); } // ITEM_DESCRIPTION if ($description = $item->get_description()) { $working_item = str_replace('{ITEM_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_DESCRIPTION', $description), $working_item); } else { $working_item = str_replace('{ITEM_DESCRIPTION}', '', $working_item); } // ITEM_ENCLOSURE_EMBED if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->native_embed()) { $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EMBED', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', '', $working_item); } // ITEM_ENCLOSURE_EXTENSION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_extension()) { $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EXTENSION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', '', $working_item); } // ITEM_ENCLOSURE_HANDLER if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_handler()) { $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HANDLER', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', '', $working_item); } // ITEM_ENCLOSURE_LENGTH if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_length()) { $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LENGTH', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', '', $working_item); } // ITEM_ENCLOSURE_LINK if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_link()) { $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LINK', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', '', $working_item); } // ITEM_ENCLOSURE_REAL_TYPE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_real_type()) { $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_REAL_TYPE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', '', $working_item); } // ITEM_ENCLOSURE_SIZE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_size()) { $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_SIZE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', '', $working_item); } // ITEM_ENCLOSURE_TYPE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_type()) { $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_TYPE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', '', $working_item); } // ITEM_ENCLOSURE_BITRATE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_bitrate()) { $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_BITRATE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', '', $working_item); } // ITEM_ENCLOSURE_CHANNELS if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_channels()) { $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_CHANNELS', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', '', $working_item); } // ITEM_ENCLOSURE_DESCRIPTION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_description()) { $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_DESCRIPTION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', '', $working_item); } // ITEM_ENCLOSURE_DURATION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_duration()) { $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_DURATION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', '', $working_item); } // ITEM_ENCLOSURE_EXPRESSION if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_expression()) { $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EXPRESSION', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', '', $working_item); } // ITEM_ENCLOSURE_FRAMERATE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_framerate()) { $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_FRAMERATE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', '', $working_item); } // ITEM_ENCLOSURE_HASH if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_hash()) { $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HASH', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', '', $working_item); } // ITEM_ENCLOSURE_HEIGHT if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_height()) { $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HEIGHT', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', '', $working_item); } // ITEM_ENCLOSURE_LANGUAGE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_language()) { $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LANGUAGE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', '', $working_item); } // ITEM_ENCLOSURE_MEDIUM if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_medium()) { $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_MEDIUM', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', '', $working_item); } // ITEM_ENCLOSURE_PLAYER if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_player()) { $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_PLAYER', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', '', $working_item); } // ITEM_ENCLOSURE_SAMPLINGRATE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_sampling_rate()) { $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_SAMPLINGRATE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', '', $working_item); } // ITEM_ENCLOSURE_THUMBNAIL if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_thumbnail()) { $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_THUMBNAIL', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', '', $working_item); } // ITEM_ENCLOSURE_TITLE if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_title()) { $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_TITLE', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', '', $working_item); } // ITEM_ENCLOSURE_WIDTH if ($enclosure = $item->get_enclosure()) { if ($encltemp = $enclosure->get_width()) { $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_WIDTH', $encltemp), $working_item); } else { $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', '', $working_item); } } else { $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', '', $working_item); } // ITEM_ID if ($id = $item->get_id()) { $working_item = str_replace('{ITEM_ID}', SimplePie_WordPress::post_process('ITEM_ID', $id), $working_item); } else { $working_item = str_replace('{ITEM_ID}', '', $working_item); } // ITEM_ID if ($latitude = $item->get_latitude()) { $working_item = str_replace('{ITEM_LATITUDE}', SimplePie_WordPress::post_process('ITEM_LATITUDE', $latitude), $working_item); } else { $working_item = str_replace('{ITEM_LATITUDE}', '', $working_item); } // ITEM_LOCAL_DATE if ($local_date = $item->get_local_date($local_date_format)) { $working_item = str_replace('{ITEM_LOCAL_DATE}', SimplePie_WordPress::post_process('ITEM_LOCAL_DATE', $local_date), $working_item); } else { $working_item = str_replace('{ITEM_LOCAL_DATE}', '', $working_item); } // ITEM_LOCAL_DATE_UTC if ($local_date = $item->get_date('U')) { $local_date = gmdate('U', $local_date); $local_date = strftime($local_date_format, $local_date); $working_item = str_replace('{ITEM_LOCAL_DATE_UTC}', SimplePie_WordPress::post_process('ITEM_LOCAL_DATE_UTC', $local_date), $working_item); } else { $working_item = str_replace('{ITEM_LOCAL_DATE_UTC}', '', $working_item); } // ITEM_LONGITUDE if ($longitude = $item->get_longitude()) { $working_item = str_replace('{ITEM_LONGITUDE}', SimplePie_WordPress::post_process('ITEM_LONGITUDE', $longitude), $working_item); } else { $working_item = str_replace('{ITEM_LONGITUDE}', '', $working_item); } // ITEM_PERMALINK if ($permalink = $item->get_permalink()) { $working_item = str_replace('{ITEM_PERMALINK}', SimplePie_WordPress::post_process('ITEM_PERMALINK', $permalink), $working_item); } else { $working_item = str_replace('{ITEM_PERMALINK}', '', $working_item); } // ITEM_TITLE if ($title = $item->get_title()) { $working_item = str_replace('{ITEM_TITLE}', SimplePie_WordPress::post_process('ITEM_TITLE', $title), $working_item); } else { $working_item = str_replace('{ITEM_TITLE}', '', $working_item); } // ITEM_PARENT_COPYRIGHT if ($copyright = $parent->get_copyright()) { $working_item = str_replace('{ITEM_PARENT_COPYRIGHT}', SimplePie_WordPress::post_process('ITEM_PARENT_COPYRIGHT', $copyright), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_COPYRIGHT}', '', $working_item); } // ITEM_PARENT_DESCRIPTION if ($description = $parent->get_description()) { $working_item = str_replace('{ITEM_PARENT_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_PARENT_DESCRIPTION', $description), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_DESCRIPTION}', '', $working_item); } // ITEM_PARENT_ENCODING if ($encoding = $parent->get_encoding()) { $working_item = str_replace('{ITEM_PARENT_ENCODING}', SimplePie_WordPress::post_process('ITEM_PARENT_ENCODING', $encoding), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_ENCODING}', '', $working_item); } // ITEM_PARENT_FAVICON if ($favicon = $parent->get_favicon()) { $working_item = str_replace('{ITEM_PARENT_FAVICON}', SimplePie_WordPress::post_process('ITEM_PARENT_FAVICON', $favicon), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_FAVICON}', '', $working_item); } // ITEM_PARENT_IMAGE_HEIGHT if ($image_height = $parent->get_image_height()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_HEIGHT}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_HEIGHT', $image_height), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_HEIGHT}', '', $working_item); } // ITEM_PARENT_IMAGE_LINK if ($image_link = $parent->get_image_link()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_LINK', $image_link), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_LINK}', '', $working_item); } // ITEM_PARENT_IMAGE_TITLE if ($image_title = $parent->get_image_title()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_TITLE}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_TITLE', $image_title), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_TITLE}', '', $working_item); } // ITEM_PARENT_IMAGE_URL if ($image_url = $parent->get_image_url()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_URL}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_URL', $image_url), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_URL}', '', $working_item); } // ITEM_PARENT_IMAGE_WIDTH if ($image_width = $parent->get_image_width()) { $working_item = str_replace('{ITEM_PARENT_IMAGE_WIDTH}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_WIDTH', $image_width), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_IMAGE_WIDTH}', '', $working_item); } // ITEM_PARENT_LANGUAGE if ($language = $parent->get_language()) { $working_item = str_replace('{ITEM_PARENT_LANGUAGE}', SimplePie_WordPress::post_process('ITEM_PARENT_LANGUAGE', $language), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_LANGUAGE}', '', $working_item); } // ITEM_PARENT_LATITUDE if ($latitude = $parent->get_latitude()) { $working_item = str_replace('{ITEM_PARENT_LATITUDE}', SimplePie_WordPress::post_process('ITEM_PARENT_LATITUDE', $latitude), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_LATITUDE}', '', $working_item); } // ITEM_PARENT_LONGITUDE if ($longitude = $parent->get_longitude()) { $working_item = str_replace('{ITEM_PARENT_LONGITUDE}', SimplePie_WordPress::post_process('ITEM_PARENT_LONGITUDE', $longitude), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_LONGITUDE}', '', $working_item); } // ITEM_PARENT_PERMALINK if ($permalink = $parent->get_permalink()) { $working_item = str_replace('{ITEM_PARENT_PERMALINK}', SimplePie_WordPress::post_process('ITEM_PARENT_PERMALINK', $permalink), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_PERMALINK}', '', $working_item); } // ITEM_PARENT_TITLE if ($title = $parent->get_title()) { $working_item = str_replace('{ITEM_PARENT_TITLE}', SimplePie_WordPress::post_process('ITEM_PARENT_TITLE', $title), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_TITLE}', '', $working_item); } // ITEM_PARENT_SUBSCRIBE_URL if ($subscribe_url = $parent->subscribe_url()) { $working_item = str_replace('{ITEM_PARENT_SUBSCRIBE_URL}', SimplePie_WordPress::post_process('ITEM_PARENT_SUBSCRIBE_URL', $subscribe_url), $working_item); } else { $working_item = str_replace('{ITEM_PARENT_SUBSCRIBE_URL}', '', $working_item); } // TRUNCATE_ITEM_DESCRIPTION if ($description = $item->get_description()) { $working_item = str_replace('{TRUNCATE_ITEM_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_DESCRIPTION', $description), $truncate_item_description), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_DESCRIPTION}', '', $working_item); } // TRUNCATE_ITEM_TITLE if ($title = $item->get_title()) { $working_item = str_replace('{TRUNCATE_ITEM_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_TITLE', $title), $truncate_item_title), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_TITLE}', '', $working_item); } // TRUNCATE_ITEM_PARENT_DESCRIPTION if ($description = $parent->get_description()) { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_PARENT_DESCRIPTION', $description), $truncate_feed_description), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_DESCRIPTION}', '', $working_item); } // TRUNCATE_ITEM_PARENT_TITLE if ($title = $parent->get_title()) { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_PARENT_TITLE', $title), $truncate_feed_title), $working_item); } else { $working_item = str_replace('{TRUNCATE_ITEM_PARENT_TITLE}', '', $working_item); } $tmpl .= $working_item; } /**************************************************************************************************************/ // LAST STUFF // Start by removing all line breaks and tabs. $tmpl = preg_replace('/(\\n|\\r|\\t)/i', "", $tmpl); // PLUGIN_DIR $tmpl = str_replace('{PLUGIN_DIR}', SIMPLEPIE_PLUGINDIR_WEB, $tmpl); $tmpl .= $post_tmpl; // Kill the object to prevent memory leaks. $feed->__destruct(); unset($feed); unset($encltemp); unset($working_item); // Return the data back to the page. return $tmpl; }</pre> </div> </figure> </div> <div class="example-item" id="0x47f87494d8c478a60e0573e91bb107ec562f7cb461b5da2bf1929435d5cec3e6-136,,166,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#15</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_15" data-hash="0x47f87494d8c478a60e0573e91bb107ec562f7cb461b5da2bf1929435d5cec3e6" data-area="136,,166,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '15')" class="rating-up btn btn-success" data-id="rating_15"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'15')" class="rating-down btn btn-danger" data-id="rating_15"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x47f87494d8c478a60e0573e91bb107ec562f7cb461b5da2bf1929435d5cec3e6-136,,166,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x47f87494d8c478a60e0573e91bb107ec562f7cb461b5da2bf1929435d5cec3e6&fullName=index.php&project=Niehztog%2FrssFilter')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2FNiehztog%2FrssFilter%2Fblob%2Fmaster%2Findex.php">index.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2FNiehztog%2FrssFilter">Niehztog/rssFilter</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="15"> <pre class="line-numbers language-php" data-end="166" data-start="137" data-highlight="152,155"> <category term="<?php echo $category; ?> "/> <?php } } if ($feed->get_copyright()) { ?> <rights><?php echo $feed->get_copyright(); ?> </rights> <?php } if ($feed->get_image_url()) { ?> <logo><?php echo $feed->get_image_url(); ?> </logo> <?php } ?> <updated><?php echo date("c"); ?> </updated> <?php /* WARNING: simplepie doesn't provide ANY feed-level date */ $i = 0; foreach ($feed->get_items() as $item) {</pre> </div> </figure> </div> <div class="example-item" id="0x435a97d371c361bdb3c3f5b4da97e29c64f3a3a38ee3bc7c3245487eea4922f9-81,,231,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#16</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_16" data-hash="0x435a97d371c361bdb3c3f5b4da97e29c64f3a3a38ee3bc7c3245487eea4922f9" data-area="81,,231,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '16')" class="rating-up btn btn-success" data-id="rating_16"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'16')" class="rating-down btn btn-danger" data-id="rating_16"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x435a97d371c361bdb3c3f5b4da97e29c64f3a3a38ee3bc7c3245487eea4922f9-81,,231,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x435a97d371c361bdb3c3f5b4da97e29c64f3a3a38ee3bc7c3245487eea4922f9&fullName=core%2Fcomponents%2Fspiefeed%2Fspiefeed.class.php&project=ncrossland%2Fspiefeed')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fncrossland%2Fspiefeed%2Fblob%2Fmaster%2Fcore%2Fcomponents%2Fspiefeed%2Fspiefeed.class.php">spiefeed.class.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fncrossland%2Fspiefeed">ncrossland/spiefeed</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="16"> <pre class="line-numbers language-php" data-end="231" data-start="82" data-highlight="173"> /** * Processing the parameters into placeholders * @param string $spie snippet parameters * @return array placeholders */ private function _setSimplePieModxPlaceholders($spie) { /** * @link http://github.com/simplepie/simplepie/tree/one-dot-two */ if (!file_exists($spie['simplePieClassFile'])) { return 'File ' . $spie['simplePieClassFile'] . ' does not exist.'; } include_once $spie['simplePieClassFile']; $feed = new SimplePie(); $joinKey = 0; foreach ($spie['setFeedUrl'] as $setFeedUrl) { $feed->set_cache_location($spie['setCacheLocation']); $feed->set_feed_url($setFeedUrl); if (isset($spie['setInputEncoding'])) { $feed->set_input_encoding($spie['setInputEncoding']); } if (isset($spie['setOutputEncoding'])) { $feed->set_output_encoding($spie['setOutputEncoding']); } // if no cURL, try fsockopen if (isset($spie['forceFSockopen'])) { $feed->force_fsockopen(true); } if (isset($spie['enableCache'])) $feed->enable_cache($spie['enableCache']); if (isset($spie['enableOrderByDate'])) $feed->enable_order_by_date($spie['enableOrderByDate']); if (isset($spie['setCacheDuration'])) $feed->set_cache_duration($spie['setCacheDuration']); if (!empty($spie['setFaviconHandler'])) $feed->set_favicon_handler($spie['setFaviconHandler'][0], $spie['setFaviconHandler'][1]); if (!empty($spie['setImageHandler'])) { // handler_image.php?image=67d5fa9a87bad230fb03ea68b9f71090 $feed->set_image_handler($spie['setImageHandler'][0], $spie['setImageHandler'][1]); } // disabled since these are all splitted into a single fetching // it's been used with different way, see below looping // if (isset($spie['setItemLimit'])) // $feed->set_item_limit((int) $spie['setItemLimit']); if (isset($spie['setJavascript'])) $feed->set_javascript($spie['setJavascript']); if (isset($spie['stripAttributes'])) $feed->strip_attributes(array_merge($feed->strip_attributes, $spie['stripAttributes'])); if (isset($spie['stripComments'])) $feed->strip_comments($spie['stripComments']); if (isset($spie['stripHtmlTags'])) $feed->strip_htmltags(array_merge($feed->strip_htmltags, $spie['stripHtmlTags'])); /** * Initiating the Feeding. * This always be placed AFTER all the settings above. */ if (!$feed->init()) { echo $feed->error(); return FALSE; } $countItems = count($feed->get_items()); if (1 > $countItems) { continue; } $feed->handle_content_type(); $countLimit = 0; foreach ($feed->get_items($getItemStart, $getItemEnd) as $item) { if (isset($spie['setItemLimit']) && $spie['setItemLimit'] == $countLimit) continue; $phArray[$joinKey]['favicon'] = $feed->get_favicon(); $phArray[$joinKey]['link'] = $item->get_link(); $phArray[$joinKey]['title'] = $item->get_title(); $phArray[$joinKey]['description'] = $item->get_description(); $phArray[$joinKey]['content'] = $item->get_content(); $phArray[$joinKey]['permalink'] = $item->get_permalink(); $parsedUrl = parse_url($phArray[$joinKey]['permalink']); $implodedParsedUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host']; $imageLink = $feed->get_image_link() != '' ? $feed->get_image_link() : $implodedParsedUrl; $phArray[$joinKey]['imageLink'] = $imageLink; $phArray[$joinKey]['imageTitle'] = $feed->get_image_title(); $phArray[$joinKey]['imageUrl'] = $feed->get_image_url(); $phArray[$joinKey]['imageWidth'] = $feed->get_image_width(); $phArray[$joinKey]['imageHeight'] = $feed->get_image_height(); $phArray[$joinKey]['date'] = $item->get_date($spie['dateFormat']); $phArray[$joinKey]['localDate'] = $item->get_local_date($spie['localDateFormat']); $phArray[$joinKey]['copyright'] = $item->get_copyright(); $phArray[$joinKey]['latitude'] = $feed->get_latitude(); $phArray[$joinKey]['longitude'] = $feed->get_longitude(); $phArray[$joinKey]['language'] = $feed->get_language(); $phArray[$joinKey]['encoding'] = $feed->get_encoding(); if ($item->get_authors()) { foreach ($item->get_authors() as $authorObject) { $authorName = $authorObject->get_name(); $authorLink = $authorObject->get_link(); $authorEmail = $authorObject->get_email(); } $phArray[$joinKey]['authorName'] = $authorName; $phArray[$joinKey]['authorLink'] = $authorLink; $phArray[$joinKey]['authorEmail'] = $authorEmail; } $category = $item->get_category(); if ($category) { $phArray[$joinKey]['category'] = htmlspecialchars_decode($category->get_label(), ENT_QUOTES); } $contributor = $item->get_contributor(); $phArray[$joinKey]['contributor'] = ''; if ($contributor) { $phArray[$joinKey]['contributor'] = $contributor->get_name(); } if ($feed->get_type() & SIMPLEPIE_TYPE_NONE) { $phArray[$joinKey]['getType'] = 'Unknown'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_RSS_ALL) { $phArray[$joinKey]['getType'] = 'RSS'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ATOM_ALL) { $phArray[$joinKey]['getType'] = 'Atom'; } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ALL) { $phArray[$joinKey]['getType'] = 'Supported'; } // Media from Flickr RSS stream if ($enclosure = $item->get_enclosure()) { $phArray[$joinKey]['itemImageThumbnailUrl'] = $enclosure->get_thumbnail(); $phArray[$joinKey]['itemImageWidth'] = $enclosure->get_width(); $phArray[$joinKey]['itemImageHeight'] = $enclosure->get_height(); } $countLimit++; $joinKey++; } // foreach ($feed->get_items($getItemStart, $getItemEnd) as $item) } // foreach ($spie['setFeedUrl'] as $setFeedUrl) return $this->_filterModxTags($phArray); }</pre> </div> </figure> </div> <div class="example-item" id="0x38644f5bc8d2cda61ba990acda3910575723f913fc16c8fa7dd4fe79b5fdbce3-217,,325,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#17</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_17" data-hash="0x38644f5bc8d2cda61ba990acda3910575723f913fc16c8fa7dd4fe79b5fdbce3" data-area="217,,325,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '17')" class="rating-up btn btn-success" data-id="rating_17"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'17')" class="rating-down btn btn-danger" data-id="rating_17"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x38644f5bc8d2cda61ba990acda3910575723f913fc16c8fa7dd4fe79b5fdbce3-217,,325,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x38644f5bc8d2cda61ba990acda3910575723f913fc16c8fa7dd4fe79b5fdbce3&fullName=plugins%2Ffeed_importer%2FFeeds.class.php&project=ahanjir07%2Fvivvo-dev')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fahanjir07%2Fvivvo-dev%2Fblob%2Fmaster%2Fplugins%2Ffeed_importer%2FFeeds.class.php">Feeds.class.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fahanjir07%2Fvivvo-dev">ahanjir07/vivvo-dev</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="17"> <pre class="line-numbers language-php" data-end="325" data-start="218" data-highlight="306"> /** * Imports articles from feed * * @return array Number of imported (index: 0) and updated (index: 1) articles */ public function import_articles() { require_once VIVVO_FS_INSTALL_ROOT . 'lib/simplepie/simplepie.php'; require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php'; require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php'; $sm = vivvo_lite_site::get_instance(); $db = $sm->get_db(); $post_master = new vivvo_post_master($sm); $simplepie = new SimplePie(); $simplepie->enable_cache(false); $simplepie->set_feed_url($feed_url = $this->get_feed()); $simplepie->enable_order_by_date(true); @$simplepie->init(); if ($simplepie->error()) { return array(0, 0); } $now = date('Y-m-d H:i:00', $now_ts = time()); $count_added = 0; $count_updated = 0; $imported = array(); if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE) { $auto_delete_ts = VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE * 86400; } else { $auto_delete_ts = false; } if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE) { $auto_archive_ts = VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE * 86400; } else { $auto_archive_ts = false; } foreach ($simplepie->get_items() as $item) { if (($item_datetime = $item->get_date('Y-m-d H:i:00')) != null) { $item_datetime_ts = strtotime($item_datetime); // make sure not to import articles which should be deleted or archived if ($auto_delete_ts and $now_ts - $item_datetime_ts > $auto_delete_ts or $auto_archive_ts and $now_ts - $item_datetime_ts > $auto_archive_ts) { continue; } } $guid = $item->get_item_tags('', 'guid'); $guid = $guid[0]['data']; if (!$guid and !($guid = $item->get_title() . $item->get_permalink())) { continue; // can't determine reliable unique identifier } $feed_item_id = md5($feed_url . $guid); if (in_array($feed_item_id, $imported)) { continue; // already imported this one, feed has duplicate items? } $res = $db->query('SELECT id, created FROM ' . VIVVO_DB_PREFIX . "articles WHERE feed_item_id = '{$feed_item_id}' LIMIT 1"); if (PEAR::isError($res)) { continue; } $update = false; if ($res->numRows() and $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { if (VIVVO_PLUGIN_FEED_IMPORTER_UPDATE_ARTICLES and $item_datetime != null and time($row['created']) < $item_datetime_ts) { $update = true; } else { $res->free(); continue; // timestamp not changed consider content is the same too... } } $res->free(); $imported[] = $feed_item_id; if (!($author = $this->get_author()) and !($author = $item->get_author())) { if (preg_match('/^[^:]+:\\/\\/(www\\.)?([^\\/]+)/', $item->get_permalink(), $author)) { $author = $author[2]; } else { $author = ''; } } $article = new Articles($sm, array('category_id' => $this->category_id, 'user_id' => VIVVO_PLUGIN_FEED_IMPORTER_USER_ID, 'author' => $author, 'title' => $title = $item->get_title(), 'created' => $item_datetime ? $item_datetime : $now, 'body' => $item->get_description(), 'status' => VIVVO_PLUGIN_FEED_IMPORTER_STATUS, 'sefriendly' => make_sefriendly($title), 'link' => $item->get_permalink(), 'show_comment' => VIVVO_PLUGIN_FEED_IMPORTER_SHOW_COMMENT, 'feed_item_id' => $feed_item_id)); $post_master->set_data_object($article); if ($update) { $article->set_id($row['id']); $post_master->sql_update() and $count_updated++; } elseif ($post_master->sql_insert()) { $count_added++; } } $this->set_favicon($simplepie->get_favicon()); $this->set_count($this->get_count() + $count_added); if (VIVVO_PLUGIN_FEED_IMPORTER_USE_LOGO and $this->get_category() and $image_url = $simplepie->get_image_url() and preg_replace('/_\\d+(\\.[^.]+)$/', '$1', $this->category->get_image()) != ($basename = basename($image_url))) { class_exists('HTTP_Request2') or (require VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/framework/PEAR/HTTP/Request2.php'); try { $request = new HTTP_Request2($image_url); $response = $request->send(); if ($response->getStatus() == 200) { $file_contents = $response->getBody(); $basename = $sm->get_file_manager()->random_file_name($basename); file_put_contents(VIVVO_FS_INSTALL_ROOT . VIVVO_FS_FILES_DIR . $basename, $file_contents); $this->category->set_image($basename); $post_master->set_data_object($this->category); $post_master->sql_update(); } } catch (Exception $e) { if (defined('VIVVO_CRONJOB_MODE')) { echo 'exception: ' . $e->getMessage() . PHP_EOL; } } } return array($count_added, $count_updated); }</pre> </div> </figure> </div> <div class="example-item" id="0xf557be5cd94931de20efbd57d5c76d9640228981b2f778103efed15c751ae3ba-779,,908,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#18</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_18" data-hash="0xf557be5cd94931de20efbd57d5c76d9640228981b2f778103efed15c751ae3ba" data-area="779,,908,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '18')" class="rating-up btn btn-success" data-id="rating_18"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'18')" class="rating-down btn btn-danger" data-id="rating_18"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0xf557be5cd94931de20efbd57d5c76d9640228981b2f778103efed15c751ae3ba-779,,908,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0xf557be5cd94931de20efbd57d5c76d9640228981b2f778103efed15c751ae3ba&fullName=network.php&project=bashrc%2Fhubzilla')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fbashrc%2Fhubzilla%2Fblob%2Fmaster%2Fnetwork.php">network.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fbashrc%2Fhubzilla">bashrc/hubzilla</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="18"> <pre class="line-numbers language-php" data-end="908" data-start="780" data-highlight="824">function discover_by_url($url, $arr = null) { require_once 'library/HTML5/Parser.php'; $x = scrape_feed($url); if (!$x) { if (!$arr) { return false; } $network = $arr['network'] ? $arr['network'] : 'unknown'; $name = $arr['name'] ? $arr['name'] : 'unknown'; $photo = $arr['photo'] ? $arr['photo'] : ''; $addr = $arr['addr'] ? $arr['addr'] : ''; $guid = $url; } $profile = $url; logger('scrape_feed results: ' . print_r($x, true)); if ($x['feed_atom']) { $guid = $x['feed_atom']; } if ($x['feed_rss']) { $guid = $x['feed_rss']; } if (!$guid) { return false; } // try and discover stuff from the feeed require_once 'library/simplepie/simplepie.inc'; $feed = new SimplePie(); $level = 0; $x = z_fetch_url($guid, false, $level, array('novalidate' => true)); if (!$x['success']) { logger('probe_url: feed fetch failed for ' . $poll); return false; } $xml = $x['body']; logger('probe_url: fetch feed: ' . $guid . ' returns: ' . $xml, LOGGER_DATA); logger('probe_url: scrape_feed: headers: ' . $x['header'], LOGGER_DATA); // Don't try and parse an empty string $feed->set_raw_data($xml ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>'); $feed->init(); if ($feed->error()) { logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error()); } $name = unxmlify(trim($feed->get_title())); $photo = $feed->get_image_url(); $author = $feed->get_author(); if ($author) { if (!$name) { $name = unxmlify(trim($author->get_name())); } if (!$name) { $name = trim(unxmlify($author->get_email())); if (strpos($name, '@') !== false) { $name = substr($name, 0, strpos($name, '@')); } } if (!$profile && $author->get_link()) { $profile = trim(unxmlify($author->get_link())); } if (!$photo) { $rawtags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') { $photo = $elems['link'][0]['attribs']['']['href']; } } } } else { $item = $feed->get_item(0); if ($item) { $author = $item->get_author(); if ($author) { if (!$name) { $name = trim(unxmlify($author->get_name())); if (!$name) { $name = trim(unxmlify($author->get_email())); } if (strpos($name, '@') !== false) { $name = substr($name, 0, strpos($name, '@')); } } if (!$profile && $author->get_link()) { $profile = trim(unxmlify($author->get_link())); } } if (!$photo) { $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/', 'thumbnail'); if ($rawmedia && $rawmedia[0]['attribs']['']['url']) { $photo = unxmlify($rawmedia[0]['attribs']['']['url']); } } if (!$photo) { $rawtags = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author'); if ($rawtags) { $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]; if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') { $photo = $elems['link'][0]['attribs']['']['href']; } } } } } if ($poll === $profile) { $lnk = $feed->get_permalink(); } if (isset($lnk) && strlen($lnk)) { $profile = $lnk; } if (!$network) { $network = 'rss'; } if (!$name) { $name = notags($feed->get_description()); } if (!$guid) { return false; } $r = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($guid)); if ($r) { return true; } if (!$photo) { $photo = z_root() . '/images/rss_icon.png'; } $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_pubkey, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_instance_url, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", dbesc($guid), dbesc($guid), dbesc($pubkey), dbesc($addr), dbesc($profile), dbesc($name), dbesc($network), dbesc(z_root()), dbesc(datetime_convert())); $photos = import_xchan_photo($photo, $guid); $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc($photos[3]), dbesc($guid)); return true; }</pre> </div> </figure> </div> <div class="example-item" id="0x0251200c72691375386d69757b8a1f33d0b2a078e41edab39e9330e3acdef03a-22,,227,"> <div class="bs-example"> <div> <div class="bs-example-title">示例#19</div> <div style="position: absolute;right: 15px;top: 10px;" id="rating_19" data-hash="0x0251200c72691375386d69757b8a1f33d0b2a078e41edab39e9330e3acdef03a" data-area="22,,227,"> <div class="rating-amount">0</div> <a title="将此示例标记为好" href="javascript:app.addRating(1, '19')" class="rating-up btn btn-success" data-id="rating_19"><i class="icon-button icon-thumbs-up"></i></a> <a title="将此示例标记为差" href="javascript:app.addRating(-1,'19')" class="rating-down btn btn-danger" data-id="rating_19"><i class="icon-button icon-thumbs-down"></i></a> </div> </div> <div style="display:flex;align-items: center;flex-wrap: wrap"> <div style="display: inline-block;margin-right: 10px"> <a class="btn btn-default" title="这个示例的直接链接" href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html#0x0251200c72691375386d69757b8a1f33d0b2a078e41edab39e9330e3acdef03a-22,,227,"><i class="icon-button icon-link"></i></a> <a rel="nofollow" class="btn btn-default" href="javascript:app.open('https://hotexamples.com/zh/site/file?hash=0x0251200c72691375386d69757b8a1f33d0b2a078e41edab39e9330e3acdef03a&fullName=modules%2Fhelper.php&project=johngrange%2Fwookeyholeweb')">显示文件</a> </div> <div class="example-project-info"> <nobr> <span>文件:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjohngrange%2Fwookeyholeweb%2Fblob%2Fmaster%2Fmodules%2Fhelper.php">helper.php</a> </nobr> <nobr> <span>项目:</span> <a target="_blank" rel="nofollow" href="https://hotexamples.com/zh/site/redirect?url=https%3A%2F%2Fgithub.com%2Fjohngrange%2Fwookeyholeweb">johngrange/wookeyholeweb</a> </nobr> </div> </div> </div> <figure class="highlight"> <div class="example" data-id="19"> <pre class="line-numbers language-php" data-end="227" data-start="23" data-highlight="108,109"> /** * getFeed * * @param array &$params The module options. * * @return void */ public static function getFeed(&$params) { // Global $mainframe; // Init feed array $light_rss = array(); // Get local module parameters from xml file module config settings $rssurl = $params->get('rssurl', null); $rssitems = $params->get('rssitems', 5); $rssdesc = $params->get('rssdesc', 1); $rssimage = $params->get('rssimage', 1); $rssitemtitle_words = $params->get('rssitemtitle_words', 0); $rssitemdesc = $params->get('rssitemdesc', 0); $rssitemdesc_images = $params->get('rssitemdesc_images', 1); $rssitemdesc_words = $params->get('rssitemdesc_words', 0); $rsstitle = $params->get('rsstitle', 1); $rsscache = $params->get('rsscache', 3600); $link_target = $params->get('link_target', 1); $no_follow = $params->get('no_follow', 0); $enable_tooltip = $params->get('enable_tooltip', 'yes'); $tooltip_desc_words = $params->get('t_word_count_desc', 25); $tooltip_desc_images = $params->get('tooltip_desc_images', 1); $tooltip_title_words = $params->get('t_word_count_title', 25); $add_dots = !EParameter::getComponentParam(CAUTOTWEETNG, 'donot_add_dots'); if (!$rssurl) { $light_rss['error'][] = 'Invalid feed url. Please enter a valid url in the module settings.'; // Halt if no valid feed url supplied return $light_rss; } switch ($link_target) { // Open links in current or new window case 1: $link_target = '_blank'; break; case 0: $link_target = '_self'; break; default: $link_target = '_blank'; break; } $light_rss['target'] = $link_target; if ($no_follow) { $light_rss['nofollow'] = 'rel="nofollow"'; } if (!class_exists('SimplePie')) { // Include Simple Pie processor class include_once JPATH_AUTOTWEET . '/libs/SimplePie_autoloader.php'; } // Load and build the feed array $feed = new SimplePie(); $use_sp_cache = EParameter::getComponentParam(CAUTOTWEETNG, 'use_sp_cache', true); if ($use_sp_cache && is_writable(JPATH_CACHE)) { $feed->set_cache_location(JPATH_CACHE); $feed->enable_cache(true); $cache_time = intval($rsscache); $feed->set_cache_duration($cache_time); } else { $feed->enable_cache(false); } $feed->set_feed_url($rssurl); // Process the loaded feed $feed->init(); $feed->handle_content_type(); // Store any error message if (isset($feed->error)) { $light_rss['error'][] = $feed->error; } // Start building the feed meta-info (title, desc and image) // Feed title if ($feed->get_title() && $rsstitle) { $light_rss['title']['link'] = $feed->get_link(); $light_rss['title']['title'] = $feed->get_title(); } // Feed description if ($rssdesc) { $light_rss['description'] = $feed->get_description(); } // Feed image if ($rssimage && $feed->get_image_url()) { $light_rss['image']['url'] = $feed->get_image_url(); $light_rss['image']['title'] = $feed->get_image_title(); } // End feed meta-info // Start processing feed items // If there are items in the feed if ($feed->get_item_quantity()) { // Start looping through the feed items $light_rss_item = 0; // Item counter for array indexing in the loop foreach ($feed->get_items(0, $rssitems) as $currItem) { // Item title $item_title = trim($currItem->get_title()); // Item title word limit check if ($rssitemtitle_words) { $item_titles = explode(' ', $item_title); $count = count($item_titles); if ($count > $rssitemtitle_words) { $item_title = ''; for ($i = 0; $i < $rssitemtitle_words; $i++) { $item_title .= ' ' . $item_titles[$i]; } if ($add_dots) { $item_title .= '...'; } } } // Item Title $light_rss['items'][$light_rss_item]['title'] = $item_title; $light_rss['items'][$light_rss_item]['link'] = $currItem->get_permalink(); // Item description if ($rssitemdesc) { $desc = trim($currItem->get_description()); if (!$rssitemdesc_images) { // Strip image tags $desc = preg_replace("/<img[^>]+\\>/i", "", $desc); } // Item description word limit check if ($rssitemdesc_words) { $texts = explode(' ', $desc); $count = count($texts); if ($count > $rssitemdesc_words) { $desc = ''; for ($i = 0; $i < $rssitemdesc_words; $i++) { // Build words $desc .= ' ' . $texts[$i]; } if ($add_dots) { $desc .= '...'; } } } // Item Description $light_rss['items'][$light_rss_item]['description'] = $desc; } // Tooltip text if ($enable_tooltip == 'yes') { // Tooltip item title $t_item_title = trim($currItem->get_title()); // Tooltip title word limit check if ($tooltip_title_words) { $t_item_titles = explode(' ', $t_item_title); $count = count($t_item_titles); if ($count > $tooltip_title_words) { $tooltip_title = ''; for ($i = 0; $i < $tooltip_title_words; $i++) { $tooltip_title .= ' ' . $t_item_titles[$i]; } if ($add_dots) { $tooltip_title .= '...'; } } else { $tooltip_title = $t_item_title; } } else { $tooltip_title = $t_item_title; } // Replace new line characters in tooltip title, important! $tooltip_title = preg_replace("/(\r\n|\n|\r)/", " ", $tooltip_title); // Format text for tooltip $tooltip_title = htmlspecialchars(html_entity_decode($tooltip_title), ENT_QUOTES); // Tooltip Title $light_rss['items'][$light_rss_item]['tooltip']['title'] = $tooltip_title; // Tooltip item description $text = trim($currItem->get_description()); if (!$tooltip_desc_images) { $text = preg_replace("/<img[^>]+\\>/i", "", $text); } // Tooltip desc word limit check if ($tooltip_desc_words) { $texts = explode(' ', $text); $count = count($texts); if ($count > $tooltip_desc_words) { $text = ''; for ($i = 0; $i < $tooltip_desc_words; $i++) { $text .= ' ' . $texts[$i]; } if ($add_dots) { $text .= '...'; } } } // Replace new line characters in tooltip, important! $text = preg_replace("/(\r\n|\n|\r)/", " ", $text); // Format text for tooltip $text = htmlspecialchars(html_entity_decode($text), ENT_QUOTES); // Tooltip Body $light_rss['items'][$light_rss_item]['tooltip']['description'] = $text; } else { // Blank $light_rss['items'][$light_rss_item]['tooltip'] = array(); } // Increment item counter $light_rss_item++; } } // End item quantity check if statement // Return the feed data structure for the template return $light_rss; }</pre> </div> </figure> </div> <div id="all-examples"></div> </div> </div> </div> <div class="page-side-banner hidden-xs hidden-sm hidden-md" style="width:300px"> <div id="ezoic-pub-ad-placeholder-131"> <div class="fx" style="width:300px"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- right-sidebar-fx --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3697522372581514" data-ad-slot="8968655429" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> </div> </div> </div> <footer class="footer"> <div class="container"> <div class="row"> <div class="col-md-12" style="text-align: center"> <a href="https://hotexamples.com/zh/site/trends?type=php%7Cf">热门功能</a> | <a href="https://hotexamples.com/zh/site/trends?type=php%7Cc"> 热门类 </a> | <a href="https://doc.hotexamples.com/zh/doc/map">文档</a> | <a href="/site/privacy">隐私政策</a> | <a href="https://cpp.hotexamples.com/direct-sales.html">Advertise with us</a> </div> </div> <div class="row"> <div class="col-md-12" style="text-align: center"> <a href="https://hotexamples.com/zh/">PHP</a> | <a href="https://csharp.hotexamples.com/zh/">C# (CSharp)</a> | <a href="https://java.hotexamples.com/zh/">Java</a> | <a href="https://golang.hotexamples.com/zh/">Golang</a> | <a href="https://cpp.hotexamples.com/zh/">C++ (Cpp)</a> | <a href="https://python.hotexamples.com/zh/">Python</a> | <a href="https://javascript.hotexamples.com/zh/">JavaScript</a> | <a href="https://typescript.hotexamples.com/zh/">TypeScript</a> </div> </div> <div class="row"> <div class="col-md-12" style="text-align: center"> <a href="https://hotexamples.com/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html">EN</a> | <a href="https://hotexamples.com/ru/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html">RU</a> | <a href="https://hotexamples.com/de/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html">DE</a> | <a href="https://hotexamples.com/fr/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html">FR</a> | <a href="https://hotexamples.com/es/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html">ES</a> | <a href="https://hotexamples.com/pt/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html">PT</a> | <a href="https://hotexamples.com/it/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html">IT</a> | <a href="https://hotexamples.com/jp/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html">JP</a> | <a href="https://hotexamples.com/zh/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html">ZH</a> | <a href="https://hotexamples.com/ko/examples/-/SimplePie/get_image_url/php-simplepie-get_image_url-method-examples.html">KO</a> </div> </div> <div class="row"> <div class="col-md-10 col-md-offset-1"> </div> <div class="col-md-1"> <!--LiveInternet counter--> <script type="text/javascript"><!-- document.write("<a href='//www.liveinternet.ru/click' " + "target=_blank><img src='//counter.yadro.ru/hit?t44.6;r" + escape(document.referrer) + ((typeof (screen) == "undefined") ? "" : ";s" + screen.width + "*" + screen.height + "*" + (screen.colorDepth ? screen.colorDepth : screen.pixelDepth)) + ";u" + escape(document.URL) + ";" + Math.random() + "' alt='' title='LiveInternet' " + "border='0' width='31' height='31'><\/a>"); //--></script><!--/LiveInternet--> </div> </div> </div> </footer> <script src="//ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="/assets/30dd86a6f06b64184847037c52c63e07aa3c9a26.js"></script> <script>jQuery(function ($) { jQuery('#search-form').yiiActiveForm([{"id":"searchform-lang","name":"lang","container":".field-searchform-lang","input":"#searchform-lang","enableAjaxValidation":true},{"id":"searchform-search","name":"search","container":".field-searchform-search","input":"#searchform-search","enableAjaxValidation":true,"validate":function (attribute, value, messages, deferred, $form) {yii.validation.required(value, messages, {"message":"Search cannot be blank."});}}], []); });</script></body> </html>