Esempio n. 1
0
function fn_get_image($image_id, $object_type, $rev_data = array(), $lang_code = CART_LANGUAGE)
{
    $table = 'images';
    $cond = '';
    $path = $object_type;
    if (!empty($rev_data)) {
        $table = 'rev_images';
        $cond = db_quote(" AND ?:{$table}.revision = ?s AND ?:{$table}.revision_id = ?i", $rev_data['revision'], $rev_data['revision_id']);
        $path .= '_rev';
    }
    $path .= "/" . floor($image_id / MAX_FILES_IN_DIR);
    if (!empty($image_id) && !empty($object_type)) {
        $image_data = db_get_row("SELECT ?:{$table}.image_path, ?:common_descriptions.description as alt, ?:{$table}.image_x, ?:{$table}.image_y FROM ?:{$table} LEFT JOIN ?:common_descriptions ON ?:common_descriptions.object_id = ?:{$table}.image_id AND ?:common_descriptions.object_holder = 'images' AND ?:common_descriptions.lang_code = ?s  WHERE ?:{$table}.image_id = ?i ?p", $lang_code, $image_id, $cond);
        if (!empty($image_data['image_path'])) {
            if (fn_get_file_ext($image_data['image_path']) == 'swf') {
                // FIXME, dirty
                $image_data['is_flash'] = true;
            }
            $image_data['http_image_path'] = Registry::get('config.http_images_path') . $path . '/' . $image_data['image_path'];
            $image_data['absolute_path'] = DIR_IMAGES . $path . '/' . $image_data['image_path'];
            $image_data['image_path'] = Registry::get('config.images_path') . $path . '/' . $image_data['image_path'];
        }
    }
    return !empty($image_data) ? $image_data : false;
}
Esempio n. 2
0
 /**
  * Saves uploaded pattern to theme
  * @param  string $style_id     style ID
  * @param  array  $style        style
  * @param  array  $uploaded_data uploaded data
  * @return array  modified style
  */
 public static function save($style_id, $style, $uploaded_data)
 {
     $style_id = fn_basename($style_id);
     $patterns = self::getPath($style_id);
     if (!is_dir($patterns)) {
         fn_mkdir($patterns);
     }
     foreach ($uploaded_data as $var => $file) {
         $fname = $var . '.' . fn_get_file_ext($file['name']);
         if (fn_copy($file['path'], $patterns . '/' . $fname)) {
             $style['data'][$var] = "url('" . self::getRelPath($style_id) . '/' . $fname . '?' . TIME . "')";
         }
     }
     return $style;
 }
Esempio n. 3
0
/**
 * Hook: generates low-resolution image from HiDPI one
 * @param array &$image_data
 * @param int &$image_id
 * @param string &$image_type
 * @param string &$images_path
 * @param array &$_data
 */
function fn_hidpi_update_image(&$image_data, &$image_id, &$image_type, &$images_path, &$_data)
{
    // Save original image
    $filename = fn_hdpi_form_name($image_data['name']);
    Storage::instance('images')->put($images_path . $filename, array('file' => $image_data['path'], 'keep_origins' => true));
    $ext = fn_get_file_ext($filename);
    // We should not process ICO files
    if ($ext == 'ico') {
        return false;
    }
    // Resize original image to non-hidpi resolution
    $_data['image_x'] = intval($_data['image_x'] / 2);
    $_data['image_y'] = intval($_data['image_y'] / 2);
    fn_put_contents($image_data['path'], fn_resize_image($image_data['path'], $_data['image_x'], $_data['image_y'], Registry::get('settings.Thumbnails.thumbnail_background_color')));
}
Esempio n. 4
0
/**
 * Filters path/files to exclude from list
 * @param string $path path to check
 * @return boolean true to exclude, false - otherwise
 */
function fn_te_filter_path($path)
{
    $filter = array();
    $fileext_filter = Registry::get('config.forbidden_file_extensions');
    $filename = basename($path);
    fn_set_hook('te_filter_path', $filter, $path, $fileext_filter);
    if (in_array(fn_get_file_ext($filename), $fileext_filter)) {
        return true;
    }
    if (!empty($filter)) {
        foreach ($filter as $f) {
            if (strpos($path, $f) === 0) {
                return true;
            }
        }
    }
    return false;
}
Esempio n. 5
0
 /**
  * Prefilter: template wrapper for design mode
  * @param  string                    $content  template content
  * @param  \Smarty_Internal_Template $template template instance
  * @return string                    template content
  */
 public static function preTemplateWrapper($content, \Smarty_Internal_Template $template)
 {
     $cur_templ = fn_addon_template_overrides($template->template_resource, $template);
     $ignored_template = array('index.tpl', 'common/pagination.tpl', 'views/categories/components/menu_items.tpl', 'views/block_manager/render/location.tpl', 'views/block_manager/render/container.tpl', 'views/block_manager/render/grid.tpl', 'views/block_manager/render/block.tpl');
     if (!in_array($cur_templ, $ignored_template) && fn_get_file_ext($cur_templ) == 'tpl') {
         // process only "real" templates (not eval'ed, etc.)
         $content = '{if $runtime.customization_mode.design == "Y" && $smarty.const.AREA == "C"}' . '{capture name="template_content"}' . $content . '{/capture}' . '{if $smarty.capture.template_content|trim}' . '{if $auth.area == "A"}' . '<span class="cm-template-box template-box" data-ca-te-template="' . $cur_templ . '" id="{set_id name="' . $cur_templ . '"}">' . '<div class="cm-template-icon icon-edit ty-icon-edit hidden"></div>' . '{$smarty.capture.template_content nofilter}<!--[/tpl_id]--></span>' . '{else}{$smarty.capture.template_content nofilter}{/if}{/if}' . '{else}' . $content . '{/if}';
     }
     return $content;
 }
Esempio n. 6
0
        $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;
    }
}
if ($mode == 'get_content') {
    $ext = fn_strtolower(fn_get_file_ext($_REQUEST['file']));
    if ($ext == 'tpl') {
        $theme_path = fn_get_theme_path('[themes]/[theme]/templates/', 'C');
        Registry::get('ajax')->assign('content', fn_get_contents($_REQUEST['file'], $theme_path));
    }
    exit;
}
Esempio n. 7
0
 /**
  * Converts URL (http://e.com/a.png) to CSS property ( url("../a.png") )
  * @param  string $style_id   style ID
  * @param  array  $style_data style data (fields)
  * @return array  modified style data
  */
 private function urlToCss($style_id, $style_data)
 {
     $patterns_url = Registry::get('config.current_location') . '/' . fn_get_theme_path('[relative]/[theme]');
     if (!empty($this->schema['backgrounds']['fields'])) {
         foreach ($this->schema['backgrounds']['fields'] as $field) {
             if (!empty($field['properties']['pattern'])) {
                 $var_name = $field['properties']['pattern'];
                 if (!empty($style_data[$var_name]) && strpos($style_data[$var_name], '//') !== false) {
                     $url = preg_replace('/url\\([\'"]?(.*?)[\'"]?\\)/', '$1', $style_data[$var_name]);
                     if (strpos($url, '//') === 0) {
                         $url = 'http:' . $url;
                     }
                     if (strpos($url, $patterns_url) !== false) {
                         $url = str_replace($patterns_url, '..', $url);
                     } elseif ($style_id) {
                         // external url
                         $content = fn_get_contents($url);
                         $filename = basename($url);
                         fn_put_contents(Patterns::getPath($style_id) . '/' . $var_name . '.' . fn_get_file_ext($filename), $content);
                         $url = Patterns::getRelPath($style_id) . '/' . $var_name . '.' . fn_get_file_ext($filename);
                     }
                     $style_data[$var_name] = 'url(' . $url . '?' . TIME . ')';
                 }
             }
         }
     }
     return $style_data;
 }
Esempio n. 8
0
/**
 * Checks uploaded file can be processed
 * @param array $uploaded_data uploaded file data
 * @param array $filter_by_ext allowed file extensions
 * @return boolean true if file can be processed, false - otherwise
 */
function fn_check_uploaded_data($uploaded_data, $filter_by_ext)
{
    $result = true;
    $processed = false;
    /**
     * Actions before check uploaded data
     *
     * @param array $uploaded_data Uploaded data
     * @param array $filter_by_ext Allowed file extensions
     * @param bool  $result        Result status
     * @param bool  $processed     Processed flag
     */
    fn_set_hook('check_uploaded_data_pre', $uploaded_data, $filter_by_ext, $result, $processed);
    if ($processed) {
        return $result;
    }
    if (!empty($uploaded_data) && is_array($uploaded_data) && !empty($uploaded_data['name'])) {
        $ext = fn_get_file_ext($uploaded_data['name']);
        if (empty($ext)) {
            $types = fn_get_ext_mime_types('mime');
            $mime = fn_get_mime_content_type($uploaded_data['path']);
            $ext = isset($types[$mime]) ? $types[$mime] : '';
        }
        if (!$processed && !empty($filter_by_ext) && !in_array(fn_strtolower($ext), $filter_by_ext)) {
            fn_set_notification('E', __('error'), __('text_not_allowed_to_upload_file_extension', array('[ext]' => $ext)));
            $result = false;
            $processed = true;
        }
        if (!$processed && in_array(fn_strtolower($ext), Registry::get('config.forbidden_file_extensions'))) {
            fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $ext)));
            $result = false;
            $processed = true;
        }
        $mime_type = fn_get_mime_content_type($uploaded_data['path'], true, 'text/plain');
        if (!$processed && !empty($uploaded_data['path']) && in_array($mime_type, Registry::get('config.forbidden_mime_types'))) {
            fn_set_notification('E', __('error'), __('text_forbidden_file_mime', array('[mime]' => $mime_type)));
            $result = false;
            $processed = true;
        }
    }
    /**
     * Actions after check uploaded data
     *
     * @param array $uploaded_data Uploaded data
     * @param array $filter_by_ext Allowed file extensions
     * @param bool  $result        Result status
     * @param bool  $processed     Processed flag
     */
    fn_set_hook('check_uploaded_data_post', $uploaded_data, $filter_by_ext, $result, $processed);
    return $result;
}
Esempio n. 9
0
/**
 * Filter data from file uploader
 *
 * @param string $name
 * @return array $filtered
 */
function fn_filter_uploaded_data($name, $filter_by_ext = array())
{
    $udata_local = fn_rebuild_files('file_' . $name);
    $udata_other = !empty($_REQUEST['file_' . $name]) ? $_REQUEST['file_' . $name] : array();
    $utype = !empty($_REQUEST['type_' . $name]) ? $_REQUEST['type_' . $name] : array();
    //var_dump($name);echo"<br/>";
    //    if($name=='p_feature_var_extra_image_detailed'){
    //        var_dump($utype);die();
    //    }
    if (empty($utype)) {
        return array();
    }
    $filtered = array();
    foreach ($utype as $id => $type) {
        if ($type == 'local' && !fn_is_empty(@$udata_local[$id])) {
            $filtered[$id] = fn_get_local_data(Bootstrap::stripSlashes($udata_local[$id]));
        } elseif ($type == 'server' && !fn_is_empty(@$udata_other[$id]) && AREA == 'A') {
            fn_get_last_key($udata_other[$id], 'fn_get_server_data', true);
            $filtered[$id] = $udata_other[$id];
        } elseif ($type == 'url' && !fn_is_empty(@$udata_other[$id])) {
            fn_get_last_key($udata_other[$id], 'fn_get_url_data', true);
            $filtered[$id] = $udata_other[$id];
        }
        if (isset($filtered[$id]) && $filtered[$id] === false) {
            unset($filtered[$id]);
            fn_set_notification('E', __('error'), __('cant_upload_file'));
        }
        if (!empty($filtered[$id]) && is_array($filtered[$id]) && !empty($filtered[$id]['name'])) {
            $filtered[$id]['name'] = str_replace(' ', '_', urldecode($filtered[$id]['name']));
            // replace spaces with underscores
            $ext = fn_get_file_ext($filtered[$id]['name']);
            if (!empty($filter_by_ext) && !in_array(fn_strtolower($ext), $filter_by_ext)) {
                unset($filtered[$id]);
                fn_set_notification('E', __('error'), __('text_not_allowed_to_upload_file_extension', array('[ext]' => $ext)));
            } elseif (in_array(fn_strtolower($ext), Registry::get('config.forbidden_file_extensions'))) {
                unset($filtered[$id]);
                fn_set_notification('E', __('error'), __('text_forbidden_file_extension', array('[ext]' => $ext)));
            }
        }
        if (!empty($filtered[$id]['path']) && in_array(fn_get_mime_content_type($filtered[$id]['path'], true, 'text/plain'), Registry::get('config.forbidden_mime_types'))) {
            fn_set_notification('E', __('error'), __('text_forbidden_file_mime', array('[mime]' => fn_get_mime_content_type($filtered[$id]['path'], true, 'text/plain'))));
            unset($filtered[$id]);
        }
    }
    static $shutdown_inited;
    if (!$shutdown_inited) {
        $shutdown_inited = true;
        register_shutdown_function('fn_remove_temp_data');
    }
    return $filtered;
}
Esempio n. 10
0
        $res = @chmod($fname, octdec($_REQUEST['perms']));
    }
    fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var($res ? 'text_permissions_changed' : 'error_permissions_not_changed'));
    Registry::get('ajax')->assign('action_type', $res ? '' : 'error');
    exit;
} elseif ($mode == 'get_file') {
    $file = basename($_REQUEST['file']);
    if (!in_array(fn_get_file_ext($file), Registry::get('config.forbidden_file_extensions'))) {
        $pname = fn_normalize_path(DIR_SKINS . $current_path);
        fn_get_file($pname . $file);
    }
    exit;
} elseif ($mode == 'edit') {
    $file = basename($_REQUEST['file']);
    $fname = fn_normalize_path(DIR_SKINS . $current_path . $file);
    if (!in_array(fn_get_file_ext($fname), Registry::get('config.forbidden_file_extensions'))) {
        if (fn_get_image_size($fname)) {
            $ajax->assign('img', Registry::get('config.http_location') . str_replace(DIR_ROOT, '', $fname));
        } else {
            $ajax->assign('content', fn_get_contents($fname));
        }
    }
    exit;
} elseif ($mode == 'restore') {
    $copied = false;
    $file = basename($_REQUEST['file']);
    $c_name = fn_normalize_path(DIR_SKINS . $current_path . $file);
    $b_path = fn_normalize_path($current_path);
    // First, try to restore object from the base repository
    $arr = explode('/', $b_path);
    $arr[0] = 'base';
Esempio n. 11
0
 /**
  * Copy file using ftp
  *
  * @param string $source source file
  * @param string $dest destination file/directory
  * @return boolean true if copied successfully, false - otherwise
  */
 function fn_uc_ftp_copy($source, $dest)
 {
     $result = false;
     $ftp = Registry::get('ftp_connection');
     if (is_resource($ftp)) {
         if (!is_dir($dest)) {
             // file
             $dest = dirname($dest);
         }
         $dest = rtrim($dest, '/') . '/';
         // force adding trailing slash to path
         $rel_path = str_replace(Registry::get('config.dir.root') . '/', '', $dest);
         $cdir = ftp_pwd($ftp);
         if (empty($rel_path)) {
             // if rel_path is empty, assume it's root directory
             $rel_path = $cdir;
         }
         if (ftp_chdir($ftp, $rel_path) && ftp_put($ftp, fn_basename($source), $source, FTP_BINARY)) {
             @ftp_site($ftp, "CHMOD " . (fn_get_file_ext($source) == 'php' ? '0644' : sprintf('0%o', DEFAULT_FILE_PERMISSIONS)) . " " . fn_basename($source));
             $result = true;
             ftp_chdir($ftp, $cdir);
         }
     }
     if (false === $result) {
         fn_set_notification('E', __('error'), __('text_uc_failed_to_ftp_copy'));
     }
     return $result;
 }
Esempio n. 12
0
function fn_restore_dump($files)
{
    if (empty($files)) {
        return false;
    }
    fn_set_progress('parts', sizeof($files));
    foreach ($files as $file) {
        $is_archive = false;
        $list = array($file);
        if (in_array(fn_get_file_ext($file), array('zip', 'tgz'))) {
            $is_archive = true;
            fn_decompress_files(Registry::get('config.dir.database') . $file, Registry::get('config.dir.database') . '_tmp');
            $list = fn_get_dir_contents(Registry::get('config.dir.database') . '_tmp', false, true, 'sql', '_tmp/');
        }
        foreach ($list as $_file) {
            db_import_sql_file(Registry::get('config.dir.database') . $_file);
        }
        if ($is_archive) {
            fn_rm(Registry::get('config.dir.database') . '_tmp');
        }
    }
    // Log database restore
    fn_log_event('database', 'restore');
    fn_set_hook('database_restore', $files);
    fn_clear_cache();
    return true;
}
Esempio n. 13
0
            $ajax->assign('file_list', $view->display('common_templates/file_browser_dirs.tpl', false));
        }
    } else {
        $view->assign('file_list', fn_get_dir(empty($_SESSION['file_browser_dir']) ? '' : $_SESSION['file_browser_dir'], '', $_REQUEST['view_type']));
        $view->assign('current_dir', htmlentities($_SESSION['file_browser_dir']));
        if ($_REQUEST['view_mode'] == 'list_view') {
            $ajax->assign('file_list', $view->display('common_templates/file_browser_dirs.tpl', false));
        } else {
            if ($_REQUEST['view_mode'] == 'thumbs_view') {
                $ajax->assign('file_list', $view->display('common_templates/file_browser_thumbnails.tpl', false));
            }
        }
    }
} elseif ($mode == 'get_content') {
    $file = $_REQUEST['file'];
    $ext = strtolower(fn_get_file_ext($file));
    if (array_search($ext, $text_files_ext) !== false) {
        $ajax->assign('content', 'text:' . fn_get_contents($file, DIR_ROOT . '/'));
    } elseif (array_search($ext, $image_files_ext) !== false) {
        $ajax->assign('content', 'image:' . $file);
    } else {
        $ajax->assign('content', '');
    }
} elseif ($mode == 'standalone') {
    $view->display('common_templates/file_browser_standalone.tpl');
} elseif ($mode == 'file_upload') {
    $uploaded_data = fn_filter_uploaded_data('upload_file');
    $error = "";
    if (!empty($uploaded_data)) {
        foreach ($uploaded_data as $k => $v) {
            if (!empty($v['error'])) {
Esempio n. 14
0
function fn_decompress_files($archive_name, $dirname = '')
{
    if (empty($dirname)) {
        $dirname = Registry::get('config.dir.files');
    }
    $ext = fn_get_file_ext($archive_name);
    try {
        // We cannot use PharData for ZIP archives. All extracted data looks broken after extract.
        if ($ext == 'zip') {
            $zip = new \ZipArchive();
            $zip->open($archive_name);
            $zip->extractTo($dirname);
            $zip->close();
        } elseif ($ext == 'tgz' || $ext == 'gz') {
            if (!class_exists('PharData')) {
                fn_set_notification('E', __('error'), __('error_class_phar_data_not_found'));
                return false;
            }
            $phar = new \PharData($archive_name);
            $phar->extractTo($dirname, null, true);
            // extract all files, and overwrite
        }
    } catch (Exception $e) {
        fn_set_notification('E', __('error'), __('unable_to_unpack_file'));
        return false;
    }
    return true;
}
Esempio n. 15
0
 public static function sendMail($params, $area = AREA, $lang_code = CART_LANGUAGE)
 {
     if (empty($params['to']) || empty($params['from']) || empty($params['tpl']) && empty($params['body'])) {
         return false;
     }
     fn_disable_live_editor_mode();
     $from = array('email' => '', 'name' => '');
     $to = array();
     $reply_to = array();
     $cc = array();
     $mailer = self::instance(!empty($params['mailer_settings']) ? $params['mailer_settings'] : array());
     fn_set_hook('send_mail_pre', $mailer, $params, $area, $lang_code);
     $mailer->ClearReplyTos();
     $mailer->ClearCCs();
     $mailer->ClearAttachments();
     $mailer->Sender = '';
     $params['company_id'] = !empty($params['company_id']) ? $params['company_id'] : 0;
     $company_data = fn_get_company_placement_info($params['company_id'], $lang_code);
     foreach (array('reply_to', 'to', 'cc') as $way) {
         if (!empty($params[$way])) {
             if (!is_array($params[$way])) {
                 ${$way}[] = !empty($company_data[$params[$way]]) ? $company_data[$params[$way]] : $params[$way];
             } else {
                 foreach ($params[$way] as $way_ar) {
                     ${$way}[] = !empty($company_data[$way_ar]) ? $company_data[$way_ar] : $way_ar;
                 }
             }
         }
     }
     if (!empty($reply_to)) {
         $reply_to = $mailer->formatEmails($reply_to);
         foreach ($reply_to as $rep_to) {
             $mailer->AddReplyTo($rep_to);
         }
     }
     if (!empty($cc)) {
         $cc = $mailer->formatEmails($cc);
         foreach ($cc as $c) {
             $mailer->AddCC($c);
         }
     }
     if (!is_array($params['from'])) {
         if (!empty($company_data[$params['from']])) {
             $from['email'] = $company_data[$params['from']];
             $from['name'] = strstr($params['from'], 'default_') ? $company_data['default_company_name'] : $company_data['company_name'];
         } elseif (self::ValidateAddress($params['from'])) {
             $from['email'] = $params['from'];
         }
     } else {
         if (!empty($params['from']['email'])) {
             if (!empty($company_data[$params['from']['email']])) {
                 $from['email'] = $company_data[$params['from']['email']];
                 if (empty($params['from']['name'])) {
                     $params['from']['name'] = strstr($params['from']['email'], 'default_') ? $company_data['default_company_name'] : $company_data['company_name'];
                 }
             } else {
                 $from['email'] = $params['from']['email'];
             }
             $from['name'] = !empty($company_data[$params['from']['name']]) ? $company_data[$params['from']['name']] : $params['from']['name'];
         }
     }
     if (empty($to) || empty($from['email'])) {
         return false;
     }
     $mailer->SetFrom($from['email'], $from['name']);
     $mailer->IsHTML(isset($params['is_html']) ? $params['is_html'] : true);
     $mailer->CharSet = CHARSET;
     // Pass data to template
     foreach ($params['data'] as $k => $v) {
         Registry::get('view')->assign($k, $v);
     }
     Registry::get('view')->assign('company_data', $company_data);
     $company_id = isset($params['company_id']) ? $params['company_id'] : null;
     if (!empty($params['tpl'])) {
         // Get template name for subject and render it
         $tpl_ext = fn_get_file_ext($params['tpl']);
         $subj_tpl = str_replace('.' . $tpl_ext, '_subj.' . $tpl_ext, $params['tpl']);
         $subject = Registry::get('view')->displayMail($subj_tpl, false, $area, $company_id, $lang_code);
         // Render template for body
         $body = Registry::get('view')->displayMail($params['tpl'], false, $area, $company_id, $lang_code);
     } else {
         $subject = $params['subj'];
         $body = $params['body'];
     }
     $mailer->Body = $mailer->attachImages($body);
     $mailer->Subject = trim($subject);
     if (!empty($params['attachments'])) {
         foreach ($params['attachments'] as $name => $file) {
             $mailer->AddAttachment($file, $name);
         }
     }
     $to = $mailer->formatEmails($to);
     foreach ($to as $v) {
         $mailer->ClearAddresses();
         $mailer->AddAddress($v, '');
         $result = $mailer->Send();
         if (!$result) {
             fn_set_notification('E', __('error'), __('error_message_not_sent') . ' ' . $mailer->ErrorInfo);
         }
         fn_set_hook('send_mail', $mailer);
     }
     return $result;
 }
Esempio n. 16
0
/**
 * 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);
}
Esempio n. 17
0
         }
         if (!$errors) {
             $lc = Languages::update($lang_data, $_REQUEST['lang_id']);
         }
         if ($lc !== false) {
             fn_save_languages_integrity();
         }
     }
     if ($lc == false) {
         fn_delete_notification('changes_saved');
     }
 }
 if ($mode == 'install_from_po') {
     $uploaded_data = fn_filter_uploaded_data('language_data', array('po', 'zip'));
     if (!empty($uploaded_data['po_file']['path'])) {
         $ext = fn_get_file_ext($uploaded_data['po_file']['name']);
         if ($ext == 'po') {
             $result = Languages::installLanguagePack($uploaded_data['po_file']['path']);
         } else {
             $result = Languages::installZipPack($uploaded_data['po_file']['path']);
         }
         if (!$result) {
             fn_delete_notification('changes_saved');
         }
     }
 }
 if ($mode == 'install' && !empty($_REQUEST['pack'])) {
     $pack_path = Registry::get('config.dir.lang_packs') . fn_basename($_REQUEST['pack']);
     if (Languages::installCrowdinPack($pack_path, array())) {
         return array(CONTROLLER_STATUS_OK, 'languages.manage');
     } else {
Esempio n. 18
0
 $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);
         }
     }
 }
 $supported_archive_types = array('tgz');
 $validators = new Validators();
 if ($validators->isZipArchiveAvailable()) {
     $supported_archive_types[] = 'zip';
 }
 $view->assign('supported_archive_types', $supported_archive_types);
Esempio n. 19
0
/**
 * Copy file using ftp
 *
 * @param string $source source file
 * @param string $dest destination file/directory
 * @return boolean true if copied successfully, false - otherwise
 */
function fn_uc_ftp_copy($source, $dest)
{
    $result = false;
    $ftp = Registry::get('uc_ftp');
    if (is_resource($ftp)) {
        if (!is_dir($dest)) {
            // file
            $dest = dirname($dest);
        }
        $dest = rtrim($dest, '/') . '/';
        // force adding trailing slash to path
        $rel_path = str_replace(DIR_ROOT . '/', '', $dest);
        $cdir = ftp_pwd($ftp);
        if (empty($rel_path)) {
            // if rel_path is empty, assume it's root directory
            $rel_path = $cdir;
        }
        if (ftp_chdir($ftp, $rel_path) && ftp_put($ftp, basename($source), $source, FTP_BINARY)) {
            $ext = fn_get_file_ext($source);
            @ftp_site($ftp, "CHMOD " . (in_array($ext, array('tpl', 'css')) ? DEFAULT_FILE_PERMISSIONS : '0644') . " " . basename($source));
            // set full permissions for templates and css files
            $result = true;
            ftp_chdir($ftp, $cdir);
        }
    }
    return $result;
}