Example #1
0
 /**
  * Return the requested stories
  *
  * @param integer $channel_id   The channel to get the stories from.
  * @param array   $filter       Additional, optional filters.
  *   <pre>
  *     max_stories  The maximum number of stories to get.
  *     start_at     The story number to start retrieving.
  *     order        How to order the results.
  *   </pre>
  *
  * @return array An array of story information
  */
 public function stories($channel_id, $filter = array())
 {
     $filter = new Horde_Support_Array($filter);
     $stories = $GLOBALS['injector']->getInstance('Jonah_Driver')->getStories(array('channel_id' => $channel_id, 'limit' => $filter->get('max_stories', 10), 'startnumber' => $filter->get('start_at', 0), 'published' => true));
     foreach (array_keys($stories) as $s) {
         if (empty($stories[$s]['body_type']) || $stories[$s]['body_type'] == 'text') {
             $stories[$s]['body_html'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($stories[$s]['body'], 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
         } else {
             $stories[$s]['body_html'] = $stories[$s]['body'];
         }
     }
     return $stories;
 }
Example #2
0
 /**
  * Lists a slice of the image ids in the given gallery.
  *
  * @param array $params  Filter parameters.
  *<pre>
  *  integer|array 'gallery_id'  - A gallery id to list images from
  *  integer 'offset'            - The image to start listing from
  *  integer 'limit'             - How many images to return
  *  array|string 'fields'       - The fields to return
  *  string 'sort'               - The field to sort by.
  *  array  'filter'             - Additional filters. Each element is an
  *                                array containing 'property', 'op', and
  *                                'value' keys. Passing 'IN' as the 'op'
  *                                and an array as 'value' will produce a
  *                                SQL IN conditional.
  *</pre>
  *
  * @return array  An array of images. Either an array of ids, or an array
  *                of field values, keyed by id.
  * @throws Ansel_Exception, InvalidArgumentException
  */
 public function listImages(array $params = array())
 {
     $params = new Horde_Support_Array($params);
     if (is_array($params['fields'])) {
         $field_count = count($params['fields']);
         $params['fields'] = implode(', ', $params['fields']);
     } elseif ($params['fields'] == '*') {
         // The count is not important, as long as it's > 1
         $field_count = 2;
     } else {
         $field_count = substr_count($params->get('fields', 'image_id'), ',') + 1;
     }
     if (is_array($params['sort'])) {
         $params['sort'] = implode(', ', $params['sort']);
     }
     if (is_array($params['gallery_id'])) {
         $query_where = 'WHERE gallery_id IN (' . implode(',', $params['gallery_id']) . ')';
     } elseif ($params['gallery_id']) {
         $query_where = 'WHERE gallery_id = ' . $params['gallery_id'];
     } else {
         $query_where = '';
     }
     if ($params['filter']) {
         foreach ($params['filter'] as $filter) {
             $query_where .= (!empty($query_where) ? ' AND ' : ' WHERE ') . $this->_toImageDriverName($filter['property']) . ' ' . $filter['op'] . ' ' . (is_array($filter['value']) ? '(' . implode(',', $filter['value']) . ')' : $filter['value']);
         }
     }
     $sql = 'SELECT ' . $params->get('fields', 'image_id') . ' FROM ansel_images ' . $query_where . ' ORDER BY ' . $params->get('sort', 'image_sort');
     $sql = $this->_db->addLimitOffset($sql, array('limit' => $params->get('limit', 0), 'offset' => $params->get('offset', 0)));
     try {
         if ($field_count > 1) {
             $results = $this->_db->selectAll($sql);
             $images = array();
             foreach ($results as $image) {
                 $images[$image['image_id']] = $image;
             }
             return $images;
         } else {
             return $this->_db->selectValues($sql);
         }
     } catch (Horde_Db_Exception $e) {
         throw new Ansel_Exception($e);
     }
 }
Example #3
0
 /**
  * Return a list of recently added images
  *
  * @param array $params  Parameter (optionally) containing:
  *<pre>
  *   (string)app       Application used if null then use default.
  *   (array)galleries  An array of gallery ids to check.  If left empty,
  *                     will search all galleries with the given
  *                     permissions for the current user.
  *   (string)view      The type of image view to return.
  *   (boolean)full     Return a full URL if this is true.
  *   (integer)limit    The maximum number of images to return.
  *   (string)style     Force the use of this gallery style
  *   (array)slugs      An array of gallery slugs
  *
  * @return array  A hash of image information arrays, keyed by image_id:
  * @see Ansel_Api::getImages
  */
 public function getRecentImages(array $params = array())
 {
     $params = new Horde_Support_Array($params);
     if ($params->app) {
         $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params->app);
     }
     $images = $GLOBALS['injector']->getInstance('Ansel_Storage')->getRecentImages($params->get('galleries', array()), $params->get('limit', 10), $params->get('slugs', array()));
     $imagelist = array();
     if ($params->style) {
         $params->style = Ansel::getStyleDefinition($params->style);
     }
     foreach ($images as $image) {
         $id = $image->id;
         $imagelist[$id]['id'] = $id;
         $imagelist[$id]['name'] = $image->filename;
         $imagelist[$id]['url'] = Ansel::getImageUrl($id, $params->get('view', 'screen'), $params->get('full', false), $params->style);
         $imagelist[$id]['caption'] = $image->caption;
         $imagelist[$id]['filename'] = $image->filename;
         $imagelist[$id]['gallery'] = $image->gallery;
         $imagelist[$id]['uploaded'] = $image->uploaded;
         $imagelist[$id]['original_date'] = $image->originalDate;
         if ($params->app && $GLOBALS['conf']['vfs']['src'] != 'direct') {
             $imagelist[$id]['url']->add('app', $params->app);
         }
     }
     return $imagelist;
 }
Example #4
0
 public function testGetValuesReturnsArrayOfValuesInTheArray()
 {
     $o = new Horde_Support_Array(array('foo' => 1, 'bar' => 2));
     $this->assertSame(array(1, 2), $o->getValues());
 }