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); }
/** * Wordbridge entry view display method * @return void **/ function display($tpl = null) { $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); if (!$item) { $item = $menu->getItem(JRequest::getInt('Itemid')); } $params = $item->params; $this->assignRef('params', $params); $postid = JRequest::getInt('p', 0); $blogInfo = WordbridgeHelper::getBlogByName($params->get('wordbridge_blog_name')); $this->assignRef('blogTitle', $blogInfo['description']); $model = $this->getModel(); $entry = $model->getEntry($postid, $blogInfo['uuid']); $baseUrl = $item->link . '&Itemid=' . $item->id; $this->assignRef('blogLink', $baseUrl); // Determine if we'll convert links $convertLinks = $params->get('wordbridge_convert_links', 'no') == 'yes' ? true : false; $this->assignRef('convertLinks', $convertLinks); $this->assignRef('content', $entry['content']); $this->assignRef('title', $entry['title']); $this->assignRef('slug', $entry['slug']); $this->assignRef('categories', $entry['categories']); $this->assignRef('postid', $entry['postid']); $this->assignRef('date', $entry['date']); // Allow JComments to be added to blog entries $jcomments = false; $jcommentsPath = JPATH_SITE . DS . 'components' . DS . 'com_jcomments' . DS; $jcommentFile = $jcommentsPath . 'jcomments.php'; if ($params->get('wordbridge_show_jcomments') == 'yes' && file_exists($jcommentFile)) { $jbase = JPATH_SITE . DS . 'components' . DS; $jPlgSrc = $jbase . 'com_wordbridge' . DS . 'assets' . DS . 'com_wordbridge.plugin.php'; $jPlgDst = $jbase . 'com_jcomments' . DS . 'plugins' . DS . 'com_wordbridge.plugin.php'; // Check to see if the integration is installed $copyRes = true; if (!file_exists($jPlgDst) || filemtime($jPlgSrc) > filemtime($jPlgDst)) { // Copy the wordbridge plugin over to jcomments $copyRes = JFile::copy($jPlgSrc, $jPlgDst); } // Only set up JComments if the wordbridge plugin is // installed OK if ($copyRes) { require_once $jcommentFile; $jid = $item->id * 10000000 + $entry['postid']; $jcomments = JComments::showComments($jid, 'com_wordbridge', $entry['title']); } } $this->assignRef('jcomments', $jcomments); $document = JFactory::getDocument(); // Set the title to place above the blog $blog_title = $params->get('page_heading'); if (!$blog_title) { $blog_title = $document->getTitle(); } $this->assignRef('blog_title', $blog_title); // Set the page title $document->setTitle($document->getTitle() . ' - ' . $entry['title']); parent::display($tpl); }
/** * Wordbridge category view display method * @return void **/ function display($tpl = null) { $mainframe =& JFactory::getApplication(); $params =& $mainframe->getParams(); $this->assignRef('params', $params); $category_name = JRequest::getVar('c', ''); $page = JRequest::getInt('page', 1); $blogInfo = WordbridgeHelper::getBlogByName($params->get('wordbridge_blog_name')); $this->assignRef('blogTitle', $blogInfo['description']); $model =& $this->getModel(); $results =& $model->getCategoryPosts($page, $category_name, $blogInfo['uuid']); $this->assignRef('entries', $results->entries); $this->assignRef('isTag', $results->isTag); $baseUrl = JSite::getMenu()->getActive()->link . '&Itemid=' . JSite::getMenu()->getActive()->id; $this->assignRef('blogLink', $baseUrl); $viewable_name = trim(JRequest::getVar('name', '')); if (empty($viewable_name)) { $viewable_name = $category_name; } $this->assignRef('categoryName', $viewable_name); $categoryUrl = $baseUrl . '&c=' . urlencode($category_name) . '&name=' . urlencode($viewable_name) . '&view=category'; if (count($results->entries) == (int) $params->get('wordbridge_blog_entry_feed_count', 10)) { $older_link = $categoryUrl . "&page=" . ($page + 1); $this->assignRef('olderLink', $older_link); } if ($page > 1) { $newer_link = $categoryUrl . "&page=" . ($page - 1); $this->assignRef('newerLink', $newer_link); } parent::display($tpl); }
/** * Wordbridge entry view display method * @return void **/ function display($tpl = null) { $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); if (!$item) { $item = $menu->getItem(JRequest::getInt('Itemid')); } $params = $item->params; $this->assignRef('params', $params); $postid = JRequest::getInt('p', 0); $blogInfo = WordbridgeHelper::getBlogByName($params->get('wordbridge_blog_name')); $this->assignRef('blogTitle', $blogInfo['description']); $model = $this->getModel(); $entry = $model->getEntry($postid, $blogInfo['uuid']); $baseUrl = $item->link . '&Itemid=' . $item->id; $this->assignRef('blogLink', $baseUrl); $this->assignRef('content', $entry['content']); $this->assignRef('title', $entry['title']); $this->assignRef('slug', $entry['slug']); $this->assignRef('categories', $entry['categories']); $this->assignRef('postid', $entry['postid']); $this->assignRef('date', $entry['date']); $document = JFactory::getDocument(); // Set the title to place above the blog $blog_title = $params->get('page_title'); if (!$blog_title) { $blog_title = $document->getTitle(); } $this->assignRef('blog_title', $blog_title); // Set the page title $document->setTitle($document->getTitle() . ' - ' . $entry['title']); parent::display($tpl); }
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; }
/** * Wordbridge entries view display method * @return void **/ function display($tpl = null) { $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); if (!$item) { $item = $menu->getItem(JRequest::getInt('Itemid')); } $params = $item->params; $this->assignRef('params', $params); $page = JRequest::getInt('page', 1); $nocache = JRequest::getBool('nocache', false); // Get the total number of blog entries $blogInfo = WordbridgeHelper::getBlogInfo(); $this->assignRef('totalEntries', $blogInfo['count']); // Work out the maximum page to show $max_page = ceil($blogInfo['count'] / $params->get('wordbridge_blog_entry_feed_count', 10)); if ($page > $max_page) { $page = $max_page; } // Determine if we'll convert links $convertLinks = $params->get('wordbridge_convert_links', 'no') == 'yes' ? true : false; $this->assignRef('convertLinks', $convertLinks); $baseUrl = $item->link . '&Itemid=' . $item->id; $this->assignRef('blogLink', $baseUrl); if ($page < $max_page) { $older_link = $baseUrl . "&page=" . ($page + 1); $this->assignRef('olderLink', $older_link); } if ($page > 1) { $newer_link = $baseUrl . "&page=" . ($page - 1); $this->assignRef('newerLink', $newer_link); } // Load the model for the desired page $model = $this->getModel(); $model->loadEntries($page, $blogInfo, $nocache); $entries = $model->getEntries(); $this->assignRef('entries', $entries); $title = $blogInfo['description']; $this->assignRef('blogTitle', $title); $document = JFactory::getDocument(); // Set the title to place above the blog $blog_title = $params->get('page_heading'); if (!$blog_title) { $blog_title = $document->getTitle(); } $this->assignRef('blog_title', $blog_title); parent::display($tpl); }
/** * Delete all the cached entries for a blog */ function clearBlogCache($blogName) { $blogInfo = WordbridgeHelper::getBlogByName($blogName); if ($blogInfo && $blogInfo['uuid']) { $db =& JFactory::getDBO(); $query = sprintf("DELETE FROM #__com_wordbridge_cache WHERE blog_uuid = %s", $db->Quote($blogInfo['uuid'])); $db->setQuery($query); $db->query(); $query = sprintf("DELETE FROM #__com_wordbridge_posts WHERE blog_uuid = %s", $db->Quote($blogInfo['uuid'])); $db->setQuery($query); $db->query(); return true; } return false; }
/** * Wordbridge category view display method * @return void **/ function display($tpl = null) { $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); if (!$item) { $item = $menu->getItem(JRequest::getInt('Itemid')); } $params = $item->params; $this->assignRef('params', $params); $category_name = JRequest::getVar('c', ''); $page = JRequest::getInt('page', 1); $blogInfo = WordbridgeHelper::getBlogByName($params->get('wordbridge_blog_name')); $this->assignRef('blogTitle', $blogInfo['description']); $model = $this->getModel(); $results = $model->getCategoryPosts($page, $category_name, $blogInfo['uuid']); $this->assignRef('entries', $results->entries); $this->assignRef('isTag', $results->isTag); $baseUrl = $item->link . '&Itemid=' . $item->id; $this->assignRef('blogLink', $baseUrl); $viewable_name = trim(JRequest::getVar('name', '')); if (empty($viewable_name)) { $viewable_name = $category_name; } $this->assignRef('categoryName', $viewable_name); $categoryUrl = $baseUrl . '&c=' . urlencode($category_name) . '&name=' . urlencode($viewable_name) . '&view=category'; if (count($results->entries) == (int) $params->get('wordbridge_blog_entry_feed_count', 10)) { $older_link = $categoryUrl . "&page=" . ($page + 1); $this->assignRef('olderLink', $older_link); } if ($page > 1) { $newer_link = $categoryUrl . "&page=" . ($page - 1); $this->assignRef('newerLink', $newer_link); } $document = JFactory::getDocument(); // Set the title to place above the blog $blog_title = $params->get('page_title'); if (!$blog_title) { $blog_title = $document->getTitle(); } $this->assignRef('blog_title', $blog_title); parent::display($tpl); }
function getObjectTitle($id) { // Data load from database by given id $db =& JFactory::getDBO(); // Need to get the blog uuid based on the current menu item $params = false; if (version_compare(JVERSION, '1.6.0', 'lt')) { $mainframe =& JFactory::getApplication(); $params =& $mainframe->getParams(); } else { $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); if (!$item) { $item = $menu->getItem(JCommentsPlugin::getItemid('com_wordbridge')); } $params = $item->params; } require_once JPATH_SITE . DS . 'components' . DS . 'com_wordbridge' . DS . 'helpers' . DS . 'helper.php'; $blogInfo = WordbridgeHelper::getBlogByName($params->get('wordbridge_blog_name')); $db->setQuery(sprintf("SELECT title FROM #__com_wordbridge_posts WHERE blog_uuid='%s' AND post_id = %d", $db->quote($blogInfo['uuid']), $id % 10000000)); return $db->loadResult(); }
} else { echo $this->content; } } else { echo $this->content; } ?> </div> <?php if (!empty($this->categories)) { ?> <div class="wordbridge_categories"> <?php $categoryLinkList = array(); foreach ($this->categories as $category) { $slug = WordbridgeHelper::nameToSlug($category); $categoryLinkList[] = sprintf('<a href="%s" class="wordbridge_category">%s</a>', $this->blogLink . '&c=' . $slug . '&view=category' . '&name=' . urlencode($category), $this->escape($category)); } echo JText::_('COM_WORDBRIDGE_POSTED_IN') . ': <span class="wordbridge_categories">' . implode(', ', $categoryLinkList) . '</span>'; ?> </div> <?php } ?> </div> <?php if ($this->jcomments != false) { echo sprintf('<div class="wordbridge_jcomments">%s</div>', $this->jcomments); } ?> </div>
?> </th> </tr> </thead> <tbody> <?php $i = 0; if ($this->entries != null) { foreach ($this->entries as $entry) { ?> <tr class="<?php echo $i++ % 2 ? "even" : "odd"; ?> "> <td class="wordbridge_col1"><?php echo WordbridgeHelper::wordBridgeStrftime('j.m.y', $entry['date'], true); ?> </td> <td class="wordbridge_col2"><?php echo sprintf('<a href="%s">%s</a>', JRoute::_($this->blogLink . '&p=' . $entry['postid'] . '&slug=' . $entry['slug'] . '&view=entry'), $this->escape($entry['title'])); ?> </td> </tr> <?php } } ?> </tbody> </table> <?php
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; }
?> </th> </tr> </thead> <tbody> <?php $i = 0; if ($this->entries != null) { foreach ($this->entries as $entry) { ?> <tr class="<?php echo $i++ % 2 ? "even" : "odd"; ?> "> <td class="wordbridge_col1"><?php echo WordbridgeHelper::wordBridgeStrftime('%e.%m.%y', $entry['date'], true); ?> </td> <td class="wordbridge_col2"><?php echo sprintf('<a href="%s">%s</a>', JRoute::_($this->blogLink . '&p=' . $entry['postid'] . '&slug=' . $entry['slug'] . '&view=entry'), $this->escape($entry['title'])); ?> </td> </tr> <?php } } ?> </tbody> </table> <?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 { $last_post = $this->escape($blog->last_post); } ?> <span class="wordbridge_last_post"><?php echo JText::sprintf('COM_WORDBRIDGE_LAST_POST', $last_post); ?> </span><br />
/** * curl_redir_exec * Work around safe_mode restrictions on CURLOPT_FOLLOWLOCATION * Taken from http://php.net/manual/en/function.curl-setopt.php#71313 * eion at bigfoot.com */ function curl_redir_exec($ch, $curl_loops = 0) { static $curl_max_loops = 20; if ($curl_loops++ >= $curl_max_loops) { return FALSE; } curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); list($header, $data) = preg_split('/(\\r?\\n){2}/', $data, 2); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code == 301 || $http_code == 302) { $matches = array(); preg_match('/Location:(.*?)(?:\\n|$)/', $header, $matches); $url = parse_url(trim(array_pop($matches))); if (!$url) { //couldn't process the url to redirect to return $data; } $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); if (!$url['scheme']) { $url['scheme'] = $last_url['scheme']; } if (!$url['host']) { $url['host'] = $last_url['host']; } if (!$url['path']) { $url['path'] = $last_url['path']; } $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query'] ? '?' . $url['query'] : ''); curl_setopt($ch, CURLOPT_URL, $new_url); return WordbridgeHelper::curl_redir_exec($ch, $curl_loops); } else { return $data; } }