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']) { if (!empty($result['path'])) { $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'], 'quality' => $preset['is_watermark'] && $preset['wm_image'] ? 100 : $preset['quality'])); $image = array('path' => $path, 'url' => $config->upload_host . '/' . $path); if ($preset['is_watermark'] && $preset['wm_image']) { img_add_watermark($image['path'], $preset['wm_image']['original'], $preset['wm_origin'], $preset['wm_margin'], $preset['quality']); } $result['image'] = $image; @unlink($result['path']); unset($result['path']); return $result; }
public function run() { $template = cmsTemplate::getInstance(); $config = cmsConfig::getInstance(); $user = cmsUser::getInstance(); $contact_id = $this->request->get('contact_id') or cmsCore::error404(); $content = $this->request->get('content') or cmsCore::error404(); $csrf_token = $this->request->get('csrf_token'); // Проверяем валидность $is_valid = is_numeric($contact_id) && cmsForm::validateCSRFToken($csrf_token, false); if (!$is_valid) { $result = array('error' => true, 'message' => ''); $template->renderJSON($result); } $contact = $this->model->getContact($user->id, $contact_id); // Контакт существует? if (!$contact) { $result = array('error' => true, 'message' => ''); $template->renderJSON($result); } // Контакт не в игноре у отправителя? if ($contact['is_ignored']) { $result = array('error' => true, 'message' => LANG_PM_CONTACT_IS_IGNORED); $template->renderJSON($result); } // Отправитель не в игноре у контакта? if ($this->model->isContactIgnored($contact_id, $user->id)) { $result = array('error' => true, 'message' => LANG_PM_YOU_ARE_IGNORED); $template->renderJSON($result); } // Контакт принимает сообщения от этого пользователя? if (!$user->isPrivacyAllowed($contact, 'messages_pm')) { $result = array('error' => true, 'message' => LANG_PM_CONTACT_IS_PRIVATE); $template->renderJSON($result); } // // Отправляем сообщение // $content_html = cmsEventsManager::hook('html_filter', $content); if (!$content_html) { $template->renderJSON(array('error' => false, 'date' => false, 'message' => false)); } $this->setSender($user->id); $this->addRecipient($contact_id); $message_id = $this->sendMessage($content_html); // // Отправляем уведомление на почту // $user_to = cmsCore::getModel('users')->getUser($contact_id); if (!$user_to['is_online']) { $this->sendNoticeEmail('messages_new'); } // // Получаем и рендерим добавленное сообщение // $message = $this->model->getMessage($message_id); $message_html = $template->render('message', array('messages' => array($message), 'user' => $user), new cmsRequest(array(), cmsRequest::CTX_INTERNAL)); // Результат $template->renderJSON(array('error' => false, 'date' => date($config->date_format, time()), 'message' => $message_html)); }
public function start() { $config = cmsConfig::getInstance(); $this->memcache = new Memcache(); $this->memcache->connect($config->cache_host, $config->cache_port) or die('Memcache connect error'); return true; }
public function getInput($value) { if ($value) { if (is_array($value)) { if (!empty($value['date'])) { $value = sprintf('%s %02d:%02d', $value['date'], $value['hours'], $value['mins']); } } } $this->data['show_time'] = $this->getOption('show_time'); $this->data['date'] = $value ? date(cmsConfig::getInstance()->date_format, strtotime($value)) : ''; if ($this->data['show_time']) { if (!$value) { $this->data['hours'] = 0; $this->data['mins'] = 0; } else { list($this->data['hours'], $this->data['mins']) = explode(':', date('H:i', strtotime($value))); } $this->data['fname_date'] = $this->element_name . '[date]'; $this->data['fname_hours'] = $this->element_name . '[hours]'; $this->data['fname_mins'] = $this->element_name . '[mins]'; } else { $this->data['fname_date'] = $this->element_name; } return parent::getInput($value); }
public function __construct($name = '') { $this->site_config = cmsConfig::getInstance(); if ($name) { $this->setName($name); } else { $device_type = cmsRequest::getDeviceType(); $template = $this->site_config->template; // шаблон в зависимости от девайса if ($device_type !== 'desktop') { $device_template = cmsConfig::get('template_' . $device_type); if ($device_template) { $template = $device_template; } } // шаблон админки, можем определить только тут $controller = cmsCore::getInstance()->uri_controller; if ($controller === 'admin' && $this->site_config->template_admin) { $template = $this->site_config->template_admin; } $this->setName($template); } $this->options = $this->getOptions(); $this->setInheritNames($this->getInheritTemplates()); $this->title = $this->site_config->sitename; $is_no_def_meta = isset($this->site_config->is_no_meta) ? $this->site_config->is_no_meta : false; if (!$is_no_def_meta) { $this->metakeys = $this->site_config->metakeys; $this->metadesc = $this->site_config->metadesc; } }
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 addContentType($ctype) { $id = $this->insert('content_types', $ctype); $config = cmsConfig::getInstance(); // получаем структуру таблиц для хранения контента данного типа $content_table_struct = $this->getContentTableStruct(); $fields_table_struct = $this->getFieldsTableStruct(); $props_table_struct = $this->getPropsTableStruct(); $props_bind_table_struct = $this->getPropsBindTableStruct(); $props_values_table_struct = $this->getPropsValuesTableStruct(); // создаем таблицы $table_name = $this->table_prefix . $ctype['name']; $this->db->createTable($table_name, $content_table_struct); $this->db->createTable("{$table_name}_fields", $fields_table_struct, $config->db_engine); $this->db->createCategoriesTable("{$table_name}_cats"); $this->db->createCategoriesBindsTable("{$table_name}_cats_bind"); $this->db->createTable("{$table_name}_props", $props_table_struct, $config->db_engine); $this->db->createTable("{$table_name}_props_bind", $props_bind_table_struct, $config->db_engine); $this->db->createTable("{$table_name}_props_values", $props_values_table_struct, $config->db_engine); // // добавляем стандартные поля // // заголовок $this->addContentField($ctype['name'], array('name' => 'title', 'title' => LANG_TITLE, 'type' => 'caption', 'ctype_id' => $id, 'is_in_list' => 1, 'is_in_item' => 1, 'is_in_filter' => 1, 'is_fixed' => 1, 'is_fixed_type' => 1, 'is_system' => 0, 'options' => array('label_in_list' => 'none', 'label_in_item' => 'none', 'min_length' => 3, 'max_length' => 100, 'is_required' => true)), true); // дата публикации $this->addContentField($ctype['name'], array('name' => 'date_pub', 'title' => LANG_DATE_PUB, 'type' => 'date', 'ctype_id' => $id, 'is_in_list' => 1, 'is_in_item' => 1, 'is_in_filter' => 1, 'is_fixed' => 1, 'is_fixed_type' => 1, 'is_system' => 1, 'options' => array('label_in_list' => 'none', 'label_in_item' => 'left', 'show_time' => true)), true); // автор $this->addContentField($ctype['name'], array('name' => 'user', 'title' => LANG_AUTHOR, 'type' => 'user', 'ctype_id' => $id, 'is_in_list' => 1, 'is_in_item' => 1, 'is_in_filter' => 0, 'is_fixed' => 1, 'is_fixed_type' => 1, 'is_system' => 1, 'options' => array('label_in_list' => 'none', 'label_in_item' => 'left')), true); // фотография $this->addContentField($ctype['name'], array('name' => 'photo', 'title' => LANG_PHOTO, 'type' => 'image', 'ctype_id' => $id, 'is_in_list' => 1, 'is_in_item' => 1, 'is_fixed' => 1, 'options' => array('size_teaser' => 'small', 'size_full' => 'normal', 'sizes' => array('micro', 'small', 'normal', 'big'))), true); // описание $this->addContentField($ctype['name'], array('name' => 'content', 'title' => LANG_DESCRIPTION, 'type' => 'text', 'ctype_id' => $id, 'is_in_list' => 1, 'is_in_item' => 1, 'is_fixed' => 1, 'options' => array('label_in_list' => 'none', 'label_in_item' => 'none')), true); cmsCache::getInstance()->clean("content.types"); return $id; }
function __construct($request) { parent::__construct($request); $config = cmsConfig::getInstance(); $this->name = str_replace('backend', '', $this->name); $this->root_path = $config->root_path . 'system/controllers/' . $this->name . '/backend/'; }
public function run() { $config = cmsConfig::getInstance(); $path = $config->upload_path . $this->installer_upload_path; $path_relative = $config->upload_root . $this->installer_upload_path; $installer_path = $path . '/' . 'install.php'; $sql_dump_path = $path . '/' . 'install.sql'; $is_imported = $this->importPackageDump($sql_dump_path); $is_installed = $this->runPackageInstaller($installer_path); // считаем, что пришла ошибка if (is_string($is_installed)) { cmsUser::addSessionMessage($is_installed, 'error'); $this->redirectToAction('install'); } $redirect_action = ''; if ($is_imported && $is_installed === true) { $redirect_action = $this->doPackage(); // если в файле install.php есть функция after_install_package, вызываем ее // этот файл, если он есть, уже должен был загружен ранее if (function_exists('after_install_package')) { call_user_func('after_install_package'); } } $is_cleared = files_clear_directory($path); return cmsTemplate::getInstance()->render('install_finish', array('is_cleared' => $is_cleared, 'redirect_action' => $redirect_action, 'path_relative' => $path_relative)); }
public function run($user) { $cfg = cmsConfig::getInstance(); $dest_dir = $cfg->upload_path . "u{$user['id']}"; files_remove_directory($dest_dir); return $user; }
public function parsePackageManifest() { $config = cmsConfig::getInstance(); $path = $config->upload_path . $this->installer_upload_path; $ini_file = $path . '/' . "manifest.{$config->language}.ini"; $ini_file_default = $path . '/' . "manifest.ru.ini"; if (!file_exists($ini_file)) { $ini_file = $ini_file_default; } if (!file_exists($ini_file)) { return false; } $manifest = parse_ini_file($ini_file, true); if (file_exists($config->upload_path . $this->installer_upload_path . '/' . 'package')) { $manifest['contents'] = $this->getPackageContentsList(); } else { $manifest['contents'] = false; } if (isset($manifest['info']['image'])) { $manifest['info']['image'] = $config->upload_host . '/' . $this->installer_upload_path . '/' . $manifest['info']['image']; } if (isset($manifest['install']) || isset($manifest['update'])) { $action = isset($manifest['install']) ? 'install' : 'update'; if (isset($manifest[$action]['type']) && isset($manifest[$action]['name'])) { $manifest['package'] = array('type' => $manifest[$action]['type'], 'type_hint' => constant('LANG_CP_PACKAGE_TYPE_' . strtoupper($manifest[$action]['type']) . '_' . strtoupper($action)), 'action' => $action, 'name' => $manifest[$action]['name'], 'controller' => isset($manifest[$action]['controller']) ? $manifest[$action]['controller'] : null); // проверяем установленную версию $manifest['package']['installed_version'] = call_user_func(array($this, $manifest[$action]['type'] . 'Installed'), $manifest['package']); } } return $manifest; }
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($ctype) { $cfg = cmsConfig::getInstance(); if ($cfg->frontpage == "content:{$ctype['name']}" && !$ctype['options']['list_on']) { $cfg->update('frontpage', 'none'); } return true; }
public function run() { $result = cmsConfig::getInstance()->update('is_site_on', 1); if (!$result) { cmsUser::addSessionMessage(LANG_CP_SETTINGS_NOT_WRITABLE, 'error'); } $this->redirectBack(); }
private function __construct() { $this->site_cfg = cmsConfig::getInstance(); $this->title = $this->homeTitle(); $this->page_keys = $this->site_cfg->keywords; $this->page_desc = $this->site_cfg->metadesc; $this->setTplInfo(); }
public function run($ctype) { $cfg = cmsConfig::getInstance(); if ($cfg->frontpage == "content:{$ctype['name']}") { $cfg->update('frontpage', 'none'); } return $ctype; }
function upgrade_component_usermaps() { $inCore = cmsCore::getInstance(); $inDB = cmsDatabase::getInstance(); $inConf = cmsConfig::getInstance(); include $_SERVER['DOCUMENT_ROOT'] . '/includes/dbimport.inc.php'; dbRunSQL($_SERVER['DOCUMENT_ROOT'] . '/components/usermaps/update.sql', $inConf->db_prefix); return true; }
public function parseRoute($uri) { $config = cmsConfig::getInstance(); $action_name = parent::parseRoute($uri); if (!$action_name && $config->ctype_default) { $action_name = parent::parseRoute($config->ctype_default . '/' . $uri); } return $action_name; }
private function getPackageContentsDir() { $config = cmsConfig::getInstance(); $path = $config->upload_path . $this->installer_upload_path . '/' . 'package'; if (!is_dir($path)) { return false; } return $path; }
/** * Устанавливает соединение с базой * @return resource $db_link */ protected static function initConnection() { $inConf = cmsConfig::getInstance(); $db_link = mysqli_connect($inConf->db_host, $inConf->db_user, $inConf->db_pass, $inConf->db_base); if (mysqli_connect_errno()) { die('Cannot connect to MySQL server: ' . mysqli_connect_error()); } mysqli_set_charset($db_link, 'utf8'); return $db_link; }
public function __construct() { $config = cmsConfig::getInstance(); if ($config->cache_enabled) { $cacher_class = 'cmsCache' . string_to_camel('_', $config->cache_method); $this->cacher = new $cacher_class(); $this->cache_ttl = $config->cache_ttl; $this->is_debug = $config->debug; } }
private function __construct() { $this->site_cfg = cmsConfig::getInstance(); $this->title = $this->homeTitle(); $this->page_keys = $this->site_cfg->keywords; $this->page_desc = $this->site_cfg->metadesc; $this->setTplInfo(); global $_LANG; $this->addPathway($_LANG['PATH_HOME'], '/'); }
public function __construct() { $config = cmsConfig::getInstance(); $this->groups = array(GUEST_GROUP_ID); $this->ip = self::getIp(); self::loadOnlineUsersIds(); if (self::isSessionSet('user:id')) { // уже авторизован $this->id = self::sessionGet('user:id'); } elseif (self::getCookie('auth')) { // пробуем авторизовать по кукису $this->id = self::autoLogin(self::getCookie('auth')); } self::deleteOldSessions($this->id); // // если авторизован, заполняем объект данными из базы // if ($this->id) { $model = cmsCore::getModel('users'); $user = $model->getUser($this->id); if (!$user) { self::logout(); return; } // если дата последнего визита еще не сохранена в сессии, // значит авторизация была только что // сохраним дату в сессии и обновим в базе if (!self::isSessionSet('user:date_log')) { self::sessionSet('user:date_log', $user['date_log']); $model->update('{users}', $this->id, array('date_log' => null), true); } // заполняем объект данными из базы foreach ($user as $field => $value) { $this->{$field} = $value; } // конвертим список аватаров в массив // к пути каждого аватара добавляем путь корня $this->avatar = cmsModel::yamlToArray($this->avatar); if ($this->avatar) { foreach ($this->avatar as $size => $path) { $this->avatar[$size] = $config->upload_host . '/' . $path; } } // кешируем список друзей в сессию $this->recacheFriends(); // создаем online-сессию self::createSession($this->id); // восстанавливаем те поля, которые не должны // изменяться в течении сессии $this->date_log = self::sessionGet('user:date_log'); $this->perms = self::getPermissions($user['groups'], $user['id']); $this->is_logged = true; cmsEventsManager::hook('user_loaded', $user); } }
public function run() { // автоматическое получение опций через $this->options здесь не // работает, потому что форма опций не содержит полей, они заполняются // динамически в админке $options = $this->loadOptions($this->name); if (!$options) { return false; } $sources_list = $options['sources']; if (!$sources_list) { return false; } $config = cmsConfig::getInstance(); if (!is_writable($config->root_path . 'cache/static/sitemaps/')) { return false; } $sources = array(); $sitemaps = array(); foreach ($sources_list as $item => $is_enabled) { if (!$is_enabled) { continue; } list($controller_name, $source) = explode('|', $item); $sources[$controller_name][] = $source; } foreach ($sources as $controller_name => $items) { $urls = array(); $controller = cmsCore::getController($controller_name); foreach ($items as $item) { $urls = $controller->runHook('sitemap_urls', array($item)); if (!$urls) { continue; } if (count($urls) > $this->max_count) { $chunk_data = array_chunk($urls, $this->max_count, true); foreach ($chunk_data as $index => $chunk_urls) { $index = $index ? '_' . $index : ''; $xml = cmsTemplate::getInstance()->renderInternal($this, 'sitemap', array('urls' => $chunk_urls)); $sitemap_file = "sitemap_{$controller_name}_{$item}{$index}.xml"; file_put_contents($config->root_path . "cache/static/sitemaps/{$sitemap_file}", $xml); $sitemaps[] = $sitemap_file; } } else { $xml = cmsTemplate::getInstance()->renderInternal($this, 'sitemap', array('urls' => $urls)); $sitemap_file = "sitemap_{$controller_name}_{$item}.xml"; file_put_contents($config->root_path . "cache/static/sitemaps/{$sitemap_file}", $xml); $sitemaps[] = $sitemap_file; } } } $xml = cmsTemplate::getInstance()->renderInternal($this, 'sitemap_index', array('sitemaps' => $sitemaps, 'host' => $config->host)); file_put_contents(cmsConfig::get('root_path') . 'cache/static/sitemaps/sitemap.xml', $xml); return true; }
function install_component_battleways() { $inCore = cmsCore::getInstance(); //подключаем ядро $inDB = cmsDatabase::getInstance(); //подключаем базу данных $inConf = cmsConfig::getInstance(); include $_SERVER['DOCUMENT_ROOT'] . '/includes/dbimport.inc.php'; dbRunSQL($_SERVER['DOCUMENT_ROOT'] . '/components/battleways/install.sql', $inConf->db_prefix); return true; }
function install_component_blog() { $inCore = cmsCore::getInstance(); //подключаем ядро $inDB = cmsDatabase::getInstance(); //подключаем базу данных $inConf = cmsConfig::getInstance(); $sql = "INSERT INTO `cms_blogs` (`user_id`, `title`, `pubdate`, `allow_who`, `view_type`, `showcats`, `ownertype`, `premod`, `forall`, `owner`, `seolink`, `rating`, `comments_count`) VALUES\n (1, 'Блог', NOW(), 'all', 'list', 1, 'single', 0, 1, 'site', 'blog', 0, 0);"; $inDB->query($sql); return true; }
public function set($key, $value, $ttl = false) { $config = cmsConfig::getInstance(); if (!$config->cache_enabled) { return false; } if (!$ttl) { $ttl = $config->cache_ttl; } return $this->cacher->set($key, $value, $ttl); }
public function run() { // если нужно, передаем управление другому экшену $config = cmsConfig::getInstance(); $values = $config->getAll(); $values['is_site_on'] = 1; $result = $config->save($values); if (!$result) { cmsUser::addSessionMessage(LANG_CP_SETTINGS_NOT_WRITABLE, 'error'); } $this->redirectBack(); }
private function checkErrors() { $config = cmsConfig::getInstance(); $errors = array(); if (!cmsCore::isWritable($config->upload_path . $this->installer_upload_path)) { $errors[] = array('text' => sprintf(LANG_CP_INSTALL_NOT_WRITABLE, $config->upload_root . $this->installer_upload_path), 'hint' => LANG_CP_INSTALL_NOT_WRITABLE_HINT, 'fix' => LANG_CP_INSTALL_NOT_WRITABLE_FIX, 'workaround' => sprintf(LANG_CP_INSTALL_NOT_WRITABLE_WA, $config->upload_root . $this->installer_upload_path)); } if (!class_exists('ZipArchive')) { $errors[] = array('text' => LANG_CP_INSTALL_NOT_ZIP, 'hint' => LANG_CP_INSTALL_NOT_ZIP_HINT, 'fix' => LANG_CP_INSTALL_NOT_ZIP_FIX, 'workaround' => sprintf(LANG_CP_INSTALL_NOT_ZIP_WA, $config->upload_root . $this->installer_upload_path)); } return $errors ? $errors : false; }
public function loadControllerBackend($controller_name, $request) { $config = cmsConfig::getInstance(); $ctrl_file = $config->root_path . 'system/controllers/' . $controller_name . '/backend.php'; if (!file_exists($ctrl_file)) { $this->halt(sprintf(LANG_CP_ERR_BACKEND_NOT_FOUND, $controller_name)); } include_once $ctrl_file; $controller_class = 'backend' . string_to_camel('_', $controller_name); $backend = new $controller_class($request); return $backend; }