/** * Perform initial checks and load requested view * * @param string $url * URL path of requested view */ public function load($url = null) { // Check for login Controller::instance()->isLoggedIn(); if (!Controller::instance()->isLoggedIn()) { $this->parseURL('/login'); } else { try { if (is_null($url)) { // Get user's default section $section_handle = Controller::instance()->User->default_section; // If the section exists, load publish view try { $section = Section::loadFromHandle($section_handle); $this->parseURL('/publish/' . $section_handle); } catch (Exception $e) { $this->parseURL('/blueprints/sections/'); } } else { $this->parseURL($url); } // TODO: Fix this if (!$this instanceof AdministrationView) { throw new Exception('View not found'); } } catch (Exception $e) { throw $e; //catch the exception print 'Sorry could not load ' . $url; } } }
public function __construct() { $this->view = Controller::instance()->View; $this->document = $this->view->document; $this->url = Controller::instance()->url; $this->setTitle(); }
/** * This part has had to be outsourced from the Constructor, * because the called Classes access the core and by * that the Core::instance() method. Thus an endless recursion * occured. because the instance is not already instantiated */ private function postConstruct() { $this->db = Grootdb::instance(); I18N::instance()->addFolder('i18n'); UserHandler::instance(); $this->controller = Controller::instance(); }
function getInstance() { if (Controller::$instance === null) { Controller::$instance = new Controller(); } return Controller::$instance; }
/** * Fetch instance of this class */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new Controller(); } return self::$instance; }
public function processRequests() { if (isset($_POST['action'])) { $actionParts = array_keys($_POST['action']); $action = end($actionParts); ##Login Attempted if ($action == 'login') { if (!isset($_POST['username']) || strlen(trim($_POST['username'])) == 0) { $this->invalid_credentials = true; $this->missing_username = true; } if (!isset($_POST['password']) || strlen(trim($_POST['password'])) == 0) { $this->invalid_credentials = true; $this->missing_password = true; } elseif (!Controller::instance()->login($_POST['username'], $_POST['password'])) { $this->invalid_credentials = true; } else { if (isset($_POST['redirect'])) { redirect(URL . str_replace(parse_url(URL, PHP_URL_PATH), NULL, $_POST['redirect'])); } redirect(ADMIN_URL . '/'); } } } }
public static function getInstance() { if (self::$instance === false) { self::$instance = new Controller(); } return self::$instance; }
public static function getInstance() { if (!isset(self::$instance)) { $class = __CLASS__; self::$instance = new $class(); } return self::$instance; }
public function __construct() { $this->view = Controller::instance()->View; $this->document = $this->view->document; $this->url = Controller::instance()->url; // Probably a neater way to store and fetch the section handle $this->section = Section::loadFromHandle($this->view->params[0]); $this->setTitle(); }
public function process($config) { $controller = Controller::instance(); $view_key = $controller->getViewKey(); static::pushPath($controller->getViewUrl('home'), i('view_label_home')); if ($view_key != 'home') { static::pushPath($controller->getViewUrl(), i('view_label_' . $view_key)); } }
public function instance() { if (self::$instance != null) { return self::$instance; } self::$instance = new Controller(); self::$instance->postConstruct(); return self::$instance; }
private function _getShowCase($genre, $page = 0, $size = 4) { $books = $this->_getBooksByGenre($genre, $page, $size); $num_books = Core::instance()->getDb()->countBookyByGenre($genre); if (count($books) == 0) { return null; } $args = array('books' => $books, 'style' => 'showcase', 'text_details' => i('To the details'), 'navigation' => true, 'prev_hidden' => $num_books <= $size, 'next_hidden' => count($books) < $size, 'config' => urlencode(json_encode(array('page' => $page, 'size' => $size, 'request' => Controller::instance()->getViewUrl() . '&ajax=1&ajax_fn=nextShowcasePage&page={%page%}&size={%size%}&genre=' . $genre)))); return TemplateRenderer::instance()->extendedRender('theme/templates/snippets/showcase.html', $args); }
public function __construct() { self::$instance = $this; foreach (loaded() as $name => $class) { $this->{$name} = load($class); } $this->view = load('View'); $this->load = load('Loader', 'system/core', NULL, 1); $this->view->load = $this->load; if (USE_AUTOLOAD) { $this->autoload = load('Autoload', 'system/core', NULL, 0); } if (USE_LANG) { $this->lang = load('Language'); $this->view->lang = $this->lang; } }
public function displayCart() { $TID = 0; if (sizeof($this->items) == 0) { return i("Your shopping cart is empty."); } $table = ""; //Erstellen des HTML Contents, der von der displayCart() Funktion dann zurückgegeben wird $table = "<p>" . i('Your shoppingcart contains') . ": " . sizeof($this->items) . " " . i('product(s)') . "</p>" . "<table id='shoppingTable'>" . "<tr id='tableTopics'>\n\t\t<td>" . i('isbn') . "</td>\n\t\t<td>" . i('Amount') . "</td>\n\t\t<td>" . i('Title') . "</td>\n\t\t<td></td>\n\t\t<td></td>\n\t\t<td>" . i('Price') . "</td>\n\t\t<td></td>"; /* Die Tabelle zur Anzeige der in den Korb gelegten Items wird aufbereitet. Der Remove Button wird hinter jeden Zeileneintrag mit der entsprechenden Post Variable * gesetzt und die + und - Buttons werden angehängt * Update 30.12: Anstatt meiner Lösung unten hätte ich besser die +/- Buttons auch schon bei der Generierung mit den Actions belegen sollen. */ foreach ($this->items as $index) { $ID2del = $index->ID; $list = BookModel::findList(array('isbn' => array($index->ID)), null); $title = $list[0]['title']; $price = $list[0]['price']; $totPrice = $price * $index->amount; $table = $table . "<tr id={$TID} onclick=''><td>{$index->ID}</td>\n\t\t\t<td>{$title}</td>\n\t\t\t<td name='amount'>{$index->amount}</td>\n\t \t \t<td>\n\t \t \t<input type='button' id='plusButton' value='+'></input></td>\n\t \t \t<td><input type='button' id='minusButton' value='-'></input></td>\n\t \t \t<td>{$totPrice}</td>\n\t \t \t<td><form action='" . Controller::instance()->getViewUrl('shoppingcart') . "&remove={$ID2del}' method='post'><input type='submit' value='" . i('Remove') . "'></input></form></td>\n\t \t \t</tr>"; $TID++; $this->subTotal += $totPrice; } /* * Totaler Wert des Warenkorbs */ $table = $table . "\n\t\t\t\t<tr>\n\t\t<td></td><td></td><td></td><td></td>\n\t\t<td></td>\n\t\t<td></td>\n\t\t<td></td>\n\t\t</tr>\n\t\t<tr>\n\t\t<td></td><td></td><td></td><td></td>\n\t\t<td>Sub Total:</td>\n\t\t<td>{$this->subTotal}</td>\n\t\t<td></td>\n\t\t</tr>"; /* * */ $table = $table . "</table>\n\t \t\t\t<div class='action-wrapper'><form action='index.php?view=shoppingcart' method='post' class='clear-form'>\n\t \t\t\t<input type='submit' value='" . i('Empty cart') . "' class='button button-primary'></input>\n\t \t\t\t<input type='hidden' name='clearCart'></input></form>"; //Add Button go to payment $table = $table . "\n\t\t\t\t<a href='index.php?view=payment' class='next'>\n <input class='button button-primary' type='button' value='" . i('Go to payment') . "'></input>\n </a></div>\n\t\t\t"; // Hier den JavascriptCode rein: Erhöhen liest Anzahl aus, zählt eins dazu und reloaded the page mit dem GET Paramter: &update=ID&Amount=NEUER AMOUNT $table = $table . "\n\t \t\t\t<script type='text/javascript'>\n\n\t \t\t\tvar theTbl = document.getElementById('shoppingTable');\n\t \t\t\tvar rows = theTbl.rows;\n\n\t\t\t\tconsole.log(rows.length);\n\n\t\t\t\tfor(var i=0;i<rows.length;i++) {\n\n \t\t\t\t \t\t\tfor(var j=0;j<rows[i].cells.length;j++)\t{\n\t \t\t\t\t\t\tconsole.log('set');\n \t\t\t \t\t\t\trows[i].cells[j].onclick = alertInnerHTML;\n\t \t\t\t\t\t\t}\n\t\t\t\t}\n\n\t \t\t\trowIndex = 0;\n\n\t \t\t\tfunction myFunction(x) {\n\t \t\t\trowIndex = x.rowIndex\n\t \t\t\twindow.alert(rowIndex)\n\t\t\t\t}\n\n\n\n\t \t\t\tfunction alertInnerHTML(e) {\n \t\t\t\t\t e = e || window.event;//IE\n\t \t\t\t\trownumber = this.parentNode.id;\n\t \t\t\t\tcellNumber = this.cellIndex;\n\n\t \t\t\t\tconsole.log('Zeilennummer: '+rownumber + ' Spalte:' +cellNumber);\n\n\t \t\t\t\tif(cellNumber==3) {\n\t \t\t\t\tconsole.log('increase');\n\t \t\t\t\tincrease(rownumber);\n\t \t\t\t\t}\n\n\t \t\t\t\tif(cellNumber==4) {\n\t \t\t\t\tdecrease(rownumber);\n\t \t\t\t\t}\n\n\t \t\t\t\t}\n\n\t \t\t \tfunction increase(rownumber) {\n\t\t\t\trownumber++;\n\t \t\t\tvar table = document.getElementById('shoppingTable');\n\t\t\t\tproductID = table.rows[rownumber].cells[0].innerHTML;\n\t \t\t\twindow.open('index.php?view=shoppingcart&action=mod&id2Change='+productID+'&change=up','_self')\n\n\t \t\t\t}\n\n\t \t\t\tfunction decrease(rownumber) {\n\t\t\t\trownumber++;\n\t \t\t\tvar table = document.getElementById('shoppingTable');\n\t\t\t\tproductID = table.rows[rownumber].cells[0].innerHTML;\n\n\t\t\t\twindow.open('index.php?view=shoppingcart&action=mod&id2Change='+productID+'&change=down','_self')\n\t \t\t\treturn false;\n\t \t\t\t}\n\n\n\n\t \t</script>"; return $table; }
public function makeMenu() { #label of selectbox $selectName = "cat"; $divId = "logo"; $classIcon = "stdanimation1_4"; $grootLogoChar = "G"; //Build html $html = ""; $selectBox = GenreModel::getTranslatedGenres(); array_unshift($selectBox, array('value' => '', 'label' => i('All'))); $cat = isset($_REQUEST['cat']) ? htmlspecialchars($_REQUEST['cat']) : null; //build the select html element $selectBoxHtml = Utilities::buildSelectbox($selectBox, $selectName, $cat); //Logo $html .= ' <a href="index.php?view=home"> <div id="' . $divId . '"> <span class="' . $classIcon . '">' . $grootLogoChar . '</span> </div> </a> '; $query_val = isset($_REQUEST['query']) ? htmlspecialchars($_REQUEST['query']) : ''; //Searchbar $html .= '<form id="search" method="GET"> ' . $selectBoxHtml . ' <input type="hidden" name="view" value="search" /> <input type="text" name="query" id="query" value="' . $query_val . '" autocomplete="off"/> <button type="submit" name="search" value="search">' . i("Search") . '</button> </form>'; //Build up all the navigation points from an array $naviElement = ""; $current_view_url = Controller::instance()->getViewUrl(); foreach (I18n::availableLanguages() as $lang) { $naviArray[] = array("link" => $current_view_url . '&lang=' . $lang, "icon" => "", "cls" => $lang == I18n::lang() ? 'active' : '', "label" => strtoupper($lang)); } //create HTML elements for each navi point foreach ($naviArray as $navi) { $navi['label'] = i($navi['label']); $naviElement .= '<li class="' . $navi['cls'] . '"><a class="stdanimation1_2" href="' . $navi["link"] . '">' . $navi["label"] . '</a></li>'; } $html .= '<ul class="menu menu-main"> ' . $naviElement . ' </ul>'; //Deside, if user is logged in or not and change appearance if (UserHandler::instance()->loggedin()) { $mask_cls = 'loggedin'; $buttons = '<input type="submit" class="button" name="Logout" value="Logout">'; //getting the values from the protected data array via class.basemodel if (UserHandler::instance()->user()) { $firstName = UserHandler::instance()->user()->getValue('first_name'); $lastName = UserHandler::instance()->user()->getValue('last_name'); } else { $firstName = ""; $lastName = ""; } $greeting = i('Hello'); $loginMask = $greeting . ' ' . $firstName . ' ' . $lastName; } else { $mask_cls = 'loggedout'; $buttons = '<input type="submit" class="button" name="Login" value="Login"/>'; $loginMask = '<div><label for="Loginname">' . i("User") . ':</label><input class="" name="Loginname" /> </div> <div><label for="Password">' . i("Password") . ':</label><input class="" type="password" name="Password" /> </div>'; } $html .= '<div class="login-mask ' . $mask_cls . '"> <form action="" method="POST"> <div class="mask">' . $loginMask . '</div> <div class="buttons">' . $buttons . '</div> </form> </div>'; return $html; }
/** * 汉字转为拼音 */ function word2pinyin($word) { if (empty($word)) { return ''; } $pin = Controller::instance('pinyin'); return str_replace('/', '', $pin->output(str_replace(' ', '', $word))); }
<?php /* For licensing terms, see /license.txt */ /** * Homepage for links tool * @package chamilo.link */ /** * Code */ namespace Link; $language_file = array('link', 'admin'); //require_once '../inc/global.inc.php'; Controller::instance()->run(); return;
/** * 解析标签list */ protected function _listdata($param) { $_param = explode(' ', $param); $param = array(); foreach ($_param as $p) { $mark = strpos($p, '='); if ($p && $mark !== false) { $var = substr($p, 0, $mark); $val = substr($p, $mark + 1); if (isset($var) && $var) { $param[$var] = $val; } } } $system = $fields = $_fields = $not = $in = $or = $between = $like = array(); $dbcache = isset($param['cache']) ? (int) $param['cache'] : 0; unset($param['cache']); if (is_array($param)) { foreach ($param as $key => $val) { //参数归类 if (in_array($key, array('return', 'more', 'page', 'urlrule', 'num', 'join', 'on', 'order', 'table', 'pagesize', 'pagerule', 'action', 'tag', 'extend', 'site', 'form', 'fields'))) { $system[$key] = $val; } else { if (substr($key, 0, 3) == 'NOT') { $key = substr($key, 3); $not[] = $key; } elseif (substr($key, 0, 2) == 'OR') { $key = substr($key, 2); $or[] = $key; } elseif (substr($key, 0, 2) == 'IN') { $key = substr($key, 2); $in[] = $key; } elseif (substr($key, 0, 2) == 'BW') { $key = substr($key, 2); $between[] = $key; } elseif (substr($key, 0, 4) == 'LIKE') { $key = substr($key, 4); $like[] = $key; } $fields[$key] = $val; $_fields[] = $key; } } } $where = ''; //设置站点id $system['site'] = !isset($system['site']) || empty($system['site']) ? App::get_site_id() : $system['site']; //Action判断 if (isset($system['action']) && $system['action'] == 'position') { //推荐位 $data = position($system['site'], $fields['id'], isset($fields['catid']) ? $fields['catid'] : 0, isset($system['num']) ? $system['num'] : 0); if ($data) { $db = Controller::model('content'); foreach ($data as $i => $t) { if ($t['contentid']) { $row = $db->db->where('id', $t['contentid'])->get('content_' . $system['site'])->row_array(); $data[$i] = $t + $row; } } } if (isset($system['return']) && $system['return'] && $system['return'] != 't') { return array('return_' . $system['return'] => $data, 'total_' . $system['return'] => count($data)); } return array('return' => $data, 'total' => count($data)); } elseif (isset($system['action']) && $system['action'] == 'keywords') { //搜索关键字 $search = Controller::model('search'); $num = $system['num'] ? (int) $system['num'] : 5; if (isset($system['order']) && $system['order']) { $order = null; $orders = explode(',', $system['order']); foreach ($orders as $t) { list($_field, $_order) = explode('_', $t); if (in_array($_field, array('id', 'keywords', 'addtime', 'total'))) { $_orderby = isset($_order) && strtoupper($_order) == 'ASC' ? 'ASC' : 'DESC'; $order .= '`' . $_field . '` ' . $_orderby . ','; } } if (substr($order, -1) == ',') { $order = substr($order, 0, -1); } } else { $order = '`total` DESC'; } $data = $search->execute('select distinct keywords as title from ' . $search->prefix . 'search order by ' . $order . ' limit ' . $num, true, $dbcache); if (isset($system['return']) && $system['return'] && $system['return'] != 't') { return array('return_' . $system['return'] => $data, 'total_' . $system['return'] => count($data)); } return array('return' => $data, 'total' => count($data)); } elseif (isset($system['action']) && $system['action'] == 'sql') { // } elseif (isset($system['action']) && $system['action'] == 'relation') { if (isset($system['tag']) && $system['tag']) { //按关键字搜索 if (isset($fields['id']) && $fields['id']) { $where .= '`id`<>' . (int) $fields['id']; } $tags = @explode(',', $system['tag']); $kwhere = $k = NULL; foreach ($tags as $tag) { if ($tag) { if (empty($k)) { $kwhere .= '`title` like "%' . $tag . '%"'; } else { $kwhere .= ' OR `title` like "%' . $tag . '%"'; } $k = 1; } } if ($kwhere) { $where .= ' AND (' . $kwhere . ')'; } unset($k, $tags, $tag, $kwhere, $system['table'], $fields['id']); } else { //手动设置的相关文章 $data = $this->relation($fields['id'], $system['num']); if (isset($system['return']) && $system['return'] && $system['return'] != 't') { return array('return_' . $system['return'] => $data, 'total_' . $system['return'] => count($data)); } return array('return' => $data, 'total' => count($data)); } } elseif (isset($system['action']) && $system['action'] == 'field') { //字段信息 $mods = get_model_data(); $mod = $mods[$fields['modelid']]; $data = array(); if ($mod['fields']) { foreach ($mod['fields']['data'] as $t) { if ($fields['name'] == $t['field']) { //加载字段配置文件 App::auto_load('fields'); $data_fields = ''; $data_fields .= '<tr id="fine_' . $t['field'] . '">'; $data_fields .= '<th>' . (isset($t['not_null']) && $t['not_null'] ? '<font color="red">*</font> ' : '') . $t['name'] . ':</th>'; $data_fields .= '<td>'; $func = 'content_' . $t['formtype']; //防止出错,把字段内容转换成数组格式 $content = array($fields['value']); $content = var_export($content, true); $field_config = var_export($t, true); if (function_exists($func)) { eval("\$data_fields .= " . $func . "(" . $t['field'] . ", " . $content . ", " . $field_config . ");"); } $data_fields .= $t['tips'] ? '<div class="onShow">' . $t['tips'] . '</div>' : ''; $data_fields .= '<span id="ck_' . $t['field'] . '"></span>'; $data_fields .= '</td>'; $data_fields .= '</tr>'; $data[0]['form'] = $data_fields; if ($t['setting']) { $c = string2array($t['setting']); if ($c['content']) { $select = explode(PHP_EOL, $c['content']); $vdata = array(); foreach ($select as $i => $c) { list($n, $v) = explode('|', $c); $vdata[trim($n)] = $v === null ? trim($n) : trim($v); } $data[0]['data'] = $vdata; } } } } } if (isset($system['return']) && $system['return'] && $system['return'] != 't') { return array('return_' . $system['return'] => $data); } return array('return' => $data); } //主表判断 if (isset($system['table']) && $system['table']) { $table = $system['table']; } elseif (isset($system['form']) && $system['form']) { $table = 'form_' . $system['site'] . '_' . $system['form']; } else { $table = 'content'; } //加载Model实例 if (strpos($table, '.') !== false) { list($plugin, $table) = explode('.', $table); $db = App::plugin_model($plugin, $table); } else { $db = Controller::model('content'); if (strpos($table, 'content') === 0) { $table .= '_' . $system['site']; } } $table = $db->prefix . $table; $db->table_name = $table; $table_join = $table_data = $table_fields = $table_join_fields = $table_data_fields = $arrchilds = null; $_table_fields = $db->get_table_fields(); $table_fields = array_intersect($_fields, $_table_fields); //status判断 if (in_array('status', $_table_fields)) { $where .= ($where ? ' AND ' : ' ') . ' `' . $table . '`.`status`=1'; } if (isset($fields['catid']) && $fields['catid']) { //栏目信息 $cats = get_category_data($system['site']); $cat = $cats[$fields['catid']]; } if (isset($system['join']) && $system['join'] && $system['on']) { //JOIN联合查询 $table_join = $system['join']; //加载Model实例 if (strpos($table_join, '.') !== false) { list($plugin, $table_join) = explode('.', $table_join); $db_join = App::plugin_model($plugin, $table_join); } else { $db_join = Controller::model($table_join); } $_table_join_fields = $db_join->get_table_fields(); $table_join_fields = array_intersect($_fields, $_table_join_fields); foreach ($table_join_fields as $k => $c) { if (in_array($c, $table_fields)) { unset($table_join_fields[$k]); } } $table_join = $db->prefix . $table_join; } if (isset($system['more']) && $system['more']) { //附表 $model = null; if ($table == $db->prefix . 'content_' . $system['site']) { $models = get_model_data('content', $system['site']); if (isset($fields['catid']) && $fields['catid'] && isset($cat) && $cat) { $model = $models[$cat['modelid']]; } elseif (isset($fields['modelid']) && $fields['modelid']) { $model = $models[$fields['modelid']]; } } elseif ($table == $db->prefix . 'member' && isset($fields['modelid']) && $fields['modelid']) { $cache = new cache_file(); $models = $cache->get('model_member'); $model = $models[$fields['modelid']]; } if ($model) { $table_data = $model['tablename']; $db_data = Controller::model($table_data); $_table_data_fields = $db_data->get_table_fields(); $table_data_fields = array_intersect($_fields, $_table_data_fields); foreach ($table_data_fields as $k => $c) { if (in_array($c, $table_fields)) { unset($table_data_fields[$k]); } } $table_data = $db->prefix . $table_data; } } //WHERE整合 $fieldsAll = array($table => $table_fields, $table_join => $table_join_fields, $table_data => $table_data_fields); foreach ($fieldsAll as $_table => $t) { if (is_array($t)) { foreach ($t as $f) { if ($fields[$f] == '') { continue; } $and_or = in_array($f, $or) ? 'OR' : 'AND'; //栏目条件根据子栏目来做为条件 if ($f == 'catid' && isset($fields['catid']) && $fields['catid']) { if (isset($cat) && $cat && $cat['child']) { $arrchilds = $cat['arrchilds']; $not_in = in_array($f, $not) ? 'NOT IN' : 'IN'; $where .= ' ' . $and_or . ' `' . $_table . '`.`catid` ' . $not_in . ' (' . $arrchilds . ')'; } elseif (strpos($fields['catid'], ',') !== false) { $not_in = in_array($f, $not) ? 'NOT IN' : 'IN'; $where .= ' ' . $and_or . ' `' . $_table . '`.`catid` ' . $not_in . ' (' . $fields['catid'] . ')'; } else { $not_in = in_array($f, $not) ? '<>' : '='; $where .= ' ' . $and_or . ' `' . $_table . '`.`catid`' . $not_in . $fields['catid']; } } elseif ($f == 'thumb' && isset($fields['thumb']) && is_numeric($fields['thumb'])) { $where .= $fields['thumb'] ? ' ' . $and_or . ' `' . $_table . '`.`thumb`<>""' : ' ' . $and_or . ' `' . $_table . '`.`thumb`=""'; } else { $not_in = in_array($f, $in) ? 'IN' : ''; $not_in = in_array($f, $not) ? 'NOT IN' : $not_in; if (in_array($f, $between)) { if (strpos($fields[$f], '_') !== false) { list($v1, $v2) = explode('_', $fields[$f]); $v1 = is_numeric($v1) ? $v1 : '"' . addslashes($v1) . '"'; $v2 = is_numeric($v2) ? $v2 : '"' . addslashes($v2) . '"'; $where .= ' ' . $and_or . ' `' . $_table . '`.`' . $f . '` BETWEEN ' . $v1 . ' AND ' . $v2; } elseif (strpos($fields[$f], ',') !== false) { list($v1, $v2) = explode(',', $fields[$f]); $v1 = is_numeric($v1) ? $v1 : '"' . addslashes($v1) . '"'; $v2 = is_numeric($v2) ? $v2 : '"' . addslashes($v2) . '"'; $where .= ' ' . $and_or . ' `' . $_table . '`.`' . $f . '` BETWEEN ' . $v1 . ' AND ' . $v2; } else { continue; } } elseif ($not_in) { $where .= ' ' . $and_or . ' `' . $_table . '`.`' . $f . '` ' . $not_in . ' (' . $fields[$f] . ')'; } elseif (in_array($f, $like)) { $value = addslashes($fields[$f]); $where .= ' ' . $and_or . ' `' . $_table . '`.`' . $f . '` LIKE "' . $value . '"'; } else { $value = is_numeric($fields[$f]) ? $fields[$f] : '"' . addslashes($fields[$f]) . '"'; $where .= ' ' . $and_or . ' `' . $_table . '`.`' . $f . '`=' . $value . ''; } } } } } if ($where) { if (substr($where, 0, 4) == ' AND') { $where = ' WHERE' . substr($where, 4); } elseif (substr($where, 0, 3) == ' OR') { $where = ' WHERE' . substr($where, 3); } else { $where = ' WHERE' . $where; } //对WHERE延展 if (isset($system['extend']) && substr($system['extend'], 0, 6) == 'WHERE.') { $where .= ' ' . str_replace('-', ' ', substr($system['extend'], 6)); unset($system['extend']); } } //延展list $extend = ''; if (isset($system['extend']) && $system['extend']) { $extend = ' ' . str_replace('-', ' ', $system['extend']); } //FROM整合 $from = 'FROM ' . $table; if ($table_data) { $from .= ' LEFT JOIN ' . $table_data . ' ON `' . $table . '`.`' . $db->get_primary_key() . '`=`' . $table_data . '`.`' . $db_data->get_primary_key() . '`'; } if ($table_join && $system['on']) { $_join_name = null; if (in_array($system['on'], $_table_fields)) { $_join_name = $table; } elseif (isset($_table_data_fields) && in_array($system['on'], $_table_data_fields)) { $_join_name = $table_data; } if ($_join_name) { $from .= ' LEFT JOIN ' . $table_join . ' ON `' . $table_join . '`.`' . $db_join->get_primary_key() . '`=`' . $_join_name . '`.`' . $system['on'] . '`'; } } //ORDER排序 $order = ''; if (isset($system['order']) && $system['order']) { if (strtoupper($system['order']) == 'RAND()') { $order .= ' ORDER BY RAND()'; } else { $orders = explode(',', $system['order']); foreach ($orders as $t) { list($_field, $_order) = explode('_', $t); $_name = null; if (in_array($_field, $_table_fields)) { $_name = $table; } elseif (isset($_table_data_fields) && in_array($_field, $_table_data_fields)) { $_name = $table_data; } elseif (isset($_table_join_fields) && in_array($_field, $_table_join_fields)) { $_name = $table_join; } $_orderby = isset($_order) && strtoupper($_order) == 'ASC' ? 'ASC' : 'DESC'; if ($_name) { $order .= ' `' . $_name . '`.`' . $_field . '` ' . $_orderby . ','; } } if (substr($order, -1) == ',') { $order = ' ORDER BY' . substr($order, 0, -1); } } } //limit与分页 $limit = ''; if (isset($system['num']) && $system['num']) { $limit = ' LIMIT ' . $system['num']; } elseif (isset($system['page'])) { $pageurl = ''; $system['page'] = (int) $system['page'] ? (int) $system['page'] : 1; if ($system['urlrule']) { $pageurl = str_replace(array('_page_', '[page]'), '{page}', $system['urlrule']); $pagesize = $system['pagesize'] ? $system['pagesize'] : (isset($cat['pagesize']) ? $cat['pagesize'] : 10); } elseif ($cat) { $pageurl = getCaturl($cat, '{page}'); $pagesize = $system['pagesize'] ? $system['pagesize'] : $cat['pagesize']; } else { $pagesize = $system['pagesize'] ? $system['pagesize'] : 10; $pageurl = '{page}'; } $sql = 'SELECT count(*) AS total ' . $from . ' ' . $where; $count = $db->execute($sql, false, $dbcache); $total = $count['total']; $pagelist = Controller::instance('pagelist'); $pagelist->loadconfig($system['pagerule'] ? $system['pagerule'] : 'pagerule'); $start_id = $pagesize * ($system['page'] - 1); $limit = ' LIMIT ' . $start_id . ',' . $pagesize; $pagelist = $pagelist->total($total)->url($pageurl)->num($pagesize)->page($system['page'])->output(); } //查询字段筛选 if (isset($system['fields']) && $system['fields']) { $fields_array = explode(',', $system['fields']); //字段参数转为数组 $select_array = array(); foreach ($fields_array as $t) { //遍历字段参数数组,筛选无用字段、字段附加表前缀 if (in_array($t, $_table_fields)) { //主表字段 $select_array[] = '`' . $table . '`.`' . $t . '`'; } elseif (isset($_table_data_fields) && in_array($t, $_table_data_fields)) { //附表字段 $select_array[] = '`' . $table_data . '`.`' . $t . '`'; } elseif (isset($_table_join_fields) && in_array($t, $_table_join_fields)) { //联合表字段 $select_array[] = '`' . $table_join . '`.`' . $t . '`'; } } $select_field = empty($select_array) ? ' * ' : ' ' . implode(',', $select_array) . ' '; //组合成sql查询格式 unset($select_array, $fields_array); } else { $select_field = ' * '; } //查询结果 $sql = 'SELECT' . $select_field . $from . $where . $order . $limit . $extend; $data = $db->execute($sql, true, $dbcache); //释放变量 unset($_param, $param, $par, $p, $fields, $_fields, $not, $in, $or, $between, $dbcache, $like); unset($table, $db, $table_join, $table_data, $table_fields, $table_join_fields, $table_data_fields, $arrchilds, $_table_fields); unset($fieldsAll, $_table_data_fields, $cache, $db_join, $cats, $cat, $models, $model, $db_data, $where, $order, $from); if (isset($system['return']) && $system['return'] && $system['return'] != 't') { return array('sql_' . $system['return'] => $sql, 'total_' . $system['return'] => isset($total) ? $total : count($data), 'return_' . $system['return'] => $data, 'pagelist_' . $system['return'] => $pagelist); } return array('pagelist' => $pagelist, 'return' => $data, 'sql' => $sql, 'total' => isset($total) ? $total : count($data)); }
/** * 下载远程图片 */ private function download_images($imgs, $uid = 0, $size = 0) { $imgs = array_unique($imgs); //去除重复图片 $regex = $replace = array(); $path = $uid ? 'uploadfiles/member/' . $uid . '/image/' . date('Ym') . '/' : 'uploadfiles/image/' . date('Ym') . '/'; $this->mkdirs($path); //水印 $config = App::get_config(); if ($config['SITE_WATERMARK']) { $image = Controller::instance('image_lib'); } foreach ($imgs as $img) { if ($uid && $size && count_member_size($uid) > $size * 1024 * 1024) { continue; } if (strpos($img, SITE_URL) !== false || substr($img, 0, 7) != 'http://') { continue; } //下载图片 $fileext = strtolower(trim(substr(strrchr($img, '.'), 1, 10))); //扩展名 $name = $path . md5($img . time()) . '.' . $fileext; $content = fn_geturl($img); if (empty($content)) { continue; } if (file_put_contents($name, $content)) { if ($config['SITE_WATERMARK']) { $image = Controller::instance('image_lib'); if ($config['SITE_WATERMARK'] == 1) { $image->set_watermark_alpha($config['SITE_WATERMARK_ALPHA']); $image->make_image_watermark($name, $config['SITE_WATERMARK_POS'], $config['SITE_WATERMARK_IMAGE']); } else { $image->set_text_content($config['SITE_WATERMARK_TEXT']); $image->make_text_watermark($name, $config['SITE_WATERMARK_POS'], $config['SITE_WATERMARK_SIZE']); } } $regex[] = $img; $replace[] = $name; } } return count($regex) > 0 ? array('regex' => $regex, 'replace' => $replace) : null; }
/** * Retrieve a new Controller implementation instance. * * @param string A Controller implementation name. * * @return Controller A Controller implementation instance. * * @throws <b>FactoryException</b> If a new controller implementation * instance cannot be created. * * @author Sean Kerr (skerr@mojavi.org) * @since 3.0.0 */ public static function newInstance($class) { try { if (!isset(self::$instance)) { // the class exists $object = new $class(); if (!$object instanceof Controller) { // the class name is of the wrong type $error = 'Class "%s" is not of the type Controller'; $error = sprintf($error, $class); throw new FactoryException($error); } // set our singleton instance self::$instance = $object; return $object; } else { $type = get_class(self::$instance); // an instance has already been created $error = 'A Controller implementation instance has already ' . 'been created'; throw new FactoryException($error); } } catch (MojaviException $e) { $e->printStackTrace(); } catch (Exception $e) { // most likely an exception from a third-party library $e = new MojaviException($e->getMessage()); $e->printStackTrace(); } }
/** * 类的单例实例化操作 */ public function instance($class_name) { return Controller::instance($class_name); }
function __construct() { self::$instance = $this; $this->load = new Loader(); }
/** * <code>Controller</code> Singleton Factory method. * * @return the Singleton instance of <code>Controller</code> */ public static function getInstance() { if (is_null(Controller::$instance)) { Controller::$instance = new Controller(); } return Controller::$instance; }
<?php $controller = Controller::instance(); $controller->render();
/** * Handle the requested action by firing off the matched handler action(s) */ public static function dispatch_request() { /* OK, set the wheels in motion... */ Plugins::act('handler_' . Controller::instance()->action, Controller::get_handler_vars()); if (method_exists(Controller::instance()->handler, 'act')) { Controller::instance()->handler->act(Controller::instance()->action); } }
/** * Singleton method. Used to construct or return controller object. Depending on type of request * Controller or AjaxController instance will be returned. * * @param null * @return Controller object */ static function getInstance() { if (!isset(self::$instance)) { if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === "XMLHttpRequest") { self::$instance = new AjaxController(); } else { self::$instance = new Controller(); } } return self::$instance; }
<?php define('DOCROOT', rtrim(dirname(__FILE__), '\\/')); define('DOMAIN', rtrim(rtrim($_SERVER['HTTP_HOST'], '\\/') . dirname($_SERVER['PHP_SELF']), '\\/')); require DOCROOT . '/symphony/bundle.php'; require LIB . '/class.controller.php'; $output = Controller::instance()->renderView(); header(sprintf('Content-Length: %d', strlen($output))); echo $output; exit;
public function loadFromPath($path, array $params = NULL) { if ($this instanceof FrontendView) { $view = $this; } else { $view = Controller::instance()->View; } $view->path = trim($path, '\\/'); preg_match('/\\/?([^\\\\\\/]+)$/', $path, $match); //Find the view handle $view->handle = $match[1]; $pathname = sprintf('%s/%s/%s.config.xml', VIEWS, $view->path, $view->handle); if (!file_exists($pathname)) { throw new ViewException(__('View, %s, could not be found.', array($pathname)), self::ERROR_VIEW_NOT_FOUND); } $doc = @simplexml_load_file($pathname); if (!$doc instanceof SimpleXMLElement) { throw new ViewException(__('Failed to load view configuration file: %s', array($pathname)), self::ERROR_FAILED_TO_LOAD); } foreach ($doc as $name => $value) { if (isset($value->item)) { $stack = array(); foreach ($value->item as $item) { array_push($stack, (string) $item); } $view->{$name} = $stack; } else { $view->{$name} = (string) $value; } } if (isset($doc->attributes()->guid)) { $view->guid = (string) $doc->attributes()->guid; } else { $view->guid = uniqid(); } if (!is_null($params)) { if (!is_array($view->{'url-parameters'}) || count($view->{'url-parameters'}) <= 0) { throw new ViewException(__('This view does not accept parameters.', array($pathname)), self::ERROR_DOES_NOT_ACCEPT_PARAMETERS); } if (count($params) > count($view->{'url-parameters'})) { throw new ViewException(__('Too many parameters supplied.', array($pathname)), self::ERROR_TOO_MANY_PARAMETERS); } foreach ($params as $index => $p) { $view->setParameter($view->{'url-parameters'}[$index], $p); } } $template = sprintf('%s/%s/%s.xsl', VIEWS, $view->path, $view->handle); if (file_exists($template) && is_readable($template)) { $view->stylesheet->load($template); } $view->getViewContext(); }