Ejemplo n.º 1
0
 public function run()
 {
     $form = $this->getForm('ctypes_basic', array('add'));
     $form = cmsEventsManager::hook('ctype_basic_form', $form);
     $is_submitted = $this->request->has('submit');
     $ctype = $form->parse($this->request, $is_submitted);
     if ($is_submitted) {
         $errors = $form->validate($this, $ctype);
         if (!$errors) {
             if (cmsCore::isControllerExists($ctype['name'])) {
                 $errors['name'] = LANG_CP_CTYPE_ERROR_NAME;
             }
         }
         if (!$errors) {
             $content_model = cmsCore::getModel('content');
             $ctype = cmsEventsManager::hook('ctype_before_add', $ctype);
             $ctype = cmsEventsManager::hook("ctype_{$ctype['name']}_before_add", $ctype);
             $ctype_id = $content_model->addContentType($ctype);
             $ctype['id'] = $ctype_id;
             cmsEventsManager::hook('ctype_after_add', $ctype);
             cmsEventsManager::hook("ctype_{$ctype['name']}_after_add", $ctype);
             if ($ctype_id) {
                 cmsCore::getController('content')->addWidgetsPages($ctype);
                 cmsUser::addSessionMessage(sprintf(LANG_CP_CTYPE_CREATED, $ctype['title']), 'success');
             }
             $this->redirectToAction('ctypes', array('labels', $ctype_id), array('wizard_mode' => true));
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $this->cms_template->render('ctypes_basic', array('do' => 'add', 'ctype' => $ctype, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 2
0
 public function run($profile)
 {
     $user = cmsUser::getInstance();
     // проверяем наличие доступа
     if ($profile['id'] != $user->id && !$user->is_admin) {
         cmsCore::error404();
     }
     $template = cmsTemplate::getInstance();
     if (!$template->hasProfileThemesOptions()) {
         cmsCore::error404();
     }
     $form = $template->getProfileOptionsForm();
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     $theme = $profile['theme'];
     if ($is_submitted) {
         // Парсим форму и получаем поля записи
         $theme = array_merge($theme, $form->parse($this->request, $is_submitted, $theme));
         // Проверям правильность заполнения
         $errors = $form->validate($this, $theme);
         if (!$errors) {
             // Обновляем профиль и редиректим на его просмотр
             $this->model->updateUserTheme($profile['id'], $theme);
             $this->redirectTo('users', $profile['id']);
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $template->render('profile_edit_theme', array('id' => $profile['id'], 'profile' => $profile, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 3
0
 public function run($tag_id)
 {
     if (!$tag_id) {
         cmsCore::error404();
     }
     $tags_model = cmsCore::getModel('tags');
     $form = $this->getForm('tag');
     $is_submitted = $this->request->has('submit');
     $tag = $tags_model->getTag($tag_id);
     $original_tag = $tag['tag'];
     if ($is_submitted) {
         $tag = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $tag);
         if ($original_tag == $tag['tag']) {
             $this->redirectToAction();
         }
         if (!$errors) {
             $duplicate_id = $tags_model->getTagId($tag['tag']);
             if (!$duplicate_id) {
                 $tags_model->updateTag($tag_id, $tag);
             }
             if ($duplicate_id) {
                 $tags_model->mergeTags($tag_id, $duplicate_id);
                 cmsUser::addSessionMessage(sprintf(LANG_TAGS_MERGED, $original_tag, $tag['tag']), 'success');
             }
             $this->redirectToAction();
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('backend/tag', array('do' => 'edit', 'tag' => $tag, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 4
0
 public function run($id = false)
 {
     if (!$id) {
         cmsCore::error404();
     }
     $widgets_model = cmsCore::getModel('widgets');
     cmsCore::loadAllControllersLanguages();
     $page = $widgets_model->getPage($id);
     if (!$page) {
         cmsCore::error404();
     }
     $form = $this->getForm('widgets_page');
     if (!$page['is_custom']) {
         $form->removeField('title', 'title');
     }
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         $page = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $page);
         if (!$errors) {
             $widgets_model->updatePage($id, $page);
             $this->redirectToAction('widgets');
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('widgets_page', array('do' => 'edit', 'page' => $page, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 5
0
 public function run($profile)
 {
     // проверяем наличие доступа
     if ($profile['id'] != $this->cms_user->id && !$this->cms_user->is_admin) {
         cmsCore::error404();
     }
     $form = $this->getForm('password');
     $is_submitted = $this->request->has('submit');
     $data = array();
     if ($is_submitted) {
         cmsCore::loadControllerLanguage('auth');
         $data = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $data);
         if (!$errors) {
             $password_hash = md5(md5($data['password']) . $this->cms_user->password_salt);
             if ($password_hash != $this->cms_user->password) {
                 $errors = array('password' => LANG_OLD_PASS_INCORRECT);
             }
         }
         if (!$errors) {
             $profile = array_merge($profile, $data);
             $result = $this->model->updateUser($profile['id'], $profile);
             if ($result['success']) {
                 cmsUser::addSessionMessage(LANG_PASS_CHANGED, 'success');
                 $this->redirectTo('users', $profile['id']);
             } else {
                 $errors = $result['errors'];
             }
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $this->cms_template->render('profile_edit_password', array('id' => $profile['id'], 'profile' => $profile, 'data' => $data, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 6
0
 public function run($template_name)
 {
     $template = new cmsTemplate($template_name);
     if (!$template->hasOptions()) {
         cmsCore::error404();
     }
     $form = $template->getOptionsForm();
     $options = $template->getOptions();
     if ($this->request->has('submit')) {
         // Парсим форму и получаем поля записи
         $options = $form->parse($this->request, true, $options);
         // Проверям правильность заполнения
         $errors = $form->validate($this, $options);
         if (!$errors) {
             if ($template->saveOptions($options)) {
                 cmsUser::addSessionMessage(LANG_CP_SAVE_SUCCESS, 'success');
             } else {
                 cmsUser::addSessionMessage(LANG_CP_SETTINGS_TPL_NOT_WRITABLE, 'error');
             }
             $this->redirectToAction('settings');
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $this->cms_template->render('settings_theme', array('template_name' => $template_name, 'options' => $options, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 7
0
 public function run()
 {
     $user = cmsUser::getInstance();
     $id = $this->request->get('id', 0);
     if (!$id) {
         cmsCore::error404();
     }
     $folder = $this->model->getContentFolder($id);
     if (!$folder) {
         cmsCore::error404();
     }
     if ($folder['user_id'] != $user->id && !$user->is_admin) {
         cmsCore::error404();
     }
     $ctype = $this->model->getContentType($folder['ctype_id']);
     $form = $this->getForm('folder');
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         // Парсим форму и получаем поля записи
         $updated_folder = $form->parse($this->request, $is_submitted);
         // Проверям правильность заполнения
         $errors = $form->validate($this, $updated_folder);
         if (!$errors) {
             // Обновляем папку и редиректим на ее просмотр
             $this->model->updateContentFolder($id, $updated_folder);
             $this->redirect(href_to('users', $folder['user_id'], array('content', $ctype['name'], $folder['id'])));
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('folder_form', array('ctype' => $ctype, 'folder' => $folder, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 8
0
 public function run($feed_id)
 {
     $feed = $this->model->getFeed($feed_id);
     if (!$feed) {
         cmsCore::error404();
     }
     $form = $this->getForm('feed');
     // выясняем контроллер ленты
     $controller = $feed['ctype_name'];
     if ($this->model->isCtypeFeed($feed['ctype_name'])) {
         $controller = 'content';
     }
     list($form, $feed) = cmsEventsManager::hook('rss_' . $controller . '_controller_form', array($form, $feed));
     list($form, $feed) = cmsEventsManager::hook('rss_edit_form', array($form, $feed));
     list($form, $feed) = cmsEventsManager::hook('rss_' . $feed['ctype_name'] . '_edit_form', array($form, $feed));
     if ($this->request->has('submit')) {
         $feed = array_merge($feed, $form->parse($this->request, true));
         $errors = $form->validate($this, $feed);
         if (!$errors) {
             $this->model->updateFeed($feed_id, $feed);
             cmsEventsManager::hook('rss_' . $controller . '_controller_after_update', $feed);
             $this->redirectToAction();
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('backend/edit', array('feed' => $feed, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 9
0
 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));
 }
Ejemplo n.º 10
0
 public function run($controller_name)
 {
     if (!$controller_name) {
         cmsCore::error404();
     }
     $controller_info = $this->model->getControllerInfo($controller_name);
     if (!$controller_info || !$controller_info['is_external']) {
         cmsCore::error404();
     }
     if ($controller_info['is_backend']) {
         $backend_context = $this->request->isAjax() ? cmsRequest::CTX_AJAX : cmsRequest::CTX_INTERNAL;
         $backend_request = new cmsRequest($this->request->getData(), $backend_context);
         $backend_controller = $this->loadControllerBackend($controller_info['name'], $backend_request);
         // смотрим специальный экшен
         if ($backend_controller->isActionExists('delete_component')) {
             $backend_controller->redirectToAction('delete_component');
         }
     }
     // нет бэкэенда или экшена, удаляем через метод модели контроллера
     // если в модели контроллера нет метода deleteController
     // будет использоваться из основной модели
     // который просто удалит запись в cms_controllers
     if (cmsCore::isModelExists($controller_info['name'])) {
         cmsCore::getModel($controller_info['name'])->deleteController($controller_info['id']);
     } else {
         $model = new cmsModel();
         $model->deleteController($controller_info['id']);
     }
     cmsUser::addSessionMessage(sprintf(LANG_CP_COMPONENT_IS_DELETED, $controller_info['title']), 'success');
     $this->redirectToAction('controllers');
 }
Ejemplo n.º 11
0
 public function run($do = false)
 {
     $updater = new cmsUpdater();
     $update = $updater->checkUpdate();
     if ($update == cmsUpdater::UPDATE_NOT_AVAILABLE) {
         cmsUser::addSessionMessage(LANG_CP_UPDATE_NOT_AVAILABLE);
         $this->redirectToAction('update');
     }
     if ($update == cmsUpdater::UPDATE_CHECK_ERROR || empty($update['version'])) {
         cmsUser::addSessionMessage(LANG_CP_UPDATE_CHECK_FAIL, 'error');
         $this->redirectToAction('update');
     }
     if (!function_exists('curl_init')) {
         cmsUser::addSessionMessage(LANG_CP_UPDATE_DOWNLOAD_FAIL, 'error');
         $this->redirectToAction('update');
     }
     $url = $update['url'];
     $package_name = basename($url);
     $destination = cmsConfig::get('upload_path') . 'installer/' . $package_name;
     $result = file_save_from_url($url, $destination);
     if ($result === false) {
         cmsUser::addSessionMessage(LANG_CP_UPDATE_DOWNLOAD_FAIL, 'error');
         $this->redirectToAction('update');
     }
     $this->redirectToAction('install', false, array('package_name' => $package_name));
 }
Ejemplo n.º 12
0
 public function run()
 {
     if (cmsUser::isLogged()) {
         $this->redirectToHome();
     }
     $users_model = cmsCore::getModel('users');
     $form = $this->getForm('restore');
     $data = array();
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         $data = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $data);
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
         if (!$errors) {
             $user = $users_model->getUserByEmail($data['email']);
             if (!$user) {
                 cmsUser::addSessionMessage(LANG_EMAIL_NOT_FOUND, 'error');
             } else {
                 $pass_token = string_random(32, $user['email']);
                 $users_model->updateUserPassToken($user['id'], $pass_token);
                 $messenger = cmsCore::getController('messages');
                 $to = array('email' => $user['email'], 'name' => $user['nickname']);
                 $letter = array('name' => 'reg_restore');
                 $messenger->sendEmail($to, $letter, array('nickname' => $user['nickname'], 'page_url' => href_to_abs('auth', 'reset', $pass_token), 'valid_until' => html_date(date('d.m.Y H:i', time() + 24 * 3600), true)));
                 cmsUser::addSessionMessage(LANG_TOKEN_SENDED, 'success');
             }
         }
     }
     return cmsTemplate::getInstance()->render('restore', array('data' => $data, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 13
0
 public function run($group)
 {
     if ($this->model->getMembership($group['id'], $this->cms_user->id)) {
         $this->redirectToAction($group['id']);
     }
     $invite = $this->model->getInvite($group['id'], $this->cms_user->id);
     if ($group['join_policy'] != groups::JOIN_POLICY_FREE && !$invite) {
         cmsCore::error404();
     }
     $result = cmsEventsManager::hook('group_before_join', array('allow' => true, 'group' => $group, 'invite' => $invite));
     if (!$result['allow']) {
         if (isset($result['access_text'])) {
             cmsUser::addSessionMessage($result['access_text'], 'error');
             if (isset($result['redirect_url'])) {
                 $this->redirect($result['redirect_url']);
             } else {
                 $this->redirectToAction($group['id']);
             }
         }
         cmsCore::error404();
     }
     $group = $result['group'];
     $invite = $result['invite'];
     $this->model->addMembership($group['id'], $this->cms_user->id);
     if ($invite) {
         $this->model->deleteInvite($invite['id']);
     }
     cmsCore::getController('activity')->addEntry($this->name, 'join', array('subject_title' => $group['title'], 'subject_id' => $group['id'], 'subject_url' => href_to_rel($this->name, $group['id']), 'group_id' => $group['id']));
     cmsUser::addSessionMessage(LANG_GROUPS_JOIN_MESSAGE, 'success');
     $this->redirectToAction($group['id']);
 }
Ejemplo n.º 14
0
 public function run()
 {
     $form = $this->getForm('preset', array('add'));
     $preset = array();
     if ($this->request->has('submit')) {
         $preset = $form->parse($this->request, true);
         $errors = $form->validate($this, $preset);
         if (!$errors) {
             if (!$preset['width'] && !$preset['height'] || $preset['is_square'] && (!$preset['width'] || !$preset['height'])) {
                 if (!$preset['width']) {
                     $errors['width'] = ERR_VALIDATE_REQUIRED;
                 }
                 if (!$preset['height']) {
                     $errors['height'] = ERR_VALIDATE_REQUIRED;
                 }
             }
         }
         if (!$errors) {
             $id = $this->model->addPreset($preset);
             // создаем дефолтные миниатюры
             $this->createDefaultImages($preset);
             $this->redirectToAction('presets');
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $this->cms_template->render('backend/preset', array('do' => 'add', 'preset' => $preset, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 15
0
 public function run($feed_id)
 {
     if (!$feed_id) {
         cmsCore::error404();
     }
     $rss_model = cmsCore::getModel('rss');
     $feed = $rss_model->getFeed($feed_id);
     $ctype_id = $feed['ctype_id'];
     $content_model = cmsCore::getModel('content');
     $fields = $content_model->getContentFields($feed['ctype_name']);
     $fields = array('' => '') + array_collection_to_list($fields, 'name', 'title');
     $form = $this->getForm('feed', array($fields));
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         $feed = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $feed);
         if (!$errors) {
             $rss_model->updateFeed($feed_id, $feed);
             $ctype = $content_model->getContentType($ctype_id);
             $ctype['options']['is_rss'] = $feed['is_enabled'];
             $content_model->updateContentType($ctype_id, array('options' => $ctype['options']));
             $this->redirectToAction();
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('backend/edit', array('feed' => $feed, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 16
0
 public function run($group_id = false)
 {
     $users_model = cmsCore::getModel('users');
     $form = $this->getForm('user', array('add'));
     $is_submitted = $this->request->has('submit');
     $user = $form->parse($this->request, $is_submitted);
     if (!$is_submitted) {
         $user['groups'] = array($group_id);
     }
     if ($is_submitted) {
         $errors = $form->validate($this, $user);
         if (mb_strlen($user['password1']) < 6) {
             $errors['password1'] = sprintf(ERR_VALIDATE_MIN_LENGTH, 6);
         }
         if (!$errors) {
             $result = $users_model->addUser($user);
             if ($result['success']) {
                 cmsUser::addSessionMessage(sprintf(LANG_CP_USER_CREATED, $user['nickname']), 'success');
                 $this->redirectToAction('users');
             } else {
                 $errors = $result['errors'];
             }
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('user', array('do' => 'add', 'user' => $user, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 17
0
 public function run($pass_token)
 {
     if (!$pass_token) {
         cmsCore::error404();
     }
     $users_model = cmsCore::getModel('users');
     $profile = $users_model->getUserByPassToken($pass_token);
     if (!$profile) {
         cmsCore::error404();
     }
     $form = $this->getForm('reset');
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         $profile = array_merge($profile, $form->parse($this->request, $is_submitted));
         $errors = $form->validate($this, $profile);
         if (!$errors) {
             $result = $users_model->updateUser($profile['id'], $profile);
             if ($result['success']) {
                 cmsUser::addSessionMessage(LANG_PASS_CHANGED, 'success');
                 $users_model->clearUserPassToken($profile['id']);
                 $this->redirectTo('users', $profile['id']);
             } else {
                 $errors = $result['errors'];
             }
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('reset', array('profile' => $profile, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 18
0
 public function run($country_id = null, $region_id = null)
 {
     if (!$country_id) {
         cmsCore::error404();
     }
     $country = $this->model->getItemById('geo_countries', $country_id);
     if (!$country) {
         cmsCore::error404();
     }
     $region = array('country_id' => $country['id']);
     if ($region_id) {
         $region = $this->model->getItemById('geo_regions', $region_id);
     }
     $form = $this->getForm('region');
     if ($this->request->has('submit')) {
         $region = $form->parse($this->request, true);
         $errors = $form->validate($this, $region);
         if (!$errors) {
             if ($region_id) {
                 $this->model->update('geo_regions', $region_id, $region);
                 cmsUser::addSessionMessage(LANG_GEO_REGION_UPDATED, 'success');
             } else {
                 $this->model->insert('geo_regions', $region);
                 cmsUser::addSessionMessage(LANG_GEO_REGION_ADDED, 'success');
             }
             $this->cms_cache->clean('geo.cities');
             $this->cms_cache->clean('geo.regions');
             $this->redirectToAction('regions', $country_id);
         }
         cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
     }
     $this->setH1(array($country['name'], isset($region['name']) ? $region['name'] : LANG_GEO_ADD_REGION));
     return $this->cms_template->render('backend/region', array('do' => $region_id ? 'edit' : 'add', 'region' => $region, 'country' => $country, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 19
0
 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']);
 }
Ejemplo n.º 20
0
 public function run()
 {
     $form = $this->getForm('options');
     if (!$form) {
         cmsCore::error404();
     }
     $is_submitted = $this->request->has('submit');
     $options = cmsController::loadOptions($this->name);
     $source_controllers = cmsEventsManager::hookAll('sitemap_sources');
     if (is_array($source_controllers)) {
         foreach ($source_controllers as $controller) {
             foreach ($controller['sources'] as $id => $title) {
                 $form->addField('sources', new fieldCheckbox("sources:{$controller['name']}|{$id}", array('title' => $title)));
             }
         }
     }
     if ($is_submitted) {
         $options = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $options);
         if (!$errors) {
             cmsUser::addSessionMessage(LANG_CP_SAVE_SUCCESS, 'success');
             cmsController::saveOptions($this->name, $options);
             $this->redirectToAction('options');
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('backend/options', array('options' => $options, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 21
0
 public function actionOptions()
 {
     if (empty($this->useDefaultOptionsAction)) {
         cmsCore::error404();
     }
     $form = $this->getForm('options');
     if (!$form) {
         cmsCore::error404();
     }
     $is_submitted = $this->request->has('submit');
     $options = cmsController::loadOptions($this->name);
     if ($is_submitted) {
         $options = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $options);
         if (!$errors) {
             cmsUser::addSessionMessage(LANG_CP_SAVE_SUCCESS, 'success');
             cmsController::saveOptions($this->name, $options);
             $this->redirectToAction('options');
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('backend/options', array('options' => $options, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 22
0
 public function run($ctype_id, $dataset_id)
 {
     if (!$ctype_id || !$dataset_id) {
         cmsCore::error404();
     }
     $content_model = cmsCore::getModel('content');
     $ctype = $content_model->getContentType($ctype_id);
     if (!$ctype) {
         cmsCore::error404();
     }
     $form = $this->getForm('ctypes_dataset', array('edit', $ctype['id']));
     $dataset = $old_dataset = $content_model->getContentDataset($dataset_id);
     $fields = $content_model->getContentFields($ctype['name']);
     if ($this->request->has('submit')) {
         $dataset = $form->parse($this->request, true);
         $dataset['filters'] = $this->request->get('filters');
         $dataset['sorting'] = $this->request->get('sorting');
         $errors = $form->validate($this, $dataset);
         if (!$errors) {
             $content_model->updateContentDataset($dataset_id, $dataset, $ctype, $old_dataset);
             $this->redirectToAction('ctypes', array('datasets', $ctype['id']));
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $this->cms_template->render('ctypes_dataset', array('do' => 'edit', 'ctype' => $ctype, 'dataset' => $dataset, 'fields' => $fields, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 23
0
 public function run()
 {
     $new_values = $this->request->get('value', array());
     $group_id = $this->request->get('group_id', 0);
     if (!$new_values || !$group_id) {
         cmsCore::error404();
     }
     $controllers = cmsPermissions::getControllersWithRules();
     $owners = array();
     foreach ($controllers as $controller_name) {
         $controller = cmsCore::getController($controller_name);
         $subjects = $controller->getPermissionsSubjects();
         $rules = cmsPermissions::getRulesList($controller_name);
         $values = array();
         foreach ($subjects as $subject) {
             $values[$subject['name']] = cmsPermissions::getPermissions($subject['name']);
         }
         $owners[$controller_name] = array('subjects' => $subjects, 'rules' => $rules, 'values' => $values);
     }
     foreach ($owners as $controller_name => $controller) {
         foreach ($controller['subjects'] as $subject) {
             $formatted_values = array();
             foreach ($controller['rules'] as $rule) {
                 $value = isset($new_values[$rule['id']][$subject['name']]) ? $new_values[$rule['id']][$subject['name']] : null;
                 $formatted_values[$rule['id']][$group_id] = $value;
             }
             cmsPermissions::savePermissions($subject['name'], $formatted_values);
         }
     }
     cmsUser::addSessionMessage(LANG_CP_PERMISSIONS_SUCCESS, 'success');
     $this->redirectBack();
 }
Ejemplo n.º 24
0
 public function run($pass_token)
 {
     if (!$pass_token) {
         cmsCore::error404();
     }
     if (cmsUser::isLogged()) {
         $this->redirectToHome();
     }
     $users_model = cmsCore::getModel('users');
     $user = $users_model->getUserByPassToken($pass_token);
     if (!$user) {
         cmsCore::error404();
     }
     $users_model->unlockUser($user['id']);
     $users_model->clearUserPassToken($user['id']);
     cmsEventsManager::hook('user_registered', $user);
     cmsUser::addSessionMessage($this->options['reg_auto_auth'] ? LANG_REG_SUCCESS_VERIFIED_AND_AUTH : LANG_REG_SUCCESS_VERIFIED, 'success');
     // авторизуем пользователя автоматически
     if ($this->options['reg_auto_auth']) {
         $user = cmsEventsManager::hook('user_login', $user);
         cmsUser::sessionSet('user', array('id' => $user['id'], 'groups' => $user['groups'], 'time_zone' => $user['time_zone'], 'perms' => cmsUser::getPermissions($user['groups']), 'is_admin' => $user['is_admin']));
         $update_data = array('ip' => cmsUser::getIp());
         $this->model->update('{users}', $user['id'], $update_data, true);
         cmsEventsManager::hook('auth_login', $user['id']);
     }
     $this->redirect($this->getAuthRedirectUrl($this->options['first_auth_redirect']));
 }
Ejemplo n.º 25
0
 public function run($profile)
 {
     // проверяем наличие доступа
     if ($profile['id'] != $this->cms_user->id) {
         cmsCore::error404();
     }
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     if (!$is_submitted && !$profile['invites_count']) {
         cmsCore::error404();
     }
     $form = new cmsForm();
     $fieldset_id = $form->addFieldset();
     if ($profile['invites_count'] > 1) {
         $form->addField($fieldset_id, new fieldText('emails', array('title' => LANG_USERS_INVITES_EMAILS, 'hint' => LANG_USERS_INVITES_EMAILS_HINT, 'rules' => array(array('required')))));
     }
     if ($profile['invites_count'] == 1) {
         $form->addField($fieldset_id, new fieldString('emails', array('title' => LANG_USERS_INVITES_EMAIL, 'rules' => array(array('required'), array('email')))));
     }
     $input = array();
     if ($is_submitted) {
         // Парсим форму и получаем поля записи
         $input = $form->parse($this->request, $is_submitted);
         // Проверям правильность заполнения
         $errors = $form->validate($this, $input);
         if (!$errors) {
             $results = $this->sendInvites($profile, $input['emails']);
             return $this->cms_template->render('profile_invites_results', array('id' => $profile['id'], 'profile' => $profile, 'results' => $results));
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $this->cms_template->render('profile_invites', array('id' => $profile['id'], 'profile' => $profile, 'form' => $form, 'input' => $input, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 26
0
 public function run($group)
 {
     if (!cmsUser::isAllowed('groups', 'delete')) {
         cmsCore::error404();
     }
     if (!cmsUser::isAllowed('groups', 'delete', 'all') && $group['owner_id'] != $this->cms_user->id) {
         cmsCore::error404();
     }
     if ($this->request->has('submit')) {
         // подтвержение получено
         $csrf_token = $this->request->get('csrf_token', '');
         $is_delete_content = $this->request->get('is_delete_content', 0);
         if (!cmsForm::validateCSRFToken($csrf_token)) {
             cmsCore::error404();
         }
         list($group, $is_delete_content) = cmsEventsManager::hook('group_before_delete', array($group, $is_delete_content));
         $this->model->removeContentFromGroup($group['id'], $is_delete_content);
         $this->model->deleteGroup($group);
         cmsUser::addSessionMessage(sprintf(LANG_GROUPS_DELETED, $group['title']));
         $this->redirectToAction('');
     } else {
         // спрашиваем подтверждение
         return $this->cms_template->render('group_delete', array('user' => $this->cms_user, 'group' => $group));
     }
 }
Ejemplo n.º 27
0
 public function run($ctype_id)
 {
     if (!$ctype_id) {
         cmsCore::error404();
     }
     $content_model = cmsCore::getModel('content');
     $ctype = $content_model->getContentType($ctype_id);
     if (!$ctype) {
         cmsCore::error404();
     }
     $form = $this->getForm('ctypes_dataset', array('add', $ctype['id']));
     $is_submitted = $this->request->has('submit');
     $fields = $content_model->getContentFields($ctype['name']);
     $dataset = array('sorting' => array(array('by' => 'date_pub', 'to' => 'desc')));
     if ($is_submitted) {
         $dataset = $form->parse($this->request, $is_submitted);
         $dataset['filters'] = $this->request->get('filters');
         $dataset['sorting'] = $this->request->get('sorting');
         $errors = $form->validate($this, $dataset);
         if (!$errors) {
             $dataset_id = $content_model->addContentDataset($dataset, $ctype);
             if ($dataset_id) {
                 cmsUser::addSessionMessage(sprintf(LANG_CP_DATASET_CREATED, $dataset['title']), 'success');
             }
             $this->redirectToAction('ctypes', array('datasets', $ctype['id']));
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('ctypes_dataset', array('do' => 'add', 'ctype' => $ctype, 'dataset' => $dataset, 'fields' => $fields, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 28
0
 public function run($template_name)
 {
     $template = new cmsTemplate($template_name);
     if (!$template->hasOptions()) {
         cmsCore::error404();
     }
     $form = $template->getOptionsForm();
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     $options = $template->getOptions();
     if ($is_submitted) {
         // Парсим форму и получаем поля записи
         $options = $form->parse($this->request, $is_submitted, $options);
         // Проверям правильность заполнения
         $errors = $form->validate($this, $options);
         if (!$errors) {
             $template->saveOptions($options);
             $this->redirectBack('settings');
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('settings_theme', array('template_name' => $template_name, 'options' => $options, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 29
0
 public function run($id)
 {
     if (!$id) {
         cmsCore::error404();
     }
     $form = $this->getForm('preset', array('edit'));
     $is_submitted = $this->request->has('submit');
     $preset = $original_preset = $this->model->getPreset($id);
     if ($preset['is_internal']) {
         $form->removeFieldset('basic');
     }
     if ($is_submitted) {
         $preset = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $preset);
         if (!$errors) {
             $this->model->updatePreset($id, $preset);
             $this->createDefaultImages(array_merge($original_preset, $preset));
             $this->redirectToAction('presets');
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('backend/preset', array('do' => 'edit', 'preset' => $preset, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Ejemplo n.º 30
0
 public function run($invited_id)
 {
     $user = cmsUser::getInstance();
     // Группы, в которые можно приглашать
     $my_groups = $this->model->getInvitableGroups($user->id);
     // Членства приглашаемого в группах
     $his_groups = $this->model->getUserMemberships($invited_id);
     // Убираем из списка группы, в которых уже состоит приглашаемый
     if (is_array($my_groups) && is_array($his_groups)) {
         foreach ($his_groups as $membership) {
             if (isset($my_groups[$membership['group_id']])) {
                 unset($my_groups[$membership['group_id']]);
             }
         }
     }
     $is_submitted = $this->request->has('submit');
     if ($is_submitted && $my_groups) {
         $group_id = $this->request->get('group_id');
         if (!isset($my_groups[$group_id])) {
             cmsCore::error404();
         }
         if ($this->model->getInvite($group_id, $invited_id)) {
             cmsUser::addSessionMessage(LANG_GROUPS_INVITE_PENDING, 'info');
             $this->redirectBack();
         }
         return $this->sendInvite($invited_id, $group_id);
     }
     return cmsTemplate::getInstance()->render('invite', array('invited_id' => $invited_id, 'groups' => $my_groups));
 }