/**
  * Outputs exception information
  * @return type
  */
 public function output()
 {
     $message = $this->message;
     fn_set_notification('E', self::ERROR_HEADER, $message);
     if ($this->getTrace()) {
         $params = array('db_host', 'db_name', 'db_user', 'db_password', 'crypt_key');
         $pattern = '/(\\s*\\[.*?(' . implode('|', $params) . ')[^\\[\\]]*\\] => )[^\\s]*/iS';
         $message .= preg_replace($pattern, '$1*****', print_r($this->getTrace(), true));
     }
     Logger::instance()->write($message);
     $filename = Registry::get('config.dir.database') . 'export.sql';
     if (file_exists($filename)) {
         $new_filename = $filename . '.' . date('Y-m-d_H-i') . '.sql';
         fn_rename($filename, $new_filename);
     }
     exit;
 }
Example #2
0
 public function rotate()
 {
     if (file_exists($this->path . $this->filename)) {
         if (empty($this->save_name)) {
             $this->save_name = date('log_commerceml.txt', TIME);
         }
         fn_rename($this->path . $this->filename, $this->path . $this->save_name);
         $logs_list = fn_get_dir_contents($this->path, false, true);
         if (!empty($logs_list) && count($logs_list) > self::MAX_LOGS_FILE) {
             rsort($logs_list);
             list(, $old_logs) = array_chunk($logs_list, self::MAX_LOGS_FILE);
             foreach ($old_logs as $filename) {
                 fn_rm($this->path . $filename);
             }
         }
     }
 }
Example #3
0
        } else {
            fn_set_notification('E', __('error'), __("text_cannot_delete_{$object}", array("[{$object}]" => fn_basename($fname))));
        }
    } else {
        fn_set_notification('E', __('error'), __('you_have_no_permissions'));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'templates.init_view?dir=' . $_REQUEST['file_path']);
} elseif ($mode == 'rename_file') {
    $pname = fn_te_normalize_path($_REQUEST, $root_dir);
    $pname_to = dirname($pname) . '/' . fn_basename($_REQUEST['rename_to']);
    $object = @is_dir($pname) ? 'directory' : 'file';
    $ext_from = fn_get_file_ext($pname);
    $ext_to = fn_get_file_ext($pname_to);
    if (in_array(fn_strtolower($ext_from), Registry::get('config.forbidden_file_extensions')) || in_array(fn_strtolower($ext_to), Registry::get('config.forbidden_file_extensions'))) {
        fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $ext_to)));
    } elseif (fn_te_check_path($pname) && fn_rename($pname, $pname_to)) {
        fn_set_notification('N', __('notice'), __("text_{$object}_renamed", array("[{$object}]" => fn_basename($pname), "[to_{$object}]" => fn_basename($pname_to))));
    } else {
        fn_set_notification('E', __('error'), __("text_cannot_rename_{$object}", array("[{$object}]" => fn_basename($pname), "[to_{$object}]" => fn_basename($pname_to))));
    }
    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))));
Example #4
0
 /**
  * Makes store files backup
  *
  * @param array $params Extra params
  *  backup_files - array List of files/folders to be added to backup
  *  pack_name - string name of result pack. Will be stored in Registry::get('config.dir.backups') . 'files/' . $pack_name
  *  fs_compress - bool Compress result dir
  * @return string Path to backuped files/archve
  */
 public static function backupFiles($params = array())
 {
     $backup_files = array('app', 'design', 'js', '.htaccess', 'api.php', 'config.local.php', 'config.php', 'index.php', 'init.php', 'robots.txt', 'var/themes_repository', 'var/snapshots');
     $backup_files[] = Registry::get('config.admin_index');
     if (fn_allowed_for('MULTIVENDOR')) {
         $backup_files[] = Registry::get('config.vendor_index');
     }
     if (!empty($params['backup_files'])) {
         $backup_files = $params['backup_files'];
     }
     if (!empty($params['extra_folders'])) {
         $params['extra_folders'] = array_map(function ($path) {
             return fn_normalize_path($path);
         }, $params['extra_folders']);
         $backup_files = array_merge($backup_files, $params['extra_folders']);
     }
     fn_set_hook('data_keeper_backup_files', $backup_files);
     $pack_name = !empty($params['pack_name']) ? $params['pack_name'] : 'backup_' . date('dMY_His', TIME);
     $destination_path = fn_get_cache_path(false) . 'tmp/backup/_files/' . $pack_name;
     $source_path = Registry::get('config.dir.root' . '/');
     fn_set_progress('step_scale', (sizeof($backup_files) + 1) * 2);
     fn_set_progress('echo', __('backup_files'), false);
     fn_rm($destination_path);
     fn_mkdir($destination_path);
     foreach ($backup_files as $file) {
         fn_set_progress('echo', __('uc_copy_files') . ': <b>' . $file . '</b>', true);
         fn_copy($source_path . $file, $destination_path . '/' . $file);
     }
     if (!empty($params['fs_compress'])) {
         fn_set_progress('echo', __('compressing_backup'), true);
         $ext = $params['fs_compress'] == 'tgz' ? '.tgz' : '.zip';
         $result = fn_compress_files($pack_name . $ext, $pack_name, fn_get_cache_path(false) . 'tmp/backup/_files/');
         $destination_path = rtrim($destination_path, '/');
         if ($result) {
             fn_rename($destination_path . $ext, Registry::get('config.dir.backups') . $pack_name . $ext);
         }
         fn_rm($destination_path);
         $destination_path .= $ext;
     }
     return $destination_path;
 }
Example #5
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;
}
Example #6
0
function fn_data_feeds_export($datafeed_id, $options = array(), $pattern = '')
{
    static $pattern;
    if (empty($pattern)) {
        $pattern = fn_get_pattern_definition('products');
    }
    $params['datafeed_id'] = $datafeed_id;
    $params['single'] = true;
    $params['available_fields'] = 'Y';
    $params = array_merge($params, $options);
    $datafeed_data = fn_data_feeds_get_data($params, DESCR_SL);
    if (empty($pattern) || empty($params['datafeed_id'])) {
        fn_set_notification('E', __('error'), __('error_exim_no_data_exported'));
        return false;
    }
    if ($datafeed_data['exclude_disabled_products'] == 'Y') {
        $params['status'] = 'A';
    }
    if (empty($datafeed_data['products']) && empty($datafeed_data['categories'])) {
        $params['cid'] = 0;
        $params['subcats'] = 'Y';
        $params['skip_view'] = 'Y';
        $params['extend'] = array('categories');
        list($products, $search) = fn_get_products($params);
        $pids = array_map(create_function('$product', '$pid = $product["product_id"]; return $pid;'), $products);
    } else {
        $pids = array();
        if (!empty($datafeed_data['products'])) {
            $pids = explode(',', $datafeed_data['products']);
        }
        if (!empty($datafeed_data['categories'])) {
            $params['cid'] = explode(',', $datafeed_data['categories']);
            $params['subcats'] = 'Y';
            $params['skip_view'] = 'Y';
            $params['extend'] = array('categories');
            list($products, $search) = fn_get_products($params);
            $_pids = array_map(create_function('$product', '$pid = $product["product_id"]; return $pid;'), $products);
            $pids = array_merge($pids, $_pids);
            unset($_pids);
        }
        $pids = array_unique($pids);
    }
    if (empty($pids)) {
        fn_set_notification('E', __('error'), __('error_exim_no_data_exported'));
        return false;
    }
    $pattern['condition']['conditions']['product_id'] = $pids;
    $fields = array();
    if (!empty($datafeed_data['fields'])) {
        foreach ($datafeed_data['fields'] as $field) {
            $fields[$field['field']] = $field['export_field_name'];
        }
    }
    $features = db_get_array('SELECT feature_id, description FROM ?:product_features_descriptions WHERE lang_code = ?s', DESCR_SL);
    $features_fields = array();
    if (!empty($features)) {
        foreach ($features as $feature) {
            $features_fields[$feature['description']] = array('process_get' => array('fn_data_feeds_get_product_features', '#key', '#field', '#lang_code'), 'linked' => false);
        }
    }
    $pattern['export_fields'] = array_merge($pattern['export_fields'], $features_fields);
    $options = $datafeed_data['export_options'];
    $options['delimiter'] = $datafeed_data['csv_delimiter'];
    $options['filename'] = $datafeed_data['file_name'];
    $options['fields_names'] = true;
    $options['force_header'] = true;
    $pattern['enclosure'] = !empty($datafeed_data['enclosure']) ? $datafeed_data['enclosure'] : '';
    if (!empty($fields)) {
        if (fn_export($pattern, $fields, $options) == true) {
            $errors = false;
            $export_location = empty($params['location']) ? $datafeed_data['export_location'] : $params['location'];
            if ($export_location == 'S') {
                if (file_exists(fn_get_files_dir_path() . $datafeed_data['file_name']) && is_dir($datafeed_data['save_dir'])) {
                    fn_rename(fn_get_files_dir_path() . $datafeed_data['file_name'], $datafeed_data['save_dir'] . '/' . $datafeed_data['file_name']);
                } else {
                    $errors = true;
                    fn_set_notification('E', __('error'), __('check_server_export_settings'));
                }
            } elseif ($export_location == 'F') {
                if (empty($datafeed_data['ftp_url'])) {
                    $errors = true;
                    fn_set_notification('E', __('error'), __('ftp_connection_problem'));
                } else {
                    preg_match("/[^\\/^\\^:]+/", $datafeed_data['ftp_url'], $matches);
                    $host = $matches[0];
                    preg_match("/.*:([0-9]+)/", $datafeed_data['ftp_url'], $matches);
                    $port = empty($matches[1]) ? 21 : $matches[1];
                    preg_match("/[^\\/]+(.*)/", $datafeed_data['ftp_url'], $matches);
                    $url = empty($matches[1]) ? '' : $matches[1];
                    $conn_id = @ftp_connect($host, $port);
                    $result = @ftp_login($conn_id, $datafeed_data['ftp_user'], $datafeed_data['ftp_pass']);
                    if (!empty($url)) {
                        @ftp_chdir($conn_id, $url);
                    }
                    $filename = fn_get_files_dir_path() . $datafeed_data['file_name'];
                    if ($result) {
                        if (@ftp_put($conn_id, $datafeed_data['file_name'], $filename, FTP_ASCII)) {
                            unlink($filename);
                        } else {
                            $errors = true;
                            fn_set_notification('E', __('error'), __('ftp_connection_problem'));
                        }
                    } else {
                        $errors = true;
                        fn_set_notification('E', __('error'), __('ftp_connection_problem'));
                    }
                    @ftp_close($conn_id);
                }
            }
            if (!$errors) {
                fn_set_notification('N', __('notice'), __('text_exim_data_exported'));
                return true;
            } else {
                unlink(fn_get_files_dir_path() . $datafeed_data['file_name']);
                return false;
            }
        } else {
            fn_set_notification('E', __('error'), __('error_exim_no_data_exported'));
            return false;
        }
    } else {
        fn_set_notification('E', __('error'), __('error_exim_fields_not_selected'));
        return false;
    }
}
Example #7
0
                    } else {
                        $tbl .= fn_price_list_print_product_data($product, $selected_fields, $style, $price_schema);
                        $fill = !$fill;
                    }
                    $counter->out();
                }
                $tbl .= '</table>';
                $counter->out();
                Pdf::batchAdd($tbl);
            }
        }
    }
    //Close and output PDF document
    $temp_filename = fn_create_temp_file();
    $imp_filename = $temp_filename . '.pdf';
    fn_rename($temp_filename, $imp_filename);
    Pdf::batchRender($imp_filename, true);
    Storage::instance('assets')->put($filename, array('file' => $imp_filename, 'caching' => true));
    fn_echo('<br />' . __('done'));
}
/**
 *
 * Adds product data in HTML format to price list table
 * @param array $product Product data
 * @param array $selected_fields Product fields that should be in price list
 * @param string $style Product row style (similar to the HTML style attribute, e.g.: style="background-color: #EEEEEE")
 * @param array $price_schema Price list columns scheme
 * @param array $options_variants Product options variants
 *
 * @return string Product data row in HTML format
 */
Example #8
0
function fn_update_image($image_data, $image_id = '0', $image_type = 'product', $rev_data = array(), $lang_code = CART_LANGUAGE)
{
    $table = 'images_links';
    $itable = 'images';
    $images_path = $image_type . '/';
    $cond = '';
    $_data = array();
    if (!empty($rev_data)) {
        $table = 'rev_images_links';
        $itable = 'rev_images';
        $images_path = $image_type . '_rev/';
        $cond = db_quote(" AND revision = ?s AND revision_id = ?i", $rev_data['revision'], $rev_data['revision_id']);
        $_data['revision'] = $rev_data['revision'];
        $_data['revision_id'] = $rev_data['revision_id'];
    }
    if (empty($image_id)) {
        $max_id = db_get_field("SELECT MAX(image_id) FROM ?:{$itable}");
        $images_path .= floor($max_id / MAX_FILES_IN_DIR) . "/";
    } else {
        $images_path .= floor($image_id / MAX_FILES_IN_DIR) . "/";
    }
    if (!fn_mkdir(DIR_IMAGES . $images_path)) {
        return false;
    }
    list($_data['image_x'], $_data['image_y'], $mime_type) = fn_get_image_size($image_data['path']);
    // Get the real image type
    $ext = fn_get_image_extension($mime_type);
    if (strpos($image_data['name'], '.') !== false) {
        $image_data['name'] = substr_replace($image_data['name'], $ext, strrpos($image_data['name'], '.') + 1);
    } else {
        $image_data['name'] .= '.' . $ext;
    }
    $fd = fopen($image_data['path'], "rb", true);
    if (!empty($fd)) {
        // Check if image path already set
        $image_path = db_get_field("SELECT image_path FROM ?:{$itable} WHERE image_id = ?i ?p", $image_id, $cond);
        // Delete image file if already exists
        if ($image_path != $image_data['name'] && empty($rev_data)) {
            fn_delete_file(DIR_IMAGES . $images_path . $image_path);
        }
        // Generate new filename if file with the same name is already exists
        if (file_exists(DIR_IMAGES . $images_path . $image_data['name']) && $image_path != $image_data['name']) {
            $image_data['name'] = substr_replace($image_data['name'], uniqid(time()) . '.', strrpos($image_data['name'], '.'), 1);
        }
        $_data['image_path'] = $image_data['name'];
        if (@fn_rename($image_data['path'], DIR_IMAGES . $images_path . $image_data['name']) == false) {
            fn_copy($image_data['path'], DIR_IMAGES . $images_path . $image_data['name']);
            @unlink($image_data['path']);
        }
        fclose($fd);
    }
    $_data['image_size'] = $image_data['size'];
    $_data['image_path'] = empty($_data['image_path']) ? '' : fn_normalize_path($_data['image_path']);
    if (!empty($image_id)) {
        db_query("UPDATE ?:{$itable} SET ?u WHERE image_id = ?i ?p", $_data, $image_id, $cond);
    } else {
        $image_id = db_query("INSERT INTO ?:{$itable} ?e", $_data);
    }
    return $image_id;
}
Example #9
0
    }
    fn_set_notification('N', fn_get_lang_var('notice'), str_replace("[{$object}]", $file, $msg));
    Registry::get('ajax')->assign('action_type', $action_type);
    exit;
} elseif ($mode == 'rename_file') {
    $file = basename($_REQUEST['file']);
    $rename_to = basename($_REQUEST['rename_to']);
    $pname = fn_normalize_path(DIR_SKINS . $current_path);
    $object = @is_dir($pname . $file) ? 'directory' : 'file';
    $ext_from = fn_get_file_ext($file);
    $ext_to = fn_get_file_ext($rename_to);
    if (in_array($ext_from, Registry::get('config.forbidden_file_extensions')) || in_array($ext_to, Registry::get('config.forbidden_file_extensions'))) {
        $action_type = 'error';
        $msg = fn_get_lang_var('text_forbidden_file_extension');
        $msg = str_replace('[ext]', $ext, $msg);
    } elseif (strpos($pname, DIR_SKINS) !== false && @fn_rename($pname . $file, $pname . $rename_to)) {
        $msg = fn_get_lang_var("text_{$object}_renamed");
        $action_type = '';
    } else {
        $action_type = 'error';
        $msg = fn_get_lang_var("text_cannot_rename_{$object}");
    }
    $msg = str_replace("[{$object}]", $file, $msg);
    $msg = str_replace("[to_{$object}]", $rename_to, $msg);
    fn_set_notification('N', fn_get_lang_var('notice'), $msg);
    Registry::get('ajax')->assign('action_type', $action_type);
    exit;
} elseif ($mode == 'create_file') {
    $file = basename($_REQUEST['file']);
    $pname = fn_normalize_path(DIR_SKINS . $current_path);
    $ext = fn_get_file_ext($file);
Example #10
0
 /**
  * Saves PDF document or outputs it
  * @param  string  $file  file with PDF document
  * @param  string  $filename filename to save PDF or name of attachment to download
  * @param  boolean $save     saves to file if true, outputs if not
  * @return mixed   true if document saved, false on failure or outputs document
  */
 protected static function output($file, $filename = '', $save = false)
 {
     if (!empty($filename) && strpos($filename, '.pdf') === false) {
         $filename .= '.pdf';
     }
     if (!empty($filename) && $save == true) {
         return fn_rename($file, $filename);
     } else {
         if (!empty($filename)) {
             $filename = fn_basename($filename);
             header("Content-disposition: attachment; filename=\"{$filename}\"");
         }
         header('Content-type: application/pdf');
         readfile($file);
         fn_rm($file);
         exit;
     }
     return false;
 }
Example #11
0
 public function backupYml()
 {
     if (file_exists($this->filepath)) {
         $path = fn_get_files_dir_path() . 'yml/';
         $archive_path = $path . 'archives/';
         fn_mkdir($archive_path);
         $archive_name = 'ym_' . date('dmY_His', TIME) . '.tgz';
         fn_compress_files($archive_name, $this->filename . '.yml', $path);
         fn_rename($path . $archive_name, $archive_path . $archive_name);
         $archives_list = fn_get_dir_contents($archive_path, false, true);
         if (!empty($archives_list) && count($archives_list) > self::ARCHIVES_LIMIT) {
             rsort($archives_list);
             list(, $old_archives) = array_chunk($archives_list, self::ARCHIVES_LIMIT);
             foreach ($old_archives as $filename) {
                 fn_rm($archive_path . $filename);
             }
         }
     }
 }
Example #12
0
function fn_google_sitemap_get_content($map_page = 0)
{
    $sitemap_settings = Registry::get('addons.google_sitemap');
    $location = fn_get_storefront_url(fn_get_storefront_protocol());
    $lmod = date("Y-m-d", TIME);
    // 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
    $parts = 0;
    if ($sitemap_settings['include_categories'] == "Y") {
        $parts++;
        $get_categories = true;
    }
    if ($sitemap_settings['include_products'] == "Y") {
        $parts++;
        $get_products = true;
    }
    if ($sitemap_settings['include_pages'] == "Y") {
        $parts++;
        $get_pages = true;
    }
    if ($sitemap_settings['include_extended'] == "Y") {
        $parts++;
        $get_features = true;
    }
    if (fn_allowed_for('MULTIVENDOR') && $sitemap_settings['include_companies'] == 'Y') {
        $parts++;
        $get_companies = true;
    }
    fn_set_progress('parts', $parts);
    // SITEMAP CONTENT
    $link_counter = 1;
    $file_counter = 1;
    $sitemap_path = fn_get_files_dir_path(false) . 'google_sitemap/';
    fn_rm($sitemap_path);
    fn_mkdir($sitemap_path);
    $file = fopen($sitemap_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 (!empty($get_categories)) {
        $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'));
        fn_set_progress('step_scale', count($categories));
        //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, 'categories');
            fwrite($file, $item);
        }
    }
    if (!empty($get_products)) {
        $total = ITEMS_PER_PAGE;
        $i = 0;
        $params = $_REQUEST;
        $params['custom_extend'] = array('categories');
        $params['sort_by'] = 'null';
        $params['only_short_fields'] = true;
        // NEEDED ONLY FOR NOT TO LOAD UNNECESSARY FIELDS FROM DB
        $params['area'] = 'C';
        $original_auth = $_SESSION['auth'];
        $_SESSION['auth'] = fn_fill_auth(array(), array(), false, 'C');
        fn_set_progress('step_scale', db_get_field("SELECT COUNT(*) FROM ?:products WHERE status = 'A'"));
        while ($params['pid'] = db_get_fields("SELECT product_id FROM ?:products WHERE status = 'A' ORDER BY product_id ASC LIMIT {$i}, {$total}")) {
            $i += $total;
            list($products) = fn_get_products($params, ITEMS_PER_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, 'products');
                fwrite($file, $item);
            }
        }
        unset($products);
        $_SESSION['auth'] = $original_auth;
    }
    if (!empty($get_pages)) {
        $page_types = fn_get_page_object_by_type();
        unset($page_types[PAGE_TYPE_LINK]);
        list($pages) = fn_get_pages(array('simple' => true, 'status' => 'A', 'page_type' => array_keys($page_types)));
        fn_set_progress('step_scale', count($pages));
        //Add the all active pages
        foreach ($pages as $page) {
            $links = fn_google_sitemap_generate_link('page', $page['page_id'], $languages, $page);
            $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, 'pages');
            fwrite($file, $item);
        }
    }
    if (!empty($get_features)) {
        $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 = ?s AND ?:product_features.status = 'A'", ProductFeatures::EXTENDED);
        fn_set_progress('step_scale', count($vars));
        //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, 'features');
            fwrite($file, $item);
        }
    }
    if (!empty($get_companies)) {
        $companies = db_get_fields("SELECT company_id FROM ?:companies WHERE status = 'A' ?p", fn_get_google_sitemap_company_condition('?:companies.company_id'));
        fn_set_progress('step_scale', count($companies));
        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, 'companies');
                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($sitemap_path . 'sitemap' . $file_counter . '.xml', $sitemap_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', fn_get_storefront_protocol());
            }
            $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($sitemap_path . 'sitemap.xml', "wb");
        fwrite($file, $index_map);
        fclose($file);
    }
    fn_set_notification('N', __('notice'), __('google_sitemap.map_generated'));
    exit;
}
        } else {
            fn_set_notification('E', __('error'), __("text_cannot_delete_{$object}", array("[{$object}]" => fn_basename($fname))));
        }
    } else {
        fn_set_notification('E', __('error'), __('you_have_no_permissions'));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path']);
} elseif ($mode == 'rename_file') {
    $pname = fn_te_normalize_path($_REQUEST, $section_root_dir);
    $pname_to = dirname($pname) . '/' . fn_basename($_REQUEST['rename_to']);
    $object = @is_dir($pname) ? 'directory' : 'file';
    $ext_from = fn_get_file_ext($pname);
    $ext_to = fn_get_file_ext($pname_to);
    if (in_array(fn_strtolower($ext_from), Registry::get('config.forbidden_file_extensions')) || in_array(fn_strtolower($ext_to), Registry::get('config.forbidden_file_extensions'))) {
        fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $ext_to)));
    } elseif (fn_te_check_path($pname, $_SESSION['active_section']) && fn_rename($pname, $pname_to)) {
        fn_set_notification('N', __('notice'), __("text_{$object}_renamed", array("[{$object}]" => fn_basename($pname), "[to_{$object}]" => fn_basename($pname_to))));
    } else {
        fn_set_notification('E', __('error'), __("text_cannot_rename_{$object}", array("[{$object}]" => fn_basename($pname), "[to_{$object}]" => fn_basename($pname_to))));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path']);
} elseif ($mode == 'create_file') {
    $file_path = fn_te_normalize_path($_REQUEST, $section_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, $_SESSION['active_section']) && @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))));
Example #14
0
<?php

/***************************************************************************
*                                                                          *
*    Copyright (c) 2004 Simbirsk Technologies Ltd. All rights reserved.    *
*                                                                          *
* This  is  commercial  software,  only  users  who have purchased a valid *
* license  and  accept  to the terms of the  License Agreement can install *
* and use this program.                                                    *
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
//
// $Id: products.post.php 6788 2009-01-16 13:29:11Z zeke $
//
if (!defined('AREA')) {
    die('Access denied');
}
if ($mode == 'clean_up') {
    fn_copy(DIR_ROOT . '/catalog/.htaccess', DIR_COMPILED . 'html_catalog_htaccess');
    fn_rm(DIR_ROOT . '/catalog', false);
    @fn_rename(DIR_COMPILED . 'html_catalog_htaccess', DIR_ROOT . '/catalog/.htaccess');
    fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('text_seo_html_catalog_cleaned_up'));
    return array(CONTROLLER_STATUS_REDIRECT, "addons.manage");
}
function fn_uc_rename_backend_files($backend_files, $dir)
{
    foreach ($backend_files as $key => $backend) {
        $new_name = Registry::get("config.{$key}");
        if (is_file($dir . $backend) && !empty($new_name)) {
            fn_rename($dir . $backend, $dir . $new_name);
        }
    }
}