get_author() public method

Get an author for the feed
Since: 1.1
public get_author ( integer $key ) : SimplePie_Author | null
$key integer The author that you want to return. Remember that arrays begin with 0, not 1
return SimplePie_Author | null
 function rss_to_activity_streams($data)
 {
     //
     $feed = new SimplePie();
     $feed->set_raw_data($data);
     //
     unset($data);
     //
     $feed->set_stupidly_fast(true);
     $feed->init();
     $feed->handle_content_type();
     //
     $id = md5($url);
     $title = 'submit';
     $link = 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
     $activityStream = new ActivityStreamsDoc($id, $title, $link);
     //
     foreach ($feed->get_items() as $item) {
         $author = $item->get_author();
         if (!$author) {
             $author = $feed->get_author();
         }
         //
         $activityStream->entry($item->get_id(), date("r", $item->get_date()), $author ? $author->get_name() : null, $author ? $author->get_link() : null, $item->get_title(), $item->get_permalink(), $item->get_description());
     }
     return $activityStream;
 }
Example #2
0
 /**
  */
 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>'));
             }
         }
     }
 }
Example #3
0
 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);
             }
         }
     }
 }
Example #4
0
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;
}
Example #5
0
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;
}
Example #6
0
function feed_meta($xml)
{
    require_once 'library/simplepie/simplepie.inc';
    $ret = array();
    if (!strlen($xml)) {
        logger('empty input');
        return $ret;
    }
    $feed = new SimplePie();
    $feed->set_raw_data($xml);
    $feed->init();
    if ($feed->error()) {
        logger('Error parsing XML: ' . $feed->error());
        return $ret;
    }
    $ret['hubs'] = $feed->get_links('hub');
    //     logger('consume_feed: hubs: ' . print_r($hubs,true), LOGGER_DATA);
    $author = array();
    $found_author = $feed->get_author();
    if ($found_author) {
        $author['author_name'] = unxmlify($found_author->get_name());
        $author['author_link'] = unxmlify($found_author->get_link());
        $rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
        logger('rawauthor: ' . print_r($rawauthor, true));
        if ($rawauthor) {
            if ($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
                $base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
                foreach ($base as $link) {
                    if (!x($author, 'author_photo') || !$author['author_photo']) {
                        if ($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar') {
                            $author['author_photo'] = unxmlify($link['attribs']['']['href']);
                            break;
                        }
                    }
                }
            }
            if ($rawauthor[0]['child'][NAMESPACE_POCO]['displayName'][0]['data']) {
                $author['full_name'] = unxmlify($rawauthor[0]['child'][NAMESPACE_POCO]['displayName'][0]['data']);
            }
            if ($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']) {
                $author['author_uri'] = unxmlify($rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']);
            }
        }
    }
    if (substr($author['author_link'], -1, 1) == '/') {
        $author['author_link'] = substr($author['author_link'], 0, -1);
    }
    $ret['author'] = $author;
    return $ret;
}
Example #7
0
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;
}
 /**
  *
  * @param object $bookmark
  * @param object $owner
  */
 protected function do_rss($bookmark, $owner)
 {
     // no bookmark, no fun
     if (empty($bookmark) || !is_object($bookmark)) {
         return false;
     }
     // no owner means no email, so no reason to parse
     if (empty($owner) || !is_object($owner)) {
         return false;
     }
     // instead of the way too simple fetch_feed, we'll use SimplePie itself
     if (!class_exists('SimplePie')) {
         require_once ABSPATH . WPINC . '/class-simplepie.php';
     }
     $url = htmlspecialchars_decode($bookmark->link_rss);
     $last_updated = strtotime($bookmark->link_updated);
     static::debug('Fetching: ' . $url, 6);
     $feed = new SimplePie();
     $feed->set_feed_url($url);
     $feed->set_cache_duration(static::revisit_time - 10);
     $feed->set_cache_location($this->cachedir);
     $feed->force_feed(true);
     // optimization
     $feed->enable_order_by_date(true);
     $feed->remove_div(true);
     $feed->strip_comments(true);
     $feed->strip_htmltags(false);
     $feed->strip_attributes(true);
     $feed->set_image_handler(false);
     $feed->init();
     $feed->handle_content_type();
     if ($feed->error()) {
         $err = new WP_Error('simplepie-error', $feed->error());
         static::debug('Error: ' . $err->get_error_message(), 4);
         $this->failed($owner->user_email, $url, $err->get_error_message());
         return $err;
     }
     // set max items to 12
     // especially useful with first runs
     $maxitems = $feed->get_item_quantity(12);
     $feed_items = $feed->get_items(0, $maxitems);
     $feed_title = $feed->get_title();
     // set the link name from the RSS title
     if (!empty($feed_title) && $bookmark->link_name != $feed_title) {
         global $wpdb;
         $wpdb->update($wpdb->prefix . 'links', array('link_name' => $feed_title), array('link_id' => $bookmark->link_id));
     }
     // if there's a feed author, get it, we may need it if there's no entry
     // author
     $feed_author = $feed->get_author();
     $last_updated_ = 0;
     if ($maxitems > 0) {
         foreach ($feed_items as $item) {
             // U stands for Unix Time
             $date = $item->get_date('U');
             if ($date > $last_updated) {
                 $fromname = $feed_title;
                 $author = $item->get_author();
                 if ($author) {
                     $fromname = $fromname . ': ' . $author->get_name();
                 } elseif ($feed_author) {
                     $fromname = $fromname . ': ' . $feed_author->get_name();
                 }
                 // this is to set the sender mail from our own domain
                 $frommail = get_user_meta($owner->ID, 'blogroll2email_email', true);
                 if (!$frommail) {
                     $sitedomain = parse_url(get_bloginfo('url'), PHP_URL_HOST);
                     $frommail = static::schedule . '@' . $sitedomain;
                 }
                 $from = $fromname . '<' . $frommail . '>';
                 $content = $item->get_content();
                 $matches = array();
                 preg_match_all('/farm[0-9]\\.staticflickr\\.com\\/[0-9]+\\/([0-9]+_[0-9a-zA-Z]+_m\\.jpg)/s', $content, $matches);
                 if (!empty($matches[0])) {
                     foreach ($matches[0] as $to_replace) {
                         $clean = str_replace('_m.jpg', '_c.jpg', $to_replace);
                         $content = str_replace($to_replace, $clean, $content);
                     }
                     $content = preg_replace("/(width|height)=\"(.*?)\" ?/is", '', $content);
                 }
                 $content = apply_filters('blogroll2email_message', $content);
                 if ($this->send($owner->user_email, $item->get_link(), $item->get_title(), $from, $url, $item->get_content(), $date)) {
                     if ($date > $last_updated_) {
                         $last_updated_ = $date;
                     }
                 }
             }
         }
     }
     // poke the link's last update field, so we know what was the last sent
     // entry's date
     $this->update_link_date($bookmark, $last_updated_);
 }
/**
 * 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;
}
Example #10
0
 $feed->init();
 $feed->handle_content_type();
 //if error found, show error message and stop parsing
 if ($feed->error()) {
     echo "<div class=\"alert alert-danger\">";
     echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>";
     echo "<strong>Error! </strong>Unable to process feed: " . $feed_name . "<br>";
     echo $feed->error();
     echo "</div>";
 } else {
     foreach ($feed->get_items() as $item) {
         $url = $item->get_permalink();
         $subject = $item->get_title();
         $content = $item->get_description();
         $date = $item->get_date('Y-m-j H:i:s');
         if ($author = $feed->get_author()) {
             $author = $author->get_name();
         } else {
             $author = "";
         }
         echo "<tr><th>" . $feed_id . "</th><th>" . $feed_name . "</th><th>" . $date . "</th><th>";
         $database->query("SELECT * FROM t_articles WHERE (url = :url OR subject = :subject) AND feed_id = :feed_id");
         $database->bind(':url', trim($url));
         $database->bind(':subject', trim($subject));
         $database->bind(':feed_id', $feed_id);
         $results = $database->resultset();
         //debug message if article is already present in database
         if (!empty($results)) {
             echo "Article already present in database";
             //debug message if article is more than one week old
         } elseif (strtotime($date) < strtotime($previousweek)) {