Ejemplo n.º 1
0
 function run()
 {
     $q = $this->get_param('query');
     if (empty($q)) {
         $q = functions::request_var('keyword');
     }
     if (loader::in_ajax()) {
         $keyword = trim($q);
     } else {
         $keyword = trim(urldecode($q));
     }
     $this->renderer->set_return('keyword', $keyword);
     $this->renderer->set_main_title('search');
     if (empty($q)) {
         return;
     }
     if (strings::strlen($keyword) < 3) {
         $this->renderer->set_message('sat.search_too_short', array('result' => false));
         $this->renderer->set_ajax_message('sat.search_too_short');
         return false;
     }
     // make search and redirect to it
     $id = $this->make_search($keyword);
     // redirect to search results
     $url = $this->_controller->get_context()->get_router()->make_url('/search/' . $id . '/');
     if (loader::in_ajax()) {
         $this->_controller->set_null_template();
         $this->renderer->set_ajax_message($this->_found ? sprintf('По вашему запросу найдено %d записей', $this->_found) : 'Подходящих записей не найдено')->set_ajax_result($this->_found)->set_ajax_redirect($url);
     } else {
         functions::redirect($url);
         core::get_instance()->halt();
     }
 }
Ejemplo n.º 2
0
 function action_index()
 {
     if (!loader::in_ajax()) {
         throw new editor_exception('Not allowed ' . __METHOD__);
     }
     $this->set_layout('embed');
     $this->set_template('partials/index');
     //dd(__METHOD__);
 }
Ejemplo n.º 3
0
 /**
  * Remember!
  * Assign current item in controller for comment linking!
  */
 function run()
 {
     if (loader::in_ajax() !== true) {
         throw new controller_exception('Cant touch this ' . __METHOD__);
         return false;
     }
     core::dprint('run comment modify');
     $pctl = core::modules()->get_router()->get_controller();
     $user = core::lib('auth')->get_user();
     /**
      * Parent item, must be assigned thru @see module_controller::set_current_item()
      * @var abs_collection_item
      */
     $post = $pctl->get_current_item();
     // var_dump(get_class($post), core::get_modules()->get_router()->get_name());
     if (!$post) {
         throw new controller_exception('No item assigned');
     }
     if (!$post->has_behavior('sat.commentable')) {
         throw new controller_exception('Not commentable');
     }
     $comments = $post->behavior('sat.commentable')->get_attach_model();
     //get_comments();
     $request = core::lib('request');
     $renderer = core::lib('renderer');
     $user_id = core::lib('auth')->get_user()->id;
     $pid = (int) $request->post('pid', 0);
     $limit = core::selfie()->cfg('comment_interval', 60);
     $auth = core::lib('auth');
     /** @var aregistry $sd */
     $sd = $auth->get_current_session()->get_storage();
     $time = $sd->comments_last_time;
     //$time = $comments->get_last_time($pid, $user_id);
     // disallow by interval
     if ($time && $time + $limit > time()) {
         $pctl->set_null_template();
         $renderer->set_ajax_answer(array('status' => false, 'id' => 0, 'message' => vsprintf(i18n::T('sat\\comment_interval_restriction'), $time + $limit - time())))->ajax_flush();
         // else core::get_instance()->set_message(array('content', 'comment_interval_restriction'));
         return;
         // exit
     }
     $sd->comments_last_time = time();
     $username = functions::request_var('username', '');
     $text = functions::request_var('text', '');
     $api = functions::request_var('api');
     $id = $comments->modify(array('user_ip' => core::lib('auth')->get_user_ip(true), 'user_id' => $user_id, 'ctype_id' => $post->get_ctype_id(), 'username' => $username, 'pid' => $pid, 'text' => $text, 'type' => functions::request_var('type', 0), 'tpid' => functions::request_var('tpid', 0), 'api' => $api));
     $comment = $comments->get_item_by_id($id);
     if (!$comment) {
         throw new controller_exception('[ajax] Comment create failed');
     }
     $comment->load_secondary();
     $renderer->set_data('comment', $comment->render())->set_ajax_answer(array('status' => true, 'id' => $id))->set_ajax_message(i18n::T('sat\\comment_posted'));
     //->set_main_template('content/comment/view');
     $renderer->ajax_flush('shared/comments/comment');
     // alright, update counter
     return $id;
 }
Ejemplo n.º 4
0
 /** Construct */
 public function __construct($module)
 {
     $this->response = new aregistry();
     $this->_in_ajax = loader::in_ajax();
     $this->context = $module;
     $this->request = core::lib('request');
     $this->renderer = core::lib('renderer');
     $this->params = $this->request->get_ident();
     $this->postdata = $this->request->filespost();
     $this->base_url = $this->context->get_editor_base_url();
     // action, colection_model (%module%_%action%_controller)
     // pre-init
     $this->construct_before();
     $this->init_mode();
     if ($this->with_model()) {
         /**
          * Force load deps when edit item
          */
         if ($this->mode == 'form') {
             $this->model_deps = true;
         }
         $this->collection_model = empty($this->collection_model) ? substr(substr(get_class($this), strlen($this->context->get_name()) + 1), 0, -11) : $this->collection_model;
         if (!isset($this->grid_name)) {
             $this->grid_name = 'grid-' . $this->params->m . '-' . $this->params->c;
             /*
             // @todo make grids unique ids
             if ($this->request->postget('grid')) {
              . '-' . functions::url_hash(microtime(1)); //str_replace('_', '-', $this->collection_model);
             }
             */
         }
         if ($this->collection !== false) {
             $this->collection = $this->create_collection();
         } else {
             $this->collection = abs_collection::get_null_collection();
         }
         if ($this->model_deps) {
             $this->collection->with_deps($this->model_deps);
         }
         // apply editor model style
         $this->set_collection_format($this->get_mode());
         $this->get_grid_filters();
         $this->prepare_grid_filters();
     }
     // is item submitted?
     $this->is_submited = (bool) $this->request->post(self::SUBMIT_CONTROL);
     // op=modify old compat
     if ($this->is_submited) {
         $this->params->op = 'modify';
         $this->submit_type = $this->request->post(self::SUBMIT_CONTROL);
     }
     // post-init
     $this->construct_after();
 }
Ejemplo n.º 5
0
 function action_form_do()
 {
     $aids = @$_COOKIE['anket'];
     $aids = explode(',', trim($aids));
     $aids = is_array($aids) ? $aids : array();
     $id = core::lib('db')->escape($this->get_param('id'));
     if (empty($id)) {
         throw new controller_exception('Bad form id');
     }
     // debug
     if (!core::is_debug() && in_array($id, $aids)) {
         $this->set_template('anket/form/already');
         return;
     }
     // load
     $form = $this->get_context()->get_form_handle()->set_where('name = "%s"', $id)->set_limit(1)->load()->get_item();
     if (!$form) {
         throw new router_exception('Form not found');
     }
     $this->get_renderer()->set_current('anket_form', $form->load_secondary()->render());
     if ($this->request->post('form_submit') == 'yes') {
         $_post = $this->request->get_post();
         /** @var anket_result_collection */
         $pres = $this->context->get_result_handle();
         $pres->set_current_form($form);
         $_post['results'] = !empty($_post['q']) ? serialize($_post['q']) : '';
         $_post['uip'] = core::lib('auth')->get_user_ip(1);
         // debug
         // if (loader::in_ajax() !== true) die('juststopped');
         $pres->create($_post);
         if (!in_array($id, $aids)) {
             $aids[] = $id;
         }
         setcookie('anket', join(',', $aids), time() + 31104000, '/');
         $result = ($item = $pres->get_last_item()) ? $item->render() : false;
         if (!loader::in_ajax()) {
             $this->set_template('anket/form/complete');
             // result.form, result.option
             $this->renderer->set_return($result);
         } else {
             $this->set_null_template();
             $this->renderer->set_ajax_message('Обработка запроса')->set_ajax_data($result)->set_ajax_result(true)->set_ajax_redirect('/anket/complete/');
         }
     }
 }
Ejemplo n.º 6
0
 function on_exception($message, $e = null)
 {
     if ($this->_exception) {
         return;
     }
     // triggered twice?
     $this->_exception = true;
     if (!$e) {
         $e = new Exception($message);
     }
     $this->renderer->set_data('exception', $e);
     if (loader::in_ajax()) {
         $this->renderer->set_ajax_message($e->getMessage())->set_ajax_result(false)->ajax_flush();
     } else {
         $this->renderer->set_template('error');
         // @todo вникуда: output_editor override this
     }
 }
Ejemplo n.º 7
0
 /**
  * Форма заявка (на обучение)
  */
 function action_form_do()
 {
     $form_do_once = $this->context->cfg('form_do_once', false);
     /* extract params from uri, trim form/do
           Array (2)
            type => "mini"
            lang => "ru" 
        */
     $uri = array_slice(explode('/', $this->get_context()->get_router()->get_uri()), 2);
     $cdata = array();
     if (!empty($uri)) {
         foreach ($uri as $k => $u) {
             if ($k > 0 && $k % 2 != 0) {
                 continue;
             } else {
                 if (isset($uri[$k + 1])) {
                     $cdata[$u] = $uri[$k + 1];
                 }
             }
         }
     }
     $aid = @$_COOKIE['request_form'];
     if ($form_do_once && !core::is_debug() && $aid) {
         $this->set_template('contacts/form/already');
         return;
     }
     $this->renderer->set_current('data', $cdata);
     if ($this->request->post('send')) {
         $post = $this->request->get_post();
         /** @var contacts_form_collection $pres */
         $pres = $this->context->get_form_handle();
         $post['uip'] = core::lib('auth')->get_user_ip(1);
         if (loader::in_ajax() !== true && !core::is_debug()) {
             die('juststopped');
         }
         $post['title'] = @$post['subject'];
         $pres->set_notify_template('feedback');
         $aid = $pres->create($post);
         setcookie('request_form', $aid, time() + 31104000, '/');
         $this->set_null_template();
         $this->renderer->set_ajax_message('Ваше сообщение отправлено')->set_ajax_result(true)->ajax_flush();
     }
 }
Ejemplo n.º 8
0
 /**
  * DisplayError
  */
 function display_error()
 {
     $title = $this->getMessage();
     $err_no = $this->getCode();
     // notify interactive user
     if (!class_exists('loader', 0) || class_exists('loader', 0) && !loader::in_ajax() && !($err_no == router_exception::NOT_FOUND && $this instanceof router_exception)) {
         if (!headers_sent()) {
             header('', true, 500);
         }
         $message = '<style>* {font: 0.97em verdana;} a {text-decoration:none;background:#EFEFEF;padding:4px;} a:hover{background: red;}</style><h1>Ups! We have an error here.</h1>';
         $subject = "Error " . ($this->log_id ? "#{$this->log_id}" : '') . " at " . (loader::in_shell() ? 'console' : $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
         $message .= "Please send report to <a href='mailto:" . $this->bugs_email . "?subject={$subject}'>Bugs mail</a>.<br/>";
         $message .= 'Thank you.<br/><br/>';
         $message .= 'Visit <a href="/">index</a> page.<br/><br/>';
         echo $message;
         // if debug
         if (class_exists('core', 0) && core::is_debug()) {
             echo '<br/>Error : ' . $title . ' : ' . $err_no;
             echo '<br/><br/>' . nl2br($this->getTraceAsString());
         }
     }
 }
Ejemplo n.º 9
0
} else {
    // simple loading (without extra data)
    $cdata->set_cfg_var('simple', true);
}
if ($cmd_op == 'update') {
    if ($cmd_pid) {
        $cdata->update_stats();
        $this->core->set_raw_message('Оновление статов', true);
    }
}
/*  Удаление позиции   [ajax]
*/
if ($cmd_op == 'drop') {
    $cdata->remove($cmd_id);
    // ajax
    if (loader::in_ajax()) {
        die;
    }
}
/*  Изменение (сабмит)
*/
if ($is_submited) {
    $up_var = $_POST;
    $cdata->modify($up_var, $cmd_id);
}
/*  Готовим данные для правки
*/
if ($cmd_op == 'edit' || $cmd_op == 'new') {
    $cdata->prepare2edt($cmd_id);
} else {
    /*  Вывод
Ejemplo n.º 10
0
 /**
  * Is enabled
  */
 function is_enabled()
 {
     return $this->_enabled && !loader::in_ajax() && !loader::in_shell() && core::lib('auth')->get_user()->is_anonymous();
 }
Ejemplo n.º 11
0
 /**
  * Route request
  * 
  * Warn! no exceptions
  * 
  * @return bool false if no routes found
  * @throws controller_exception, router_exception
  */
 function route($parts)
 {
     $this->_uri = implode('/', $parts);
     if (is_callable(array($this, 'route_before'))) {
         $this->route_before($parts);
     }
     core::dprint(array('[route] %s using defaut router, mod: %s', $this->_uri, $this->context->get_name()));
     // give up loading routes if set in routers class
     if (empty($this->_routes)) {
         $this->_routes = $this->load_routes();
     }
     if (empty($this->_routes)) {
         core::dprint('Empty routes in ' . get_class($this), core::E_ERROR);
         return false;
     }
     foreach ($this->_routes as $id => $route) {
         // normalize
         if (!isset($route['match']) && !isset($route['regex'])) {
             $route['match'] = $id;
         }
         if (!isset($route['action'])) {
             $route['action'] = $id;
         }
         if (!isset($route['type'])) {
             $route['type'] = 'method';
         }
         // class
         if (!isset($route['template'])) {
             $route['template'] = $id;
         }
         if ($route['action'] instanceof Closure) {
             $route['type'] = 'inline';
         }
         if ($route['type'] == 'method') {
             $route['action'] = str_replace('/', '_', $route['action']);
         }
         // append section to match if any
         // if (isset($route['section']) && !empty($route['match']))    $route['match']     = $route['section'] . '/' . $route['match'];
         $this->_filters = array();
         $back_uri = $this->_uri;
         // match filters
         // all filters created before dispatch!
         $this->match_filters($route);
         // route
         $params = null;
         if ($this->_debug) {
             core::dprint('.. route ' . $id);
             core::dprint_r($route);
         }
         if ($this->_is_route_matched($route, $params)) {
             // pure ajax routes
             if (isset($route['ajax']) && true !== loader::in_ajax()) {
                 throw new router_exception('Invalid query. Code.A6299');
             }
             if (isset($route['auth']['level'])) {
                 if ($route['auth']['level'] > core::lib('auth')->get_user()->level) {
                     throw new router_exception('Access denied. Code.A6298');
                 }
             }
             core::dprint(array('Route matched "%s"', $id));
             $this->_route = $route;
             $this->context->get_controller()->run($route, $params);
             $this->run_filters();
             return true;
         }
         // restore uri, loop again?
         $this->_uri = $back_uri;
     }
     return false;
 }
Ejemplo n.º 12
0
 /**
     кэш только для основного домена.
     на алиасах не работает! 
 */
 function init91()
 {
     if (core::in_editor() || loader::in_ajax() || loader::in_shell()) {
         return;
     }
     // @todo cancel on errors!
     if (tf_exception::get_last_exception()) {
         return;
     }
     // check current site
     if (!($tsite = $this->get_current_site()) || !$tsite->is_staticable()) {
         return;
     }
     /* save static cache!
           skip logged in users, debug mode
        */
     if ($this->get_core()->cfg('sat_use_static') && !core::lib('auth')->logged_in() && !core::is_debug()) {
         $file = $this->get_static_node_path($tnode = $this->get_router()->get_current_node());
         $pagination_filter = $this->get_router()->get_filter('pagination');
         if ($pagination_filter && ($page = $pagination_filter->get_start())) {
             $file = str_replace('/index.html', "/page/{$page}/index.html", $file);
         }
         core::dprint(array('generate staic : %s', $file), core::E_DEBUG4);
         if (!file_exists($file)) {
             $dir = dirname($file);
             if (!is_dir($dir)) {
                 mkdir($dir, 0777, true);
             }
             file_put_contents($file, core::lib('renderer')->get_buffer());
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * @param $msg
  * @param int $code
  * @return $this
  */
 function error($msg, $code = 500)
 {
     @header(' ', true, $code);
     $error = i18n::T('errors.' . $code);
     $template = loader::in_ajax() ? 'partials/error' : 'error';
     $this->renderer->set_page_title($error)->set_return('error', array('message' => $error, 'code' => $code))->set_return('message', $msg)->set_main_template($template);
     $this->renderer->output();
     $this->halt();
 }
Ejemplo n.º 14
0
 /**
  * Cp action
  */
 function cp_profile()
 {
     $post = core::lib('request')->get_post();
     // change nick, email, gender, password
     if ('update_profile' == core::get_params('op')) {
         $error = false;
         try {
             $this->get_context()->update_user_profile($post);
         } catch (validator_exception $e) {
             $error = $e->getMessage();
             $error = $this->get_context()->translate($error);
         }
         $message = $error !== false ? $error : $this->get_context()->translate('profile_update_ok');
         if (loader::in_ajax()) {
             $this->set_null_template();
             core::lib('renderer')->set_ajax_answer(array('status' => false === $error, 'message' => $message));
         } else {
             $core = core::get_instance();
             $core->set_raw_message($message);
             $core->set_message_data(false, false !== $error);
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * var dump
  */
 public static function var_dump()
 {
     // silent in ajax
     if (loader::in_ajax() || !core::debug_level()) {
         return;
     }
     $console = self::lib('console');
     $dbg_info = '';
     // if no console, trace not available
     if ($console) {
         $dbg_trace = $console->debug_backtrace_smart();
         if (isset($dbg_trace[1]) && !isset($dbg_trace[1]['class'])) {
             $dbg_trace[1]['class'] = '';
         }
         $dbg_info = $dbg_trace[0]['file'] . ' in ' . $dbg_trace[0]['line'] . (!isset($dbg_trace[1]) ? '' : " ({$dbg_trace[1]['class']}::{$dbg_trace[1]['function']}) ");
     }
     $count = func_num_args();
     if (empty($count)) {
         return false;
     }
     $args = func_get_args();
     $i = 0;
     foreach ($args as $p) {
         $i++;
         echo "<code style='color:blue'>VARDUMP #{$i} {$dbg_info}</code>";
         var_dump($p);
     }
 }
Ejemplo n.º 16
0
 /**
  * Final output     
  * called from @see core::shutdown
  */
 public function output()
 {
     if (loader::in_ajax()) {
         return $this->output_ajax();
     }
     /** give up if in crontab */
     if (loader::in_shell()) {
         return false;
     }
     $core = core::get_instance();
     core::dprint('renderer::ouput', core::E_DEBUG0);
     $this->content_type_header();
     // disabled
     if ($this->_disable_output) {
         return false;
     }
     $cfg_data = array();
     // initial
     $this->output_begin();
     if (core::in_editor()) {
         $this->output_editor();
     }
     $tpl = $this->page_template;
     // check message
     if ($msg = $core->get_message()) {
         $this->render_message($msg, $core->get_message_data());
     } elseif (!empty($this->_message)) {
         $this->render_message($this->_message['message'], @$this->_message['data']);
     }
     // no template
     if (empty($tpl)) {
         core::dprint('render with empty page template assigned');
         //throw new renderer_exception('render with empty page template assigned');
     }
     /*
         Throwing exception here 
         Will result in 
         Fatal error: Exception thrown without a stack frame in Unknown on line 0
     */
     if (false == $this->get_main_template()) {
         core::dprint('render with empty main template assigned');
         // throw new renderer_exception('render with empty main template assigned');
     }
     $this->output_end($tpl);
 }