public function index($room_id) { $room = $this->Room->getRoomById($room_id); $this->set('room', $room); if (!empty($room)) { $last_update = time(); $idafter = 0; $messages = $this->Message->getMessages($room_id); if (!empty($messages)) { $messages = array_reverse($messages); $idafter = $messages[count($messages) - 1]['Message']['message_id']; } // Render message list $view = new View($this, false); $view->layout = false; $view->set(compact('messages', $messages)); $view->viewPath = 'Message'; $message_list = $view->render('message_list'); $this->set('message_list', $message_list); $this->set('idafter', $idafter); $this->set('last_update', $last_update); $this->set('title', $room['Room']['name']); } else { $this->set('title', 'Room not found!'); } }
public function __construct() { $view = new View(); $view->show('header.php', array('title' => 'Home')); $view->show('home.php'); $view->show('footer.php'); }
/** * generate xml for a form from a table * * @param object $setup * @return string * @author Andy Bennett */ function get_form_xml($setup) { $file_name = $setup->form_name; $dir = DATAPATH . '/xml/forms/'; $path = $dir . $file_name . '.xml'; if (file_exists($path)) { return file_get_contents($path); } if (!isset($setup->model) || !is_object($setup->model)) { $config = Kohana::config('controls.controllers'); $name = Kohana::instance()->uri->segment(1); if (!isset($config->{$name})) { throw new Exception("No controller set up"); } $this->set_table($config->{$name}['table']); } else { $this->set_table($setup->model->get_table()); $name = $setup->form_name; } $field_data = $this->db->field_data($this->table); // print_r($field_data); $view = new View('xml/form'); $view->field_data = $field_data; $view->name = Kohana::instance()->uri->segment(1); $view->action = Kohana::instance()->uri->segment(2); $data = $view->render(); if (file_exists($dir)) { file_put_contents($path, $data); } return $data; }
public function __construct($id = false) { parent::__construct(); $this->add("products"); $this->name = "form_slider"; $this->enctype = "multipart/form-data"; $this->action = URL::current(); $this->products = ProductDB::getAdminShow(); if (!$id) { $this->text("title", "Название:"); $this->textarea("description", "Описание:"); $this->submit("insert_slider", "Сохранить"); } else { $this->add("img"); $this->add("product_id"); $this->hidden("id", $id); $obj = new SliderDB(); $obj->load($id); $this->text("title", "Название:", $obj->title); $img = ProductDB::getCellOnID($obj->product_id, "img"); $view = new View(Config::DIR_TMPL); $this->img = $view->render("img", array("src" => Config::DIR_IMG_PRODUCT . $img), true); $this->textarea("description", "Описание:", $obj->description); $this->submit("update_slider", "Сохранить"); $this->product_id = $obj->product_id; } }
protected function addedAction($title, $content) { ArticlesModel::add($title, $content); $view = new View(); $view->item = $single_article; $view->display('NewAddedArticle.php'); }
public function index($feedtype = 'rss2') { if (!Kohana::config('settings.allow_feed')) { throw new Kohana_404_Exception(); } if ($feedtype != 'atom' and $feedtype != 'rss2') { throw new Kohana_404_Exception(); } // How Many Items Should We Retrieve? $limit = (isset($_GET['l']) and !empty($_GET['l']) and (int) $_GET['l'] <= 200) ? (int) $_GET['l'] : 20; // Start at which page? $page = (isset($_GET['p']) and !empty($_GET['p']) and (int) $_GET['p'] >= 1) ? (int) $_GET['p'] : 1; $page_position = $page == 1 ? 0 : $page * $limit; // Query position $site_url = url::base(); // Cache the Feed with subdomain in the cache name if mhi is set $subdomain = ''; if (substr_count($_SERVER["HTTP_HOST"], '.') > 1 and Kohana::config('config.enable_mhi') == TRUE) { $subdomain = substr($_SERVER["HTTP_HOST"], 0, strpos($_SERVER["HTTP_HOST"], '.')); } $cache = Cache::instance(); $feed_items = $cache->get($subdomain . '_feed_' . $limit . '_' . $page); if ($feed_items == NULL) { // Cache is Empty so Re-Cache $incidents = ORM::factory('incident')->where('incident_active', '1')->orderby('incident_date', 'desc')->limit($limit, $page_position)->find_all(); $items = array(); foreach ($incidents as $incident) { $categories = array(); foreach ($incident->category as $category) { $categories[] = (string) $category->category_title; } $item = array(); $item['id'] = $incident->id; $item['title'] = $incident->incident_title; $item['link'] = $site_url . 'reports/view/' . $incident->id; $item['description'] = $incident->incident_description; $item['date'] = $incident->incident_date; $item['categories'] = $categories; if ($incident->location_id != 0 and $incident->location->longitude and $incident->location->latitude) { $item['point'] = array($incident->location->latitude, $incident->location->longitude); $items[] = $item; } } $cache->set($subdomain . '_feed_' . $limit . '_' . $page, $items, array('feed'), 3600); // 1 Hour $feed_items = $items; } $feedpath = $feedtype == 'atom' ? 'feed/atom/' : 'feed/'; header('Content-Type: application/' . ($feedtype == 'atom' ? 'atom' : 'rss') . '+xml; charset=utf-8'); $view = new View('feed/' . $feedtype); $view->feed_title = Kohana::config('settings.site_name'); $view->site_url = $site_url; $view->georss = 1; // this adds georss namespace in the feed $view->feed_url = $site_url . $feedpath; $view->feed_date = gmdate("D, d M Y H:i:s T", time()); $view->feed_description = Kohana::lang('ui_admin.incident_feed') . ' ' . Kohana::config('settings.site_name'); $view->items = $feed_items; $view->render(TRUE); }
public function indexAction() { $view = new View("DJView"); $view->setViewPath(APPLICATION_PATH . DIRECTORY_SEPARATOR . "views"); $view->setAttribute("beatModel", $this->beatModel); return $view; }
private function _send_reset($form) { $user_name = $form->reset->inputs["name"]->value; $user = user::lookup_by_name($user_name); if ($user && !empty($user->email)) { $user->hash = random::hash(); $user->save(); $message = new View("reset_password.html"); $message->confirm_url = url::abs_site("password/do_reset?key={$user->hash}"); $message->user = $user; Sendmail::factory()->to($user->email)->subject(t("Password Reset Request"))->header("Mime-Version", "1.0")->header("Content-type", "text/html; charset=UTF-8")->message($message->render())->send(); log::success("user", t("Password reset email sent for user %name", array("name" => $user->name))); } else { if (!$user) { // Don't include the username here until you're sure that it's XSS safe log::warning("user", t("Password reset email requested for user %user_name, which does not exist.", array("user_name" => $user_name))); } else { log::warning("user", t("Password reset failed for %user_name (has no email address on record).", array("user_name" => $user->name))); } } // Always pretend that an email has been sent to avoid leaking // information on what user names are actually real. message::success(t("Password reset email sent")); json::reply(array("result" => "success")); }
function __construct($path) { $chanbar = ' <ul> <li id="settings" class="option"><a href="#" class="button">settings</a></li> <li id="files" class="option"><a href="#" class="button">files</a></li> <li id="people" class="option"><a href="#" class="button">people</a></li> </ul> '; $user = Auth::user(); $curchan = DB::get()->val('SELECT name from channels where user_id = :user_id AND active = 1', array('user_id' => $user->id)); if ($curchan == '') { $curchan = 'bar'; } $widgets = Widgets::get_widgets(); $components = array('title' => 'Barchat Home', 'path' => $path, 'chanbar' => $chanbar, 'user_id' => Auth::user_id(), 'username' => $user->username, 'nickname' => $user->nickname, 'session_key' => $user->session_key, 'cur_chan' => addslashes($curchan), 'widgets' => $widgets); $v = new View($components); Plugin::call('reload', $user); //check for user agent $useragent = $_SERVER['HTTP_USER_AGENT']; // if (preg_match('/ip(hone|od|ad)/i', $useragent)) { $v->render('template-ios'); } else { $v->render('template'); } }
private function _send_reset() { $form = $this->_reset_form(); $valid = $form->validate(); if ($valid) { $user = user::lookup_by_name($form->reset->inputs["name"]->value); if (!$user->loaded || empty($user->email)) { $form->reset->inputs["name"]->add_error("no_email", 1); $valid = false; } } if ($valid) { $user->hash = md5(rand()); $user->save(); $message = new View("reset_password.html"); $message->confirm_url = url::abs_site("password/do_reset?key={$user->hash}"); $message->user = $user; Sendmail::factory()->to($user->email)->subject(t("Password Reset Request"))->header("Mime-Version", "1.0")->header("Content-type", "text/html; charset=iso-8859-1")->message($message->render())->send(); log::success("user", t("Password reset email sent for user %name", array("name" => $user->name))); } else { // Don't include the username here until you're sure that it's XSS safe log::warning("user", "Password reset email requested for bogus user"); } message::success(t("Password reset email sent")); print json_encode(array("result" => "success")); }
public function actionUser() { $view = new View(); $view->addBufferMain('admin'); $view->addBuffers('user'); $view->renderBuffer(); }
function items($name = '', $version = '') { $data['inventory_items'] = array(); $data['name'] = 'No item'; if ($name) { $name = rawurldecode($name); $inventory_item_obj = new Inventory_model(); $data['name'] = $name; if ($version) { $version = rawurldecode($version); $items = $inventory_item_obj->retrieve_many('name = ? AND version = ?', array($name, $version)); } else { $items = $inventory_item_obj->retrieve_many('name = ?', array($name)); } foreach ($items as $item) { $machine = new Machine_model($item->serial); $reportdata = new Reportdata_model($item->serial); $instance['serial'] = $item->serial; $instance['hostname'] = $machine->computer_name; $instance['username'] = $reportdata->console_user; $instance['version'] = $item->version; $instance['bundleid'] = $item->bundleid; $instance['bundlename'] = $item->bundlename; $instance['path'] = $item->path; $data['inventory_items'][] = $instance; } } $obj = new View(); $obj->view('inventory/inventoryitem_detail', $data); }
/** * Adds header. * * @param string $class * * @return View */ public function addHeader($class = 'Menu_Objective') { $this->header_wrap = $this->add('View', null, 'Header', array('layout/fluid', 'Header')); /** @type View $this->header_wrap */ $this->header = $this->header_wrap->add($class, null, 'Header_Content'); return $this->header; }
public function delete() { if (!$this->request->is('post')) { $response['success'] = false; $response['error'] = __('Sorry, an error has occured.<br />Please try again.'); } else { $conditions = array('Subscription.feed_id' => $this->request->query['id'], 'Subscription.user_id' => $this->request->query['user']); $subscription = $this->Subscription->find('first', array('conditions' => $conditions)); if (!$subscription) { $response['success'] = false; $response['error'] = __('Sorry, an error has occured.<br />Please try again.'); } else { $this->Subscription->id = $subscription['Subscription']['id']; if ($this->Subscription->delete()) { $response['success'] = true; } else { $response['success'] = false; $response['error'] = __('Sorry, an error has occured.<br />Please try again.'); } } } $view = new View($this->controller, false); $view->layout = 'ajax'; $view->set('data', $response); $html = $view->render('/Shared/json/data'); echo $html; die; }
/** * Demonstrates how to use views inside of views. */ function template() { $data = array('title' => 'View-in-View Example', 'content' => 'This is my view-in-view page content.', 'copyright' => '© 2007 Kohana Team'); $view = new View('viewinview/container', $data); $view->header = new View('viewinview/header', $data); $view->render(TRUE); }
/** * Methode : page envoyer le mailing */ public function envoyer() { if ($_POST) { $texte = $this->input->post('texte'); $format = $this->input->post('format'); $sujet = $this->input->post('sujet'); $format = $format == 1 ? TRUE : FALSE; $users = $this->user->select(); $nbr_envois = 0; foreach ($users as $user) { if ($format) { $view = new View('mailing/template'); $view->name = ucfirst(mb_strtolower($user->username)); $view->content = $texte; $message = $view->render(); } else { $message = $texte; } if (email::send($user->email, Kohana::config('email.from'), $sujet, $message, $format)) { $nbr_envois++; } } return url::redirect('mailing?msg=' . urlencode(Kohana::lang('mailing.send_valide', number_format($nbr_envois)))); } else { return parent::redirect_erreur('mailing'); } }
function run() { $router = new Router(); try { /** @var RouterResult $result */ $result = $router->process($this->config['routes']); $actionName = $result->getActionName(); $controllerName = $result->getControllerName(); $params = $result->getParams(); /** @var Controller $controller */ $controller = new $controllerName(); $controller->setParams($params); if ($controller instanceof \Framework\Config\ConfigAwareInterface) { $controller->setConfig($this->config); } $viewData = $controller->{$actionName}(); if ($controller->getUseTemplate() == true) { $template = $result->getController() . '/' . $result->getAction(); $useLayout = $controller->getUseLayout(); $view = new View(); $view->display($viewData, $template, $useLayout); } } catch (Exception\NotFoundException $e) { header("HTTP/1.0 404 Not Found"); $message = $this->config['environment'] === \Framework\App::DEVELOPMENT_ENVIRONMENT ? 'Page Not Found' : $e->getMessage(); $view = new View(); $view->display(['message' => $message], 'error/error'); } catch (Exception\BaseException $e) { header("HTTP/1.0 500 Internal Server Error"); $message = $this->config['environment'] === \Framework\App::DEVELOPMENT_ENVIRONMENT ? 'Internal Server Error' : $e->getMessage(); $view = new View(); $view->display(['message' => $message], 'error/error'); } }
function build() { $result=''; $rendered=''; $resultfilter = new $this->filter_class(); $resultfilter->controller = $this->controller; $resultfilter->datasource = $this->datasource; foreach($this->controller->appmeta->filter as $field => $filter) { if ($filter->hidden != 'true') { $resultfilter->clear(); $resultfilter->field = $field; $resultfilter->datasource = $this->datasource; $resultfilter->init(); $rendered .= $resultfilter->build(); } } if (!empty($this->container_template)) { $view=new View($this->container_template,$this->controller); $result=$view->render(array('meta'=>$this->controller->appmeta, 'control' => $this, 'content' => $rendered)); } else { $result=$rendered; } return $result; }
function items($name = '', $payload = '') { // Protect this handler if (!$this->authorized()) { redirect('auth/login'); } $data['profile_items'] = array(); $data['name'] = 'No item'; if ($name) { $name = rawurldecode($name); $profile_item_obj = new Profile_model(); $data['profile_name'] = $name; if ($payload) { $payload = rawurldecode($payload); $items = $profile_item_obj->retrieve_many('payload_name = ? GROUP BY serial_number', array($payload)); $data['name'] = $payload; } else { $items = $profile_item_obj->retrieve_many('profile_name = ? GROUP BY serial_number', array($name)); $data['name'] = $name; } foreach ($items as $item) { $machine = new Machine_model($item->serial_number); $instance['serial'] = $item->serial_number; $instance['hostname'] = $machine->computer_name; $instance['payload'] = $item->profile_name; $data['profile_items'][] = $instance; } } $obj = new View(); $obj->view('profile/profileitem_detail', $data); }
/** * Checks whether the response was cached and set the body accordingly. * * @param CakeEvent $event containing the request and response object * @return CakeResponse with cached content if found, null otherwise */ public function beforeDispatch(CakeEvent $event) { if (Configure::read('Cache.check') !== true) { return; } $path = $event->data['request']->here(); if ($path === '/') { $path = 'home'; } $prefix = Configure::read('Cache.viewPrefix'); if ($prefix) { $path = $prefix . '_' . $path; } $path = strtolower(Inflector::slug($path)); $filename = CACHE . 'views' . DS . $path . '.php'; if (!file_exists($filename)) { $filename = CACHE . 'views' . DS . $path . '_index.php'; } if (file_exists($filename)) { $controller = null; $view = new View($controller); $result = $view->renderCache($filename, microtime(true)); if ($result !== false) { $event->stopPropagation(); $event->data['response']->body($result); return $event->data['response']; } } }
public function display() { $view = new View(); $view->setTemplate('navBar'); $view->assign('active', $this->active); return $view->loadTemplate(); }
public function main() { //Create a new view and pass it our template $view = new View(strtolower($this->viewfile)); //Assign Page Variable $view->assign('var1', 'About page variable.'); }
/** * Generates a model for a given schema * * @usage ./metal model/create --database=default --schema=public --table=user --related * @switch database The name of the database in the conf file * @switch schema The name of the schema, default is 'public' * @switch table The name of the table to generate the model for * @switch related Boolean determines if any related models should be generated. */ public function create() { $db = Database::Get($this->request->input->database); $schemaName = $this->request->input->schema ? $this->request->input->schema : 'public'; $schema = $db->table($schemaName, $this->request->input->table, $this->request->input->related); $rel_classname = ''; $names = explode('_', $this->request->input->table); foreach ($names as $n) { $rel_classname .= ucfirst($n); } $view = new View('index.html', $this, PATH_SYS . 'shell/view/model/'); $model = $view->render(array('classname' => $rel_classname, 'schema' => $schema, 'database' => $this->request->input->database)); $path = PATH_APP . 'model/' . $schemaName; if (!file_exists($path)) { mkdir($path); } file_put_contents($path . '/' . $schema->tablename . EXT, $model); foreach ($schema->related as $table) { $rel_classname = ''; $names = explode('_', $table->tablename); foreach ($names as $n) { $rel_classname .= ucfirst($n); } $model = $view->render(array('classname' => $rel_classname, 'schema' => $table, 'database' => $this->request->input->database)); $path = PATH_APP . 'model/' . $table->schema; if (!file_exists($path)) { mkdir($path); } file_put_contents($path . '/' . $table->tablename . EXT, $model); } die; }
public function actionShowLesson() { $auth = Auth::checkAuth(); $view = new View(); $view->auth = $auth; if (!isset($_GET['id'])) { header("Location: /learns/"); } if ($auth) { $user = Auth::getUser(); $id = $_GET['id']; $lesson = Lessons::getLesson($id); $course = Courses::getCourse($lesson->course_id); $lesson_prew = Lessons::getLessonByNumber($lesson->lesson_number - 1, $lesson->course_id); $lesson_next = Lessons::getLessonByNumber($lesson->lesson_number + 1, $lesson->course_id); $view->user_login = $user->user_login; $view->user_group = $user->user_group; $view->lesson = $lesson; $view->course = $course; $view->lesson_prew = $lesson_prew; $view->lesson_next = $lesson_next; $view->display('header.php'); $view->display('lessons/lesson_view.php'); $view->display('footer.php'); } else { header("Location: /learns/"); } }
/** * index method */ public function index() { if ($this->param['method'] == 'POST') { $result = null; switch ($this->param['action']) { case 'create': $result = $this->transaction('create', $_POST); break; case 'modify': $result = $this->transaction('modify', $_POST); break; case 'remove': $result = $this->transaction('remove', $_POST); break; case 'sort': $result = $this->transaction('sort', $_POST); break; } if ($result) { Module::afterAction($result); } Goose::end(); } else { require_once __GOOSE_PWD__ . $this->path . 'view.class.php'; $view = new View($this); $view->render(); } }
/** * This little guy will add the UI to the /reports page so we can switch between AND and OR */ public function _add_report_filter_ui() { $operator = $this->_get_logical_operator(); $view = new View('adminmap/report_filter_ui'); $view->operator = $operator; $view->render(true); }
function run($action = 'main', $layout = 'layout') { $db = new Db(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); if(substr($action, -1) == '/') { // remove last slash if exists $action = substr($action, 0, -1); } $action = str_replace('/', '_', $action); $controller = WWW_ROOT . '/controllers/' . $action . '.php'; if(strcmp(realpath($controller), $_SERVER['DOCUMENT_WWW_ROOT'])) { $view = new View($action, $layout); if(isset($_SESSION['user'])) { $user = $_SESSION['user']; $view->set('user', $user); } if(is_file($controller)) { include($controller); } else { $view->changeAction('404'); } $view->set('user', $user); $view->display(); } else { trigger_error('Hacker attack from IP:' . $_SERVER['REMOTE_ADDR']); die(); } }
public function index($feedtype = 'rss2') { if (!Kohana::config('settings.allow_feed')) { throw new Kohana_404_Exception(); } if ($feedtype != 'atom' and $feedtype != 'rss2') { throw new Kohana_404_Exception(); } $feedpath = $feedtype == 'atom' ? 'feed/atom/' : 'feed/'; $site_url = url::base(); $incidents = ORM::factory('incident')->where('incident_active', '1')->orderby('incident_date', 'desc')->limit(20)->find_all(); $items = array(); foreach ($incidents as $incident) { $item = array(); $item['title'] = $incident->incident_title; $item['link'] = $site_url . 'reports/view/' . $incident->id; $item['description'] = $incident->incident_description; $item['date'] = $incident->incident_date; if ($incident->location_id != 0 and $incident->location->longitude and $incident->location->latitude) { $item['point'] = array($incident->location->latitude, $incident->location->longitude); $items[] = $item; } } header("Content-Type: text/xml; charset=utf-8"); $view = new View('feed_' . $feedtype); $view->feed_title = htmlspecialchars(Kohana::config('settings.site_name')); $view->site_url = $site_url; $view->georss = 1; // this adds georss namespace in the feed $view->feed_url = $site_url . $feedpath; $view->feed_date = gmdate("D, d M Y H:i:s T", time()); $view->feed_description = 'Incident feed for ' . Kohana::config('settings.site_name'); $view->items = $items; $view->render(TRUE); }
public static function run($uri) { self::$router = new Router($uri); self::$db = new DB(Config::get('db.host'), Config::get('db.user'), Config::get('db.password'), Config::get('db.db_name')); Lang::load(self::$router->getLanguage()); $controller_class = ucfirst(self::$router->getController()) . 'Controller'; $controller_method = strtolower(self::$router->getMethodPrefix() . self::$router->getAction()); $layout = self::$router->getRoute(); if ($layout == 'user' && Session::get('role') != 'user') { if ($controller_method != 'login') { Router::redirect('/users/login'); } } elseif ($layout == 'admin' && Session::get('role') != 'admin') { if ($controller_method != 'admin_login') { Router::redirect('/admin/users/login'); } } $controller_object = new $controller_class(); if (method_exists($controller_object, $controller_method)) { $view_path = $controller_object->{$controller_method}(); $view_object = new View($controller_object->getData(), $view_path); $content = $view_object->render(); } else { throw new Exception('Method ' . $controller_method . ' of class ' . $controller_class . ' does not exist.'); } $layout_path = VIEWS_PATH . DS . $layout . '.html'; $layout_view_object = new View(compact('content'), $layout_path); echo $layout_view_object->render(); }
public function delete($id) { $inscription = $this->Inscription->findSingleRowBy(["IDINSCRIPTION" => $id]); $idclasse = $inscription['IDCLASSE']; if ($this->Inscription->delete($id)) { # Supprimer les notes qu'il a eu lorsqu'il etai inscrit dans # cette classe /*$this->Note->deleteNoteByDesinscription($inscription['ANNEEACADEMIQUE'], $inscription['IDELEVE']);*/ $json = array(); $elevesinscrits = $this->Inscription->getInscrits($idclasse, $this->session->anneeacademique); $view = new View(); $view->Assign("eleves", $elevesinscrits); $json[0] = $view->Render("classe" . DS . "ajax" . DS . "eleve", false); //Liste des eleves non inscrits mis a jour $elevesnoninscripts = $this->Inscription->getNonInscrits($this->session->anneeacademique); $comboEleve = new Combobox($elevesnoninscripts, "listeeleve", "IDELEVE", "CNOM"); $view->Assign("comboEleves", $comboEleve->view()); $json[1] = $view->Render("classe" . DS . "ajax" . DS . "dialog-1", false); } else { $json[0] = "Erreur de suppression"; $json[1] = new Combobox(NULL, "listeeleve", "IDELEVE", "CNOM"); } echo json_encode($json); }