Beispiel #1
0
function fn_settings_actions_addons_webmail(&$new_value, $old_value)
{
    if ($new_value == 'A') {
        // Copy data directory to "var"
        $dir_data = DIR_ROOT . '/var/webmail';
        if (fn_copy(DIR_ADDONS . 'webmail/lib/webmail/data', $dir_data) == false) {
            $msg = fn_get_lang_var('text_cannot_write_directory');
            fn_set_notification('E', fn_get_lang_var('error'), str_replace('[directory]', $dir_data, $msg));
            $new_value = 'D';
            return false;
        }
        $config = Registry::get('config');
        $_settings = $dir_data . '/settings/settings.xml';
        // 1 step, generate config file
        $xml = simplexml_load_file($_settings);
        $xml->Common->DBLogin = $config['db_user'];
        $xml->Common->DBPassword = $config['db_password'];
        $xml->Common->DBName = $config['db_name'];
        $xml->Common->DBHost = $config['db_host'];
        if (fn_put_contents($_settings, $xml->asXML()) == false) {
            $msg = fn_get_lang_var('cannot_write_file');
            fn_set_notification('E', fn_get_lang_var('error'), str_replace('[file]', $_settings, $msg));
            $new_value = 'D';
            return false;
        }
        include DIR_ADDONS . 'webmail/lib/webmail/web/class_settings.php';
        include DIR_ADDONS . 'webmail/lib/webmail/web/class_dbstorage.php';
        // Init mailbee core
        $null = null;
        $settings =& Settings::CreateInstance();
        $dbStorage =& DbStorageCreator::CreateDatabaseStorage($null);
        $dbStorage->Connect();
        $dbStorage->CreateTables($settings->DbPrefix);
    }
}
Beispiel #2
0
 /**
  * Put file to storage
  *
  * @param  string $file   file path in storage
  * @param  array  $params uploaded data and options
  * @return array  file size and file name
  */
 public function put($file, $params)
 {
     if (empty($params['overwrite'])) {
         $file = $this->generateName($file);
         // check if name is unique and generate new if not
     }
     $file = $this->prefix($file);
     if (!empty($params['compress'])) {
         if (!empty($params['contents'])) {
             $params['contents'] = gzencode($params['contents']);
         }
     }
     if (!fn_mkdir(dirname($file))) {
         return false;
     }
     if (!empty($params['file'])) {
         fn_copy($params['file'], $file);
     } else {
         fn_put_contents($file, $params['contents']);
     }
     if (!file_exists($file)) {
         return false;
     }
     $filesize = filesize($file);
     if (!empty($params['file']) && empty($params['keep_origins'])) {
         fn_rm($params['file']);
     }
     return array($filesize, str_replace($this->prefix(), '', $file));
 }
/**
 * 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']];
    }
}
Beispiel #4
0
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);
}
Beispiel #5
0
/**
 * Hook: generates low-resolution image from HiDPI one
 * @param array &$image_data
 * @param int &$image_id
 * @param string &$image_type
 * @param string &$images_path
 * @param array &$_data
 */
function fn_hidpi_update_image(&$image_data, &$image_id, &$image_type, &$images_path, &$_data)
{
    // Save original image
    $filename = fn_hdpi_form_name($image_data['name']);
    Storage::instance('images')->put($images_path . $filename, array('file' => $image_data['path'], 'keep_origins' => true));
    // Resize original image to non-hidpi resolution
    $_data['image_x'] = intval($_data['image_x'] / 2);
    $_data['image_y'] = intval($_data['image_y'] / 2);
    fn_put_contents($image_data['path'], fn_resize_image($image_data['path'], $_data['image_x'], $_data['image_y']));
}
Beispiel #6
0
 public function updateViaFtp($content, $settings)
 {
     $this->saveBackup();
     $tmp_file = fn_create_temp_file();
     fn_put_contents($tmp_file, $content);
     $ftp_copy_result = fn_copy_by_ftp($tmp_file, $this->path, $settings);
     fn_rm($tmp_file);
     $status = $ftp_copy_result === true;
     return array($status, $ftp_copy_result);
 }
Beispiel #7
0
 /**
  * Generates new snapshot
  * @param array $params params list
  */
 public static function create($params)
 {
     if (empty($params['dir_root'])) {
         $params['dir_root'] = Registry::get('config.dir.root');
     }
     if (empty($params['dist'])) {
         $params['dist'] = false;
     }
     $dir_root = $params['dir_root'];
     $dist = $params['dist'];
     $folders = array('app', 'js', $params['theme_rel_backend']);
     if ($dist) {
         $themes_dir = $params['themes_repo'];
         $themes_dir_to = $params['themes_frontend'];
     } else {
         $themes_dir = $params['themes_frontend'];
     }
     $themes = fn_get_dir_contents($themes_dir);
     $snapshot = array('time' => time(), 'files' => array(), 'dirs' => array(), 'themes' => array());
     if ($dist) {
         $snapshot['db_scheme'] = fn_get_contents($dir_root . '/install/database/scheme.sql');
         // remove myslqdump comments
         $snapshot['db_scheme'] = preg_replace('|/\\*!.+\\*/;\\n|imSU', '', $snapshot['db_scheme']);
         // form list of tables
         preg_match_all('/create table `(.+)`/imSU', $snapshot['db_scheme'], $tables);
         $snapshot['db_tables'] = !empty($tables[1]) ? $tables[1] : array();
     }
     $new_snapshot = self::make($dir_root, $folders, array('config.local.php'));
     self::arrayMerge($snapshot, $new_snapshot);
     foreach ($folders as $folder_name) {
         $path = $dir_root . '/' . $folder_name;
         $new_snapshot = self::make($path);
         self::arrayMerge($snapshot, $new_snapshot);
     }
     foreach ($themes as $theme_name) {
         if (is_numeric($theme_name) && $theme_name === strval($theme_name + 0)) {
             continue;
             // this is company subfolder
         }
         $path = "{$themes_dir}/{$theme_name}";
         if ($dist) {
             $new_snapshot = self::make($path, array(), array(), array($themes_dir => $themes_dir_to), true);
         } else {
             $new_snapshot = self::make($path, array(), array(), array(), true);
         }
         $snapshot['themes'][$theme_name]['files'] = $snapshot['themes'][$theme_name]['dirs'] = array();
         self::arrayMerge($snapshot['themes'][$theme_name], $new_snapshot);
     }
     $snapshot['addons'] = fn_get_dir_contents(Registry::get('config.dir.addons'));
     fn_mkdir(Registry::get('config.dir.snapshots'));
     $snapshot_filename = fn_strtolower(PRODUCT_VERSION . '_' . (PRODUCT_STATUS ? PRODUCT_STATUS . '_' : '') . PRODUCT_EDITION . ($dist ? '_dist' : ''));
     $snapshot_filecontent = '<?php $snapshot' . ($dist ? '_dist' : '') . ' = ' . var_export($snapshot, true) . '; ?>';
     fn_put_contents(Registry::get('config.dir.snapshots') . "{$snapshot_filename}.php", $snapshot_filecontent);
 }
Beispiel #8
0
 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;
 }
 static function clear($changed_tables)
 {
     $tags = array();
     foreach ($changed_tables as $table => $flag) {
         if (!empty(self::$_cache_handlers[$table])) {
             $tags = fn_array_merge($tags, array_keys(self::$_cache_handlers[$table]), false);
         }
     }
     foreach ($tags as $tag) {
         fn_rm(DIR_CACHE . $tag, true);
     }
     fn_put_contents(DIR_CACHE . self::$_handlers_name, serialize(self::$_cache_handlers));
     return true;
 }
Beispiel #10
0
/**
 * Hook: generates low-resolution image from HiDPI one
 * @param array &$image_data
 * @param int &$image_id
 * @param string &$image_type
 * @param string &$images_path
 * @param array &$_data
 */
function fn_hidpi_update_image(&$image_data, &$image_id, &$image_type, &$images_path, &$_data)
{
    // Save original image
    $filename = fn_hdpi_form_name($image_data['name']);
    Storage::instance('images')->put($images_path . $filename, array('file' => $image_data['path'], 'keep_origins' => true));
    $ext = fn_get_file_ext($filename);
    // We should not process ICO files
    if ($ext == 'ico') {
        return false;
    }
    // Resize original image to non-hidpi resolution
    $_data['image_x'] = intval($_data['image_x'] / 2);
    $_data['image_y'] = intval($_data['image_y'] / 2);
    fn_put_contents($image_data['path'], fn_resize_image($image_data['path'], $_data['image_x'], $_data['image_y'], Registry::get('settings.Thumbnails.thumbnail_background_color')));
}
Beispiel #11
0
 /**
  * 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;
 }
 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']));
     }
 }
Beispiel #13
0
function fn_generate_thumbnail($image_path, $width, $height = 0, $make_box = false, $force = null)
{
    if (empty($image_path)) {
        return '';
    }
    if (strpos($image_path, '://') === false) {
        if (strpos($image_path, '/') !== 0) {
            // relative path
            $image_path = Registry::get('config.current_path') . '/' . $image_path;
        }
        $image_path = (defined('HTTPS') ? 'https://' . Registry::get('config.https_host') : 'http://' . Registry::get('config.http_host')) . $image_path;
    }
    $_path = str_replace(Registry::get('config.current_location') . '/', '', $image_path);
    $image_url = explode('/', $_path);
    $image_name = array_pop($image_url);
    $image_dir = array_pop($image_url);
    $image_dir .= '/' . $width . (empty($height) ? '' : '/' . $height);
    $filename = $image_dir . '/' . $image_name;
    $real_path = htmlspecialchars_decode(DIR_ROOT . '/' . $_path, ENT_QUOTES);
    $th_path = htmlspecialchars_decode(DIR_THUMBNAILS . $filename, ENT_QUOTES);
    if (!fn_mkdir(DIR_THUMBNAILS . $image_dir)) {
        return '';
    }
    if (!file_exists($th_path) || $force != null) {
        if (fn_get_image_size($real_path)) {
            $image = fn_get_contents($real_path);
            fn_put_contents($th_path, $image);
            if ($force == "new") {
                fn_place_new($th_path);
            }
            fn_resize_image($th_path, $th_path, $width, $height, $make_box);
        } else {
            return '';
        }
    }
    return Registry::get('config.thumbnails_path') . $filename;
}
Beispiel #14
0
function fn_sdek_get_ticket_order($data_auth, $order_id, $chek_id)
{
    unset($data_auth['Number']);
    $xml = '            ' . RusSdek::arraySimpleXml('OrdersPrint', $data_auth, 'open');
    $order_sdek = array('Number' => $order_id . '_' . $chek_id, 'Date' => $data_auth['Date']);
    $xml .= '            ' . RusSdek::arraySimpleXml('Order', $order_sdek);
    $xml .= '            ' . '</OrdersPrint>';
    $response = RusSdek::xmlRequest('http://gw.edostavka.ru:11443/orders_print.php', $xml, $data_auth);
    $download_file_dir = fn_get_files_dir_path() . '/sdek' . '/' . $chek_id . '/';
    fn_rm($download_file_dir);
    fn_mkdir($download_file_dir);
    $name = $order_id . '.pdf';
    $download_file_path = $download_file_dir . $name;
    if (!fn_is_empty($response)) {
        fn_put_contents($download_file_path, $response);
    }
}
Beispiel #15
0
 /**
  * Add a new record to LOG file.
  *
  * @param  string $type    notification type (E - error, W - warning, N - notice)
  * @param  string $title   notification title
  * @param  string $message notification message
  * @return bool   true if record was added
  */
 public function logMessage($type, $title, $message)
 {
     $log_wrote = false;
     $file_path = Registry::get('config.dir.root') . '/' . self::LOG_FILE;
     // Create file if not exists
     if (!file_exists($file_path)) {
         fn_put_contents($file_path, '');
     }
     if (is_file($file_path) && is_writable($file_path)) {
         file_put_contents($file_path, $this->_formatLogMessage($type, $title, $message), FILE_APPEND);
         $log_wrote = true;
     }
     return $log_wrote;
 }
    $_SESSION['show_active_skins_only'] = 'Y';
}
$view->assign('show_active_skins_only', $_SESSION['show_active_skins_only']);
// Disable debug console
$view->debugging = false;
$message = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($mode == 'edit') {
        fn_trusted_vars('file_content');
        if (defined('DEVELOPMENT')) {
            exit;
        }
        $file = basename($_REQUEST['file']);
        $fname = fn_normalize_path(DIR_SKINS . $current_path . $file);
        if (strpos($fname, DIR_SKINS) !== false && @is_writable($fname) && !in_array(fn_get_file_ext($fname), Registry::get('config.forbidden_file_extensions'))) {
            fn_put_contents($fname, $_REQUEST['file_content']);
            $_msg = fn_get_lang_var('text_file_saved');
            $_msg = str_replace('[file]', $file, $_msg);
            fn_set_notification('N', fn_get_lang_var('notice'), $_msg);
        } else {
            $_msg = fn_get_lang_var('cannot_write_file');
            $_msg = str_replace('[file]', $file, $_msg);
            fn_set_notification('E', fn_get_lang_var('error'), $_msg);
        }
        exit;
    }
    if ($mode == 'upload_file') {
        $uploaded_data = fn_filter_uploaded_data('uploaded_data');
        $pname = fn_normalize_path(DIR_SKINS . $current_path);
        foreach ((array) $uploaded_data as $udata) {
            if (!(strpos($pname, DIR_SKINS) !== false && @fn_copy($udata['path'], $pname . $udata['name']))) {
Beispiel #17
0
function fn_find_file($prefix, $file)
{
    $file = fn_strip_slashes($file);
    // Absolute path
    if (is_file($file)) {
        return realpath($file);
    }
    // Path is relative to prefix
    if (is_file($prefix . '/' . $file)) {
        return realpath($prefix . '/' . $file);
    }
    // Url
    if (strpos($file, '://') !== false) {
        $content = fn_get_contents($file);
        if (!empty($content)) {
            $fname = basename($file);
            if (empty($fname) || strpos($fname, '?') !== false) {
                $fname = basename(fn_create_temp_file());
            }
            if (fn_put_contents(DIR_COMPILED . $fname, $content)) {
                return DIR_COMPILED . $fname;
            }
        }
    }
    return false;
}
Beispiel #18
0
/**
 * 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;
}
Beispiel #19
0
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
$_SESSION['current_path'] = empty($_SESSION['current_path']) ? '' : preg_replace('/^\\//', '', $_SESSION['current_path']);
$current_path = $_SESSION['current_path'];
// Disable debug console
Tygh::$app['view']->debugging = false;
$message = array();
$root_dir = fn_te_get_root('full');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($mode == 'edit') {
        fn_trusted_vars('file_content');
        $file_path = fn_te_normalize_path($_REQUEST, $root_dir);
        $is_forbidden_ext = in_array(fn_strtolower(fn_get_file_ext($file_path)), Registry::get('config.forbidden_file_extensions'));
        if (fn_te_check_path($file_path) && @is_writable($file_path) && !$is_forbidden_ext) {
            fn_put_contents($file_path, $_REQUEST['file_content']);
            fn_set_notification('N', __('notice'), __('text_file_saved', array('[file]' => fn_basename($file_path))));
            Tygh::$app['ajax']->assign('saved', true);
            // Clear template cache of updated template for the customer front-end
            $view = Tygh::$app['view'];
            $view->setArea('C', '', Registry::get('runtime.company_id'));
            $updated_template_path = str_replace($view->getTemplateDir(0), '', $file_path);
            $view->clearCompiledTemplate($updated_template_path);
            $view->setArea(AREA, '', Registry::get('runtime.company_id'));
        } else {
            fn_set_notification('E', __('error'), __('cannot_write_file', array('[file]' => fn_get_rel_dir($file_path))));
        }
        exit;
    }
    if ($mode == 'upload_file') {
        $uploaded_data = fn_filter_uploaded_data('uploaded_data');
Beispiel #20
0
 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);
 }
Beispiel #21
0
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($mode == 'update_customization_mode') {
        fn_update_customization_mode($_REQUEST['customization_modes']);
        return array(CONTROLLER_STATUS_OK, $_REQUEST['current_url']);
    }
    if ($mode == 'live_editor_update') {
        fn_trusted_vars('value');
        fn_live_editor_update_object($_REQUEST);
        exit;
    }
    if ($mode == 'save_template') {
        fn_trusted_vars('content');
        $ext = fn_strtolower(fn_get_file_ext($_REQUEST['file']));
        if ($ext == 'tpl') {
            $theme_path = fn_get_theme_path('[themes]/[theme]/templates/', 'C');
            if (fn_put_contents($_REQUEST['file'], $_REQUEST['content'], $theme_path)) {
                fn_set_notification('N', __('notice'), __('text_file_saved', array('[file]' => fn_basename($_REQUEST['file']))));
            }
        }
        return array(CONTROLLER_STATUS_REDIRECT, $_REQUEST['current_url']);
    }
    if ($mode == 'restore_template') {
        $copied = false;
        $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) {
Beispiel #22
0
 /**
  * This is a copy of the fn_uc_is_writable_dest function which was removed in 4.1.5
  *
  * Check if destination is writable
  *
  * @param string $dest destination file/directory
  * @return boolean true if writable, false - if not
  */
 private static function isWritableDest($dest)
 {
     $dest = rtrim($dest, '/');
     if (is_file($dest)) {
         $f = @fopen($dest, 'ab');
         if ($f === false) {
             return false;
         }
         fclose($f);
     } elseif (is_dir($dest)) {
         if (!fn_put_contents($dest . '/zzzz.zz', '1')) {
             return false;
         }
         fn_rm($dest . '/zzzz.zz');
     } else {
         return false;
     }
     return true;
 }
 /**
  * Assembles the message body.  Returns an empty string on failure.
  * @access public
  * @return string The assembled message body
  */
 public function CreateBody()
 {
     $body = '';
     if ($this->sign_key_file) {
         $body .= $this->GetMailMIME();
     }
     $this->SetWordWrap();
     switch ($this->message_type) {
         case 'alt':
             $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
             $body .= $this->EncodeString($this->AltBody, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
             $body .= $this->EncodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->EndBoundary($this->boundary[1]);
             break;
         case 'plain':
             $body .= $this->EncodeString($this->Body, $this->Encoding);
             break;
         case 'attachments':
             $body .= $this->GetBoundary($this->boundary[1], '', '', '');
             $body .= $this->EncodeString($this->Body, $this->Encoding);
             $body .= $this->LE;
             $body .= $this->AttachAll();
             break;
         case 'alt_attachments':
             $body .= sprintf("--%s%s", $this->boundary[1], $this->LE);
             $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE . $this->LE);
             $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE;
             // Create text body
             $body .= $this->EncodeString($this->AltBody, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE;
             // Create the HTML body
             $body .= $this->EncodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->EndBoundary($this->boundary[2]);
             $body .= $this->AttachAll();
             break;
     }
     if ($this->IsError()) {
         $body = '';
     } elseif ($this->sign_key_file) {
         try {
             $file = tempnam('', 'mail');
             fn_put_contents($file, $body);
             //TODO check this worked
             $signed = tempnam("", "signed");
             if (@openssl_pkcs7_sign($file, $signed, "file://" . $this->sign_cert_file, array("file://" . $this->sign_key_file, $this->sign_key_pass), NULL)) {
                 @unlink($file);
                 @unlink($signed);
                 $body = file_get_contents($signed);
             } else {
                 @unlink($file);
                 @unlink($signed);
                 throw new phpmailerException($this->Lang("signing") . openssl_error_string());
             }
         } catch (phpmailerException $e) {
             $body = '';
             if ($this->exceptions) {
                 throw $e;
             }
         }
     }
     return $body;
 }
Beispiel #24
0
                 $manifest = json_decode($manifest_content, true);
             } else {
                 $manifest = parse_ini_file($theme_path . '/' . THEME_MANIFEST_INI);
             }
             $manifest['title'] = $_REQUEST['theme_data']['title'];
             $manifest['description'] = $_REQUEST['theme_data']['description'];
             // Put logos of current layout to manifest
             $logos = fn_get_logos(Registry::get('runtime.company_id'));
             foreach ($logos as $type => $logo) {
                 if (!empty($logo['image'])) {
                     $filename = fn_basename($logo['image']['relative_path']);
                     Storage::instance('images')->export($logo['image']['relative_path'], $theme_path . '/media/images/' . $filename);
                     $manifest[$type] = 'media/images/' . $filename;
                 }
             }
             fn_put_contents($theme_path . '/' . THEME_MANIFEST, json_encode($manifest));
             fn_install_theme($theme_dest, Registry::get('runtime.company_id'), false);
         }
     } else {
         fn_set_notification('W', __('warning'), __('warning_theme_clone_dir_exists'));
     }
 } elseif ($mode == 'upload') {
     $theme_pack = fn_filter_uploaded_data('theme_pack', Registry::get('config.allowed_pack_exts'));
     if (empty($theme_pack[0])) {
         fn_set_notification('E', __('error'), __('text_allowed_to_upload_file_extension', array('[ext]' => implode(',', Registry::get('config.allowed_pack_exts')))));
     } else {
         $theme_pack = $theme_pack[0];
         // Extract the add-on pack and check the permissions
         $extract_path = fn_get_cache_path(false) . 'tmp/theme_pack/';
         $destination = Registry::get('config.dir.themes_repository');
         // Re-create source folder
Beispiel #25
0
 if ($mode == 'update_location') {
     fn_trusted_vars('location_data');
     $_REQUEST['location_data']['lang_code'] = DESCR_SL;
     $location_id = Location::instance()->update($_REQUEST['location_data']);
     $suffix .= "&selected_location=" . $location_id;
 }
 if ($mode == 'export_layout') {
     $location_ids = isset($_REQUEST['location_ids']) ? $_REQUEST['location_ids'] : array();
     $layout_id = Registry::get('runtime.layout.layout_id');
     $content = Exim::instance()->export($layout_id, $location_ids, $_REQUEST);
     $filename = empty($_REQUEST['filename']) ? date_format(TIME, "%m%d%Y") . 'xml' : $_REQUEST['filename'];
     if (Registry::get('runtime.company_id')) {
         $filename = Registry::get('runtime.company_id') . '/' . $filename;
     }
     fn_mkdir(dirname(Registry::get('config.dir.layouts') . $filename));
     fn_put_contents(Registry::get('config.dir.layouts') . $filename, $content);
     fn_set_notification('N', __('notice'), __('text_exim_data_exported'));
     // Direct download
     if ($_REQUEST['output'] == 'D') {
         return array(CONTROLLER_STATUS_REDIRECT, 'block_manager.manage?meta_redirect_url=block_manager.get_file%26filename=' . $_REQUEST['filename']);
         // Output to screen
     } elseif ($_REQUEST['output'] == 'C') {
         return array(CONTROLLER_STATUS_REDIRECT, 'block_manager.get_file?to_screen=Y&filename=' . $_REQUEST['filename']);
     }
 }
 if ($mode == 'import_layout') {
     $data = fn_filter_uploaded_data('filename');
     if (!empty($data[0]['path'])) {
         $result = Exim::instance()->importFromFile($data[0]['path'], $_REQUEST);
         if ($result) {
             fn_set_notification('N', __('notice'), __('text_exim_data_imported_clear'));
Beispiel #26
0
function fn_qr_generate($order_info, $delimenter = '|', $dir = "")
{
    $processor_params = $order_info['payment_method']['processor_params'];
    $format_block = 'ST' . '0001' . '2' . $delimenter;
    $required_block = array('Name' => $processor_params['sbrf_recepient_name'], 'PersonalAcc' => $processor_params['sbrf_settlement_account'], 'BankName' => $processor_params['sbrf_bank'], 'BIC' => $processor_params['sbrf_bik'], 'CorrespAcc' => $processor_params['sbrf_cor_account']);
    $required_block = fn_qr_array2string($required_block, $delimenter);
    $additional_block = array('PayeeINN' => $processor_params['sbrf_inn'], 'Sum' => $order_info['total'] * 100, 'Purpose' => __('sbrf_order_payment') . ' №' . $order_info['order_id'], 'LastName' => $order_info['b_lastname'], 'FirstName' => $order_info['b_firstname'], 'PayerAddress' => $order_info['b_city'], 'Phone' => $order_info['b_phone']);
    $additional_block = fn_qr_array2string($additional_block, $delimenter);
    $string = $format_block . $required_block . $additional_block;
    $string = substr($string, 0, -1);
    $resolution = $processor_params['sbrf_qr_resolution'];
    $data = array('cht' => 'qr', 'choe' => 'UTF-8', 'chl' => $string, 'chs' => $resolution . 'x' . $resolution, 'chld' => 'M|4');
    $url = 'https://chart.googleapis.com/chart';
    $response = Http::get($url, $data);
    if (!strpos($response, 'Error')) {
        fn_put_contents($dir . 'qr_code_' . $order_info['order_id'] . '.png', $response);
        $path = $dir . 'qr_code_' . $order_info['order_id'] . '.png';
    } else {
        $path = fn_get_contents(DIR_ROOT . '/images/no_image.png');
    }
    return $path;
}
Beispiel #27
0
 /**
  * Converts URL (http://e.com/a.png) to CSS property ( url("../a.png") )
  * @param  string $style_id   style ID
  * @param  array  $style_data style data (fields)
  * @return array  modified style data
  */
 private function urlToCss($style_id, $style_data)
 {
     $patterns_url = Patterns::instance($this->params)->getUrl($style_id, true);
     if (!empty($this->schema['backgrounds']['fields'])) {
         foreach ($this->schema['backgrounds']['fields'] as $field) {
             if (!empty($field['properties']['pattern'])) {
                 $var_name = $field['properties']['pattern'];
                 if (!empty($style_data[$var_name]) && strpos($style_data[$var_name], '//') !== false) {
                     $url = preg_replace('/url\\([\'"]?(.*?)[\'"]?\\)/', '$1', $style_data[$var_name]);
                     if (strpos($url, '//') === 0) {
                         $url = 'http:' . $url;
                     }
                     $url = fn_normalize_path($url);
                     if (strpos($url, $patterns_url) !== false) {
                         $url = str_replace($patterns_url, '..', $url);
                         if (strpos($url, '?') !== false) {
                             // URL is parsed by Less::parseUrls method, so remove everything after ?
                             list($url) = explode('?', $url);
                         }
                     } elseif ($style_id) {
                         // external url
                         $tmp_file = fn_create_temp_file();
                         fn_put_contents($tmp_file, fn_get_contents($url));
                         $_style = Patterns::instance($this->params)->save($style_id, array('data' => $style_data), array($var_name => array('name' => fn_basename($url), 'path' => $tmp_file)));
                         $style_data = $_style['data'];
                         continue;
                         // assignment done in save method
                     }
                     $style_data[$var_name] = 'url(' . $url . ')';
                 }
             }
         }
     }
     return $style_data;
 }
Beispiel #28
0
 public static function copyPresetImages()
 {
     $theme_name = Registry::get('config.base_theme');
     $presets_path = fn_get_theme_path('[themes]/' . $theme_name . '/presets/data', 'C');
     $preset_images_path = fn_get_theme_path('[themes]/' . $theme_name . '/media/images/patterns', 'C');
     $files = fn_get_dir_contents($presets_path, false, true);
     foreach ($files as $file) {
         $content = fn_get_contents($presets_path . '/' . $file);
         if (preg_match('/@general_bg_image\\: url\\(["]?(.*?)["]?\\)/', $content, $m)) {
             $image_name = fn_basename($m[1]);
             if (strpos($image_name, '?') !== false) {
                 list($image_name) = explode('?', $image_name);
             }
             if (file_exists($preset_images_path . '/' . $image_name)) {
                 $preset_dir = str_replace('.less', '', $file);
                 $new_path = $preset_images_path . '/' . $preset_dir;
                 fn_mkdir($new_path);
                 fn_copy($preset_images_path . '/' . $image_name, $new_path);
                 $content = str_replace($image_name, $preset_dir . '/' . $image_name, $content);
                 fn_put_contents($presets_path . '/' . $file, $content);
             }
         }
     }
     return true;
 }
Beispiel #29
0
/**
 * 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);
}
Beispiel #30
0
/**
 * Merges css and less files
 *
 * @param array $files Array with style files
 * @param string $styles Style code
 * @param string $prepend_prefix Prepend prefix
 * @param array $params additional params
 */
function fn_merge_styles($files, $styles = '', $prepend_prefix = '', $params = array(), $area = AREA)
{
    $prefix = !empty($prepend_prefix) ? 'embedded' : 'standalone';
    $make_rtl = false;
    if (fn_is_rtl_language()) {
        $prefix .= '-rtl';
        $make_rtl = true;
    }
    $output = '';
    $less_output = '';
    $less_reflection = array();
    $compiled_less = '';
    $compiled_css = '';
    $relative_path = fn_get_theme_path('[relative]/[theme]/css', $area);
    $hashes = array();
    $names = array_map(function ($v) {
        return !empty($v['relative']) ? $v['relative'] : false;
    }, $files);
    // Check file changes
    if (Development::isEnabled('compile_check') || Debugger::isActive()) {
        $dir_root = Registry::get('config.dir.root');
        foreach ($names as $index => $name) {
            if (file_exists($dir_root . '/' . $name)) {
                $hashes[] = $name . filemtime($dir_root . '/' . $name);
            }
        }
    }
    $hashes[] = md5(implode('|', $names));
    $hashes[] = md5($styles);
    if ($area == 'C') {
        $hashes[] = Registry::get('runtime.layout.layout_id');
        $hashes[] = Registry::get('runtime.layout.style_id');
    }
    arsort($hashes);
    $hash = md5(implode(',', $hashes) . PRODUCT_VERSION) . fn_get_storage_data('cache_id');
    $filename = $prefix . '.' . $hash . '.css';
    $theme_manifest = Themes::factory(fn_get_theme_path('[theme]', 'C'))->getManifest();
    if (!Storage::instance('assets')->isExist($relative_path . '/' . $filename)) {
        Debugger::checkpoint('Before styles compilation');
        foreach ($files as $src) {
            $m_prefix = '';
            $m_suffix = '';
            if (!empty($src['media'])) {
                $m_prefix = "\n@media " . $src['media'] . " {\n";
                $m_suffix = "\n}\n";
            }
            if (strpos($src['file'], '.css') !== false) {
                $output .= "\n" . $m_prefix . fn_get_contents($src['file']) . $m_suffix;
            } elseif ($area != 'C' || empty($theme_manifest['converted_to_css'])) {
                $less_output_chunk = '';
                if (file_exists($src['file'])) {
                    if ($area == 'C' && (empty($theme_manifest['parent_theme']) || $theme_manifest['parent_theme'] == 'basic')) {
                        $less_output_chunk = "\n" . $m_prefix . fn_get_contents($src['file']) . $m_suffix;
                    } else {
                        $less_output_chunk = "\n" . $m_prefix . '@import "' . str_replace($relative_path . '/', '', $src['relative']) . '";' . $m_suffix;
                    }
                }
                if (!empty($params['reflect_less'])) {
                    if (preg_match('{/addons/([^/]+)/}is', $src['relative'], $m)) {
                        $less_reflection['output']['addons'][$m[1]] .= $less_output_chunk;
                    } else {
                        $less_reflection['output']['main'] .= $less_output_chunk;
                    }
                }
                $less_output .= $less_output_chunk;
            }
        }
        $header = str_replace('[files]', implode("\n", $names), Registry::get('config.js_css_cache_msg'));
        if (!empty($styles)) {
            $less_output .= $styles;
        }
        // Prepend all styles with prefix
        if (!empty($prepend_prefix)) {
            $less_output = $output . "\n" . $less_output;
            $output = '';
        }
        if (!empty($output)) {
            $compiled_css = Less::parseUrls($output, Storage::instance('assets')->getAbsolutePath($relative_path), fn_get_theme_path('[themes]/[theme]/media', $area));
        }
        if (!empty($theme_manifest['converted_to_css']) && $area == 'C') {
            $theme_css_path = fn_get_theme_path('[themes]/[theme]', $area) . '/css';
            $pcl_filepath = $theme_css_path . '/' . Themes::$compiled_less_filename;
            if (file_exists($pcl_filepath)) {
                $compiled_css .= fn_get_contents($pcl_filepath);
            }
            list($installed_addons) = fn_get_addons(array('type' => 'active'));
            foreach ($installed_addons as $addon) {
                $addon_pcl_filpath = $theme_css_path . "/addons/{$addon['addon']}/" . Themes::$compiled_less_filename;
                if (file_exists($pcl_filepath)) {
                    $compiled_css .= fn_get_contents($addon_pcl_filpath);
                }
            }
        }
        if (!empty($less_output)) {
            $less = new Less();
            if (!empty($params['compressed'])) {
                $less->setFormatter('compressed');
            }
            $less->setImportDir($relative_path);
            try {
                $compiled_less = $less->customCompile($less_output, Storage::instance('assets')->getAbsolutePath($relative_path), array(), $prepend_prefix, $area);
            } catch (Exception $e) {
                $skip_save = true;
                $shift = 4;
                $message = '<div style="border: 2px solid red; padding: 5px;">LESS ' . $e->getMessage();
                if (preg_match("/line: (\\d+)/", $message, $m)) {
                    $lo = explode("\n", $less_output);
                    $message .= '<br /><br /><pre>' . implode("\n", array_splice($lo, intval($m[1]) - $shift, $shift * 2)) . '</pre>';
                }
                $message .= '</div>';
                fn_set_notification('E', __('error'), $message);
            }
        }
        if (empty($skip_save)) {
            $compiled_content = $compiled_css . "\n" . $compiled_less;
            // Move all @import links to the Top of the file.
            if (preg_match_all('/@import url.*?;/', $compiled_content, $imports)) {
                $compiled_content = preg_replace('/@import url.*?;/', '', $compiled_content);
                foreach ($imports[0] as $import_link) {
                    $compiled_content = $import_link . "\n" . $compiled_content;
                }
            }
            if ($make_rtl) {
                $compiled_content = \CSSJanus::transform($compiled_content);
                $compiled_content = "body {\ndirection: rtl;\n}\n" . $compiled_content;
            }
            Storage::instance('assets')->put($relative_path . '/' . $filename, array('contents' => $header . $compiled_content, 'compress' => false, 'caching' => true));
            if (!empty($params['use_scheme'])) {
                fn_put_contents(fn_get_cache_path(false) . 'theme_editor/' . $filename, $output . '#LESS#' . $less_output);
            }
            if (!empty($params['reflect_less'])) {
                $less_reflection['import_dirs'] = array($relative_path);
                fn_put_contents(fn_get_cache_path(false) . 'less_reflection.json', json_encode($less_reflection));
            }
        }
        Debugger::checkpoint('After styles compilation');
    }
    $url = Storage::instance('assets')->getUrl($relative_path . '/' . $filename);
    return $url;
}