示例#1
0
 /**
  * Create new view.
  *
  * @param  Model_Flyer  $flyer
  */
 public function __construct(Model_Flyer $flyer)
 {
     parent::__construct();
     $this->flyer = $flyer;
     $this->image = $flyer->image();
     $this->event = $flyer->event();
     $this->title = HTML::chars($this->event ? $this->event->name : $flyer->name);
 }
示例#2
0
 /**
  * Get newsfeed item as HTML
  *
  * @param   Model_NewsfeedItem  $item
  * @return  string
  */
 public static function get(Model_NewsfeedItem $item)
 {
     $text = '';
     switch ($item->type) {
         case self::TYPE_COMMENT:
             $gallery = Model_Gallery::factory($item->data['gallery_id']);
             $image = Model_Image::factory($item->data['image_id']);
             if ($gallery->loaded() && $image->loaded()) {
                 $text = __('commented to an image<br />:gallery', array(':gallery' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), '<i class="icon-camera icon-white"></i> ' . HTML::chars($gallery->name), array('class' => 'hoverable'))));
             }
             break;
         case self::TYPE_COMMENT_FLYER:
             $flyer = Model_Flyer::factory($item->data['flyer_id']);
             if ($flyer->loaded()) {
                 $text = __('commented to a flyer<br />:flyer', array(':flyer' => HTML::anchor(Route::url('flyer', array('id' => $flyer->id)), '<i class="icon-picture icon-white"></i> ' . ($flyer->name ? HTML::chars($flyer->name) : __('flyer')), array('class' => 'hoverable'))));
             }
             break;
         case self::TYPE_FLYER_EDIT:
             $flyer = Model_Flyer::factory($item->data['flyer_id']);
             if ($flyer->loaded()) {
                 $text = __('updated flyer<br />:flyer', array(':flyer' => HTML::anchor(Route::url('flyer', array('id' => $flyer->id)), '<i class="icon-picture icon-white"></i> ' . ($flyer->name ? HTML::chars($flyer->name) : __('flyer')), array('class' => 'hoverable'))));
             }
             break;
         case self::TYPE_NOTE:
             $gallery = Model_Gallery::factory($item->data['gallery_id']);
             $image = Model_Image::factory($item->data['image_id']);
             $user = Model_User::find_user($item->data['user_id']);
             if ($gallery->loaded() && $image->loaded() && $user->loaded()) {
                 $text = __('tagged :user to an image<br />:gallery', array(':user' => HTML::user($user), ':gallery' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), '<i class="icon-tag icon-white"></i> ' . HTML::chars($gallery->name), array('class' => 'hoverable'))));
             }
             break;
     }
     return $text;
 }
示例#3
0
文件: full.php 项目: anqh/anqh
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        ?>

<div class="image">
	<figure>

		<?php 
        echo HTML::image($this->flyer->image_url());
        ?>

	</figure>
</div>

<?php 
        return ob_get_clean();
    }
示例#4
0
 /**
  * Get side image.
  *
  * @param   Model_Event  $event
  * @return  View_Generic_SideImage
  */
 protected function section_event_image(Model_Event $event)
 {
     // Display front flyer by default
     if ($image = $event->flyer_front()) {
         $flyer = Model_Flyer::factory()->find_by_image($image->id);
         $link = Route::model($flyer);
     } else {
         if ($image = $event->flyer_back()) {
             $flyer = Model_Flyer::factory()->find_by_image($image->id);
             $link = Route::model($flyer);
         } else {
             if (count($flyers = $event->flyers())) {
                 $flyer = $flyers[0];
                 $image = $flyer->image();
                 $link = Route::model($flyer);
             } else {
                 $image = null;
                 $link = null;
             }
         }
     }
     return new View_Generic_SideImage($image, $link);
 }
示例#5
0
文件: event.php 项目: anqh/events
 /**
  * Get event flyers.
  *
  * @return  Model_Flyer[]
  */
 public function flyers()
 {
     return Model_Flyer::factory()->find_by_event($this->id);
 }
示例#6
0
文件: galleries.php 项目: anqh/anqh
 /**
  * Set flyer page actions.
  *
  * @param  Model_Flyer  $flyer
  */
 protected function _set_flyer_actions(Model_Flyer $flyer = null)
 {
     $this->view->tabs[] = array('link' => Route::get('flyer')->uri(array('id' => 'undated')), 'text' => '<i class="icon-random"></i> ' . __('Random undated flyer'));
     $this->view->tabs[] = array('link' => Route::get('flyer')->uri(array('id' => 'random')), 'text' => '<i class="icon-random"></i> ' . __('Random flyer'));
     if ($flyer) {
         // Set browse flyers to
         if ($flyer->stamp_begin) {
             $this->view->tabs['flyers']['link'] = $flyer->has_full_date() ? Route::url('flyers', array('year' => date('Y', $flyer->stamp_begin), 'month' => date('n', $flyer->stamp_begin))) : Route::url('flyers', array('year' => date('Y', $flyer->stamp_begin)));
         }
         Route::url('flyers', array('action' => '', 'year' => date('Y', $flyer->stamp_begin), 'month' => date('m', $flyer->stamp_begin)));
         if ($event = $flyer->event()) {
             $this->view->tabs[] = array('link' => Route::model($event), 'text' => '<i class="icon-calendar"></i> ' . __('Event') . ' &raquo;');
         }
     }
 }
示例#7
0
文件: events.php 项目: anqh/events
 /**
  * Get side image.
  *
  * @param   Model_Event  $event
  * @return  View_Generic_SideImage
  */
 protected function section_event_image(Model_Event $event)
 {
     // Display front flyer by default
     if ($image = $event->flyer_front()) {
         $flyer = Model_Flyer::factory()->find_by_image($image->id);
         $link = Route::model($flyer);
     } else {
         if ($image = $event->flyer_back()) {
             $flyer = Model_Flyer::factory()->find_by_image($image->id);
             $link = Route::model($flyer);
         } else {
             if (count($flyers = $event->flyers())) {
                 $flyer = $flyers[0];
                 $image = $flyer->image();
                 $link = Route::model($flyer);
             } else {
                 $image = null;
                 $link = null;
             }
         }
     }
     if (Permission::has($event, Model_User::PERMISSION_UPDATE, self::$user)) {
         $uri = Route::model($event, 'image');
         $actions = array();
         $actions[] = HTML::anchor($uri, '<i class="icon-plus-sign icon-white"></i> ' . __('Add flyer'), array('class' => 'btn btn-small btn-primary image-add ajaxify'));
         if ($image) {
             $actions[] = HTML::anchor($uri . '?token=' . Security::csrf() . '&front=' . $image->id, __('As front'), array('class' => 'btn btn-small btn-inverse image-change' . ($event->flyer_front_image_id == $image->id ? ' disabled' : ''), 'data-change' => 'front'));
             $actions[] = HTML::anchor($uri . '?token=' . Security::csrf() . '&back=' . $image->id, __('As back'), array('class' => 'btn btn-small btn-inverse image-change' . ($event->flyer_back_image_id == $image->id ? ' disabled' : ''), 'data-change' => 'back'));
             $actions[] = HTML::anchor($uri . '?token=' . Security::csrf() . '&delete=' . $image->id, '<i class="icon-trash"></i> ' . __('Delete'), array('class' => 'btn btn-small btn-inverse image-delete'));
         }
     } else {
         $actions = null;
     }
     $section = new View_Generic_SideImage($image, $link);
     $section->actions = $actions;
     return $section;
 }
示例#8
0
文件: galleries.php 项目: anqh/anqh
 /**
  * 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) {
         // Image
         case self::TYPE_COMMENT:
         case self::TYPE_NOTE:
             $gallery = Model_Gallery::factory($item->data['gallery_id']);
             $image = Model_Image::factory($item->data['image_id']);
             if ($gallery->loaded() && $image->loaded()) {
                 $text = HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), '<i class="fa fa-camera-retro"></i> ' . HTML::chars($gallery->name), array('class' => 'hoverable'));
             }
             break;
             // Flyer
         // Flyer
         case self::TYPE_COMMENT_FLYER:
         case self::TYPE_FLYER_EDIT:
             $flyer = Model_Flyer::factory($item->data['flyer_id']);
             if ($flyer->loaded()) {
                 $text = HTML::anchor(Route::url('flyer', array('id' => $flyer->id)), '<i class="fa fa-picture"></i> ' . ($flyer->name ? HTML::chars($flyer->name) : __('flyer')), array('class' => 'hoverable'));
             }
             break;
             // Gallery
         // Gallery
         case self::TYPE_UPLOAD:
             $gallery = Model_Gallery::factory($item->data['gallery_id']);
             if ($gallery->loaded()) {
                 $text = HTML::anchor(Route::model($gallery), '<i class="fa fa-camera-retro"></i> ' . HTML::chars($gallery->name), array('class' => 'hoverable'));
             }
             break;
     }
     return $text;
 }
示例#9
0
文件: events.php 项目: anqh/anqh
 /**
  * Edit event
  *
  * @param  integer  $event_id
  */
 protected function _edit_event($event_id = null)
 {
     $this->history = false;
     if ($event_id) {
         // Editing old
         $event = Model_Event::factory($event_id);
         if (!$event->loaded()) {
             throw new Model_Exception($event, $event_id);
         }
         Permission::required($event, Model_Event::PERMISSION_UPDATE);
         $cancel = Request::back(Route::model($event), true);
         $this->view = View_Page::factory(HTML::chars($event->name));
         // Set actions
         if (Permission::has($event, Model_Event::PERMISSION_DELETE)) {
             $this->view->actions[] = array('link' => Route::model($event, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="fa fa-trash-o"></i> ' . __('Delete event'), 'class' => 'btn-danger event-delete');
         }
         $edit = true;
         $event->update_count++;
         $event->modified = time();
     } else {
         // Creating new
         $event = new Model_Event();
         Permission::required($event, Model_Event::PERMISSION_CREATE);
         $cancel = Request::back(Route::get('events')->uri(), true);
         $this->view = View_Page::factory(__('New event'));
         $event->author_id = Visitor::$user->id;
         $event->created = time();
         $edit = false;
     }
     // Handle post
     if ($_POST && Security::csrf_valid()) {
         $preview = isset($_POST['preview']);
         // Handle venue
         if ($venue_hidden = Arr::get($_POST, 'venue_hidden')) {
             // Hidden events require only city
         } else {
             if ($venue_id = (int) Arr::get_once($_POST, 'venue_id')) {
                 // Old venue
                 $venue = Model_Venue::factory($venue_id);
             } else {
                 if ($venue_name = Arr::get($_POST, 'venue_name')) {
                     // Check for duplicate venue
                     $venues = Model_Venue::factory()->find_by_name($venue_name);
                     if ($venues->count()) {
                         $city_name = strtolower(Arr::get($_POST, 'city_name'));
                         foreach ($venues as $venue_old) {
                             if (strtolower($venue_old->city_name) == $city_name) {
                                 $venue = $venue_old;
                                 break;
                             }
                         }
                     }
                 }
             }
         }
         $post = Arr::intersect($_POST, Model_Event::$editable_fields);
         if (isset($post['stamp_begin']['date']) && isset($post['stamp_end']['time']) && !isset($post['stamp_end']['date'])) {
             $post['stamp_end']['date'] = $post['stamp_begin']['date'];
         }
         $event->set_fields($post);
         if (Arr::get($_POST, 'free')) {
             $event->price = 0;
         }
         // Venue/location
         $event->venue_hidden = (bool) $venue_hidden;
         if ($venue_hidden) {
             // Hidden events don't have a venue
             $event->venue_id = null;
             $event->venue_name = null;
         } else {
             if (isset($venue)) {
                 // Venue loaded
                 $event->venue_id = $venue->id;
                 $event->city_name = $venue->city_name;
             } else {
                 if (!empty($venue_name)) {
                     // Create new venue
                     $venue = Model_Venue::factory();
                     $venue->name = Arr::get($_POST, 'venue_name');
                     $venue->address = Arr::get($_POST, 'address');
                     $venue->latitude = Arr::get($_POST, 'latitude');
                     $venue->longitude = Arr::get($_POST, 'longitude');
                     $venue->foursquare_id = Arr::get($_POST, 'foursquare_id');
                     $venue->event_host = true;
                     $venue->author_id = Visitor::$user->id;
                     $venue->city_name = $event->city_name;
                     if (!$preview) {
                         try {
                             $venue->save();
                             $event->venue_id = $venue->id;
                         } catch (Validation_Exception $venue_validation) {
                         }
                     }
                 }
             }
         }
         // Validate event
         try {
             $event->is_valid();
         } catch (Validation_Exception $event_validation) {
         }
         // Handle preview request
         if ($preview) {
             if ($this->ajax) {
                 $preview = '<p>' . self::_event_subtitle($event) . '</p>';
                 $preview .= '<div id="main" class="col-md-8">';
                 $preview .= $this->section_event_main($event);
                 $preview .= '<hr></div>';
                 $this->response->body($preview);
             }
             return;
         }
         // Flyer
         if ($flyer_url = Arr::get($_POST, 'flyer')) {
             $event->flyer_url = $flyer_url;
             $image = new Model_Image();
             $image->remote = $flyer_url;
             $image->created = time();
             $image->author_id = Visitor::$user->id;
             try {
                 $image->save();
                 try {
                     $flyer = new Model_Flyer();
                     $flyer->set_fields(array('image_id' => $image->id, 'name' => $event->name, 'stamp_begin' => $event->stamp_begin));
                     $flyer->save();
                 } catch (Validation_Exception $flyer_validation) {
                     $flyer_error = print_r($flyer_validation->array->errors('validation'), true);
                 }
             } catch (Validation_Exception $image_validation) {
                 $flyer_error = print_r($image_validation->array->errors('validation'), true);
             } catch (Kohana_Exception $e) {
                 $flyer_error = $e->getMessage();
             }
         }
         // If no errors found, save
         if (!isset($venue_validation) && !isset($event_validation) && !isset($flyer_error)) {
             // Make sure end time is after start time, i.e. the next day
             if ($event->stamp_end < $event->stamp_begin) {
                 $event->stamp_end += Date::DAY;
             }
             $event->save();
             // Handle flyer
             if (isset($image) && isset($flyer) && $flyer->loaded()) {
                 $flyer->event_id = $event->id;
                 $flyer->save();
                 $event->set_flyer($flyer);
                 $event->save();
             }
             // Set tags
             $event->set_tags(Arr::get($_POST, 'tag'));
             if ($edit) {
                 // Don't flood edits right after save
                 if (time() - $event->created > 60 * 30) {
                     NewsfeedItem_Events::event_edit(Visitor::$user, $event);
                 }
             } else {
                 NewsfeedItem_Events::event(Visitor::$user, $event);
                 // Add to favorites
                 $event->add_favorite(Visitor::$user);
                 // Create forum topic
                 if ($event->add_forum_topic()) {
                     Visitor::$user->post_count++;
                     Visitor::$user->save();
                 }
             }
             $this->request->redirect(Route::model($event));
         }
     }
     // Remove orphan flyer on all errors
     if (isset($flyer)) {
         $flyer->delete();
     } else {
         if (isset($image)) {
             $image->delete();
         }
     }
     // Tags
     $tags = array();
     $tag_group = new Model_Tag_Group('Music');
     if ($tag_group->loaded() && count($tag_group->tags())) {
         foreach ($tag_group->tags() as $tag) {
             $tags[$tag->id()] = $tag->name();
         }
     }
     // Form
     $section = $this->section_event_edit($event);
     $section->event_errors = isset($event_validation) ? $event_validation->array->errors('validation') : null;
     $section->flyer_error = isset($flyer_error) ? $flyer_error : null;
     $section->venue = isset($venue) ? $venue : $event->venue;
     $section->venue_errors = isset($venue_validation) ? $venue_validation->array->errors('validation') : null;
     $section->cancel = $cancel;
     $this->view->add(View_Page::COLUMN_TOP, $section);
 }
示例#10
0
文件: core.php 项目: anqh/core
 /**
  * Get user's new comment counts.
  *
  * @param   Model_User  $user
  * @return  array
  */
 public static function notifications(Model_User $user)
 {
     $new = array();
     // Profile comments
     if ($user->new_comment_count) {
         $new['new-comments'] = HTML::anchor(URL::user($user), '<i class="icon-comment icon-white"></i> ' . $user->new_comment_count, array('class' => 'badge badge-info', 'title' => __('New comments')));
     }
     // Forum private messages
     $private_messages = Forum::find_new_private_messages($user);
     if (count($private_messages)) {
         $new_messages = 0;
         foreach ($private_messages as $private_message) {
             $new_messages += $private_message->unread;
         }
         $new['new-private-messages'] = HTML::anchor(Route::model($private_message->topic()) . '?page=last#last', '<i class="icon-comment icon-white"></i> ' . $new_messages, array('class' => 'badge badge-info', 'title' => __('New private messages')));
     }
     unset($private_messages);
     // Blog comments
     $blog_comments = Model_Blog_Entry::factory()->find_new_comments($user);
     if (count($blog_comments)) {
         $new_comments = 0;
         foreach ($blog_comments as $blog_entry) {
             $new_comments += $blog_entry->new_comment_count;
         }
         $new['new-blog-comments'] = HTML::anchor(Route::model($blog_entry), '<i class="icon-comment icon-white"></i> ' . $new_comments, array('class' => 'badge badge-info', 'title' => __('New blog comments')));
     }
     unset($blog_comments);
     // Forum quotes
     $forum_quotes = Model_Forum_Quote::factory()->find_by_user($user);
     if (count($forum_quotes)) {
         $new_quotes = count($forum_quotes);
         $quote = $forum_quotes->current();
         $new['new-forum-quotes'] = HTML::anchor(Route::get('forum_post')->uri(array('topic_id' => $quote->forum_topic_id, 'id' => $quote->forum_post_id)) . '#post-' . $quote->forum_post_id, '<i class="icon-comment icon-white"></i> ' . $new_quotes, array('class' => 'badge badge-info', 'title' => __('Forum quotes')));
     }
     // Images waiting for approval
     if (Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_APPROVE_WAITING, $user)) {
         $gallery_approvals = Model_Gallery::factory()->find_pending(Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_APPROVE, $user) ? null : $user);
         if (count($gallery_approvals)) {
             $new_approvals = count($gallery_approvals);
             $new['new-gallery-approvals'] = HTML::anchor(Route::get('galleries')->uri(array('action' => 'approval')), '<i class="icon-exclamation-sign icon-white"></i> ' . $new_approvals, array('class' => 'badge badge-warning', 'title' => __('Galleries waiting for approval')));
         }
     }
     // Flyer comments
     $flyer_comments = Model_Flyer::factory()->find_new_comments($user);
     $flyers = array();
     if (count($flyer_comments)) {
         $new_comments = 0;
         foreach ($flyer_comments as $flyer) {
             $flyers[$flyer->image_id] = true;
             $new_comments += $flyer->image()->new_comment_count;
         }
         $new['new-flyer-comments'] = HTML::anchor(Route::get('flyer')->uri(array('id' => $flyer->id, 'action' => '')), '<i class="icon-picture icon-white"></i> ' . $new_comments, array('class' => 'badge badge-info', 'title' => __('New flyer comments')));
     }
     unset($flyer_comments);
     // Image comments
     $image_comments = Model_Image::factory()->find_new_comments($user);
     $note_comments = Model_Image_Note::factory()->find_new_comments($user);
     if (count($image_comments) || count($note_comments)) {
         $new_comments = 0;
         $new_image = null;
         foreach ($image_comments as $image) {
             // @TODO: Until flyer comments are fixed..
             if (!isset($flyers[$image->id])) {
                 $new_comments += $image->new_comment_count;
                 $new_image_id = $image->id;
             }
         }
         foreach ($note_comments as $note) {
             $new_comments += $note->new_comment_count;
             $new_image_id = $note->image_id;
         }
         if ($new_comments) {
             $new['new-image-comments'] = HTML::anchor(Route::get('gallery_image')->uri(array('gallery_id' => Route::model_id(Model_Gallery::find_by_image($new_image_id)), 'id' => $new_image_id, 'action' => '')), '<i class="icon-camera icon-white"></i> ' . $new_comments, array('class' => 'badge badge-info', 'title' => __('New image comments')));
         }
     }
     unset($image_comments, $note_comments, $new_image);
     // Image tags
     $notes = Model_Image_Note::factory()->find_new_notes($user);
     if (count($notes)) {
         $new_notes = 0;
         $new_note_image_id = null;
         /** @var  Model_Image_Note  $note */
         foreach ($notes as $note) {
             $new_notes++;
             $new_note_image_id = $note->image_id;
         }
         if ($new_notes) {
             $new['new-image-notes'] = HTML::anchor(Route::get('gallery_image')->uri(array('gallery_id' => Route::model_id(Model_Gallery::find_by_image($new_note_image_id)), 'id' => $new_note_image_id, 'action' => '')), '<i class="icon-tag icon-white"></i> ' . $new_notes, array('class' => 'badge badge-info', 'title' => __('New image tags')));
         }
     }
     unset($note_comments, $new_note_image_id);
     return $new;
 }