Esempio n. 1
0
 public static function downloadDistr()
 {
     // Get needed version
     $version_info = self::GetNextVersionInfo();
     if (!$version_info['next_version'] || !$version_info['update_url']) {
         return false;
     }
     $download_file_dir = TWIGMO_UPGRADE_DIR . $version_info['next_version'] . '/';
     $download_file_path = $download_file_dir . 'twigmo.tgz';
     $unpack_path = $download_file_path . '_unpacked';
     fn_rm($download_file_dir);
     fn_mkdir($download_file_dir);
     fn_mkdir($unpack_path);
     $data = fn_get_contents($version_info['update_url']);
     if (!fn_is_empty($data)) {
         fn_put_contents($download_file_path, $data);
         $res = fn_decompress_files($download_file_path, $unpack_path);
         if (!$res) {
             fn_set_notification('E', __('error'), __('twgadmin_failed_to_decompress_files'));
             return false;
         }
         return $unpack_path . '/';
     } else {
         fn_set_notification('E', __('error'), __('text_uc_cant_download_package'));
         return false;
     }
 }
Esempio n. 2
0
 public function generate($force = false)
 {
     $filename = $this->getFileName();
     if (!is_dir(dirname($filename))) {
         fn_mkdir(dirname($filename));
     }
     if ($force) {
         fn_rm($filename);
     }
     if (!file_exists($filename)) {
         fn_set_progress('echo', __('generating_xls'), false);
         $header = $data = array();
         $currencies = Registry::get('currencies');
         $currency = $currencies[CART_SECONDARY_CURRENCY];
         $currency_format = '#' . $currency['thousands_separator'] . '##0.' . str_repeat('0', $currency['decimals']);
         $currency_format = $currency['after'] == 'Y' ? $currency_format . $currency['symbol'] : $currency['symbol'] . $currency_format;
         foreach ($this->selected_fields as $field_id => $field_value) {
             $header[$this->price_schema['fields'][$field_id]['title']] = $field_id == 'price' ? $currency_format : 'string';
         }
         $this->writer->writeSheetHeader($this->sheet, $header);
         $this->render();
         $this->writer->writeToFile($filename);
     }
     return $filename;
 }
Esempio n. 3
0
/**
 * 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']];
    }
}
Esempio n. 4
0
 public function __construct($config)
 {
     $this->_config = array('store_prefix' => !empty($config['store_prefix']) ? $config['store_prefix'] : null, 'dir_cache' => $config['dir']['cache_registry']);
     if (fn_mkdir($this->_mapTags('')) == false) {
         throw new PermissionsException('Cache: "' . $this->_mapTags('') . '" directory is not writable');
     }
     parent::__construct($config);
     return true;
 }
 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;
 }
Esempio n. 6
0
 /**
  * Copy file outside the storage
  *
  * @param  string $src  file path in storage
  * @param  string $dest path to local file
  * @return int    number of bytes copied
  */
 public function export($src, $dest)
 {
     if (!fn_mkdir(dirname($dest))) {
         return false;
     }
     $res = $this->s3()->get_object($this->getOption('bucket'), $this->prefix($src), array('fileDownload' => $dest));
     if ($res->isOK()) {
         return true;
     }
     return false;
 }
Esempio n. 7
0
 public function generate($filename)
 {
     @ignore_user_abort(1);
     @set_time_limit(0);
     fn_mkdir(dirname($filename));
     $file = fopen($filename, 'wb');
     $this->head($file);
     $this->body($file);
     $this->bottom($file);
     fclose($file);
 }
Esempio n. 8
0
 public function __construct($format = 'csv', $price_id = 0)
 {
     $this->format = $format;
     $this->price_id = $price_id;
     $this->filename = 'log_tmp_' . $price_id . '.' . $this->format;
     $this->path = fn_get_files_dir_path() . 'yml/logs/';
     fn_mkdir($this->path);
     $file_is_new = !file_exists($this->path . $this->filename);
     $this->file = fopen($this->path . $this->filename, 'ab');
     if ($file_is_new && $this->format == 'csv') {
         fwrite($this->file, 'Type; Object ID; Message;' . PHP_EOL);
     }
 }
Esempio n. 9
0
 public function __construct()
 {
     $this->filename = 'log_commerceml.txt';
     list($this->path, $url_commerceml, $url_images) = RusEximCommerceml::getDirCommerceML();
     if (!is_dir($this->path)) {
         fn_mkdir($this->path);
         @chmod($this->path, 0777);
     }
     $file_is_new = !file_exists($this->path . $this->filename);
     $this->file = fopen($this->path . $this->filename, 'ab');
     if ($file_is_new) {
         fwrite($this->file, 'Message: ' . PHP_EOL);
         @chmod($this->file, 0777);
     }
 }
Esempio n. 10
0
 /**
  * Saves uploaded pattern to theme
  * @param  string $style_id     style ID
  * @param  array  $style        style
  * @param  array  $uploaded_data uploaded data
  * @return array  modified style
  */
 public static function save($style_id, $style, $uploaded_data)
 {
     $style_id = fn_basename($style_id);
     $patterns = self::getPath($style_id);
     if (!is_dir($patterns)) {
         fn_mkdir($patterns);
     }
     foreach ($uploaded_data as $var => $file) {
         $fname = $var . '.' . fn_get_file_ext($file['name']);
         if (fn_copy($file['path'], $patterns . '/' . $fname)) {
             $style['data'][$var] = "url('" . self::getRelPath($style_id) . '/' . $fname . '?' . TIME . "')";
         }
     }
     return $style;
 }
Esempio n. 11
0
 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']));
     }
 }
Esempio n. 12
0
 public function generate($force = false)
 {
     $filename = $this->getFileName();
     if (!is_dir(dirname($filename))) {
         fn_mkdir(dirname($filename));
     }
     if ($force) {
         fn_rm($filename);
     }
     // Min column width in percent
     $min_width = array('product' => 50, 'product_code' => 13, 'image' => 10);
     if (!file_exists($filename)) {
         $max_perc = 100;
         $field_count = count($this->selected_fields);
         // First step. Check for the min width.
         $perc = intval($max_perc / $field_count);
         foreach ($this->selected_fields as $field_name => $active) {
             if (isset($min_width[$field_name])) {
                 if ($min_width[$field_name] > $perc) {
                     $max_perc -= $min_width[$field_name];
                     $field_count--;
                 }
             }
         }
         // Second step. Set up the new width values.
         $perc = intval($max_perc / $field_count);
         foreach ($this->selected_fields as $field_name => $active) {
             if (!isset($min_width[$field_name]) || $min_width[$field_name] < $perc) {
                 $this->price_schema['fields'][$field_name]['min_width'] = $perc;
             } else {
                 $this->price_schema['fields'][$field_name]['min_width'] = $min_width[$field_name];
             }
         }
         fn_set_progress('echo', __('generating_pdf'), false);
         $this->render();
     }
     return $filename;
 }
Esempio n. 13
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);
    }
}
Esempio n. 14
0
    die('Access denied');
}
if (Registry::get('config.demo_mode')) {
    // ElFinder should not work in demo mode
    $message = json_encode(array('error' => __('error_demo_mode')));
    exit($message);
}
if (AREA == 'C') {
    if (!Registry::get('runtime.customization_mode.live_editor')) {
        die('Access denied');
    }
}
$private_files_path = fn_get_files_dir_path();
$public_files_path = fn_get_public_files_path();
fn_mkdir($private_files_path);
fn_mkdir($public_files_path);
$start_path = '';
if (!empty($_REQUEST['init']) && !empty($_REQUEST['start_path'])) {
    unset($_GET['target']);
    $start_path = fn_normalize_path($private_files_path . $_REQUEST['start_path']);
    if (strpos($start_path, $private_files_path) !== 0) {
        $start_path = '';
    }
}
$extra_path = str_replace(Storage::instance('images')->getAbsolutePath(''), '', $public_files_path);
$opts = array('roots' => array(array('driver' => 'Tygh\\ElFinder\\Volume', 'uploadDeny' => Registry::get('config.forbidden_mime_types'), 'fileMode' => DEFAULT_FILE_PERMISSIONS, 'dirMode' => DEFAULT_DIR_PERMISSIONS, 'uploadMaxSize' => Bootstrap::getIniParam('upload_max_filesize', true), 'alias' => __('private_files'), 'tmbPath' => '', 'path' => $private_files_path, 'startPath' => $start_path, 'mimeDetect' => 'internal', 'archiveMimes' => array('application/zip'), 'icon' => Registry::get('config.current_location') . '/js/lib/elfinder/img/volume_icon_local.png'), array('driver' => 'Tygh\\ElFinder\\Volume', 'uploadDeny' => Registry::get('config.forbidden_mime_types'), 'fileMode' => DEFAULT_FILE_PERMISSIONS, 'dirMode' => DEFAULT_DIR_PERMISSIONS, 'uploadMaxSize' => Bootstrap::getIniParam('upload_max_filesize', true), 'alias' => __('public_files'), 'tmbPath' => '', 'path' => $public_files_path, 'URL' => Storage::instance('images')->getUrl($extra_path), 'mimeDetect' => 'internal', 'archiveMimes' => array('application/zip'), 'icon' => Registry::get('config.current_location') . '/js/lib/elfinder/img/volume_icon_local.png')));
if ($mode == 'images') {
    unset($opts['roots'][0]);
}
$connector = new \elFinderConnector(new Core($opts));
$connector->run();
Esempio n. 15
0
         $rub = substr($for_rub, 0, -$length_for_rub);
         $length_for_kop = $currency['decimals'];
         $kop = substr($for_rub, -$length_for_kop);
         $total_print = '<strong>' . $rub . '</strong>&nbsp;' . __("sbrf_rub") . '&nbsp;<strong>' . $kop . '</strong>&nbsp;' . __("sbrf_kop");
     } else {
         $total_print = '<strong>' . $for_rub . '</strong>&nbsp;' . __("sbrf_rub");
     }
 } else {
     $total_print = fn_format_price_by_currency($order_info['total']);
 }
 $view = Tygh::$app['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'));
 $temp_dir = Registry::get('config.dir.cache_misc') . 'tmp/';
 fn_mkdir($temp_dir);
 $path = fn_qr_generate($order_info, '|', $temp_dir);
 $url_qr_code = Registry::get('config.http_location') . '/' . fn_get_rel_dir($path);
 $view->assign('url_qr_code', $url_qr_code);
 if ($mode == "send_sbrf_receipt") {
     if (!empty($order_info['email'])) {
         fn_disable_live_editor_mode();
         $html = array($view->displayMail('addons/rus_payments/print_sbrf_receipt.tpl', false, 'C'));
         Pdf::render($html, fn_get_files_dir_path() . 'sberbank_receipt.pdf', 'save');
         $data = array('order_info' => $order_info, 'total_print' => $total_print, 'fonts_path' => fn_get_theme_path('[relative]/[theme]/media/fonts'), 'url_qr_code' => $url_qr_code, 'email_subj' => __("sbrf_receipt_for_payment", array('[order_id]' => $order_info['order_id'])));
         Mailer::sendMail(array('to' => $order_info['email'], 'from' => 'default_company_orders_department', 'data' => $data, 'attachments' => array(fn_get_files_dir_path() . 'sberbank_receipt.pdf'), 'tpl' => 'addons/rus_payments/print_sbrf_receipt.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_sbrf_receipt.tpl', true, 'C');
Esempio n. 16
0
 /**
  * Installs new language from ZIP pack
  *
  * @param string $path   Path to ZIP file
  * @param array  $params
  *  reinstall: Skip adding new language
  *  validate_lang_code:Check meta information (lang_code) with updated language data (lang_code) and forbid to update if does not match
  *  force_lang_code: Skip meta lang code and use this one in all laguage variables
  * @return int Language ID
  */
 public static function installZipPack($path, $params = array())
 {
     $result = false;
     // Extract language pack and check the permissions
     $extract_path = fn_get_cache_path(false) . 'tmp/language_pack/';
     // Re-create source folder
     fn_rm($extract_path);
     fn_mkdir($extract_path);
     fn_copy($path, $extract_path . 'pack.zip');
     if (fn_decompress_files($extract_path . 'pack.zip', $extract_path)) {
         fn_rm($extract_path . 'pack.zip');
         $result = self::installCrowdinPack($extract_path, $params);
     } else {
         fn_set_notification('E', __('error'), __('broken_po_pack'));
     }
     return $result;
 }
Esempio n. 17
0
     }
 }
 if ($mode == 'm_delete') {
     if (!empty($_REQUEST['backup_files'])) {
         foreach ($_REQUEST['backup_files'] as $file) {
             @unlink(Registry::get('config.dir.backups') . fn_basename($file));
         }
     }
 }
 if ($mode == 'upload') {
     $dump = fn_filter_uploaded_data('dump', array('sql', 'tgz', 'zip'));
     if (!empty($dump)) {
         $dump = array_shift($dump);
         // Check if backups folder exists. If not - create it
         if (!is_dir(Registry::get('config.dir.backups'))) {
             fn_mkdir(Registry::get('config.dir.backups'));
         }
         if (fn_copy($dump['path'], Registry::get('config.dir.backups') . $dump['name'])) {
             fn_set_notification('N', __('notice'), __('done'));
         } else {
             fn_set_notification('E', __('error'), __('cant_create_backup_file'));
         }
     } else {
         fn_set_notification('E', __('error'), __('cant_upload_file'));
     }
 }
 if ($mode == 'optimize') {
     // Log database optimization
     fn_log_event('database', 'optimize');
     $all_tables = db_get_fields("SHOW TABLES");
     fn_set_progress('parts', sizeof($all_tables));
Esempio n. 18
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) {
Esempio n. 19
0
/**
 * Copy file taking into account accessibility via php/ftp
 *
 * @param string $source source file
 * @param string $dest destination file/directory
 * @return boolean true if directory copied correctly, false - otherwise
 */
function fn_copy($source, $dest)
{
    $result = false;
    $file_name = basename($source);
    if (!file_exists($dest)) {
        if (basename($dest) == $file_name) {
            // if we're copying the file, create parent directory
            fn_mkdir(dirname($dest));
        } else {
            fn_mkdir($dest);
        }
    }
    fn_echo(' .');
    if (is_writable($dest) || is_writable(dirname($dest)) && !file_exists($dest)) {
        if (is_dir($dest)) {
            $dest .= '/' . basename($source);
        }
        $result = copy($source, $dest);
        fn_uc_chmod_file($dest);
    }
    if (!$result) {
        // try ftp
        $result = fn_uc_ftp_copy($source, $dest);
    }
    return $result;
}
Esempio n. 20
0
 public static function writeLog($data, $file = 'sberbank.log')
 {
     $path = fn_get_files_dir_path();
     fn_mkdir($path);
     $file = fopen($path . $file, 'a');
     if (!empty($file)) {
         fputs($file, 'TIME: ' . date('Y-m-d H:i:s', TIME) . "\n");
         fputs($file, fn_array2code_string($data) . "\n\n");
         fclose($file);
     }
 }
Esempio n. 21
0
/**
 * Init pdf engine
 *
 * @return boolean always true
 */
function fn_init_pdf()
{
    // pdf can't be generated correctly without DOM extension (DOMDocument class)
    if (!class_exists('DOMDocument')) {
        $msg = AREA == 'A' ? fn_get_lang_var('error_generate_pdf_admin') : fn_get_lang_var('error_generate_pdf_customer');
        fn_set_notification('E', fn_get_lang_var('error'), $msg);
        return false;
    }
    if (defined('PDF_STARTED')) {
        return true;
    }
    define('CACHE_DIR', DIR_CACHE . 'pdf/cache');
    define('OUTPUT_FILE_DIRECTORY', DIR_CACHE . 'pdf/out');
    define('WRITER_TEMPDIR', DIR_CACHE . 'pdf/temp');
    if (!is_dir('CACHE_DIR')) {
        fn_mkdir(CACHE_DIR);
    }
    if (!is_dir('OUTPUT_FILE_DIRECTORY')) {
        fn_mkdir(OUTPUT_FILE_DIRECTORY);
    }
    if (!is_dir('WRITER_TEMPDIR')) {
        fn_mkdir(WRITER_TEMPDIR);
    }
    require DIR_CORE . 'class.pdf_converter.php';
    parse_config_file(HTML2PS_DIR . 'html2ps.config');
    fn_define('PDF_STARTED', true);
    return true;
}
Esempio n. 22
0
 /**
  * Used to sanitize user-inputed HTML from any XSS code.
  * Use this function when you want to use HTML-code inputed by users safely.
  *
  * @param string $raw_html Input HTML code
  *
  * @return string Sanitized HTML ready to be safely displayed on page.
  */
 public static function sanitizeHtml($raw_html)
 {
     try {
         $cache_dir = fn_get_cache_path(false) . 'html_purifier/';
         if (!is_dir($cache_dir)) {
             fn_mkdir($cache_dir);
         }
         $config_instance = \HTMLPurifier_Config::createDefault();
         $config_instance->set('HTML.DefinitionID', PRODUCT_NAME . '_' . PRODUCT_VERSION);
         $config_instance->set('HTML.DefinitionRev', 1);
         $config_instance->set('Cache.SerializerPath', $cache_dir);
         $config_instance->set('Cache.SerializerPermissions', DEFAULT_DIR_PERMISSIONS);
         $config_instance->autoFinalize = false;
         /**
          * Allows to configure HTMLPurifier before it purifies given HTML.
          *
          * @param \HTMLPurifier_Config $config_instance Instance of HTMLPurifier_Config
          * @param string               $raw_html        HTML to be purified
          */
         fn_set_hook('sanitize_html', $config_instance, $raw_html);
         /** @var \HTMLPurifier_HTMLDefinition $html_definition */
         if ($html_definition = $config_instance->maybeGetRawHTMLDefinition()) {
             $html_definition->addAttribute('a', 'target', new \HTMLPurifier_AttrDef_Enum(array('_blank', '_self', '_target', '_top')));
         }
         $purifier_instance = \HTMLPurifier::instance($config_instance);
         $html_purify = $purifier_instance->purify($raw_html);
         return html_entity_decode($html_purify, ENT_QUOTES, 'UTF-8');
     } catch (\Exception $e) {
         throw new DeveloperException($e->getMessage());
     }
 }
Esempio n. 23
0
    return array(CONTROLLER_STATUS_REDIRECT, 'templates.init_view?dir=' . $_REQUEST['file_path']);
} elseif ($mode == 'create_file') {
    $file_path = fn_te_normalize_path($_REQUEST, $root_dir);
    $file_info = fn_pathinfo($file_path);
    if (in_array(fn_strtolower($file_info['extension']), Registry::get('config.forbidden_file_extensions')) || empty($file_info['filename'])) {
        fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $file_info['extension'])));
    } elseif (fn_te_check_path($file_path) && @touch($file_path)) {
        fn_te_chmod($file_path, DEFAULT_FILE_PERMISSIONS, false);
        fn_set_notification('N', __('notice'), __('text_file_created', array('[file]' => fn_basename($file_path))));
    } else {
        fn_set_notification('E', __('error'), __('text_cannot_create_file', array('[file]' => fn_basename($file_path))));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'templates.init_view?dir=' . $_REQUEST['file_path']);
} elseif ($mode == 'create_folder') {
    $folder_path = fn_te_normalize_path($_REQUEST, $root_dir);
    if (fn_te_check_path($folder_path) && fn_mkdir($folder_path)) {
        fn_set_notification('N', __('notice'), __('text_directory_created', array('[directory]' => fn_basename($folder_path))));
    } else {
        fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_basename($folder_path))));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'templates.init_view?dir=' . $_REQUEST['file_path']);
} elseif ($mode == 'get_file') {
    $pname = fn_te_normalize_path($_REQUEST, $root_dir);
    if (fn_te_check_path($pname)) {
        if (is_file($pname) && !in_array(fn_strtolower(fn_get_file_ext($pname)), Registry::get('config.forbidden_file_extensions'))) {
            fn_get_file($pname);
        }
    }
    exit;
} elseif ($mode == 'edit') {
    $fname = fn_te_normalize_path($_REQUEST, $root_dir);
Esempio n. 24
0
/**
 * Create new file and put serialized data here
 * @param string $file_name
 * @param array $data
 * @param boolean $serialize
 */
function fn_twg_write_to_file($file_name, $data, $serialize = true)
{
    $dir = dirname($file_name);
    if (!file_exists($dir)) {
        fn_mkdir($dir);
    }
    $file = @fopen($file_name, 'w');
    if ($file === false) {
        $message = str_replace('[file]', $file_name, __('cannot_write_file'));
        fn_set_notification('E', __('error'), $message);
        return false;
    }
    fwrite($file, $serialize ? serialize($data) : $data);
    fclose($file);
}
Esempio n. 25
0
/**
 * Recursively copy directory (or just a file)
 *
 * @param string $source
 * @param string $dest
 * @param bool $silent
 */
function fn_copy($source, $dest, $silent = true)
{
    //var_dump($silent);
    //var_dump($source);
    // Simple copy for a file
    if (is_file($source)) {
        if (@is_dir($dest)) {
            $dest .= '/' . basename($source);
        }
        if (filesize($source) == 0) {
            $fd = fopen($dest, 'w');
            fclose($fd);
            $res = true;
        } else {
            $res = @copy($source, $dest);
        }
        @chmod($dest, DEFAULT_FILE_PERMISSIONS);
        //var_dump('1');
        return $res;
    }
    // Make destination directory
    if ($silent == false) {
        fn_echo('Creating directory <b>' . (strpos($dest, DIR_ROOT) === 0 ? str_replace(DIR_ROOT . '/', '', $dest) : $dest) . '</b><br />');
    }
    if (!@is_dir($dest)) {
        if (fn_mkdir($dest) == false) {
            //			var_dump('2');
            return false;
        }
    }
    // Loop through the folder
    if (@is_dir($source)) {
        $dir = dir($source);
        while (false !== ($entry = $dir->read())) {
            // Skip pointers
            if ($entry == '.' || $entry == '..') {
                continue;
            }
            // Deep copy directories
            if ($dest !== $source . '/' . $entry) {
                if (fn_copy($source . '/' . $entry, $dest . '/' . $entry, $silent) == false) {
                    //					var_dump('3');
                    return false;
                }
            }
        }
        // Clean up
        $dir->close();
        return true;
    } else {
        //	var_dump('4');
        return false;
    }
}
Esempio n. 26
0
/**
 * Export image (moves to selected directory on filesystem)
 *
 * @param int $image_id ID of the image
 * @param string $object object to export image for (product, category, etc...)
 * @param string $backup_path path to export image
 * @return string path to the exported image
 */
function fn_export_image($image_id, $object, $backup_path = '', $include_alt = true)
{
    if (empty($backup_path)) {
        $backup_path = 'exim/backup/images/' . $object . '/';
    }
    $backup_path = rtrim(fn_normalize_path($backup_path), '/');
    $images_path = fn_get_files_dir_path() . $backup_path;
    // if backup dir does not exist then try to create it
    fn_mkdir($images_path);
    $image_data = db_get_row("SELECT image_id, image_path FROM ?:images WHERE image_id = ?i", $image_id);
    if (empty($image_data)) {
        return '';
    }
    if ($include_alt) {
        $alt_data = db_get_hash_single_array("SELECT lang_code, description FROM ?:common_descriptions WHERE ?:common_descriptions.object_id = ?i AND ?:common_descriptions.object_holder = 'images'", array('lang_code', 'description'), $image_id);
        $alt_text = '#{';
        if (!empty($alt_data)) {
            foreach ($alt_data as $lang_code => $text) {
                $alt_text .= '[' . $lang_code . ']:' . $text . ';';
            }
        }
        $alt_text .= '}';
    }
    $path = $images_path . '/' . fn_basename($image_data['image_path']);
    Storage::instance('images')->export($object . '/' . floor($image_id / MAX_FILES_IN_DIR) . '/' . $image_data['image_path'], $path);
    return $backup_path . '/' . fn_basename($image_data['image_path']) . (!empty($alt_data) && $include_alt ? $alt_text : '');
}
Esempio n. 27
0
/**
 * Create temporary file
 *
 * @return temporary file
 */
function fn_create_temp_file()
{
    fn_mkdir(Registry::get('config.dir.cache_misc') . 'tmp');
    $tmpnam = fn_normalize_path(tempnam(Registry::get('config.dir.cache_misc') . 'tmp/', 'tmp_'));
    return $tmpnam;
}
Esempio n. 28
0
function fn_google_sitemap_get_content($map_page = 0)
{
    $cache_path = fn_get_cache_path(false) . 'google_sitemap/';
    define('ITEMS_PER_PAGE', 500);
    define('MAX_URLS_IN_MAP', 50000);
    // 50 000 is the maximum for one sitemap file
    define('MAX_SIZE_IN_KBYTES', 10000);
    // 10240 KB || 10 Mb is the maximum for one sitemap file
    $sitemap_settings = Registry::get('addons.google_sitemap');
    $location = Registry::get('config.http_location');
    $lmod = date("Y-m-d", TIME);
    header("Content-Type: text/xml;charset=utf-8");
    // HEAD SECTION
    $simple_head = <<<HEAD
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">


HEAD;
    $simple_foot = <<<FOOT

</urlset>
FOOT;
    $index_map_url = <<<HEAD
    <url>
        <loc>{$location}/</loc>
        <lastmod>{$lmod}</lastmod>
        <changefreq>{$sitemap_settings['site_change']}</changefreq>
        <priority>{$sitemap_settings['site_priority']}</priority>
    </url>

HEAD;
    // END HEAD SECTION
    // SITEMAP CONTENT
    $link_counter = 1;
    $file_counter = 1;
    fn_mkdir($cache_path);
    $file = fopen($cache_path . 'sitemap' . $file_counter . '.xml', "wb");
    fwrite($file, $simple_head . $index_map_url);
    $languages = db_get_hash_single_array("SELECT lang_code, name FROM ?:languages WHERE status = 'A'", array('lang_code', 'name'));
    if ($sitemap_settings['include_categories'] == "Y") {
        $categories = db_get_fields("SELECT category_id FROM ?:categories WHERE FIND_IN_SET(?i, usergroup_ids) AND status = 'A' ?p", USERGROUP_ALL, fn_get_google_sitemap_company_condition('?:categories.company_id'));
        //Add the all active categories
        foreach ($categories as $category) {
            $links = fn_google_sitemap_generate_link('category', $category, $languages);
            $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['categories_change'], $sitemap_settings['categories_priority']);
            fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot);
            fwrite($file, $item);
        }
    }
    if ($sitemap_settings['include_products'] == "Y") {
        $page = 1;
        $total = ITEMS_PER_PAGE;
        $params = $_REQUEST;
        $params['page'] = $page;
        $params['custom_extend'] = array('categories');
        $params['sort_by'] = 'null';
        $params['only_short_fields'] = true;
        while (ITEMS_PER_PAGE * ($params['page'] - 1) <= $total) {
            list($products, $search) = fn_get_products($params, ITEMS_PER_PAGE);
            $total = $search['total_items'];
            $params['page']++;
            foreach ($products as $product) {
                $links = fn_google_sitemap_generate_link('product', $product['product_id'], $languages);
                $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['products_change'], $sitemap_settings['products_priority']);
                fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot);
                fwrite($file, $item);
            }
        }
        unset($products);
    }
    if ($sitemap_settings['include_pages'] == "Y") {
        $pages = db_get_fields("SELECT page_id FROM ?:pages WHERE status = 'A' AND page_type != 'L' ?p", fn_get_google_sitemap_company_condition('?:pages.company_id'));
        //Add the all active pages
        foreach ($pages as $page) {
            $links = fn_google_sitemap_generate_link('page', $page, $languages);
            $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['pages_change'], $sitemap_settings['pages_priority']);
            fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot);
            fwrite($file, $item);
        }
    }
    if ($sitemap_settings['include_extended'] == "Y") {
        $vars = db_get_fields("SELECT ?:product_feature_variants.variant_id FROM ?:product_feature_variants " . "LEFT JOIN ?:product_features ON (?:product_feature_variants.feature_id = ?:product_features.feature_id) " . "WHERE ?:product_features.feature_type = 'E' AND ?:product_features.status = 'A'");
        //Add the all active extended features
        foreach ($vars as $var) {
            $links = fn_google_sitemap_generate_link('extended', $var, $languages);
            $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['extended_change'], $sitemap_settings['extended_priority']);
            fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot);
            fwrite($file, $item);
        }
    }
    if (Registry::isExist("addons.news_and_emails") && $sitemap_settings['include_news'] == 'Y') {
        $news = db_get_fields("SELECT news_id FROM ?:news WHERE status = 'A' ?p", fn_get_google_sitemap_company_condition('?:news.company_id'));
        if (!empty($news)) {
            foreach ($news as $news_id) {
                $links = fn_google_sitemap_generate_link('news', $news_id, $languages);
                $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['news_change'], $sitemap_settings['news_priority']);
                fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot);
                fwrite($file, $item);
            }
        }
    }
    if (fn_allowed_for('MULTIVENDOR') && $sitemap_settings['include_companies'] == 'Y') {
        $companies = db_get_fields("SELECT company_id FROM ?:companies WHERE status = 'A' ?p", fn_get_google_sitemap_company_condition('?:companies.company_id'));
        if (!empty($companies)) {
            foreach ($companies as $company_id) {
                $links = fn_google_sitemap_generate_link('companies', $company_id, $languages);
                $item = fn_google_sitemap_print_item_info($links, $lmod, $sitemap_settings['companies_change'], $sitemap_settings['companies_priority']);
                fn_google_sitemap_check_counter($file, $link_counter, $file_counter, $links, $simple_head, $simple_foot);
                fwrite($file, $item);
            }
        }
    }
    fn_set_hook('sitemap_item', $sitemap_settings, $file, $lmod, $link_counter, $file_counter);
    fwrite($file, $simple_foot);
    fclose($file);
    if ($file_counter == 1) {
        fn_rename($cache_path . 'sitemap' . $file_counter . '.xml', $cache_path . 'sitemap.xml');
    } else {
        // Make a map index file
        $maps = '';
        $seo_enabled = Registry::get('addons.seo.status') == 'A' ? true : false;
        for ($i = 1; $i <= $file_counter; $i++) {
            if ($seo_enabled) {
                $name = $location . '/sitemap' . $i . '.xml';
            } else {
                $name = fn_url('xmlsitemap.view?page=' . $i, 'C', 'http');
            }
            $name = htmlentities($name);
            $maps .= <<<MAP
    <sitemap>
        <loc>{$name}</loc>
        <lastmod>{$lmod}</lastmod>
    </sitemap>

MAP;
        }
        $index_map = <<<HEAD
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

{$maps}
</sitemapindex>
HEAD;
        $file = fopen($cache_path . 'sitemap.xml', "wb");
        fwrite($file, $index_map);
        fclose($file);
    }
    $filename = $cache_path . 'sitemap.xml';
    if (!empty($map_page)) {
        $name = $cache_path . 'sitemap' . $map_page . '.xml';
        if (file_exists($name)) {
            $filename = $name;
        }
    }
    readfile($filename);
    exit;
}
Esempio n. 29
0
 /**
  * Creates database and imports dump there
  * @param  string  $db_name db name
  * @return boolean true on success, false - otherwise
  */
 public static function createDb($db_name = '')
 {
     $snapshot_dir = Registry::get('config.dir.snapshots');
     $dbdump_filename = empty($db_name) ? 'cmp_current.sql' : 'cmp_release.sql';
     if (!fn_mkdir($snapshot_dir)) {
         fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_get_rel_dir($snapshot_dir))));
         return false;
     }
     $dump_file = $snapshot_dir . $dbdump_filename;
     if (is_file($dump_file)) {
         if (!is_writable($dump_file)) {
             fn_set_notification('E', __('error'), __('dump_file_not_writable'));
             return false;
         }
     }
     $fd = @fopen($snapshot_dir . $dbdump_filename, 'w');
     if (!$fd) {
         fn_set_notification('E', __('error'), __('dump_cant_create_file'));
         return false;
     }
     if (!empty($db_name)) {
         Database::changeDb($db_name);
     }
     // set export format
     db_query("SET @SQL_MODE = 'MYSQL323'");
     fn_start_scroller();
     $create_statements = array();
     $insert_statements = array();
     $status_data = db_get_array("SHOW TABLE STATUS");
     $dbdump_tables = array();
     foreach ($status_data as $k => $v) {
         $dbdump_tables[] = $v['Name'];
     }
     // get status data
     $t_status = db_get_hash_array("SHOW TABLE STATUS", 'Name');
     foreach ($dbdump_tables as $k => $table) {
         fn_echo('<br />' . __('backupping_data') . ': <b>' . $table . '</b>&nbsp;&nbsp;');
         $total_rows = db_get_field("SELECT COUNT(*) FROM {$table}");
         $index = db_get_array("SHOW INDEX FROM {$table}");
         $order_by = array();
         foreach ($index as $kk => $vv) {
             if ($vv['Key_name'] == 'PRIMARY') {
                 $order_by[] = '`' . $vv['Column_name'] . '`';
             }
         }
         if (!empty($order_by)) {
             $order_by = 'ORDER BY ' . implode(',', $order_by);
         } else {
             $order_by = '';
         }
         // Define iterator
         if (!empty($t_status[$table]) && $t_status[$table]['Avg_row_length'] < DB_MAX_ROW_SIZE) {
             $it = DB_ROWS_PER_PASS;
         } else {
             $it = 1;
         }
         for ($i = 0; $i < $total_rows; $i = $i + $it) {
             $table_data = db_get_array("SELECT * FROM {$table} {$order_by} LIMIT {$i}, {$it}");
             foreach ($table_data as $_tdata) {
                 $_tdata = fn_add_slashes($_tdata, true);
                 $values = array();
                 foreach ($_tdata as $v) {
                     $values[] = $v !== null ? "'{$v}'" : 'NULL';
                 }
                 fwrite($fd, "INSERT INTO {$table} (`" . implode('`, `', array_keys($_tdata)) . "`) VALUES (" . implode(', ', $values) . ");\n");
             }
             fn_echo(' .');
         }
     }
     fn_stop_scroller();
     if (!empty($db_name)) {
         Settings::instance()->reloadSections();
     }
     if (fn_allowed_for('ULTIMATE')) {
         $companies = fn_get_short_companies();
         asort($companies);
         $settings['company_root'] = Settings::instance()->getList();
         foreach ($companies as $k => $v) {
             $settings['company_' . $k] = Settings::instance()->getList(0, 0, false, $k);
         }
     } else {
         $settings['company_root'] = Settings::instance()->getList();
     }
     if (!empty($db_name)) {
         Database::changeDb(Registry::get('config.db_name'));
     }
     $settings = self::processSettings($settings, '');
     $settings = self::formatSettings($settings['data']);
     ksort($settings);
     $data = print_r($settings, true);
     fwrite($fd, $data);
     fclose($fd);
     @chmod($snapshot_dir . $dbdump_filename, DEFAULT_FILE_PERMISSIONS);
     return true;
 }
Esempio n. 30
0
function fn_companies_update_logos($company_id, $old_logos)
{
    $logotypes = fn_filter_uploaded_data('logotypes');
    $areas = fn_companies_get_manifest_definition();
    // Update company logotypes
    if (!empty($logotypes)) {
        $logos = $old_logos;
        foreach ($logotypes as $type => $logo) {
            $area = $areas[$type];
            $short_name = "company/{$company_id}/{$type}_{$logo['name']}";
            $filename = DIR_IMAGES . $short_name;
            fn_mkdir(dirname($filename));
            if (fn_copy($logo['path'], $filename)) {
                list($w, $h, ) = fn_get_image_size($filename);
                $logos[$area['name']] = array('vendor' => 1, 'filename' => $short_name, 'width' => $w, 'height' => $h);
            } else {
                $text = fn_get_lang_var('text_cannot_create_file');
                $text = str_replace('[file]', $filename, $text);
                fn_set_notification('E', fn_get_lang_var('error'), $text);
            }
            @unlink($logo['path']);
        }
        $logos = serialize($logos);
        db_query("UPDATE ?:companies SET logos = ?s WHERE company_id = ?i", $logos, $company_id);
    }
    fn_save_logo_alt($areas, $company_id);
}