public function action_plugin_activation($file)
 {
     DB::register_table('abbrev');
     /*
      * Create the database table, or upgrade it
      */
     $dbms = DB::get_driver_name();
     $sql = 'CREATE TABLE ' . DB::table('abbrev') . ' ' . '(';
     if ($dbms == 'sqlite') {
         $sql .= 'xid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,';
     } else {
         if ($dbms == 'mysql') {
             $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT,' . 'UNIQUE KEY xid (xid),';
         } else {
             $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT,' . 'UNIQUE KEY xid (xid),';
         }
     }
     $sql .= 'abbrev VARCHAR(255),' . 'caseful INTEGER DEFAULT 0,' . "prefix VARCHAR(16) DEFAULT '\\b'," . "postfix VARCHAR(16) DEFAULT '\\b'," . 'priority INTEGER DEFAULT 100,' . 'definition VARCHAR(255)' . ')';
     if (!DB::dbdelta($sql)) {
         Utils::debug(DB::get_errors());
     }
     if ($file == str_replace('\\', '/', $this->get_file())) {
         ACL::create_token(self::PLUGIN_TOKEN, _t('Allow use of Abbrev plugin'), 'Category', false);
         $group = UserGroup::get_by_name('admin');
         $group->grant(self::PLUGIN_TOKEN);
     }
 }
 public function filter_optimize_database($result, $paramarray)
 {
     $space_saved = 0;
     $tables = 0;
     switch (DB::get_driver_name()) {
         case 'mysql':
             $q = 'SHOW TABLE STATUS WHERE data_free > 0';
             $tables = DB::get_results($q);
             if (count($tables) > 0) {
                 foreach ($tables as $table) {
                     $q2 = 'OPTIMIZE TABLE ' . $table->Name;
                     if (DB::query($q2)) {
                         $space_saved += $table->Data_free;
                         $tables++;
                     }
                 }
                 EventLog::log('Database Tables Optimized. ' . Utils::human_size($space_saved) . ' reclaimed from ' . HabariLocale::_n('table', 'tables', $tables) . '.');
             }
             $result = true;
             break;
         case 'sqlite':
             if (DB::exec('VACUUM')) {
                 $result = true;
                 EventLog::log('SQLite database VACUUM\'ed successfully.');
             } else {
                 $result = false;
             }
             break;
         default:
             $result = false;
             break;
     }
     return $result;
 }
    /**
     * Plugin plugin_activation action, executed when any plugin is activated
     * @param string $file The filename of the plugin that was activated.
     */
    public function action_plugin_activation($file = '')
    {
        // Was this plugin activated?
        if (Plugins::id_from_file($file) == Plugins::id_from_file(__FILE__)) {
            // Register a default event log type for this plugin
            EventLog::register_type("default", "FeedList");
            // Register the name of a new database table
            DB::register_table('feedlist');
            // 'plugin_activation' hook is called without first calling 'init'
            // Create the database table, or upgrade it
            switch (DB::get_driver_name()) {
                case 'mysql':
                    $schema = 'CREATE TABLE {feedlist} (
				id INT UNSIGNED AUTO_INCREMENT,
				feed_id INT NOT NULL DEFAULT 0,
				guid VARCHAR(255) NOT NULL,
				title VARCHAR(255) NOT NULL,
				link VARCHAR(255) NOT NULL,
				updated DATETIME NOT NULL,
				description TEXT,
				PRIMARY KEY (id),
				UNIQUE KEY guid (guid)
				);';
                    break;
                case 'sqlite':
                    $schema = 'CREATE TABLE {feedlist} (
				id INTEGER PRIMARY KEY AUTOINCREMENT, 
				feed_id INTEGER NOT NULL DEFAULT 0,
				guid VARCHAR(255) UNIQUE NOT NULL,
				title VARCHAR(255) NOT NULL,
				link VARCHAR(255) NOT NULL,
				updated DATETIME NOT NULL,
				description TEXT
				);';
                    break;
            }
            DB::dbdelta($schema);
            // Log a table creation event
            EventLog::log('Installed feedlist cache table.');
            // Add a periodical execution event to be triggered hourly
            CronTab::add_hourly_cron('feedlist', 'load_feeds', 'Load feeds for feedlist plugin.');
            // Log the cron creation event
            EventLog::log('Added hourly cron for feed updates.');
        }
    }
 public function action_init()
 {
     DB::register_table('l_data');
     DB::register_table('l_source');
     switch (DB::get_driver_name()) {
         case 'sqlite':
             $q = "CREATE TABLE " . DB::table('l_data') . "(\n\t\t\t\t\tid INTIGER NOT NULL AUTOINCREMENT,\n\t\t\t\t\tname VARCHAR(255) NOT NULL,\n\t\t\t\t\tcontent TEXT NOT NULL,\n\t\t\t\t\tdata BLOB NOT NULL,\n\t\t\t\t\tdate VARCHAR(255) NOT NULL,\n\t\t\t\t\tlink VARCHAR(255) NOT NULL,\n\t\t\t\t\tenabled TINYINT(1) NOT NULL,\n\t\t\t\t\tCREATE UNIQUE INDEX IF NOT EXISTS id ON " . DB::table('l_data') . "(id);\n\t\t\t\t);";
             return $sql = DB::dbdelta($q);
             break;
         case 'mysql':
             $q = "CREATE TABLE " . DB::table('l_data') . "(\n\t\t\t\t\tid INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\tname VARCHAR(255) NOT NULL,\n\t\t\t\t\tcontent TEXT NOT NULL,\n\t\t\t\t\tdata BLOB NOT NULL,\n\t\t\t\t\tdate VARCHAR(255) NOT NULL,\n\t\t\t\t\tlink VARCHAR(255) NOT NULL,\n\t\t\t\t\tenabled TINYINT(1) NOT NULL,\n\t\t\t\t\tUNIQUE KEY id (id)\n\t\t\t\t);";
             return $sql = DB::dbdelta($q);
             break;
         case 'postgresql':
             // need to figure out what schema changes are needed for postgreSQL
             break;
     }
     $this->add_template('lifestream_template', dirname(__FILE__) . '/lifestream_template.php');
 }
 public function action_plugin_activation($file)
 {
     DB::register_table('macro');
     /*
      * Create the database table, or upgrade it
      */
     $dbms = DB::get_driver_name();
     $sql = 'CREATE TABLE ' . DB::table('macro') . ' ' . '(';
     if ($dbms == 'sqlite') {
         $sql .= 'xid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ';
     } else {
         if ($dbms == 'mysql') {
             $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT, ' . 'UNIQUE KEY xid (xid), ';
         } else {
             $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT, ' . 'UNIQUE KEY xid (xid), ';
         }
     }
     $sql .= 'name VARCHAR(255), ' . 'enabled INTEGER DEFAULT 1, ' . 'modified INTEGER, ' . 'description TEXT, ' . 'definition TEXT NOT NULL, ' . 'container INTEGER DEFAULT 0, ' . 'nargs INTEGER DEFAULT 0, ' . 'eval INTEGER DEFAULT 0' . ')';
     if (!DB::dbdelta($sql)) {
         //            Utils::debug(DB::get_errors());
     }
     if ($file == str_replace('\\', '/', $this->get_file())) {
         ACL::create_token(self::PLUGIN_TOKEN, _t('Allow use of Macros plugin'), 'Category', false);
         $group = UserGroup::get_by_name('admin');
         $group->grant(self::PLUGIN_TOKEN);
     }
 }
 /**
  * Handles get requests for the system information page.
  */
 public function get_sysinfo()
 {
     $sysinfo = array();
     $siteinfo = array();
     // Assemble Site Info
     $siteinfo[_t('Habari Version')] = Version::get_habariversion();
     if (Version::is_devel()) {
         $siteinfo[_t('Habari Version')] .= " r" . Version::get_svn_revision();
     }
     $siteinfo[_t('Habari API Version')] = Version::get_apiversion();
     $siteinfo[_t('Habari DB Version')] = Version::get_dbversion();
     $siteinfo[_t('Active Theme')] = Options::get('theme_name');
     $siteinfo[_t('Site Language')] = strlen(Options::get('system_locale')) ? Options::get('system_locale') : 'en-us';
     $this->theme->siteinfo = $siteinfo;
     // Assemble System Info
     $sysinfo[_t('PHP Version')] = phpversion();
     $sysinfo[_t('Server Software')] = $_SERVER['SERVER_SOFTWARE'];
     $sysinfo[_t('Database')] = DB::get_driver_name() . ' - ' . DB::get_driver_version();
     $sysinfo[_t('PHP Extensions')] = implode(', ', get_loaded_extensions());
     if (defined('PCRE_VERSION')) {
         $sysinfo[_t('PCRE Version')] = PCRE_VERSION;
     } else {
         // probably PHP < 5.2.4
         ob_start();
         phpinfo(8);
         $phpinfo = ob_get_contents();
         ob_end_clean();
         preg_match('/PCRE Library Version.*class="v">(.*)$/mi', $phpinfo, $matches);
         $sysinfo[_t('PCRE Version')] = $matches[1];
     }
     $sysinfo[_t('Browser')] = $_SERVER['HTTP_USER_AGENT'];
     $this->theme->sysinfo = $sysinfo;
     // Assemble Class Info
     $classinfo = Utils::glob(HABARI_PATH . "/user/classes/*.php");
     if (count($classinfo)) {
         $classinfo = array_map('realpath', $classinfo);
     }
     $this->theme->classinfo = $classinfo;
     // Assemble Plugin Info
     $raw_plugins = Plugins::get_active();
     $plugins = array('system' => array(), 'user' => array(), '3rdparty' => array(), 'other' => array());
     foreach ($raw_plugins as $plugin) {
         $file = $plugin->get_file();
         if (preg_match('%[\\\\/](system|3rdparty|user)[\\\\/]plugins[\\\\/]%i', $file, $matches)) {
             // A plugin's info is XML, cast the element to a string. See #1026.
             $plugins[strtolower($matches[1])][(string) $plugin->info->name] = $file;
         } else {
             $plugins['other'][$plugin->info->name] = $file;
         }
     }
     $this->theme->plugins = $plugins;
     $this->display('sysinfo');
 }
Exemple #7
0
 /**
  * Provide default Habari features for curious plugins
  * @param array $provided Features already collected from interrogated plugins
  * @return array Plugin Features plus Habari Features
  */
 public static function filter_provided($provided = array())
 {
     foreach (array(Version::HABARI_MAJOR_MINOR, DB::get_driver_name()) as $feature) {
         $provided[$feature] = array("Habari");
     }
     return $provided;
 }
	/**
	 * Gets a database schema associated with this pluggable
	 * @return string The database schema
	 */
	final public function get_db_schema()
	{
		$db = DB::get_driver_name();
		$schema = dirname( $this->get_file() ) . '/schema/' . $db . '.sql';
		return file_get_contents( $schema );
	}
Exemple #9
0
 /**
  * Handles get requests for the system information page.
  */
 public function get_sysinfo()
 {
     $sysinfo = array();
     $siteinfo = array();
     // Assemble Site Info
     $siteinfo[_t('Habari Version')] = Version::get_habariversion();
     if (Version::is_devel()) {
         $siteinfo[_t('Habari Version')] .= " " . Version::get_git_short_hash();
     }
     $siteinfo[_t('Habari API Version')] = Version::get_apiversion();
     $siteinfo[_t('Habari DB Version')] = Version::get_dbversion();
     $siteinfo[_t('Active Theme')] = Options::get('theme_name');
     $siteinfo[_t('System Locale')] = HabariLocale::get();
     $siteinfo[_t('Cache Class')] = Cache::get_class();
     $this->theme->siteinfo = $siteinfo;
     // Assemble System Info
     $sysinfo[_t('PHP Version')] = phpversion();
     $sysinfo[_t('Server Software')] = $_SERVER['SERVER_SOFTWARE'];
     $sysinfo[_t('Database')] = DB::get_driver_name() . ' - ' . DB::get_driver_version();
     $sysinfo[_t('PHP Extensions')] = implode(', ', get_loaded_extensions());
     $sysinfo[_t('PHP Configuration Settings')] = implode("<br>", Utils::get_ini_settings());
     if (defined('PCRE_VERSION')) {
         $sysinfo[_t('PCRE Version')] = PCRE_VERSION;
     } else {
         // probably PHP < 5.2.4
         ob_start();
         phpinfo(8);
         $phpinfo = ob_get_contents();
         ob_end_clean();
         preg_match('/PCRE Library Version.*class="v">(.*)$/mi', $phpinfo, $matches);
         $sysinfo[_t('PCRE Version')] = $matches[1];
     }
     $sysinfo[_t('Browser')] = $_SERVER['HTTP_USER_AGENT'];
     $this->theme->sysinfo = $sysinfo;
     // Assemble Class Info
     $classinfo = Utils::glob(HABARI_PATH . "/user/classes/*.php");
     if (count($classinfo)) {
         $classinfo = array_map('realpath', $classinfo);
     }
     $this->theme->classinfo = $classinfo;
     // Assemble Plugin Info
     $raw_plugins = Plugins::get_active();
     $plugins = array('system' => array(), 'user' => array(), '3rdparty' => array(), 'other' => array());
     foreach ($raw_plugins as $plugin) {
         $file = $plugin->get_file();
         // Catch plugins that are symlinked from other locations as ReflectionClass->getFileName() only returns the ultimate file path, not the symlink path, and we really want the symlink path
         $all_plugins = Plugins::list_all();
         $filename = basename($file);
         if (array_key_exists($filename, $all_plugins) && $all_plugins[$filename] != $file) {
             $file = $all_plugins[$filename];
         }
         if (preg_match('%[\\\\/](system|3rdparty|user)[\\\\/]plugins[\\\\/]%i', $file, $matches)) {
             // A plugin's info is XML, cast the element to a string. See #1026.
             $plugins[strtolower($matches[1])][(string) $plugin->info->name] = $file;
         } else {
             // A plugin's info is XML, cast the element to a string.
             $plugins['other'][(string) $plugin->info->name] = $file;
         }
     }
     $this->theme->plugins = $plugins;
     $this->theme->admin_page = _t('System Information');
     $this->display('sysinfo');
 }