/** * @param string $str * @return string * * smiles process */ public function smile($str) { $str = Plugins::intercept('before_smiles_parse', $str); $Register = Register::getInstance(); $path = $Register['Config']->read('smiles_set'); $path = ROOT . '/sys/img/smiles/' . (!empty($path) ? $path : 'fapos') . '/info.php'; include $path; $from = array(); $to = array(); if (isset($smilesList) && is_array($smilesList)) { foreach ($smilesList as $smile) { $from[] = $smile['from']; $to[] = '<img alt="' . $smile['from'] . '" title="' . $smile['from'] . '" src="' . WWW_ROOT . '/sys/img/smiles/fapos/' . $smile['to'] . '" />'; } } $str = str_replace($from, $to, $str); return $str; }
/** * @param string $content data for parse and view * @access protected */ protected function _view($content) { $Register = Register::getInstance(); if (!empty($this->template) && $this->wrap == true) { Plugins::intercept('before_parse_layout', $this); $this->View->setLayout($this->template); $markers = $this->getGlobalMarkers(file_get_contents($this->View->getTemplateFilePath('main.html'))); $markers['content'] = $content; // Cache global markers if ($this->cached) { if ($this->Cache->check($this->cacheKey . '_global_markers')) { $gdata = $this->Cache->read($this->cacheKey . '_global_markers'); $this->globalMarkers = array_merge($this->globalMarkers, unserialize($gdata)); } else { $gdata = serialize($this->globalMarkers); $this->Cache->write($gdata, $this->cacheKey . '_global_markers', $this->cacheTags); } } $boot_time = round(getMicroTime() - $Register['fps_boot_start_time'], 4); $markers = array_merge($markers, array('boot_time' => $boot_time)); $output = $this->render('main.html', $markers); } else { $output = $content; } $this->_afterRender(); echo $output; if (Config::read('debug_mode') == 1) { echo AtmDebug::getBody(); } die; }
public function add() { //turn access $this->ACL->turn(array('foto', 'add_materials')); // Обрезаем переменные до длины, указанной в параметре maxlength тега input $title = trim(mb_substr($_POST['title'], 0, 128)); $description = trim($_POST['main_text']); $in_cat = intval($_POST['cats_selector']); // Check fields $errors = $this->Register['Validate']->check($this->Register['action']); //categories list $className = $this->Register['ModManager']->getModelNameFromModule($this->module . 'Categories'); $catModel = new $className(); $sql = $catModel->getCollection(array('id' => $in_cat)); if (empty($sql)) { $errors[] = __('Can not find category'); } // errors if (!empty($errors)) { $data = array('title' => null, 'description' => $description, 'in_cat' => $in_cat); $data = array_merge($data, $_POST); $data['errors'] = $errors; $_SESSION['FpsForm'] = $data; redirect('/foto/add_form/'); } // spam protected if (isset($_SESSION['unix_last_post']) and time() - $_SESSION['unix_last_post'] < 10) { return $this->showInfoMessage(__('Your message has been added'), '/foto/'); } // Формируем SQL-запрос на добавление темы $description = mb_substr($description, 0, Config::read('description_lenght', 'foto')); $res = array('title' => $title, 'description' => $description, 'date' => new Expr('NOW()'), 'author_id' => $_SESSION['user']['id'], 'category_id' => $in_cat, 'filename' => ''); try { $entity = new FotoEntity($res); $id = $entity->save(); if (!$id) { throw new Exception('ERROR: SAVE_ERR'); } $filename = $this->__saveFile($_FILES['foto'], $id); if (!$filename) { throw new Exception('ERROR: FILE_UPL'); } $entity->setFilename($filename)->save(); } catch (Exception $e) { $entity->delete(); $data = array('title' => null, 'description' => null, 'in_cat' => $in_cat); $data = array_merge($data, $_POST); $data['errors'] = array(__('Some error occurred')); $_SESSION['FpsForm'] = $data; redirect('/foto/add_form/'); } // hook for plugins Plugins::intercept('new_entity', array('entity' => $entity, 'module' => $this->module)); //clean cache $this->Cache->clean(CACHE_MATCHING_TAG, array('module_foto')); $this->DB->cleanSqlCache(); if ($this->Log) { $this->Log->write('adding foto', 'foto id(' . $id . ')'); } return $this->showInfoMessage(__('Material successfully added'), '/foto/'); }
/** * Get correct name of template for current user */ function getTemplateName() { $template = Config::read('template'); $template = Plugins::intercept('select_template', $template); return $template; }
/** * @param null|int $id */ public function view($id = null) { //turn access $this->ACL->turn(array($this->module, 'view_product')); $id = intval($id); if (empty($id) || $id < 1) { redirect('/'); } $where = array("(quantity > 0 || hide_not_exists = '0')"); $where['id'] = $id; $this->Model->bindModel('attributes_group'); $this->Model->bindModel('attributes.content'); $this->Model->bindModel('vendor'); $this->Model->bindModel('category'); $this->Model->bindModel('author'); $this->Model->bindModel('attaches'); $entity = $this->Model->getFirst($where); if (empty($entity)) { redirect('/error.php?ac=404'); } if ($entity->getAvailable() == 0 && !$this->ACL->turn(array('other', 'can_see_hidden'), false)) { return $this->showInfoMessage(__('Permission denied'), '/' . $this->module . '/'); } if (!$this->ACL->checkCategoryAccess($entity->getCategory()->getNo_access())) { return $this->showInfoMessage(__('Permission denied'), '/' . $this->module . '/'); } Plugins::intercept('view_category', $entity->getCategory()); // category block $this->_getCatsTree($entity->getCategory()->getId()); // Comments && add comment form if (Config::read('comment_active', $this->module) == 1 && $this->ACL->turn(array($this->module, 'view_comments'), false) && $entity->getCommented() == 1) { if ($this->ACL->turn(array($this->module, 'add_comments'), false)) { $this->comments_form = $this->_add_comment_form($id); } $this->comments = $this->_get_comments($entity); } $tags = $entity->getTags(); if (!empty($tags)) { $this->addToPageMetaContext('tags', h($tags)); } $this->addToPageMetaContext('entity_title', h($entity->getTitle())); $this->addToPageMetaContext('category_title', h($entity->getCategory()->getTitle())); $navi = array(); $navi['module_url'] = get_url('/' . $this->module . '/'); $navi['category_url'] = get_url('/' . $this->module . '/category/' . $entity->getCategory()->getId()); $navi['category_name'] = h($entity->getCategory()->getTitle()); $navi['navigation'] = $this->_buildBreadCrumbs($entity->getCategory()->getId()); $this->_globalize($navi); $filters = $this->__getProductsFilters($entity->getCategory()->getId()); $filters .= $this->__getVendorsFilter($entity->getCategory()->getId()); $this->_globalize(array('products_filters' => $filters)); $markers = array(); $markers['moder_panel'] = $this->_getAdminBar($entity); $entry_url = entryUrl($entity, $this->module); $markers['entry_url'] = $entry_url; $markers['main_text'] = $this->Textarier->parseBBCodes($entity->getDescription(), $entity); $entity->setAdd_markers($markers); $source = $this->render('material.html', array('context' => array('entity' => $entity))); return $this->_view($source); }
/** * * Validate data and create a new record into * Data Base. If an errors, redirect user to add form * and show error message where speaks as not to admit * errors in the future * */ public function add() { //turn access $this->ACL->turn(array($this->module, 'add_materials')); $errors = $this->Register['Validate']->check($this->Register['action']); $form_fields = $this->Register['Validate']->getFormFields($this->Register['action']); // Check additional fields if an exists. // This must be doing after define $error variable. if (is_object($this->AddFields)) { try { $_addFields = $this->AddFields->checkFields(); } catch (Exception $e) { $errors[] = $this->AddFields->getErrors(); } } // Если пользователь хочет посмотреть на сообщение перед отправкой if (isset($_POST['viewMessage'])) { $_SESSION['viewMessage'] = array_merge($form_fields, $_POST); redirect('/' . $this->module . '/add_form/'); } if (!empty($_POST['cats_selector'])) { $categoryModel = $this->Register['ModManager']->getModelInstance($this->module . 'Categories'); $cat = $categoryModel->getById($_POST['cats_selector']); if (empty($cat)) { $errors[] = '<li>' . __('Can not find category') . '</li>' . "\n"; } } // Errors if (!empty($errors)) { $_SESSION['FpsForm'] = array_merge($form_fields, $_POST); $_SESSION['FpsForm']['errors'] = $errors; redirect('/' . $this->module . '/add_form/'); } // Защита от того, чтобы один пользователь не добавил // 100 материалов за одну минуту if (isset($_SESSION['unix_last_post']) and time() - $_SESSION['unix_last_post'] < 10) { return $this->showInfoMessage(__('Your message has been added'), '/' . $this->module . '/'); } //remove cache $this->Register['Cache']->clean(CACHE_MATCHING_ANY_TAG, array('module_' . $this->module)); $this->DB->cleanSqlCache(); $post = $this->Register['Validate']->getAndMergeFormPost($this->Register['action'], array(), true); extract($post); // Auto tags generation if (empty($tags)) { $TagGen = new MetaTags(); $tags = $TagGen->getTags($_POST['main_text']); $tags = !empty($tags) && is_array($tags) ? implode(',', array_keys($tags)) : ''; } // Обрезаем переменные до длины, указанной в параметре maxlength тега input $commented = !empty($_POST['commented']) ? 1 : 0; $available = !empty($_POST['available']) ? 1 : 0; if (!$this->ACL->turn(array($this->module, 'record_comments_management'), false)) { $commented = '1'; } if (!$this->ACL->turn(array($this->module, 'hide_material'), false)) { $available = '1'; } $max_lenght = $this->Register['Config']->read('max_lenght', $this->module); $add = mb_substr($main_text, 0, $max_lenght); $res = array('title' => $title, 'main' => $add, 'date' => new Expr('NOW()'), 'author_id' => $_SESSION['user']['id'], 'category_id' => $cats_selector, 'description' => $description, 'tags' => $tags, 'sourse' => $sourse, 'sourse_email' => $sourse_email, 'sourse_site' => $sourse_site, 'commented' => $commented, 'available' => $available, 'view_on_home' => $cat->getView_on_home(), 'premoder' => 'confirmed'); if ($this->ACL->turn(array($this->module, 'materials_require_premoder'), false)) { $res['premoder'] = 'nochecked'; } $className = ucfirst($this->module) . 'Entity'; $new = new $className($res); $last_id = $new->save(); if (is_object($this->AddFields)) { $this->AddFields->save($last_id, $_addFields); } downloadAttaches($this->module, $last_id); // hook for plugins Plugins::intercept('new_entity', array('entity' => $new, 'module' => $this->module)); //clean cache $this->Register['Cache']->clean(CACHE_MATCHING_TAG, array('module_' . $this->module)); $this->DB->cleanSqlCache(); if ($this->Log) { $this->Log->write('adding ' . $this->module, $this->module . ' id(' . $last_id . ')'); } return $this->showInfoMessage(__('Material successfully added'), '/' . $this->module . '/view/' . $last_id); }
/** * @param $params * @return void */ function callAction($params) { // if we have one argument, we get page if it exists or error if (!is_file(ROOT . '/modules/' . strtolower($params[0]) . '/index.php')) { $params = array(0 => 'pages', 1 => 'index', 2 => $params[0]); } include_once ROOT . '/modules/' . strtolower($params[0]) . '/index.php'; $module = ucfirst($params[0]) . 'Module'; if (!class_exists($module)) { $this->Register['DocParser']->showHttpError(); } // Parse two and more arguments if (count($params) > 1) { // Human Like URL if ($this->Register['Config']->read('hlu_understanding') || $this->Register['Config']->read('hlu')) { if ($params[1] !== 'view' && (empty($params[2]) || !is_numeric($params[2]))) { // Geting new HLU title if he was changed. $mat_id = $this->getNewHLUTitle($params[1], $params[0]); if ($mat_id) { // redirect to new URL (might the title was changed) redirect($params[0] . '/' . $mat_id, 301); } } } } $this->Register['dispath_params'] = $params; if (count($params) == 1) { $params[] = 'index'; } $this->module = new $module($params); // Parse second argument if (count($params) > 1) { if (preg_match('#^_+#', $params[1])) { $this->Register['DocParser']->showHttpError(); } if (!method_exists($this->module, $params[1])) { if (method_exists($this->module, $params[0] === 'forum' ? 'view_theme' : 'view')) { // geting entity ID by HLU title from URL $params[2] = $this->module->getEntryId($params[1]); $params[1] = $params[0] === 'forum' ? 'view_theme' : 'view'; } else { $this->Register['DocParser']->showHttpError(); } } } $params = Plugins::intercept('before_call_module', $params); call_user_func_array(array($this->module, $params[1]), array_slice($params, 2)); }
/** * @return string - $this->_view * * Doing search and build page with results */ public function index() { //check index $this->__checkIndex(); $minInput = $this->Register['Config']->read('min_lenght', $this->module); if (!empty($minInput)) { $this->minInputStr = (int) $minInput; } $html = null; $error = null; $results = null; if (isset($_POST['m'])) { $modules = array(); foreach ($_POST['m'] as $m) { if ($m == 'forum' or $m == 'news' or $m == 'stat' or $m == 'loads') { Array_push($modules, $m); } } } else { $modules = array('forum', 'news', 'stat', 'loads'); } $_SESSION['m'] = $modules; if (isset($_POST['search']) || isset($_GET['search'])) { $str = isset($_POST['search']) ? h($_POST['search']) : ''; if (empty($str)) { $str = isset($_GET['search']) ? h($_GET['search']) : ''; } if (!is_string($str)) { $str = (string) $str; } $str = trim($str); if (empty($str) || mb_strlen($str) < $this->minInputStr) { $error = $error . '<li>' . sprintf(__('Very small query'), $this->minInputStr) . '</li>'; } if ($this->cached) { $this->cacheKey .= '_' . md5($str); if ($this->Cache->check($this->cacheKey)) { $html = $this->Cache->read($this->cacheKey); return $this->_view($html); } } $_SESSION['search_query'] = $str; if (!empty($error)) { $_SESSION['FpsForm'] = array(); $_SESSION['FpsForm']['errors'] = $error; redirect($this->getModuleURL()); } $str = Plugins::intercept('before_search', $str); $results = $this->__search($str, $modules); $results = Plugins::intercept('search_results', $results); if (count($results) && is_array($results)) { foreach ($results as $result) { if (preg_match('#(.{0,100}' . $str . '.{0,100})#miu', $result->getIndex(), $match)) { $announce = $match[1]; } else { $announce = mb_substr($result->getIndex(), 0, 150); } $title = h($result->getEntity_title()); $announce = str_replace($str, '<strong>' . $str . '</strong>', h($announce)); $entry_url = get_url('/' . $result->getModule() . $result->getEntity_view() . $result->getEntity_id()); $result->setEntry_url($entry_url); $result->setTitle($title); $result->setAnnounce($announce); } } else { $error = __('No results'); // TODO } } else { $_SESSION['search_query'] = ''; } // Nav block $nav = array(); $nav['navigation'] = get_link(__('Home'), '/') . __('Separator') . $this->module_title; $this->_globalize($nav); if (!empty($str)) { $this->addToPageMetaContext('entity_title', $str); } $this->returnForm = false; $form = $this->form(); $source = $this->render('search_list.html', array('context' => array('results' => $results, 'form' => $form, 'error' => $error))); //write into cache if ($this->cached && !empty($str)) { //set users_id that are on this page $this->setCacheTag(array('search_str_' . $str)); $this->cacheKey .= '_' . md5($str); $this->Cache->write($source, $this->cacheKey, $this->cacheTags); } return $this->_view($source); }
redirect('/' . $this->module); } $commModel = $this->Register['ModManager']->getModelInstance('Comments'); $comment = $commModel->getById($id); if (!$comment) { return $this->showInfoMessage(__('Comment not found'), '/' . $this->module . '/'); } // Categories tree $this->Model->bindModel('category'); $entity = $this->Model->getById($comment->getEntity_id()); if ($entity && $entity->getCategory_id()) { $this->categories = $this->_getCatsTree($entity->getCategory_id()); } else { $this->categories = $this->_getCatsTree(); } Plugins::intercept('view_category', $entity->getCategory()); $markers = array(); $markers['disabled'] = $comment->getUser_id() ? ' disabled="disabled"' : ''; // Если при заполнении формы были допущены ошибки if (isset($_SESSION['FpsForm'])) { $errors = $_SESSION['FpsForm']['errors']; $message = $_SESSION['FpsForm']['message']; $name = $_SESSION['FpsForm']['name']; unset($_SESSION['FpsForm']); } else { $errors = ''; $message = $comment->getMessage(); $name = $comment->getName(); } $markers['action'] = get_url('/' . $this->module . '/update_comment/' . $id); $markers['errors'] = $errors;
/** * * Validate data and create a new record into * Data Base. If an errors, redirect user to add form * and show error message where speaks as not to admit * errors in the future * * @return none; */ public function add() { //turn access $this->ACL->turn(array($this->module, 'add_materials')); $errors = $this->Register['Validate']->check($this->Register['action']); // Check additional fields if an exists. // This must be doing after define $error variable. if (is_object($this->AddFields)) { try { $_addFields = $this->AddFields->checkFields(); } catch (Exception $e) { $errors[] = $this->AddFields->getErrors(); } } $fields = array('description', 'tags', 'sourse', 'sourse_email', 'sourse_site', 'download_url', 'download_url_size'); $fields_settings = $this->Register['Config']->read('fields', $this->module); foreach ($fields as $field) { if (empty($_POST[$field]) && in_array($field, $fields_settings)) { ${$field} = null; } else { ${$field} = trim($_POST[$field]); } } // Обрезаем переменные до длины, указанной в параметре maxlength тега input $title = mb_substr(trim($_POST['title']), 0, 128); $addLoad = trim($_POST['mainText']); $title = trim($title); $in_cat = intval($_POST['cats_selector']); $commented = !empty($_POST['commented']) ? 1 : 0; $available = !empty($_POST['available']) ? 1 : 0; if (!$this->ACL->turn(array($this->module, 'record_comments_management'), false)) { $commented = '1'; } if (!$this->ACL->turn(array($this->module, 'hide_material'), false)) { $available = '1'; } // Preview if (isset($_POST['viewMessage'])) { $_SESSION['viewMessage'] = array_merge(array('title' => null, 'mainText' => null, 'in_cat' => $in_cat, 'description' => null, 'tags' => null, 'sourse' => null, 'sourse_email' => null, 'sourse_site' => null, 'download_url' => null, 'download_url_size' => null, 'commented' => null, 'available' => null), $_POST); redirect('/' . $this->module . '/add_form/'); } $sectionModel = $this->Register['ModManager']->getModelInstance($this->module . 'Categories'); $section = $sectionModel->getById($in_cat); if (!$section) { $errors[] = __('Can not find category'); } // Errors if (!empty($errors)) { $_SESSION['FpsForm'] = array_merge(array('title' => null, 'mainText' => null, 'in_cat' => $in_cat, 'description' => null, 'tags' => null, 'sourse' => null, 'sourse_email' => null, 'sourse_site' => null, 'download_url' => null, 'download_url_size' => null, 'commented' => null, 'available' => null), $_POST); $_SESSION['FpsForm']['errors'] = $errors; redirect('/' . $this->module . '/add_form/'); } //Проверяем прикрепленный файл... $file = ''; if (!empty($_FILES['attach_file']['name'])) { $file = $this->__saveFile($_FILES['attach_file']); } // span protected if (isset($_SESSION['unix_last_post']) and time() - $_SESSION['unix_last_post'] < 30) { return $this->showInfoMessage(__('Your message has been added'), '/' . $this->module . '/'); } // Auto tags generation if (empty($tags)) { $TagGen = new MetaTags(); $tags = $TagGen->getTags($addLoad); $tags = !empty($tags) && is_array($tags) ? implode(',', array_keys($tags)) : ''; } // Формируем SQL-запрос на добавление темы $max_lenght = Config::read('max_lenght', $this->module); $addLoad = mb_substr($addLoad, 0, $max_lenght); $data = array('title' => $title, 'main' => $addLoad, 'date' => new Expr('NOW()'), 'author_id' => $_SESSION['user']['id'], 'category_id' => $in_cat, 'download' => $file, 'description' => $description, 'tags' => $tags, 'sourse' => $sourse, 'sourse_email' => $sourse_email, 'sourse_site' => $sourse_site, 'download_url' => $download_url, 'download_url_size' => (int) $download_url_size, 'commented' => $commented, 'available' => $available, 'view_on_home' => $section->getView_on_home()); $entity = new LoadsEntity($data); $last_id = $entity->save(); // Get last insert ID and save additional fields if an exists and activated. // This must be doing only after save main(parent) material if (is_object($this->AddFields)) { $this->AddFields->save($last_id, $_addFields); } downloadAttaches($this->module, $last_id); // hook for plugins Plugins::intercept('new_entity', array('entity' => $entity, 'module' => $this->module)); //clear cache $this->Cache->clean(CACHE_MATCHING_ANY_TAG, array('module_' . $this->module)); $this->DB->cleanSqlCache(); if ($this->Log) { $this->Log->write('adding ' . $this->module, $this->module . ' id(' . $last_id . ')'); } return $this->showInfoMessage(__('Material successfully added'), '/' . $this->module . '/'); }
| @copyright ©Andrey Brykin 2010-2012 | | @last mod. 2012/04/29 | \-----------------------------------------------*/ /*-----------------------------------------------\ | | | any partial or not partial extension | | CMS AtomX,without the consent of the | | author, is illegal | |------------------------------------------------| | Любое распространение | | CMS AtomX или ее частей, | | без согласия автора, является не законным | \-----------------------------------------------*/ header('Content-Type: text/html; charset=utf-8'); if (file_exists('install')) { include_once 'sys/settings/config.php'; if (!empty($set) && !empty($set['db']['name']) && (!empty($set['db']['user']) || !empty($set['db']['pass']))) { die('Before use your site, delete INSTALL dir! <br />Перед использованием удалите папку INSTALL'); } header('Location: install'); die; } include_once 'sys/boot.php'; Plugins::intercept('before_pather', array()); /** * Parser URL * Get params from URL and launch needed module and action */ new Pather($Register); Plugins::intercept('after_pather', array()); //pr($Register);