Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }