Пример #1
0
 /**
  * Returns link to the object of db for writing (always main DB)
  *
  * @return \cs\DB\_Abstract
  */
 function db_prime()
 {
     if (is_object($this->db_prime)) {
         return $this->db_prime;
     }
     /**
      * Save reference for faster access
      */
     $this->db_prime = DB::instance()->{(string) $this->cdb()}();
     return $this->db_prime;
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 function __construct($database, $user = '', $password = '', $host = 'localhost', $charset = 'utf8', $prefix = '')
 {
     $this->connecting_time = microtime(true);
     /**
      * Parsing of $host variable, detecting port and persistent connection
      */
     $host = explode(':', $host);
     $port = ini_get('mysqli.default_port') ?: 3306;
     if (count($host) == 1) {
         $host = $host[0];
     } elseif (count($host) == 2) {
         if ($host[0] == 'p') {
             $host = "{$host['0']}:{$host['1']}";
         } else {
             $port = $host[1];
             $host = $host[0];
         }
     } elseif (count($host) == 3) {
         $port = $host[2];
         $host = "{$host['0']}:{$host['1']}";
     }
     $this->instance = @new \MySQLi($host, $user, $password, $database, $port);
     if (is_object($this->instance) && !$this->instance->connect_errno) {
         $this->database = $database;
         /**
          * Changing DB charset
          */
         if ($charset && $charset != $this->instance->get_charset()->charset) {
             $this->instance->set_charset($charset);
         }
         $this->connected = true;
     } else {
         return false;
     }
     $this->connecting_time = microtime(true) - $this->connecting_time;
     $db = DB::instance();
     $db->time += $this->connecting_time;
     $this->db_type = 'mysql';
     $this->prefix = $prefix;
     return $this;
 }
Пример #3
0
<?php

/**
 * @package        Update
 * @category       modules
 * @author         Nazar Mokrynskyi <*****@*****.**>
 * @copyright      Copyright (c) 2014, Nazar Mokrynskyi
 * @license        MIT License, see license.txt
 */
namespace cs;

use h;
$Config = Config::instance();
$db = DB::instance();
$Index = Index::instance();
$module_object = $Config->module('Update');
if (!$module_object->version) {
    $module_object->version = 0;
}
if (isset($Config->route[0]) && $Config->route[0] == 'process') {
    $version = (int) $module_object->version;
    for ($i = 1; file_exists(MFOLDER . "/sql/{$i}.sql") || file_exists(MFOLDER . "/php/{$i}.php"); ++$i) {
        if ($version < $i) {
            if (file_exists(MFOLDER . "/sql/{$i}.sql")) {
                foreach (explode(';', file_get_contents(MFOLDER . "/sql/{$i}.sql")) as $s) {
                    if ($s) {
                        $db->{'0'}()->q($s);
                    }
                }
            }
            if (file_exists(MFOLDER . "/php/{$i}.php")) {
Пример #4
0
/**
 * @package		Plupload
 * @category	modules
 * @author		Moxiecode Systems AB
 * @author		Nazar Mokrynskyi <*****@*****.**> (integration with CleverStyle CMS)
 * @copyright	Moxiecode Systems AB
 * @license		GNU GPL v2, see license.txt
 */
namespace cs\modules\Plupload;

use cs\Config, cs\DB, cs\Storage, cs\Trigger;
Trigger::instance()->register('admin/System/components/modules/uninstall/process', function ($data) {
    if ($data['name'] != 'Plupload') {
        return;
    }
    $module_data = Config::instance()->module('Plupload');
    $storage = Storage::instance()->{$module_data->storage('files')};
    $cdb = DB::instance()->{$module_data->db('files')};
    unset($module_data);
    if (!$storage || !$cdb) {
        return;
    }
    $files = $cdb->q("SELECT `source`\n\t\t\tFROM `[prefix]plupload_files`");
    while ($f = $cdb->fs($files)) {
        $storage->unlink($f);
    }
    if ($storage->is_dir('Plupload')) {
        $storage->rmdir('Plupload');
    }
});
Пример #5
0
 /**
  * Getting of debug information
  *
  * @return Page
  */
 protected function get_debug_info()
 {
     $Config = Config::instance();
     $db = DB::instance();
     $L = Language::instance();
     $debug_tabs = [];
     $debug_tabs_content = '';
     /**
      * DB queries
      */
     if ($Config->core['show_db_queries']) {
         $debug_tabs[] = $L->db_queries;
         $tmp = '';
         foreach ($db->get_connections_list() as $name => $database) {
             $queries = $database->queries();
             $tmp .= h::{'p.cs-padding-left'}($L->debug_db_info($name != 0 ? $L->db . ' ' . $database->database() : $L->core_db . ' (' . $database->database() . ')', format_time(round($database->connecting_time(), 5)), $queries['num'], format_time(round($database->time(), 5))));
             foreach ($queries['text'] as $i => $text) {
                 $tmp .= h::code($text . h::br(2) . '#' . h::i(format_time(round($queries['time'][$i], 5))), ['class' => ($queries['time'][$i] > 0.1 ? 'uk-alert-danger ' : '') . 'uk-alert']);
             }
         }
         unset($error, $name, $database, $i, $text);
         $debug_tabs_content .= h::div(h::p($L->debug_db_total($db->queries, format_time(round($db->time, 5))), $L->failed_connections . ': ' . h::b(implode(', ', $db->get_connections_list(false)) ?: $L->no), $L->successful_connections . ': ' . h::b(implode(', ', $db->get_connections_list(true)) ?: $L->no), $L->mirrors_connections . ': ' . h::b(implode(', ', $db->get_connections_list('mirror')) ?: $L->no), $L->active_connections . ': ' . (count($db->get_connections_list()) ? '' : h::b($L->no))) . $tmp);
         unset($tmp);
     }
     /**
      * Cookies
      */
     if ($Config->core['show_cookies']) {
         $debug_tabs[] = $L->cookies;
         $tmp = [h::td($L->key . ':', ['style' => 'width: 20%;']) . h::td($L->value)];
         foreach ($_COOKIE as $i => $v) {
             $tmp[] = h::td($i . ':', ['style' => 'width: 20%;']) . h::td(xap($v));
         }
         unset($i, $v);
         $debug_tabs_content .= h::{'table.cs-padding-left tr'}($tmp);
         unset($tmp);
     }
     $this->debug_info = $this->process_replacing(h::{'ul.cs-tabs li'}($debug_tabs) . h::div($debug_tabs_content));
     return $this;
 }
Пример #6
0
/**
 * Updates user contacts for specified provider
 *
 * @param \Hybrid_User_Contact[]	$contacts
 * @param string					$provider
 */
function update_user_contacts($contacts, $provider)
{
    $Cache = Cache::instance();
    $id = User::instance()->id;
    /**
     *	@var \cs\DB\_Abstract $cdb
     */
    $cdb = DB::instance()->{Config::instance()->module('HybridAuth')->db('integration')}();
    $cdb->q("DELETE FROM `[prefix]users_social_integration_contacts`\n\t\tWHERE\n\t\t\t`id`\t\t= '%s' AND\n\t\t\t`provider`\t= '%s'", $id, $provider);
    if (!empty($contacts)) {
        $insert = [];
        $params = [];
        foreach ($contacts as $contact) {
            $insert[] = "('%s', '%s', '%s')";
            $params[] = $id;
            $params[] = $provider;
            $params[] = $contact->identifier;
        }
        $insert = implode(',', $insert);
        $cdb->q("INSERT INTO `[prefix]users_social_integration_contacts`\n\t\t\t(\n\t\t\t\t`id`,\n\t\t\t\t`provider`,\n\t\t\t\t`identifier`\n\t\t\t) VALUES {$insert}", $params);
    }
    unset($Cache->{"HybridAuth/contacts/{$id}"});
}
Пример #7
0
    $Index->form = false;
    switch ($Index->route_path[2]) {
        case 'phpinfo':
            $Index->Content = ob_wrapper(function () {
                phpinfo();
            });
            break;
        case 'readme.html':
            $Index->Content = file_get_contents(DIR . '/readme.html');
    }
    $Index->stop;
    return;
}
$hhvm_version = defined('HHVM_VERSION') ? HHVM_VERSION : false;
$Index->form = false;
$Index->content(h::{'table.cs-table-borderless.cs-left-even.cs-right-odd tr| td'}([h::{'a.cs-button[target=_blank]'}('phpinfo()', ['href' => "{$Index->action}/phpinfo"]) . h::{'a.cs-button[target=_blank]'}($L->information_about_system, ['href' => "{$Index->action}/readme.html"]) . h::{'div#cs-system-license.uk-modal pre.uk-modal-dialog-large'}(file_get_contents(DIR . '/license.txt'), ['title' => "{$L->system} » {$L->license}"]) . h::{'button#cs-system-license-open'}($L->license, ['data-title' => $L->click_to_view_details]), ['colspan' => 2]], ["{$L->operation_system}:", php_uname('s') . ' ' . php_uname('r') . ' ' . php_uname('v')], ["{$L->server_type}:", server_api()], preg_match('/apache/i', $_SERVER['SERVER_SOFTWARE']) ? [$L->version_of('Apache') . ':', apache_version()] : false, preg_match('/nginx/i', $_SERVER['SERVER_SOFTWARE']) ? [$L->version_of('Nginx') . ':', explode('/', $_SERVER['SERVER_SOFTWARE'])[1]] : false, $hhvm_version ? [$L->version_of('HHVM') . ':', $hhvm_version] : false, $hhvm_version ? false : ["{$L->available_ram}:", str_replace(['K', 'M', 'G'], [" {$L->KB}", " {$L->MB}", " {$L->GB}"], ini_get('memory_limit'))], [$L->version_of('PHP') . ':', PHP_VERSION], ["{$L->php_components}:", h::{'table.cs-left-odd.cs-table-borderless tr| td'}(["{$L->mcrypt}:", [check_mcrypt() ? $L->on : $L->off . h::icon('info-sign', ['data-title' => $L->mcrypt_warning]), ['class' => state(check_mcrypt())]]], ["{$L->zlib}:", $L->get(zlib())], zlib() ? ["{$L->zlib_compression}:", $L->get(zlib_compression())] : false, zlib_compression() ? ["{$L->zlib_compression_level}:", zlib_compression_level()] : false, ["{$L->curl_lib}:", [$L->get(curl()), ['class' => state(curl())]]], ["{$L->apc_module}:", [$L->get(apc()), ['class' => version_compare(PHP_VERSION, '5.5', '>=') ? false : state(apc())]]], ["{$L->memcached_module}:", [$L->get(memcached())]])], ["{$L->main_db}:", $Core->db_type], ["{$L->properties} {$Core->db_type}:", h::{'table.cs-left-odd.cs-table-borderless tr| td'}(["{$L->host}:", $Core->db_host], [$L->version_of($Core->db_type) . ':', [DB::instance()->server()]], ["{$L->name_of_db}:", $Core->db_name], ["{$L->prefix_for_db_tables}:", $Core->db_prefix])], ["{$L->main_storage}:", $Core->storage_type], ["{$L->cache_engine}:", $Core->cache_engine], ["{$L->free_disk_space}:", format_filesize(disk_free_space('./'), 2)], ["{$L->php_ini_settings}:", h::{'table.cs-left-odd.cs-table-borderless tr| td'}(["{$L->allow_file_upload}:", [$L->get(ini_get('file_uploads')), ['class' => state(ini_get('file_uploads'))]]], $hhvm_version ? false : ["{$L->max_file_uploads}:", ini_get('max_file_uploads')], ["{$L->upload_limit}:", format_filesize(str_replace(['K', 'M', 'G'], [" {$L->KB}", " {$L->MB}", " {$L->GB}"], ini_get('upload_max_filesize')))], ["{$L->post_max_size}:", format_filesize(str_replace(['K', 'M', 'G'], [" {$L->KB}", " {$L->MB}", " {$L->GB}"], ini_get('post_max_size')))], $hhvm_version ? false : ["{$L->max_execution_time}:", format_time(ini_get('max_execution_time'))], $hhvm_version ? false : ["{$L->max_input_time}:", format_time(ini_get('max_input_time'))], $hhvm_version ? false : ["{$L->default_socket_timeout}:", format_time(ini_get('default_socket_timeout'))], ["{$L->allow_url_fopen}:", [$L->get(ini_get('allow_url_fopen')), ['class' => state(ini_get('allow_url_fopen'))]]], ["{$L->display_errors}:", [$L->get(display_errors()), ['class' => state(!display_errors())]]])]));
function state($state)
{
    return $state ? 'uk-alert-success' : 'uk-alert-danger';
}
/**
 * Returns server type
 *
 * @return string
 */
function server_api()
{
    $phpinfo = ob_wrapper(function () {
        phpinfo();
    });
    if (preg_match('/apache/i', $_SERVER['SERVER_SOFTWARE'])) {
Пример #8
0
 /**
  * Query
  *
  * SQL request into DB
  *
  * @abstract
  *
  * @param string|string[]		$query	SQL query string or array, may be a format string in accordance with the first parameter of sprintf() function
  * @param string|string[]		$params	May be array of arguments for formatting of <b>$query</b><br>
  * 										or string - in this case it will be first argument for formatting of <b>$query</b>
  * @param string				$param	if <b>$params</s> is string - this parameter will be second argument for formatting of <b>$query</b>.
  * 										If you need more arguments - add them after this one, function will accept them.
  *
  * @return bool|object|resource
  */
 function q($query, $params = [], $param = null)
 {
     $query = str_replace('[prefix]', $this->prefix, $query);
     switch (func_num_args()) {
         default:
             $params = array_slice(func_get_args(), 1);
             break;
         case 0:
             return false;
         case 1:
         case 2:
             if (!is_array($params)) {
                 $params = [$params];
             }
             break;
     }
     if (!empty($params)) {
         unset($param);
         foreach ($params as &$param) {
             $param = $this->s($param, false);
         }
         unset($param);
     }
     if (is_array($query) && !empty($query)) {
         $time_from = microtime(true);
         foreach ($query as &$q) {
             $local_params = $params;
             if (is_array($q)) {
                 if (count($q) > 1) {
                     $local_params = array_slice($q, 1);
                 }
                 $q = $q[0];
             }
             $q = empty($local_params) ? $q : vsprintf($q, $local_params);
         }
         unset($local_params, $q);
         $db = DB::instance();
         $this->queries['num'] += count($query);
         $db->queries += count($query);
         $return = $this->q_multi_internal($query);
         $db->time += round(microtime(true) - $time_from, 6);
         return $return;
     }
     if (!$query) {
         return true;
     }
     $this->query['time'] = microtime(true);
     $this->query['text'] = empty($params) ? $query : vsprintf($query, $params);
     if (DEBUG) {
         $this->queries['text'][] = $this->query['text'];
     }
     $result = $this->q_internal($this->query['text']);
     $this->query['time'] = round(microtime(true) - $this->query['time'], 6);
     $this->time += $this->query['time'];
     if (DEBUG) {
         $this->queries['time'][] = $this->query['time'];
     }
     ++$this->queries['num'];
     $db = DB::instance();
     $db->time += $this->query['time'];
     ++$db->queries;
     return $result;
 }