/**
  * If a search feed, set it up
  */
 public function postRssSearch($h)
 {
     $search = $h->cage->get->sanitizeTags('search');
     if (!$search || !$h->isActive('search')) {
         return false;
     }
     require_once PLUGINS . 'search/search.php';
     $search_plugin = new Search();
     $prepared_search = $search_plugin->prepareSearchFilter($h, $search);
     extract($prepared_search);
     // override "relevance DESC" so the RSS feed updates with the latest related terms.
     $h->vars['postRssOrderBy'] = "post_date DESC";
     $h->vars['postRssFeed']['description'] = $h->lang["sb_base_rss_stories_search"] . " " . stripslashes($search);
 }
Esempio n. 2
0
 /**
  * Prepare search filter
  */
 public function prepareSearchFilter($h, $search, $return = 'posts')
 {
     $searchFuncs = new Search();
     return $searchFuncs->prepareSearchFilter($this, $search, $return);
 }
 /**
  * Main function that calls others
  *
  * @return bool
  */
 public function settings($h)
 {
     // grab the number of pending posts:
     $sql = "SELECT COUNT(post_id) FROM " . TABLE_POSTS . " WHERE post_status = %s";
     $num_pending = $h->db->get_var($h->db->prepare($sql, 'pending'));
     if (!$num_pending) {
         $num_pending = "0";
     }
     $h->vars['num_pending'] = $num_pending;
     // clear variables:
     $h->vars['search_term'] = '';
     // Get settings
     $submit_settings = $h->getSerializedSettings('submit');
     $set_pending = $submit_settings['set_pending'];
     if ($set_pending == 'some_pending' || $set_pending == 'all_pending') {
         $h->vars['post_status_filter'] = 'pending';
     } else {
         $h->vars['post_status_filter'] = 'all';
     }
     // Get unique statuses for Filter form:
     $h->vars['statuses'] = $h->getUniqueStatuses();
     // if checkboxes
     if ($h->cage->get->getAlpha('type') == 'checkboxes' && $h->cage->get->keyExists('post')) {
         foreach ($h->cage->get->keyExists('post') as $id => $checked) {
             $h->readPost($id);
             $h->message = $h->lang["post_man_checkboxes_status_changed"];
             // default "Changed status" message
             switch ($h->cage->get->testAlnumLines('checkbox_action')) {
                 case 'new_selected':
                     $h->changePostStatus('new');
                     $h->pluginHook('post_man_status_new');
                     break;
                 case 'top_selected':
                     $h->changePostStatus('top');
                     $h->pluginHook('post_man_status_top');
                     break;
                 case 'pending_selected':
                     $h->changePostStatus('pending');
                     $h->pluginHook('post_man_status_pending');
                     break;
                 case 'bury_selected':
                     $h->changePostStatus('buried');
                     $h->pluginHook('post_man_status_buried');
                     break;
                 case 'delete_selected':
                     $h->deletePost();
                     $h->pluginHook('post_man_delete');
                     $h->message = $h->lang["post_man_checkboxes_post_deleted"];
                     break;
                 default:
                     // do nothing
                     $h->message = $h->lang["post_man_checkboxes_no_action"];
                     $h->messageType = 'red';
                     break;
             }
         }
         // Need to clear both these caches to be sure related items are updated in widgets, etc.:
         $h->clearCache('html_cache', false);
         $h->clearCache('db_cache', false);
     }
     $p = new Post();
     // if search
     $search_term = '';
     if ($h->cage->get->getAlpha('type') == 'search') {
         $search_term = $h->cage->get->sanitizeTags('search_value');
         $h->vars['search_term'] = $search_term;
         // used to refill the search box after a search
         if ($h->isActive('search')) {
             if (strlen($search_term) < 3) {
                 $h->message = $h->lang["user_man_search_too_short"];
                 $h->messageType = 'red';
             } else {
                 $s = new Search();
                 require_once PLUGINS . 'sb_base/libs/SbBaseFunctions.php';
                 $sbFuncs = new SbBaseFunctions();
                 // get count
                 $s->prepareSearchFilter($h, stripslashes(trim($h->db->escape($search_term))), 'count');
                 $filtered_search = $sbFuncs->filter($h->vars['filter'], 0, true, $h->vars['select'], $h->vars['orderby']);
                 $posts_count = $sbFuncs->getPosts($h, $filtered_search);
                 $count = $posts_count[0]->number;
                 // get query
                 $s->prepareSearchFilter($h, stripslashes(trim($h->db->escape($search_term))), 'query');
                 $prepared_filter = $sbFuncs->filter($h->vars['filter'], 0, true, $h->vars['select'], $h->vars['orderby']);
                 if (isset($prepared_filter[1])) {
                     $query = $h->db->prepare($prepared_filter);
                 } else {
                     $query = $prepared_filter[0];
                     // returns the prepared query array
                 }
             }
         } else {
             $h->message = $h->lang["post_man_need_search"];
             $h->messageType = 'red';
         }
     }
     // if filter
     $filter = '';
     if ($h->cage->get->getAlpha('type') == 'filter') {
         $filter = $h->cage->get->testAlnumLines('post_status_filter');
         $h->vars['post_status_filter'] = $filter;
         // used to refill the filter box after use
         switch ($filter) {
             case 'all':
                 $sort_clause = ' ORDER BY post_date DESC';
                 // ordered newest first for convenience
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_POSTS;
                 $count = $h->db->get_var($h->db->prepare($count_sql));
                 $sql = "SELECT * FROM " . TABLE_POSTS . $sort_clause;
                 $query = $h->db->prepare($sql);
                 break;
             case 'not_buried':
                 $where_clause = " WHERE post_status != %s";
                 $sort_clause = ' ORDER BY post_date DESC';
                 // ordered newest first for convenience
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_POSTS . $where_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, 'buried'));
                 $sql = "SELECT * FROM " . TABLE_POSTS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, 'buried');
                 break;
             case 'newest':
                 $sort_clause = ' ORDER BY post_date DESC';
                 // same as "all"
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_POSTS;
                 $count = $h->db->get_var($h->db->prepare($count_sql));
                 $sql = "SELECT * FROM " . TABLE_POSTS . $sort_clause;
                 $query = $h->db->prepare($sql);
                 break;
             case 'oldest':
                 $sort_clause = ' ORDER BY post_date ASC';
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_POSTS;
                 $count = $h->db->get_var($h->db->prepare($count_sql));
                 $sql = "SELECT * FROM " . TABLE_POSTS . $sort_clause;
                 $query = $h->db->prepare($sql);
                 break;
             default:
                 $where_clause = " WHERE post_status = %s";
                 $sort_clause = ' ORDER BY post_date DESC';
                 // ordered newest first for convenience
                 $count_sql = "SELECT count(*) AS number FROM " . TABLE_POSTS . $where_clause;
                 $count = $h->db->get_var($h->db->prepare($count_sql, $filter));
                 $sql = "SELECT * FROM " . TABLE_POSTS . $where_clause . $sort_clause;
                 $query = $h->db->prepare($sql, $filter);
                 // filter = new, top, or other post status
                 break;
         }
     }
     if (!isset($query)) {
         // default list
         if ($h->vars['post_status_filter'] == 'pending') {
             $where_clause = " WHERE post_status = %s";
             $sort_clause = ' ORDER BY post_date DESC';
             // ordered newest first for convenience
             $count_sql = "SELECT count(*) AS number FROM " . TABLE_POSTS . $where_clause;
             $count = $h->db->get_var($h->db->prepare($count_sql, 'pending'));
             $sql = "SELECT * FROM " . TABLE_POSTS . $where_clause . $sort_clause;
             $query = $h->db->prepare($sql, 'pending');
         } else {
             $sort_clause = ' ORDER BY post_date DESC';
             // ordered newest first for convenience
             $count_sql = "SELECT count(*) AS number FROM " . TABLE_POSTS;
             $count = $h->db->get_var($h->db->prepare($count_sql));
             $sql = "SELECT * FROM " . TABLE_POSTS . $sort_clause;
             $query = $h->db->prepare($sql);
         }
     }
     $pagedResults = $h->pagination($query, $count, 20, 'posts');
     if ($pagedResults) {
         $h->vars['post_man_rows'] = $this->drawRows($h, $p, $pagedResults, $filter, $search_term);
     } elseif ($h->vars['post_status_filter'] == 'pending') {
         $h->message = $h->lang['post_man_no_pending_posts'];
         $h->messageType = 'green';
     }
     // Show template:
     $h->displayTemplate('post_man_main', 'post_manager');
 }
 /**
  * Get related results from the database
  *
  * @param string $search_terms - space separated string of words
  * @param int $num_posts - the max number of posts to return
  * return array|false
  */
 public function getRelatedPosts($h, $search_terms = '', $num_posts = 10)
 {
     if (!$h->isActive('search')) {
         return false;
     }
     require_once PLUGINS . 'search/search.php';
     $search = new Search();
     $h->vars['filter']['post_archived != %s'] = 'Y';
     $h->vars['filter']['post_id != %d'] = $h->post->id;
     $prepared_search = $search->prepareSearchFilter($h, $search_terms);
     extract($prepared_search);
     // include sb_base_functions class:
     require_once PLUGINS . 'sb_base/libs/SbBaseFunctions.php';
     $funcs = new SbBaseFunctions();
     $prepared_filter = $funcs->filter($h->vars['filter'], $num_posts, false, $h->vars['select'], $h->vars['orderby']);
     $results = $funcs->getPosts($h, $prepared_filter);
     return $results;
 }