コード例 #1
0
ファイル: user.php プロジェクト: anqh/anqh
 /**
  * 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_DEFAULT_IMAGE:
             $image = Model_Image::factory($item->data['image_id']);
             if ($image->loaded()) {
                 $text = __('changed their default image');
             }
             break;
         case self::TYPE_FRIEND:
             if ($item->is_aggregate()) {
                 if ($links = self::get_links($item)) {
                     $text = __('added :friends as friends', array(':friends' => Text::implode_and($links)));
                 }
             } else {
                 if ($link = self::get_link($item)) {
                     $text = __('added :friend as a friend', array(':friend' => $link));
                 }
             }
             break;
         case self::TYPE_LOGIN:
             $text = __('logged in');
             break;
     }
     return $text;
 }
コード例 #2
0
ファイル: galleries.php プロジェクト: anqh/galleries
 /**
  * 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
ファイル: comment.php プロジェクト: anqh/anqh
 /**
  * Get comment image
  *
  * @return  Model_Image
  */
 public function image()
 {
     try {
         return $this->image_id ? Model_Image::factory($this->image_id) : null;
     } catch (AutoModeler_Exception $e) {
         return null;
     }
 }
コード例 #4
0
ファイル: user.php プロジェクト: anqh/core
 /**
  * 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_DEFAULT_IMAGE:
             $image = Model_Image::factory($item->data['image_id']);
             if ($image->loaded()) {
                 $text = __('changed their default image');
             }
             break;
         case self::TYPE_FRIEND:
             $friend = Model_User::find_user($item->data['friend_id']);
             if ($friend->loaded()) {
                 $text = __('added :friend as a friend', array(':friend' => HTML::user($friend)));
             }
             break;
         case self::TYPE_LOGIN:
             $text = __('logged in');
             break;
     }
     return $text;
 }
コード例 #5
0
ファイル: galleries.php プロジェクト: anqh/anqh
 /**
  * Get notification as HTML.
  *
  * @static
  * @param   Model_Notification
  * @return  string
  */
 public static function get(Model_Notification $notification)
 {
     $text = '';
     switch ($notification->type) {
         case self::TYPE_IMAGE_COMMENT:
             $user = Model_User::find_user($notification->user_id);
             $image = Model_Image::factory($notification->data_id);
             if ($user->loaded() && $image->loaded()) {
                 $gallery = $image->gallery();
                 $text = __(':user commented your :photo: <em>:comment</em>', array(':user' => HTML::user($user), ':photo' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), __('photo'), array('class' => 'hoverable')), ':comment' => Text::smileys(Text::auto_link_urls(HTML::chars($notification->text)))));
             } else {
                 $notification->delete();
             }
             break;
         case self::TYPE_IMAGE_NOTE:
             $user = Model_User::find_user($notification->user_id);
             $image = Model_Image::factory($notification->data_id);
             if ($user->loaded() && $image->loaded()) {
                 $gallery = $image->gallery();
                 $text = __(':user tagged you to a :photo', array(':user' => HTML::user($user), ':photo' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), __('photo'), array('class' => 'hoverable'))));
             } else {
                 $notification->delete();
             }
             break;
         case self::TYPE_IMAGE_REPORT:
             $user = Model_User::find_user($notification->user_id);
             $image = Model_Image::factory($notification->data_id);
             if ($user->loaded() && $image->loaded()) {
                 $gallery = $image->gallery();
                 $text = __(':user reported a :photo: <em>:reason</em>', array(':user' => HTML::user($user), ':photo' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), __('photo'), array('class' => 'hoverable')), ':reason' => $notification->text ? HTML::chars($notification->text) : __('No reason')));
             } else {
                 $notification->delete();
             }
             break;
     }
     return $text;
 }
コード例 #6
0
ファイル: galleries.php プロジェクト: anqh/galleries
 /**
  * Action: upload
  */
 public function action_upload()
 {
     // Load existing gallery if any
     $gallery_id = (int) $this->request->param('gallery_id');
     if (!$gallery_id) {
         $gallery_id = (int) $this->request->param('id');
     }
     if ($gallery_id) {
         // Existing gallery
         $gallery = Model_Gallery::factory($gallery_id);
         if (!$gallery->loaded()) {
             throw new Model_Exception($gallery, $gallery_id);
         }
     } else {
         // New gallery
         return $this->_edit_gallery(null, Arr::get($_REQUEST, 'event'));
     }
     Permission::required(new Model_Gallery(), Model_Gallery::PERMISSION_UPLOAD, self::$user);
     // Handle post
     $errors = array();
     if ($_FILES) {
         $file = Arr::get($_FILES, 'file');
         if ($file) {
             // We need to flatten our file one level as ajax uploaded files are set up funnily.
             // Support for ajax uploads one by one for now..
             foreach ($file as $key => $value) {
                 is_array($value) and $file[$key] = $value[0];
             }
             // Needed for IE response
             if ($multiple = Arr::get($_REQUEST, 'multiple', false)) {
                 $this->auto_render = false;
             }
             // Upload info for JSON
             $info = new stdClass();
             $info->name = HTML::chars($file['name']);
             $info->size = intval($file['size']);
             // Save image
             try {
                 // Make sure we don't timeout. An external queue would be better thuough.
                 set_time_limit(0);
                 ignore_user_abort(true);
                 // Duplicate filename check
                 $uploaded = Session::instance()->get('uploaded', array());
                 if (isset($uploaded[$gallery->id]) && in_array($file['name'], $uploaded[$gallery->id])) {
                     throw new Kohana_Exception(__('Already uploaded'));
                 }
                 $image = Model_Image::factory();
                 $image->normal = 'wide';
                 $image->set_fields(array('author_id' => self::$user->id, 'file' => $file, 'status' => Model_Image::NOT_ACCEPTED, 'created' => time()));
                 $image->save();
                 // Save exif
                 try {
                     $exif = Model_Image_Exif::factory();
                     $exif->image_id = $image->id;
                     $exif->save();
                 } catch (Kohana_Exception $e) {
                     throw $e;
                 }
                 // Set the image as gallery image
                 $gallery->relate('images', array($image->id));
                 $gallery->image_count++;
                 $gallery->save();
                 // Mark filename as uploaded for current gallery
                 $uploaded[$gallery->id][] = $file['name'];
                 Session::instance()->set('uploaded', $uploaded);
                 // Make sure the user has photo role to be able to see uploaded pictures
                 if (!self::$user->has_role('photo')) {
                     self::$user->add_role('photo');
                 }
                 // Show image if uploaded with ajax
                 if ($this->ajax || $multiple) {
                     $info->url = $image->get_url();
                     $info->thumbnail_url = $image->get_url(Model_Image::SIZE_THUMBNAIL);
                     $info->gallery_url = Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => 'approve'));
                     $info->delete_url = Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => 'delete')) . '?token=' . Security::csrf();
                     $info->delete_type = 'GET';
                     $this->response->body(json_encode(array($info)));
                     return;
                 }
                 $this->request->redirect(Route::model($gallery));
             } catch (Validation_Exception $e) {
                 $errors = $e->array->errors('validation');
             } catch (Kohana_Exception $e) {
                 $errors = array('file' => $e->getMessage());
             }
             // Show errors if uploading with ajax, skip form
             if (($this->ajax || $multiple) && !empty($errors)) {
                 $info->error = Arr::get($errors, 'file');
                 $this->response->body(json_encode(array($info)));
                 return;
             }
         }
     }
     // Build page
     $this->view = View_Page::factory($gallery->name);
     $images = count($gallery->images());
     $this->view->subtitle = __($images == 1 ? ':images image' : ':images images', array(':images' => $images)) . ' - ' . HTML::time(Date::format('DMYYYY', $gallery->date), $gallery->date, true);
     // Upload
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_upload());
     // Help
     $this->view->add(View_Page::COLUMN_SIDE, $this->section_upload_help());
 }
コード例 #7
0
ファイル: user.php プロジェクト: anqh/core
 /**
  * Action: image
  */
 public function action_image()
 {
     $this->history = false;
     $user = $this->_get_user();
     Permission::required($user, Model_User::PERMISSION_UPDATE, self::$user);
     // Change default image
     if ($image_id = (int) Arr::get($_REQUEST, 'default')) {
         /** @var  Model_Image  $image */
         $image = Model_Image::factory($image_id);
         if (Security::csrf_valid() && $image->loaded() && $user->has('images', $image->id)) {
             $user->default_image_id = $image->id;
             $user->picture = $image->get_url();
             $user->save();
         }
         $cancel = true;
     }
     // Delete existing
     if ($image_id = (int) Arr::get($_REQUEST, 'delete')) {
         /** @var  Model_Image  $image */
         $image = Model_Image::factory($image_id);
         if (Security::csrf_valid() && $image->loaded() && $user->has('images', $image->id)) {
             $user->remove('image', $image->id);
             if ($image->id === $user->default_image_id) {
                 $user->default_image_id = null;
                 $user->picture = null;
             }
             $user->save();
             $image->delete();
         }
         $cancel = true;
     }
     // Cancel change
     if (isset($cancel) || isset($_REQUEST['cancel'])) {
         $this->request->redirect(URL::user($user));
     }
     $image = Model_Image::factory();
     $image->author_id = $user->id;
     $image->created = time();
     // Handle post
     $errors = array();
     if ($_POST && $_FILES) {
         $image->file = Arr::get($_FILES, 'file');
         try {
             $image->save();
             // Add exif, silently continue if failed - not critical
             try {
                 $exif = Model_Image_Exif::factory();
                 $exif->image_id = $image->id;
                 $exif->save();
             } catch (Kohana_Exception $e) {
             }
             // Set the image as user image
             $user->relate('images', array($image->id));
             $user->default_image_id = $image->id;
             $user->picture = $image->get_url();
             // @TODO: Legacy, will be removed after migration
             $user->save();
             // Newsfeed
             NewsfeedItem_User::default_image($user, $image);
             $this->request->redirect(URL::user($user));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         } catch (Kohana_Exception $e) {
             $errors = array('file' => __('Failed with image'));
         }
     }
     // Build page
     $this->_set_page($user);
     $this->view->tab = 'profile';
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_upload(URL::user($user), $errors));
 }
コード例 #8
0
ファイル: galleries.php プロジェクト: anqh/anqh
 /**
  * Get top images.
  *
  * @param   string   $type
  * @param   integer  $top
  * @param   integer  $user_id
  * @param   boolean  $wide
  * @return  View_Gallery_Top
  */
 public function section_top($type, $top = 10, $user_id = null, $wide = true)
 {
     $section = new View_Gallery_Top($type, Model_Image::factory()->find_top($type, $top, null, $user_id));
     $section->wide = $wide;
     return $section;
 }
コード例 #9
0
ファイル: user.php プロジェクト: anqh/anqh
 /**
  * Get user's default image url
  *
  * @param   string  $size
  * @return  string
  */
 public function get_image_url($size = null)
 {
     $image = null;
     if ($this->default_image_id) {
         $image = Model_Image::factory($this->default_image_id)->get_url($size);
     } else {
         if (Valid::url($this->picture)) {
             $image = $this->picture;
         } else {
             if (count($images = $this->images())) {
                 $image = $images->current()->get_url($size);
             }
         }
     }
     return $image;
 }
コード例 #10
0
ファイル: events.php プロジェクト: anqh/events
 /**
  * Action: image
  */
 public function action_image()
 {
     $this->history = false;
     // Load event
     /** @var  Model_Event  $event */
     $event_id = (int) $this->request->param('id');
     $event = Model_Event::factory($event_id);
     if (!$event->loaded()) {
         throw new Model_Exception($event, $event_id);
     }
     Permission::required($event, Model_Event::PERMISSION_UPDATE, self::$user);
     if ($this->_request_type !== Controller::REQUEST_AJAX) {
         $this->page_title = HTML::chars($event->name);
     }
     if (isset($_REQUEST['front'])) {
         // Change front flyer
         /** @var  Model_Flyer  $flyer */
         $flyer = Model_Flyer::factory()->find_by_image((int) $_REQUEST['front']);
         if (Security::csrf_valid() && $flyer->loaded() && $flyer->event_id == $event->id) {
             $event->flyer_front_image_id = $flyer->image_id;
             $event->flyer_front_url = $flyer->image()->get_url();
             $event->save();
         }
         $cancel = true;
     } else {
         if (isset($_REQUEST['back'])) {
             // Change back flyer
             /** @var  Model_Flyer  $flyer */
             $flyer = Model_Flyer::factory()->find_by_image((int) $_REQUEST['back']);
             if (Security::csrf_valid() && $flyer->loaded() && $flyer->event_id == $event->id) {
                 $event->flyer_back_image_id = $flyer->image_id;
                 $event->flyer_back_url = $flyer->image()->get_url();
                 $event->save();
             }
             $cancel = true;
         } else {
             if (isset($_REQUEST['delete'])) {
                 // Delete existing
                 /** @var  Model_Flyer  $flyer */
                 $flyer = Model_Flyer::factory()->find_by_image((int) $_REQUEST['delete']);
                 if (Security::csrf_valid() && $flyer->loaded() && $flyer->event_id == $event->id) {
                     if ($flyer->image_id == $event->flyer_front_image_id) {
                         $event->flyer_front_image_id = null;
                         $event->flyer_front_url = null;
                     } else {
                         if ($flyer->image_id == $event->flyer_back_image_id->id) {
                             $event->flyer_back_image_id = null;
                             $event->flyer_back_url = null;
                         }
                     }
                     $event->save();
                     $flyer->delete();
                 }
                 $cancel = true;
             }
         }
     }
     // Cancel change
     if (isset($cancel) || isset($_REQUEST['cancel'])) {
         if ($this->_request_type === Controller::REQUEST_AJAX) {
             $this->response->body($this->section_carousel($event));
             return;
         }
         $this->request->redirect(Route::model($event));
     }
     // Handle post
     $errors = array();
     if ($_POST && $_FILES) {
         $image = Model_Image::factory();
         $image->author_id = self::$user->id;
         $image->created = time();
         $image->file = Arr::get($_FILES, 'file');
         $image->description = $event->get_forum_topic();
         try {
             $image->save();
             // Add exif, silently continue if failed - not critical
             try {
                 $exif = Model_Image_Exif::factory();
                 $exif->image_id = $image->id;
                 $exif->save();
             } catch (Kohana_Exception $e) {
             }
             // Add flyer
             try {
                 $flyer = Model_Flyer::factory();
                 $flyer->set_fields(array('image_id' => $image->id, 'event_id' => $event->id, 'name' => $event->name, 'stamp_begin' => $event->stamp_begin));
                 $flyer->save();
             } catch (Kohana_Exception $e) {
                 //					$event->add('flyers', $image);
             }
             if ($event->flyer_front_image_id) {
                 if (!$event->flyer_back_image_id) {
                     // Back flyer not set, set it
                     $event->flyer_back_image_id = $image->id;
                     $event->flyer_back_url = $image->get_url();
                 }
             } else {
                 // Front flyer not set, set it
                 $event->flyer_front_image_id = $image->id;
                 $event->flyer_front_url = $image->get_url();
             }
             $event->save();
             //				NewsfeedItem_Events::event_edit(self::$user, $event);
             if ($this->_request_type === Controller::REQUEST_AJAX) {
                 $this->response->body($this->section_carousel($event));
                 return;
             }
             $this->request->redirect(Route::model($event));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         } catch (Kohana_Exception $e) {
             $errors = array('file' => __('Failed with image'));
         }
     }
     $view = $this->section_flyer_upload(Route::model($event, 'image'), $this->_request_type === Controller::REQUEST_AJAX ? Route::model($event, 'image') . '?cancel' : Route::model($event), $errors);
     if ($this->_request_type === Controller::REQUEST_AJAX) {
         $this->response->body($view);
         return;
     }
     // Build page
     $this->view = View_Page::factory($event->name);
     $this->view->add(View_Page::COLUMN_MAIN, $view);
 }
コード例 #11
0
ファイル: events.php プロジェクト: anqh/anqh
 /**
  * Action: flyer
  */
 public function action_flyer()
 {
     $this->history = false;
     // Load event
     /** @var  Model_Event  $event */
     $event_id = (int) $this->request->param('id');
     $event = Model_Event::factory($event_id);
     if (!$event->loaded()) {
         throw new Model_Exception($event, $event_id);
     }
     Permission::required($event, Model_Event::PERMISSION_UPDATE);
     if ($this->_request_type !== Controller::REQUEST_AJAX) {
         $this->page_title = HTML::chars($event->name);
     }
     if (isset($_REQUEST['default'])) {
         // Change front flyer
         /** @var  Model_Flyer  $flyer */
         $flyer = new Model_Flyer((int) $_REQUEST['default']);
         if (Security::csrf_valid() && $flyer->loaded() && $flyer->event_id == $event->id) {
             if ($event->set_flyer($flyer)) {
                 $event->save();
             }
         }
         $cancel = true;
     } else {
         if (isset($_REQUEST['delete'])) {
             // Delete existing
             /** @var  Model_Flyer  $flyer */
             $flyer_id = (int) $_REQUEST['delete'];
             $flyer = new Model_Flyer($flyer_id);
             if (Security::csrf_valid() && $flyer->loaded() && $flyer->event_id == $event->id) {
                 $flyer->delete();
                 // Set new default?
                 if ($flyer_id == $event->flyer_id) {
                     $event->flyer_id = null;
                     if ($event->set_flyer()) {
                         $event->save();
                     }
                 }
             }
             $cancel = true;
         }
     }
     // Cancel change
     if (isset($cancel) || isset($_REQUEST['cancel'])) {
         if ($this->_request_type === Controller::REQUEST_AJAX) {
             $this->response->body($this->section_carousel($event));
             return;
         }
         $this->request->redirect(Route::model($event));
     }
     // Handle post
     $errors = array();
     if ($_POST && $_FILES) {
         $image = Model_Image::factory();
         $image->author_id = Visitor::$user->id;
         $image->created = time();
         $image->file = Arr::get($_FILES, 'file');
         $image->description = $event->get_forum_topic();
         try {
             $image->save();
             // Add flyer
             try {
                 $flyer = Model_Flyer::factory();
                 $flyer->set_fields(array('image_id' => $image->id, 'event_id' => $event->id, 'name' => $event->name, 'stamp_begin' => $event->stamp_begin));
                 $flyer->save();
                 // Set as default?
                 if (!$event->flyer_id && $event->set_flyer($flyer)) {
                     $event->save();
                 }
             } catch (Kohana_Exception $e) {
             }
             if ($this->_request_type === Controller::REQUEST_AJAX) {
                 $this->response->body($this->section_carousel($event));
                 return;
             }
             $this->request->redirect(Route::model($event));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validation');
         } catch (Kohana_Exception $e) {
             $errors = array('file' => __('Failed with image'));
         }
     }
     $view = $this->section_flyer_upload(Route::model($event, 'flyer'), $this->_request_type === Controller::REQUEST_AJAX ? Route::model($event, 'flyer') . '?cancel' : Route::model($event), $errors);
     if ($this->_request_type === Controller::REQUEST_AJAX) {
         $this->response->body($view);
         return;
     }
     // Build page
     $this->view = View_Page::factory($event->name);
     $this->view->add(View_Page::COLUMN_CENTER, $view);
 }
コード例 #12
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;
 }
コード例 #13
0
ファイル: user.php プロジェクト: anqh/core
 /**
  * Get user's default image url
  *
  * @param   string  $size
  * @return  string
  */
 public function get_image_url($size = null)
 {
     if ($this->default_image_id) {
         $image = Model_Image::factory($this->default_image_id)->get_url($size);
     } else {
         if (Valid::url($this->picture)) {
             $image = $this->picture;
         } else {
             $image = null;
         }
     }
     return $image;
 }
コード例 #14
0
ファイル: venues.php プロジェクト: anqh/anqh
 /**
  * Get venue image.
  *
  * @param   Model_Venue  $venue
  * @return  View_Generic_SideImage
  */
 public function section_venue_image($venue)
 {
     $section = new View_Generic_SideImage($venue->default_image_id ? Model_Image::factory($venue->default_image_id) : null);
     if (Permission::has($venue, Model_Venue::PERMISSION_UPDATE)) {
         $uri = Route::model($venue, 'image');
         $actions = array(HTML::anchor($uri, '<i class="icon-plus-sign icon-white"></i> ' . __('Add image'), array('class' => 'btn btn-mini btn-primary image-add ajaxify')));
         if ($venue->default_image_id) {
             $actions[] = HTML::anchor($uri . '?' . Security::csrf_query() . '&delete=' . $venue->default_image_id, '<i class="icon-trash"></i> ' . __('Delete'), array('class' => 'btn btn-mini image-delete'));
         }
         $section->actions = $actions;
     }
     return $section;
 }
コード例 #15
0
ファイル: gallery.php プロジェクト: anqh/anqh
 /**
  * Get visible gallery images
  *
  * @return  Model_Image[]
  */
 public function images()
 {
     return $this->find_related('images', DB::select_array(Model_Image::factory()->fields())->join('users', 'LEFT')->on('users.id', '=', 'images.author_id')->where('images.status', '=', Model_Image::VISIBLE)->order_by('users.username', 'ASC')->order_by('images.id', 'ASC'), null);
 }
コード例 #16
0
ファイル: exif.php プロジェクト: anqh/anqh
 /**
  * Get the image of current EXIF data.
  *
  * @return  Model_Image
  */
 public function image()
 {
     return Model_Image::factory($this->image_id);
 }
コード例 #17
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;
 }