function format_article_url1($article) { if ($article->sefriendly != '') { $href = $article->id . '-' . urlencode($article->sefriendly); } else { $title = make_sefriendly($article->title); if ($title != '') { $href = $article->id . '-' . $title; } else { $href = $article->id; } } $sm = $article->_site_manager; $cat = $sm->get_categories(); if ($cat->list[$article->category_id]) { $breadcrumbs = $cat->list[$article->category_id]->get_breadcrumb_href(); } if ($breadcrumbs) { return make_proxied_url($breadcrumbs . $href . '.html'); } return 'index.php?news=' . $article->get_id(); }
/** * Edit form * * @param integer $form_id * @param array $data * @param array $elements * @return boolean true on succes, or false on fail */ function edit($form_id, $data, $elements) { $sm = vivvo_lite_site::get_instance(); if ($sm->user and $sm->user->can('MANAGE_PLUGIN', 'form_builder')) { if (!vivvo_hooks_manager::call('form_builder_edit', array(&$form_id, &$data, &$elements))) { return vivvo_hooks_manager::get_status(); } if (empty($data['email'])) { $this->set_error_code(10714); // you must enter email return false; } $form_list = new FormBuilderForms_list(); $form = $form_list->get_form_by_id($form_id); $form_url = $form->url; if ($form !== false) { if ($data['action'] == '') { $data['action'] = 'form_builder'; } if ($data['cmd'] == '') { $data['cmd'] = 'mail'; } $data['url'] = make_sefriendly($data['url']); if (!preg_match('/^[a-z_0-9\\-]*$/', $data['url'])) { $this->set_error_code(10715); return false; } if (!preg_match('|^([^:]+)://|', $data['message_url']) && trim($data['message_url']) != '') { $data['message_url'] = 'http://' . $data['message_url']; } if ($form->populate($data, true) === false) { $this->set_error_info($form->get_error_info()); return false; } $this->_post_master->set_data_object($form); if ($this->_post_master->sql_update()) { $form_element_list = new FormBuilderFields_list(); $form_element_list->get_elements_by_form_id($form->id); $form_element_list->sql_delete_list($this->_post_master); if (is_array($elements) && !empty($elements)) { foreach ($elements as $k => $v) { $form_element = new FormBuilderFields(); $form_element->populate($v); $form_element->form_id = $form->id; $this->_post_master->set_data_object($form_element); $this->_post_master->sql_insert(); } } $um = $sm->get_url_manager(); if (!empty($form->url) && $form->url != $form_url) { $um->unregister_url($form_url); $um->register_url($form->url, 'plugins/form_builder/form_builder_url_handler.php', 'form_builder_url_handler', 'form_builder_content_handler'); } else { if (empty($form->url) && $form->url != $form_url) { $um->unregister_url($form_url); } } return true; } else { $this->set_error_code(10704); return false; } } else { $this->set_error_code(10705); return false; } } else { $this->set_error_code(10706); return false; } }
/** * Sets list of applied tags (from form) * * @param mixed $tags */ public function set_tags($article_tags) { is_array($article_tags) or $article_tags = explode(',', $article_tags); $topics = array(); $tags = array(); class_exists('tag_service') or (require VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/service/Tags.service.php'); $tag_service = new tag_service(); foreach ($article_tags as &$pair) { if (!preg_match('/^\\d+:\\d+$/', $pair)) { $name = trim(preg_replace('/(^\\[|\\]$)/', '', $pair)); if (!$name) { $pair = false; continue; } $topic_id = 0; $tag_id = $tag_service->add_tag($name, make_sefriendly($name)); } else { list($topic_id, $tag_id) = explode(':', $pair, 2); } if (!$tag_id) { $pair = false; continue; } $topics[$topic_id] = 1; $tags[$tag_id] = 1; $pair = array('tag_id' => $tag_id, 'topic_id' => $topic_id); } unset($pair); $topic_ids = secure_sql_in(array_keys($topics)); $tag_ids = secure_sql_in(array_keys($tags)); $db = vivvo_lite_site::get_instance()->get_db(); $res = $db->query('SELECT id, name FROM ' . VIVVO_DB_PREFIX . "tags WHERE id IN ({$tag_ids})"); if (PEAR::isError($res)) { return; } $tags = $res->fetchAll(MDB2_FETCHMODE_ASSOC, true); $res = $db->query('SELECT id, name FROM ' . VIVVO_DB_PREFIX . "tags_groups WHERE id IN ({$topic_ids})"); if (PEAR::isError($res)) { return; } $topics = $res->fetchAll(MDB2_FETCHMODE_ASSOC, true); $this->applied_tags = array(); foreach ($article_tags as $pair) { if ($pair and isset($tags[$pair['tag_id']]) and isset($topics[$pair['topic_id']])) { $this->applied_tags[] = array_merge($pair, array('tag_name' => $tags[$pair['tag_id']], 'topic_name' => $topics[$pair['topic_id']])); } } }
public function add_tag_names_to_topic($tag_names, $topic_id) { if (!$this->check_token()) { return false; } if (!vivvo_hooks_manager::call('tag_addTagToGroup', array(&$tag_names, &$topic_id))) { return vivvo_hooks_manager::get_status(); } if (!is_array($tag_names)) { $tag_names = array_map('trim', explode(',', $tag_names)); } foreach ($tag_names as $tag_name) { $tag_name = preg_replace('/[\\s\\n\\r]+/', ' ', $tag_name); if ($tag_name) { $tag_id = $this->add_tag($tag_name, make_sefriendly($tag_name)); if ($tag_id === false) { return false; } if ($this->add_tag_to_group($tag_id, $topic_id) === false) { return false; } } } return true; }
/** * Edit category * * @param integer $category_id * @param array $data * @return boolean true on success or false on fail */ function edit_category($category_id, $data) { if (!$this->check_token()) { return false; } if (!vivvo_hooks_manager::call('category_edit', array(&$category_id, &$data))) { return vivvo_hooks_manager::get_status(); } $sm = vivvo_lite_site::get_instance(); if ($sm->user) { if ($sm->user->is_admin()) { $category_id = (int) $category_id; if (isset($data['category_name'])) { $data['category_name'] = trim($data['category_name']); } if (empty($data['sefriendly'])) { if (isset($data['category_name']) && !empty($data['category_name'])) { $data['sefriendly'] = make_sefriendly($data['category_name']); } } else { $data['sefriendly'] = make_sefriendly($data['sefriendly']); } if (isset($data['sefriendly'])) { $sefriendly = secure_sql($data['sefriendly']); $sql = 'SELECT id FROM ' . VIVVO_DB_PREFIX . "categories WHERE sefriendly = '{$sefriendly}' AND id <> {$category_id} LIMIT 1 UNION\n\t\t\t\t\t\t\t\tSELECT id FROM " . VIVVO_DB_PREFIX . "tags_groups WHERE url = '{$sefriendly}' LIMIT 1"; if (($res = $sm->get_db()->query($sql)) && $res->numRows() > 0) { $this->set_error_code(2101); return false; } } $category_list = $sm->get_categories(); $category = $category_list->list[$category_id]; $redirect = $in_category['redirect']; array_walk($in_category, 'array_htmlspecialchars'); $in_category['redirect'] = $redirect; if (!empty($data['form']) and $data['form'] == 'link' and empty($data['redirect'])) { $this->set_error_code(12, vivvo_lang::get_instance()->get_value('LNG_DB_categories_redirect')); return false; } if (isset($category)) { if (!$category->populate($data, true)) { $this->set_error_info($category->get_error_info()); return false; } $this->_post_master->set_data_object($category); if ($this->_post_master->sql_update()) { $fm = $sm->get_file_manager(); if ($fm->is_uploaded('CATEGORY_abstact_image')) { $abstract_image = $fm->upload('CATEGORY_abstact_image'); if ($abstract_image != false) { $category->set_image($abstract_image); $this->_post_master->set_data_object($category); $this->_post_master->sql_update(); } } admin_log($sm->user->get_username(), 'Edited category #' . $category_id); return true; } else { $this->set_error_code(2110); return false; } } else { $this->set_error_code(2111); return false; } } else { $this->set_error_code(2112); return false; } } else { $this->set_error_code(2113); return false; } }
/** * Imports articles from feed * * @return array Number of imported (index: 0) and updated (index: 1) articles */ public function import_articles() { require_once VIVVO_FS_INSTALL_ROOT . 'lib/simplepie/simplepie.php'; require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php'; require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php'; $sm = vivvo_lite_site::get_instance(); $db = $sm->get_db(); $post_master = new vivvo_post_master($sm); $simplepie = new SimplePie(); $simplepie->enable_cache(false); $simplepie->set_feed_url($feed_url = $this->get_feed()); $simplepie->enable_order_by_date(true); @$simplepie->init(); if ($simplepie->error()) { return array(0, 0); } $now = date('Y-m-d H:i:00', $now_ts = time()); $count_added = 0; $count_updated = 0; $imported = array(); if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE) { $auto_delete_ts = VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE * 86400; } else { $auto_delete_ts = false; } if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE) { $auto_archive_ts = VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE * 86400; } else { $auto_archive_ts = false; } foreach ($simplepie->get_items() as $item) { if (($item_datetime = $item->get_date('Y-m-d H:i:00')) != null) { $item_datetime_ts = strtotime($item_datetime); // make sure not to import articles which should be deleted or archived if ($auto_delete_ts and $now_ts - $item_datetime_ts > $auto_delete_ts or $auto_archive_ts and $now_ts - $item_datetime_ts > $auto_archive_ts) { continue; } } $guid = $item->get_item_tags('', 'guid'); $guid = $guid[0]['data']; if (!$guid and !($guid = $item->get_title() . $item->get_permalink())) { continue; // can't determine reliable unique identifier } $feed_item_id = md5($feed_url . $guid); if (in_array($feed_item_id, $imported)) { continue; // already imported this one, feed has duplicate items? } $res = $db->query('SELECT id, created FROM ' . VIVVO_DB_PREFIX . "articles WHERE feed_item_id = '{$feed_item_id}' LIMIT 1"); if (PEAR::isError($res)) { continue; } $update = false; if ($res->numRows() and $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { if (VIVVO_PLUGIN_FEED_IMPORTER_UPDATE_ARTICLES and $item_datetime != null and time($row['created']) < $item_datetime_ts) { $update = true; } else { $res->free(); continue; // timestamp not changed consider content is the same too... } } $res->free(); $imported[] = $feed_item_id; if (!($author = $this->get_author()) and !($author = $item->get_author())) { if (preg_match('/^[^:]+:\\/\\/(www\\.)?([^\\/]+)/', $item->get_permalink(), $author)) { $author = $author[2]; } else { $author = ''; } } $article = new Articles($sm, array('category_id' => $this->category_id, 'user_id' => VIVVO_PLUGIN_FEED_IMPORTER_USER_ID, 'author' => $author, 'title' => $title = $item->get_title(), 'created' => $item_datetime ? $item_datetime : $now, 'body' => $item->get_description(), 'status' => VIVVO_PLUGIN_FEED_IMPORTER_STATUS, 'sefriendly' => make_sefriendly($title), 'link' => $item->get_permalink(), 'show_comment' => VIVVO_PLUGIN_FEED_IMPORTER_SHOW_COMMENT, 'feed_item_id' => $feed_item_id)); $post_master->set_data_object($article); if ($update) { $article->set_id($row['id']); $post_master->sql_update() and $count_updated++; } elseif ($post_master->sql_insert()) { $count_added++; } } $this->set_favicon($simplepie->get_favicon()); $this->set_count($this->get_count() + $count_added); if (VIVVO_PLUGIN_FEED_IMPORTER_USE_LOGO and $this->get_category() and $image_url = $simplepie->get_image_url() and preg_replace('/_\\d+(\\.[^.]+)$/', '$1', $this->category->get_image()) != ($basename = basename($image_url))) { class_exists('HTTP_Request2') or (require VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/framework/PEAR/HTTP/Request2.php'); try { $request = new HTTP_Request2($image_url); $response = $request->send(); if ($response->getStatus() == 200) { $file_contents = $response->getBody(); $basename = $sm->get_file_manager()->random_file_name($basename); file_put_contents(VIVVO_FS_INSTALL_ROOT . VIVVO_FS_FILES_DIR . $basename, $file_contents); $this->category->set_image($basename); $post_master->set_data_object($this->category); $post_master->sql_update(); } } catch (Exception $e) { if (defined('VIVVO_CRONJOB_MODE')) { echo 'exception: ' . $e->getMessage() . PHP_EOL; } } } return array($count_added, $count_updated); }
/** * 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; } }