/** * Smarty plugin * @package Smarty * @subpackage plugins */ function smarty_function_script($params, &$smarty) { static $scripts = array(); static $packer_loaded = false; /*if (!empty($params['include'])) { return implode("\n", $scripts); }*/ if (!isset($scripts[$params['src']])) { $path = Registry::get('config.current_path'); if (Registry::get('config.tweaks.js_compression') == true && strpos($params['src'], 'lib/') === false) { if (!file_exists(DIR_CACHE . $params['src'])) { if ($packer_loaded == false) { include_once DIR_LIB . 'packer/class.JavaScriptPacker.php'; $packer_loaded = true; } fn_mkdir(dirname(DIR_CACHE . $params['src'])); $packer = new JavaScriptPacker(fn_get_contents(DIR_ROOT . '/' . $params['src'])); fn_put_contents(DIR_CACHE . $params['src'], $packer->pack()); } $path = Registry::get('config.cache_path'); } $scripts[$params['src']] = '<script type="text/javascript" src="' . $path . '/' . $params['src'] . '"></script>'; // If output is captured, don't print script tag in the buffer, it will be printed directly to the screen if (!empty($smarty->_in_capture)) { $buff = array_pop($smarty->_in_capture); $smarty->_in_capture[] = $buff; $smarty->_scripts[$buff][] = $scripts[$params['src']]; return ''; } return $scripts[$params['src']]; } }
public static function process_sbrf_currencies($primary_currency = CART_PRIMARY_CURRENCY) { $date = date('d/m/Y'); $link = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req=' . $date; $xml = @simplexml_load_string(fn_get_contents($link)); $sbrf_currencies = self::format_sbrf_currensies($xml); if (empty($sbrf_currencies) || $primary_currency != CURRENCY_RUB && !isset($sbrf_currencies[$primary_currency])) { return false; } $currencies = Registry::get('currencies'); if ($primary_currency != CURRENCY_RUB) { if (isset($sbrf_currencies[$primary_currency]) && isset($currencies[CURRENCY_RUB])) { $primary_coefficient = $sbrf_currencies[$primary_currency]['nominal'] / $sbrf_currencies[$primary_currency]['value']; $currency_data = array('coefficient' => $primary_coefficient); db_query("UPDATE ?:currencies SET ?u WHERE currency_code = ?s", $currency_data, CURRENCY_RUB); } unset($sbrf_currencies[$primary_currency]); foreach ($currencies as $curr_code => $curr_data) { if (isset($sbrf_currencies[$curr_code])) { $coefficient_rub = $sbrf_currencies[$curr_code]['nominal'] / $sbrf_currencies[$curr_code]['value']; $currency_data = array('coefficient' => $primary_coefficient / $coefficient_rub); db_query("UPDATE ?:currencies SET ?u WHERE currency_code = ?s ", $currency_data, $curr_code); } } } else { foreach ($currencies as $curr_code => $curr_data) { if (isset($sbrf_currencies[$curr_code])) { $currency_data = array('coefficient' => $sbrf_currencies[$curr_code]['value'] / $sbrf_currencies[$curr_code]['nominal']); db_query("UPDATE ?:currencies SET ?u WHERE currency_code = ?s ", $currency_data, $curr_code); } } } return true; }
function fn_replace_rewrite_condition($file_name, $condition, $comment) { if (!empty($condition)) { $condition = "\n" . "# {$comment}\n" . "<IfModule mod_rewrite.c>\n" . "RewriteEngine on\n" . $condition . "</IfModule>\n" . "# /{$comment}"; } $content = fn_get_contents($file_name); if ($content === false) { $content = ''; } elseif (!empty($content)) { // remove old instructions $data = explode("\n", $content); $remove_start = false; foreach ($data as $k => $line) { if (preg_match("/# {$comment}/", $line)) { $remove_start = true; } if ($remove_start) { unset($data[$k]); } if (preg_match("/# \\/{$comment}/", $line)) { $remove_start = false; } } $content = implode("\n", $data); } $content .= $condition; return fn_put_contents($file_name, $content); }
/** * Smarty plugin * @package Smarty * @subpackage plugins */ function smarty_block_scripts($params, $content, &$smarty, &$repeat) { if ($repeat == true) { Registry::set('runtime.inside_scripts', 1); return; } if (Registry::get('config.tweaks.dev_js')) { $content .= smarty_helper_inline_scripts($params, $content, $smarty, $repeat); return $content; } $scripts = array(); $external_scripts = array(); $dir_root = Registry::get('config.dir.root'); $return = ''; $current_location = Registry::get('config.current_location'); if (preg_match_all('/\\<script(.*?)\\>(.*?)\\<\\/script\\>/s', $content, $m)) { $contents = ''; foreach ($m[1] as $src) { if (!empty($src) && preg_match('/src ?= ?"([^"]+)"/', $src, $_m)) { if (strpos($_m[1], $current_location) !== false) { $scripts[] = str_replace($current_location, '', preg_replace('/\\?.*?$/', '', $_m[1])); } else { $external_scripts[] = $_m[1]; } } } // Check file changes in dev mode $names = $scripts; if (Development::isEnabled('compile_check')) { foreach ($names as $index => $name) { if (is_file($dir_root . '/' . $name)) { $names[$index] .= filemtime($dir_root . '/' . $name); } } } $filename = 'js/tygh/scripts-' . md5(implode(',', $names)) . fn_get_storage_data('cache_id') . '.js'; if (!Storage::instance('statics')->isExist($filename)) { foreach ($scripts as $src) { $contents .= fn_get_contents(Registry::get('config.dir.root') . $src); } $contents = str_replace('[files]', implode("\n", $scripts), Registry::get('config.js_css_cache_msg')) . $contents; $contents = Minifier::minify($contents, array('flaggedComments' => false)); Storage::instance('statics')->put($filename, array('contents' => $contents, 'compress' => false, 'caching' => true)); } $return = '<script type="text/javascript" src="' . Storage::instance('statics')->getUrl($filename) . '?ver=' . PRODUCT_VERSION . '"></script>' . "\n"; if (!empty($external_scripts)) { foreach ($external_scripts as $sc) { $return .= '<script type="text/javascript" src="' . $sc . '"></script>' . "\n"; } } foreach ($m[2] as $sc) { if (!empty($sc)) { $return .= '<script type="text/javascript">' . $sc . '</script>' . "\n"; } } $return .= smarty_helper_inline_scripts($params, $content, $smarty, $repeat); } return $return; }
static function init() { if (!is_dir(DIR_CACHE)) { fn_mkdir(DIR_CACHE); } $ch = fn_get_contents(DIR_CACHE . self::$_handlers_name); self::$_cache_handlers = !empty($ch) ? @unserialize($ch) : array(); return true; }
public function acquireLock($key, $cache_level) { $fname = $this->_mapTags('locks') . '/' . $key . $cache_level; if (file_exists($fname)) { $ttl = fn_get_contents($fname); if ($ttl < time()) { // lock expired return fn_put_contents($fname, time() + Registry::LOCK_EXPIRY); } } else { return fn_put_contents($fname, time() + Registry::LOCK_EXPIRY); } return false; }
function fn_get_google_categories($lang_code = DEFAULT_LANGUAGE) { $urls = fn_google_export_available_categories(); if (empty($urls[$lang_code])) { return false; } $url = $urls[$lang_code]; $content = fn_get_contents($url); if ($content) { $result = explode("\n", $content); $result = array_diff($result, array('')); return array_slice($result, 1); } return false; }
/** * Downloads upgrade package from the Upgade server * * @param array $schema Package schema * @param string $package_path Path where the upgrade pack must be saved * @return bool True if upgrade package was successfully downloaded, false otherwise */ public function downloadPackage($schema, $package_path) { $data = fn_get_contents(Registry::get('config.resources.updates_server') . '/index.php?dispatch=product_updates.get_package&package_id=' . $schema['package_id'] . '&edition=' . PRODUCT_EDITION . '&license_number=' . $this->uc_settings['license_number']); if (!empty($data)) { fn_put_contents($package_path, $data); if (md5_file($package_path) == $schema['md5']) { $result = array(true, ''); } else { fn_rm($package_path); $result = array(false, __('text_uc_broken_package')); } } else { $result = array(false, __('text_uc_cant_download_package')); } return $result; }
/** * Smarty plugin * @package Smarty * @subpackage plugins */ function smarty_block_scripts($params, $content, &$smarty, &$repeat) { if ($repeat == true) { return; } if (Registry::get('config.tweaks.dev_js')) { return $content; } $scripts = array(); $dir_root = Registry::get('config.dir.root'); $return = ''; if (preg_match_all('/\\<script(.*?)\\>(.*?)\\<\\/script\\>/s', $content, $m)) { $contents = ''; foreach ($m[1] as $src) { if (!empty($src) && preg_match('/src ?= ?"([^"]+)"/', $src, $_m)) { $scripts[] = str_replace(Registry::get('config.current_location'), '', preg_replace('/\\?.*?$/', '', $_m[1])); } } // Check file changes in dev mode $names = $scripts; if (Development::isEnabled('compile_check')) { foreach ($names as $index => $name) { if (is_file($dir_root . '/' . $name)) { $names[$index] .= filemtime($dir_root . '/' . $name); } } } $gz_suffix = Registry::get('config.tweaks.gzip_css_js') ? '.gz' : ''; $filename = 'js/tygh/scripts-' . md5(implode(',', $names)) . fn_get_storage_data('cache_id') . '.js'; if (!Storage::instance('statics')->isExist($filename . $gz_suffix)) { foreach ($scripts as $src) { $contents .= fn_get_contents(Registry::get('config.dir.root') . $src); } $contents = str_replace('[files]', implode("\n", $scripts), Registry::get('config.js_css_cache_msg')) . $contents; Storage::instance('statics')->put($filename . $gz_suffix, array('contents' => $contents, 'compress' => Registry::get('config.tweaks.gzip_css_js'), 'caching' => true)); } $return = '<script type="text/javascript" src="' . Storage::instance('statics')->getUrl($filename) . '?ver=' . PRODUCT_VERSION . '"></script>'; foreach ($m[2] as $sc) { if (!empty($sc)) { $return .= '<script type="text/javascript">' . $sc . '</script>' . "\n"; } } } return $return; }
public static function updateUaRules() { $update_needed = false; if (!file_exists(TWIGMO_UA_RULES_FILE)) { $update_needed = true; } else { $rules_serialized = fn_get_contents(TWIGMO_UA_RULES_FILE); $md5_on_twigmo = Http::get(TWG_CHECK_UA_UPDATES); if (md5($rules_serialized) != $md5_on_twigmo) { $update_needed = true; } } if (!$update_needed) { return; } $rules_on_twigmo = Http::get(TWG_UA_RULES); fn_twg_write_to_file(TWIGMO_UA_RULES_FILE, $rules_on_twigmo, false); }
public function downloadPackage($schema, $package_path) { if (!empty($schema['download_key'])) { $upgrade_path = $this->settings['packages_server'] . $this->settings['addon'] . '/' . $schema['file']; $addon_upgrades_dir = Registry::get('config.dir.addons') . $this->settings['addon'] . '/upgrades/'; $addon_upgrades_path = $addon_upgrades_dir . $schema['file']; if (!file_exists($addon_upgrades_path)) { fn_mkdir($addon_upgrades_dir); $addon_upgrade_data = fn_get_contents($upgrade_path); fn_put_contents($addon_upgrades_path, $addon_upgrade_data); } $result = fn_copy($addon_upgrades_path, $package_path); if ($result) { fn_rm($addon_upgrades_path); } //cleanup $message = $result ? '' : __('failed') . '-' . $addon_upgrades_path; return array($result, $message); } else { return array(false, __($schema['error_message'])); } }
function get_data($url) { if (is_numeric($url)) { return new FetchedDataURL($this->content[$url], array(), ""); } else { if (substr($url, 0, 8) == 'file:///') { $url = substr($url, 10); if (defined('IS_WINDOWS')) { $url = substr($url, 1); } } if (strpos($url, Registry::get('config.http_location')) === 0) { $file = str_replace(Registry::get('config.http_location'), DIR_ROOT, $url); } elseif (strpos($url, Registry::get('config.https_location')) === 0) { $file = str_replace(Registry::get('config.https_location'), DIR_ROOT, $url); } if (!empty($file) && file_exists($file)) { $result = fn_get_contents($file); } else { list(, $result) = fn_http_request('GET', $url); } return new FetchedDataURL($result, array(), ""); } }
/** * Get data from url * * @param string $val * @return array $val */ function fn_get_url_data($val) { if (!preg_match('/:\\/\\//', $val)) { $val = 'http://' . $val; } $result = false; $_data = fn_get_contents($val); if (!empty($_data)) { $result = array('name' => fn_basename($val)); // Check if the file is dynamically generated if (strpos($result['name'], '&') !== false || strpos($result['name'], '?') !== false) { $result['name'] = 'url_uploaded_file_' . uniqid(TIME); } $result['path'] = fn_create_temp_file(); $result['size'] = strlen($_data); $fd = fopen($result['path'], 'wb'); fwrite($fd, $_data, $result['size']); fclose($fd); @chmod($result['path'], DEFAULT_FILE_PERMISSIONS); $cache = Registry::get('temp_fs_data'); if (!isset($cache[$result['path']])) { // cache file to allow multiple usage $cache[$result['path']] = $result['path']; Registry::set('temp_fs_data', $cache); } } return $result; }
public static function checkStoreImportAvailability($license_number, $version, $edition = PRODUCT_EDITION) { $request = array('dispatch' => 'product_updates.check_storeimport_available', 'license_key' => $license_number, 'ver' => $version, 'edition' => $edition); $data = Http::get(Registry::get('config.resources.updates_server'), $request, array('timeout' => 10)); if (empty($data)) { $data = fn_get_contents(Registry::get('config.resources.updates_server') . '/index.php?' . http_build_query($request)); } $result = false; if (!empty($data)) { // Check if we can parse server response if (strpos($data, '<?xml') !== false) { $xml = simplexml_load_string($data); $result = (string) $xml == 'Y' ? true : false; } } return $result; }
// Set system notifications if (Registry::get('config.demo_mode') != true && AREA == 'A' && !defined('DEVELOPMENT')) { // If username equals to the password if ($password == $user_data['user_login']) { $msg = fn_get_lang_var('warning_insecure_password'); $msg = str_replace('[link]', fn_url('profiles.update'), $msg); fn_set_notification('E', fn_get_lang_var('warning'), $msg, true, 'insecure_password'); } // Insecure admin script if (Registry::get('config.admin_index') == 'admin.php') { fn_set_notification('E', fn_get_lang_var('warning'), fn_get_lang_var('warning_insecure_admin_script'), true); } if (Registry::get('settings.General.auto_check_updates') == 'Y' && fn_check_user_access($auth['user_id'], 'upgrade_store')) { // If upgrades available $uc_settings = fn_get_settings('Upgrade_center'); $data = fn_get_contents($uc_settings['updates_server'] . '/index.php?target=product_updates&mode=check_available&ver=' . PRODUCT_VERSION); /* NULLED BY FLIPMODE! @ 2010/09/06 */ // $data = fn_get_contents($uc_settings['updates_server'] . '/index.php?target=product_updates&mode=check_available&ver=' . PRODUCT_VERSION . '&license_number=' . $uc_settings['license_number']); if ($data == 'AVAILABLE') { $msg = fn_get_lang_var('text_upgrade_available'); $msg = str_replace('[link]', fn_url('upgrade_center.manage'), $msg); fn_set_notification('W', fn_get_lang_var('notice'), $msg, true, 'upgrade_center'); } } } if (!empty($_REQUEST['remember_me'])) { fn_set_cookie(AREA_NAME . '_user_id', $user_data['user_id'], COOKIE_ALIVE_TIME); fn_set_cookie(AREA_NAME . '_password', $user_data['password'], COOKIE_ALIVE_TIME); } // Set last login time db_query("UPDATE ?:users SET ?u WHERE user_id = ?i", array('last_login' => TIME), $user_data['user_id']);
/** * Get data from url * * @param string $val * @return array $val */ function fn_get_url_data($val) { $tmp = fn_strip_slashes($val); $_data = fn_get_contents($tmp); if (!empty($_data)) { $val = array(); $val['name'] = basename($tmp); // Check if the file is dynamically generated if (strpos($val['name'], '&') !== false || strpos($val['name'], '?') !== false) { $val['name'] = 'url_uploaded_file_' . uniqid(TIME); } $val['path'] = fn_create_temp_file(); $val['size'] = strlen($_data); $fd = fopen($val['path'], 'wb'); fwrite($fd, $_data, $val['size']); fclose($fd); @chmod($val['path'], DEFAULT_FILE_PERMISSIONS); $cache =& Registry::get('temp_fs_data'); if (!isset($cache[$val['path']])) { // cache file to allow multiple usage $cache[$val['path']] = $val['path']; } } return $val; }
} else { fn_set_notification('E', __('error'), __('you_have_no_permissions')); } exit; } elseif ($mode == 'restore') { $copied = false; $file_path = fn_te_normalize_path($_REQUEST, $root_dir); if (fn_te_check_path($file_path)) { $repo_path = str_replace($root_dir, fn_te_get_root('repo'), $file_path); if (!file_exists($repo_path) && fn_get_theme_path('[theme]') != Registry::get('config.base_theme') && is_dir(fn_get_theme_path('[repo]/[theme]'))) { $repo_path = preg_replace("/\\/themes_repository\\/(\\w+)\\//", "/themes_repository/" . Registry::get('config.base_theme') . "/", $repo_path); } $object_base = is_file($repo_path) ? 'file' : (is_dir($repo_path) ? 'directory' : ''); if (!empty($object_base) && fn_copy($repo_path, $file_path)) { fn_set_notification('N', __('notice'), __("text_{$object_base}_restored", array("[{$object_base}]" => fn_basename($file_path)))); Tygh::$app['ajax']->assign('content', fn_get_contents($file_path)); $copied = true; } } if (!$copied) { $object_base = empty($object_base) ? 'file' : $object_base; fn_set_notification('E', __('error'), __("text_cannot_restore_{$object_base}", array("[{$object_base}]" => fn_basename($file_path)))); } return array(CONTROLLER_STATUS_REDIRECT, 'templates.init_view?dir=' . $_REQUEST['file_path'] . '/' . $_REQUEST['file']); } /** * Checks if working path is inside root directory * @param string $path working path * @return boolean true of success, false - otherwise */ function fn_te_check_path($path)
/** * Returns image width, height, mime type and local path to image * * @param string $file path to image * @return array array with width, height, mime type and path */ function fn_get_image_size($file) { // File is url, get it and store in temporary directory if (strpos($file, '://') !== false) { $tmp = fn_create_temp_file(); if (fn_put_contents($tmp, fn_get_contents($file)) == 0) { return false; } $file = $tmp; } list($w, $h, $t, $a) = @getimagesize($file); if (empty($w)) { return false; } $t = image_type_to_mime_type($t); return array($w, $h, $t, $file); }
$image_path = 'sess_data/' . fn_basename($_REQUEST['image']); if (Storage::instance('custom_files')->isExist($image_path)) { $real_path = Storage::instance('custom_files')->getAbsolutePath($image_path); list(, , $image_type, $tmp_path) = fn_get_image_size($real_path); if ($type == 'T') { $thumb_path = $image_path . '_thumb'; if (!Storage::instance('custom_files')->isExist($thumb_path)) { // Output a thumbnail image list($cont, $format) = fn_resize_image($tmp_path, Registry::get('settings.Thumbnails.product_lists_thumbnail_width'), Registry::get('settings.Thumbnails.product_lists_thumbnail_height'), Registry::get('settings.Thumbnails.thumbnail_background_color')); if (!empty($cont)) { Storage::instance('custom_files')->put($thumb_path, array('contents' => $cont)); } } $real_path = Storage::instance('custom_files')->getAbsolutePath($thumb_path); } header('Content-type: ' . $image_type); fn_echo(fn_get_contents($real_path)); exit; } // Not image file. Display spacer instead. header('Content-type: image/gif'); readfile(fn_get_theme_path('[themes]/[theme]') . '/media/images/spacer.gif'); exit; } elseif ($mode == 'thumbnail') { $img = fn_generate_thumbnail($_REQUEST['image_path'], $_REQUEST['w'], $_REQUEST['h']); if (!empty($img)) { header('Content-type: ' . fn_get_file_type($img)); fn_echo(fn_get_contents($img)); } exit; }
/** * Makes diff between original and latest snapshots * @param array $params $_REQUEST params * @return array array with changed data */ public static function changes($params) { $results = array(); $creation_time = 0; $changes_tree = array(); $db_diff = ''; $db_d_diff = ''; $dist_filename = self::getName('dist'); $snapshot_filename = self::getName('current'); if (is_file($dist_filename)) { if (is_file($snapshot_filename)) { include $snapshot_filename; include $dist_filename; list($added, $changed, $deleted) = self::diff($snapshot, $snapshot_dist); foreach ($snapshot['themes'] as $theme_name => $data) { $data_dist = self::buildTheme($theme_name, $snapshot_dist); list($theme_added, $theme_changed, $theme_deleted) = self::diff($data, $data_dist); self::arrayMerge($added, $theme_added); self::arrayMerge($changed, $theme_changed); self::arrayMerge($deleted, $theme_deleted); } $tree = self::buildTree(array('added' => $added, 'changed' => $changed, 'deleted' => $deleted)); $tables = db_get_fields('SHOW TABLES'); $creation_time = $snapshot['time']; $changes_tree = $tree; if (!empty($snapshot_dist['db_scheme'])) { $db_scheme = ''; foreach ($tables as $table) { if (!in_array($table, $snapshot_dist['db_tables'])) { continue; } $db_scheme .= "\nDROP TABLE IF EXISTS `" . $table . "`;\n"; $__scheme = db_get_row("SHOW CREATE TABLE {$table}"); $__scheme = array_pop($__scheme); $replaced_scheme = preg_replace('/ AUTO_INCREMENT=[0-9]*/i', '', $__scheme); if (!empty($replaced_scheme) && is_string($replaced_scheme)) { $__scheme = $replaced_scheme; } $db_scheme .= $__scheme . ";"; } $db_scheme = str_replace('default', 'DEFAULT', $db_scheme); $snapshot_dist['db_scheme'] = str_replace('default', 'DEFAULT', $snapshot_dist['db_scheme']); $db_diff = self::textDiff($snapshot_dist['db_scheme'], $db_scheme); } if (isset($params['db_ready']) && $params['db_ready'] == 'Y') { $snapshot_dir = Registry::get('config.dir.snapshots'); $s_r = fn_get_contents($snapshot_dir . 'cmp_release.sql'); $s_c = fn_get_contents($snapshot_dir . 'cmp_current.sql'); @ini_set('memory_limit', '255M'); $db_d_diff = self::textDiff($s_r, $s_c); } } $dist_filename = ''; } return array('creation_time' => $creation_time, 'changes_tree' => $changes_tree, 'db_diff' => $db_diff, 'db_d_diff' => $db_d_diff, 'dist_filename' => $dist_filename); }
/** * Fuctnions parses SQL file and import data from it * * @param string $file File for import * @param integer $buffer Buffer size for fread function * @param bool $show_status Show or do not show process by printing ' .' * @param integer $show_create_table 0 - Do not print the name of created table, 1 - Print name and get lang_var('create_table'), 2 - Print name without getting lang_var * @param bool $check_prefix Check table prefix and replace it with the installed in config.php * @param bool $track Use queries cache. Do not execute queries that already are executed. * @param bool $skip_errors Skip errors or not * @param bool $move_progress_bar Move COMET progress bar or not on show progress * @return bool false, if file is not accessible */ function db_import_sql_file($file, $buffer = 16384, $show_status = true, $show_create_table = 1, $check_prefix = false, $track = false, $skip_errors = false, $move_progress_bar = true) { if (file_exists($file)) { $path = dirname($file); $file_name = fn_basename($file); $tmp_file = $path . "/{$file_name}.tmp"; $executed_queries = array(); if ($track && file_exists($tmp_file)) { $executed_queries = unserialize(fn_get_contents($tmp_file)); } if ($skip_errors) { $_skip_errors = Registry::get('runtime.database.skip_errors'); Registry::set('runtime.database.skip_errors', true); } $fd = fopen($file, 'r'); if ($fd) { $ret = array(); $rest = ''; $fs = filesize($file); if ($show_status && $move_progress_bar) { fn_set_progress('step_scale', ceil($fs / $buffer)); } while (!feof($fd)) { $str = $rest . fread($fd, $buffer); $rest = fn_parse_queries($ret, $str); if ($show_status) { fn_set_progress('echo', '<br />' . __('importing_data'), $move_progress_bar); } if (!empty($ret)) { foreach ($ret as $query) { if (!in_array($query, $executed_queries)) { if ($show_create_table && preg_match('/CREATE\\s+TABLE\\s+`?(\\w+)`?/i', $query, $matches)) { if ($show_create_table == 1) { $_text = __('creating_table'); } elseif ($show_create_table == 2) { $_text = 'Creating table'; } $table_name = $check_prefix ? fn_check_db_prefix($matches[1], Registry::get('config.table_prefix')) : $matches[1]; if ($show_status) { fn_set_progress('echo', '<br />' . $_text . ': <b>' . $table_name . '</b>', $move_progress_bar); } } if ($check_prefix) { $query = fn_check_db_prefix($query); } Database::query($query); if ($track) { $executed_queries[] = $query; fn_put_contents($tmp_file, serialize($executed_queries)); } if ($show_status) { fn_echo(' .'); } } } $ret = array(); } } fclose($fd); return true; } if ($skip_errors) { Registry::set('runtime.database.skip_errors', $_skip_errors); } } return false; }
protected function tryImport($importPath, $parentBlock, $out) { if ($importPath[0] == "function" && $importPath[1] == "url") { $importPath = $this->flattenList($importPath[2]); } $str = $this->coerceString($importPath); if ($str === null) { return false; } $url = $this->compileValue($this->lib_e($str)); // don't import if it ends in css if (substr_compare($url, '.css', -4, 4) === 0) { return false; } $realPath = $this->findImport($url); if ($realPath === null) { return false; } if ($this->importDisabled) { return array(false, "/* import disabled */"); } if (isset($this->allParsedFiles[realpath($realPath)])) { return array(false, null); } $this->addParsedFile($realPath); $hash = md5($realPath); $cache_file = Registry::get('config.dir.cache_static') . '/less/' . $hash; $parser = $this->makeParser($realPath); $root = null; if (file_exists($cache_file) && filemtime($realPath) < filemtime($cache_file)) { $root = unserialize(fn_get_contents($cache_file)); } if (!is_object($root)) { $root = $parser->parse(fn_get_contents($realPath)); fn_mkdir(dirname($cache_file)); fn_put_contents($cache_file, serialize($root)); } // set the parents of all the block props foreach ($root->props as $prop) { if ($prop[0] == "block") { $prop[1]->parent = $parentBlock; } } // copy mixins into scope, set their parents // bring blocks from import into current block // TODO: need to mark the source parser these came from this file foreach ($root->children as $childName => $child) { if (isset($parentBlock->children[$childName])) { $parentBlock->children[$childName] = array_merge($parentBlock->children[$childName], $child); } else { $parentBlock->children[$childName] = $child; } } $pi = pathinfo($realPath); $dir = $pi["dirname"]; list($top, $bottom) = $this->sortProps($root->props, true); $this->compileImportedProps($top, $parentBlock, $out, $parser, $dir); return array(true, $bottom, $parser, $dir); }
function fn_twg_process_ua($ua) { $result = 'unknown'; if (!file_exists(TWIGMO_UA_RULES_FILE)) { return $result; } $rules = unserialize(fn_get_contents(TWIGMO_UA_RULES_FILE)); if (!is_array($rules)) { return $result; } $ua_meta = fn_twg_get_ua_meta($ua, $rules); // Save stat foreach ($ua_meta as $section => $value) { $where = array('section' => $section, 'value' => $value, 'month' => date('Y-m-1')); $count = db_get_field('SELECT count FROM ?:twigmo_ua_stat WHERE ?w', $where); if ($count) { db_query('UPDATE ?:twigmo_ua_stat SET count=count+1 WHERE ?w', $where); } else { $where['count'] = 1; db_query('INSERT INTO ?:twigmo_ua_stat ?e', $where); } } if ($ua_meta['device'] and in_array($ua_meta['device'], array('phone', 'tablet'))) { $result = $ua_meta['device']; } return $result; }
/** * Puts list of local files to storage * * @param array $list files list (relative path) * @param string $prefix absolute path prefix * @param array $params additional parameters list * @return boolean true on success, false if at least one put was failed */ public function putList($list, $prefix, $params = array()) { if (!empty($list)) { fn_set_progress('step_scale', sizeof($list)); foreach ($list as $item) { fn_set_progress('echo', '.'); if (strpos($prefix, '://') !== false) { $params['contents'] = fn_get_contents($prefix . $item); } else { $params['file'] = $prefix . $item; $params['keep_origins'] = true; } if (!$this->put($item, $params)) { return false; } } } return true; }
/** * Gets google font properties * @param string $font font name * @return array font properties */ private function getGoogleFontData($font) { if (empty($this->google_fonts)) { $fonts = fn_get_contents(Registry::get('config.dir.root') . '/js/tygh/google_fonts_list.js'); $this->google_fonts = json_decode($fonts, true); } foreach ($this->google_fonts as $sections => $fonts) { foreach ($fonts as $gfont) { if ($gfont['name'] == $font) { return $gfont; } } } return array(); }
$full_path = fn_get_theme_path('[themes]/[theme]', 'C') . '/templates/' . $_REQUEST['file']; if (fn_check_path($full_path)) { $c_name = fn_normalize_path($full_path); $r_name = fn_normalize_path(Registry::get('config.dir.themes_repository') . Registry::get('config.base_theme') . '/templates/' . $_REQUEST['file']); if (is_file($r_name)) { $copied = fn_copy($r_name, $c_name); } if ($copied) { fn_set_notification('N', __('notice'), __('text_file_restored', array('[file]' => fn_basename($_REQUEST['file'])))); } else { fn_set_notification('E', __('error'), __('text_cannot_restore_file', array('[file]' => fn_basename($_REQUEST['file'])))); } if ($copied) { if (defined('AJAX_REQUEST')) { Registry::get('ajax')->assign('force_redirection', fn_url($_REQUEST['current_url'])); Registry::get('ajax')->assign('non_ajax_notifications', true); } return array(CONTROLLER_STATUS_OK, $_REQUEST['current_url']); } } exit; } } if ($mode == 'get_content') { $ext = fn_strtolower(fn_get_file_ext($_REQUEST['file'])); if ($ext == 'tpl') { $theme_path = fn_get_theme_path('[themes]/[theme]/templates/', 'C'); Registry::get('ajax')->assign('content', fn_get_contents($_REQUEST['file'], $theme_path)); } exit; }
/** * Runs specified controller by including its file * * @param string $path path to controller * @return array controller return status */ function fn_run_controller($path, $controller, $mode, $action, $dispatch_extra) { static $check_included = array(); $auth =& $_SESSION['auth']; if (!empty($check_included[$path])) { $code = fn_get_contents($path); $code = str_replace(array('function fn', '<?php', '?>'), array('function _fn', '', ''), $code); return eval($code); } else { $check_included[$path] = true; return include $path; } }
// FIXME: Bacward preset compatibility if (!empty($_REQUEST['preset_id'])) { $_REQUEST['style_id'] = $_REQUEST['preset_id']; } Styles::factory(fn_get_theme_path('[theme]', 'C'))->delete($_REQUEST['style_id']); return array(CONTROLLER_STATUS_OK, 'theme_editor.view'); } elseif ($mode == 'get_css') { // FIXME: Backward presets compatibility if (!empty($_REQUEST['preset'])) { $_REQUEST['style'] = $_REQUEST['preset']; } $css_filename = !empty($_REQUEST['css_filename']) ? fn_basename($_REQUEST['css_filename']) : ''; $theme_name = fn_get_theme_path('[theme]', 'C'); $content = ''; if (!empty($css_filename)) { $content = fn_get_contents(fn_get_cache_path(false) . 'theme_editor/' . $css_filename); if (strpos($content, '#LESS') !== false) { list($css_content, $less_content) = explode('#LESS#', $content); $css_content = Less::parseUrls($css_content, Registry::get('config.dir.root'), fn_get_theme_path('[themes]/[theme]/media')); } else { $less_content = $content; $css_content = ''; } $data = array(); // FIXME: Bacward preset compatibility if (!empty($_REQUEST['preset_id'])) { $_REQUEST['style_id'] = $_REQUEST['preset_id']; } // If theme ID passed, set default theme if (!empty($_REQUEST['style_id'])) { fn_theme_editor_set_style($_REQUEST['style_id']);
public function loadData($url) { if (!empty($url)) { $this->loadRSS(fn_get_contents($url)); } }
//fn_set_notification('I','view>',print_r($view)); $view->assign('total_print', $total_print); $view->assign('order_info', $order_info); $view->assign('fonts_path', fn_get_theme_path('[relative]/[theme]/media/fonts')); if ($order_info['shipping_cost'] != 0) { $view->assign('shipping_cost', true); } if ($mode == "send_account_payment") { if (!empty($order_info['email'])) { fn_disable_live_editor_mode(); $html = array($view->displayMail('addons/rus_payments/print_invoice_payment.tpl', false, 'C')); Pdf::render($html, fn_get_files_dir_path() . 'account_payment.pdf', 'save'); $data = array('order_info' => $order_info, 'total_print' => $total_print, 'fonts_path' => fn_get_theme_path('[relative]/[theme]/media/fonts')); Mailer::sendMail(array('to' => $order_info['email'], 'from' => 'default_company_orders_department', 'data' => $data, 'attachments' => array(fn_get_files_dir_path() . 'account_payment.pdf'), 'tpl' => 'addons/rus_payments/print_invoice_payment.tpl', 'is_html' => true), 'A'); fn_set_notification('N', __('notice'), __('text_email_sent')); } } else { $view->assign('show_print_button', true); $view->displayMail('addons/rus_payments/print_invoice_payment.tpl', true, 'C'); } exit; } elseif ($mode == 'get_stamp') { Header("Content-Type: image/png"); Header("Content-Type: image/jpg"); Header("Content-Type: image/jpeg"); Header("Content-Type: image/gif"); $path_stamp = fn_get_image_pairs($_REQUEST['payment_id'], 'stamp', 'M', true, true, DESCR_SL); $image = fn_get_contents($path_stamp['icon']['absolute_path']); fn_echo($image); exit; }