public function uploadWithPreset($name, $preset_name) { $config = cmsConfig::getInstance(); $uploader = new cmsUploader(); $result = $uploader->upload($name, $this->allowed_extensions); if ($result['success']) { if (!$uploader->isImage($result['path'])) { $result['success'] = false; $result['error'] = LANG_UPLOAD_ERR_MIME; } } if (!$result['success']) { $uploader->remove($result['path']); return $result; } $preset = $this->model->getPresetByName($preset_name); if (!$preset) { return array('success' => false, 'error' => ''); } $path = $uploader->resizeImage($result['path'], array('width' => $preset['width'], 'height' => $preset['height'], 'square' => $preset['is_square'])); $image = array('path' => $path, 'url' => $config->upload_host . '/' . $path); if ($preset['is_watermark'] && $preset['wm_image']) { $this->addWatermark($image['path'], $preset['wm_image']['original'], $preset['wm_origin'], $preset['wm_margin']); } $result['image'] = $image; unlink($result['path']); unset($result['path']); return $result; }
public function processUpload($album_id) { $config = cmsConfig::getInstance(); $uploader = new cmsUploader(); $result = $uploader->upload('qqfile'); if (!$result['success']) { cmsTemplate::getInstance()->renderJSON($result); $this->halt(); } $preset = array('width' => 600, 'height' => 460, 'is_square' => false, 'is_watermark' => false); if (!empty($this->options['preset'])) { $preset = cmsCore::getModel('images')->getPresetByName($this->options['preset']); } $result['paths'] = array('big' => $uploader->resizeImage($result['path'], array('width' => $preset['width'], 'height' => $preset['height'], 'square' => $preset['is_square'])), 'normal' => $uploader->resizeImage($result['path'], array('width' => 160, 'height' => 160, 'square' => true)), 'small' => $uploader->resizeImage($result['path'], array('width' => 64, 'height' => 64, 'square' => true)), 'original' => $result['url']); if ($preset['is_watermark'] && !empty($preset['wm_image'])) { $images_controller = cmsCore::getController('images'); $images_controller->addWatermark($result['paths']['big'], $preset['wm_image']['original'], $preset['wm_origin'], $preset['wm_margin']); } $result['filename'] = basename($result['path']); if (empty($this->options['is_origs'])) { @unlink($result['path']); unset($result['paths']['original']); } unset($result['path']); $result['url'] = $config->upload_host . '/' . $result['paths']['small']; $result['id'] = $this->model->addPhoto($album_id, $result['paths']); cmsTemplate::getInstance()->renderJSON($result); $this->halt(); }
public function store($value, $is_submitted, $old_value = null) { $config = cmsConfig::getInstance(); $files_model = cmsCore::getModel('files'); if ($value) { $file = cmsModel::yamlToArray($old_value); $path = $config->upload_path . $file['path']; @unlink($path); $files_model->deleteFile($file['id']); $old_value = null; } $uploader = new cmsUploader(); if (!$uploader->isUploaded($this->name)) { return $old_value; } $allowed_extensions = $this->getOption('extensions'); $max_size_mb = $this->getOption('max_size_mb'); if (!trim($allowed_extensions)) { $allowed_extensions = false; } if (!$max_size_mb) { $max_size_mb = 0; } $result = $uploader->upload($this->name, $allowed_extensions, $max_size_mb * 1048576); if (!$result['success']) { if (!empty($result['path'])) { $uploader->remove($result['path']); } cmsUser::addSessionMessage($result['error'], 'error'); return null; } $file = $files_model->registerFile($result['url'], $result['name']); return array('id' => $file['id'], 'url_key' => $file['url_key'], 'name' => $result['name'], 'size' => $result['size'], 'path' => $result['url']); }
public function run() { // // формируем виджеты главной админки // // Виджет статистики $chart_nav = cmsEventsManager::hookAll('admin_dashboard_chart'); $cookie = cmsUser::getCookie('dashboard_chart'); $defaults = array('controller' => 'users', 'section' => 'reg', 'period' => 7); if ($cookie) { $cookie = json_decode($cookie, true); if (is_array($cookie)) { $defaults = array('controller' => $cookie['c'], 'section' => $cookie['s'], 'period' => $cookie['p']); } } $dashboard_blocks[] = array('title' => LANG_CP_DASHBOARD_STATS, 'class' => 'col3', 'html' => $this->cms_template->getRenderedChild('index_chart', array('chart_nav' => $chart_nav, 'defaults' => $defaults))); $uploader = new cmsUploader(); $extensions = get_loaded_extensions(); $sysinfo = array(LANG_CP_DASHBOARD_SI_PHP => phpversion(), LANG_CP_DASHBOARD_SI_ML => files_format_bytes(files_convert_bytes(@ini_get('memory_limit'))), LANG_CP_DASHBOARD_SI_MAX => $uploader->getMaxUploadSize(), LANG_CP_DASHBOARD_SI_IP => filter_input(INPUT_SERVER, 'SERVER_ADDR'), LANG_CP_DASHBOARD_SI_ROOT => ROOT, LANG_CP_DASHBOARD_SI_SESSION => session_save_path(), LANG_CP_DASHBOARD_SI_ION => in_array('ionCube Loader', $extensions), LANG_CP_DASHBOARD_SI_ZEND => in_array('Zend Optimizer', $extensions), LANG_CP_DASHBOARD_SI_ZENDG => in_array('Zend Guard Loader', $extensions)); $dashboard_blocks[] = array('title' => LANG_CP_DASHBOARD_SYSINFO, 'html' => $this->cms_template->getRenderedChild('index_sysinfo', array('sysinfo' => $sysinfo))); $dashboard_blocks[] = array('title' => LANG_CP_DASHBOARD_RESOURCES, 'html' => $this->cms_template->getRenderedChild('index_resources', array())); $dashboard_blocks = array_merge($dashboard_blocks, cmsEventsManager::hookAll('admin_dashboard_block', false, array())); $_block_id = 0; foreach ($dashboard_blocks as $dashboard_block) { // в одном хуке можно создавать несколько виджетов админки // для этого хук должен вернуть массив виджетов if (!isset($dashboard_block['title'])) { foreach ($dashboard_block as $sub_dashboard_block) { $sub_dashboard_block['id'] = $_block_id; $result_dashboard_blocks[$_block_id] = $sub_dashboard_block; $_block_id++; } } else { $dashboard_block['id'] = $_block_id; $result_dashboard_blocks[$_block_id] = $dashboard_block; } $_block_id++; } // формируем с учетом порядка if (!empty($this->options['dashboard_order'])) { $order_id = 1000; foreach ($result_dashboard_blocks as $block_id => $block) { if (isset($this->options['dashboard_order'][$block_id])) { $order_id = $this->options['dashboard_order'][$block_id]; } else { $order_id += 1; } $_result_dashboard_blocks[$order_id] = $block; } ksort($_result_dashboard_blocks); } else { $_result_dashboard_blocks = $result_dashboard_blocks; } return $this->cms_template->render('index', array('dashboard_blocks' => $_result_dashboard_blocks)); }
public function run() { $chart_nav = cmsEventsManager::hookAll('admin_dashboard_chart'); $uploader = new cmsUploader(); $extensions = get_loaded_extensions(); $sysinfo = array(LANG_CP_DASHBOARD_SI_PHP => phpversion(), LANG_CP_DASHBOARD_SI_ML => files_format_bytes(files_convert_bytes(@ini_get('memory_limit'))), LANG_CP_DASHBOARD_SI_MAX => $uploader->getMaxUploadSize(), LANG_CP_DASHBOARD_SI_IP => filter_input(INPUT_SERVER, 'SERVER_ADDR'), LANG_CP_DASHBOARD_SI_ROOT => ROOT, LANG_CP_DASHBOARD_SI_ION => in_array('ionCube Loader', $extensions), LANG_CP_DASHBOARD_SI_ZEND => in_array('Zend Optimizer', $extensions), LANG_CP_DASHBOARD_SI_ZENDG => in_array('Zend Guard Loader', $extensions)); $cookie = cmsUser::getCookie('dashboard_chart'); $defaults = array('controller' => 'users', 'section' => 'reg', 'period' => 7); if ($cookie) { $cookie = json_decode($cookie, true); if (is_array($cookie)) { $defaults = array('controller' => $cookie['c'], 'section' => $cookie['s'], 'period' => $cookie['p']); } } return cmsTemplate::getInstance()->render('index', array('dashboard_blocks' => cmsEventsManager::hookAll('admin_dashboard_block'), 'chart_nav' => $chart_nav, 'sysinfo' => $sysinfo, 'defaults' => $defaults)); }
private function uploadPackage() { $uploader = new cmsUploader(); if (!$uploader->isUploaded($this->upload_name)) { return false; } files_clear_directory(cmsConfig::get('upload_path') . $this->installer_upload_path); $result = $uploader->uploadForm($this->upload_name, $this->upload_exts, 0, $this->installer_upload_path); if (!$result['success']) { cmsUser::addSessionMessage($result['error'], 'error'); return false; } return $result['name']; }