/** * * @param type $query * @param type $tpl * @param type $class */ public static function tpl($query = 'showposts=8', $tpl = 'masonry-grid', $id = "masonry") { //echo '<div id="masonry">'; $_query = new WP_Query($query); if ($_query->have_posts()) { while ($_query->have_posts()) { $_query->the_post(); core_module::tpl($tpl, 'masonry'); } } else { core_mods::modules('sample', 'masonry'); } wp_reset_postdata(); //echo '</div>'; }
public static function tpl($query = 'showposts=3', $data = array('class' => 'flexslider'), $tpl = "flex-slider-index") { ?> <div class="flexslider-container"> <div class="flexslider"> <ul class="slides"> <?php $fx_query = new WP_Query($query); if ($fx_query->have_posts()) { while ($fx_query->have_posts()) { $fx_query->the_post(); core_module::tpl($tpl, 'flex-slider', $data); } } wp_reset_query(); ?> </ul> </div> </div> <?php }
public static function related($tpl = 'related') { global $post; // Reference : http://codex.wordpress.org/Function_Reference/wp_get_post_tags // we are using this function to get an array of tags assigned to current post $tags = wp_get_post_tags($post->ID); if ($tags) { $first_tag = $tags[0]->term_id; // we only need the id of first tag // arguments for query_posts : http://codex.wordpress.org/Function_Reference/query_posts $args = array('tag__in' => array($first_tag), 'post__not_in' => array($post->ID), 'showposts' => 4, 'ignore_sticky_posts' => 1); // WP_Query takes the same arguments as query_posts $related_query = new WP_Query($args); if ($related_query->have_posts()) { core_module::tpl(); wp_reset_query(); // to reset the loop : http://codex.wordpress.org/Function_Reference/wp_reset_query } } else { echo "Sorry there are no Related Post"; } }
/** * Завершающий init 9 */ public function init9() { core::dprint('[users/shutdown]'); return parent::init9(); }
/** * editor entry */ function on_editor() { // assign core::lib('editor')->assign_module_menu(array('users' => array('url' => '?m=users&c=users', 'title' => $this->translate('users')), 'bans' => array('url' => '?m=users&c=bans', 'title' => $this->translate('bans')), 'sessions' => array('url' => '?m=users&c=sessions', 'title' => $this->translate('sessions')))); return parent::on_editor(); }
/** * 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; }
function __construct() { parent::__construct(); $this->msg = new msg(); $this->users = new users(); }
/** @return abs_collection */ protected function create_collection() { return $this->context->model($this->collection_model, $this->collection_config); }
/** * INIT0 - call right after create an instance of core * create basic stuff * @throws core_exception */ public function init0() { if ($this->initialized) { throw new core_exception('Already initialized'); } $this->initialized = self::IS_LOADING; self::dprint(array("core::init0 %s", loader::with_composer() ? '+composer' : ''), self::E_DEBUG2); // templates setup self::register_lib('tpl_parser', function () { return tpl_loader::factory(core::selfie()->cfg('lib_tpl_parser')); }); // renderer self::register_lib('renderer', function () { return 0 ? new \SatCMS\Modules\Core\Base\ObjectMock() : new tf_renderer(core::selfie()->cfg('template'), core::lib('tpl_parser')); }); // database setup (database-`mysql`) $this->configure_database($this->cfg('database')); // set default timezone $tz = $this->cfg('default_timezone'); date_default_timezone_set($tz ? $tz : 'Europe/Moscow'); // load core config $this->dyn_config = $this->model('config', array('render_by_key' => true))->load()->merge_with($this->config); // content-types $ctype_config = loader::get_docs() . 'ctypes.cfg'; $ctype_array = fs::file_exists($ctype_config) ? parse_ini_file($ctype_config, true) : array(); $this->_ctypes = $this->get_ctype_handle(); $this->_ctypes->from_array($ctype_array); // add libs self::register_lib('logger', function () { return tf_logger::get_instance()->enable(!core::get_instance()->cfg('disable_logs', false)); }); self::register_lib('manager', new tf_manager()); self::register_lib('request', new tf_request()); $modules_config = array(); if ('file' == $this->cfg('modules_config', '') && ($modules_config_file = loader::get_docs() . 'modules.cfg') && fs::file_exists($modules_config_file)) { $modules_config = parse_ini_file($modules_config_file, true); } else { try { $modules_config = $this->module('modules', array('key' => 'tag'))->as_array(); } catch (module_exception $e) { // misconfigured modules, some of modules not exists throw new core_exception($e->getMessage(), tf_exception::CRITICAL); } } // site init %domain% // config/%domain%/init.php $site_config = array(); $site_config_path = $this->cfg('site_config'); if (!empty($site_config_path)) { $host = @$_SERVER['HTTP_HOST']; if ('%domain%' == $site_config_path) { $site_config_path = strpos($host, 'www.') === 0 ? substr($host, 4) : $host; } $mod_config_file = loader::get_docs() . $site_config_path . '/init.php'; if ($site_config_path && file_exists($mod_config_file)) { $site_config = (include $mod_config_file); } } // import module config `mod_{module}` // allow overrides modules.cfg foreach ($this->config as $cfg_key => $cfg) { if (strpos($cfg_key, 'mod_') === 0) { $cfg_key = substr($cfg_key, 4); $modules_config[$cfg_key] = @$modules_config[$cfg_key] ?: array(); $modules_config[$cfg_key] = functions::array_merge_recursive_distinct($modules_config[$cfg_key], $cfg); } } // module manager self::$modules = new core_modules($modules_config, $site_config); // finish core init0 proccess parent::init0(); // check bans if (!$this->cfg('no_bans_check') && isset($_SERVER['REQUEST_URI']) && ($_uri = $_SERVER['REQUEST_URI']) && !empty($_uri)) { if ($this->get_bans_handle()->check_spam($_uri)) { throw new core_exception(i18n::T('you_are_banned'), tf_exception::CRITICAL); } } self::register_lib('auth', new tf_auth(loader::in_shell()))->start_session(); if (self::in_editor()) { // editor kickstart $this->lib('editor'); } register_shutdown_function(array($this, 'halt')); $this->initialized = true; }
/** * INIT0 - call right after create an instance of core * create basic stuff * @throws core_exception */ public function init0() { // templates setup self::register_lib('tpl_parser', tpl_loader::factory()); // renderer self::register_lib('renderer', new tf_renderer($this->get_cfg_var('site_url') . loader::DIR_TEMPLATES . $this->get_cfg_var('template') . '/', self::lib('tpl_parser'))); // database setup self::register_lib('db', $db_test = db_loader::get($this->get_cfg_var('database'))); if (!$db_test && !defined('TF_TEST_INFECTED')) { throw new core_exception('Database connection problem', tf_exception::CRITICAL); } // set default timezone $tz = $this->get_cfg_var('default_timezone'); date_default_timezone_set($tz ? $tz : 'Europe/Moscow'); // load core config $this->dyn_config = $this->class_register('config', array('render_by_key' => true)); $this->dyn_config->merge_with($this->config); // add libs self::register_lib('logger', tf_logger::get_instance()); // ->enable(!$this->get_cfg_var('disable_logger', false)); if (!defined('TF_TEST_INFECTED')) { set_error_handler(create_function('$x, $y', 'if (0 != ini_get("error_reporting")) throw new system_exception($y, $x);'), E_ALL & ~E_NOTICE); } self::register_lib('manager', new tf_manager()); self::register_lib('validator', new tf_validator()); self::register_lib('request', new tf_request()); $modules_array = array(); if ('file' == $this->get_cfg_var('modules_config', '') && ($modules_config = loader::get_docs() . 'modules.cfg') && fs::file_exists($modules_config)) { $modules_array = parse_ini_file($modules_config, true); } else { try { $modules_array = $this->class_register('modules', array('key' => 'tag'))->as_array(); } catch (modules_exception $e) { // probably misconfigured modules table, some of modules not exists throw new core_exception($e->getMessage(), tf_exception::CRITICAL); } } // modules manager self::$modules = new modules_factory($modules_array); // finish core init0 proccess parent::init0(); // check bans if (!$this->get_cfg_var('no_bans_check') && isset($_SERVER['REQUEST_URI']) && ($_uri = $_SERVER['REQUEST_URI']) && !empty($_uri)) { if ($this->get_bans_handle()->check_spam($_uri)) { throw new core_exception($this->get_langword('you_are_banned'), tf_exception::CRITICAL); } } /* content type in autoload so convert it to object an destroy it */ if (self::in_editor()) { self::register_lib('editor', new tf_editor()); } // register auth if ($musers = $this->module('users')) { self::register_lib('auth', new tf_auth($musers, loader::in_shell())); } $this->initialized = true; }
/** * Direct to renderer * * @param mixed $t * @param mixed $append */ function set_title($t, $append = true) { $t = $this->context->T($t); $this->renderer->set_page_title($t, $append); }