function run() { /**@var tf_sat $sat */ $sat = core::module('sat'); $site = $sat->get_current_site(); $json_file = loader::get_public('assets/' . $site->domain . '.json'); $last_mod = @filemtime($json_file); $tree_last_mod = 0; if ($last_mod) { $last_node = $sat->get_node_handle()->set_where('site_id = %d', $sat->get_current_site_id())->set_order('updated_at DESC')->load_first(); $tree_last_mod = $last_node ? $last_node->updated_at : 0; core::dprint(__METHOD__ . ': cached'); // uptodate if ($tree_last_mod <= $last_mod) { $this->renderer->set_ajax_answer(file_get_contents($json_file))->ajax_flush(); return; } } core::dprint(__METHOD__ . ': fetch!'); $tree = $sat->get_current_site_tree(); $allowedKeys = array('title', 'url'); array_walk($tree, function (&$v) use($allowedKeys) { $v = array_intersect_key($v, array_flip($allowedKeys)); }); $tree = array_values($tree); // cache file_put_contents($json_file, functions::json_encode($tree)); $this->renderer->set_ajax_answer($tree)->ajax_flush(); }
/** @return anket_result_option_collection */ function get_result_options() { if (!isset($this->_result_options)) { $this->_result_options = core::module('anket')->get_result_option_handle()->set_where('pid = %d', $this->id)->load(); } return $this->_result_options; }
function get_anket_result() { if (!isset($this->_anket_result) && core::modules()->is_registered('anket')) { $this->_anket_result = core::module('anket')->get_managed_item('anket_result', $this->result_id, array('with_module_prefix' => 1)); } return $this->_anket_result; }
/** @return anket_answer_collection */ function get_answers() { if (!isset($this->_answers)) { $this->_answers = core::module('anket')->get_answer_handle()->set_where('pid = %d', $this->id)->load(); } return $this->_answers; }
function get_widgets() { if (!isset($this->_widgets)) { $this->_widgets = core::module('sat')->get_widget_handle()->set_where('pid = %d', $this->id)->load(); } return $this->_widgets; }
function get_childrens() { if (!isset($this->_childrens)) { $this->_childrens = core::module('sat')->get_menu_handle()->set_where('pid = %d', $this->id)->load(); } return $this->_childrens; }
function run() { $site_id = core::module('sat')->get_current_site_id(); $page = ($pf = $this->_controller->get_router()->get_filter('pagination')) ? $pf->get_start() : 0; /** @var \tf\core\collection_filter*/ $f = $this->_controller->get_context()->get_qa_question_handle()->get_filter('/contacts/qa/')->set_config(array('where_sql' => "site_id = {$site_id} AND active"))->set_per_page($this->_per_page)->set_pagination($page); $this->renderer->set_return('posts', $f->apply()->as_array()); }
private function create_objects($classes) { $this->_objects = array(); foreach ($classes as $class) { list($module, $class) = explode('/', $class); $this->_objects["{$module}_{$class}"] = core::module($module)->class_register($class, array('no_preload' => true)); } }
function get_fields($parent = null) { if (!isset($this->_fields)) { $this->_fields = core::module('extrafs')->get_field_handle()->set_where('gid = %d', $this->id)->set_parent($parent ? $parent : $this->get_container()->get_parent())->load(); foreach ($this->_fields as $f) { $f->set_group($this); } } return $this->_fields; }
/** * Similar posts * @param array (site_id, pid, count) */ function qa($params = null) { // 'pid' => int 558 $site_id = core::module('sat')->get_current_site_id(); $count = isset($params->count) ? $params->count : 5; $ctx = $this->get_context(); $posts = $ctx->get_qa_question_handle(); $posts->set_limit($count)->set_where('site_id = %d AND active', $site_id)->load(); return $posts ? $posts->render() : false; }
private function create_objects($classes) { $this->_objects = array(); if (!empty($classes)) { foreach ($classes as $class) { list($module, $class) = explode('.', $class); $this->_objects["{$module}_{$class}"] = core::module($module)->model($class); core::dprint(array("[GENERATOR] Add %s", "{$module}_{$class}"), core::E_MESSAGE); } } }
/** * Get handle for this content type * * Calls to module::get_{ctype}_handle() * Warn! Handle are cached/cleaned * * @return IAbs_Collection handle */ function get_handle() { if (!empty($this->_handle)) { $this->_handle->clear(); } else { $module = core::module($this->module); $method = 'get_' . $this->name . 's_handle'; $this->_handle = call_user_func(array($module, $method)); } return $this->_handle; }
/** * get values for mapped parent * @return extrafs_value_collection */ function get_field_values() { if (!isset($this->_extra_fs_values_collection)) { // fetch values for current parent *pid* $this->_extra_fs_values_collection = core::module('extrafs')->get_value_handle()->set_where('pid = %d AND ctype_id = %d', $this->_parent->get_id(), $this->_parent->get_ctype_id())->load(); } foreach ($this as $v) { $v->get_field_value(); } return $this->_extra_fs_values_collection; }
function run() { $posts = core::module('sat')->get_news_handle()->set_order('created_at DESC')->set_limit(10)->where('active', true)->with_deps(array('category'))->load()->render(); $parser = tpl_loader::get_parser(true); $parser->assign('site', core::module('sat')->get_current_site()->render()); $parser->assign('posts', $posts); header('Content-Type: text/xml; charset=UTF-8'); // display appends smarty_debug echo $parser->fetch('partials/sat/news/xml.tpl'); core::selfie()->halt(); }
/** * @param int $id */ function sync_children($id = 0) { // sqlite: UPDATE sat_sat_news_category SET c_count = (SELECT COUNT(*) FROM sat_sat_news p2 WHERE p2.pid = sat_sat_news_category.id) $collection = core::module('sat')->model($this->child_model); if (!$collection) { throw new collection_exception('Bad model in category: ' . $this->child_model); } $table = $this->get_table(); $table_model = $collection->get_table(); $sql = "UPDATE {$table} SET c_count = (SELECT COUNT(*) FROM {$table_model} p2 WHERE p2.pid = {$table}.id)"; if ($id) { $sql .= " WHERE id = {$id}"; } $this->db->query($sql); }
function run($file) { if (empty($file) || !file_exists($file)) { throw new tf_exception('Empty file'); } $response = file_get_contents($file); $xmldoc = new SimpleXMLElement($response); $this->module = core::module('sat'); $this->collection = $this->module->get_node_handle(); $this->collection->remove_all_fast(); foreach ($xmldoc->node as $node) { $this->import_node($node); } $this->collection->sync_children_count(); }
/** * Log action * * @param mixed $action * @param mixed $data * @param mixed $comment maybe array for vsprintf(1,...) */ function log($action, $data, $comment = '') { $plogs = core::module('moswar')->get_logs_handle(); $data['pid'] = $this->_acc->id; $data['action'] = $action; if (is_array($comment)) { $comment = vsprintf(array_shift($comment), $comment); } $data['comment'] = $comment; if (!empty($this->_log_comment)) { $data['comment'] .= " " . $this->_log_comment; } $plogs->create($data); core::dprint(array('[MW_LOG] %s : %s (gold=%d, ore=%d, xp=%d) %s', $action, $data['result'] ? 'OK' : 'FAIL', @$data['gold'], @$data['ore'], @$data['xp'], $data['comment'])); $this->_log_comment = ''; }
function update_stats() { // cache for minute if (time() < $this->updtime + 60) { return; } if (!$this->_parent || $this->_parent->id != $this->pid) { $this->_parent = core::module('moswar')->get_accounts_handle()->set_where('id = %d', $this->pid)->set_limit(1)->load()->get_item(); } $mwlib = core::module('moswar')->get_moswar_lib($this->_parent); $data = $mwlib->get_player_info_indirect($this->c_id); foreach ($data as $k => $v) { $this->set_data($k, $v); } $this->set_data('updtime', time()); $this->save(); }
function create_anket_result($id, $_post) { /** @var anket_form_item */ $form = core::module('anket')->get_form_handle()->set_where('id = "%d"', $id)->set_limit(1)->load()->get_item(); if (!$form) { throw new collection_exception('Bad form id'); } /** @var anket_result_collection */ $pres = core::module('anket')->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->set_notify_user(false)->create($_post); return ($item = $pres->get_last_item()) ? $item : false; }
/** * Make search */ public function make_search($key) { $id = false; $psearchs = $this->_controller->get_context()->get_search_handle(); $psearch_results = $this->_controller->get_context()->get_search_result_handle(); $core = core::get_instance(); $site_id = $this->_controller->get_context()->get_current_site_id(); // check key exists if ($search_item = $psearchs->get_by_key($key, $site_id)) { $id = $search_item->id; $this->_found = $search_item->c_count; } // if too old, clean search results, make it new if ($search_item) { if ($search_item->time + $this->_expire_time < time()) { // clear $search_item->remove(); $search_item = null; } } if (!$search_item) { $this->_found = 0; $cdata = core::module('sat')->get_node_handle(); $orig_key = $key; # remove this for non test # $key = strings::convert_from($key); $key = core::lib('db')->escape(strings::strtolower($key)); $cdata->set_where("site_id = {$site_id} AND active AND LCASE(title) LIKE '%{$key}%'")->load(); $result = array(); $ctype = $core->get_ctype('sat.node')->get_id(); $this->_found = $cdata->count(); if (!$cdata->is_empty()) { foreach ($cdata as $item) { $result[] = array('title' => $item->title, 'description' => strip_tags($item->description), 'time' => $item->updated_at, 'url' => $item->get_url(), 'ctype' => $ctype, 'post_id' => $item->id); } } // create search history item $id = $psearchs->create(array('uid' => $this->_controller->get_user()->id, 'keyword' => $key, 'c_count' => $this->_found, 'site_id' => $site_id)); // fill results foreach ($result as $v) { $v['pid'] = $id; $psearch_results->create($v); } } return $id; }
function run() { //if (loader::in_ajax() !== true && !core::is_debug()) die('juststopped'); if ($this->request->post('form_submit') == 'yes') { $_post = $this->request->get_post(); $pres = $this->_controller->get_context()->get_qa_question_handle(); /** @var tf_auth */ $auth = core::lib('auth'); $_post['session_id'] = $auth->get_current_session()->get_id(); $_post['site_id'] = core::module('sat')->get_current_site_id(); $_post['active'] = false; if ($auth->get_user()->level >= 50) { $_post['active'] = true; } $aid = $pres->create($_post); $this->renderer->set_ajax_message('Обработка запроса')->set_ajax_result((bool) $aid)->set_ajax_data($aid ? $pres->get_last_item()->render() : false)->ajax_flush(false); } }
/** * Called from module::on_editor * @throws acl_exception */ function on_editor($mod) { $this->module = $mod; $section = core::get_params('c'); $id = (int) core::get_params('id'); // module checks goes on top, so skip if section empty if (empty($section)) { return; } if (!core::module('users')->with_acls()) { return; } // override section acl / id if (isset($this->_actions[$section]['acl_id'])) { $id = core::get_params($this->_actions[$section]['acl_id']); } if (isset($this->_actions[$section]['acl'])) { $section = $this->_actions[$section]['acl']; } $op = 'read'; // @todo check this $is_submitted = (bool) $this->request->get_post('is_submitted', 0); $_op = core::get_params('op'); if ($_op == 'edit') { $op = 'update'; } if ($_op == 'drop') { $op = 'delete'; } if (empty($id) && $is_submitted) { $op = 'create'; } if (!empty($id) && $is_submitted) { $op = 'update'; } if (is_callable(array($mod, 'editor_check_acls'))) { $result = call_user_func(array($mod, 'editor_check_acls'), array('section' => &$section, 'section_id' => &$id, 'action' => &$op)); // WARN! true skips checks if ($result === true) { return; } } $this->check_acls($section, $id, $op); }
* @package TwoFace * @author Golovkin Vladimir <*****@*****.**> http://www.skillz.ru * @copyright SurSoft (C) 2008 * @version $Id: mod.php,v 1.2 2008/05/23 15:02:37 surg30n Exp $ */ if (!defined('IN_MAIN')) { die; } $user = $this->get_user(); if ($user->level < $user->get_container()->get_level_by_name('mod')) { core::get_instance()->set_raw_message('restricted'); $this->set_null_template(); return false; } /* Вывод Очищаем и перезагружаем! */ $posts_base_url = $this->get_context()->get_cp_links('post'); $this->get_context()->set_cp_data('posts_base_url', $posts_base_url['url']); $cdata = core::module('content')->get_posts_handle(); $base_url = $this->get_context()->get_cp_links('mod'); $base_url = $base_url['url']; $page = $this->get_context()->get_core()->pagination(); $cdata->with_comments(false); $cdata->with_deps(false); $cdata_filter = new collection_filter($cdata, $base_url); //$cdata_filter->set_filter('b_approved', false); $cdata->set_order('b_approved ASC, date_mod DESC'); $cdata_filter->set_pagination($page, 50); $data = $cdata_filter->apply(); core::lib('renderer')->set_posts($data);
/** * Get managed model item * @return abs_collection_item */ public function get_managed_item($model, $id) { // check if model prefixed if (strpos($model, '.') !== false) { $_model = explode('.', $model); if ($_model[0] !== $this->get_name()) { return core::module($_model[0])->get_managed_item($_model[1], $id); } $model = $_model[1]; } // prefix module.model $_model = 'model.' . $this->get_name() . '.' . $model; $item = $this->manager->get($model, $id); if ($item === null) { $item = $this->model($model)->load_only_id($id); $this->manager->set($_model, $id, $item); } return $item; }
<?php require "../loader.php"; $i = core::module('sat')->get_node_image_handle(); $i->create(array('file' => array('size' => 1, 'name' => '518.jpg', 'tmp_name' => 'E:/tmp/auto/logan/export/img/518.jpg'))); $item = $i->get_last_item(); var_dump($item->render());
$core = core::get_instance(); $core->lib('logger')->log('SMS Payment', print_r($_GET, 1)); $smskey = $core->get_cfg_var('sms_seckey', ''); core::lib('renderer')->set_content_type('text/plain'); $smsid = functions::request_var('smsid', ''); $num = functions::request_var('num', ''); $operator = functions::request_var('operator', ''); $userid = functions::request_var('user_id', ''); $cost = functions::request_var('cost', ''); $msg = functions::request_var('msg', ''); $skey = functions::request_var('skey', ''); list($prefix, $msg) = explode(' ', $msg); if ($skey != md5($smskey)) { header("HTTP/1.0 404 Not Found"); echo "Error! invalid sek key"; die; } $user = trim($msg); $user = core::module('users')->get_user($user, 'login'); if ($user->is_anonymous()) { header("HTTP/1.0 404 Not Found"); echo "Error! invalid login"; die; } echo "smsid:{$smsid}\n"; echo "status:reply\n"; echo "content-type:text/plain\n\n"; $pay_for = $core->get_cfg_var('sms_payd_period', '30'); $user->pay_for($pay_for, $cost); echo sprintf("User %s successfuly payd for %s days.", $user->login, $pay_for); die;
<?php require "loader.php"; core::module('users')->clean_sessions();
function load_acls() { $this->_acls = core::module('users')->get_acl_handle()->load_for_group($this->id); return $this->_acls; }
/** * Make url */ function make_urls() { $url = core::module('sat')->get_router()->make_url('/' . $this->container->child_model . '/' . $this->slug . '/'); $this->append_urls('self', $url); }
/** * Text * @return text */ function text($params = false) { if (empty($params->id)) { return false; } $cdata = $this->get_context()->get_text($params->id, core::module('sat')->get_current_site()->id); return $cdata ? $cdata->text : "%{$params->id}%"; }