/** * Serves the locale Javascript to translate javascript strings. */ public function locale_js() { header('Expires: ' . gmdate('D, d M Y H:i:s ', time() + 432000) . 'GMT'); header('content-type: text/javascript'); $domain = HabariLocale::get_messages(); $domain_json = json_encode($domain); $js = <<<TEEHEE function _t() { var domain = {$domain_json}; var s = arguments[0]; if(domain[s] != undefined) { s = domain[s][1][0]; } for(var i = 1; i <= arguments.length; i++) { r = new RegExp('%' + (i) + '\\\\\$s', 'g'); if(!s.match(r)) { r = new RegExp('%s'); } s = s.replace(r, arguments[i]); } return s; } TEEHEE; echo Plugins::filter('locale_js', $js); }
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; }
/** * Handles POST requests from the options admin page */ public function post_options() { $option_items = array(); $timezones = DateTimeZone::listIdentifiers(); $timezones = array_merge(array('' => ''), array_combine(array_values($timezones), array_values($timezones))); $option_items[_t('Name & Tagline')] = array('title' => array('label' => _t('Site Name'), 'type' => 'text', 'helptext' => ''), 'tagline' => array('label' => _t('Site Tagline'), 'type' => 'text', 'helptext' => ''), 'about' => array('label' => _t('About'), 'type' => 'textarea', 'helptext' => '')); $option_items[_t('Publishing')] = array('pagination' => array('label' => _t('Items per Page'), 'type' => 'text', 'helptext' => ''), 'atom_entries' => array('label' => _t('Entries to show in Atom feed'), 'type' => 'text', 'helptext' => ''), 'comments_require_id' => array('label' => _t('Require Comment Author Info'), 'type' => 'checkbox', 'helptext' => ''), 'spam_percentage' => array('label' => _t('Comment SPAM Threshold'), 'type' => 'text', 'helptext' => _t('The likelihood a comment is considered SPAM, in percent.'))); $option_items[_t('Time & Date')] = array('timezone' => array('label' => _t('Time Zone'), 'type' => 'select', 'selectarray' => $timezones, 'helptext' => _t('Current Date Time: %s', array(HabariDateTime::date_create()->format()))), 'dateformat' => array('label' => _t('Date Format'), 'type' => 'text', 'helptext' => _t('Current Date: %s', array(HabariDateTime::date_create()->date))), 'timeformat' => array('label' => _t('Time Format'), 'type' => 'text', 'helptext' => _t('Current Time: %s', array(HabariDateTime::date_create()->time)))); $option_items[_t('Language')] = array('locale' => array('label' => _t('Locale'), 'type' => 'select', 'selectarray' => array_merge(array('' => 'default'), array_combine(HabariLocale::list_all(), HabariLocale::list_all())), 'helptext' => _t('International language code')), 'system_locale' => array('label' => _t('System Locale'), 'type' => 'text', 'helptext' => _t('The appropriate locale code for your server'))); $option_items[_t('Troubleshooting')] = array('log_min_severity' => array('label' => _t('Minimum Severity'), 'type' => 'select', 'selectarray' => LogEntry::list_severities(), 'helptext' => _t('Only log entries with a this or higher severity.')), 'log_backtraces' => array('label' => _t('Log Backtraces'), 'type' => 'checkbox', 'helptext' => _t('Logs error backtraces to the log table\'s data column. Can drastically increase log size!'))); /*$option_items[_t('Presentation')] = array( 'encoding' => array( 'label' => _t('Encoding'), 'type' => 'select', 'selectarray' => array( 'UTF-8' => 'UTF-8' ), 'helptext' => '', ), );*/ $option_items = Plugins::filter('admin_option_items', $option_items); $form = new FormUI('Admin Options'); $tab_index = 3; foreach ($option_items as $name => $option_fields) { $fieldset = $form->append('wrapper', Utils::slugify(_u($name)), $name); $fieldset->class = 'container settings'; $fieldset->append('static', $name, '<h2>' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>'); foreach ($option_fields as $option_name => $option) { $field = $fieldset->append($option['type'], $option_name, $option_name, $option['label']); $field->template = 'optionscontrol_' . $option['type']; $field->class = 'item clear'; if ($option['type'] == 'select' && isset($option['selectarray'])) { $field->options = $option['selectarray']; } $field->tabindex = $tab_index; $tab_index++; if (isset($option['helptext'])) { $field->helptext = $option['helptext']; } else { $field->helptext = ''; } } } /* @todo: filter for additional options from plugins * We could either use existing config forms and simply extract * the form controls, or we could create something different */ $submit = $form->append('submit', 'apply', _t('Apply'), 'admincontrol_submit'); $submit->tabindex = $tab_index; $form->on_success(array($this, 'form_options_success')); $this->theme->form = $form->get(); $this->theme->option_names = array_keys($option_items); $this->theme->display('options'); }
public function testPlural_tests() { // de $this->assertEquals(HabariLocale::__run_plural_test('Plural-Forms: nplurals=2; plural=(n==1?0:1);'), '10111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'); // fr $this->assertEquals(HabariLocale::__run_plural_test('Plural-Forms: nplurals=2; plural=n>1?1:0'), '00111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'); // lt $this->assertEquals(HabariLocale::__run_plural_test('Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2;'), '20111111112222222222201111111120111111112011111111201111111120111111112011111111201111111120111111112011111111222222222220111111112011111111201111111120111111112011111111201111111120111111112011111111'); // cz $this->assertEquals(HabariLocale::__run_plural_test('Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;'), '20111222222222222222201112222220111222222011122222201112222220111222222011122222201112222220111222222011122222222222222220111222222011122222201112222220111222222011122222201112222220111222222011122222'); // hu $this->assertEquals(HabariLocale::__run_plural_test('Plural-Forms: nplurals=1; plural=0;'), '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'); // ru $this->assertEquals(HabariLocale::__run_plural_test('Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;'), '20111222222222222222201112222220111222222011122222201112222220111222222011122222201112222220111222222011122222222222222220111222222011122222201112222220111222222011122222201112222220111222222011122222'); // pl $this->assertEquals(HabariLocale::__run_plural_test('Plural-Forms: nplurals=3; plural=n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2'), '20111222222222222222221112222222111222222211122222221112222222111222222211122222221112222222111222222211122222222222222222111222222211122222221112222222111222222211122222221112222222111222222211122222'); // sl $this->assertEquals(HabariLocale::__run_plural_test('Plural-Forms: nplurals=4; plural=n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3'), '30122333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333012233333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333'); }
/** * Load translations from a given file. * * @param string $domain the domain to load the data into * @param string $file the file name * @return boolean TRUE if data was successfully loaded, FALSE otherwise */ private static function load_file($domain, $file) { if (!file_exists($file)) { Error::raise(sprintf(_t('No translations found for locale %s, domain %s!'), self::$locale, $domain)); return FALSE; } if (filesize($file) < 24) { Error::raise(sprintf(_t('Invalid .MO file for locale %s, domain %s!'), self::$locale, $domain)); return FALSE; } $fp = fopen($file, 'rb'); $data = fread($fp, filesize($file)); fclose($fp); // determine endianness $little_endian = TRUE; list(, $magic) = unpack('V1', substr($data, 0, 4)); switch ($magic & 0xffffffff) { case (int) 0x950412de: $little_endian = TRUE; break; case (int) 0xde120495: $little_endian = FALSE; break; default: Error::raise(sprintf(_t('Invalid magic number 0x%08x in %s!'), $magic, $file)); return FALSE; } $revision = substr($data, 4, 4); if ($revision != 0) { Error::raise(sprintf(_t('Unknown revision number %d in %s!'), $revision, $file)); return FALSE; } $l = $little_endian ? 'V' : 'N'; if ($data && strlen($data) >= 20) { $header = substr($data, 8, 12); $header = unpack("{$l}1msgcount/{$l}1msgblock/{$l}1transblock", $header); if ($header['msgblock'] + ($header['msgcount'] - 1) * 8 > filesize($file)) { Error::raise(sprintf(_t('Message count (%d) out of bounds in %s!'), $header['msgcount'], $file)); return FALSE; } $lo = "{$l}1length/{$l}1offset"; for ($msgindex = 0; $msgindex < $header['msgcount']; $msgindex++) { $msginfo = unpack($lo, substr($data, $header['msgblock'] + $msgindex * 8, 8)); $msgids = explode("", substr($data, $msginfo['offset'], $msginfo['length'])); $transinfo = unpack($lo, substr($data, $header['transblock'] + $msgindex * 8, 8)); $transids = explode("", substr($data, $transinfo['offset'], $transinfo['length'])); self::$messages[$domain][$msgids[0]] = array($msgids, $transids); } } // setup plural functionality self::$plural_function = self::get_plural_function(self::$messages[$domain][''][1][0]); // only use locale if we actually read something return count(self::$messages) > 0; }
/** * 读取读取跳转代码 --boboit 2015.11.30 */ include "checkParameter.php"; define('HABARI_PATH', dirname(__FILE__)); define("habari", dirname(__FILE__)); ob_start(); require dirname(__FILE__) . '/system/autoload.php'; spl_autoload_register('habari_autoload'); SuperGlobal::process_gps(); if (!defined('SUPPRESS_ERROR_HANDLER')) { Error::handle_errors(); } $config = Site::get_dir('config_file'); require_once $config; HabariLocale::set(Config::get('locale', 'en-us')); if (!defined('DEBUG')) { define('DEBUG', false); } DB::connect(); $start_time = strtotime(date("Y-m-d 00:00:00", strtotime("-1 day"))); $end_time = strtotime(date("Y-m-d 23:59:59", strtotime("-1 day"))); if (isset($_GET['st']) && !empty($_GET['st'])) { $start_time = strtotime($_GET['st']); } if (isset($_GET['et']) && !empty($_GET['et'])) { $end_time = strtotime($_GET['et']); } $hbslf_visit = DB::get_results('SELECT distinct ip FROM `hbslf_visit` where date_add >=' . $start_time . ' AND date_add <=' . $end_time); $hbslf_redirect = DB::get_results('SELECT distinct ip FROM `hbslf_redirect`where date_add >=' . $start_time . ' AND date_add <=' . $end_time); echo $visit = count($hbslf_visit);
define('DEBUG', false); } // The configuration file does not exist. // Therefore we load the installer to create the configuration file and install a base database. $installer = new InstallHandler(); $installer->begin_install(); } /* Habari is installed and we established a connection with the database */ // Set the locale from database or default locale if (Options::get('locale')) { HabariLocale::set(Options::get('locale')); } else { HabariLocale::set('en-us'); } if (Options::get('system_locale')) { HabariLocale::set_system_locale(Options::get('system_locale')); } // Verify if the database has to be upgraded. if (Version::requires_upgrade()) { $installer = new InstallHandler(); $installer->upgrade_db(); } // If we're doing unit testing, stop here if (defined('UNIT_TEST')) { return; } // if this is an asyncronous call, ignore abort. if (isset($_GET['asyncronous']) && Utils::crypt(Options::get('guid'), $_GET['asyncronous'])) { ignore_user_abort(true); } // Send the Content-Type HTTP header.
/** * Return the info XML for a plugin based on a filename * * @param string $file The filename of the plugin file * @return SimpleXMLElement The info structure for the plugin, or null if no info could be loaded */ public static function load_info( $file ) { $info = null; $xml_file = preg_replace( '%\.plugin\.php$%i', '.plugin.xml', $file ); if ( file_exists( $xml_file ) && $xml_content = file_get_contents( $xml_file ) ) { // tell libxml to throw exceptions and let us check for errors $old_error = libxml_use_internal_errors( true ); try { $info = new SimpleXMLElement( $xml_content ); // if the xml file uses a theme element name instead of pluggable, it's old if ( $info->getName() != 'pluggable' ) { $info = 'legacy'; } // Translate the plugin description HabariLocale::translate_xml( $info, $info->description ); // Translate the plugin help foreach( $info->help as $help ) { HabariLocale::translate_xml( $help, $help->value ); } } catch ( Exception $e ) { EventLog::log( _t( 'Invalid plugin XML file: %1$s', array( $xml_file ) ), 'err', 'plugin' ); $info = 'broken'; } // restore the old error level libxml_use_internal_errors( $old_error ); } return $info; }
/** * Load a translation domain/file for this pluggable * @return boolean true if data was successfully loaded, false otherwise */ public function load_text_domain( $domain ) { $base_dir = realpath( dirname( $this->get_file() ) ); return HabariLocale::load_pluggable_domain( $domain, $base_dir ); }
<?php if (!defined('HABARI_PATH')) { die('No direct access'); } ?> </div><!-- end wrapper --> <script type="text/javascript"> function _t() { var domain = <?php // retrieve only the translated strings that are used by this page's javascript functions. $messages = array_intersect_key(HabariLocale::get_messages(), array_flip(array("All selected", "%s selected", "None selected"))); echo json_encode($messages); ?> ; var s = arguments[0]; if(domain[s] != undefined) { s = domain[s][1][0]; } for(var i = 1; i <= arguments.length; i++) { r = new RegExp('%' + (i) + '\\\\\$s', 'g'); if(!s.match(r)) { r = new RegExp('%s'); } s = s.replace(r, arguments[i]); } return s; } </script>
/** * 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'); }
/** * Entry point for installation. The reason there is a begin_install * method to handle is that conceivably, the user can stop installation * mid-install and need an alternate entry point action at a later time. */ public function act_begin_install() { // Create a new theme to handle the display of the installer $this->theme = Themes::create('installer', 'RawPHPEngine', HABARI_PATH . '/system/installer/'); /** * Set user selected Locale or default */ $this->theme->locales = HabariLocale::list_all(); if (isset($_POST['locale']) && $_POST['locale'] != null) { HabariLocale::set($_POST['locale']); $this->theme->locale = $_POST['locale']; $this->handler_vars['locale'] = $_POST['locale']; } else { HabariLocale::set('en-us'); $this->theme->locale = 'en-us'; $this->handler_vars['locale'] = 'en-us'; } /* * Check .htaccess first because ajax doesn't work without it. */ if (!$this->check_htaccess()) { $this->handler_vars['file_contents'] = htmlentities(implode("\n", $this->htaccess())); $this->display('htaccess'); } // Dispatch AJAX requests. if (isset($_POST['ajax_action'])) { switch ($_POST['ajax_action']) { case 'check_mysql_credentials': self::ajax_check_mysql_credentials(); exit; break; case 'check_pgsql_credentials': self::ajax_check_pgsql_credentials(); exit; break; case 'check_sqlite_credentials': self::ajax_check_sqlite_credentials(); exit; break; } } // set the default values now, which will be overriden as we go $this->form_defaults(); if (!$this->meets_all_requirements()) { $this->display('requirements'); } /* * Add the AJAX hooks */ Plugins::register(array('InstallHandler', 'ajax_check_mysql_credentials'), 'ajax_', 'check_mysql_credentials'); Plugins::register(array('InstallHandler', 'ajax_check_pgsql_credentials'), 'ajax_', 'check_pgsql_credentials'); /* * Let's check the config.php file if no POST data was submitted */ if (!file_exists(Site::get_dir('config_file')) && !isset($_POST['admin_username'])) { // no config file, and no HTTP POST $this->display('db_setup'); } // try to load any values that might be defined in config.php if (file_exists(Site::get_dir('config_file'))) { include Site::get_dir('config_file'); // check for old style config (global variable, pre-dates registry based config if (!Config::exists('db_connection') && isset($db_connection)) { // found old style config... // set up registry: Config::set('db_connection', $db_connection); // assign handler vars (for config file write) $this->set_handler_vars_from_db_connection(); // write new config file if ($this->write_config_file(true)) { // successful, so redirect: Utils::redirect(Site::get_url('habari')); } } if (Config::exists('db_connection')) { $this->set_handler_vars_from_db_connection(); } // if a $blog_data array exists in config.php, use it // to pre-load values for the installer // ** this is completely optional ** if (isset($blog_data)) { foreach ($blog_data as $blog_datum => $value) { $this->handler_vars[$blog_datum] = $value; } } } // now merge in any HTTP POST values that might have been sent // these will override the defaults and the config.php values $this->handler_vars = $this->handler_vars->merge($_POST); // we need details for the admin user to install if ('' == $this->handler_vars['admin_username'] || '' == $this->handler_vars['admin_pass1'] || '' == $this->handler_vars['admin_pass2'] || '' == $this->handler_vars['admin_email']) { // if none of the above are set, display the form $this->display('db_setup'); } $db_type = $this->handler_vars['db_type']; if ($db_type == 'mysql' || $db_type == 'pgsql') { $this->handler_vars['db_host'] = $_POST["{$db_type}_db_host"]; $this->handler_vars['db_user'] = $_POST["{$db_type}_db_user"]; $this->handler_vars['db_pass'] = $_POST["{$db_type}_db_pass"]; $this->handler_vars['db_schema'] = $_POST["{$db_type}_db_schema"]; } // we got here, so we have all the info we need to install // make sure the admin password is correct if ($this->handler_vars['admin_pass1'] !== $this->handler_vars['admin_pass2']) { $this->theme->assign('form_errors', array('password_mismatch' => _t('Password mis-match.'))); $this->display('db_setup'); } // check whether prefix is valid if (isset($this->handler_vars['table_prefix']) && preg_replace('/[^a-zA-Z_]/', '', $this->handler_vars['table_prefix']) !== $this->handler_vars['table_prefix']) { $this->theme->assign('form_errors', array('table_prefix' => _t('Allowed characters are A-Z, a-z and "_".'))); $this->display('db_setup'); } // Make sure we still have a valid connection if (!call_user_func(array($this, "check_{$db_type}"))) { $this->display('db_setup'); } // try to write the config file if (!$this->write_config_file()) { $this->theme->assign('form_errors', array('write_file' => _t('Could not write config.php file...'))); $this->display('db_setup'); } // try to install the database if (!$this->install_db()) { // the installation failed for some reason. // re-display the form $this->display('db_setup'); } // activate plugins on POST if (count($_POST) > 0) { $this->activate_plugins(); } // Installation complete. Secure sqlite if it was chosen as the database type to use if ($db_type == 'sqlite') { if (!$this->secure_sqlite()) { $this->theme->sqlite_contents = implode("\n", $this->sqlite_contents()); $this->display('sqlite'); } } EventLog::log(_t('Habari successfully installed.'), 'info', 'default', 'habari'); Utils::redirect(Site::get_url('habari')); }