/** * Gets theme patterns * @param string $style_id style ID * @return array theme patterns */ public static function get($style_id) { $style_id = fn_basename($style_id); $url = Registry::get('config.current_location') . '/' . fn_get_theme_path('[relative]/[theme]/media/images/patterns/' . $style_id . '/'); $patterns = self::getPath($style_id); return fn_get_dir_contents($patterns, false, true, '', $url); }
function fn_get_payment_templates() { $templates = fn_get_dir_contents(DIR_SKINS . Registry::get('settings.skin_name_customer') . '/customer/views/orders/components/payments/', false, true, '.tpl'); if (is_array($templates)) { foreach ($templates as $k => $v) { $templates[$k] = $v; } } return $templates; }
function fn_settings_variants_addons_hybrid_auth_icons_pack() { $available_icons_packs = array(); $theme_name = Settings::instance()->getValue('theme_name', ''); $icons_dir = fn_get_theme_path('[themes]/', 'C') . $theme_name . '/media/images/addons/hybrid_auth/icons/'; $icons_packs = fn_get_dir_contents($icons_dir); foreach ($icons_packs as $id => $icons_packs_name) { $available_icons_packs[$icons_packs_name] = $icons_packs_name; } return $available_icons_packs; }
function fn_settings_variants_appearance_default_image_previewer() { $previewers_path = Registry::get('config.dir.root') . '/js/tygh/previewers'; $previewers = fn_get_dir_contents($previewers_path, false, true, 'js'); $return = array(); foreach ($previewers as $previewer) { $previewer_description = fn_get_file_description($previewers_path . '/' . $previewer, 'previewer-description'); $return[fn_basename($previewer, '.previewer.js')] = $previewer_description; } return $return; }
public static final function removeDirectoryContent($path) { if (is_array($path)) { foreach ($path as $dir) { self::removeDirectoryContent($dir); } return true; } self::removeFiles(fn_get_dir_contents($path, true, true, '', $path)); return true; }
/** * Gets theme patterns * @param string $style_id style ID * @param boolean $url_prefix prefix files with URL if set to true * @return array theme patterns */ public function get($style_id, $url_prefix = true) { $style_id = fn_basename($style_id); $patterns = $this->getPath($style_id); $url = $this->getUrl($style_id); $prefix = $patterns . '/'; if ($url_prefix) { $prefix = Registry::get('config.current_location') . '/' . fn_get_rel_dir($this->getPath($style_id) . '/'); } return fn_get_dir_contents($patterns, false, true, '', $prefix); }
/** * Generates new snapshot * @param array $params params list */ public static function create($params) { if (empty($params['dir_root'])) { $params['dir_root'] = Registry::get('config.dir.root'); } if (empty($params['dist'])) { $params['dist'] = false; } $dir_root = $params['dir_root']; $dist = $params['dist']; $folders = array('app', 'js', $params['theme_rel_backend']); if ($dist) { $themes_dir = $params['themes_repo']; $themes_dir_to = $params['themes_frontend']; } else { $themes_dir = $params['themes_frontend']; } $themes = fn_get_dir_contents($themes_dir); $snapshot = array('time' => time(), 'files' => array(), 'dirs' => array(), 'themes' => array()); if ($dist) { $snapshot['db_scheme'] = fn_get_contents($dir_root . '/install/database/scheme.sql'); // remove myslqdump comments $snapshot['db_scheme'] = preg_replace('|/\\*!.+\\*/;\\n|imSU', '', $snapshot['db_scheme']); // form list of tables preg_match_all('/create table `(.+)`/imSU', $snapshot['db_scheme'], $tables); $snapshot['db_tables'] = !empty($tables[1]) ? $tables[1] : array(); } $new_snapshot = self::make($dir_root, $folders, array('config.local.php')); self::arrayMerge($snapshot, $new_snapshot); foreach ($folders as $folder_name) { $path = $dir_root . '/' . $folder_name; $new_snapshot = self::make($path); self::arrayMerge($snapshot, $new_snapshot); } foreach ($themes as $theme_name) { if (is_numeric($theme_name) && $theme_name === strval($theme_name + 0)) { continue; // this is company subfolder } $path = "{$themes_dir}/{$theme_name}"; if ($dist) { $new_snapshot = self::make($path, array(), array(), array($themes_dir => $themes_dir_to), true); } else { $new_snapshot = self::make($path, array(), array(), array(), true); } $snapshot['themes'][$theme_name]['files'] = $snapshot['themes'][$theme_name]['dirs'] = array(); self::arrayMerge($snapshot['themes'][$theme_name], $new_snapshot); } $snapshot['addons'] = fn_get_dir_contents(Registry::get('config.dir.addons')); fn_mkdir(Registry::get('config.dir.snapshots')); $snapshot_filename = fn_strtolower(PRODUCT_VERSION . '_' . (PRODUCT_STATUS ? PRODUCT_STATUS . '_' : '') . PRODUCT_EDITION . ($dist ? '_dist' : '')); $snapshot_filecontent = '<?php $snapshot' . ($dist ? '_dist' : '') . ' = ' . var_export($snapshot, true) . '; ?>'; fn_put_contents(Registry::get('config.dir.snapshots') . "{$snapshot_filename}.php", $snapshot_filecontent); }
/** * Returns addons list that need be installed for some PRODUCT TYPE * * @param string $product_type Product type * @return array List af addons */ private function _getAddons($product_type = PRODUCT_EDITION) { $available_addons = fn_get_dir_contents(Registry::get('config.dir.addons'), true, false); $addons_list = array(); foreach ($available_addons as $addon_name) { $scheme = SchemesManager::getScheme($addon_name); if (!empty($scheme)) { $auto_install = $scheme->autoInstallFor(); if (in_array($product_type, $auto_install)) { $addons_list[] = $addon_name; } } } return $addons_list; }
/** * Gets list of styles * * @return array List of available styles */ public function getList($params = array()) { $styles = array(); $style_files = array(); $path = $this->getStylesPath(); $style_files = fn_get_dir_contents($path, false, true, 'less'); fn_set_hook('styles_get_list', $style_files, $params); if (!empty($style_files)) { foreach ($style_files as $id => $style_id) { $style_id = fn_basename($style_id, '.less'); $styles[$style_id] = self::get($style_id, $params); } } return $styles; }
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); } } } }
function fn_mp_get_setting_templates() { $templates = array(); $skin_path = fn_get_theme_path('[themes]/[theme]', 'A'); $relative_directory_path = 'addons/maps_provider/settings/'; $template_path = $skin_path . '/templates/' . $relative_directory_path; $_templates = fn_get_dir_contents($template_path, false, true, '.tpl'); if (!empty($_templates)) { $needles = array('settings_', '.tpl'); $replacements = array('', ''); foreach ($_templates as $template) { if (preg_match('/^settings_/', $template, $m)) { $_template = str_replace($needles, $replacements, $template); // Get the provider name $templates[$_template] = $relative_directory_path . $template; } } } return $templates; }
/** * Gets list of styles * * @return array List of available styles */ public function getList($params = array()) { $styles = array(); $style_files = array(); $path = $this->getStylesPath(); $style_files = fn_get_dir_contents($path, false, true, 'less'); /** * Modifies styles list * * @param object $this Styles object * @param array $style_files style files list * @param array $params search params */ fn_set_hook('styles_get_list', $this, $style_files, $params); if (!empty($style_files)) { foreach ($style_files as $id => $style_id) { $style_id = fn_basename($style_id, '.less'); $styles[$style_id] = $this->get($style_id, $params); } } return $styles; }
/** * Init skin * * @param array $params request parameters * @return boolean always true */ function fn_init_skin($params) { if ((Registry::get('settings.skin_name_' . AREA_NAME) == '' || !is_dir(DIR_SKINS . Registry::get('settings.skin_name_' . AREA_NAME))) && !defined('SKINS_PANEL')) { $all = fn_get_dir_contents(DIR_SKINS, true); $skin_found = false; foreach ($all as $sk) { if (is_file(DIR_SKINS . $sk . '/' . AREA_NAME . '/index.tpl')) { Registry::set('settings.skin_name' . AREA_NAME, basename($sk)); $skin_found = true; break; } } if ($skin_found == false) { die("No skins found"); } else { echo <<<EOT \t\t\t\t<div style="background: #ff0000; color: #ffffff; font-weight: bold;" align="center">SELECTED SKIN NOT FOUND. REPLACED BY FIRST FOUND</div> EOT; } } if (defined('DEVELOPMENT')) { foreach (Registry::get('config.dev_skins') as $k => $v) { Registry::set('settings.skin_name_' . $k, $v); } } // Allow user to change the skin during the current session if (defined('SKINS_PANEL')) { $demo_skin = fn_get_cookie('demo_skin'); if (!empty($params['demo_skin'][AREA])) { $tmp_skin = basename($params['demo_skin'][AREA]); if (is_dir(DIR_SKINS . $tmp_skin)) { Registry::set('settings.skin_name_' . AREA_NAME, $tmp_skin); $demo_skin[AREA] = $tmp_skin; } else { Registry::set('settings.skin_name_' . AREA_NAME, $demo_skin[AREA]); } } elseif (empty($demo_skin[AREA])) { $demo_skin[AREA] = 'basic'; } Registry::set('settings.skin_name_' . AREA_NAME, $demo_skin[AREA]); fn_set_cookie('demo_skin', $demo_skin); Registry::set('demo_skin', array('selected' => $demo_skin, 'available_skins' => fn_get_available_skins(AREA_NAME))); } $skin_name = Registry::get('settings.skin_name_' . AREA_NAME); Registry::set('config.skin_name', $skin_name); Registry::set('config.skin_path', Registry::get('config.current_path') . '/skins/' . $skin_name . '/' . AREA_NAME); Registry::set('config.no_image_path', Registry::get('config.images_path') . 'no_image.gif'); return true; }
/** * Copies files using FTP access * * @param string $source Absolute path (non-ftp) to source dir/file * @param string $destination Absolute path (non-ftp) to destination dir/file * @param array $ftp_access * array( * 'hostname', * 'username', * 'password', * 'directory' * ) * @return bool true if all files were copied or (string) Error message */ function fn_copy_by_ftp($source, $destination, $ftp_access) { try { $ftp = new Ftp(); $ftp->connect($ftp_access['hostname']); $ftp->login($ftp_access['username'], $ftp_access['password']); $ftp->chdir($ftp_access['directory']); $files = $ftp->nlist(''); if (!empty($files) && in_array('config.php', $files)) { $ftp_destination = str_replace(Registry::get('config.dir.root'), '', $destination); if (is_file($source)) { // File try { $file = ltrim($ftp_destination, '/'); $ftp->put($file, $source, FTP_BINARY); } catch (FtpException $e) { throw new FtpException('ftp_access_denied' . ':' . $e->getMessage()); } } else { // Dir $ftp->chdir($ftp_access['directory'] . $ftp_destination); $struct = fn_get_dir_contents($source, false, true, '', '', true); foreach ($struct as $file) { $dir = dirname($file); if (!$ftp->isDir($dir)) { try { $ftp->mkDirRecursive($dir); } catch (FtpException $e) { throw new FtpException('ftp_access_denied' . ':' . $e->getMessage()); } } try { $ftp->put($file, $source . $file, FTP_BINARY); } catch (FtpException $e) { throw new FtpException('ftp_access_denied' . ':' . $e->getMessage()); } } } return true; } else { throw new FtpException('ftp_directory_is_incorrect'); } } catch (FtpException $e) { return __('invalid_ftp_access') . ': ' . $e->getMessage(); } return false; }
} if ($mode == 'getfile' && !empty($_REQUEST['file'])) { fn_get_file(Registry::get('config.dir.backups') . fn_basename($_REQUEST['file'])); } elseif ($mode == 'manage') { $view = Tygh::$app['view']; // Calculate database size and fill tables array $status_data = db_get_array("SHOW TABLE STATUS"); $database_size = 0; $all_tables = array(); foreach ($status_data as $k => $v) { $database_size += $v['Data_length'] + $v['Index_length']; $all_tables[] = $v['Name']; } $view->assign('database_size', $database_size); $view->assign('all_tables', $all_tables); $files = fn_get_dir_contents(Registry::get('config.dir.backups'), false, true, array('.sql', '.tgz', '.zip'), '', true); sort($files, SORT_STRING); $backup_files = array(); $date_format = Registry::get('settings.Appearance.date_format') . ' ' . Registry::get('settings.Appearance.time_format'); if (is_array($files)) { $backup_dir = Registry::get('config.dir.backups'); foreach ($files as $file) { $ext = fn_get_file_ext($backup_dir . $file); $backup_files[$file]['size'] = filesize($backup_dir . $file); $backup_files[$file]['create'] = fn_date_format(filemtime($backup_dir . $file), $date_format); if ($ext == 'sql') { $backup_files[$file]['type'] = 'database'; } else { $backup_files[$file]['type'] = DataKeeper::getArchiveType($backup_dir . $file); } }
/** * Create a new filename with postfix * * @param string $path * @param string $file * @return array ($full_path, $new_filename) */ function fn_generate_file_name($path, $file) { if (!file_exists($path . $file)) { return array($path . $file, $file); } $files = fn_get_dir_contents($path, false, true); $num = 1; $found = false; $file_ext = fn_get_file_ext($file); $file_name = basename($path . $file, '.' . $file_ext); while (!$found) { $new_filename = $file_name . '_' . $num . '.' . $file_ext; if (!in_array($new_filename, $files)) { break; } $num++; } return array($path . $new_filename, $new_filename); }
function fn_get_default_layouts_sources($theme_name = '', $themes_path = '') { $layouts_sources = array(); if (empty($themes_path)) { $themes_path = fn_get_theme_path('[themes]', 'C'); } if (empty($theme_name)) { $installed_themes = fn_get_dir_contents($themes_path, true); foreach ($installed_themes as $theme_name) { $layouts_sources = array_merge($layouts_sources, fn_get_default_layouts_sources($theme_name, $themes_path)); } } else { $layouts_path = $themes_path . '/' . $theme_name . '/layouts/'; $layouts = fn_get_dir_contents($layouts_path, false, true, '.xml'); foreach ($layouts as $layout_name) { $layout_path = fn_normalize_path($layouts_path . $layout_name); if (file_exists($layout_path)) { $layout_data = Exim::instance(Registry::get('runtime.company_id'), 0, $theme_name)->getLayoutData($layout_path, false); if (!empty($layout_data)) { $layout_data['theme_name'] = $theme_name; $layout_data['filename'] = $layout_name; $layouts_sources[] = $layout_data; } } } } return $layouts_sources; }
$new_status = $_REQUEST['status']; if ($old_status != $new_status) { $func = 'fn_settings_actions_addons_' . $_REQUEST['id']; if (function_exists($func)) { $func($new_status, $old_status); } if ($old_status != $new_status) { db_query("UPDATE ?:addons SET status = ?s WHERE addon = ?s", $_REQUEST['status'], $_REQUEST['id']); fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('status_changed')); } else { $ajax->assign('return_status', $old_status); } } exit; } elseif ($mode == 'manage') { $all_addons = fn_get_dir_contents(DIR_ADDONS, true, false); $installed_addons = db_get_hash_array("SELECT a.addon, a.status, d.description as name, b.description, LENGTH(a.options) as has_options, d.object_id, d.object_type FROM ?:addons as a LEFT JOIN ?:addon_descriptions as d ON d.addon = a.addon AND d.object_id = '' AND d.object_type = 'A' AND d.lang_code = ?s LEFT JOIN ?:addon_descriptions as b ON b.addon = a.addon AND b.object_id = '' AND b.object_type = 'D' AND b.lang_code = ?s ORDER BY d.description ASC", 'addon', CART_LANGUAGE, CART_LANGUAGE); fn_update_lang_objects('installed_addons', $installed_addons); $addons_list = array(); foreach ($all_addons as $addon) { if (!empty($installed_addons[$addon])) { $addons_list[$addon] = $installed_addons[$addon]; } else { if (file_exists(DIR_ADDONS . $addon . '/addon.xml')) { $xml = simplexml_load_file(DIR_ADDONS . $addon . '/addon.xml'); $addons_list[$addon] = array('status' => 'N', 'name' => (string) $xml->name); } } } $view->assign('addons_list', fn_sort_array_by_key($addons_list, 'name', SORT_ASC)); }
function fn_get_gift_certificate_templates() { $templates = array(); $dir = fn_get_theme_path('[themes]/[theme]/mail/templates', 'C') . '/addons/gift_certificates/templates'; $files = fn_get_dir_contents($dir, false, true, 'tpl'); foreach ($files as $file) { $path_parts = explode(".", $file); $file_name = __($path_parts[0]); $templates[$file] = !empty($file_name) ? $file_name : ucfirst($path_parts[0]); } return $templates; }
/** * Gets meta information from the PO file * * @param string $base_path Root dir * @param string $pack_file PO file name (without .po extension) * @param bool $reinstall Use this flag, if pack was alread installed before to get META information * @return array List of lang pack meta information */ public static function getLangPacksMeta($base_path = '', $pack_file = '', $reinstall = false, $check_installed = true) { $installed_languages = $check_installed ? self::getAll(true) : array(); $path = empty($base_path) ? Registry::get('config.dir.lang_packs') : $base_path; $return = array(); if (empty($pack_file)) { $po_file_list = array(); foreach (fn_get_dir_contents($path, true, false) as $pack_directory) { if (is_dir($path . $pack_directory)) { $po_file_list[] = $pack_directory . '/core.po'; } } } else { $po_file_list = array($pack_file); } foreach ($po_file_list as $po_file_name) { $po_file_path = $path . $po_file_name; if (!file_exists($po_file_path)) { fn_set_notification('E', __('error'), __('incorrect_po_pack_structure', array('[pack_path]' => fn_get_rel_dir(dirname($po_file_path))))); continue; } $metadata = Po::getMeta($po_file_path); if (is_array($metadata)) { if (!self::isValidMeta($metadata)) { fn_set_notification('E', __('error'), __('po_file_is_incorrect', array('[file]' => fn_get_rel_dir($po_file_path)))); continue; } } else { fn_set_notification('E', __('error'), $metadata); continue; } if (isset($installed_languages[$metadata['lang_code']]) && !$reinstall) { continue; } $return[] = $metadata; } if (!empty($pack_file) && !empty($return)) { return reset($return); } return $return; }
/** * Validate specified data by schema * * @param array $schema Incoming validator schema * @param array $request Request data * * @return array Validation result and Data to be displayed */ public function check($schema, $request) { $data = array(); $show_notifications = !empty($request['change_ftp_settings']); if (!empty($schema['files'])) { $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)] = $file_data; } } $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 => $file_data) { $schema['files']['design/themes/' . $theme_name . '/' . $file_path] = $file_data; } } } foreach ($schema['files'] as $file_path => $file_data) { $result = true; $original_path = $this->config['dir']['root'] . '/' . $file_path; switch ($file_data['status']) { case 'changed': if (file_exists($original_path)) { if (!$this->isWritable($original_path)) { $result = $this->correctPermissions($original_path, $show_notifications); } } else { $file_path = $this->getParentDir($file_path); if (!$this->isWritable($this->config['dir']['root'] . '/' . $file_path)) { $result = $this->correctPermissions($original_path, $show_notifications); } } break; case 'deleted': if (file_exists($original_path)) { if (!$this->isWritable($original_path)) { $result = $this->correctPermissions($original_path, $show_notifications); } } if ($result) { $file_path = $this->getParentDir($file_path); if (!$this->isWritable($this->config['dir']['root'] . '/' . $file_path)) { $result = $this->correctPermissions($this->config['dir']['root'] . '/' . $file_path, $show_notifications); } } break; case 'new': if (file_exists($original_path) && !$this->isWritable($original_path)) { $result = $this->correctPermissions($original_path, $show_notifications); $file_path = dirname($file_path); } else { $file_path = $this->getParentDir($file_path); if (!$this->isWritable($this->config['dir']['root'] . '/' . $file_path)) { $result = $this->correctPermissions($this->config['dir']['root'] . '/' . $file_path, $show_notifications); } } break; } if (!$result) { $data[] = $file_path; } } } $backups_writable = $this->checkDirectoryIsWritable($this->config['dir']['backups'], $show_notifications); if (!$backups_writable) { $data[] = $this->config['dir']['backups']; } $upgrades_dir = $this->config['dir']['root'] . '/upgrades'; $upgrades_writable = $this->checkDirectoryIsWritable($upgrades_dir, $show_notifications); if (!$upgrades_writable) { $data[] = $upgrades_dir; } // Exclude duplicates $data = array_unique($data); if ($show_notifications && empty($data)) { return array(false, 'ok'); } else { return array(empty($data), $data); } }
/** * Gets meta information from the PO file * * @param string $base_path Root dir * @param string $pack_file PO file name (without .po extension) * @param bool $reinstall Use this flag, if pack was alread installed before to get META information * @return array List of lang pack meta information */ public static function getLangPacksMeta($base_path = '', $pack_file = '', $reinstall = false, $check_installed = true) { if ($check_installed) { $installed_languages = fn_get_translation_languages(true); } else { $installed_languages = array(); } $path = empty($base_path) ? Registry::get('config.dir.lang_packs') : $base_path; $langs = array(); if (!empty($pack_file)) { $langs_packs = array($pack_file); } else { $_packs = fn_get_dir_contents($path, true, false, '.po'); foreach ($_packs as $_pack) { $langs_packs[] = $_pack . '/core.po'; } } foreach ($langs_packs as $pack_name) { $pack_meta = Po::getMeta($path . $pack_name); if (!is_array($pack_meta)) { fn_set_notification('E', __('error'), $pack_meta); continue; } if (isset($installed_languages[$pack_meta['lang_code']]) && !$reinstall) { continue; } $langs[] = $pack_meta; } if (!empty($pack_file) && !empty($langs)) { return reset($langs); } return $langs; }
/** * 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; }
/** * Put directory to storage * * @param string $dir directory to get files from * @param array $params additional parameters * @return boolean true of success, false on fail */ public function putDir($dir, $params = array()) { $s3 = $this->s3(); // get object to initialize class and get access to contstants below $i = 0; $max_batch = 10; $files = fn_get_dir_contents($dir, false, true, '', '', true); fn_set_progress('step_scale', sizeof($files)); foreach ($files as $source_file) { fn_set_progress('echo', '.'); $i++; $data = array('acl' => \AmazonS3::ACL_PUBLIC, 'headers' => array()); // File can not be accessible via direct link if ($this->getOption('secured')) { $data['headers']['Content-disposition'] = 'attachment; filename="' . fn_basename($source_file) . '"'; $data['acl'] = \AmazonS3::ACL_PRIVATE; } $data['contentType'] = fn_get_file_type($source_file); $data['fileUpload'] = $dir . '/' . $source_file; $res = $s3->batch()->create_object($this->getOption('bucket'), $this->prefix($source_file), $data); if ($i == $max_batch) { $s3->batch()->send(); $i = 0; } } if (!empty($i)) { $s3->batch()->send(); // send the rest of the batch } return true; }
function fn_get_available_skins($area = '') { $sdir = 'var/skins_repository'; if (!is_dir(DIR_ROOT . '/' . $sdir)) { $sdir = 'skins'; } $skins = fn_get_dir_contents(DIR_ROOT . '/' . $sdir, true); sort($skins); $result = array(); foreach ($skins as $v) { if (is_dir(DIR_ROOT . '/' . $sdir . '/' . $v) && $v != 'base') { $arr = @parse_ini_file(DIR_ROOT . '/' . $sdir . '/' . $v . '/' . SKIN_MANIFEST); if ((empty($area) || !empty($arr[$area])) && !empty($arr)) { $result[$v] = $arr; } } } return $result; }
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; }
/** * Returns list of available languages * * @return array List of available languages */ public function getAvailableLangs() { $lang_files = fn_get_dir_contents(Registry::get('config.dir.install') . 'langs/translations', false, true, '.json'); $languages = array(); foreach ($lang_files as $lang_file) { $lang_code = str_replace('.json', '', $lang_file); $languages[$lang_code] = $this->getLanguageVariable($lang_code); } return $languages; }
/** * Installs theme * * @param int $layout_id layout ID to create logo for * @param string $theme_name theme name * @param int $company_id company ID * @return boolean always true */ function fn_install_theme($theme_name, $company_id = null, $install_layouts = true) { // Copy files fn_install_theme_files($theme_name, $theme_name, true); Settings::instance()->updateValue('theme_name', $theme_name, '', true, $company_id); $repo_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C', $company_id, false); $logo_ids = array(); // Import theme layout $layouts = fn_get_dir_contents($repo_dest . '/layouts/', false, true, '.xml'); // FIXME: Backward compability for layouts if (empty($layouts) && file_exists($repo_dest . '/layouts.xml')) { $layouts = array('../layouts.xml'); } if (!empty($layouts) && $install_layouts) { foreach ($layouts as $layout_name) { $layout_path = fn_normalize_path($repo_dest . '/layouts/' . $layout_name); if (file_exists($layout_path)) { $layout_id = Exim::instance($company_id, 0, $theme_name)->importFromFile($layout_path, array('override_by_dispatch' => true, 'clean_up' => true, 'import_style' => 'create')); if (empty($layout_id)) { continue; } $layout_data = Layout::instance()->get($layout_id); $_o_ids = fn_create_theme_logos_by_layout_id($theme_name, $layout_id, $company_id, false, $layout_data['style_id']); $logo_ids = array_merge($logo_ids, $_o_ids); } } } else { $params = array('theme_name' => $theme_name); $exists = Layout::instance($company_id)->getList($params); if (empty($exists)) { $layout_id = Layout::instance($company_id)->update(array('name' => __('main'), 'theme_name' => $theme_name, 'is_default' => 1)); $layout_data = Layout::instance()->get($layout_id); $logo_ids = fn_create_theme_logos_by_layout_id($theme_name, $layout_id, $company_id, false, $layout_data['style_id']); } } return $logo_ids; }
/** * Get list of templates that should be overridden by addons * * @param string $resource_name Base template name * @param Smarty $view Templater object * * @return string Overridden template name */ function fn_addon_template_overrides($resource_name, &$view) { static $init = array(); $o_name = 'template_overrides_' . AREA; $template_dir = rtrim($view->getTemplateDir(0), '/') . '/'; if (!isset($init[$o_name])) { Registry::registerCache($o_name, array('addons'), Registry::cacheLevel('static')); if (!Registry::isExist($o_name)) { $template_overrides = array(); foreach (Registry::get('addons') as $a => $_settings) { $odir = $template_dir . 'addons/' . $a . '/overrides'; if ($_settings['status'] == 'A' && is_dir($odir)) { $tpls = fn_get_dir_contents($odir, false, true, '', '', true); foreach ($tpls as $k => $t) { $tpl_hash = md5($t); if (empty($template_overrides[$tpl_hash])) { $template_overrides[$tpl_hash] = $template_dir . 'addons/' . $a . '/overrides/' . $t; } } } } if (empty($template_overrides)) { $template_overrides['plug'] = true; } Registry::set($o_name, $template_overrides); } $init[$o_name] = true; } return Registry::ifGet($o_name . '.' . md5($resource_name), $resource_name); }
/** * Gets all available patterns for the section * * @param string $section section to get patterns for * @param string $get_for get import or export patterns * @return array */ function fn_get_patterns($section, $get_for) { // Get core patterns $files = fn_get_dir_contents(Registry::get('config.dir.schemas') . 'exim', false, true, '.php'); foreach (Registry::get('addons') as $addon_name => $addon_data) { if ($addon_data['status'] != 'A') { continue; } $schema_dir = Registry::get('config.dir.addons') . $addon_name . '/schemas/exim'; if (is_dir($schema_dir)) { $_files = fn_get_dir_contents($schema_dir, false, true, '.php'); foreach ($_files as $key => $filename) { if (strpos($filename, '.post.php') !== false) { unset($_files[$key]); } } if (!empty($_files)) { $files = fn_array_merge($files, $_files, false); } } } $patterns = array(); $sections = array(); foreach ($files as $schema_file) { if (strpos($schema_file, '.functions.') !== false) { // skip functions schema definition continue; } $pattern_id = str_replace('.php', '', $schema_file); $pattern = fn_get_pattern_definition($pattern_id, $get_for); if (empty($pattern) || !fn_check_pattern_permissions($pattern, $get_for, $_SESSION['auth']['user_id'])) { continue; } $sections[$pattern['section']] = array('title' => __($pattern['section']), 'href' => 'exim.' . Registry::get('runtime.mode') . '?section=' . $pattern['section']); if ($pattern['section'] == $section) { $patterns[$pattern_id] = $pattern; } } if (Registry::get('runtime.company_id')) { $schema = fn_get_permissions_schema('vendor'); // Check if the selected section is available if (isset($schema[$get_for]['sections'][$section]['permission']) && !$schema[$get_for]['sections'][$section]['permission']) { return array('', ''); } if (!empty($schema[$get_for]['sections'])) { foreach ($schema[$get_for]['sections'] as $section_id => $data) { if (isset($data['permission']) && !$data['permission']) { unset($sections[$section_id]); } } } if (!empty($schema[$get_for]['patterns'])) { foreach ($schema[$get_for]['patterns'] as $pattern_id => $data) { if (isset($data['permission']) && !$data['permission']) { unset($patterns[$pattern_id]); } } } } ksort($sections, SORT_STRING); uasort($patterns, 'fn_sort_patterns'); return array($sections, $patterns); }