Ejemplo n.º 1
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));
 }
Ejemplo n.º 2
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $template = cmsTemplate::getInstance();
     $entry_id = $this->request->get('id');
     // Проверяем валидность
     $is_valid = is_numeric($entry_id);
     if (!$is_valid) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         $template->renderJSON($result);
     }
     $user = cmsUser::getInstance();
     $entry = $this->model->getEntry($entry_id);
     $replies = $this->model->getReplies($entry_id);
     if (!$replies) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         $template->renderJSON($result);
     }
     $permissions = array('add' => $user->is_logged, 'delete' => $user->is_admin || $user->id == $entry['profile_id']);
     $html = $template->renderInternal($this, 'entry', array('entries' => $replies, 'user' => $user, 'permissions' => $permissions));
     // Формируем и возвращаем результат
     $result = array('error' => false, 'html' => $html);
     $template->renderJSON($result);
 }
Ejemplo n.º 3
0
 public function getWidget($title, $target, $permissions = array())
 {
     $user = cmsUser::getInstance();
     extract($target);
     $page = $this->request->get('page', 1);
     $show_id = $this->request->get('wid');
     $go_reply = $this->request->get('reply', 0);
     $show_reply_id = 0;
     if ($show_id) {
         $entry = $this->model->getEntry($show_id);
         if ($entry) {
             if ($entry['parent_id'] > 0) {
                 $show_id = $entry['parent_id'];
                 $show_reply_id = $entry['id'];
             }
             $page = $this->model->getEntryPageNumber($show_id, $target, self::$perpage);
         }
     }
     $total = $this->model->getEntriesCount($profile_type, $profile_id);
     $entries = $this->model->getEntries($profile_type, $profile_id, $page);
     $entries = cmsEventsManager::hook('wall_before_list', $entries);
     $csrf_token_seed = implode('/', array($profile_type, $profile_id));
     $template = cmsTemplate::getInstance();
     return $template->renderInternal($this, 'list', array('title' => $title, 'user' => $user, 'controller' => $controller, 'profile_type' => $profile_type, 'profile_id' => $profile_id, 'user' => $user, 'entries' => $entries, 'permissions' => $permissions, 'page' => $page, 'perpage' => wall::$perpage, 'total' => $total, 'max_entries' => $show_id ? 0 : 5, 'csrf_token_seed' => $csrf_token_seed, 'show_id' => $show_id, 'show_reply_id' => $show_reply_id, 'go_reply' => $go_reply));
 }
Ejemplo n.º 4
0
 private function parseHide($text, $hidden = false)
 {
     $inUser = cmsUser::getInstance();
     global $_LANG;
     $pattern = '/\\[hide(?:=?)([0-9]*)\\](.*?)\\[\\/hide\\]/sui';
     preg_match($pattern, $text, $matches);
     if (!$matches) {
         return $text;
     }
     if ($hidden) {
         $replacement = '<noindex>' . $_LANG['P_HIDE_TEXT_MOD'] . '</noindex>';
     } else {
         if (!$inUser->id) {
             $replacement = '<noindex><div class="bb_tag_hide">' . $_LANG['P_HIDE_TEXT'] . '</div></noindex>';
         } else {
             if (!$matches[1]) {
                 $replacement = '<div class="bb_tag_hide">${2}</div>';
             } elseif ($inUser->rating > $matches[1] || $inUser->is_admin) {
                 $replacement = '<div class="bb_tag_hide">${2}</div>';
             } else {
                 $replacement = '<div class="bb_tag_hide">' . sprintf($_LANG['P_HIDE_TEXT_RATING'], cmsCore::spellCount($matches[1], $_LANG['P_ITEM1'], $_LANG['P_ITEM2'], $_LANG['P_ITEM10'])) . '</div>';
             }
         }
     }
     return preg_replace($pattern, $replacement, $text);
 }
Ejemplo n.º 5
0
 private function sendInvites($profile, $emails_list)
 {
     $user = cmsUser::getInstance();
     $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($user->id);
         $to = array('email' => $email, 'name' => $email);
         $letter = array('name' => 'users_invite');
         $messenger->sendEmail($to, $letter, array('nickname' => $user->nickname, 'code' => $invite['code'], 'page_url' => href_to_abs('auth', 'register') . "?inv={$invite['code']}"));
         $results['success'][$email] = true;
         $auth_model->markInviteSended($invite['id'], $user->id, $email);
         if (sizeof($results['success']) + sizeof($results['failed']) >= $profile['invites_count']) {
             break;
         }
     }
     return $results;
 }
Ejemplo n.º 6
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.º 7
0
function mod_calendar_eventview($module_id)
{
    $inCore = cmsCore::getInstance();
    $inUser = cmsUser::getInstance();
    $DB = cmsDatabase::getInstance();
    $cfg = $inCore->loadComponentConfig('calendar');
    if ($inUser->id != 0 and $cfg['calendar_module'] == "user") {
        //Запрос к БД
        $sql = "\r\n\tSELECT cms_events.* ,\r\n\tcms_events_category.tx,\r\n\tcms_events_category.bg\r\n\tFROM cms_events \r\n\tLEFT JOIN cms_events_signup ON cms_events.id=cms_events_signup.event_id \r\n\tLEFT JOIN cms_events_category ON cms_events.category_id = cms_events_category.id\r\n\tWHERE \r\n\tcms_events.start_time > " . time() . " AND \r\n\tcms_events.author_id = " . $inUser->id . " OR \r\n\tcms_events_signup.user_id = " . $inUser->id . " AND \r\n\tcms_events.author_id <> " . $inUser->id . " AND \r\n\tcms_events.start_time > " . time() . " \r\n\tGROUP BY cms_events.id ORDER BY cms_events.start_time ASC LIMIT " . $cfg['calendar_module_count'];
    } else {
        $sql = "SELECT cms_events.*,\r\n\t    cms_events_category.tx,\r\n\t    cms_events_category.bg\r\n\t    FROM cms_events\r\n\t    LEFT JOIN cms_events_category ON cms_events.category_id = cms_events_category.id\t    \r\n\t    WHERE cms_events.`type` = 'public' \r\n\t    AND cms_events.start_time > " . time() . " \r\n\t    ORDER BY cms_events.start_time ASC LIMIT " . $cfg['calendar_module_count'];
    }
    $result = $DB->query($sql);
    if ($DB->error()) {
        return false;
    }
    $events = array();
    while ($event = $DB->fetch_assoc($result)) {
        if ($event['author_id'] == $inUser->id) {
            $event['time'] == "";
        }
        if ($event['category_id'] == 0) {
            $event['bg'] = '#C3BCB9';
            $event['tx'] = '#000000';
        }
        $events[] = $event;
    }
    $smarty = $inCore->initSmarty('modules', 'mod_calendar_eventview.tpl');
    $smarty->assign('events', $events);
    $smarty->display('mod_calendar_eventview.tpl');
    return true;
}
Ejemplo n.º 8
0
 public function run()
 {
     $user = cmsUser::getInstance();
     $is_allowed = $user->isInGroups($this->options['groups_allowed']);
     $contacts = $this->model->getContacts($user->id);
     cmsTemplate::getInstance()->render('index', array('user' => $user, 'is_allowed' => $is_allowed, 'contacts' => $contacts));
 }
Ejemplo n.º 9
0
 public function execute($event, $user)
 {
     parent::execute();
     $inCore = cmsCore::getInstance();
     $inUser = cmsUser::getInstance();
     $inCore->loadModel('usermaps');
     $model = new cms_model_usermaps();
     $catalogs = array();
     $user_id = $user['id'];
     $limit = $this->config['Количество объектов'];
     $steep = $this->config['Квадрат поиска в метрах'];
     $have_point = $model->getUserPlace($user_id);
     if ($have_point) {
         $points = $model->getArround($have_point['id']);
     }
     ob_start();
     if ($have_point and $inUser->id == $user_id) {
         $smarty = $this->inCore->initSmarty('plugins', 'p_places_sosedi.tpl');
         $smarty->assign('total', count($points));
         $smarty->assign('points', $points);
         $smarty->display('p_places_sosedi.tpl');
     }
     $html = ob_get_clean();
     return $html;
 }
Ejemplo n.º 10
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     if (!cmsUser::isAllowed('comments', 'delete')) {
         cmsCore::error404();
     }
     $comment = $this->model->getComment((int) $this->request->get('id'));
     // Проверяем
     if (!$comment) {
         cmsTemplate::getInstance()->renderJSON($result = array('error' => true, 'message' => LANG_ERROR));
     }
     $user = cmsUser::getInstance();
     if (!cmsUser::isAllowed('comments', 'delete', 'all') && !cmsUser::isAllowed('comments', 'delete', 'full_delete')) {
         if (cmsUser::isAllowed('comments', 'delete', 'own') && $comment['user']['id'] != $user->id) {
             cmsTemplate::getInstance()->renderJSON(array('error' => true, 'message' => LANG_ERROR));
         }
     }
     // проверяем, есть ли дети комментария
     $is_comment_child = $this->model->getItemByField('comments', 'parent_id', $comment['id']);
     $this->model->deleteComment($comment['id'], !$is_comment_child && cmsUser::isAllowed('comments', 'delete', 'full_delete', true));
     if (cmsUser::isAllowed('comments', 'delete', 'full_delete')) {
         cmsEventsManager::hook('comments_after_delete', $comment['id']);
     } else {
         cmsEventsManager::hook('comments_after_hide', $comment['id']);
     }
     cmsTemplate::getInstance()->renderJSON(array('error' => false, 'message' => LANG_COMMENT_DELETED));
 }
Ejemplo n.º 11
0
function mod_menu($mod, $cfg)
{
    $inCore = cmsCore::getInstance();
    $inUser = cmsUser::getInstance();
    $menuid = $inCore->menuId();
    $full_menu = $inCore->getMenuStruct();
    $current_uri = '/' . $inCore->getUri();
    if (!isset($cfg['menu'])) {
        $menu = 'mainmenu';
    } else {
        $menu = $cfg['menu'];
    }
    if (!isset($cfg['show_home'])) {
        $cfg['show_home'] = 1;
    }
    if (!isset($cfg['is_sub_menu'])) {
        $cfg['is_sub_menu'] = 0;
    }
    // текущий пункт меню
    $currentmenu = isset($full_menu[$menuid]) ? $full_menu[$menuid] : array();
    // результирующий массив меню
    $items = array();
    // id корня меню если обычный вывод меню, $menuid если режим подменю
    if ($cfg['is_sub_menu']) {
        // в подменю не должно быть ссылки на главную
        $cfg['show_home'] = 0;
        // на главной или нет активного пункта меню
        if ($menuid == 1 || !$currentmenu) {
            return false;
        }
        foreach ($full_menu as $item) {
            if ($item['NSLeft'] > $currentmenu['NSLeft'] && $item['NSRight'] < $currentmenu['NSRight'] && in_array($menu, $item['menu']) && ($item['is_lax'] || cmsCore::checkContentAccess($item['access_list'], false)) && $item['published']) {
                $item['link'] = cmsUser::stringReplaceUserProperties($item['link']);
                $item['title'] = cmsUser::stringReplaceUserProperties($item['title'], true);
                $items[] = $item;
                // массивы для сортировки
                $nsl[] = $item['NSLeft'];
                $ord[] = $item['ordering'];
            }
        }
    } else {
        foreach ($full_menu as $item) {
            if (in_array($menu, $item['menu']) && ($item['is_lax'] || cmsCore::checkContentAccess($item['access_list'], false)) && $item['published']) {
                $item['link'] = cmsUser::stringReplaceUserProperties($item['link']);
                $item['title'] = cmsUser::stringReplaceUserProperties($item['title'], true);
                $items[] = $item;
                // массивы для сортировки
                $nsl[] = $item['NSLeft'];
                $ord[] = $item['ordering'];
            }
        }
    }
    if (!$items) {
        return false;
    }
    // сортируем массив
    array_multisort($nsl, SORT_ASC, $ord, SORT_ASC, $items);
    cmsPage::initTemplate('modules', $cfg['tpl'])->assign('menuid', $menuid)->assign('currentmenu', $currentmenu)->assign('current_uri', $current_uri)->assign('menu', $menu)->assign('items', $items)->assign('last_level', 0)->assign('user_id', $inUser->id)->assign('is_admin', $inUser->is_admin)->assign('cfg', $cfg)->display($cfg['tpl']);
    return true;
}
Ejemplo n.º 12
0
 public function run($profile, $tab_name)
 {
     $user = cmsUser::getInstance();
     // Доступность профиля для данного пользователя
     if (!$user->isPrivacyAllowed($profile, 'users_profile_view')) {
         cmsCore::error404();
     }
     $arguments = func_get_args();
     $tabs_menu = $this->getProfileMenu($profile);
     if (!isset($this->tabs[$tab_name]) || !$this->tabs[$tab_name]) {
         cmsCore::error404();
     }
     $tab = $this->tabs[$tab_name];
     if (!isset($this->tabs_controllers[$tab['controller']])) {
         cmsCore::error404();
     }
     $controller = $this->tabs_controllers[$tab['controller']];
     unset($this->tabs);
     unset($this->tabs_controllers);
     $html = $controller->runHook('user_tab_show', $arguments);
     if (!$html) {
         cmsCore::error404();
     }
     cmsTemplate::getInstance()->render('profile_tab', array('tabs' => $tabs_menu, 'profile' => $profile, 'user' => $user, 'html' => $html));
 }
Ejemplo n.º 13
0
 public function photomap($photo)
 {
     $inCore = cmsCore::getInstance();
     $inUser = cmsUser::getInstance();
     $type = "photo";
     if ($photo['user_id'] == $inUser->id) {
         $is_author = TRUE;
     }
     $sql = mysql_query("SELECT * FROM cms_places_events WHERE `object_id` = '" . $photo['id'] . "' AND `object_type` = '{$type}'");
     $cfg = $inCore->loadComponentConfig('usermaps');
     ob_start();
     if (mysql_num_rows($sql) == 1 or $is_author) {
         $point = mysql_fetch_assoc($sql);
         if ($point['x'] == "" or $point['y'] == "") {
             $center = $cfg['maps_center'];
             $have_point = FALSE;
         } else {
             $center = '"' . $point['x'] . '","' . $point['y'] . '"';
             $have_point = TRUE;
         }
         $smarty = $this->inCore->initSmarty('plugins', 'p_places_imagesonmap.tpl');
         $smarty->assign('is_author', $is_author);
         $smarty->assign('photo_id', $photo['id']);
         $smarty->assign('photo_type', $type);
         $smarty->assign('center', $center);
         $smarty->assign('cfg', $cfg);
         $smarty->assign('have_point', $have_point);
         $smarty->display('p_places_imagesonmap.tpl');
     }
     $html = ob_get_clean();
     return $html;
 }
Ejemplo n.º 14
0
 public function run($group)
 {
     $user = cmsUser::getInstance();
     if (!cmsUser::isAllowed('groups', 'delete')) {
         cmsCore::error404();
     }
     if (!cmsUser::isAllowed('groups', 'delete', 'all') && $group['owner_id'] != $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', false);
         if (!cmsForm::validateCSRFToken($csrf_token)) {
             cmsCore::error404();
         }
         $this->model->removeContentFromGroup($group['id'], $is_delete_content);
         $this->model->deleteGroup($group['id']);
         cmsUser::addSessionMessage(sprintf(LANG_GROUPS_DELETED, $group['title']));
         $this->redirectToAction('');
     } else {
         // спрашиваем подтверждение
         return cmsTemplate::getInstance()->render('group_delete', array('user' => $user, 'group' => $group));
     }
 }
Ejemplo n.º 15
0
Archivo: get.php Proyecto: asphix/icms2
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     if (!cmsUser::isAllowed('comments', 'edit')) {
         cmsCore::error404();
     }
     $comment_id = $this->request->get('id');
     // Проверяем валидность
     $is_valid = is_numeric($comment_id);
     if (!$is_valid) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         cmsTemplate::getInstance()->renderJSON($result);
     }
     $user = cmsUser::getInstance();
     $comment = $this->model->getComment($comment_id);
     if (!cmsUser::isAllowed('comments', 'edit', 'all')) {
         if (cmsUser::isAllowed('comments', 'edit', 'own') && $comment['user']['id'] != $user->id) {
             $result = array('error' => true, 'message' => LANG_ERROR);
             cmsTemplate::getInstance()->renderJSON($result);
         }
     }
     // Формируем и возвращаем результат
     $result = array('error' => $comment ? false : true, 'id' => $comment_id, 'html' => $comment ? string_strip_br($comment['content']) : false);
     cmsTemplate::getInstance()->renderJSON($result);
 }
Ejemplo n.º 16
0
 /**
  * Возвращает код баннера по названию позиции
  * Считаются просмотры
  * @param int $id
  * @return html
  */
 public static function getBannerHTML($position)
 {
     $inDB = cmsDatabase::getInstance();
     $inUser = cmsUser::getInstance();
     $position = $inDB->escape_string($position);
     $html = '';
     $banner = $inDB->get_fields('cms_banners', "position = '{$position}' AND published = 1 AND ((maxhits > hits) OR (maxhits = 0))", '*', 'RAND()');
     if (!$banner) {
         return $html;
     }
     if ($banner['typeimg'] == 'image') {
         $html = self::getImageBanner($banner);
     }
     if ($banner['typeimg'] == 'swf') {
         $html = self::getSwfBanner($banner);
     }
     if ($html) {
         // обновляем статистику просмотра баннера
         $inDB->query("INSERT IGNORE INTO cms_banner_hits (banner_id, ip) VALUES ('{$banner['id']}', '{$inUser->ip}')");
         if ($inDB->get_last_id()) {
             $inDB->query("UPDATE cms_banners SET hits = hits + 1 WHERE id= '{$banner['id']}'");
         }
     }
     return $html;
 }
Ejemplo n.º 17
0
 public function run($profile_id)
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $user = cmsUser::getInstance();
     $direction = $this->request->get('direction');
     $comment = $this->request->get('comment');
     //
     // Проверяем валидность
     //
     $is_valid = $user->is_logged && cmsUser::isAllowed('users', 'vote_karma') && is_numeric($profile_id) && $user->id != $profile_id && in_array($direction, array('up', 'down')) && (!$this->options['is_karma_comments'] || $comment);
     if (!$is_valid) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         cmsTemplate::getInstance()->renderJSON($result);
     }
     $profile = $this->model->getUser($profile_id);
     if (!$profile || !$this->model->isUserCanVoteKarma($user->id, $profile_id, $this->options['karma_time'])) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         cmsTemplate::getInstance()->renderJSON($result);
     }
     //
     // Сохраняем оценку
     //
     $vote = array('user_id' => $user->id, 'profile_id' => $profile_id, 'points' => $direction == 'up' ? 1 : -1, 'comment' => $comment);
     $vote_id = $this->model->addKarmaVote($vote);
     $value = $profile['karma'] + $vote['points'];
     $result = array('error' => $vote_id ? false : true, 'value' => html_signed_num($value), 'css_class' => html_signed_class($value));
     cmsTemplate::getInstance()->renderJSON($result);
 }
Ejemplo n.º 18
0
 public function actionLogout()
 {
     cmsEventsManager::hook('auth_logout', cmsUser::getInstance()->id);
     cmsUser::logout();
     $this->redirectToHome();
     $this->halt();
 }
Ejemplo n.º 19
0
function mod_actions(array $mod, $cfg)
{
    $inDB = cmsDatabase::getInstance();
    $inActions = cmsActions::getInstance();
    global $_LANG;
    if (!isset($cfg['show_target'])) {
        $cfg['show_target'] = 1;
    }
    if (!isset($cfg['limit'])) {
        $cfg['limit'] = 15;
    }
    if (!isset($cfg['show_link'])) {
        $cfg['show_link'] = 1;
    }
    if (!isset($cfg['action_types'])) {
        echo $_LANG['MODULE_NOT_CONFIGURED'];
        return true;
    }
    if (!$cfg['show_target']) {
        $inActions->showTargets(false);
    }
    $inActions->onlySelectedTypes($cfg['action_types']);
    $inDB->limitIs($cfg['limit']);
    $actions = $inActions->getActionsLog();
    if (!$actions) {
        return false;
    }
    cmsPage::initTemplate('modules', $cfg['tpl'])->assign('actions', $actions)->assign('cfg', $cfg)->assign('user_id', cmsUser::getInstance()->id)->display($cfg['tpl']);
    return true;
}
Ejemplo n.º 20
0
 public function actionWidget($field_id, $city_id = false)
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $template = cmsTemplate::getInstance();
     $user = cmsUser::getInstance();
     $countries = $this->model->getCountries();
     $countries = array('0' => LANG_GEO_SELECT_COUNTRY) + $countries;
     $regions = array();
     $cities = array();
     $region_id = false;
     $country_id = false;
     if ($user->is_logged && !$city_id && $user->city['id']) {
         $city_id = $user->city['id'];
     }
     if ($city_id) {
         $city_parents = $this->model->getCityParents($city_id);
         $region_id = $city_parents['region_id'];
         $country_id = $city_parents['country_id'];
         $regions = $this->model->getRegions($country_id);
         $regions = array('0' => LANG_GEO_SELECT_REGION) + $regions;
         $cities = $this->model->getCities($region_id);
         $cities = array('0' => LANG_GEO_SELECT_CITY) + $cities;
     }
     $template->render('widget', array('field_id' => $field_id, 'city_id' => $city_id, 'country_id' => $country_id, 'region_id' => $region_id, 'countries' => $countries, 'regions' => $regions, 'cities' => $cities));
 }
Ejemplo n.º 21
0
 public function run($photo_id = null)
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     if (!$photo_id) {
         $photo_id = $this->request->get('id');
         if (!$photo_id) {
             cmsCore::error404();
         }
     }
     $photo = $this->model->getPhoto($photo_id);
     $success = true;
     // проверяем наличие доступа
     $user = cmsUser::getInstance();
     if (!cmsUser::isAllowed('albums', 'edit')) {
         $success = false;
     }
     if (!cmsUser::isAllowed('albums', 'edit', 'all') && $photo['user_id'] != $user->id) {
         $success = false;
     }
     if (!$success) {
         cmsTemplate::getInstance()->renderJSON(array('success' => false));
     }
     $album = cmsCore::getModel('content')->getContentItem('albums', $photo['album_id']);
     $this->model->deletePhoto($photo_id);
     $this->model->setRandomAlbumCoverImage($photo['album_id']);
     cmsTemplate::getInstance()->renderJSON(array('success' => true, 'album_url' => href_to('albums', $album['slug'] . '.html')));
 }
Ejemplo n.º 22
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     if (!cmsUser::isAllowed('comments', 'delete')) {
         cmsCore::error404();
     }
     $comment_id = $this->request->get('id');
     // Проверяем валидность
     $is_valid = is_numeric($comment_id);
     if (!$is_valid) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         cmsTemplate::getInstance()->renderJSON($result);
     }
     $user = cmsUser::getInstance();
     $comment = $this->model->getComment($comment_id);
     if (!cmsUser::isAllowed('comments', 'edit', 'all')) {
         if (cmsUser::isAllowed('comments', 'edit', 'own') && $comment['user']['id'] != $user->id) {
             $result = array('error' => true, 'message' => LANG_ERROR);
             cmsTemplate::getInstance()->renderJSON($result);
         }
     }
     $this->model->deleteComment($comment_id);
     $result = array('error' => false, 'message' => LANG_COMMENT_DELETED);
     cmsTemplate::getInstance()->renderJSON($result);
 }
Ejemplo n.º 23
0
    public function displayEditor($field_id, $content = '')
    {
        $lang = cmsConfig::get('language');
        $user = cmsUser::getInstance();
        cmsTemplate::getInstance()->addJS('wysiwyg/tinymce/tinymce.min.js');
        $dom_id = str_replace(array('[', ']'), array('_', ''), $field_id);
        echo html_textarea($field_id, $content, array('id' => $dom_id));
        ?>
<script type="text/javascript" >
$(document).ready(function(){
 	tinymce.init({mode : "exact", 
	              elements : "<?php 
        echo $field_id;
        ?>
",
				  language : "ru",
				 plugins: [
         "link image lists media responsivefilemanager "
   ],
    relative_urls: false,
   
    filemanager_title:"Responsive Filemanager",
    external_filemanager_path:"/filemanager/",
    external_plugins: { "filemanager" : "/filemanager/plugin.min.js"},
    
				  image_advtab: true,
   toolbar1: "undo redo | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | styleselect",
   toolbar2: "| responsivefilemanager | image | media | link unlink anchor | "
	   			  
				  });
				  });
</script>
<?php 
    }
Ejemplo n.º 24
0
function mod_cart($module_id, $cfg)
{
    $inDB = cmsDatabase::getInstance();
    $inUser = cmsUser::getInstance();
    cmsCore::includeFile('components/catalog/includes/shopcore.php');
    $sid = session_id();
    $items = array();
    $total_summ = 0;
    $user_sql = $inUser->id ? "c.user_id='{$inUser->id}'" : "c.session_id='{$sid}'";
    $sql = "SELECT i.title, i.price, i.category_id, i.id, c.itemscount\n            FROM cms_uc_cart c\n            INNER JOIN cms_uc_items i ON i.id = c.item_id\n            WHERE {$user_sql}";
    $result = $inDB->query($sql);
    $items_count = $inDB->num_rows($result);
    if ($items_count) {
        while ($con = $inDB->fetch_assoc($result)) {
            $price = shopDiscountPrice($con['id'], $con['category_id'], $con['price']);
            $totalcost = $con['itemscount'] * $price;
            $total_summ += $totalcost;
            $con['price'] = number_format($price, 2, '.', ' ');
            $con['totalcost'] = number_format($totalcost, 2, '.', ' ');
            $items[] = $con;
        }
    }
    cmsPage::initTemplate('modules', 'mod_cart')->assign('cfg', $cfg)->assign('items_count', $items_count)->assign('total_summ', number_format($total_summ, 2, '.', ' '))->assign('items', $items)->display('mod_cart.tpl');
    return true;
}
Ejemplo n.º 25
0
function mod_user_friend($mod, $cfg)
{
    $inDB = cmsDatabase::getInstance();
    $inUser = cmsUser::getInstance();
    if (!$inUser->id) {
        return false;
    }
    if ($cfg['view_type'] == 'table') {
        $sql = "SELECT\r\n                CASE\r\n                WHEN f.from_id = {$inUser->id}\r\n                THEN f.to_id\r\n                WHEN f.to_id = {$inUser->id}\r\n                THEN f.from_id\r\n                END AS user_id, u.login, u.nickname, u.is_deleted, p.imageurl\r\n                FROM cms_user_friends f\r\n                INNER JOIN cms_online o ON o.user_id = CASE WHEN f.from_id = {$inUser->id} THEN f.to_id WHEN f.to_id = {$inUser->id} THEN f.from_id END\r\n                LEFT JOIN cms_users u ON u.id = o.user_id\r\n                LEFT JOIN cms_user_profiles p ON p.user_id = u.id\r\n                WHERE (from_id = {$inUser->id} OR to_id = {$inUser->id}) AND is_accepted =1 LIMIT " . $cfg['limit'];
    } else {
        $sql = "SELECT\r\n                CASE\r\n                WHEN f.from_id = {$inUser->id}\r\n                THEN f.to_id\r\n                WHEN f.to_id = {$inUser->id}\r\n                THEN f.from_id\r\n                END AS user_id, u.login, u.nickname\r\n                FROM cms_user_friends f\r\n                INNER JOIN cms_online o ON o.user_id = CASE WHEN f.from_id = {$inUser->id} THEN f.to_id WHEN f.to_id = {$inUser->id} THEN f.from_id END\r\n                LEFT JOIN cms_users u ON u.id = o.user_id\r\n                WHERE (from_id = {$inUser->id} OR to_id = {$inUser->id}) AND is_accepted =1 LIMIT " . $cfg['limit'];
    }
    $result = $inDB->query($sql);
    $total = $inDB->num_rows($result);
    if ($total) {
        $friends = array();
        while ($friend = $inDB->fetch_assoc($result)) {
            $friend['avatar'] = $cfg['view_type'] == 'table' ? cmsUser::getUserAvatarUrl($friend['user_id'], 'small', $friend['imageurl'], $friend['is_deleted']) : false;
            $friend['user_link'] = cmsUser::getProfileLink($friend['login'], $friend['nickname']);
            $friends[$friend['user_id']] = $friend;
        }
    }
    cmsPage::initTemplate('modules', $cfg['tpl'])->assign('friends', $friends)->assign('total', $total)->assign('cfg', $cfg)->display($cfg['tpl']);
    return true;
}
Ejemplo n.º 26
0
 public function run($tab = 'all')
 {
     $user = cmsUser::getInstance();
     $dataset_name = false;
     $datasets = $this->getDatasets();
     if ($tab && isset($datasets[$tab])) {
         $dataset_name = $tab;
         $dataset = $datasets[$tab];
         if (isset($dataset['filter']) && is_callable($dataset['filter'])) {
             $this->model = $dataset['filter']($this->model, $dataset);
         }
     } else {
         if ($tab) {
             cmsCore::error404();
         }
     }
     // Сортировка
     if ($dataset_name) {
         $this->model->orderBy($datasets[$dataset_name]['order'][0], $datasets[$dataset_name]['order'][1]);
     }
     // Формируем базовые URL для страниц
     $page_url = array('base' => href_to($this->name, $dataset_name ? 'index/' . $dataset_name : ''), 'first' => href_to($this->name, $dataset_name ? 'index/' . $dataset_name : ''));
     // Получаем HTML списка записей
     $profiles_list_html = $this->renderProfilesList($page_url, $dataset_name);
     return cmsTemplate::getInstance()->render('index', array('datasets' => $datasets, 'dataset_name' => $dataset_name, 'dataset' => $dataset, 'user' => $user, 'profiles_list_html' => $profiles_list_html), $this->request);
 }
Ejemplo n.º 27
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.º 28
0
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $comment_id = $this->request->get('comment_id');
     $score = $this->request->get('score');
     // Проверяем валидность
     $is_valid = is_numeric($comment_id) && in_array($score, array(-1, 1));
     $template = cmsTemplate::getInstance();
     if (!$is_valid) {
         $template->renderJSON(array('error' => true));
     }
     $user = cmsUser::getInstance();
     $is_can_rate = cmsUser::isAllowed('comments', 'rate');
     if (!$is_can_rate) {
         $template->renderJSON(array('error' => true));
     }
     $is_voted = $this->model->isUserVoted($comment_id, $user->id);
     if ($is_voted) {
         $template->renderJSON(array('error' => true));
     }
     $comment = $this->model->getComment($comment_id);
     if ($comment['user_id'] == $user->id) {
         $template->renderJSON(array('error' => true));
     }
     $success = $this->model->rateComment($comment_id, $user->id, $score);
     $template->renderJSON(array('error' => !$success));
 }
Ejemplo n.º 29
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));
 }
Ejemplo n.º 30
0
 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));
 }