Example #1
0
 /**
  * Database driver choose
  *
  * @param array $conf
  * @return object
  */
 private static function instance($conf)
 {
     $driver = Tools::chef($conf, 'driver', NULL);
     if (is_null($driver)) {
         $driver = Config::query('db/0');
     }
     switch ($driver['engine']) {
         case 'Mysqldb':
         case 'mysqldb':
         case 'mysql':
             return new Mysqldb($driver);
         case 'Sqlitedb':
         case 'sqlitedb':
         case 'sqlite':
             return new Sqlitedb($driver);
             break;
         case 'PostgreSQLdb':
         case 'Postgresqldb':
         case 'postgresql':
             return new Postgresqldb($driver);
             break;
         default:
             return new Mysqldb($driver);
     }
 }
Example #2
0
 /**
  * Store log record (LIFO)
  * @param array $record
  * @return array
  */
 public function log($record = [])
 {
     $log = Config::query('store/log');
     if (array_key_exists('case', $record) && array_key_exists('message', $record)) {
         $log[] = ['timestamp' => time(), 'case' => $record['case'], 'message' => $record['message']];
     }
     Config::set('store/log', $log);
 }
Example #3
0
 /**
  * Set permission $perm is octal int (0777 NOT 777)
  * @param string $path
  * @param int $perm
  * @return bool
  */
 protected static function defaultFilePermission()
 {
     return Config::query('system/filePermission') === false ? 0644 : Config::query('system/filePermission');
 }
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $settings = array('site' => array('path', 'locale_path', 'ssl', 'sslserver'), 'theme' => array('server', 'dir', 'path', 'sslserver', 'sslpath'), 'avatar' => array('server', 'dir', 'path'), 'attachments' => array('server', 'dir', 'path', 'sslserver', 'sslpath'));
     // XXX: If we're only going to have one boolean on thi page we
     // can remove some of the boolean processing code --Z
     static $booleans = array('site' => array('fancy'));
     $values = array();
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->trimmed("{$section}-{$setting}");
         }
     }
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->boolean($setting) ? 1 : 0;
         }
     }
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
Example #5
0
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $settings = array('openid' => array('trusted_provider', 'required_team'));
     static $booleans = array('openid' => array('append_username'), 'site' => array('openidonly'));
     $values = array();
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->trimmed($setting);
         }
     }
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->boolean($setting) ? 1 : 0;
         }
     }
     // This throws an exception on validation errors
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
Example #6
0
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $booleans = array('sessions' => array('handle', 'debug'));
     $values = array();
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->boolean($setting) ? 1 : 0;
         }
     }
     // This throws an exception on validation errors
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
Example #7
0
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $settings = array('profile' => array('biolimit'), 'newuser' => array('welcome', 'default'));
     static $booleans = array('invite' => array('enabled'));
     $values = array();
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->trimmed("{$section}-{$setting}");
         }
     }
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->boolean("{$section}-{$setting}") ? 1 : 0;
         }
     }
     // This throws an exception on validation errors
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
Example #8
0
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $settings = array('sitemap' => array('googlekey', 'yahookey', 'bingkey'));
     $values = array();
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->trimmed($setting);
         }
     }
     // This throws an exception on validation errors
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $settings = array('license' => array('type', 'owner', 'url', 'title', 'image'));
     $values = array();
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->trimmed($setting);
         }
     }
     // This throws an exception on validation errors
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
Example #10
0
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $settings = array('adsense' => array('adScript', 'client', 'mediumRectangle', 'rectangle', 'leaderboard', 'wideSkyscraper'));
     $values = array();
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->trimmed($setting);
         }
     }
     // This throws an exception on validation errors
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
Example #11
0
 /**
  * Save the new design settings
  *
  * @return void
  */
 function saveDesignSettings()
 {
     // Workaround for PHP returning empty $_POST and $_FILES when POST
     // length > post_max_size in php.ini
     if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
         $msg = _('The server was unable to handle that much POST ' . 'data (%s bytes) due to its current configuration.');
         $this->clientException(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
         return;
     }
     // check for an image upload
     $bgimage = $this->saveBackgroundImage();
     static $settings = array('theme', 'logo');
     $values = array();
     foreach ($settings as $setting) {
         $values[$setting] = $this->trimmed($setting);
     }
     $this->validate($values);
     $oldtheme = common_config('site', 'theme');
     $config = new Config();
     $config->query('BEGIN');
     // Only update colors if the theme has not changed.
     if ($oldtheme == $values['theme']) {
         $bgcolor = new WebColor($this->trimmed('design_background'));
         $ccolor = new WebColor($this->trimmed('design_content'));
         $sbcolor = new WebColor($this->trimmed('design_sidebar'));
         $tcolor = new WebColor($this->trimmed('design_text'));
         $lcolor = new WebColor($this->trimmed('design_links'));
         Config::save('design', 'backgroundcolor', $bgcolor->intValue());
         Config::save('design', 'contentcolor', $ccolor->intValue());
         Config::save('design', 'sidebarcolor', $sbcolor->intValue());
         Config::save('design', 'textcolor', $tcolor->intValue());
         Config::save('design', 'linkcolor', $lcolor->intValue());
     }
     $onoff = $this->arg('design_background-image_onoff');
     $on = false;
     $off = false;
     if ($onoff == 'on') {
         $on = true;
     } else {
         $off = true;
     }
     $tile = $this->boolean('design_background-image_repeat');
     // Hack to use Design's bit setter
     $scratch = new Design();
     $scratch->setDisposition($on, $off, $tile);
     Config::save('design', 'disposition', $scratch->disposition);
     foreach ($settings as $setting) {
         Config::save('site', $setting, $values[$setting]);
     }
     if (isset($bgimage)) {
         Config::save('design', 'backgroundimage', $bgimage);
     }
     $config->query('COMMIT');
 }
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $settings = array('twitter' => array('consumer_key', 'consumer_secret'), 'integration' => array('source'));
     static $booleans = array('twitter' => array('signin'));
     if (Event::handle('TwitterBridgeAdminImportControl')) {
         $booleans['twitterimport'] = array('enabled');
     }
     $values = array();
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->trimmed($setting);
         }
     }
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->boolean($setting) ? 1 : 0;
         }
     }
     // This throws an exception on validation errors
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $settings = array('twitter' => array('consumer_key', 'consumer_secret'), 'integration' => array('source'));
     static $booleans = array('twitter' => array('signin'));
     if (Event::handle('TwitterBridgeAdminImportControl')) {
         $booleans['twitterimport'] = array('enabled');
     }
     $values = array();
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->trimmed($setting);
         }
     }
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->boolean($setting) ? 1 : 0;
         }
     }
     // This throws an exception on validation errors
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     // Flush the router cache: we may have enabled/disabled bridging,
     // which will add or remove some actions.
     $cache = Cache::instance();
     $cache->delete(Router::cacheKey());
     return;
 }
Example #14
0
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $settings = array('site' => array('name', 'broughtby', 'broughtbyurl', 'email', 'timezone', 'language', 'site', 'textlimit', 'dupelimit'));
     $values = array();
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->trimmed($setting);
         }
     }
     // This throws an exception on validation errors
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $settings = array('snapshot' => array('run', 'reporturl', 'frequency'));
     $values = array();
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->trimmed($setting);
         }
     }
     // This throws an exception on validation errors
     $this->validate($values);
     // assert(all values are valid);
     $config = new Config();
     $config->query('BEGIN');
     foreach ($settings as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
 /**
  * Save settings from the form
  *
  * @return void
  */
 function saveSettings()
 {
     static $booleans = array('site' => array('private', 'inviteonly', 'closed'), 'public' => array('localonly'));
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             $values[$section][$setting] = $this->boolean($setting) ? 1 : 0;
         }
     }
     $config = new Config();
     $config->query('BEGIN');
     foreach ($booleans as $section => $parts) {
         foreach ($parts as $setting) {
             Config::save($section, $setting, $values[$section][$setting]);
         }
     }
     $config->query('COMMIT');
     return;
 }
 /**
  * Save the new design settings
  *
  * @return void
  */
 function saveDesignSettings()
 {
     // Workaround for PHP returning empty $_POST and $_FILES when POST
     // length > post_max_size in php.ini
     if (empty($_FILES) && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) {
         // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit.
         // TRANS: %s is the number of bytes of the CONTENT_LENGTH.
         $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH']));
         $this->clientException(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
         return;
     }
     // check for file uploads
     $bgimage = $this->saveBackgroundImage();
     $customTheme = $this->saveCustomTheme();
     $oldtheme = common_config('site', 'theme');
     if ($customTheme) {
         // This feels pretty hacky :D
         $this->args['theme'] = $customTheme;
         $themeChanged = true;
     } else {
         $themeChanged = $this->trimmed('theme') != $oldtheme;
     }
     static $settings = array('theme', 'logo', 'ssllogo');
     $values = array();
     foreach ($settings as $setting) {
         $values[$setting] = $this->trimmed($setting);
     }
     $this->validate($values);
     $config = new Config();
     $config->query('BEGIN');
     if ($themeChanged) {
         // If the theme has changed, reset custom colors and let them pick
         // up the new theme's defaults.
         $colors = array('background', 'content', 'sidebar', 'text', 'link');
         foreach ($colors as $colorKey) {
             // Clear from global config so we see defaults on this page...
             $GLOBALS['config']['design'][$colorKey . 'color'] = false;
             // And remove old settings from DB...
             $this->deleteSetting('design', $colorKey . 'color');
         }
     } else {
         // Only save colors from the form if the theme has not changed.
         //
         // @fixme a future more ajaxy form should allow theme switch
         // and color customization in one step.
         $bgcolor = new WebColor($this->trimmed('design_background'));
         $ccolor = new WebColor($this->trimmed('design_content'));
         $sbcolor = new WebColor($this->trimmed('design_sidebar'));
         $tcolor = new WebColor($this->trimmed('design_text'));
         $lcolor = new WebColor($this->trimmed('design_links'));
         Config::save('design', 'backgroundcolor', $bgcolor->intValue());
         Config::save('design', 'contentcolor', $ccolor->intValue());
         Config::save('design', 'sidebarcolor', $sbcolor->intValue());
         Config::save('design', 'textcolor', $tcolor->intValue());
         Config::save('design', 'linkcolor', $lcolor->intValue());
     }
     $onoff = $this->arg('design_background-image_onoff');
     $on = false;
     $off = false;
     if ($onoff == 'on') {
         $on = true;
     } else {
         $off = true;
     }
     $tile = $this->boolean('design_background-image_repeat');
     // Hack to use Design's bit setter
     $scratch = new Design();
     $scratch->setDisposition($on, $off, $tile);
     Config::save('design', 'disposition', $scratch->disposition);
     foreach ($settings as $setting) {
         Config::save('site', $setting, $values[$setting]);
     }
     if (isset($bgimage)) {
         Config::save('design', 'backgroundimage', $bgimage);
     }
     if (common_config('custom_css', 'enabled')) {
         $css = $this->arg('css');
         if ($css != common_config('custom_css', 'css')) {
             Config::save('custom_css', 'css', $css);
         }
     }
     $config->query('COMMIT');
 }