Ejemplo n.º 1
0
/**
 * Resets number of today's reads (cron task function).
 *
 * @param vivvo_lite_site	$sm
 */
function auto_reset_today_read($sm)
{
    require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php';
    $article_list = new Articles_list($sm);
    $article_list->search(array(), '', 'ascending', 0, 0, false);
    require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php';
    $pm = new vivvo_post_master($sm);
    $article_list->sql_update_list($pm, array('today_read' => '0'), NULL, true);
    if (defined('VIVVO_CRONJOB_MODE')) {
        echo 'auto_reset_today_read: Finished.' . PHP_EOL;
    }
}
Ejemplo n.º 2
0
/**
 * Archive articles (cron task function).
 *
 * @param vivvo_lite_site	$sm
 */
function auto_archive($sm)
{
    require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php';
    if (VIVVO_ARTICLE_AUTO_ARCHIVE > 0) {
        $article_list = new Articles_list();
        $search_params = array('search_cid' => VIVVO_ARTICLE_AUTO_ARCHIVE_ITEMS, 'search_before_after' => 0, 'search_search_date' => VIVVO_ARTICLE_AUTO_ARCHIVE);
        $article_list->search($search_params, '', 'ascending', 0, 0, false);
        require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php';
        $article_list->sql_update_list(new vivvo_post_master(), array('status' => '-1'), null, true);
        if (defined('VIVVO_CRONJOB_MODE')) {
            echo 'auto_archive: Finished.' . PHP_EOL;
        } else {
            admin_log('(Cron task: Auto Archive)', 'Finished.');
        }
    }
}
Ejemplo n.º 3
0
 /**
  * Set fields in article
  *
  * @param	array	$articles_ids
  * @param	string	$field_name
  * @param	string	$value
  * @param	integer	$all_matching
  * @return	boolean	true on success or false on fail
  */
 function set_field($article_ids, $field_name, $value, $all_matching = 0)
 {
     if (!$this->check_token()) {
         return false;
     }
     if (!vivvo_hooks_manager::call('article_setField', array(&$article_ids, &$field_name, &$value, &$all_matching))) {
         return vivvo_hooks_manager::get_status();
     }
     $sm = vivvo_lite_site::get_instance();
     if ($sm->user) {
         $editor_restriction = $sm->user->get_privilege_object_ids('EDITOR', 'Categories');
         if (!empty($editor_restriction)) {
             $article_list = new Articles_list();
             if (!in_array('0', $editor_restriction)) {
                 if ($field_name == 'category_id' && !in_array($value, $editor_restriction)) {
                     $this->set_error_code(2012);
                     return false;
                 }
             }
             if ($field_name == 'status' && !$sm->user->can_change_status($value, '*')) {
                 $this->set_error_code(2012);
                 return false;
             }
             if ($all_matching == 1) {
                 $article_params = Articles_list::get_search_params_from_url($sm);
                 if (!is_array($article_params['search_options']['search_cid'])) {
                     $article_params['search_options']['search_cid'] = explode(',', $article_params['search_options']['search_cid']);
                 }
                 if (!in_array('0', $editor_restriction) && isset($article_params['search_options']['search_cid'])) {
                     $article_params['search_options']['search_cid'] = array_intersect($editor_restriction, $article_params['search_options']['search_cid']);
                 }
                 $article_list->search($article_params['search_options'], '', 'ascending', 0, 0, false);
                 if (!in_array($field_name, array('applyTags', 'editTags'))) {
                     if ($article_list->sql_update_list($this->_post_master, array($field_name => $value), NULL, true)) {
                         admin_log($sm->user->get_username(), 'Edited articles #' . trim(implode(',', $article_ids)));
                         return true;
                     } else {
                         $this->set_error_code(2010);
                         return false;
                     }
                 } else {
                     $res = $sm->get_db()->query('SELECT a.id ' . $article_list->_query->get_from() . ' ' . $article_list->_query->get_join() . ' ' . $article_list->_query->get_where() . ' ' . $article_list->_query->get_group_by() . ' ' . $article_list->_query->get_having());
                     if (PEAR::isError($res)) {
                         $this->set_error_code(2010);
                         return false;
                     }
                     $article_ids = $res->fetchCol();
                     $res->free();
                 }
             } elseif (!in_array($field_name, array('applyTags', 'editTags'))) {
                 $article_list->get_articles_by_ids($article_ids, $editor_restriction);
                 if ($article_list->sql_update_list($this->_post_master, array($field_name => $value))) {
                     admin_log($sm->user->get_username(), 'Edited articles #' . trim(implode(',', $article_ids)));
                     return true;
                 } else {
                     $this->set_error_code(2011);
                     return false;
                 }
             }
             if ($field_name == 'applyTags') {
                 require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/service/Tags.service.php';
                 $this->tag_service = new tag_service($sm);
                 $tags = array_map(array($this, 'parse_tags'), explode(',', $value));
                 foreach ($article_ids as $article_id) {
                     foreach ($tags as $id) {
                         $this->tag_service->add_tag_to_group($id[1], $id[0], $article_id);
                     }
                 }
                 return true;
             } elseif ($field_name == 'editTags') {
                 $tags = explode(',', $value);
                 foreach ($article_ids as $article_id) {
                     $this->manageTags($tags, $article_id);
                 }
                 return true;
             }
             $this->set_error_code(2011);
             return false;
         } else {
             $this->set_error_code(2012);
             return false;
         }
     } else {
         $this->set_error_code(2013);
         return false;
     }
 }