예제 #1
0
 /**
  * getCategoryPosts
  * Gets the blog posts from wordpress for a specific category, 
  * and stores the blog posts locally
  */
 function getCategoryPosts($page, $category_name, $blog_uuid)
 {
     // Load up the entries
     $results = $this->_loadEntriesFromWeb($page, $category_name);
     WordbridgeHelper::storeBlogEntries($results->entries, $blog_uuid);
     return $results;
 }
예제 #2
0
 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;
 }
예제 #3
0
 /**
  * _storeEntriesInDB
  * Gets the blog posts from wordpress, and stores them locally
  */
 function _storeEntriesInDB($page, $blogInfo)
 {
     $db = JFactory::getDBO();
     // First, clean the cache, by looking up all the current
     // cached entries, removing the page entries, then deleting
     // the main cache mapping
     $id_query = sprintf('SELECT DISTINCT id FROM #__com_wordbridge_cache WHERE blog_uuid = %s AND page_num = %d', $db->quote($blogInfo['uuid'], true), $page);
     $db->setQuery($id_query);
     $id_rows = $db->loadRowList();
     if (count($id_rows)) {
         $cache_ids = array();
         foreach ($id_rows as $row) {
             $cache_ids[] = $row[0];
         }
         $del_cache_query = 'DELETE FROM #__com_wordbridge_pages WHERE cache_id IN (' . implode(',', $cache_ids) . ')';
         $db->setQuery($del_cache_query);
         $db->execute();
     }
     $del_query = sprintf('DELETE FROM #__com_wordbridge_cache WHERE blog_uuid = %s AND page_num = %d', $db->quote($blogInfo['uuid'], true), $page);
     $db->setQuery($del_query);
     $db->execute();
     // Load up the entries
     $this->_loadEntriesFromWeb($page);
     // Create a cache map for this result set
     $add_query = sprintf('INSERT INTO #__com_wordbridge_cache (blog_uuid, statuses_count, last_post_id, page_num) VALUES (%s, %d, %d, %d)', $db->quote($blogInfo['uuid'], true), $blogInfo['count'], $blogInfo['last_post_id'], $page);
     $db->setQuery($add_query);
     $db->execute();
     // Grab the newly created cache map, and create page entries
     $query = sprintf('SELECT id FROM #__com_wordbridge_cache WHERE blog_uuid = %s AND statuses_count = %d AND last_post_id = %d AND page_num = %d', $db->quote($blogInfo['uuid'], true), $blogInfo['count'], $blogInfo['last_post_id'], $page);
     $db->setQuery($query);
     $cache_id = $db->loadResult();
     if ($cache_id) {
         $post_order = 1;
         WordbridgeHelper::storeBlogEntries($this->_entries, $blogInfo['uuid']);
         foreach ($this->_entries as $entry) {
             // Update the locally cached page mapping
             $page_query = sprintf('INSERT INTO #__com_wordbridge_pages VALUES (%d, %d, %d)', $cache_id, $post_order++, $entry['postid']);
             $db->setQuery($page_query);
             $db->execute();
         }
     }
 }