/** * Get newsfeed item as HTML * * @static * @param Model_NewsfeedItem $item * @return string */ public static function get(Model_NewsFeedItem $item) { $text = ''; switch ($item->type) { case self::TYPE_EVENT: $event = Model_Event::factory($item->data['event_id']); if ($event->loaded()) { $text = __('added new event<br />:event', array(':event' => HTML::anchor(Route::model($event), '<i class="icon-calendar icon-white"></i> ' . HTML::chars($event->name), array('class' => 'hoverable')))); } break; case self::TYPE_EVENT_EDIT: $event = Model_Event::factory($item->data['event_id']); if ($event->loaded()) { $text = __('updated event<br />:event', array(':event' => HTML::anchor(Route::model($event), '<i class="icon-calendar icon-white"></i> ' . HTML::chars($event->name), array('class' => 'hoverable')))); } break; case self::TYPE_FAVORITE: $event = Model_Event::factory($item->data['event_id']); if ($event->loaded()) { $text = __('added event to favorites<br />:event', array(':event' => HTML::anchor(Route::model($event), '<i class="icon-heart icon-white"></i> ' . HTML::chars($event->name), array('class' => 'hoverable')))); } break; } return $text; }
/** * Get event attached to gallery. * * @return Model_Event */ public function event() { try { return $this->event_id ? Model_Event::factory($this->event_id) : null; } catch (AutoModeler_Exception $e) { return null; } }
/** * Get anchor to newsfeed item target. * * @static * @param Model_NewsfeedItem $item * @return string */ public static function get_link(Model_NewsfeedItem $item) { $text = ''; switch ($item->type) { case self::TYPE_EVENT: case self::TYPE_EVENT_EDIT: case self::TYPE_FAVORITE: $event = Model_Event::factory($item->data['event_id']); if ($event->loaded()) { $text = HTML::anchor(Route::model($event), '<i class="fa fa-calendar"></i> ' . HTML::chars($event->name), array('class' => 'hoverable')); } break; } return $text; }
/** * Action: event */ public function action_event() { $event_id = (int) $this->request->param('id'); $event = Model_Event::factory($event_id); if (!$event->loaded()) { throw new Model_Exception($event, $event_id); } // Redirect if ($topic = Model_Forum_Topic::factory()->find_by_bind($event, 'events')) { // Topic existing $this->request->redirect(Route::model($topic)); } else { // @todo Create new topic $this->request->redirect(Route::get('forum')->uri()); } }
/** * Action: event */ public function action_event() { $event_id = (int) $this->request->param('id'); $event = Model_Event::factory($event_id); if (!$event->loaded()) { throw new Model_Exception($event, $event_id); } // Go to before or after event discussion? $time = $this->request->param('time'); if (!$time) { $time = $event->stamp_begin > time() ? 'before' : 'after'; } $bind = $time == 'before' ? 'events_upcoming' : 'events_past'; // Redirect if ($topic = Model_Forum_Topic::factory()->find_by_bind($event, $bind)) { // Topic existing $this->request->redirect(Route::model($topic)); } else { // @todo Create new topic $this->request->redirect(Route::get('forum')->uri()); } }
/** * Get gallery edit form. * * @param Model_Event $event Bound event, if any * @return View_Gallery_Edit */ public function section_gallery_edit(Model_Event $event = null) { $section = new View_Gallery_Edit($event); // Add suggestions if creating new if (!$event) { $events = Model_Event::factory()->find_favorites_past(self::$user, 10); if ($events && count($events)) { $section->events = $events; } } return $section; }
/** * Get favorite events timeline. * * @param Model_User $user * @return View_Events_Timeline */ public function section_favorites(Model_User $user) { $upcoming = Model_Event::factory()->find_favorites_upcoming($user, 0, 'DESC'); $past = Model_Event::factory()->find_favorites_past($user, 0); $favorites = array(); foreach ($upcoming as $event) { $favorites[] = $event; } foreach ($past as $event) { $favorites[] = $event; } return new View_Events_Timeline($favorites); }
/** * Find upcoming events at venue. * * @param integer $limit * @return Database_Result */ public function find_events_upcoming($limit = 25) { return $this->find_related('event', DB::select_array(Model_Event::factory()->fields())->where('stamp_begin', '>=', strtotime('today'))->order_by('stamp_begin', 'DESC')->limit($limit)); }
/** * Destroy controller */ public function after() { if ($this->ajax || $this->internal) { // AJAX and HMVC requests $this->response->body($this->response->body() . ''); } else { if ($this->auto_render) { // Normal requests $session = Session::instance(); // Save current URI /* Moved to Controller if ($this->history && $this->response->status() < 400) { $uri = $this->request->current_uri(); unset($this->breadcrumb[$uri]); $this->breadcrumb = array_slice($this->breadcrumb, -9, 9, true); $this->breadcrumb[$uri] = $this->page_title; $session ->set('history', $uri . ($_GET ? URL::query($_GET) : '')) ->set('breadcrumb', $this->breadcrumb); } */ // Controller name as the default page id if none set empty($this->page_id) and $this->page_id = $this->request->controller(); // Stylesheets $styles = array('ui/boot.css' => null, 'ui/typo.css' => null, 'ui/base.css' => null, 'ui/jquery-ui.css' => null, 'http://fonts.googleapis.com/css?family=Nobile:regular,bold' => null); // Generic views Widget::add('breadcrumb', View::factory('generic/breadcrumb', array('breadcrumb' => $this->breadcrumb, 'last' => !$this->history))); Widget::add('actions', View::factory('generic/actions', array('actions' => $this->page_actions))); Widget::add('navigation', View::factory('generic/navigation', array('items' => Kohana::$config->load('site.menu'), 'selected' => $this->page_id))); if (!empty($this->tabs)) { Widget::add('subnavigation', View::factory('generic/navigation', array('items' => $this->tabs, 'selected' => $this->tab_id))); } /* Widget::add('tabs', View::factory('generic/tabs_top', array( 'tabs' => $this->tabs, 'selected' => $this->tab_id ))); */ // Footer Widget::add('footer', View_Module::factory('events/event_list', array('mod_id' => 'footer-events-new', 'mod_class' => 'article grid4 first cut events', 'mod_title' => __('New events'), 'events' => Model_Event::factory()->find_new(10)))); Widget::add('footer', View_Module::factory('forum/topiclist', array('mod_id' => 'footer-topics-active', 'mod_class' => 'article grid4 cut topics', 'mod_title' => __('New posts'), 'topics' => Model_Forum_Topic::factory()->find_by_latest_post(10)))); Widget::add('footer', View_Module::factory('blog/entry_list', array('mod_id' => 'footer-blog-entries', 'mod_class' => 'article grid4 cut blogentries', 'mod_title' => __('New blogs'), 'entries' => Model_Blog_Entry::factory()->find_new(10)))); // Skin $skins = Kohana::$config->load('site.skins'); $skin = 'dark'; //$session->get('skin', 'dark'); $skin_imports = array('ui/mixin.less', 'ui/grid.less', 'ui/layout.less', 'ui/widget.less', 'ui/custom.less'); // Dock $classes = array(); foreach ($skins as $skin_name => &$skin_config) { $skin_config['path'] = 'ui/' . $skin_name . '/skin.less'; $classes[] = HTML::anchor(Route::get('setting')->uri(array('action' => 'skin', 'value' => $skin_name)), $skin_config['name'], array('class' => 'theme', 'rel' => $skin_name)); } //Widget::add('dock', __('Theme') . ': ' . implode(', ', $classes)); // Language selection $available_languages = Kohana::$config->load('locale.languages'); if (count($available_languages)) { $languages = array(); foreach ($available_languages as $lang => $locale) { $languages[] = HTML::anchor('set/lang/' . $lang, HTML::chars($locale[2])); } // Widget::add('dock', ' | ' . __('Language: ') . implode(', ', $languages)); } // Search /* Widget::add('search', View_Module::factory('generic/search', array( 'mod_id' => 'search' ))); */ // Visitor card Widget::add('visitor', View::factory('generic/visitor', array('user' => self::$user))); // Time & weather Widget::add('dock', ' | ' . View::factory('generic/clock', array('user' => self::$user))); // Pin Widget::add('dock', ' | ' . HTML::anchor('#pin', '▲', array('title' => __('Lock menu'), 'class' => 'icon unlock', 'onclick' => '$("#header").toggleClass("pinned"); return false;'))); // End Widget::add('end', View::factory('generic/end')); // Analytics if ($google_analytics = Kohana::$config->load('site.google_analytics')) { Widget::add('head', HTML::script_source("\nvar tracker;\nhead.js(\n\t{ 'google-analytics': 'http://www.google-analytics.com/ga.js' },\n\tfunction() {\n\t\ttracker = _gat._getTracker('" . $google_analytics . "');\n\t\ttracker._trackPageview();\n\t}\n);\n")); } // Open Graph $og = array(); foreach ((array) Anqh::open_graph() as $key => $value) { $og[] = '<meta property="' . $key . '" content="' . HTML::chars($value) . '" />'; } if (!empty($og)) { Widget::add('head', implode("\n", $og)); } // Share if (Anqh::share()) { if ($share = Kohana::$config->load('site.share')) { // 3rd party share Widget::add('share', View_Module::factory('share/share', array('mod_class' => 'like', 'id' => $share))); Widget::add('foot', View::factory('share/foot', array('id' => $share))); } else { if ($facebook = Kohana::$config->load('site.facebook')) { // Facebook Like Widget::add('share', View_Module::factory('facebook/like')); Widget::add('ad_top', View::factory('facebook/connect', array('id' => $facebook))); } } } // Ads $ads = Kohana::$config->load('site.ads'); if ($ads && $ads['enabled']) { foreach ($ads['slots'] as $ad => $slot) { Widget::add($slot, View::factory('ads/' . $ad), Widget::MIDDLE); } } // And finally the profiler stats if (self::$user && self::$user->has_role('admin')) { //in_array(Kohana::$environment, array(Kohana::DEVELOPMENT, Kohana::TESTING))) { Widget::add('foot', View::factory('generic/debug')); Widget::add('foot', View::factory('profiler/stats')); } // Do some CSS magic to page class $page_class = explode(' ', $this->language . ' ' . $session->get('page_width', 'fixed') . ' ' . $session->get('page_main', 'left') . ' ' . $this->request->action() . ' ' . $this->page_class); // Controller set classes $page_class = implode(' ', array_unique(array_map('trim', $page_class))); // Bind the generic page variables $this->template->set('styles', $styles)->set('skin', $skin)->set('skins', $skins)->set('skin_imports', $skin_imports)->set('language', $this->language)->set('page_id', $this->page_id)->set('page_class', $page_class)->set('page_title', $this->page_title)->set('page_subtitle', $this->page_subtitle); // Add statistics $queries = 0; if (Kohana::$profiling) { foreach (Profiler::groups() as $group => $benchmarks) { if (strpos($group, 'database') === 0) { $queries += count($benchmarks); } } } $total = array('{memory_usage}' => number_format((memory_get_peak_usage() - KOHANA_START_MEMORY) / 1024, 2) . 'KB', '{execution_time}' => number_format(microtime(true) - KOHANA_START_TIME, 5), '{database_queries}' => $queries, '{included_files}' => count(get_included_files())); $this->template = strtr($this->template, $total); // Render page if ($this->auto_render === true) { $this->response->body($this->template); } } } return parent::after(); }
/** * Get events. * * @return View_Events_List */ public function section_events_updated() { $section = new View_Events_List(); $section->title = __('Updated events'); $section->events = Model_Event::factory()->find_modified(10); return $section; }
/** * Destroy controller. */ public function after() { if ($this->_request_type !== Controller::REQUEST_INITIAL) { // AJAX and HMVC requests $this->response->body((string) $this->response->body()); } else { if ($this->auto_render) { // Normal requests // Footer $section = new View_Events_List(); $section->class .= ' col-sm-4'; $section->title = __('New events'); $section->events = Model_Event::factory()->find_new(10); $this->view->add(View_Page::COLUMN_FOOTER, $section); $section = new View_Topics_List(); $section->class .= ' col-sm-4'; $section->topics = Model_Forum_Topic::factory()->find_by_latest_post(10); $this->view->add(View_Page::COLUMN_FOOTER, $section); $section = new View_Blogs_List(); $section->class .= ' col-sm-4'; $section->title = __('New blogs'); $section->blog_entries = Model_Blog_Entry::factory()->find_new(10); $this->view->add(View_Page::COLUMN_FOOTER, $section); // Ads /* $ads = Kohana::$config->load('site.ads'); if ($ads && $ads['enabled']) { foreach ($ads['slots'] as $ad => $slot) { if ($slot == 'side') { $this->view->add(View_Page::COLUMN_SIDE, View::factory('ads/' . $ad)); } else { Widget::add($slot, View::factory('ads/' . $ad), Widget::MIDDLE); } } }*/ // Theme $theme = $this->session->get('theme'); //Arr::get($_COOKIE, 'theme'); if (!in_array($theme, array_keys(Kohana::$config->load('site.themes')))) { if (Visitor::$user) { $theme = Visitor::$user->setting('ui.theme'); } if (!$theme) { $theme = Kohana::$config->load('site.theme'); } $this->session->set('theme', $theme); } // Do some CSS magic to page class $page_class = array_merge(array('theme-' . $theme, Visitor::$user ? 'authenticated' : 'unauthenticated'), explode(' ', $this->page_class)); $page_class = implode(' ', array_unique($page_class)); // Set the generic page variables $this->view->language = $this->language; $this->view->id = $this->page_id; $this->view->class = $page_class; if ($this->page_actions) { $this->view->tabs = $this->page_actions; } if ($this->page_breadcrumbs) { $this->view->breadcrumbs = $this->page_breadcrumbs; } // Set meta data if (!Anqh::page_meta('title')) { Anqh::page_meta('title', $this->view->title ? $this->view->title : Kohana::$config->load('site.site_name')); } // And finally the profiler stats if (Visitor::$user && Visitor::$user->has_role('admin')) { Widget::add('foot', new View_Generic_Debug()); Widget::add('foot', View::factory('profiler/stats')); } } } parent::after(); }
/** * Destroy controller. */ public function after() { if ($this->_request_type !== Controller::REQUEST_INITIAL) { // AJAX and HMVC requests $this->response->body((string) $this->response->body()); } else { if ($this->auto_render) { // Normal requests // Stylesheets $styles = array('ui/jquery-ui.css', 'http://fonts.googleapis.com/css?family=Terminal+Dosis'); // Skins $selected_skin = $this->session->get('skin', 'blue'); // Less files needed to build a skin $less_imports = array('ui/mixin.less', 'ui/anqh.less'); $skins = array(HTML::style('static/css/bootstrap.css'), HTML::style('static/css/bootstrap-responsive.css')); foreach (array('blue') as $skin) { $skinsi[] = Less::style('ui/' . $skin . '.less', array('title' => $skin, 'rel' => $skin == $selected_skin ? 'stylesheet' : 'alternate stylesheet'), false, $less_imports); } // Footer $section = new View_Events_List(); $section->class .= ' span4'; $section->title = __('New events'); $section->events = Model_Event::factory()->find_new(10); Widget::add('footer', $section); $section = new View_Topics_List(); $section->class .= ' span4'; $section->title = __('New posts'); $section->topics = Model_Forum_Topic::factory()->find_by_latest_post(10); Widget::add('footer', $section); $section = new View_Blogs_List(); $section->class .= ' span4'; $section->title = __('New blogs'); $section->blog_entries = Model_Blog_Entry::factory()->find_new(10); Widget::add('footer', $section); // Open Graph $og = array(); foreach ((array) Anqh::open_graph() as $key => $value) { $og[] = '<meta property="' . $key . '" content="' . HTML::chars($value) . '" />'; } if (!empty($og)) { Widget::add('head', implode("\n", $og)); } // Analytics if ($google_analytics = Kohana::$config->load('site.google_analytics')) { Widget::add('head', HTML::script_source("\nvar tracker;\nhead.js(\n\t{ 'google-analytics': 'http://www.google-analytics.com/ga.js' },\n\tfunction() {\n\t\ttracker = _gat._getTracker('" . $google_analytics . "');\n\t\ttracker._trackPageview();\n\t}\n);\n")); } // Ads /* $ads = Kohana::$config->load('site.ads'); if ($ads && $ads['enabled']) { foreach ($ads['slots'] as $ad => $slot) { if ($slot == 'side') { $this->view->add(View_Page::COLUMN_SIDE, View::factory('ads/' . $ad)); } else { Widget::add($slot, View::factory('ads/' . $ad), Widget::MIDDLE); } } }*/ // Do some CSS magic to page class $page_class = array_merge(array($this->language, $this->request->action(), self::$user ? 'authenticated' : 'unauthenticated'), explode(' ', $this->page_class)); $page_class = implode(' ', array_unique($page_class)); // Set the generic page variables $this->view->styles = $styles; $this->view->skins = $skins; $this->view->language = $this->language; $this->view->id = $this->page_id; $this->view->class = $page_class; if ($this->page_actions) { $this->view->tabs = $this->page_actions; } if ($this->page_breadcrumbs) { $this->view->breadcrumbs = $this->page_breadcrumbs; } // And finally the profiler stats if (self::$user && self::$user->has_role('admin')) { //in_array(Kohana::$environment, array(Kohana::DEVELOPMENT, Kohana::TESTING))) { Widget::add('foot', View::factory('generic/debug')); Widget::add('foot', View::factory('profiler/stats')); } } } parent::after(); }