/**
  * $mode LOCK_SH | LOCK_EX
  */
 public static function lock($mode, $lock_file_name = 'global')
 {
     if (self::$_fIsLocked) {
         return false;
     }
     $lock_file = CConf::get('cache_dir') . $lock_file_name . '.lock';
     self::$_fLockFileHandler = new CFile($lock_file);
     self::$_fLockFileHandler->open('w');
     if (!self::$_fLockFileHandler->isError()) {
         CProfiler::lockStart();
         self::$_fLockFileHandler->lock($mode);
         CProfiler::lockStop();
         self::$_fIsLocked = true;
         return true;
     } else {
         return false;
     }
 }
 function getImageInfo()
 {
     global $application;
     $imageInfo = array('largeimage' => array('url' => '', 'width' => '', 'height' => '', 'is_exist' => false), 'smallimage' => array('url' => '', 'width' => 0, 'height' => 0, 'is_exist' => false));
     $images_dir = $application->getAppIni('PATH_IMAGES_DIR');
     $images_url = $application->getAppIni('URL_IMAGES_DIR');
     if ($application->getCurrentProtocol() == "https" && $application->getAppIni('HTTPS_URL_IMAGES_DIR')) {
         $images_url = $application->getAppIni('HTTPS_URL_IMAGES_DIR');
     }
     $gc_images = CConf::get('gc_image_name');
     foreach ($gc_images as $id => $fname) {
         if (file_exists($images_dir . $fname)) {
             $imageInfo[$id] = array('url' => $images_url . $fname, 'is_exist' => true);
             $size = @getimagesize($images_dir . $fname);
             if ($size !== false && isset($size[0]) && isset($size[1])) {
                 $imageInfo[$id]['width'] = $size[0];
                 $imageInfo[$id]['height'] = $size[1];
             }
         }
     }
     return $imageInfo;
 }
Example #3
0
<?php

/***********************************************************************
| Avactis (TM) Shopping Cart software developed by HBWSL.
| http://www.avactis.com
| -----------------------------------------------------------------------
| All source codes & content (c) Copyright 2004-2010, HBWSL.
| unless specifically noted otherwise.
| =============================================
| This source code is released under the Avactis License Agreement.
| The latest version of this license can be found here:
| http://www.avactis.com/license.php
|
| By using this software, you acknowledge having read this license agreement
| and agree to be bound thereby.
|
 ***********************************************************************/
/**
 * @package DataConverter
 * @author Oleg F. Vlasenko, Egor V. Derevyankin
 *
 */
define('DC_SCRIPTS_DEFINITION_FILE', CConf::get('modules_dir') . 'data_converter/includes/scripts.xml');
define('DC_WORKER_TIME_OUT', 1);
define('CSV_HEADER_RX', '/.*/');
 protected static function _createCacheStorage($cache_storage_name)
 {
     $cache_storages = CConf::get('cache_storages');
     if (is_array($cache_storages) && isset($cache_storages[$cache_storage_name])) {
         $cache_storage_descr = $cache_storages[$cache_storage_name];
         if (!isset($cache_storage_descr['driver'])) {
             throw new Exception("Failed to create cache storage object '{$cache_storage_name}', because the configuration (conf.main.php) file does not contain the driver record for this cache storage.");
         }
         $driver = $cache_storage_descr['driver'];
         $args = isset($cache_storage_descr['args']) ? $cache_storage_descr['args'] : array();
         $driver_obj = null;
         switch (count($args)) {
             case 0:
                 $driver_obj = new $driver();
                 break;
             case 1:
                 $driver_obj = new $driver($args[0]);
                 break;
             case 2:
                 $driver_obj = new $driver($args[0], $args[1]);
                 break;
             default:
                 throw new Exception("Failed to create cache storage driver!");
                 break;
         }
         $store_uid = 'global_' . sha1(CConf::get('base_dir'));
         return new CCacheStorageWrapperNamespace(new CCacheStorage($driver_obj), $store_uid);
     } else {
         throw new Exception("Failed to create cache storage object! Request cache storage to create is '{$cache_storage_name}'. The configuration (conf.main.php) file does not contain the creation description.");
     }
 }
 /**
  * Use avactis-system/admin/index.php?asc_action=combine_php
  */
 function combinePreloadedPHP()
 {
     global $application;
     $mm = $application->getInstance('Modules_Manager');
     $sys_dir = CConf::get('system_dir');
     $modules_dir = CConf::get('modules_dir');
     $add_modules_dir = CConf::get('add_modules_dir');
     $conf_core = CConf::get('preload_core_php');
     $core_files = array();
     foreach ($conf_core['files'] as $file) {
         $core_files[] = realpath($sys_dir . $file);
     }
     if ($php = fopen($conf_core['combined_file'], 'w')) {
         $this->addPhpFiles($php, array_filter($core_files));
         $file = new CFile($application->appIni['PATH_TAGS_FILE']);
         $tags = $file->getLines();
         if (is_array($tags)) {
             foreach ($tags as $tag) {
                 fwrite($php, "if (! function_exists('{$tag}')) {\n" . $application->getTagFunction($tag) . "\n} else { \nCTrace::inf('Registering tag: function \\'{$tag}\\' is already defined.'); }\n");
                 fwrite($php, "if (! function_exists('get{$tag}')) {\n" . $application->getTagGetFunction($tag) . "\n} else { \nCTrace::inf('Registering tag: function \\'get{$tag}\\' is already defined.'); }\n");
                 fwrite($php, "if (! function_exists('getVal{$tag}')) {\n" . $application->getTagGetValFunction($tag) . "\n} else { \nCTrace::inf('Registering tag: function \\'getVal{$tag}\\' is already defined.'); }\n");
             }
             fwrite($php, "\ndefine('GLOBAL_TAGS_REGISTERED', 'yes');\n");
         }
         fclose($php);
     }
     $modules_core = CConf::get('preload_modules_php');
     $modules_files = array();
     foreach ($modules_core['files'] as $file) {
         if (is_file(realpath($add_modules_dir . $file))) {
             $modules_files[] = realpath($add_modules_dir . $file);
         } else {
             $modules_files[] = realpath($modules_dir . $file);
         }
     }
     foreach ($mm->moduleList as $module_name => $moduleInfo) {
         // see using of COMPILED_MODULES_LOADED constant
         if (isset($moduleInfo->constantsFile)) {
             $const_file = realpath($modules_dir . $moduleInfo->directory . $moduleInfo->constantsFile);
             if (!in_array($const_file, $modules_files) && !in_array($const_file, $core_files)) {
                 $modules_files[] = $const_file;
             }
         }
         $queries_file = realpath($modules_dir . $moduleInfo->directory . 'dbqueries/common.php');
         if (!in_array($queries_file, $modules_files) && !in_array($queries_file, $core_files)) {
             $modules_files[] = $queries_file;
         }
     }
     if ($php = fopen($modules_core['combined_file'], 'w')) {
         $this->addPhpFiles($php, array_filter($modules_files));
         fwrite($php, "\ndefine('COMPILED_MODULES_LOADED', 'yes');\n");
         fclose($php);
     }
     $conf_modules_views_cz = CConf::get('preload_modules_views_cz_php');
     $modules_files = array();
     foreach ($conf_modules_views_cz['files'] as $file) {
         if (is_file(realpath($add_modules_dir . $file))) {
             $modules_files[] = realpath($add_modules_dir . $file);
         } else {
             $modules_files[] = realpath($modules_dir . $file);
         }
     }
     if ($php = fopen($conf_modules_views_cz['combined_file'], 'w')) {
         $this->addPhpFiles($php, array_filter($modules_files));
         //            var_dump($mm->czViewList, $mm->czAliasesList);
         foreach (array_keys($mm->czViewList) as $view) {
             fwrite($php, "\nif (! function_exists('{$view}')) {\n    " . $mm->getViewFunction($view) . "\n}\nelse {\n    CTrace::inf('Registering module view: function \\'{$view}\\' is already defined.');\n}\nif (! function_exists('get{$view}')) {\n    " . $mm->getViewGetFunction($view) . "\n}\nelse {\n    CTrace::inf('Registering module view: function \\'get{$view}\\' is already defined.');\n}");
         }
         foreach ($mm->czAliasesList as $alias_name => $view_name) {
             fwrite($php, "\nif (! function_exists('{$alias_name}')) {\n    " . $mm->getAliasFunction($alias_name, $view_name) . "\n}\nelse {\n    CTrace::inf('Registering module alias: function \\'{$alias_name}\\' is already defined.');\n}\nif (! function_exists('get{$alias_name}')) {\n    " . $mm->getAliasGetFunction($alias_name, $view_name) . "\n}\nelse {\n    CTrace::inf('Registering module alias: function \\'get{$alias_name}\\' is already defined.');\n}");
         }
         fwrite($php, "\ndefine('MODULES_VIEWS_REGISTERED', 'yes');\n");
         fclose($php);
     }
 }
Example #6
0
 static function writeCSV()
 {
     if (!self::$write_csv) {
         return;
     }
     $profiler_dir = CConf::get('cache_dir');
     $request_id = substr(md5(microtime(true)), 0, 6);
     global $zone;
     $requests_csv = $profiler_dir . 'requests.csv';
     self::prepareCSV($requests_csv, array('zone', 'script', 'request'));
     self::writeCSVRecords($requests_csv, $request_id, array(array($zone == 'AdminZone' ? 'AZ' : 'CZ', $_SERVER['SCRIPT_NAME'], $_SERVER['QUERY_STRING'])));
     $general_csv = $profiler_dir . 'general.total.csv';
     self::prepareCSV($general_csv, self::$profiler->getFields());
     self::writeCSVRecords($general_csv, $request_id, array(self::$profiler->getData()));
     foreach (self::$stack as $key => $p) {
         $general_csv = $profiler_dir . 'general.' . self::prepareProfilerFileName($key) . '.csv';
         self::prepareCSV($general_csv, $p->getFields());
         self::writeCSVRecords($general_csv, $request_id, array($p->getData()));
     }
     if (self::$display_cache) {
         $cache_stat = CCacheFactory::getStat('array');
         foreach ($cache_stat as $key => $cache_data) {
             $cache_csv = $profiler_dir . 'cache.' . strtolower($key) . '.csv';
             unset($cache_data['storage']['log']);
             $fields_storage = array_keys($cache_data['storage']);
             $fields_driver = array_keys($cache_data['driver']);
             array_walk($fields_storage, 'self::addCacheFieldPrefix', 'storage_');
             array_walk($fields_driver, 'self::addCacheFieldPrefix', 'driver_');
             self::prepareCSV($cache_csv, array_merge($fields_storage, $fields_driver));
             self::writeCSVRecords($cache_csv, $request_id, array(array_merge($cache_data['storage'], $cache_data['driver'])));
         }
     }
     if (self::$display_include) {
         $include_csv = $profiler_dir . 'include.csv';
         self::prepareCSV($include_csv, array('counter', 'file_path'));
         $records = array();
         foreach (self::$profiler->cnt_include as $file => $ctr) {
             $records[] = array($ctr, $file);
         }
         self::writeCSVRecords($include_csv, $request_id, $records);
     }
     if (self::$display_queries) {
         $queries_csv = $profiler_dir . 'queries.csv';
         self::prepareCSV($queries_csv, array('total', 'unique', 'executed', 'time_db_layer', 'query_name'));
         $records = array();
         foreach (self::$profiler->cnt_queries_executed as $query => $counter) {
             if ($counter > 1) {
                 $records[] = array(@$counter['all'], sizeof(@$counter['unique']), @$counter['really'], self::$profiler->timer_db_layer_queries[$query]->getTime(), $query);
             }
         }
         self::writeCSVRecords($queries_csv, $request_id, $records);
     }
     if (self::$display_file_io) {
         $file_io_csv = $profiler_dir . 'file_io.csv';
         self::prepareCSV($file_io_csv, array('read', 'write', 'read-write', 'parse', 'test', 'delete', 'file'));
         $records = array();
         foreach (self::$profiler->cnt_file_io as $file => $cntrs) {
             $records[] = array((int) @$cntrs['read'], (int) @$cntrs['write'], (int) @$cntrs['read-write'], (int) @$cntrs['parse'], (int) @$cntrs['test'], (int) @$cntrs['delete'], $file);
         }
         self::writeCSVRecords($file_io_csv, $request_id, $records);
     }
     if (self::$display_block_tags) {
         $block_tags_csv = $profiler_dir . 'block_tags.csv';
         self::prepareCSV($block_tags_csv, array('counter', 'time', 'block_tag'));
         $records = array();
         foreach (self::$profiler->timer_block_tags as $block_tag => $time) {
             $records[] = array($time->getTotalCounter(), $time->getTime(), $block_tag);
         }
         self::writeCSVRecords($block_tags_csv, $request_id, $records);
     }
 }
function loadModuleFile($filename)
{
    global $application;
    $modules_dir = CConf::get('modules_dir');
    $add_modules_dir = CConf::get('add_modules_dir');
    if (is_file($add_modules_dir . $filename)) {
        _use($add_modules_dir . $filename);
    } else {
        _use($modules_dir . $filename);
    }
}
Example #8
0
 /**
  * Prepares the query of type CREATE TABLE.
  *
  * @ to finish the function
  * @return a string, containing the SQL query 'CREATE'
  * @param DB_Table_Create object $QueryData
  */
 function PrepareCreateQuery($QueryData)
 {
     self::$table_list_cache = null;
     $SQL = ' CREATE TABLE ';
     $table = $QueryData->getTable();
     $SQL .= $table . ' (';
     $fields = $QueryData->getFields();
     if (sizeof($fields) > 0) {
         foreach ($fields as $val) {
             $SQL .= $val['field_name'] . ' ' . $val['field_type'] . ' ' . $val['field_NULL'] . ' ' . ($val['field_default'] != '' ? 'default ' . $val['field_default'] : '') . ' ' . $val['field_extras'] . ",\n";
         }
     }
     $keys = $QueryData->getKeys();
     if (sizeof($keys) > 0) {
         $SQL .= 'PRIMARY KEY (' . implode(', ', $keys) . "),\n";
     }
     $indexes = $QueryData->getIndexes();
     if (sizeof($indexes) > 0) {
         foreach ($indexes as $key => $val) {
             if (_ml_strpos(_ml_strtoupper($val), "UNIQUE") === 0) {
                 $SQL .= ' ' . $val . ' (' . $key . "),\n";
             } elseif (_ml_strpos(_ml_strtoupper($val), "FULLTEXT") === 0) {
                 $SQL .= ' ' . $val . ' (' . $key . "),\n";
             } else {
                 $SQL .= ' INDEX ' . $val . ' (' . $key . "),\n";
             }
         }
     }
     if ($SQL[_byte_strlen($SQL) - 2] == ',') {
         $SQL = _byte_substr($SQL, 0, _byte_strlen($SQL) - 2);
     }
     $table_engine = CConf::get('mysql_table_engine');
     $SQL .= ") ENGINE={$table_engine} DEFAULT CHARSET=utf8";
     return $SQL;
 }
Example #9
0
 public static function init($confdir)
 {
     include $confdir . 'conf.main.php';
     @(include $confdir . 'conf.local.php');
     self::$conf = $conf;
 }
Example #10
0
set_error_handler('__error_handler__', E_ERROR);
register_shutdown_function('__shutdown__');
include_once $_core_directory . 'bootstrap.php';
include_once $_core_directory . 'const.php';
include_once $_core_directory . 'ctimer.php';
include_once $_core_directory . 'profiler.php';
include_once $_core_directory . 'cfile.php';
include_once $_core_directory . 'trace.php';
include_once $_core_directory . 'tracefilter.php';
include_once $_core_directory . 'tracelogrotation.php';
include_once $_core_directory . 'tracewriter.php';
include_once $_core_directory . 'upgrade.php';
CConf::init(dirname(__FILE__) . '/conf/');
CProfiler::init();
// init default trace loggers
$tracelog = CConf::get('tracelog');
if ($tracelog) {
    CTrace::startScript();
    CTrace::setId(getmypid());
    foreach ($tracelog as $trace_cfg) {
        if ($trace_cfg['enabled'] == 'yes') {
            $r = new CTraceLogRotation($trace_cfg['file'], $trace_cfg['rotation']['size'], $trace_cfg['rotation']['rotate']);
            $r->rotate();
            $tw = new CTraceWriter($trace_cfg['file'], $trace_cfg['template'], new CTraceFilter($trace_cfg['filter']));
            CTrace::registerWriter($tw);
        }
    }
}
// must be defined after CTrace initialization.
// all php notices, warnings and errors will be logged, so we need to set E_ALL level
//error_reporting(E_ERROR);
 public static function saveThemeCss($theme_name, $stylesheets, $skin = null)
 {
     if (!$skin) {
         $skin = modApiFunc('Configuration', 'getValue', STOREFRONT_ACTIVE_SKIN);
     }
     $backup_path = CConf::get('themes_backup_dir') . $skin . '.' . $theme_name . date('.Y-m-d.H-i-s') . '.css';
     $file = new CFile($backup_path);
     $file->putContent($stylesheets);
     $theme_path = self::getThemePath($theme_name, $skin);
     $file = new CFile($theme_path);
     if ($file->putContent($stylesheets)) {
         return array('result' => self::OK, 'message' => '');
     }
     return array('result' => self::FAIL, 'message' => getXMsg('LF', 'LF_THEME_CANT_WRITE'), 'what_to_do' => strtr(getXMsg('LF', 'LF_THEME_PERMISSIONS'), array('%theme_file%' => $theme_path)), 'path' => $theme_path);
 }