コード例 #1
0
 /**
  * Set configuration data
  *
  * @param string $name		Variable name
  * @param string $property	Variable property name
  * @param string $value		Variable value
  * @param string $module	Module name
  * @param string $reg_exp	Variable value restriction
  * @param string $doamin_id	Doamin restriction
  *
  * @return boolean True on success, false on fail
  */
 function set_conf($name, $property = '', $value, $module = '', $reg_exp = '', $domain_id = 1)
 {
     require_once VIVVO_FS_FRAMEWORK . 'vivvo_preference.php';
     if (!$this->_post_master) {
         $this->set__post_master();
     }
     $config_list = new preferences_list();
     $conf = $config_list->get_preference_by_all_variable($name, '', '', '');
     if ($conf) {
         if ($property != '') {
             $conf->set_variable_property($property);
         }
         $conf->set_variable_value($value);
         if ($module != '') {
             $conf->set_module($module);
         }
         if ($reg_exp != '') {
             $conf->set_reg_exp($reg_exp);
         }
         $conf->set_domain_id($domain_id);
         $this->_post_master->set_data_object($conf);
         $this->_post_master->sql_update();
         vivvo_cache::get_instance()->delete('configuration');
     } else {
         $this->add_conf($name, $property, $value, $module, $reg_exp, $domain_id);
     }
 }
コード例 #2
0
ファイル: import_feed.php プロジェクト: ahanjir07/vivvo-dev
/**
 * Import feed
 */
function import_feed(&$sm)
{
    require_once dirname(__FILE__) . '/../feed.class.php';
    $category_list = $sm->get_categories();
    $category_keys = array_keys($category_list->list);
    require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php';
    require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php';
    $pm =& new vivvo_post_master($sm);
    $al =& new Articles_list($sm);
    if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE > 0) {
        $al->_query->add_where('created < ( DATE_SUB( \'' . date('Y-m-d H:i:s') . '\', INTERVAL ' . VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE . ' DAY ))');
        $al->_query->add_where('feed_data != \'\'');
        $al->_query->set_from('`' . VIVVO_DB_PREFIX . 'Articles`');
        $al->_query->add_fields('*');
        $al->sql_delete_list($pm, NULL, true);
        $al->reset_list_query();
    }
    if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE > 0) {
        $al->search(array('search_search_date' => VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE, 'search_before_after' => '-1'), '', '', 0, 0, false);
        $al->_query->add_where('feed_data != \'\'');
        $al->sql_update_list($pm, array('status' => -1), NULL, true);
    }
    $fl =& new Feeds_list($sm);
    $fl->search(array());
    foreach ($fl->list as $feed) {
        if (in_array($feed->category_id, $category_keys)) {
            $feed->get_articles();
            require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php';
            $post_master = new vivvo_post_master($sm);
            $post_master->set_data_object($feed);
            $post_master->sql_update();
        } else {
            $pm->set_data_object($feed);
            $pm->sql_delete();
        }
    }
}
コード例 #3
0
/**
 * Import articles (cron task function).
 *
 * @param vivvo_lite_site	$sm
 */
function auto_import_feeds($sm)
{
    require_once dirname(__FILE__) . '/../core/Feeds.class.php';
    require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php';
    $db = $sm->get_db();
    if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE > 0) {
        $datetime = date('Y-m-d H:i:59', VIVVO_START_TIME - VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE * 86400);
        if (VIVVO_PLUGIN_FEED_IMPORTER_TRASH) {
            $db->exec('UPDATE ' . VIVVO_DB_PREFIX . "articles SET status = -2 WHERE created < '{$datetime}' AND feed_item_id IS NOT NULL AND status > -2");
        } else {
            $db->exec('DELETE FROM ' . VIVVO_DB_PREFIX . "articles WHERE created < '{$datetime}' AND feed_item_id IS NOT NULL");
        }
    }
    if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE > 0) {
        $datetime = date('Y-m-d H:i:59', VIVVO_START_TIME - VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE * 86400);
        $db->exec('UPDATE ' . VIVVO_DB_PREFIX . "articles SET status = -1 WHERE created < '{$datetime}' AND feed_item_id IS NOT NULL");
    }
    $feed_list = Feeds_list::factory();
    $feed_list->search(array());
    $post_master = new vivvo_post_master($sm);
    $total_added = 0;
    $total_updated = 0;
    foreach ($feed_list->list as $feed) {
        $counts = $feed->import_articles();
        $total_added += $counts[0];
        $total_updated += $counts[1];
        $post_master->set_data_object($feed);
        $post_master->sql_update();
    }
    if (defined('VIVVO_CRONJOB_MODE')) {
        $feed_count = count($feed_list->list);
        echo "auto_import_feeds: Imported {$total_added} and updated {$total_updated} article(s) from {$feed_count} feed(s)." . PHP_EOL;
    } elseif (defined('VIVVO_FEED_IMPORTER_ADMIN_VIEW')) {
        echo json_encode(array('feeds' => count($feed_list->list), 'added' => $total_added, 'updated' => $total_updated));
    }
}
コード例 #4
0
 /**
  * deletes object from database
  */
 public function sql_delete()
 {
     require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/framework/vivvo_post.php';
     $pm = new vivvo_post_master(vivvo_lite_site::get_instance());
     $pm->set_data_object($this);
     $pm->sql_delete();
 }
コード例 #5
0
 function logout()
 {
     session_destroy();
     $sm = vivvo_lite_site::get_instance();
     if ($sm->user) {
         class_exists('vivvo_post_master') or (require VIVVO_FS_FRAMEWORK . 'vivvo_post.php');
         $post_master = new vivvo_post_master();
         $sm->user->reset_user_hash();
         $post_master->set_data_object($sm->user);
         $post_master->sql_update();
     }
     $sm->user = false;
     return true;
 }
コード例 #6
0
ファイル: vivvo_cron.php プロジェクト: ahanjir07/vivvo-dev
 /**
  * Add/edit cron job
  *
  * @param array|string $time_mask 	Unix crontab time mask/array @see vivvo_cron_manager::create_time_mask
  * @param string $file				File containg the script
  * @param string $class				Class name
  * @param string $method			Method/function name
  * @param array $arguments			Arguments for cron function
  */
 function cron_job($time_mask, $file, $class, $method, $arguments = array())
 {
     if (is_array($time_mask)) {
         $time_mask = $this->create_time_mask($time_mask);
     }
     $cron_list = new vivvo_cron_list();
     $cron_job = $cron_list->get_cron_job_by_hash(md5($file . $class . $method . serialize($arguments)));
     if ($cron_job) {
         $pm = new vivvo_post_master();
         $cron_job->set_time_mask($time_mask);
         $cron_job->set_nextrun(0);
         $pm->set_data_object($cron_job);
         $pm->sql_update();
     } else {
         $pm = new vivvo_post_master();
         $cron_job = new vivvo_cron();
         $cron_job->set_time_mask($time_mask);
         $cron_job->set_file($file);
         $cron_job->set_class($class);
         $cron_job->set_method($method);
         $cron_job->set_arguments(serialize($arguments));
         $cron_job->set_hash(md5($file . $class . $method . serialize($arguments)));
         $pm->set_data_object($cron_job);
         $pm->sql_insert();
     }
 }
コード例 #7
0
 function register_url($url, $file, $url_hanlder, $content_handler = '')
 {
     if (!preg_match('/[^a-zA-Z\\d\\-_\\.%~]/i', $url) && !vivvo_lite_site::get_instance()->is_registered_url($url) && !empty($file) && !empty($url_hanlder)) {
         require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php';
         require_once VIVVO_FS_FRAMEWORK . 'vivvo_preference.php';
         $config = new preferences();
         $pm = new vivvo_post_master();
         $config->set_variable_name($url);
         $config->set_variable_property('file');
         $config->set_variable_value($file);
         $config->set_module('url_modules');
         $config->set_domain_id(1);
         $pm->set_data_object($config);
         $pm->sql_insert();
         $config->set_variable_name($url);
         $config->set_variable_property('url_handler_function');
         $config->set_variable_value($url_hanlder);
         $config->set_module('url_modules');
         $config->set_domain_id(1);
         $pm->set_data_object($config);
         $pm->sql_insert();
         if (!empty($content_handler)) {
             $config->set_variable_name($url);
             $config->set_variable_property('content_handler_function');
             $config->set_variable_value($content_handler);
             $config->set_module('url_modules');
             $config->set_domain_id(1);
             $pm->set_data_object($config);
             $pm->sql_insert();
         }
         return true;
     }
     return false;
 }
コード例 #8
0
 /**
  * Saves auto-draft of an article
  *
  * @param	int		$article_id
  * @param	string	$title
  * @param	string	$abstract
  * @param	string	$body
  * @param	string	$time
  * @param	int		$user
  * @return	ArticlesRevisions|false
  */
 public static function save_auto_draft($article_id, $title, $abstract, $body, $time, $user)
 {
     $sm = vivvo_lite_site::get_instance();
     // remove all other auto-drafts for this arrticle (if any), as there should be only one
     $sm->get_db()->exec('DELETE FROM ' . VIVVO_DB_PREFIX . "articles_revisions\n\t\t\t\t WHERE article_id = {$article_id} AND type = 1");
     $revision = new ArticlesRevisions($sm, array('article_id' => $article_id, 'version' => 0, 'title' => $title, 'abstract' => $abstract, 'body' => $body, 'created_time' => $time, 'creator_id' => $user, 'type' => 1));
     class_exists('vivvo_post_master') or (require VIVVO_FS_FRAMEWORK . 'vivvo_post.php');
     $post_master = new vivvo_post_master($sm);
     $post_master->set_data_object($revision);
     if ($post_master->sql_insert()) {
         return $revision;
     }
     return false;
 }
コード例 #9
0
ファイル: feed.class.php プロジェクト: ahanjir07/vivvo-dev
 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());
 }
コード例 #10
0
ファイル: Feeds.class.php プロジェクト: ahanjir07/vivvo-dev
 /**
  * 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);
 }
コード例 #11
0
ファイル: module.class.php プロジェクト: ahanjir07/vivvo-dev
 /**
  * Save module preferences
  *
  * @param vivvo_site $site_manager
  * @param vivvo_post_master $post_master
  * @param integer $box_def_id
  * @param array $prefs
  * @return mixed on SUCCES true, on ERROR error code
  */
 function save_preferences($site_manager, $post_master, $box_def_id, $prefs)
 {
     $box_params_list = new box_def_list();
     $box = $box_params_list->get_box_by_id($box_def_id);
     if ($box) {
         $box->set_params('');
         if (!empty($prefs) && is_array($prefs)) {
             $box->set_params($prefs);
         }
         $post_master->set_data_object($box);
         if (!$post_master->sql_update()) {
             // DB insert fail
             return 801;
         }
         return true;
     } else {
         //TODO error code
         return 802;
     }
 }