Esempio n. 1
1
 public function init()
 {
     $photo = cmsCore::getController('photos');
     return array(array('type' => 'fieldset', 'title' => LANG_OPTIONS, 'childs' => array(new fieldCheckbox('options:auto_user', array('title' => LANG_PHOTOS_O_AUTO_USER, 'hint' => LANG_PHOTOS_O_AUTO_USER_HINT, 'default' => 1)), new fieldCheckbox('options:auto_group', array('title' => LANG_PHOTOS_O_AUTO_GROUP, 'hint' => LANG_PHOTOS_O_AUTO_GROUP_HINT, 'default' => 1)), new fieldCheckbox('options:auto_ctype_item', array('title' => LANG_PHOTOS_O_AUTO_CTYPE_ITEM, 'hint' => LANG_PHOTOS_O_AUTO_CTYPE_ITEM_HINT, 'default' => 1)), new fieldList('options:target', array('title' => LANG_PHOTOS_O_TARGET, 'items' => array(LANG_ALL, LANG_PHOTOS_PUBLIC_ALBUMS, LANG_PHOTOS_USER_ALBUMS), 'default' => 0)), new fieldList('options:album_id', array('title' => LANG_PHOTOS_ALBUM, 'generator' => function () {
         $_items = cmsCore::getModel('content')->limit(false)->disablePrivacyFilter()->getContentItemsForSitemap('albums', array('id', 'title'));
         $items = array('' => '');
         if ($_items) {
             foreach ($_items as $item) {
                 $items[$item['id']] = $item['title'];
             }
         }
         return $items;
     }, 'default' => '')), new fieldList('options:ordering', array('title' => LANG_SORTING, 'items' => array('' => '') + modelPhotos::getOrderList(), 'default' => '')), new fieldList('options:orientation', array('title' => LANG_PHOTOS_O_ORIENTATION, 'items' => modelPhotos::getOrientationList(), 'default' => '')), new fieldList('options:type', array('title' => LANG_PHOTOS_O_TYPE, 'items' => !empty($photo->options['types']) ? array('' => LANG_PHOTOS_ALL) + $photo->options['types'] : array(), 'default' => '')), new fieldNumber('options:width', array('title' => LANG_PHOTOS_SIZE_W . ', ' . mb_strtolower(LANG_PHOTOS_MORE_THAN), 'units' => 'px', 'default' => '')), new fieldNumber('options:height', array('title' => LANG_PHOTOS_SIZE_H . ', ' . mb_strtolower(LANG_PHOTOS_MORE_THAN), 'units' => 'px', 'default' => '')), new fieldNumber('options:limit', array('title' => LANG_LIST_LIMIT, 'default' => 10, 'rules' => array(array('required')))))));
 }
Esempio n. 2
0
 public function getProfileMenu($profile)
 {
     $menu = array(array('title' => LANG_USERS_PROFILE_INDEX, 'url' => href_to($this->name, $profile['id']), 'url_mask' => href_to($this->name, $profile['id'])));
     $this->tabs = $this->model->getUsersProfilesTabs(true, 'name');
     $this->tabs_controllers = array();
     if ($this->tabs) {
         foreach ($this->tabs as $tab) {
             $default_tab_info = array('title' => $tab['title'], 'url' => href_to($this->name, $profile['id'], $tab['name']));
             if (!$this->isControllerEnabled($tab['controller'])) {
                 continue;
             }
             if (empty($this->tabs_controllers[$tab['controller']])) {
                 $controller = cmsCore::getController($tab['controller'], $this->request);
             } else {
                 $controller = $this->tabs_controllers[$tab['controller']];
             }
             $tab_info = $controller->runHook('user_tab_info', array('profile' => $profile, 'tab_name' => $tab['name']));
             if ($tab_info == false) {
                 continue;
             } else {
                 if ($tab_info === true) {
                     $tab_info = $default_tab_info;
                 } else {
                     $tab_info = array_merge($default_tab_info, $tab_info);
                 }
             }
             $menu[] = $tab_info;
             $this->tabs_controllers[$tab['controller']] = $controller;
         }
     }
     return $menu;
 }
Esempio n. 3
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $comment_id = $this->request->get('comment_id', 0);
     $score = $this->request->get('score', '');
     // Проверяем валидность
     $is_valid = is_numeric($comment_id) && in_array($score, array(-1, 1));
     if (!$is_valid) {
         $this->cms_template->renderJSON(array('error' => true));
     }
     $is_can_rate = cmsUser::isAllowed('comments', 'rate');
     if (!$is_can_rate) {
         $this->cms_template->renderJSON(array('error' => true));
     }
     $is_voted = $this->model->isUserVoted($comment_id, $this->cms_user->id);
     if ($is_voted) {
         $this->cms_template->renderJSON(array('error' => true));
     }
     $comment = $this->model->getComment($comment_id);
     if ($comment['user_id'] == $this->cms_user->id) {
         $this->cms_template->renderJSON(array('error' => true));
     }
     $success = $this->model->rateComment($comment_id, $this->cms_user->id, $score);
     if ($success && $comment['user_id'] && !empty($this->options['update_user_rating'])) {
         $rating = $this->model->getItemById('{users}', $comment['user_id']);
         $this->model->update('{users}', $comment['user_id'], array('rating' => $rating['rating'] + $score));
     }
     cmsCore::getController('activity')->addEntry($this->name, 'vote.comment', array('is_private' => (int) $comment['is_private'], 'subject_title' => $comment['target_title'], 'subject_id' => $comment_id, 'subject_url' => $comment['target_url'] . '#comment_' . $comment['id']));
     $this->cms_template->renderJSON(array('error' => !$success));
 }
Esempio n. 4
0
 public function run($ctype_name = false)
 {
     $user = cmsUser::getInstance();
     $template = cmsTemplate::getInstance();
     $counts = $this->model->getTasksCounts($user->id);
     $is_moderator = $this->model->isUserModerator($user->id);
     if (!$is_moderator) {
         cmsCore::error404();
     }
     if (!$counts) {
         return $template->render('empty');
     }
     $is_index = false;
     $ctypes_list = array_keys($counts);
     if (!$ctype_name) {
         $ctype_name = $ctypes_list[0];
         $is_index = true;
     }
     $content_controller = cmsCore::getController('content');
     $ctypes = $content_controller->model->filterIn('name', $ctypes_list)->getContentTypesFiltered();
     $ctypes = array_collection_to_list($ctypes, 'name', 'title');
     $ctype = $content_controller->model->getContentTypeByName($ctype_name);
     $content_controller->model->filterByModeratorTask($user->id, $ctype_name);
     $page_url = $is_index ? href_to($this->name) : href_to($this->name, $ctype_name);
     $content_controller->model->disableApprovedFilter();
     $list_html = $content_controller->renderItemsList($ctype, $page_url, true);
     return $template->render('index', array('is_index' => $is_index, 'counts' => $counts, 'ctype' => $ctype, 'ctypes' => $ctypes, 'ctype_name' => $ctype_name, 'list_html' => $list_html, 'user' => $user));
 }
Esempio n. 5
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));
 }
Esempio n. 6
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']);
 }
Esempio n. 7
0
 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();
 }
Esempio n. 8
0
 public function run($id)
 {
     if (!$id) {
         cmsCore::error404();
     }
     $content_model = cmsCore::getModel('content');
     $ctype = $content_model->getContentType($id);
     $ctype = cmsEventsManager::hook("ctype_before_delete", $ctype);
     $content_model->deleteContentType($id);
     cmsEventsManager::hook("ctype_after_delete", $ctype);
     cmsCore::getModel('widgets')->deletePagesByName('content', "{$ctype['name']}.*");
     $binded_widgets = $content_model->get('widgets_bind', function ($item, $model) {
         $item['options'] = cmsModel::yamlToArray($item['options']);
         return $item;
     });
     if ($binded_widgets) {
         foreach ($binded_widgets as $widget) {
             if (isset($widget['options']['ctype_id']) && $ctype['id'] == $widget['options']['ctype_id']) {
                 $content_model->delete('widgets_bind', $widget['id']);
             }
         }
     }
     cmsCore::getController('activity')->deleteType('content', "add.{$ctype['name']}");
     $this->redirectToAction('ctypes');
 }
Esempio n. 9
0
 public function run($id)
 {
     if (!$id) {
         cmsCore::error404();
     }
     $users_model = cmsCore::getModel('users');
     $group = $users_model->getGroup($id);
     if (!$group) {
         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);
     }
     $template = cmsTemplate::getInstance();
     $template->setMenuItems('users_group', array(array('title' => LANG_CONFIG, 'url' => href_to($this->name, 'users', array('group_edit', $id))), array('title' => LANG_PERMISSIONS, 'url' => href_to($this->name, 'users', array('group_perms', $id)))));
     return $template->render('users_group_perms', array('group' => $group, 'owners' => $owners));
 }
Esempio n. 10
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();
 }
Esempio n. 11
0
 public function run($user)
 {
     // Если пользователь отключил уведомления о новых комментариях
     // через личные сообщения, то выходим
     if (empty($user['notify_options']['comments_new'])) {
         return $user;
     }
     if (!in_array($user['notify_options']['comments_new'], array('pm', 'both'))) {
         return $user;
     }
     // Если новых комментариев на отслеживаемых страницах не появлялось
     // то тоже выходим
     $counts = $this->model->getTrackedNewCounts($user['id'], $user['date_log']);
     if (!$counts) {
         return $user;
     }
     $messenger = cmsCore::getController('messages');
     $messenger->addRecipient($user['id']);
     foreach ($counts as $data) {
         $spellcount = html_spellcount($data['count'], LANG_NEW_COMMENT1, LANG_NEW_COMMENT2, LANG_NEW_COMMENT10);
         $notice = array('content' => sprintf(LANG_COMMENTS_TRACKED_NEW, $data['target_title'], $spellcount), 'actions' => array('view' => array('title' => LANG_SHOW, 'href' => href_to($data['target_url']) . '?new_comments#comments'), 'stop' => array('title' => LANG_COMMENTS_TRACK_STOP, 'controller' => $this->name, 'action' => 'track_stop', 'params' => array($data['target_controller'], $data['target_subject'], $data['target_id']))));
         $messenger->sendNoticePM($notice, 'comments_new');
     }
     return $user;
 }
Esempio 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));
 }
Esempio n. 13
0
 private function sendInvites($profile, $emails_list)
 {
     $results = array('success' => array(), 'failed' => array());
     $emails = string_explode_list($emails_list);
     $auth_controller = cmsCore::getController('auth');
     $auth_model = cmsCore::getModel('auth');
     $messenger = cmsCore::getController('messages');
     foreach ($emails as $email) {
         if ($this->validate_email($email) !== true) {
             $results['failed'][$email] = ERR_VALIDATE_EMAIL;
             continue;
         }
         if ($this->model->getUserByEmail($email)) {
             $results['failed'][$email] = LANG_REG_EMAIL_EXISTS;
             continue;
         }
         if (!$auth_controller->isEmailAllowed($email)) {
             $results['failed'][$email] = LANG_AUTH_RESTRICTED_EMAILS;
             continue;
         }
         $invite = $auth_model->getNextInvite($this->cms_user->id);
         $to = array('email' => $email, 'name' => $email);
         $letter = array('name' => 'users_invite');
         $messenger->sendEmail($to, $letter, array('nickname' => $this->cms_user->nickname, 'code' => $invite['code'], 'page_url' => href_to_abs('auth', 'register') . "?inv={$invite['code']}"));
         $results['success'][$email] = true;
         $auth_model->markInviteSended($invite['id'], $this->cms_user->id, $email);
         if (sizeof($results['success']) + sizeof($results['failed']) >= $profile['invites_count']) {
             break;
         }
     }
     return $results;
 }
Esempio n. 14
0
File: orfo.php Progetto: mafru/icms2
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $orfo = $this->request->get('orfo');
     $url = $this->request->get('url');
     $comment = $this->request->get('comment', false);
     $author = !cmsUser::isLogged() ? cmsUser::getIp() : cmsUser::get('nickname');
     $form = $this->getForm('orfo');
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         $data = $form->parse($this->request, $is_submitted);
         $data['date'] = date('Y-m-d H:i:s');
         $errors = $form->validate($this, $data);
         dump($errors);
         if (!$errors) {
             $this->model->addComplaints($data);
             $messenger = cmsCore::getController('messages');
             $messenger->addRecipient(1);
             $notice = array('content' => sprintf(LANG_COMPLAINTS_ADD_NOTICE, $url, $orfo), 'options' => array('is_closeable' => true));
             $messenger->ignoreNotifyOptions()->sendNoticePM($notice, 'complaints_add');
         }
         cmsTemplate::getInstance()->renderJSON(array('errors' => false, 'callback' => 'formSuccess'));
     }
     $data = array('orfo' => $orfo, 'url' => $url, 'author' => $author, 'comment' => $comment);
     return cmsTemplate::getInstance()->render('orfo', array('form' => $form, 'data' => $data));
 }
Esempio n. 15
0
 public function run($group)
 {
     $activity_controller = cmsCore::getController('activity', $this->request);
     $activity_controller->model->filterEqual('group_id', $group['id']);
     $page_url = href_to($this->name, $group['id'], 'activity');
     $html = $activity_controller->renderActivityList($page_url);
     return cmsTemplate::getInstance()->render('group_activity', array('user' => $this->cms_user, 'group' => $group, 'html' => $html));
 }
Esempio n. 16
0
 public function run()
 {
     $users_options = cmsCore::getController('users')->getOptions();
     if (!$users_options['is_wall']) {
         return false;
     }
     return array('users_wall_write' => array('title' => LANG_WALL_NOTIFY_NEW, 'options' => array('', 'email')));
 }
Esempio n. 17
0
 public function run($group)
 {
     $users_request = new cmsRequest($this->request->getData(), cmsRequest::CTX_INTERNAL);
     $users_controller = cmsCore::getController('users', $users_request);
     $this->model->filterUsersMembers($group['id'], $users_controller->model);
     $page_url = href_to($this->name, $group['id'], 'members');
     $profiles_list_html = $users_controller->renderProfilesList($page_url);
     return cmsTemplate::getInstance()->render('group_members', array('user' => $this->cms_user, 'group' => $group, 'profiles_list_html' => $profiles_list_html));
 }
Esempio n. 18
0
 public function notifyAuthor($ctype_name, $item)
 {
     $users_model = cmsCore::getModel('users');
     $author = $users_model->getUser($item['user_id']);
     $messenger = cmsCore::getController('messages');
     $to = array('email' => $author['email'], 'name' => $author['nickname']);
     $letter = array('name' => 'moderation_refused');
     $messenger->sendEmail($to, $letter, array('nickname' => $author['nickname'], 'page_title' => $item['title'], 'date' => html_date_time()));
 }
Esempio n. 19
0
 public function sendNoticeAccepted($friend)
 {
     $user = cmsUser::getInstance();
     $messenger = cmsCore::getController('messages');
     $messenger->addRecipient($friend['id']);
     $sender_link = '<a href="' . href_to($this->name, $user->id) . '">' . $user->nickname . '</a>';
     $notice = array('content' => sprintf(LANG_USERS_FRIENDS_DONE, $sender_link));
     $messenger->sendNoticePM($notice, 'users_friend_aссept');
 }
Esempio n. 20
0
 private function notifyProfileOwner($profile_id, $entry)
 {
     if ($entry['user_id'] == $profile_id) {
         return;
     }
     $messenger = cmsCore::getController('messages');
     $messenger->addRecipient($profile_id);
     $messenger->sendNoticeEmail('wall_reply', array('profile_url' => href_to_abs('users', $profile_id) . "?wid={$entry['id']}&reply=1", 'author_url' => href_to_abs('users', $entry['user_id']), 'author_nickname' => $entry['user_nickname'], 'content' => $entry['content_html']));
 }
Esempio n. 21
0
 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;
 }
Esempio n. 22
0
 public function run()
 {
     $rules = $this->model->filterEqual('is_active', 1)->getMigrationRules();
     if (!$rules) {
         return;
     }
     foreach ($rules as $rule) {
         extract($rule);
         $this->model->filterGroup($group_from_id);
         $users = $this->model->getUsers();
         if (!$users) {
             continue;
         }
         $passed_field = $passed_from ? 'date_group' : 'date_reg';
         $now_time = time();
         foreach ($users as $user) {
             $is_migrate = true;
             if ($is_passed) {
                 $start_time = strtotime($user[$passed_field]);
                 $days = round(($now_time - $start_time) / 60 / 60 / 24);
                 if ($days < $passed_days) {
                     $is_migrate = false;
                 }
             }
             if ($is_rating) {
                 if ($user['rating'] < $rating) {
                     $is_migrate = false;
                 }
             }
             if ($is_karma) {
                 if ($user['karma'] < $karma) {
                     $is_migrate = false;
                 }
             }
             if (!$is_migrate) {
                 continue;
             }
             if (!$is_keep_group) {
                 if (($key = array_search($group_from_id, $user['groups'])) !== false) {
                     unset($user['groups'][$key]);
                 }
             }
             $user['groups'][] = $group_to_id;
             $user['groups'] = array_unique($user['groups']);
             $this->model->updateUser($user['id'], array('groups' => $user['groups'], 'date_group' => null));
             if (!$is_notify) {
                 continue;
             }
             $messenger = cmsCore::getController('messages');
             $messenger->addRecipient($user['id']);
             $messenger->sendNoticePM(array('content' => nl2br($notify_text)));
         }
     }
 }
Esempio n. 23
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $notice_id = $this->request->get('notice_id') or cmsCore::error404();
     $action_name = $this->request->get('action_name') or cmsCore::error404();
     $user = cmsUser::getInstance();
     $template = cmsTemplate::getInstance();
     $notice = $this->model->getNotice($notice_id);
     $result = array('error' => true);
     //
     // Проверяем хозяина уведомления
     //
     if ($notice['user_id'] != $user->id) {
         $template->renderJSON(array('error' => true, 'message' => 'unknown user'));
     }
     //
     // Если это закрытие уведомления и его можно закрывать, то закроем
     //
     if ($action_name == 'close' && $notice['options']['is_closeable']) {
         $this->model->deleteNotice($notice_id);
         $template->renderJSON(array('error' => false));
     }
     //
     // Проверяем наличие требуемого действия
     //
     if (!isset($notice['actions'][$action_name])) {
         $template->renderJSON(array('error' => true, 'message' => 'unknown action'));
     }
     $action = $notice['actions'][$action_name];
     //
     // Если указан URL для редиректа, то возвращаем его
     //
     if (isset($action['href'])) {
         $result = array('error' => false, 'href' => $action['href']);
     }
     //
     // Если указан контроллер и действие, то выполняем
     //
     if (isset($action['controller'], $action['action'])) {
         $params = isset($action['params']) ? $action['params'] : array();
         $controller = cmsCore::getController($action['controller']);
         $controller->runAction($action['action'], $params);
         $result = array('error' => false);
     }
     //
     // Удаляем уведомление и возвращаем результат
     //
     if (!$result['error']) {
         $this->model->deleteNotice($notice_id);
     }
     $template->renderJSON($result);
 }
Esempio n. 24
0
 public function actionUpload()
 {
     $images_controller = cmsCore::getController('images');
     $result = $images_controller->uploadWithPreset('inline_upload_file', 'wysiwyg_markitup');
     if (!$result['success']) {
         cmsTemplate::getInstance()->renderJSON(array('status' => 'error', 'msg' => $result['error']));
         $this->halt();
     }
     cmsTemplate::getInstance()->renderJSON(array('status' => 'success', 'src' => $result['image']['url']));
     $this->halt();
 }
Esempio n. 25
0
 public function actionUpload()
 {
     if (!cmsUser::isLogged()) {
         return $this->cms_template->renderJSON(array('status' => 'error', 'msg' => 'auth error'));
     }
     $result = cmsCore::getController('images')->uploadWithPreset('inline_upload_file', 'wysiwyg_markitup');
     if (!$result['success']) {
         return $this->cms_template->renderJSON(array('status' => 'error', 'msg' => $result['error']));
     }
     return $this->cms_template->renderJSON(array('status' => 'success', 'src' => $result['image']['url']));
 }
Esempio n. 26
0
 public function run($group)
 {
     $is_member = $this->model->getMembership($group['id'], $this->cms_user->id);
     $is_owner = $group['owner_id'] == $this->cms_user->id;
     if ($is_member && !$is_owner) {
         $group = cmsEventsManager::hook('group_before_leave', $group);
         $this->model->deleteMembership($group['id'], $this->cms_user->id);
         cmsCore::getController('activity')->addEntry($this->name, 'leave', 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_LEAVE_MESSAGE, 'info');
     $this->redirectToAction($group['id']);
 }
Esempio n. 27
0
 public function run($group)
 {
     $user = cmsUser::getInstance();
     $is_member = $this->model->getMembership($group['id'], $user->id);
     $is_owner = $group['owner_id'] == $user->id;
     if ($is_member && !$is_owner) {
         $this->model->deleteMembership($group['id'], $user->id);
         cmsCore::getController('activity')->addEntry($this->name, "leave", array('subject_title' => $group['title'], 'subject_id' => $group['id'], 'subject_url' => href_to($this->name, $group['id']), 'group_id' => $group['id']));
     }
     cmsUser::addSessionMessage(LANG_GROUPS_LEAVE_MESSAGE, 'info');
     $this->redirectToAction($group['id']);
 }
Esempio n. 28
0
 public function run($id)
 {
     if (!$id) {
         cmsCore::error404();
     }
     $content_model = cmsCore::getModel('content');
     $ctype = $content_model->getContentType($id);
     $ctype = cmsEventsManager::hook("ctype_before_delete", $ctype);
     $content_model->deleteContentType($id);
     cmsEventsManager::hook("ctype_after_delete", $ctype);
     cmsCore::getModel('widgets')->deletePagesByName('content', "{$ctype['name']}.*");
     cmsCore::getController('activity')->deleteType('content', "add.{$ctype['name']}");
     $this->redirectToAction('ctypes');
 }
Esempio n. 29
0
 public function run($group, $ctype_name = false)
 {
     if (!$ctype_name) {
         cmsCore::error404();
     }
     $user = cmsUser::getInstance();
     $content_controller = cmsCore::getController('content', $this->request);
     $ctype = $content_controller->model->getContentTypeByName($ctype_name);
     if (!$ctype) {
         cmsCore::error404();
     }
     $content_controller->model->filterEqual('parent_id', $group['id'])->filterEqual('parent_type', 'group')->orderBy('date_pub', 'desc')->forceIndex('parent_id');
     $page_url = href_to($this->name, $group['id'], array('content', $ctype_name));
     $html = $content_controller->renderItemsList($ctype, $page_url);
     return cmsTemplate::getInstance()->render('group_content', array('user' => $user, 'group' => $group, 'ctype' => $ctype, 'html' => $html));
 }
Esempio n. 30
0
 public function showUploadForm($album_id)
 {
     if (!cmsUser::isAllowed('albums', 'add')) {
         cmsCore::error404();
     }
     $user = cmsUser::getInstance();
     $content_model = cmsCore::getModel('content');
     $ctype = $content_model->getContentTypeByName('albums');
     $albums = $content_model->filterEqual('user_id', $user->id)->filterOr()->filterEqual('is_public', 1)->orderByList(array(array('by' => 'is_public', 'to' => 'asc'), array('by' => 'date_pub', 'to' => 'desc')))->getContentItems('albums');
     if (!$albums) {
         $this->redirect(href_to('albums', 'add'));
     }
     if ($this->request->has('submit')) {
         $album_id = $this->request->get('album_id');
         if (!isset($albums[$album_id])) {
             $this->redirectBack();
         }
         if (!$this->request->has('photos')) {
             $this->redirectBack();
         }
         $album = $albums[$album_id];
         $photos_titles = $this->request->get('photos');
         $this->model->assignAlbumId($album_id);
         $this->model->updateAlbumCoverImage($album['id'], $photos_titles);
         $this->model->updateAlbumPhotosCount($album_id, sizeof($photos_titles));
         $this->model->updatePhotoTitles($album_id, $photos_titles);
         $activity_thumb_images = array();
         $photos = $this->model->getPhotosByIdsList(array_keys($photos_titles));
         $photos_count = count($photos);
         if ($photos_count > 5) {
             $photos = array_slice($photos, 0, 4);
         }
         if ($photos_count) {
             foreach ($photos as $photo) {
                 $activity_thumb_images[] = array('url' => href_to('photos', 'view', $photo['id']), 'src' => html_image_src($photo['image'], 'small'));
             }
         }
         $activity_controller = cmsCore::getController('activity');
         $activity_controller->addEntry($this->name, "add.photos", array('user_id' => $user->id, 'subject_title' => $album['title'], 'subject_id' => $album['id'], 'subject_url' => href_to('albums', $album['slug'] . '.html'), 'is_private' => isset($album['is_private']) ? $album['is_private'] : 0, 'group_id' => isset($album['parent_id']) ? $album['parent_id'] : null, 'images' => $activity_thumb_images, 'images_count' => $photos_count));
         $this->redirect(href_to('albums', $albums[$album_id]['slug'] . '.html'));
     }
     $photos = $this->model->getOrphanPhotos();
     if (!isset($albums[$album_id])) {
         $album_id = false;
     }
     cmsTemplate::getInstance()->render('upload', array('ctype' => $ctype, 'albums' => $albums, 'photos' => $photos, 'album_id' => $album_id));
 }