Example #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);
    }
}
 function process($tmp_filename, $content_type)
 {
     $dest_filename = OUTPUT_FILE_DIRECTORY . $this->filename_escape($this->get_filename()) . "." . $content_type->default_extension;
     fn_copy($tmp_filename, $dest_filename);
     $text = $this->_link_text;
     $text = preg_replace('/%link%/', 'file://' . $dest_filename, $text);
     $text = preg_replace('/%name%/', $this->get_filename(), $text);
     print $text;
 }
Example #3
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;
 }
Example #4
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']));
     }
 }
Example #5
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));
     foreach ($all_tables as $table) {
         fn_set_progress('echo', __('optimizing_table') . "&nbsp;<b>{$table}</b>...<br />");
 private static function _getUploadedLogos()
 {
     $logos = fn_filter_uploaded_data('tw_settings');
     $logo_names = array('logo', 'favicon');
     $options = array();
     foreach ($logo_names as $logo_name) {
         if ($logos and !empty($logos[$logo_name])) {
             $logo = $logos[$logo_name];
             $filename = fn_twg_get_images_path() . $logo['name'];
             // On some hosts files copy buggy
             touch($filename);
             if (!fn_copy($logo['path'], $filename)) {
                 $_text = __('text_cannot_create_file');
                 $text = str_replace('[file]', $filename, $_text);
                 fn_set_notification('E', __('error'), $text);
             } else {
                 $options[$logo_name . '_url'] = $filename;
             }
             @unlink($logo['path']);
         }
     }
     return $options;
 }
Example #7
0
    if (fn_te_check_path($fname) && !in_array(fn_strtolower(fn_get_file_ext($fname)), Registry::get('config.forbidden_file_extensions'))) {
        Tygh::$app['ajax']->assign('content', fn_get_contents($fname));
    } else {
        fn_set_notification('E', __('error'), __('you_have_no_permissions'));
    }
    exit;
} elseif ($mode == 'restore') {
    $copied = false;
    $file_path = fn_te_normalize_path($_REQUEST, $root_dir);
    if (fn_te_check_path($file_path)) {
        $repo_path = str_replace($root_dir, fn_te_get_root('repo'), $file_path);
        if (!file_exists($repo_path) && fn_get_theme_path('[theme]') != Registry::get('config.base_theme') && is_dir(fn_get_theme_path('[repo]/[theme]'))) {
            $repo_path = preg_replace("/\\/themes_repository\\/(\\w+)\\//", "/themes_repository/" . Registry::get('config.base_theme') . "/", $repo_path);
        }
        $object_base = is_file($repo_path) ? 'file' : (is_dir($repo_path) ? 'directory' : '');
        if (!empty($object_base) && fn_copy($repo_path, $file_path)) {
            fn_set_notification('N', __('notice'), __("text_{$object_base}_restored", array("[{$object_base}]" => fn_basename($file_path))));
            Tygh::$app['ajax']->assign('content', fn_get_contents($file_path));
            $copied = true;
        }
    }
    if (!$copied) {
        $object_base = empty($object_base) ? 'file' : $object_base;
        fn_set_notification('E', __('error'), __("text_cannot_restore_{$object_base}", array("[{$object_base}]" => fn_basename($file_path))));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'templates.init_view?dir=' . $_REQUEST['file_path'] . '/' . $_REQUEST['file']);
}
/**
 * Checks if working path is inside root directory
 * @param string $path working path
 * @return boolean true of success, false - otherwise
Example #8
0
/**
 * Move addon pack from temporarily folder to specified place and install it if possible
 *
 * @param string $from Source path
 * @param string $to Destination path
 * @return bool true if installed, false otherwise
 */
function fn_addons_move_and_install($from, $to)
{
    if (defined('AJAX_REQUEST')) {
        Registry::get('ajax')->assign('non_ajax_notifications', true);
    }
    $struct = fn_get_dir_contents($from, false, true, '', '', true);
    $addon_name = '';
    foreach ($struct as $file) {
        if (preg_match('/app.+?addons[^a-zA-Z0-9_]+([a-zA-Z0-9_-]+).+?addon.xml$/i', $file, $matches)) {
            if (!empty($matches[1])) {
                $addon_name = $matches[1];
                break;
            }
        }
    }
    $relative_addon_path = str_replace(Registry::get('config.dir.root') . '/', '', Registry::get('config.dir.addons'));
    if (!file_exists($from . $relative_addon_path . $addon_name . '/addon.xml')) {
        fn_set_notification('E', __('error'), __('broken_addon_pack'));
        return false;
    }
    fn_copy($from, $to);
    fn_install_addon($addon_name);
    fn_rm($from);
    return true;
}
Example #9
0
     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) {
             fn_set_notification('N', __('notice'), __('text_file_restored', array('[file]' => fn_basename($_REQUEST['file']))));
         } else {
             fn_set_notification('E', __('error'), __('text_cannot_restore_file', array('[file]' => fn_basename($_REQUEST['file']))));
         }
         if ($copied) {
             if (defined('AJAX_REQUEST')) {
                 Registry::get('ajax')->assign('force_redirection', fn_url($_REQUEST['current_url']));
                 Registry::get('ajax')->assign('non_ajax_notifications', true);
             }
             return array(CONTROLLER_STATUS_OK, $_REQUEST['current_url']);
         }
     }
     exit;
Example #10
0
/**
 * Create/Update payments data
 *
 * @param array $payment_data
 * @param int $payment_id
 * @param string $lang_code 2-letter language code
 * @return int Payment id
 */
function fn_update_payment($payment_data, $payment_id, $lang_code = DESCR_SL)
{
    $certificate_file = fn_filter_uploaded_data('payment_certificate');
    $certificates_dir = Registry::get('config.dir.certificates');
    fn_set_hook('update_payment_pre', $payment_data, $payment_id, $lang_code, $certificate_file, $certificates_dir);
    /**
     * Create/update the certificate file
     * only for an existing payment method.
     *
     * Non-existing payment method will be created first,
     * then will be updated. (fn_update_payment calling at line 450).
     */
    if ($payment_id) {
        if ($certificate_file) {
            $file = reset($certificate_file);
            $filename = $payment_id . '/' . $file['name'];
            fn_mkdir($certificates_dir . $payment_id);
            fn_copy($file['path'], $certificates_dir . $filename);
            $payment_data['processor_params']['certificate_filename'] = $filename;
        }
        $old_params = fn_get_processor_data($payment_id);
        if (empty($payment_data['processor_params']['certificate_filename']) && isset($old_params['processor_params']['certificate_filename'])) {
            $payment_data['processor_params']['certificate_filename'] = $old_params['processor_params']['certificate_filename'];
        }
        if (!empty($payment_data['processor_params']['certificate_filename'])) {
            if (!empty($old_params['processor_params']['certificate_filename']) && $payment_data['processor_params']['certificate_filename'] != $old_params['processor_params']['certificate_filename']) {
                fn_rm($certificates_dir . $old_params['processor_params']['certificate_filename']);
            }
            if (!file_exists($certificates_dir . $payment_data['processor_params']['certificate_filename'])) {
                $payment_data['processor_params']['certificate_filename'] = '';
            }
        }
    }
    if (!empty($payment_data['processor_id'])) {
        $payment_data['template'] = db_get_field("SELECT processor_template FROM ?:payment_processors WHERE processor_id = ?i", $payment_data['processor_id']);
    }
    $payment_data['localization'] = !empty($payment_data['localization']) ? fn_implode_localizations($payment_data['localization']) : '';
    $payment_data['usergroup_ids'] = empty($payment_data['usergroup_ids']) ? USERGROUP_ALL : (is_array($payment_data['usergroup_ids']) ? implode(',', $payment_data['usergroup_ids']) : $payment_data['usergroup_ids']);
    $payment_data['tax_ids'] = !empty($payment_data['tax_ids']) ? fn_create_set($payment_data['tax_ids']) : '';
    // Update payment processor settings
    $processor_params = array();
    if (!empty($payment_data['processor_params'])) {
        $processor_params = $payment_data['processor_params'];
        $payment_data['processor_params'] = serialize($payment_data['processor_params']);
    }
    if (!empty($payment_id)) {
        $arow = db_query("UPDATE ?:payments SET ?u WHERE payment_id = ?i", $payment_data, $payment_id);
        db_query("UPDATE ?:payment_descriptions SET ?u WHERE payment_id = ?i AND lang_code = ?s", $payment_data, $payment_id, $lang_code);
        if ($arow === false) {
            fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('payment'))), '', '404');
            $payment_id = false;
        }
    } else {
        $payment_data['payment_id'] = $payment_id = db_query("INSERT INTO ?:payments ?e", $payment_data);
        foreach (fn_get_translation_languages() as $payment_data['lang_code'] => $_v) {
            db_query("INSERT INTO ?:payment_descriptions ?e", $payment_data);
        }
        /**
         * Update the certificate
         */
        if ($certificate_file && $payment_id) {
            unset($payment_data['lang_code']);
            $payment_data['processor_params'] = $processor_params;
            fn_update_payment($payment_data, $payment_id, $lang_code);
        }
    }
    fn_attach_image_pairs('payment_image', 'payment', $payment_id, $lang_code);
    fn_set_hook('update_payment_post', $payment_data, $payment_id, $lang_code, $certificate_file, $certificates_dir, $processor_params);
    return $payment_id;
}
Example #11
0
function fn_update_attachments($attachment_data, $attachment_id, $object_type, $object_id, $type = 'M', $lang_code = CART_LANGUAGE)
{
    $object_id = intval($object_id);
    if (!fn_mkdir(DIR_ATTACHMENTS)) {
        return false;
    }
    $revision_id = 0;
    if (AREA == 'A' && Registry::is_exist('revisions') && !Registry::get('revisions.working')) {
        $revisions = Registry::get('revisions');
        if (!empty($revisions['objects'][$object_type]) && !empty($revisions['objects'][$object_type]['tables'])) {
            $object_data = $revisions['objects'][$object_type];
            if ($object_data['attachments']) {
                $entry = array($object_data['key'] => $object_id);
                list($revision, $revision_id) = fn_revisions_get_last($object_type, $entry, 0, 'attachments');
            }
        }
    }
    if ($revision_id) {
        $_ = 'rev_';
        $revision_condition = db_quote(" AND revision = ?s AND revision_id = ?i", $revision, $revision_id);
    } else {
        $_ = '';
        $revision_condition = '';
    }
    $directory = DIR_ATTACHMENTS . '/' . $object_type . ($revision_condition ? '_rev' : '') . '/' . $object_id;
    if (!fn_mkdir($directory)) {
        return false;
    }
    $uploaded_data = fn_filter_uploaded_data('attachment_files');
    $rec = array('usergroup_ids' => empty($attachment_data['usergroup_ids']) ? '' : implode(',', $attachment_data['usergroup_ids']), 'position' => $attachment_data['position']);
    db_query("UPDATE ?:{$_}attachment_descriptions SET description = ?s WHERE attachment_id = ?i AND lang_code = ?s ?p", $attachment_data['description'], $attachment_id, $lang_code, $revision_condition);
    db_query("UPDATE ?:{$_}attachments SET ?u WHERE attachment_id = ?i AND object_type = ?s AND object_id = ?i AND type = ?s ?p", $rec, $attachment_id, $object_type, $object_id, $type, $revision_condition);
    if ($attachment_id && !empty($uploaded_data[$attachment_id]) && $uploaded_data[$attachment_id]['size']) {
        $filename = $uploaded_data[$attachment_id]['name'];
        $old_filename = db_get_field("SELECT filename FROM ?:{$_}attachments WHERE attachment_id = ?i ?p", $attachment_id, $revision_condition);
        if (!$revision_id && $old_filename && is_file($directory . '/' . $old_filename)) {
            unlink($directory . '/' . $old_filename);
        }
        $i = 1;
        while (is_file($directory . '/' . $filename)) {
            $filename = substr_replace($uploaded_data[$attachment_id]['name'], sprintf('%03d', $i) . '.', strrpos($uploaded_data[$attachment_id]['name'], '.'), 1);
            $i++;
        }
        fn_copy($uploaded_data[$attachment_id]['path'], $directory . '/' . $filename);
        if (is_file($directory . '/' . $filename)) {
            $filesize = filesize($directory . '/' . $filename);
            db_query("UPDATE ?:{$_}attachments SET filename = ?s, filesize = ?i WHERE attachment_id = ?i ?p", $filename, $filesize, $attachment_id, $revision_condition);
        }
    }
    return true;
}
Example #12
0
 /**
  * Copies theme files from the theme_repository to design folder
  *
  * @param  array $schema UC package schema
  * @return array List of processed files
  */
 protected function processThemesFiles($schema)
 {
     if (empty($schema['files'])) {
         return array();
     }
     $repo_files = array();
     $repo_path = str_replace($this->config['dir']['root'] . '/', '', $this->config['dir']['themes_repository']);
     // Process themes_repository
     foreach ($schema['files'] as $file_path => $file_data) {
         if (strpos($file_path, $repo_path) !== false) {
             $path = str_replace($repo_path, '', $file_path);
             $path = explode('/', $path);
             $theme_name = array_shift($path);
             $repo_files[$theme_name][] = implode('/', $path);
         }
     }
     $themes = fn_get_dir_contents($this->config['dir']['root'] . '/design/themes/');
     foreach ($themes as $theme_name) {
         $manifest = Themes::factory($theme_name)->getManifest();
         $parent_theme = empty($manifest['parent_theme']) ? 'basic' : $manifest['parent_theme'];
         if (!empty($repo_files[$parent_theme])) {
             foreach ($repo_files[$parent_theme] as $file_path) {
                 // Check if we need to create folders path before copying
                 $dir_path = dirname($this->config['dir']['root'] . '/design/themes/' . $theme_name . '/' . $file_path);
                 fn_mkdir($dir_path);
                 fn_copy($this->config['dir']['themes_repository'] . $parent_theme . '/' . $file_path, $this->config['dir']['root'] . '/design/themes/' . $theme_name . '/' . $file_path);
             }
         }
     }
     return $repo_files;
 }
Example #13
0
 /**
  * Remove LESS files
  *
  * @param string $from       The directory the LESS files are removed from
  * @param string $backup_dir Backup directory
  * @param array  $exclude    The list of directories to skip while removing
  *
  * @return boolean Result
  */
 protected function removeLessFiles($from, $backup_dir, $exclude = array())
 {
     $less_files = fn_get_dir_contents($from, false, true, '.less', '', true, $exclude);
     foreach ($less_files as $less_file) {
         if (!empty($backup_dir)) {
             if (!(fn_mkdir(dirname($backup_dir . '/' . $less_file)) && fn_copy($from . '/' . $less_file, $backup_dir . '/' . $less_file))) {
                 return false;
             }
         }
         fn_rm($from . '/' . $less_file);
     }
     return true;
 }
Example #14
0
 } elseif ($mode == 'upload') {
     if (defined('RESTRICTED_ADMIN') || Registry::get('runtime.company_id')) {
         fn_set_notification('E', __('error'), __('access_denied'));
         return array(CONTROLLER_STATUS_REDIRECT, 'addons.manage');
     }
     $addon_pack = fn_filter_uploaded_data('addon_pack', Registry::get('config.allowed_pack_exts'));
     if (empty($addon_pack[0])) {
         fn_set_notification('E', __('error'), __('text_allowed_to_upload_file_extension', array('[ext]' => implode(',', Registry::get('config.allowed_pack_exts')))));
     } else {
         // Extract the add-on pack and check the permissions
         $extract_path = fn_get_cache_path(false) . 'tmp/addon_pack/';
         $addon_pack = $addon_pack[0];
         // Re-create source folder
         fn_rm($extract_path);
         fn_mkdir($extract_path);
         fn_copy($addon_pack['path'], $extract_path . $addon_pack['name']);
         if (fn_decompress_files($extract_path . $addon_pack['name'], $extract_path)) {
             fn_rm($extract_path . $addon_pack['name']);
             $struct = fn_get_dir_contents($extract_path, false, true, '', '', true);
             $addon_name = '';
             $relative_addon_path = str_replace(Registry::get('config.dir.root') . '/', '', Registry::get('config.dir.addons'));
             foreach ($struct as $file) {
                 if (preg_match('#' . $relative_addon_path . '[^a-zA-Z0-9_]*([a-zA-Z0-9_-]+).+?addon.xml$#i', $file, $matches)) {
                     if (!empty($matches[1])) {
                         $addon_name = $matches[1];
                     }
                 }
             }
             if (empty($addon_name)) {
                 fn_set_notification('E', __('error'), __('broken_addon_pack'));
                 if (defined('AJAX_REQUEST')) {
Example #15
0
         // cleanup cache
     }
     $suffix = '?selected_section=restore';
 }
 if ($mode == 'delete') {
     if (!empty($_REQUEST['backup_files'])) {
         foreach ($_REQUEST['backup_files'] as $file) {
             @unlink(DIR_DATABASE . 'backup/' . $file);
         }
     }
 }
 if ($mode == 'upload') {
     $sql_dump = fn_filter_uploaded_data('sql_dump');
     if (!empty($sql_dump)) {
         $sql_dump = array_shift($sql_dump);
         fn_copy($sql_dump['path'], DIR_DATABASE . 'backup/' . $sql_dump['name']);
     }
 }
 if ($mode == 'optimize') {
     // Log database optimization
     fn_log_event('database', 'optimize');
     $all_tables = db_get_fields("SHOW TABLES");
     fn_start_scroller();
     foreach ($all_tables as $table) {
         fn_echo(fn_get_lang_var('optimizing_table') . "&nbsp;<b>{$table}</b>...<br />");
         db_query("OPTIMIZE TABLE {$table}");
         db_query("ANALYZE TABLE {$table}");
         $fields = db_get_hash_array("SHOW COLUMNS FROM {$table}", 'Field');
         if (!empty($fields['is_global'])) {
             // Sort table by is_global field
             fn_echo(fn_get_lang_var('sorting_data') . "&nbsp;<b>{$table}</b>...<br />");
Example #16
0
/**
 * Installs theme files
 *
 * @param string $source_theme source theme name
 * @param string $dest_theme destination theme name
 * @param boolean $from_repo flag, if set to true, theme files are copied from themes_repository
 * @return boolean true if theme was installed, false otherwise
 */
function fn_install_theme_files($source_theme, $dest_theme, $from_repo = true)
{
    $path_dest = fn_get_theme_path('[themes]/' . $dest_theme, 'C');
    if (!fn_is_theme_installed($dest_theme)) {
        if (!fn_mkdir($path_dest)) {
            fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_get_rel_dir($path_dest))));
            return false;
        }
        $path_repo_base = '';
        if ($from_repo) {
            $path_repo = fn_get_theme_path('[repo]/' . $source_theme, 'C');
            $manifest = Themes::factory($source_theme)->getRepoManifest();
            $parent_theme = isset($manifest['parent_theme']) ? $manifest['parent_theme'] : Registry::get('config.base_theme');
            if (!empty($parent_theme) && $source_theme != $parent_theme) {
                $path_repo_base = fn_get_theme_path('[repo]/' . $parent_theme, 'C');
            }
        } else {
            $path_repo = fn_get_theme_path('[themes]/' . $source_theme, 'C');
        }
        fn_set_progress('parts', fn_dirs_count($path_repo_base) + fn_dirs_count($path_repo) + 1);
        // FIXME: Backward compatibility. Create manifest.json if theme only has manifest.ini
        if (file_exists($path_repo . '/' . THEME_MANIFEST_INI) && !file_exists($path_repo . '/' . THEME_MANIFEST)) {
            $content = parse_ini_file($path_repo . '/' . THEME_MANIFEST_INI);
            fn_put_contents($path_repo . '/' . THEME_MANIFEST, json_encode($content));
        }
        if (!empty($path_repo_base)) {
            fn_copy($path_repo_base, $path_dest, false);
            // Clear layouts and styles data
            fn_rm($path_dest . '/styles');
            fn_rm($path_dest . '/layouts');
            // FIXME: Backward compatibility
            fn_rm($path_dest . '/presets');
        }
        fn_copy($path_repo, $path_dest, false);
    }
    // Re-install add-ons template files
    list($installed_addons) = fn_get_addons(array('type' => 'installed'));
    foreach ($installed_addons as $addon) {
        fn_install_addon_templates($addon['addon']);
    }
    return true;
}
Example #17
0
     }
     fn_rm(DIR_COMPILED . 'customer', false);
     fn_rm(DIR_COMPILED . 'admin', false);
     $suffix = '.design_mode';
 }
 if ($mode == 'update_logos') {
     $logos = fn_filter_uploaded_data('logotypes');
     $areas = fn_get_manifest_definition();
     fn_save_logo_alt($areas);
     // Update customer logotype
     if (!empty($logos)) {
         foreach ($logos as $type => $logo) {
             $area = $areas[$type];
             $manifest = parse_ini_file(DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . SKIN_MANIFEST, true);
             $filename = DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . $area['path'] . '/images/' . $logo['name'];
             if (fn_copy($logo['path'], $filename)) {
                 list($w, $h, ) = fn_get_image_size($filename);
                 $manifest[$area['name']]['filename'] = $logo['name'];
                 $manifest[$area['name']]['width'] = $w;
                 $manifest[$area['name']]['height'] = $h;
                 fn_write_ini_file(DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . SKIN_MANIFEST, $manifest);
             } 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']);
         }
     }
     $suffix = '.logos';
 }
Example #18
0
 /**
  * Copy files inside storage
  *
  * @param  string  $src  source file/directory
  * @param  string  $dest destination file/directory
  * @return boolean true if copied successfully, false - otherwise
  */
 public function copy($src, $dest)
 {
     $dest = $this->prefix($dest);
     if (!$this->isExist($src) || !fn_mkdir(dirname($dest))) {
         return false;
     }
     return fn_copy($this->prefix($src), $dest);
 }
Example #19
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);
}
Example #20
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 = '')
{
    $images_path = (!empty($backup_path) ? fn_strip_slashes($backup_path) : DIR_IMAGES . 'images_backup') . '/' . $object . '/';
    // if backup dir does not exist then try to create it
    if (!is_dir($images_path)) {
        fn_mkdir($images_path);
    }
    $image_data = db_get_row("SELECT image_id, image_path FROM ?:images WHERE image_id = ?i", $image_id);
    $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);
    if (empty($image_data)) {
        return '';
    }
    $path = $images_path . basename($image_data['image_path']);
    $orig_path = DIR_IMAGES . $object . '/' . floor($image_id / MAX_FILES_IN_DIR) . '/' . $image_data['image_path'];
    if (is_file($orig_path)) {
        fn_copy($orig_path, $path);
    }
    return $path . (!empty($alt_data) ? '#' . serialize($alt_data) : '');
}
Example #21
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;
 }
Example #22
0
 private function _copyFiles()
 {
     if (is_dir($this->store_data['path'] . '/var/attachments')) {
         fn_copy($this->store_data['path'] . '/var/attachments', DIR_ROOT . '/var/attachments', true);
     }
     $type_path_info = Registry::get('config.storage.downloads');
     fn_copy($this->store_data['path'] . '/var/downloads', $type_path_info['dir'], true);
     return true;
 }
Example #23
0
                 if ((string) $item['for'] == 'description' && (string) $item['lang'] == $descriptions['lang_code']) {
                     $descriptions['description'] = (string) $item;
                 }
             }
         }
         db_query("REPLACE INTO ?:addon_descriptions ?e", $descriptions);
     }
 }
 // Install templates
 $areas = array('customer', 'admin', 'mail');
 $addon = (string) $xml->id;
 $installed_skins = fn_get_dir_contents(DIR_SKINS);
 foreach ($installed_skins as $skin_name) {
     foreach ($areas as $area) {
         if (is_dir(DIR_SKINS_REPOSITORY . 'base/' . $area . '/addons/' . $addon)) {
             fn_copy(DIR_SKINS_REPOSITORY . 'base/' . $area . '/addons/' . $addon, DIR_SKINS . $skin_name . '/' . $area . '/addons/' . $addon);
         }
     }
 }
 // Execute optional queries
 if (isset($xml->opt_queries)) {
     foreach ($xml->opt_queries->item as $v) {
         if (!isset($v['for']) || (string) $v['for'] == 'install') {
             db_query((string) $v);
         }
     }
 }
 // Add optional language variables
 if (isset($xml->opt_language_variables)) {
     $cache = array();
     foreach ($xml->opt_language_variables->item as $v) {
Example #24
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 #25
0
/**
 * Function get local uploaded
 *
 * @param unknown_type $val
 * @staticvar array $cache
 * @return unknown
 */
function fn_get_local_data($val)
{
    $cache =& Registry::get('temp_fs_data');
    if (!isset($cache[$val['path']])) {
        // cache file to allow multiple usage
        $tempfile = fn_create_temp_file();
        //	var_dump($tempfile);
        /*error_reporting(E_ALL);
        		ini_set('display_errors', '1');
        		*/
        if (move_uploaded_file($val['path'], $tempfile) == true) {
            @chmod($tempfile, DEFAULT_FILE_PERMISSIONS);
            $cache[$val['path']] = $tempfile;
        } else {
            $cache[$val['path']] = '';
        }
    }
    if (defined('KEEP_UPLOADED_FILES')) {
        $tempfile = fn_create_temp_file();
        fn_copy($cache[$val['path']], $tempfile);
        clearstatcache();
        $val['path'] = $tempfile;
    } else {
        $val['path'] = $cache[$val['path']];
        //	$val['path'] = $val['path'];
    }
    return $val;
}
Example #26
0
         } else {
             return array(CONTROLLER_STATUS_OK, 'themes.manage');
         }
     }
     $non_writable_folders = fn_check_copy_ability($source, $destination);
     if (!empty($non_writable_folders)) {
         if (!empty($_REQUEST['ftp_access'])) {
             Tygh::$app['view']->assign('ftp_access', $_REQUEST['ftp_access']);
         }
         Tygh::$app['view']->assign('non_writable', $non_writable_folders);
         if (defined('AJAX_REQUEST')) {
             Tygh::$app['view']->display('views/themes/components/correct_permissions.tpl');
             exit;
         }
     } else {
         fn_copy($source, $destination);
         fn_rm($source);
         if (defined('AJAX_REQUEST')) {
             Tygh::$app['ajax']->assign('force_redirection', fn_url('themes.manage'));
             exit;
         }
     }
 }
 if ($mode == 'install') {
     if (!empty($_REQUEST['theme_name'])) {
         // Copy theme files to design/themes directory
         fn_install_theme_files($_REQUEST['theme_name'], $_REQUEST['theme_name']);
     }
     return array(CONTROLLER_STATUS_OK, 'themes.manage?selected_section=general');
 }
 if ($mode == 'delete') {
Example #27
0
/**
 * Function get local uploaded
 *
 * @param array $val
 * @staticvar array $cache
 * @return array
 */
function fn_get_local_data($val)
{
    $cache = Registry::get('temp_fs_data');
    if (!isset($cache[$val['path']])) {
        // cache file to allow multiple usage
        $tempfile = fn_create_temp_file();
        if (move_uploaded_file($val['path'], $tempfile) == true) {
            @chmod($tempfile, DEFAULT_FILE_PERMISSIONS);
            clearstatcache(true, $tempfile);
            $cache[$val['path']] = $tempfile;
        } else {
            $cache[$val['path']] = '';
        }
        Registry::set('temp_fs_data', $cache);
    }
    if (defined('KEEP_UPLOADED_FILES')) {
        $tempfile = fn_create_temp_file();
        fn_copy($cache[$val['path']], $tempfile);
        $val['path'] = $tempfile;
    } else {
        $val['path'] = $cache[$val['path']];
    }
    return !empty($val['size']) ? $val : false;
}
Example #28
0
function fn_copy_product_files($file_id, $file, $product_id, $var_prefix = 'file')
{
    $revisions = Registry::get('revisions');
    if (!empty($revisions['objects']['product']['tables'])) {
        $revision = true;
    } else {
        $revision = false;
    }
    if ($revision) {
        $filename = $file['name'];
        $i = 1;
        while (is_file(substr(DIR_DOWNLOADS, 0, -1) . ($revision ? '_rev' : '') . '/' . $product_id . '/' . $filename)) {
            $filename = substr_replace($file['name'], sprintf('%03d', $i) . '.', strrpos($file['name'], '.'), 1);
            $i++;
        }
    } else {
        $filename = $file['name'];
    }
    $_data = array();
    $_data[$var_prefix . '_path'] = $filename;
    $_data[$var_prefix . '_size'] = $file['size'];
    list($new_file, $_data[$var_prefix . '_path']) = fn_generate_file_name(substr(DIR_DOWNLOADS, 0, -1) . ($revision ? '_rev' : '') . '/' . $product_id . '/', $_data[$var_prefix . '_path']);
    if (fn_copy($file['path'], $new_file) == false) {
        $_msg = fn_get_lang_var('cannot_write_file');
        $_msg = str_replace('[file]', $new_file, $_msg);
        fn_set_notification('E', fn_get_lang_var('error'), $_msg);
        return false;
    }
    db_query('UPDATE ?:product_files SET ?u WHERE file_id = ?i', $_data, $file_id);
    return true;
}
Example #29
0
 /**
  * Copy style
  * @param  string  $from style ID to copy from
  * @param  string  $to   style ID to copy to
  * @return boolean true on success, false otherwise
  */
 public function copy($from, $to)
 {
     $from = fn_basename($from);
     $to = fn_basename($to);
     $style_file_from = $this->getStyleFile($from);
     $style_file_to = $this->getStyleFile($to, 'less');
     if (is_file($style_file_from)) {
         if (fn_copy($style_file_from, $style_file_to)) {
             $types = array('css');
             foreach ($types as $type) {
                 $style_file_from = $this->getStyleFile($from, $type);
                 if (file_exists($style_file_from)) {
                     fn_copy($style_file_from, $this->getStyleFile($to, $type));
                 }
             }
             fn_copy(Patterns::instance($this->params)->getPath($from), Patterns::instance($this->params)->getPath($to));
             $content = fn_get_contents($style_file_to);
             $content = str_replace('/patterns/' . $from . '/', '/patterns/' . $to . '/', $content);
             fn_put_contents($style_file_to, $content);
             // Clone logos for new style
             $logos = db_get_array('SELECT * FROM ?:logos WHERE style_id = ?s AND company_id = ?i', $from, $this->company_id);
             foreach ($logos as $logo) {
                 $object_id = fn_update_logo(array('type' => $logo['type'], 'layout_id' => $logo['layout_id'], 'style_id' => $to), $this->company_id);
                 fn_clone_image_pairs($object_id, $logo['logo_id'], 'logos');
             }
             return true;
         }
     }
     return false;
 }
Example #30
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;
 }