function _default_assignments() { $sm = vivvo_lite_site::get_instance(); $um = $sm->get_url_manager(); $dm = $sm->get_dump_manager(); $template = $sm->get_template(); require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php'; $articles_list = new Articles_list($sm); $articles_list->reset_list_query(); $template->assign('website_articles_pending', strval($articles_list->get_count(array('search_status' => 0)))); //Check installer if (file_exists(dirname(__FILE__) . '/../installer/index.php')) { $dm->add_dump('warning', 0, vivvo_lang::get_instance()->get_value('LNG_ADMIN_INSTALLER_WARNING')); } }
/** * Edit article * * @param integer $article_id * @param array $data * @return boolean true on success or false on fail */ function edit_article($article_id, $in_article) { if (!$this->check_token()) { return false; } if (!vivvo_hooks_manager::call('article_edit', array(&$article_id, &$in_article))) { 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'); $writer_restriction = $sm->user->get_privilege_object_ids('WRITE', 'Categories'); if (!empty($writer_restriction)) { $article_list = new Articles_list(); //Try to load article with EDITOR privileges if (!empty($editor_restriction)) { $article = $article_list->get_article_by_id($article_id, $editor_restriction); } //If no article try to load article with WRITE privileges if (empty($article)) { if (!empty($editor_restriction)) { $article_list->reset_list_query(); } if ($article_list->get_user_articles_by_ids($article_id, $sm->user->get_id(), $writer_restriction)) { $article = current($article_list->list); } else { $article = false; } } if ($article !== false) { if (isset($in_article['title'])) { $in_article['title'] = trim($in_article['title']); } if (!strlen(trim($in_article['sefriendly']))) { $in_article['sefriendly'] = make_sefriendly($in_article['title']); $source = 'title'; } else { $in_article['sefriendly'] = make_sefriendly($in_article['sefriendly']); $source = 'sefriendly'; } if (!empty($in_article['sefriendly'])) { $sql = 'SELECT id FROM ' . VIVVO_DB_PREFIX . 'articles WHERE sefriendly = \'' . secure_sql($in_article['sefriendly']) . '\' AND id != ' . $article_id; $res = $sm->get_db()->query($sql); if ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { if ($source == 'sefriendly') { $this->set_error_code(2014); return false; } else { $in_article['sefriendly'] = ''; } } } if (!$sm->user->is_admin()) { if (!in_array('0', $writer_restriction) && !in_array($in_article['category_id'], $writer_restriction)) { unset($in_article['category_id']); } } if (!$sm->user->can_change_status($in_article['status'], $article->status)) { unset($in_article['status']); } if ($sm->user->is('EDITOR', 'Categories', $in_article['category_id'])) { if (!isset($in_article['user_id']) or $in_article['user_id'] == '') { $in_article['user_id'] = $sm->user->get_id(); } } else { unset($in_article['user_id']); unset($in_article['author']); } $body = $in_article['body']; array_walk($in_article, 'array_htmlspecialchars'); $in_article['body'] = $body; $in_article['last_edited'] = date('Y-m-d H:i:s'); if (isset($in_article['created'])) { $in_article['created'] = date('Y-m-d H:i:00', $in_article['created']); } if ($keep_revisions = (defined('VIVVO_REVISIONS_KEEP_COPIES') and VIVVO_REVISIONS_KEEP_COPIES)) { $old_content = array('title' => $article->get_title(), 'abstract' => $article->get_abstract(), 'body' => $article->get_body()); } if ($article->populate($in_article, true) === false) { $this->set_error_info($article->get_error_info()); return false; } $this->_post_master->set_data_object($article); if ($this->_post_master->sql_update()) { $fm = $sm->get_file_manager(); if ($fm->is_uploaded('ARTICLE_abstact_image')) { $abstract_image = $fm->upload('ARTICLE_abstact_image', '', 'jpg,jpeg,gif,png'); if ($abstract_image != false) { $article->set_id($article_id); $article->set_image($abstract_image); $this->_post_master->set_data_object($article); $this->_post_master->sql_update(); } else { $this->set_error_code($fm->get_error_code()); return false; } } if (defined('VIVVO_CUSTOM_FIELD_UPLOAD') && VIVVO_CUSTOM_FIELD_UPLOAD == 1) { $files = $fm->get_upload_keys(); if ($files) { $dbm = $sm->get_db_manager(); $fields = $dbm->get_table_fields(VIVVO_DB_PREFIX . 'articles'); if (!empty($fields)) { foreach ($files as $file) { $file_field = substr($file, 8); if (preg_match('/^ARTICLE_file_/', $file) && in_array($file_field, $fields)) { $uploaded = $fm->upload($file); if ($uploaded != false) { $id = $this->_post_master->get_work_id(); $article->set_id($id); $article->__set($file_field, $uploaded); $this->_post_master->set_data_object($article); $this->_post_master->sql_update(); } } } } } } isset($in_article['tags']) or $in_article['tags'] = ''; $this->manageTags(explode(',', $in_article['tags']), $article->get_id()); // save revision if ($keep_revisions) { class_exists('ArticlesRevisions') or (require VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/ArticlesRevisions.class.php'); ArticlesRevisions::save_revision($article->get_id(), $old_content['title'], $old_content['abstract'], $old_content['body'], $in_article['last_edited'], $sm->user->get_id()); } admin_log($sm->user->get_username(), 'Edited article #' . $article_id); return true; } else { $this->set_error_code(2015); return false; } } else { $this->set_error_code(2016); return false; } } else { $this->set_error_code(2017); return false; } } else { $this->set_error_code(2018); return false; } }