function get_articles() { $sm =& $this->_site_manager; require_once VIVVO_FS_INSTALL_ROOT . '/lib/simplepie/simplepie.php'; $feed_r = new SimplePie(); $feed_r->enable_cache(false); $feed_r->set_feed_url($this->get_feed()); $feed_r->init(); foreach ($feed_r->get_items() as $item) { $status = true; $guid = $item->get_item_tags('', 'guid'); $guid = $guid[0]['data']; if ($guid != '') { $sql = 'SELECT count( * ) as count FROM ' . VIVVO_DB_PREFIX . 'Articles WHERE feed_data = \'' . md5($guid) . '\' LIMIT 1'; $feed_data = md5($guid); } else { $sql = 'SELECT count( * ) as count FROM ' . VIVVO_DB_PREFIX . 'Articles WHERE feed_data = \'' . md5($item->get_title() . $item->get_permalink()) . '\'LIMIT 1'; $feed_data = md5($item->get_title() . $item->get_permalink()); } $res =& $sm->_db->query($sql); $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC); if ($row['count']) { $status = false; } if ($status) { require_once VIVVO_FS_INSTALL_ROOT . '/lib/vivvo/core/Articles.class.php'; require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php'; $article = new Articles($sm); if ($this->get_author() != '') { $author = $this->get_author(); } elseif ($item->get_author() != '') { $author = $item->get_author(); } else { preg_match('/^http:\\/\\/(www\\.)?([^\\/]+)/', $item->get_permalink(), $author); $author = $author[2]; } if (VIVVO_PLUGIN_FEED_IMPORTER_FRIENDLY == 1) { $sefriendly_url = strtolower(preg_replace('/[^a-zA-Z\\d\\-]/i', '_', $item->get_title())); $keywords = preg_split("/[\\s_]+/", $sefriendly_url, VIVVO_PLUGIN_FEED_IMPORTER_MAX_WORD_NUM + 1, PREG_SPLIT_NO_EMPTY); $output_string = ''; for ($i = 0; $i < VIVVO_PLUGIN_FEED_IMPORTER_MAX_WORD_NUM; $i++) { $output_string .= '_' . $keywords[$i]; } $sefriendly_url = trim($output_string, "_"); //If sefriendly exists $sql = 'SELECT count( * ) as count FROM ' . VIVVO_DB_PREFIX . 'Articles WHERE sefriendly = \'' . secure_sql($sefriendly_url) . '\' LIMIT 1'; $res =& $sm->_db->query($sql); $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC); if ($row['count']) { $sefriendly_url = ''; } } else { $sefriendly_url = ''; } $sql = 'SELECT max( order_num ) as max FROM ' . VIVVO_DB_PREFIX . 'Articles'; $res =& $sm->_db->query($sql); if ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { $order_num = $row['max'] + 1; } else { $order_num = 1; } $data = array('category_id' => $this->category_id, 'user_id' => VIVVO_PLUGIN_FEED_IMPORTER_USER_ID, 'author' => $author, 'title' => $item->get_title(), 'created' => $item->get_date('Y-m-d H:i:s'), 'body' => $item->get_description(), 'status' => VIVVO_PLUGIN_FEED_IMPORTER_STATUS, 'sefriendly' => $sefriendly_url, 'link' => $item->get_permalink(), 'order_num' => $order_num, 'feed_data' => $feed_data); $article->populate($data, true); $post_master = new vivvo_post_master($sm); $post_master->set_data_object($article); if ($post_master->sql_insert()) { $this->set_count($this->get_count() + 1); } } } $this->set_favicon($feed_r->get_favicon()); }
/** * Add new article * * @param array $in_article * @return boolean true on success or false on fail */ function add_article($in_article) { if (!$this->check_token()) { return false; } if (!vivvo_hooks_manager::call('article_add', array(&$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)) { $in_article['title'] = trim($in_article['title']); $article_list = new Articles_list(); $new_order_num = $article_list->get_max('order_num'); if ($new_order_num) { $in_article['order_num'] = $new_order_num + 1; } else { $in_article['order_num'] = 1; } 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, sefriendly, status FROM ' . VIVVO_DB_PREFIX . 'articles WHERE `sefriendly` = \'' . secure_sql($in_article['sefriendly']) . '\' GROUP BY `status`; '; $res = $sm->get_db()->query($sql); $arrData = array(); if (!PEAR::isError($res)) { $arrData = $res->fetchAll(MDB2_FETCHMODE_ASSOC); $res->free(); } // First check trashed articles, if sefriendly occupied, return error foreach ($arrData as $key => $value) { if ($value['status'] == -2) { $this->set_error_code(2037); return false; } } // If sefriendly found among Active articles foreach ($arrData as $key => $value) { if (is_array($value) && count($value) > 0 && $value['status'] > -2) { if ($source == 'sefriendly') { $this->set_error_code(2001); return false; } else { $in_article['sefriendly'] = ''; } } } unset($arrData); } if (!$sm->user->can_change_status($in_article['status'])) { $in_article['status'] = 0; } 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 { $in_article['user_id'] = $sm->user->get_id(); $in_article['author'] = $sm->user->get_name(); } $in_article['user_domain'] = VIVVO_USER_SOURCE; if (!$sm->user->is_admin()) { if (!in_array('0', $writer_restriction) && !in_array($in_article['category_id'], $writer_restriction)) { $this->set_error_code(2036); return false; } } $body = $in_article['body']; array_walk($in_article, 'array_htmlspecialchars'); $in_article['body'] = $body; $in_article['created'] = date('Y-m-d H:i:00', $in_article['created']); $article = new Articles($sm); if ($article->populate($in_article, true) === false) { $this->set_error_info($article->get_error_info()); return false; } if ($article->author == '') { $article->author = $article->get_author_name(); } $this->_post_master->set_data_object($article); if ($this->_post_master->sql_insert()) { $id = $this->_post_master->get_work_id(); $article->set_id($id); if (!vivvo_hooks_manager::call('article_add_postinsert', array(&$article))) { return vivvo_hooks_manager::get_status(); } $um = $sm->get_url_manager(); $um->set_param('ARTICLE_id', $id); $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_image($abstract_image); $this->_post_master->set_data_object($article); $this->_post_master->sql_update(); } } if ($fm->is_uploaded('ARTICLE_attachment')) { $attachment = $fm->upload('ARTICLE_attachment'); if ($attachment != false) { $article->set_document($attachment); $this->_post_master->set_data_object($article); $this->_post_master->sql_update(); } } 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) { $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']), $id); admin_log($sm->user->get_username(), 'Created article #' . $this->_post_master->get_work_id()); return true; } else { $this->set_error_code(2002); return false; } } else { $this->set_error_code(2003); return false; } } else { $this->set_error_code(2004); return false; } }