/** * Get newsfeed item as HTML * * @param Newsfeed_Model $item * @return string */ public static function get(NewsFeedItem_Model $item) { $text = ''; switch ($item->type) { case self::TYPE_COMMENT: $gallery = new Gallery_Model($item->data['gallery_id']); $image = new Image_Model($item->data['image_id']); if ($gallery->loaded() && $image->loaded()) { $text = __('commented to an image in :gallery', array(':gallery' => html::anchor(url::model($gallery) . '/' . $image->id, text::title($gallery->name), array('title' => $gallery->name)))); } break; } return $text; }
/** * Get newsfeed item as HTML * * @param Newsfeed_Model $item * @return string */ public static function get(NewsFeedItem_Model $item) { $text = ''; switch ($item->type) { case self::TYPE_EVENT: $event = new Event_Model($item->data['event_id']); if ($event->id) { $text = __('added new event :event', array(':event' => html::anchor(url::model($event), text::title($event->name), array('title' => $event->name)))); } break; case self::TYPE_FAVORITE: $event = new Event_Model($item->data['event_id']); if ($event->id) { $text = __('added event :event to favorites', array(':event' => html::anchor(url::model($event), text::title($event->name), array('title' => $event->name)))); } break; } return $text; }
/** * Get newsfeed item as HTML * * @param Newsfeed_Model $item * @return string */ public static function get(NewsFeedItem_Model $item) { $text = ''; switch ($item->type) { case self::TYPE_COMMENT: $entry = new Blog_Entry_Model($item->data['entry_id']); if ($entry->id) { $text = __('commented to blog :blog', array(':blog' => html::anchor(url::model($entry), text::title($entry->name), array('title' => $entry->name)))); } break; case self::TYPE_ENTRY: $entry = new Blog_Entry_Model($item->data['entry_id']); if ($entry->id) { $text = __('wrote a new blog entry :blog', array(':blog' => html::anchor(url::model($entry), text::title($entry->name), array('title' => $entry->name)))); } break; } return $text; }
/** * Get newsfeed item as HTML * * @param Newsfeed_Model $item * @return string */ public static function get(NewsFeedItem_Model $item) { $text = ''; switch ($item->type) { case self::TYPE_REPLY: $topic = new Forum_Topic_Model($item->data['topic_id']); if ($topic->id) { $text = __('replied to topic :topic', array(':topic' => html::anchor(url::model($topic) . '/page/last#last', text::title($topic->name), array('title' => $topic->name)))); } break; case self::TYPE_TOPIC: $topic = new Forum_Topic_Model($item->data['topic_id']); if ($topic->id) { $text = __('started a new topic :topic', array(':topic' => html::anchor(url::model($topic), text::title($topic->name), array('title' => $topic->name)))); } break; } return $text; }
</h3> <sup><?php echo $venue_category->description; ?> </sup> <ul> <?php $city_id = false; foreach ($venue_category->venues->find_all() as $venue) { if ($venue->city_id == $city_id) { continue; } $city_id = $venue->city_id; ?> <li><?php echo html::anchor(url::model($venue_category) . '#' . utf8::strtolower($venue->city->city), $venue->city->city); ?> </li> <?php } ?> </ul> </li> <?php } ?> </ul> </div> </section>
<?php if ($event->price !== null && $event->price != -1) { ?> <span class="details price"><?php echo $event->price == 0 ? __('Free entry') : '<var>' . format::money($event->price, $event->country->currencycode) . '</var>'; ?> </span> <?php } ?> <?php if ($event->venue_id) { ?> <span class="details venue">@ <?php echo html::anchor(url::model($event->venue), $event->venue->name); ?> , <?php echo html::chars($event->venue->city->city); ?> </span> <?php } elseif ($event->venue_name || $event->city_name) { ?> <span class="details venue">@ <?php echo html::chars($event->venue_name) . ($event->venue_name && $event->city_name ? ', ' : '') . html::chars($event->city_name); ?> </span> <?php } ?>
?> <ul> <?php foreach ($galleries as $gallery) { ?> <li class="unit size1of2"> <div class="thumb unit size2of5"> <?php echo html::anchor(url::model($gallery), html::image('http://' . Kohana::config('site.image_server') . '/kuvat/' . $gallery->dir . '/thumb_' . $gallery->default_image->legacy_filename)); ?> </div> <header> <h4><?php echo html::anchor(url::model($gallery), text::title($gallery->name)); ?> </h4> <span class="details"> <?php echo html::time(date::format('DMYYYY', $gallery->event_date), $gallery->event_date, true); ?> , <?php echo __2(':images image', ':images images', $gallery->image_count, array(':images' => '<var>' . $gallery->image_count . '</var>')); ?> </span> </header> </li> <?php }
* @package Anqh * @author Antti Qvickström * @copyright (c) 2010 Antti Qvickström * @license http://www.opensource.org/licenses/mit-license.php MIT license */ ?> <?php if (empty($tags)) { ?> <div class="notice"><?php echo Kohana::lang('tags.error_no_tags_found'); ?> </div> <?php } else { ?> <ul> <?php foreach ($tags as $tag) { ?> <li><?php echo html::anchor(url::model($tag), $tag->name); ?> </li> <?php } ?> </ul> <?php }
<li class="unit size1of2"><?php echo html::icon_value(array(':topics' => $area->topics), ':topics topic', ':topics topics', 'topics'); ?> </li> <li class="unit size1of2"><?php echo html::icon_value(array(':posts' => $area->posts), ':posts post', ':posts posts', 'posts'); ?> </li> </ul> </header> <footer> <?php if ($area->topics > 0) { ?> <?php echo __('Last post in :area by :user :ago ago', array(':area' => html::anchor(url::model($area->last_topic) . '/page/last#last', text::limit_chars(text::title($area->last_topic->name), 20, '…', true), array('title' => html::specialchars($area->last_topic->name))), ':user' => html::user(null, $area->last_topic->last_poster), ':ago' => html::time(date::timespan_short($area->last_topic->last_posted), $area->last_topic->last_posted))); ?> <?php } else { ?> <sup><?php echo __('No topics found'); ?> </sup> <?php } ?> </footer> </article> <?php
<article class="venue venue-<?php echo $venue->id; ?> "> <header> <h4><?php echo html::anchor(url::model($venue), $venue->name); ?> </h4> </header> <footer> <?php if ($venue->default_image_id) { ?> <?php echo html::anchor(url::model($venue), html::img($venue->default_image, 'thumb'), array('style' => 'display:block;height:31px;')); ?> <?php } ?> </footer> </article>
<ul class="contentlist favorites events"> <?php foreach ($favorites as $favorite) { ?> <li class="event-<?php echo $favorite->id; ?> "> <?php echo date::format('DDMMYYYY', $favorite->start_time); ?> <?php echo html::anchor(url::model($favorite), text::title($favorite->name), array('title' => html::specialchars($favorite->name))); ?> </li> <?php } ?> </ul>
/** * Handle forum quotations * * @param BBCode $bbcode * @param string $action * @param string $name * @param string $default * @param array $params * @param string $content * @return string */ public function bbcode_quote($bbcode, $action, $name, $default, $params, $content) { // Pass all to 2nd phase if ($action == BBCODE_CHECK) { return true; } // Parse parameters foreach ($params['_params'] as $param) { switch ($param['key']) { // Parent post id case 'post': $post_id = (int) $param['value']; $post = ORM::factory('forum_post', $post_id); break; // Parent post author // Parent post author case 'author': $author_name = $param['value']; $author = ORM::factory('user')->find_user($author_name); break; } } // Add parent post if (isset($post) && $post->id) { $quote = '<blockquote cite="' . url::model($post->forum_topic) . '/' . $post->id . '#post-' . $post->id . '">'; // Override author $author = $post->author; } else { $quote = '<blockquote>'; } $quote .= '<p>' . trim($content) . '</p>'; // Post author if (isset($author) && $author->id) { $quote .= '<cite>' . __('-- :author', array(':author' => html::user($author))) . '</cite>'; } else { if (isset($author_name)) { $quote .= '<cite>' . __('-- :author', array(':author' => html::specialchars($author_name))) . '</cite>'; } } $quote .= '</blockquote>'; return $quote; }
/** * Edit event * * @param int|string $event_id */ public function _event_edit($event_id = false) { $this->history = false; $event = new Event_Model((int) $event_id); // For authenticated users only if (!$this->user || !$event->is_author() && !$this->visitor->logged_in(array('admin', 'event moderator'))) { url::back('/events'); } $errors = $form_errors = array(); $form_values = $event->as_array(); $form_values['start_date'] = ''; $form_values['start_hour'] = ''; $form_values['end_hour'] = ''; /***** CHECK POST *****/ if (request::method() == 'post') { $post = array_merge($this->input->post(), $_FILES); $extra = array('start_time' => date::unix2sql(strtotime($post['start_date'] . ' ' . date::time_24h($post['start_hour'])))); if (!empty($post['end_hour'])) { $end_time = strtotime($post['start_date']); // end hour is earlier than start hour = event ends the next day if ($post['end_hour'] < $post['start_hour']) { $end_time = strtotime('+1 day', $end_time); } $extra['end_time'] = date('Y-m-d', $end_time) . ' ' . date::time_24h($post['end_hour']) . ':00'; } // update $editing = (bool) $event->id; if ($editing) { $extra['modified'] = date::unix2sql(time()); $extra['modifies'] = (int) $event->modifies + 1; } else { $extra['author_id'] = $this->user->id; } $city = ORM::factory('city', $post['city_id']); if ($city) { $extra['country_id'] = $city->country_id; } if (csrf::valid() && $event->validate($post, true, $extra)) { // Update tags $event->remove(ORM::factory('tag')); if (!empty($post['tags'])) { foreach ($post['tags'] as $tag_id => $tag) { $event->add(ORM::factory('tag', $tag_id)); } $event->save(); } // Handle flyer uploads foreach (array('flyer_front_image_id' => $post->flyer_front, 'flyer_back_image_id' => $post->flyer_back) as $image_id => $flyer) { if (isset($flyer) && empty($flyer['error'])) { $image = Image_Model::factory('events.flyer', $flyer, $this->user->id); if ($image->id) { $event->add($image); $event->{$image_id} = $image->id; $event->save(); } } } if (!$editing) { newsfeeditem_events::event($this->user, $event); } url::redirect(url::model($event)); } else { $form_errors = $post->errors(); } $form_values = arr::overwrite($form_values, $post->as_array()); } /***** /CHECK POST *****/ /***** SHOW FORM *****/ if ($event->id) { $this->page_actions[] = array('link' => url::model($event) . '/delete/?token=' . csrf::token(), 'text' => __('Delete event'), 'class' => 'event-delete'); $this->page_title = text::title($event->name); $this->page_subtitle = __('Edit event'); list($form_values['start_date'], $form_values['start_hour']) = explode(' ', date('Y-m-d H', strtotime($event->start_time))); if (!empty($event->end_time)) { list($temp, $form_values['end_hour']) = explode(' ', date('Y-m-d H', strtotime($event->end_time))); } } else { $this->page_title = __('New event'); } $form = $event->get_form(); // Tags if ($tag_group = Kohana::config('events.tag_group')) { $form['tags'] = $form_values['tags'] = array(); $tags = ORM::factory('tag_group', $tag_group); foreach ($tags->tags as $tag) { $form['tags'][$tag->id] = $tag->name; if ($event->has($tag)) { $form_values['tags'][$tag->id] = $tag->name; } } } // City autocomplete $this->_autocomplete_city('city_name'); // Venue autocomplete $venues = ORM::factory('venue')->where('event_host', '=', 1)->find_all(); $hosts = array(); foreach ($venues as $venue) { $hosts[] = "{ id: '" . $venue->id . "', text: '" . html::chars($venue->name) . "' }"; } widget::add('foot', html::script_source('var venues = [' . implode(', ', $hosts) . "];\n\$('input[name=venue_name]').autocomplete(venues, {\n\tformatItem: function(item) {\n\t\treturn item.text;\n\t}\n}).result(function(event, item) {\n\t\$('input[name=venue_id]').val(item.id);\n});")); // Date pickers widget::add('foot', html::script_source("\$('input#start_date').datepicker({ dateFormat: 'd.m.yy', firstDay: 1, changeFirstDay: false, showOtherMonths: true, showWeeks: true, showStatus: true, showOn: 'both' });")); if (empty($errors)) { widget::add('main', View::factory('events/event_edit', array('form' => $form, 'values' => $form_values, 'errors' => $form_errors))); } else { // $this->_error(Kohana::lang('generic.error'), $errors); } /***** /SHOW FORM *****/ $this->_side_views(); }
<li class="group"> <h5><?php echo html::anchor(url::model($group), text::title($group->name)); ?> </h5> <ul class="areas"> <?php foreach ($group->forum_areas->find_all() as $area) { ?> <?php if ($area->has_access(Forum_Area_Model::ACCESS_READ)) { ?> <li><?php echo html::anchor(url::model($area), text::title($area->name), array('title' => strip_tags($area->description))); ?> </li> <?php } ?> <?php } ?> </ul> </li> <?php } ?>
} ?> </nav> <?php if ($next) { ?> <?php echo html::anchor(url::model($gallery) . '/' . $next->id, html::image('http://' . Kohana::config('site.image_server') . '/kuvat/' . $gallery->dir . '/pieni_' . $image->legacy_filename), array('title' => __('Next image'))); ?> <?php } else { ?> <?php echo html::anchor(url::model($gallery), html::image('http://' . Kohana::config('site.image_server') . '/kuvat/' . $gallery->dir . '/pieni_' . $image->legacy_filename), array('title' => __('Back to gallery'))); ?> <?php } ?> <?php if ($image->description) { ?> <?php $names = array(); foreach (explode(',', $image->description) as $name) { $names[] = html::user(trim($name)); } ?> <footer>
/** * Edit tag * * @param integer|string $tag_id * @param integer|string $group_id */ public function _tag_edit($tag_id = false, $group_id = false) { $this->history = false; // for authenticated users only if (!$this->user) { url::redirect('/tags'); } $errors = $form_errors = array(); $tag = new Tag_Model((int) $tag_id); $form_values = $tag->get_defaults(); // check post if (request::method() == 'post') { $post = $this->input->post(); $extra = array('author_id' => $this->user->id); if ($tag->validate($post, true, $extra)) { url::redirect(url::model($tag)); } else { $form_errors = $post->errors(); } $form_values = arr::overwrite($form_values, $post->as_array()); } // editing old? if ($tag_id) { $this->page_subtitle = __('Edit tag'); $this->breadcrumb[] = html::anchor(url::model($tag->tag_group), $tag->tag_group->name); $this->breadcrumb[] = html::anchor(url::model($tag), $tag->name); if ($this->visitor->logged_in('admin')) { $this->page_actions[] = array('link' => url::model($tag) . '/delete', 'text' => __('Delete tag'), 'class' => 'tag-delete'); } if (!$tag->id) { $errors = array('tags.error_tag_not_found'); } } else { $this->page_subtitle = __('Add tag'); if ($group_id) { $tag_group = new Tag_Group_Model((int) $group_id); $this->breadcrumb[] = html::anchor(url::model($tag_group), $tag_group->name); $this->breadcrumb[] = html::anchor(url::model($tag_group) . '/add', __('Add tag')); if ($tag_group->id) { $form_values['tag_group_id'] = $tag_group->id; } else { $errors = array('tags.error_tag_group_not_found'); } } } // show form if (empty($errors)) { widget::add('main', View_Mod::factory('tags/tag_edit', array('values' => $form_values, 'errors' => $form_errors))); } else { $this->_error(Kohana::lang('generic.error'), $errors); } $this->_side_views(); }
?> <?php if (empty($entries)) { ?> <span class="notice"><?php echo __('No blog entries found'); ?> </span> <?php } else { ?> <ul> <?php foreach ($entries as $entry) { ?> <li class="blogentry-<?php echo $entry->id; ?> "><?php echo html::anchor(url::model($entry), $entry->name); ?> </li> <?php } ?> </ul> <?php }
?> <?php if (empty($topics)) { ?> <span class="notice"><?php echo __('No topics found'); ?> </span> <?php } else { ?> <ul> <?php foreach ($topics as $topic) { ?> <li class="topic-<?php echo $topic->id; ?> "><?php echo html::anchor(url::model($topic) . '/page/last#last', $topic->name); ?> </li> <?php } ?> </ul> <?php }
/** * Edit venue * * @param integer|string $venue_id * @param integer|string $category_id */ public function _venue_edit($venue_id = false, $category_id = false) { $this->history = false; $venue = new Venue_Model((int) $venue_id); // Check access if (!($venue->loaded() && $venue->has_access(Venue_Model::ACCESS_EDIT)) && !(!$venue->loaded() && $this->visitor->logged_in(array('admin', 'venue moderator', 'venue')))) { url::back('venues'); } $errors = $form_errors = array(); $form_values = $venue->as_array(); // check post if (request::method() == 'post') { $post = array_merge($this->input->post(), $_FILES); $extra = array('author_id' => $this->user->id); // got address, get geocode if (!empty($post['address']) && !empty($post['city_name'])) { list($extra['latitude'], $extra['longitude']) = Gmap::address_to_ll(implode(', ', array($post['address'], $post['zip'], $post['city_name']))); } if (csrf::valid() && $venue->validate($post, true, $extra)) { // handle logo upload if (isset($post->logo) && empty($post->logo['error'])) { $logo = Image_Model::factory('venues.logo', $post->logo, $this->user->id); if ($logo->id) { $venue->add($logo); $venue->default_image_id = $logo->id; $venue->save(); } } // handle picture uploads foreach (array($post->picture1, $post->picture2) as $picture) { if (isset($picture) && empty($picture['error'])) { $image = Image_Model::factory('venues.image', $picture, $this->user->id); if ($image->id) { $venue->add($image); $venue->save(); } } } // update tags $venue->remove(ORM::factory('tag')); if (!empty($post->tags)) { foreach ($post->tags as $tag_id => $tag) { $venue->add(ORM::factory('tag', $tag_id)); } } url::redirect(url::model($venue)); } else { $form_errors = $post->errors(); } $form_values = arr::overwrite($form_values, $post->as_array()); } // editing old? if ($venue_id) { if ($venue->has_access(Venue_Model::ACCESS_DELETE)) { $this->page_actions[] = array('link' => 'venue/' . url::title($venue->id, $venue->name) . '/delete/?token=' . csrf::token(), 'text' => __('Delete venue'), 'class' => 'venue-delete'); } $this->page_subtitle = __('Edit venue'); if (!$venue->id) { $errors = array('venues.error_venue_not_found'); } else { $venue_category = $venue->venue_category; } } else { $this->page_subtitle = __('Add venue'); if ($category_id) { $venue_category = new Venue_Category_Model((int) $category_id); if ($venue_category->id) { $form_values['venue_category_id'] = $venue_category->id; } else { $errors = array('venues.error_venue_category_not_found'); } } } $this->page_actions[] = array('link' => 'venue/' . url::title($venue->id, $venue->name), 'text' => __('Cancel'), 'class' => 'cancel'); $this->breadcrumb[] = html::anchor('/venues/' . url::title($venue_category->id, $venue_category->name), $venue_category->name); if ($venue->id) { $this->breadcrumb[] = html::anchor('/venue/' . url::title($venue->id, $venue->name), $venue->name); } // show form if (empty($errors)) { $form = array(); // tags if ($venue_category->tag_group_id) { $form['tags'] = $form_values['tags'] = array(); foreach ($venue_category->tag_group->tags as $tag) { $form['tags'][$tag->id] = $tag->name; if ($venue->has($tag)) { $form_values['tags'][$tag->id] = $tag->name; } } } $venue_categories = ORM::factory('venue_category')->find_all()->select_list('id', 'name'); $form['venue_category_id'] = $venue_categories; widget::add('main', View_Mod::factory('venues/venue_edit', array('form' => $form, 'values' => $form_values, 'errors' => $form_errors))); // city autocomplete $this->_autocomplete_city(); } else { $this->_error(Kohana::lang('generic.error'), $errors); } $this->_side_views(); }
/** * Edit entry * * @param integer|string $entry_id */ public function _entry_edit($entry_id = false) { $this->history = false; $entry = new Blog_Entry_Model((int) $entry_id); // For authenticated users only if (!$this->user || !$entry->is_author() && !$this->visitor->logged_in('admin')) { url::redirect(empty($_SESSION['history']) ? '/blogs' : $_SESSION['history']); } $errors = $form_errors = array(); $form_messages = ''; $form_values = $entry->as_array(); /***** CHECK POST *****/ if (request::method() == 'post') { $post = $this->input->post(); // update $editing = (bool) $entry->id; if ($editing) { $extra['modified'] = date::unix2sql(time()); $extra['modifies'] = (int) $entry->modifies + 1; } else { $extra['author_id'] = $this->user->id; } if ($entry->validate($post, true, $extra)) { // News feed event if (!$editing) { newsfeeditem_blog::entry($this->user, $entry); } url::redirect(url::model($entry)); } else { $form_errors = $post->errors(); $form_messages = $post->message(); } $form_values = arr::overwrite($form_values, $post->as_array()); } /***** /CHECK POST *****/ /***** SHOW FORM *****/ if ($entry->id) { $this->page_actions[] = array('link' => url::model($entry) . '/delete?token=' . csrf::token($this->user->id), 'text' => __('Delete entry'), 'class' => 'entry-delete'); $this->page_title = text::title($entry->name); $this->page_subtitle = __('Edit entry'); } else { $this->page_title = __('New entry'); } $form = $entry->get_form(); if (empty($errors)) { widget::add('head', html::script(array('js/jquery.markitup.pack.js', 'js/markitup.bbcode.js'))); widget::add('main', View::factory('blog/entry_edit', array('form' => $form, 'values' => $form_values, 'errors' => $form_errors, 'messages' => $form_messages))); } else { $this->_error(Kohana::lang('generic.error'), $errors); } /***** /SHOW FORM *****/ }
* @author Antti Qvickström * @copyright (c) 2010 Antti Qvickström * @license http://www.opensource.org/licenses/mit-license.php MIT license */ ?> <ul> <?php foreach ($gallery->find_images() as $image) { ?> <li class="unit size1of4"> <div class="thumb"> <?php echo html::anchor(url::model($gallery) . '/' . $image->id, html::image('http://' . Kohana::config('site.image_server') . '/kuvat/' . $gallery->dir . '/thumb_' . $image->legacy_filename), array('title' => html::chars($image->description))); ?> </div> <?php echo html::icon_value(array(':comments' => $image->comments), ':comments comment', ':comments comments', 'posts'); ?> <?php echo html::icon_value(array(':views' => $image->views), ':views view', ':views views', 'views'); ?> </li> <?php } ?> </ul>
if ($post->modifies > 0) { ?> <br /> <?php echo __('Edited :ago ago', array(':ago' => html::time(date::timespan_short($post->modified), $post->modified))); ?> <?php } ?> <?php if ($post->parent_id) { $parent_topic = $post->parent->forum_topic; ?> <br /> <?php echo __('Replying to :parent', array(':parent' => html::anchor(url::model($parent_topic) . '/' . $post->parent_id . '#post-' . $post->parent_id, text::title($parent_topic->name)))); ?> <?php } ?> </span> </header> <section class="post-content"> <?php echo BB::factory($post->post)->render(); ?> </section>
?> </h4> <ul class="details unit size1of6"> <!-- <li class="unit size1of2"><?php echo html::icon_value(array(':views' => $topic->reads), ':views view', ':views views', 'views'); ?> </li> --> <li class="unit size1of1"><?php echo html::icon_value(array(':replies' => $topic->posts - 1), ':replies reply', ':replies replies', 'posts'); ?> </li> </ul> </header> <footer> <?php if (isset($area)) { ?> <?php echo __('In :area.', array(':area' => html::anchor(url::model($topic->forum_area), text::title($topic->forum_area->name), array('title' => strip_tags($topic->forum_area->description))))); ?> <?php } ?> <?php echo __('Last post by :user :ago ago', array(':user' => html::nick(false, $topic->last_poster), ':ago' => html::time(date::timespan_short($topic->last_posted), $topic->last_posted))); ?> </footer> </article> <?php }
/** * Edit topic * * @param mixed $topic_id * @param mixed $area_id */ public function _topic_edit($topic_id, $area_id = false) { $this->history = false; $errors = array(); $forum_topic = new Forum_Topic_Model((int) $topic_id); $forum_area = $forum_topic->loaded() ? $forum_topic->forum_area : new Forum_Area_Model((int) $area_id); if ($forum_topic->loaded()) { // Editing topic $editing = true; if (!$forum_topic->has_access(Forum_Topic_Model::ACCESS_EDIT)) { url::back('forum'); } } else { if ($forum_area->loaded()) { // New topic $editing = false; if (!$forum_area->has_access(Forum_Area_Model::ACCESS_WRITE)) { url::back('forum'); } } else { // New topic in unknown area $errors[] = __('Area :area or topic :topic not found', array(':area' => (int) $area_id, ':topic' => (int) $topic_id)); } } if (empty($errors)) { $forum_post = new Forum_Post_Model((int) $forum_topic->first_post_id); $form_errors = array(); $form_values_topic = $forum_topic->as_array(); $form_values_post = $forum_post->as_array(); $form_topics = false; // Bound area? if ($forum_area->is_type(Forum_Area_Model::TYPE_BIND)) { // Get bind config and load topics $bind = Forum_Area_Model::binds($forum_area->bind); if ($editing) { // Can't edit bound topic $form_topics = array($forum_topic->bind_id => $forum_topic->name); } else { // Try to load options from configured model try { $bind_topics = ORM::factory($bind['model'])->find_bind_topics($forum_area->bind); $form_topics = array(0 => __('Choose..')) + $bind_topics; } catch (Kohana_Exception $e) { $form_topics = array(); } } } // Admin actions if ($editing && $forum_topic->has_access(Forum_Topic_Model::ACCESS_DELETE)) { $this->page_actions[] = array('link' => url::model($forum_topic) . '/delete/?token=' . csrf::token(), 'text' => __('Delete topic'), 'class' => 'topic-delete'); } // Check post if ($post = $this->input->post()) { $post['forum_area_id'] = $forum_area->id; $topic = $post; if (isset($bind_topics)) { $topic['name'] = arr::get($bind_topics, (int) $topic['bind_id'], ''); } $post_extra = $topic_extra = array('author_id' => $this->user->id, 'author_name' => $this->user->username); if ($editing) { $post_extra['modifies'] = (int) $forum_post->modifies + 1; $post_extra['modified'] = date::unix2sql(time()); } $post_extra['author_ip'] = $this->input->ip_address(); $post_extra['author_host'] = $this->input->host_name(); // validate post first and save topic if ok if (csrf::valid() && $forum_post->validate($post, false, $post_extra) && $forum_topic->validate($topic, true, $topic_extra)) { // post $forum_post->forum_topic_id = $forum_topic->id; $forum_post->save(); if (!$editing) { // topic $forum_topic->first_post_id = $forum_post->id; $forum_topic->last_post_id = $forum_post->id; $forum_topic->last_poster = $this->user->username; $forum_topic->last_posted = date::unix2sql(time()); $forum_topic->posts = 1; $forum_topic->save(); // area $forum_area->last_topic_id = $forum_topic->id; $forum_area->posts += 1; $forum_area->topics += 1; $forum_area->save(); // user $this->user->posts += 1; $this->user->save(); // News feed newsfeeditem_forum::topic($this->user, $forum_topic); } // redirect back to topic URL::redirect(url::model($forum_topic)); } else { $form_errors = array_merge($post->errors(), is_object($topic) ? $topic->errors() : array()); } $form_values_topic = arr::overwrite($form_values_topic, is_object($topic) ? $topic->as_array() : $topic); $form_values_post = arr::overwrite($form_values_post, $post->as_array()); } } // Show form if (empty($errors)) { $this->breadcrumb[] = html::anchor(url::model($forum_area), text::title($forum_area->name)); $this->page_title = $editing ? text::title($forum_topic->name) : __('New topic'); $this->page_subtitle = __('Area :area', array(':area' => html::anchor(url::model($forum_area), text::title($forum_area->name), array('title' => strip_tags($forum_area->description))))); widget::add('head', html::script(array('js/jquery.markitup.pack', 'js/markitup.bbcode'))); widget::add('main', View_Mod::factory('forum/topic_edit', array('topic' => $form_values_topic, 'topics' => $form_topics, 'post' => $form_values_post, 'errors' => $form_errors))); } else { $this->_error(__('Error'), $errors); } $this->_side_views(); }
* * @package Blog * @author Antti Qvickström * @copyright (c) 2010 Antti Qvickström * @license http://www.opensource.org/licenses/mit-license.php MIT license */ ?> <?php foreach ($entries as $entry) { ?> <article> <header> <?php echo html::avatar($entry->author->avatar, $entry->author->username); ?> <h4><?php echo html::anchor(url::model($entry), text::title($entry->name), array('title' => $entry->name)); ?> </h4> <span class="details"> <?php echo __('By :user :ago ago', array(':user' => html::user($entry->author), ':ago' => html::time(date::timespan_short($entry->created), $entry->created))); ?> </span> </header> </article> <?php }