function _loadEntriesFromWeb($page = 1, $category_name) { $params =& JComponentHelper::getParams('com_wordbridge'); $blogname = $params->get('wordbridge_blog_name'); if (empty($blogname) || !function_exists('curl_init')) { return null; } $isTag = false; $ucategory = urlencode(strtolower($category_name)); $pageParam = ''; if ($page > 1) { $pageParam = '&paged=' . (int) $page; } $url = sprintf('http://%s/?feed=rss2&category_name=%s%s', WordbridgeHelper::fqdnBlogName($blogname), $ucategory, $pageParam); $tagUrl = sprintf('http://%s/?feed=rss2&tag=%s%s', WordbridgeHelper::fqdnBlogName($blogname), $ucategory, $pageParam); $blogInfo = WordbridgeHelper::getBlogByName($blogname); if ($blogInfo['uuid'] && WordbridgeHelper::isTag($blogInfo['uuid'], $category_name)) { $isTag = true; $url = $tagUrl; } $results = WordbridgeHelper::getEntriesFromUrl($url); if (!$isTag && !count($results) && $page <= 1) { if ($blogInfo['uuid']) { WordbridgeHelper::addTag($blogInfo['uuid'], $category_name); } $isTag = true; $results = WordbridgeHelper::getEntriesFromUrl($tagUrl); } return (object) array('isTag' => $isTag, 'entries' => $results); }
function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { // Need to look up all the menu items that are linked to blogs $results = array(); $text = trim($text); if (empty($text)) { return $results; } if (is_array($areas)) { if (count(array_intersect($areas, array_keys($this->onContentSearchAreas()))) == 0) { return array(); } } // We want to keep an eye on any blogs we've seen before, as // they may be linked in as multiple menus $seenBlogs = array(); $menuIDs = WordbridgeHelper::getWordbridgeMenuIDs(); $app = JFactory::getApplication(); $menu = $app->getMenu(); foreach ($menuIDs as $itemid) { $params = $menu->getParams($itemid); $blog_name = $params->get('wordbridge_blog_name'); if (!$params || $params->get('wordbridge_searchable') == 'no' || empty($blog_name)) { continue; } if (array_key_exists($blog_name, $seenBlogs)) { continue; } $seenBlogs[$blog_name] = 1; // Create a curl request for the search $blogInfo = WordbridgeHelper::getBlogInfo($blog_name, true); if (!$blogInfo) { continue; } $url = sprintf('http://%s/?s=%s&feed=rss2', WordbridgeHelper::fqdnBlogName($blog_name), urlencode($text)); $entries = WordbridgeHelper::getEntriesFromUrl($url); WordbridgeHelper::storeBlogEntries($entries, $blogInfo['uuid']); foreach ($entries as $entry) { $results[] = (object) array('href' => sprintf('index.php?option=com_wordbridge&Itemid=%d&view=entry&p=%d&slug=%s', $itemid, $entry['postid'], urlencode($entry['slug'])), 'title' => $entry['title'], 'section' => JText::_('PLG_SEARCH_WORDBRIDGE_AREA'), 'created' => $entry['date'], 'text' => strip_tags($entry['content'])); } } // Results really should be sorted switch ($ordering) { case 'oldest': usort($results, array('plgSearchWordbridge', '_sortByOldest')); break; case 'alpha': usort($results, array('plgSearchWordbridge', '_sortByName')); break; case 'newest': default: usort($results, array('plgSearchWordbridge', '_sortByNewest')); break; } return $results; }
</h2> <?php if (count($this->stats)) { ?> <p> <?php echo JText::_('COM_WORDBRIDGE_BRIDGE_MSG'); ?> </p> <?php foreach ($this->stats as $blog) { ?> <div> <?php echo sprintf('<h3><a href="http://%s/" target="_blank">%s</a></h3>', $this->escape(WordbridgeHelper::fqdnBlogName($blog->blog_name)), $this->escape(WordbridgeHelper::fqdnBlogName($blog->blog_name))); ?> <blockquote id="wordbridge_blog_<?php echo $blog->blog_name; ?> "> <span class="wordbridge_updated"><?php echo JText::sprintf('COM_WORDBRIDGE_LAST_UPDATED', $blog->updated == null ? JText::_('COM_WORDBRIDGE_NEVER') : WordbridgeHelper::wordBridgeStrftime('%c', $blog->updated)); ?> </span><br /> <?php // Truncate the last post value, so it doesn't swamp the page $last_post = ''; if (strlen($blog->last_post) > 51) { $last_post = $this->escape(substr($blog->last_post, 0, 50)) . '…'; } else {
function _loadEntriesFromWeb($page = 1) { $app = JFactory::getApplication(); $params = $app->getParams(); $blogname = $params->get('wordbridge_blog_name'); if (empty($blogname) || !function_exists('curl_init')) { return false; } $url = WordbridgeHelper::fqdnBlogName($blogname); if (!preg_match("/^https?:\\/\\/.+/", $url)) { $url = sprintf('http://%s', $url); } $url = sprintf('%s/?feed=rss2&paged=%d', $url, (int) $page); $this->_entries = WordbridgeHelper::getEntriesFromUrl($url); return true; }
/** * getTotalBlogPosts * @return int the total number of blog posts for the blog */ function getBlogInfo($blogname = null, $useStored = false) { $info = array('count' => 0, 'description' => '', 'last_post_id' => 0, 'updated' => 0, 'last_post' => '', 'name' => '', 'uuid' => '', 'id' => ''); if ($blogname == null) { $params =& JComponentHelper::getParams('com_wordbridge'); $blogname = trim($params->get('wordbridge_blog_name')); } if (empty($blogname) || !function_exists('curl_init')) { return $info; } $info['name'] = $blogname; $stored_blog = WordbridgeHelper::getBlogByName($blogname); if ($stored_blog && $useStored) { return $stored_blog; } // Keep the uuid constant, or create a new one if ($stored_blog) { $info['uuid'] = $stored_blog['uuid']; } else { $info['uuid'] = uniqid(); } // Only use the twitter API for blogs hosted at wordpress.com $fqdn = WordbridgeHelper::fqdnBlogName($blogname); if (substr($fqdn, -14) == '.wordpress.com') { $url = sprintf('http://twitter-api.wordpress.com/users/show.xml?screen_name=%s', urlencode($fqdn)); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); $xml = WordbridgeHelper::curl_redir_exec($curl); curl_close($curl); if (empty($xml)) { return $info; } $doc = new DOMDocument(); $doc->loadXML($xml); $info['count'] = $doc->getElementsByTagName('statuses_count')->item(0)->textContent; $info['description'] = $doc->getElementsByTagName('description')->item(0)->textContent; $info['id'] = $doc->getElementsByTagName('id')->item(0)->textContent; // Get the last post information, removing the blog ID that // comes out when using the twitter API $info['last_post_id'] = $doc->getElementsByTagName('status')->item(0)->getElementsByTagName('id')->item(0)->textContent; $info['last_post_id'] = (int) substr($info['last_post_id'], strlen($info['id'])); $info['last_post'] = $doc->getElementsByTagName('status')->item(0)->getElementsByTagName('text')->item(0)->textContent; } else { if (preg_match("/^https?:\\/\\/.+/", $fqdn)) { $url = sprintf('%s/?feed=wordbridge', $fqdn); } else { $url = sprintf('http://%s/?feed=wordbridge', $fqdn); } $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); $xml = WordbridgeHelper::curl_redir_exec($curl); curl_close($curl); #echo htmlspecialchars(print_r($xml, 1)); if (empty($xml)) { return $info; } $doc = new DOMDocument(); $doc->loadXML($xml); $info['count'] = $doc->getElementsByTagName('count')->item(0)->textContent; $info['description'] = $doc->getElementsByTagName('description')->item(0)->textContent; $info['id'] = $doc->getElementsByTagName('id')->item(0)->textContent; // Get the last post information $info['last_post_id'] = $doc->getElementsByTagName('last_post_id')->item(0)->textContent; $info['last_post'] = $doc->getElementsByTagName('last_post')->item(0)->textContent; } // Update the stored blog basic details if need be if (!empty($info['description'])) { if ($stored_blog) { if ($stored_blog['description'] != $info['description'] || $stored_blog['name'] != $blogname || $stored_blog['last_post'] != $info['last_post']) { WordbridgeHelper::storeBlog($info['id'], $info['uuid'], $blogname, $info['description'], $info['last_post']); } } else { // Store the blog data locally WordbridgeHelper::storeBlog($info['id'], $info['uuid'], $blogname, $info['description'], $info['last_post']); } } return $info; }