示例#1
0
function get_pages_rows()
{
    $L = Language::instance();
    $Static_pages = Static_pages::instance();
    $categories = array_slice(Config::instance()->route, 2);
    $structure = $Static_pages->get_structure();
    $path = [];
    if (!empty($categories)) {
        foreach ($categories as $category) {
            $category = $Static_pages->get_category($category)['path'];
            if (isset($structure['categories'][$category])) {
                $structure = $structure['categories'][$category];
                $path[] = $structure['path'];
            }
        }
        unset($category);
    }
    Page::instance()->title($structure['id'] == 0 ? $L->root_category : $structure['title']);
    $path = !empty($path) ? implode('/', $path) . '/' : '';
    $content = [];
    if (!empty($structure['pages'])) {
        foreach ($structure['pages'] as &$page) {
            $page = $Static_pages->get($page);
            $content[] = [[h::a($page['title'], ['href' => $path . $page['path']]), ['class' => 'cs-static-pages-padding-left-0']], h::{'a.cs-button-compact'}([h::icon('file-text'), ['href' => "admin/Static_pages/edit_page/{$page['id']}", 'data-title' => $L->edit]], [h::icon('trash-o'), ['href' => "admin/Static_pages/delete_page/{$page['id']}", 'data-title' => $L->delete]])];
        }
    }
    return [$content];
}
示例#2
0
 /**
  * @static
  * Text translation from one language to another
  *
  * @param string $text Text for translation
  * @param string $from Language translate from
  * @param string $to   Language translate to
  *
  * @return bool|string Translated string of <b>false</b> if failed
  */
 static function translate($text, $from, $to)
 {
     if (!curl()) {
         return $text;
     }
     if (empty(self::$accessToken)) {
         $settings = Config::instance()->core['auto_translation_engine'];
         if (!(curl() && isset($settings['client_id'], $settings['client_secret']) && $settings['client_id'] && $settings['client_secret'])) {
             return false;
         }
         self::$accessToken = self::getTokens('client_credentials', 'http://api.microsofttranslator.com', $settings['client_id'], $settings['client_secret'], 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/');
     }
     //Create a streams context.
     $objContext = stream_context_create(['http' => ['header' => 'Authorization: Bearer ' . self::$accessToken]]);
     //Call Soap Client and get translation
     $Soap = new SoapClient('http://api.microsofttranslator.com/V2/Soap.svc', ['soap_version' => 'SOAP_1_2', 'encoding' => 'UTF-8', 'exceptions' => true, 'trace' => true, 'cache_wsdl' => 'WSDL_CACHE_NONE', 'stream_context' => $objContext, 'user_agent' => 'PHP-SOAP/' . PHP_VERSION . "\r\nAuthorization: Bearer " . self::$accessToken]);
     if (!$Soap) {
         return $text;
     }
     return $Soap->Translate(['text' => $text, 'from' => $from, 'to' => $to, 'contentType' => 'text/html', 'category' => 'general'])->TranslateResult;
 }
示例#3
0
 /**
  * Moves an uploaded file to a new location
  *
  * @abstract
  *
  * @see move_uploaded_file()
  *
  * @param string	$filename
  * @param string	$destination
  *
  * @return bool
  */
 function move_uploaded_file($filename, $destination)
 {
     $temp = md5(uniqid(microtime(true)));
     while (file_exists(TEMP . "/{$temp}")) {
         $temp = md5(uniqid(microtime(true)));
     }
     time_limit_pause();
     if (move_uploaded_file($filename, TEMP . "/{$temp}") === false) {
         time_limit_pause(false);
         return false;
     }
     time_limit_pause(false);
     return $this->request(['function' => __FUNCTION__, 'filename' => Config::instance()->base_url() . "/{$temp}", 'destination' => $destination])[1] && unlink(TEMP . "/{$temp}");
 }
示例#4
0
/**
 * Get HybridAuth instance with current configuration. Strongly recommended for usage
 *
 * @param null|string	$provider
 * @param null|string	$base_url
 *
 * @return Hybrid_Auth
 */
function get_hybridauth_instance($provider = null, $base_url = null)
{
    require_once __DIR__ . '/../Hybrid/Auth.php';
    $Config = Config::instance();
    $User = User::instance();
    $HybridAuth = new Hybrid_Auth(['base_url' => $base_url ?: $Config->base_url() . "/HybridAuth/{$provider}/endpoint/" . $User->get_session(), 'providers' => $Config->module('HybridAuth')->providers]);
    if ($User->user() && MODULE != 'HybridAuth') {
        $HybridAuth->restoreSessionData(serialize($User->get_data('HybridAuth_session')));
    }
    return $HybridAuth;
}
示例#5
0
<?php

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

use h, cs\Config, cs\Index, cs\Language\Prefix, cs\Page;
$Index = Index::instance();
$L = new Prefix('oauth2_');
Page::instance()->title($L->list_of_client);
$Index->apply_button = false;
$module_data = Config::instance()->module('OAuth2');
$Index->content(h::{'p.lead.cs-center'}($L->list_of_clients) . h::{'table.cs-table.cs-center-all'}(h::{'thead tr th'}([$L->client_name, 'client_id', 'client_secret', $L->action]) . h::{'tbody tr'}(array_map(function ($client) use($L) {
    return h::td([$client['name'], h::{'input{disabled]'}($client['id']), h::{'input{disabled]'}($client['secret']), h::{'a.cs-button-compact'}([h::icon('pencil'), ['href' => "admin/OAuth2/clients/edit/{$client['id']}", 'data-title' => $L->edit]]) . h::{'a.cs-button-compact'}([h::icon('trash-o'), ['href' => "admin/OAuth2/clients/delete/{$client['id']}", 'data-title' => $L->delete]])], ['class' => $client['active'] ? false : 'text-muted']);
}, OAuth2::instance()->clients_list()))) . h::{'table.cs-table-borderless.cs-left-even.cs-right-odd.uk-margin-top tr| td'}([h::info('oauth2_allow_guest_tokens'), h::{'input[type=radio]'}(['name' => 'general[guest_tokens]', 'checked' => $module_data->guest_tokens, 'value' => [0, 1], 'in' => [$L->no, $L->yes]])], [h::info('oauth2_automatic_prolongation'), h::{'input[type=radio]'}(['name' => 'general[automatic_prolongation]', 'checked' => $module_data->automatic_prolongation, 'value' => [0, 1], 'in' => [$L->no, $L->yes]])], [h::info('oauth2_expiration'), h::{'input[type=number]'}(['name' => 'general[expiration]', 'value' => $module_data->expiration, 'min' => 1]) . $L->seconds]) . h::{'p.cs-left a.cs-button'}([$L->add_client, ['href' => 'admin/OAuth2/clients/add']]));
示例#6
0
<?php

/**
 * @package		CleverStyle CMS
 * @subpackage	System module
 * @category	modules
 * @author		Nazar Mokrynskyi <*****@*****.**>
 * @copyright	Copyright (c) 2011-2014, Nazar Mokrynskyi
 * @license		MIT License, see license.txt
 */
namespace cs\modules\System;

use h, cs\Config, cs\Core, cs\Index, cs\Language;
$Config = Config::instance();
$L = Language::instance();
$Config->reload_languages();
$translate_engines = _mb_substr(get_files_list(ENGINES . '/Text', '/^[^_].*?\\.php$/i', 'f'), 0, -4);
$translate_engines_settings = [];
$current_engine_settings = '';
foreach ($translate_engines as $engine) {
    $parameters = file_get_json(ENGINES . '/Text/' . $engine . '.json');
    if (is_array($parameters) && !empty($parameters)) {
        $table = '';
        foreach ($parameters as $paremeter => $description) {
            $table .= h::{'tr td'}([$description, h::input(['name' => 'core[auto_translation_engine][' . $paremeter . ']', 'value' => isset($Config->core['auto_translation_engine'][$paremeter]) ? $Config->core['auto_translation_engine'][$paremeter] : ''])]);
        }
        $translate_engines_settings[] = base64_encode(h::table($table));
    } else {
        $translate_engines_settings[] = base64_encode($parameters ?: $L->no_settings_found);
    }
    if ($engine == $Config->core['auto_translation_engine']['name']) {
示例#7
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');
    }
});
示例#8
0
 protected function set_internal($item, $value, $save = true)
 {
     $Config = Config::instance();
     $module_data =& $Config->components['modules'][$this->module];
     if (!isset($module_data['data'])) {
         $module_data['data'] = [];
     }
     $module_data['data'][$item] = $value;
     $this->module_data = $module_data;
     if ($save) {
         return $Config->save();
     }
     return true;
 }
示例#9
0
/**
 * Checks whether specified functionality available or not
 *
 * @param string|string[]	$functionality	One functionality or array of them
 *
 * @return bool								<i>true</i> if all functionality available, <i>false</i> otherwise
 */
function functionality($functionality)
{
    if (is_array($functionality)) {
        $result = true;
        foreach ($functionality as $f) {
            $result = $result && functionality($f);
        }
        return $result;
    }
    $all = Cache::instance()->get("functionality", function () {
        $functionality = [];
        $components = Config::instance()->components;
        foreach ($components['modules'] as $module => $module_data) {
            if ($module_data['active'] != 1 || !file_exists(MODULES . "/{$module}/meta.json")) {
                continue;
            }
            $meta = file_get_json(MODULES . "/{$module}/meta.json");
            if (!isset($meta['provide'])) {
                continue;
            }
            $functionality = array_merge($functionality, (array) $meta['provide']);
        }
        unset($module, $module_data, $meta);
        foreach ($components['plugins'] as $plugin) {
            if (!file_exists(PLUGINS . "/{$plugin}/meta.json")) {
                continue;
            }
            $meta = file_get_json(PLUGINS . "/{$plugin}/meta.json");
            if (!isset($meta['provide'])) {
                continue;
            }
            $functionality = array_merge($functionality, (array) $meta['provide']);
        }
        return $functionality;
    });
    return array_search($functionality, $all) !== false;
}
示例#10
0
 /**
  * Returns database index
  *
  * @return int
  */
 protected function cdb()
 {
     return Config::instance()->module('Static_pages')->db('pages');
 }
示例#11
0
/**
 * Check backward dependencies (during uninstalling/disabling)
 *
 * @param string	$name	Component name
 * @param string	$type	Component type module|plugin
 * @param string	$mode	Mode of checking for modules uninstall|disable
 *
 * @return bool
 */
function check_backward_dependencies($name, $type = 'module', $mode = 'disable')
{
    switch ($type) {
        case 'module':
            $dir = MODULES . "/{$name}";
            break;
        case 'plugin':
            $dir = PLUGINS . "/{$name}";
            break;
        default:
            return false;
    }
    if (!file_exists("{$dir}/meta.json")) {
        return true;
    }
    $meta = file_get_json("{$dir}/meta.json");
    $return = true;
    $Config = Config::instance();
    $L = Language::instance();
    $Page = Page::instance();
    /**
     * Checking for backward dependencies of modules
     */
    $return_m = true;
    foreach ($Config->components['modules'] as $module => $module_data) {
        /**
         * If module uninstalled, disabled (in disable check mode), module name is the same as checking or meta.json file does not exists
         * Then skip this module
         */
        if ($module_data['active'] == -1 || $mode == 'disable' && $module_data['active'] == 0 || $module == $name && $type == 'module' || !file_exists(MODULES . "/{$module}/meta.json")) {
            continue;
        }
        $module_require = file_get_json(MODULES . "/{$module}/meta.json");
        if (!isset($module_require['require'])) {
            continue;
        }
        $module_require = dep_normal($module_require['require']);
        if (isset($module_require[$meta['package']]) || isset($meta['provide']) && array_intersect(array_keys($module_require), (array) $meta['provide'])) {
            if ($return_m) {
                $Page->warning($L->dependencies_not_satisfied);
            }
            $return_m = false;
            $Page->warning($L->this_package_is_used_by_module($module));
        }
    }
    $return = $return && $return_m;
    unset($return_m, $module, $module_data, $module_require);
    /**
     * Checking for backward dependencies of plugins
     */
    $return_p = true;
    foreach ($Config->components['plugins'] as $plugin) {
        if ($plugin == $name && $type == 'plugin' || !file_exists(PLUGINS . "/{$plugin}/meta.json")) {
            continue;
        }
        $plugin_require = file_get_json(PLUGINS . "/{$plugin}/meta.json");
        if (!isset($plugin_require['require'])) {
            continue;
        }
        $plugin_require = dep_normal($plugin_require['require']);
        if (isset($plugin_require[$meta['package']]) || isset($meta['provide']) && array_intersect(array_keys($plugin_require), (array) $meta['provide'])) {
            if ($return_p) {
                $Page->warning($L->dependencies_not_satisfied);
            }
            $return_p = false;
            $Page->warning($L->this_package_is_used_by_plugin($plugin));
        }
    }
    return $return && $return_p;
}
示例#12
0
        case 'api':
            return;
        case 'Static_pages':
            $rc = ['index'];
    }
    $Static_pages = Static_pages::instance();
    $structure = $Static_pages->get_structure();
    $categories = array_slice($rc, 0, -1);
    if (!empty($categories)) {
        foreach ($categories as $category) {
            if (isset($structure['categories'][$category])) {
                $structure = $structure['categories'][$category];
                $path[] = $structure['path'];
            }
        }
        unset($category);
    }
    unset($categories);
    if (isset($structure['pages'][array_slice($rc, -1)[0]])) {
        $data['rc'] = 'Static_pages/' . $structure['pages'][array_slice($rc, -1)[0]];
    }
})->register('System/Index/construct', function () {
    if (!ADMIN) {
        return;
    }
    switch (Config::instance()->components['modules']['Static_pages']['active']) {
        case 0:
        case 1:
            require __DIR__ . '/trigger/installed.php';
    }
});
示例#13
0
<?php

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

use h, cs\Config, cs\Index, cs\Language\Prefix, cs\Page;
$Index = Index::instance();
$L = new Prefix('oauth2_');
$client = OAuth2::instance()->get_client(Config::instance()->route[2]);
Page::instance()->title($L->editing_of_client($client['name']));
$Index->apply_button = false;
$Index->cancel_button_back = true;
$Index->action = 'admin/OAuth2/clients/list';
$Index->content(h::{'p.lead.cs-center'}($L->editing_of_client($client['name'])) . h::{'table.cs-table-borderless.cs-left-even.cs-right-odd tr'}(h::th($L->client_name) . h::{'td input[name=name]'}(['value' => $client['name']]), h::th('client_secret') . h::{'td input[name=secret]'}(['value' => $client['secret']]), h::th($L->client_domain) . h::{'td input[name=domain]'}(['value' => $client['domain']]), h::th($L->active) . h::{'td input[type=radio][name=active]'}(['checked' => $client['active'], 'value' => [0, 1], 'in' => [$L->no, $L->yes]])) . h::{'input[type=hidden][name=id]'}(['value' => $client['id']]) . h::{'input[type=hidden][name=mode][value=edit]'}());
示例#14
0
<?php

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

use cs\Config, cs\Index, cs\User;
$module_properties = Config::instance()->module('Moderation');
$User = User::instance();
if (!$User->admin() && !in_array($module_properties->moderators_group ?: User::ADMIN_GROUP_ID, $User->get_groups())) {
    error_code(403);
    return;
}
$Index = Index::instance();
if (!isset($Index->route_path[1])) {
    $Index->route_path[1] = 'default';
}
示例#15
0
<?php

/**
 * @package		Static Pages
 * @category	modules
 * @author		Nazar Mokrynskyi <*****@*****.**>
 * @copyright	Copyright (c) 2011-2014, Nazar Mokrynskyi
 * @license		MIT License, see license.txt
 */
namespace cs\modules\Static_pages;

use h, cs\Config, cs\Index, cs\Language;
$Index = Index::instance();
$L = Language::instance();
$rc = Config::instance()->route;
$Index->buttons = false;
$Index->content(h::{'table.cs-left-all.cs-table'}(h::{'thead tr th'}([$L->page_title, ['style' => 'width: 80%']], $L->action) . h::{'tbody tr| td'}(get_pages_rows())) . h::{'p.cs-left a.cs-button'}([$L->add_page, ['href' => 'admin/Static_pages/add_page/' . array_slice($rc, -1)[0]]]));
示例#16
0
 /**
  * Pseudo tag for labels with tooltips, specified <i>input</i> is translation item of <b>$L</b> object,
  * <i>input</i>_into item of <b>$L</b> is content of tooltip
  *
  * @static
  *
  * @param array|string	$in
  * @param array			$data
  *
  * @return mixed
  */
 static function info($in = '', $data = [])
 {
     if (isset($in['insert']) || isset($data['insert'])) {
         return static::__callStatic(__FUNCTION__, func_get_args());
     }
     if ($in === false) {
         return '';
     } elseif (is_array($in)) {
         return static::__callStatic(__FUNCTION__, [$in, $data]);
     }
     $L = Language::instance();
     if (Config::instance(true)->core['show_tooltips']) {
         return static::span($L->{$in}, array_merge(['data-title' => $L->{$in . '_info'}], $data));
     } else {
         return static::span($L->{$in}, $data);
     }
 }
示例#17
0
<?php

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

use cs\Config, cs\Index;
$OAuth2 = OAuth2::instance();
$Index = Index::instance();
if (isset($_POST['mode'])) {
    switch ($_POST['mode']) {
        case 'add':
            $Index->save((bool) $OAuth2->oauth2_add_client($_POST['name'], $_POST['domain'], $_POST['active']));
            break;
        case 'edit':
            $Index->save($OAuth2->set_client($_POST['id'], $_POST['secret'], $_POST['name'], $_POST['domain'], $_POST['active']));
            break;
        case 'delete':
            $Index->save($OAuth2->del_client($_POST['id']));
    }
}
if (isset($_POST['general'])) {
    $Index->save(Config::instance()->module('OAuth2')->set($_POST['general']));
}
示例#18
0
function get_block_content($id)
{
    $Config = Config::instance();
    return Text::instance()->process($Config->module('System')->db('texts'), $Config->components['blocks'][$id]['content']);
}
示例#19
0
            $Page->error(['access_denied', 'client_secret do not corresponds client_id']);
        }
        $token_data = $OAuth2->get_token($access_token, $client_id, $client['secret']);
    } else {
        $token_data = $OAuth2->get_token($access_token, $client_id, $client['secret']);
        if ($token_data['type'] == 'code') {
            error_code(403);
            $Page->error(['invalid_request', "This access_token can't be used without client_secret"]);
        }
    }
    if (!$token_data) {
        error_code(403);
        $Page->error(['access_denied', 'access_token expired']);
    }
    $_POST['session'] = $_REQUEST['session'] = $token_data['session'];
    _setcookie('session', $token_data['session']);
    if (!Config::instance()->module('OAuth2')->guest_tokens) {
        Trigger::instance()->register('System/User/construct/after', function () {
            if (!User::instance()->user()) {
                error_code(403);
                Page::instance()->error(['access_denied', 'Guest tokens disabled']);
            }
        });
    }
})->register('System/Index/mainmenu', function ($data) {
    if ($data['path'] == 'OAuth2') {
        $data['hide'] = true;
        return false;
    }
    return true;
});
示例#20
0
 /**
  * Get token data
  *
  * @param string		$access_token
  * @param string		$client			Client id
  * @param string		$secret			Client secret
  *
  * @return array|bool					<i>false</i> on failure, array ['user' => id, 'session' => id, 'expire' => unix time, 'type' => 'code'|'token']
  */
 function get_token($access_token, $client, $secret)
 {
     $client = $this->get_client($client);
     if (!is_md5($access_token) || !$client || $client['secret'] != $secret) {
         return false;
     }
     $Cache = $this->cache;
     $data = $Cache->get("tokens/{$access_token}", function () use($client, $access_token) {
         return $this->db()->qf(["SELECT\n\t\t\t\t\t`user`,\n\t\t\t\t\t`session`,\n\t\t\t\t\t`expire`,\n\t\t\t\t\t`type`\n\t\t\t\tFROM `[prefix]oauth2_clients_sessions`\n\t\t\t\tWHERE\n\t\t\t\t\t`id`\t\t\t= '%s' AND\n\t\t\t\t\t`access_token`\t= '%s'\n\t\t\t\tLIMIT 1", $client['id'], $access_token]);
     });
     if ($data) {
         if ($data['expire'] < TIME) {
             return false;
         }
         if (!$this->get_access($client['id'], $data['user'])) {
             $this->db_prime()->q(["DELETE FROM `[prefix]oauth2_clients_sessions`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`\t\t\t= '%s' AND\n\t\t\t\t\t\t`access_token`\t= '%s'\n\t\t\t\t\tLIMIT 1", $client['id'], $access_token]);
             unset($Cache->{"tokens/{$access_token}"});
             $data = false;
             /**
              * Automatic prolongation of tokens' expiration time if configured
              */
         } elseif ($this->automatic_prolongation && $data['expire'] < TIME - $this->expiration * Config::instance()->core['update_ratio'] / 100) {
             $data['expire'] = TIME + $this->expiration;
             $this->db_prime()->q("UPDATE `[prefix]oauth2_clients_sessions`\n\t\t\t\t\tSET `expire` = '%s'\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`\t\t\t= '%s' AND\n\t\t\t\t\t\t`access_token`\t= '%s'\n\t\t\t\t\tLIMIT 1", $data['expire'], $client['id'], $access_token);
             $Cache->{"tokens/{$access_token}"} = $data;
         }
     }
     return $data;
 }
示例#21
0
<?php

/**
 * @package		Static Pages
 * @category	modules
 * @author		Nazar Mokrynskyi <*****@*****.**>
 * @copyright	Copyright (c) 2011-2014, Nazar Mokrynskyi
 * @license		MIT License, see license.txt
 */
namespace cs\modules\Static_pages;

use h, cs\Config, cs\Index, cs\Language, cs\Page;
$Index = Index::instance();
$L = Language::instance();
$id = (int) Config::instance()->route[1];
$data = Static_pages::instance()->get_category($id);
Page::instance()->title($L->editing_of_page_category($data['title']));
$Index->apply_button = false;
$Index->cancel_button_back = true;
$Index->action = 'admin/Static_pages';
$Index->content(h::{'p.lead.cs-center'}($L->editing_of_page_category($data['title'])) . h::{'table.cs-table-borderless.cs-center-all'}(h::{'thead tr th'}($L->parent_category, $L->category_title, h::info('category_path')), h::{'tbody tr td'}(h::{'select[name=parent][size=5]'}(get_categories_list($id), ['selected' => $data['parent']]), h::{'input[name=title]'}(['value' => $data['title']]), h::{'input[name=path]'}(['value' => $data['path']]))) . h::{'input[type=hidden][name=id]'}(['value' => $id]) . h::{'input[type=hidden][name=mode][value=edit_category]'}());
示例#22
0
 protected function cdb()
 {
     return Config::instance()->module('Precincts')->db('precincts');
 }
示例#23
0
 /**
  * Put or change data of cache item
  *
  * @param string	$item	May contain "/" symbols for cache structure, for example users/<i>user_id</i>
  * @param mixed		$data
  *
  * @return bool
  */
 function set($item, $data)
 {
     $data = @_json_encode($data);
     if (mb_strpos($item, '/') !== false) {
         $path = mb_substr($item, 0, mb_strrpos($item, '/'));
         if (!is_dir(CACHE . "/{$path}")) {
             @mkdir(CACHE . "/{$path}", 0700, true);
         }
         unset($path);
     }
     if (!file_exists(CACHE . "/{$item}") || is_writable(CACHE . "/{$item}")) {
         if ($this->cache_size > 0) {
             $dsize = strlen($data);
             if ($dsize > $this->cache_size) {
                 return false;
             }
             if (file_exists(CACHE . "/{$item}")) {
                 $dsize -= filesize(CACHE . "/{$item}");
             }
             $cache_size_file = fopen(CACHE . '/size', 'c+b');
             $time = microtime(true);
             while (!flock($cache_size_file, LOCK_EX | LOCK_NB)) {
                 if ($time < microtime(true) - 0.5) {
                     fclose($cache_size_file);
                     return false;
                 }
                 usleep(1000);
             }
             unset($time);
             $cache_size = (int) stream_get_contents($cache_size_file);
             $cache_size += $dsize;
             if ($cache_size > $this->cache_size) {
                 $cache_list = get_files_list(CACHE, false, 'f', true, true, 'date|desc');
                 foreach ($cache_list as $file) {
                     $cache_size -= filesize($file);
                     unlink($file);
                     $disk_size = $this->cache_size * 2 / 3;
                     if ($cache_size <= $disk_size * Config::instance()->core['update_ratio'] / 100) {
                         break;
                     }
                 }
                 unset($cache_list, $file);
             }
             if (($return = file_put_contents(CACHE . "/{$item}", $data, LOCK_EX | FILE_BINARY)) !== false) {
                 ftruncate($cache_size_file, 0);
                 fseek($cache_size_file, 0);
                 fwrite($cache_size_file, $cache_size > 0 ? $cache_size : 0);
             }
             flock($cache_size_file, LOCK_UN);
             fclose($cache_size_file);
             return $return;
         } else {
             return file_put_contents(CACHE . "/{$item}", $data, LOCK_EX | FILE_BINARY);
         }
     } else {
         $L = Language::instance();
         trigger_error($L->file . ' ' . CACHE . "/{$item} {$L->not_writable}", E_USER_WARNING);
         return false;
     }
 }