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); }
/** * 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(); }
/** * 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; }