/**
  * adds filter to sql query
  *
  * @param	string	$type
  * @param	string	$condition
  */
 public function add_filter($type, $condition = '')
 {
     switch ($type) {
         case 'id':
         case 'article_id':
         case 'duration':
         case 'year':
             $condition = (int) $condition;
             $this->_query->add_where("{$type} = {$condition}");
             break;
         case 'minute':
         case 'hour':
         case 'dom':
         case 'month':
         case 'dow':
             $condition = ArticlesSchedule::getHexMask($condition, $type);
             $this->_query->add_where("{$type} & {$condition}");
             break;
         case 'id_in':
         case 'article_id_in':
         case 'duration_in':
         case 'year_in':
             $condition = secure_sql_in($condition);
             $type = substr($type, 0, -3);
             $this->_query->add_where("{$type} IN ({$condition})");
             break;
         case 'id_not_in':
         case 'article_id_not_in':
         case 'duration_not_in':
         case 'year_not_in':
             $condition = secure_sql_in($condition);
             $type = substr($type, 0, -7);
             $this->_query->add_where("{$type} NOT IN ({$condition})");
             break;
         case 'duration_lt':
         case 'year_lt':
             $condition = (int) $condition;
             $type = substr($type, 0, -3);
             $this->_query->add_where("{$type} < {$condition}");
             break;
         case 'duration_lte':
         case 'year_lte':
             $condition = (int) $condition;
             $type = substr($type, 0, -4);
             $this->_query->add_where("{$type} <= {$condition}");
             break;
         case 'duration_gt':
         case 'year_gt':
             $condition = (int) $condition;
             $type = substr($type, 0, -3);
             $this->_query->add_where("{$type} > {$condition}");
             break;
         case 'duration_gte':
         case 'year_gte':
             $condition = (int) $condition;
             $type = substr($type, 0, -4);
             $this->_query->add_where("{$type} >= {$condition}");
             break;
     }
 }
Example #2
0
 function add_filter($type, $condition = '')
 {
     $condition = secure_sql($condition);
     switch ($type) {
         case 'a.id':
             $condition = secure_sql_in($condition);
             $this->_query->add_where("a.id IN ({$condition})");
             break;
         case '!a.id':
             $condition = secure_sql_in($condition);
             $this->_query->add_where("a.id NOT IN ({$condition})");
             break;
         case 'a.category_id':
             $condition = secure_sql_in($condition);
             $this->_query->add_where("a.category_id IN ({$condition})");
             break;
         case '!a.category_id':
             $condition = secure_sql_in($condition);
             $this->_query->add_where("a.category_id NOT IN ({$condition})");
             break;
         case 'a.user_id':
             $condition = secure_sql_in($condition);
             $this->_query->add_where("a.user_id IN ({$condition})");
             $this->_query->add_where("a.user_domain = '" . VIVVO_USER_SOURCE . "'");
             break;
         case 'a.user_domain':
             $this->_query->add_where("a.user_domain = '{$condition}'");
             break;
         case 'a.author_exact_name':
             $this->_query->add_where("a.author = '{$condition}'");
             break;
         case 'a.author':
             $condition = escape_sql_like($condition);
             $this->_query->add_where("a.author LIKE '%{$condition}%'");
             break;
         case 'a.title':
             $condition = escape_sql_like($condition);
             $this->_query->add_where("a.title LIKE '%{$condition}%'");
             break;
         case 'a.image':
             $this->_query->add_where("a.image = '{$condition}'");
             break;
         case 'a.created_month':
             $this->_query->add_where("MONTH(a.created) = '{$condition}'");
             break;
         case 'a.created_year':
             $this->_query->add_where("YEAR(a.created) = '{$condition}'");
             break;
         case 'a.created_day':
             $this->_query->add_where("DAY(a.created) = '{$condition}'");
             break;
         case 'a.created_before':
             $current_time = date('Y-m-d H:i:00', VIVVO_START_TIME);
             $this->_query->add_where("a.created < (DATE_SUB('{$current_time}', INTERVAL {$condition}  DAY))");
             break;
         case 'a.created_after':
             $current_time = date('Y-m-d H:i:00', VIVVO_START_TIME);
             $this->_query->add_where("a.created > (DATE_SUB('{$current_time}', INTERVAL {$condition} DAY))");
             break;
         case 'a.created_filter':
             $current_time = date('Y-m-d H:i:00', VIVVO_START_TIME);
             $this->_query->add_where("a.created < '{$current_time}'");
             break;
         case 'a.body':
             $this->_query->add_where("MATCH (title,body,abstract) AGAINST ('{$condition}' IN BOOLEAN MODE)");
             break;
         case 'a.last_read':
             $this->_query->add_where("a.last_read = '{$condition}'");
             break;
         case 'a.times_read':
             $this->_query->add_where("a.times_read = '{$condition}'");
             break;
         case 'a.today_read':
             $this->_query->add_where("a.today_read = '{$condition}'");
             break;
         case 'a.status':
             $this->_query->add_where("a.status = '{$condition}'");
             break;
         case 'a.not_status':
             $this->_query->add_where("a.status != '{$condition}'");
             break;
         case 'a.status_limit':
             $this->_query->add_where('a.status > 0');
             break;
         case 'a.sefriendly':
             $this->_query->add_where("a.sefriendly = '{$condition}'");
             break;
         case 'a.link':
             $this->_query->add_where("a.link = '{$condition}'");
             break;
         case 'a.order_num':
             $this->_query->add_where("a.order_num = '{$condition}'");
             break;
         case 'a.show_poll':
             $this->_query->add_where("a.show_poll = '{$condition}'");
             break;
         case 'a.rss_feed':
             $this->_query->add_where("a.rss_feed = '{$condition}'");
             break;
         case 'a.show_comment':
             $this->_query->add_where("a.show_comment = '{$condition}'");
             break;
         case 'a.keywords':
             $this->_query->add_where("a.keywords = '{$condition}'");
             break;
         case 'a.description':
             $this->_query->add_where("a.description = '{$condition}'");
             break;
         case 'a.emailed':
             $this->_query->add_where("a.emailed = '{$condition}'");
             break;
         case 'a.vote_num':
             $this->_query->add_where("a.vote_num = '{$condition}'");
             break;
         case 'a.vote_sum':
             $this->_query->add_where("a.vote_sum = '{$condition}'");
             break;
         case 'a.abstract':
             $this->_query->add_where("a.abstract = '{$condition}'");
             break;
         case 'related':
             $this->_query->add_join(' INNER JOIN ' . VIVVO_DB_PREFIX . 'related AS r ON r.related_article_id = a.id ', 'r');
             $this->_query->add_order('r.relevance DESC');
             $this->_query->add_where('r.article_id = ' . (int) $condition);
             break;
         case 'tag':
             $condition = secure_sql_in($condition, false);
             $this->_query->add_join(' INNER JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at');
             $this->_query->add_join(' INNER JOIN ' . VIVVO_DB_PREFIX . 'tags as t ON t.id = at.tag_id ', 't');
             $this->_query->add_where("t.name IN ({$condition})");
             $this->_query->add_group_by('a.id');
             break;
         case 'tag_matches':
             $condition = escape_sql_like($condition);
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at');
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'tags as t ON t.id = at.tag_id ', 't');
             $this->_query->add_where("t.name LIKE '%{$condition}%'");
             $this->_query->add_group_by('a.id');
             break;
         case 'tag_id':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at');
             $condition = secure_sql_in($condition);
             $this->_query->add_where("at.tag_id IN ({$condition})");
             $this->_query->add_group_by('a.id');
             break;
         case 'all_tag_ids':
             is_array($condition) or $condition = explode(',', $condition);
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at');
             $value = (int) array_shift($condition);
             $this->_query->add_where("at.tag_id = {$value}");
             $this->_query->add_group_by('a.id');
             $tag_ids = array();
             foreach ($condition as $value) {
                 $tag_ids[] = (int) $value;
             }
             if (!empty($tag_ids)) {
                 $tag_ids = implode(',', $tag_ids);
                 $this->_query->add_where('a.id IN (SELECT article_id FROM ' . VIVVO_DB_PREFIX . "articles_tags WHERE tag_id IN ({$tag_ids}))");
             }
             break;
         case 'tags_group_id':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at');
             $condition = secure_sql_in($condition);
             $this->_query->add_where("at.tags_group_id IN ({$condition})");
             $this->_query->add_group_by('a.id');
             break;
         case 'user_group_id':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at');
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'group_user AS gu ON at.user_id = gu.user_id ', 'gu');
             $condition = secure_sql_in($condition);
             $this->_query->add_where("gu.group_id IN ({$condition})");
             $this->_query->add_group_by('a.id');
             break;
         case 'not_user_group_id':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at');
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'group_user AS gu ON at.user_id = gu.user_id ', 'gu');
             $condition = secure_sql_in($condition);
             $this->_query->add_where("gu.group_id NOT IN ({$condition})");
             $this->_query->add_group_by('a.id');
             break;
         case 'tags_group_name':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at ON at.article_id = a.id ', 'at');
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'tags_groups as tg ON at.tags_group_id = tg.id ', 'tg');
             $condition = explode(',', $condition);
             foreach ($condition as &$topic) {
                 $topic = "'" . secure_sql($topic) . "'";
             }
             unset($topic);
             $condition = implode(',', $condition);
             $this->_query->add_where("tg.name IN ({$condition})");
             $this->_query->add_group_by('a.id');
             break;
         case 'sc.id':
         case 'sc.duration':
         case 'sc.status':
         case 'sc.year':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc');
             $condition = (int) $condition;
             $this->_query->add_where("{$type} = {$condition}");
             break;
         case 'sc.minute':
         case 'sc.hour':
         case 'sc.dom':
         case 'sc.month':
         case 'sc.dow':
             require_once VIVVO_FS_ROOT . 'lib/vivvo/core/ArticlesSchedule.class.php';
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc');
             $condition = ArticlesSchedule::getHexMask($condition, substr($type, 3));
             $this->_query->add_where("{$type} & {$condition}");
             break;
         case 'sc.date':
             if (!is_array($condition)) {
                 $parts = explode(',', date('i,G,j,n,w,Y', $condition));
                 $condition = array('minute' => (int) $parts[0], 'hour' => $parts[1], 'dom' => $parts[2], 'month' => $parts[3], 'dow' => $parts[4] + 1, 'year' => $parts[5]);
             }
             require_once VIVVO_FS_ROOT . 'lib/vivvo/core/ArticlesSchedule.class.php';
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc');
             $condition = ArticlesSchedule::getHexMask($condition);
             foreach ($condition as $name => $value) {
                 if ($name == 'year') {
                     $value = (int) $value;
                     $this->_query->add_where("sc.year = {$value}");
                 } else {
                     $this->_query->add_where("sc.{$name} & {$value}");
                 }
             }
             break;
         case 'sc.id_in':
         case 'sc.duration_in':
         case 'sc.year_in':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc');
             $condition = secure_sql_in($condition);
             $type = substr($type, 0, -3);
             $this->_query->add_where("{$type} IN ({$condition})");
             break;
         case 'sc.id_not_in':
         case 'sc.duration_not_in':
         case 'sc.year_not_in':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc');
             $condition = secure_sql_in($condition);
             $type = substr($type, 0, -7);
             $this->_query->add_where("{$type} NOT IN ({$condition})");
             break;
         case 'sc.duration_lt':
         case 'sc.year_lt':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc');
             $condition = (int) $condition;
             $type = substr($type, 0, -3);
             $this->_query->add_where("{$type} < {$condition}");
             break;
         case 'sc.duration_lte':
         case 'sc.year_lte':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc');
             $condition = (int) $condition;
             $type = substr($type, 0, -4);
             $this->_query->add_where("{$type} <= {$condition}");
             break;
         case 'sc.duration_gt':
         case 'sc.year_lg':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc');
             $condition = (int) $condition;
             $type = substr($type, 0, -3);
             $this->_query->add_where("{$type} > {$condition}");
             break;
         case 'sc.duration_gte':
         case 'sc.year_gte':
             $this->_query->add_join(' LEFT JOIN ' . VIVVO_DB_PREFIX . 'articles_schedule AS sc ON sc.article_id = a.id ', 'sc');
             $condition = (int) $condition;
             $type = substr($type, 0, -4);
             $this->_query->add_where("{$type} >= {$condition}");
             break;
     }
 }
 /**
  * Edit article schedule
  *
  * @param	array	$schedule_params
  * @return	bool
  */
 public function edit_schedule($schedule_params)
 {
     if (!vivvo_hooks_manager::call('schedule_edit', array(&$schedule_params))) {
         return vivvo_hooks_manager::get_status();
     }
     $sm = $this->get_site_manager();
     if ($sm->user && $sm->user->can('MANAGE_SCHEDULES')) {
         $schedule_list = new ArticlesSchedule_list($sm);
         $schedule = $schedule_list->get_schedule_by_id((int) $schedule_params['id']);
         if ($schedule) {
             $new_schedule = ArticlesSchedule::createFromCronMask($schedule_params['time_mask'], (int) $schedule_params['article_id']);
             if ($new_schedule) {
                 $new_schedule->set_id($schedule->get_id());
                 $new_schedule->set_duration($schedule_params['duration']);
                 $new_schedule->sql_update();
                 return true;
             } else {
                 $this->set_error_code(2802);
             }
         } else {
             $this->set_error_code(2804);
         }
     } else {
         $this->set_error_code(2803);
     }
     return false;
 }