gallery
[ class tree: gallery ] [ index: gallery ] [ all elements ]

Source for file gallery.inc.php

Documentation is available at gallery.inc.php

  1. <?php
  2.     /**
  3.      * @author            Matthias Reuter ($LastChangedBy: matthias $)
  4.      * @version            $LastChangedDate: 2009-01-18 03:52:31 +0000 (So, 18 Jan 2009) $
  5.      * @package            gallery
  6.      * @copyright        2007-2010 IPBWI development team
  7.      * @link            http://ipbwi.com/examples/topic.php
  8.      * @since            2.0
  9.      * @license            http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
  10.      */
  11.     class ipbwi_gallery extends ipbwi {
  12.         private $ipbwi            null;
  13.         public $installed        = false;
  14.         public $url                = false;
  15.  
  16.         /**
  17.          * @desc            Loads and checks different vars when class is initiating
  18.          * @author            Matthias Reuter
  19.          * @since            2.0
  20.          * @ignore
  21.          */
  22.         public function __construct($ipbwi){
  23.             // loads common classes
  24.             $this->ipbwi $ipbwi;
  25.  
  26.             // check if IP.gallery is installed
  27.             $query $this->ipbwi->ips_wrapper->DB->query('SELECT conf_value,conf_default FROM '.$this->ipbwi->board['sql_tbl_prefix'].'core_sys_conf_settings WHERE conf_key="gallery_images_url"');
  28.             if($this->ipbwi->ips_wrapper->DB->getTotalRows($query!= 0){
  29.                 $data $this->ipbwi->ips_wrapper->DB->fetch($query);
  30.                 // retrieve Gallery URL
  31.                 $this->url = (($data['conf_value'!= ''$data['conf_value'$data['conf_default']).'/';
  32.                 $this->installed = true;
  33.             }
  34.         }
  35.         /**
  36.          * @desc            Returns categories readable by the current member.
  37.          * @return    array    Readable category IDs
  38.          * @author            Matthias Reuter
  39.          * @author            Pita <peter@randomnity.com>
  40.          * @sample
  41.          *  <code>
  42.          *  $ipbwi->gallery->getViewable();
  43.          *  </code>
  44.          * @since            2.0
  45.          */
  46.         public function getViewable(){
  47.             if($cache $this->ipbwi->cache->get('galleryGetViewable'$this->ipbwi->member->myInfo['member_id'])){
  48.                 return $cache;
  49.             }else{
  50.                 $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '.$this->ipbwi->board['sql_tbl_prefix'].'gallery_categories');
  51.                 $cats array();
  52.                 while($row $this->ipbwi->ips_wrapper->DB->fetch()){
  53.                     if($this->ipbwi->group->isInGroup($row['perms_view'])){
  54.                         $cats[$row['id']] $row['id'];
  55.                     }
  56.                 }
  57.                 $this->ipbwi->cache->save('galleryGetViewable'$this->ipbwi->member->myInfo['member_id']$cats);
  58.                 return $cats;
  59.             }
  60.         }
  61.         /**
  62.          * @desc            lists latest images from IP.gallery.
  63.          * @return    array    Image-Informations as multidimensional array
  64.          * @author            Matthias Reuter
  65.          * @since            2.02
  66.          */
  67.         public function getLatestList($catIDs=false,$settings=array()){
  68.             if($this->installed === true){
  69.                 if(is_array($catIDs)){
  70.                     // todo
  71.                 }elseif($catIDs == '*'){
  72.                     $viewable $this->getViewable();
  73.                     if(isset($viewable[1])){
  74.                         $viewable[0'0';
  75.                     }
  76.                     $catquery ' AND (category_id="'.implode('" OR category_id="',$viewable).'")';
  77.                 }elseif(intval($catIDs!= 0){
  78.                     $catquery ' AND category_id="'.$catIDs.'"';
  79.                 }else{
  80.                     $catquery false;
  81.                 }
  82.                 if(empty($settings['start'])){
  83.                     $settings['start'0;
  84.                 }
  85.                 if(empty($settings['limit'])){
  86.                     $settings['limit'15;
  87.                 }
  88.                 if(empty($settings['memberid'])){
  89.                     $fromMember false;
  90.                 }else{
  91.                     $fromMember ' AND member_id = "'.$settings['memberid'].'"';
  92.                 }
  93.  
  94.                 // get latest images
  95.                 $query $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '.$this->ipbwi->board['sql_tbl_prefix'].'gallery_images WHERE approved="1"'.$catquery.$fromMember.' ORDER BY id DESC LIMIT '.intval($settings['start']).','.intval($settings['limit']));
  96.                 if($this->ipbwi->ips_wrapper->DB->getTotalRows($query== 0){
  97.                     return false;
  98.                 }
  99.                 $data array();
  100.                 while($row $this->ipbwi->ips_wrapper->DB->fetch($query)){
  101.                     $row['caption']            $this->ipbwi->properXHTML($this->ipbwi->bbcode->bbcode2html($this->ipbwi->bbcode->html2bbcode($row['caption']),false));
  102.                     $row['description']        $this->ipbwi->properXHTML($this->ipbwi->bbcode->bbcode2html($this->ipbwi->bbcode->html2bbcode($row['description']),false));
  103.                     $row['copyright']        $this->ipbwi->properXHTML($this->ipbwi->bbcode->bbcode2html($this->ipbwi->bbcode->html2bbcode($row['copyright']),false));
  104.                     $data[$row;
  105.                 }
  106.                 return $data;
  107.             }else{
  108.                 return false;
  109.             }
  110.         }
  111.         /**
  112.          * @desc            Returns all subcategories of the delivered cats.
  113.          * @param    mixed    $forums category IDs as int or array
  114.          * @param    string    $outputType The following output types are supported:<br>
  115.          *                      'html_form' to get a list of <option>-tags<br>
  116.          *                      'array' (default) for an array-list<br>
  117.          *                      'array_ids_only' for an array-list with forum IDs only<br>
  118.          *                      'name_id_with_indent' for an array list of names with indent according to the forum structure
  119.          * @param    string    $indentString The string for indent, default is '-'
  120.          * @return    mixed    List of all subcategories
  121.          * @author            Matthias Reuter
  122.          * @sample
  123.          *  <code>
  124.          *  $ipbwi->gallery->getAllSubs(array(55,22,77),'html_form');
  125.          *  </code>
  126.          * @since            2.0
  127.          */
  128.         public function getAllSubs($cats,$outputType='array',$indentString='—',$indent=false,$selectedID=false){
  129.             if($this->installed === true){
  130.                 $output false;
  131.                 // get all categories, if needed
  132.                 if(is_string($cats&& $cats == '*'){
  133.                     $cats $this->catList();
  134.                 // get forum information of requested category
  135.                 }elseif(is_string($cats)){
  136.                     $cats array($this->info($cats));
  137.                 }
  138.                 // save original indent string
  139.                 if(isset($indent)){
  140.                     $orig_indent $indent;
  141.                 }else{
  142.                     $orig_indent false;
  143.                 }
  144.                 // grab all forums from every delivered cat-id
  145.                 if(is_array($cats&& count($cats0){
  146.                     foreach($cats as $i){
  147.                         if($outputType == 'html_form')// give every forum its own option-tag
  148.                             $select 'id,name';
  149.                             $output .= '<option'.(($selectedID == $i['id']' selected="selected"' '').(($i['parent'== '0'' style="background-color:#2683AE;color:#FFF;font-weight:bold;"' ' style="color:#666;"').' value="'.$i['id'].'">&nbsp;&nbsp;'.$indent.'&nbsp;&nbsp;'.$i['name'].'</option>';
  150.                         }elseif($outputType == 'array')// merge all forum-data in one, big array
  151.                             $select '*';
  152.                             $output[$i['id']] $i;
  153.                         }elseif($outputType == 'array_ids_only')// merge all forum-data in one, big array
  154.                             $select 'id';
  155.                             if(is_array($i)){
  156.                                 $output[$i['id']] $i['id'];
  157.                             }else{
  158.                                 $output[$i$i;
  159.                             }
  160.                         }elseif($outputType == 'name_id_with_indent')// return name and id, with indent
  161.                             $select 'id,name';
  162.                             $output[$i['id']] $i;
  163.                             $output[$i['id']]['name'$indent.$i['name'];
  164.                         }
  165.                         // grab all subforums from each delivered cat-id
  166.                         if($subqery $this->ipbwi->ips_wrapper->DB->query('SELECT '.$select.' FROM '.$this->ipbwi->board['sql_tbl_prefix'].'gallery_categories WHERE parent = '.$i['id'].' ORDER BY c_order ASC')){
  167.                             // extend indent-string
  168.                             $indent $indent.$indentString;
  169.                             // get all subforums in an array
  170.                             while($row $this->ipbwi->ips_wrapper->DB->fetch($subqery)){
  171.                                 if($outputType == 'array_ids_only'){
  172.                                     $subforums[$row['id']] $row['id'];
  173.                                 }else{
  174.                                     $row['last_pic_name'$this->ipbwi->properXHTML($row['last_pic_name']);
  175.                                     $row['name'$this->ipbwi->properXHTML($row['name']);
  176.                                     $row['description'$this->ipbwi->properXHTML($row['description']);
  177.                                     $subforums[$row;
  178.                                 }
  179.                             }
  180.                             // make it rekursive
  181.                             if(isset($subforums&& is_array($subforums&& count($subforums0){
  182.                                 if($outputType == 'html_form'){
  183.                                     // give every forum its own option-tag
  184.                                     $output .= $this->getAllSubs($subforums,$outputType,$indentString,$indent,$selectedID);
  185.                                 }elseif($outputType == 'array' || $outputType == 'array_ids_only'){
  186.                                     // merge all forum-data in one, big array
  187.                                     $output $output+$this->getAllSubs($subforums,$outputType,$indentString,$indent,$selectedID);
  188.                                 }elseif($outputType == 'name_id_with_indent'){
  189.                                     $output $output+$this->getAllSubs($subforums,$outputType,$indentString,$indent,$selectedID);
  190.                                 }
  191.                             }
  192.                             // reset the temp-values
  193.                             $subforums false;
  194.                             $indent $orig_indent;
  195.                         }
  196.                     }
  197.                 }else{
  198.                     return false;
  199.                 }
  200.                 return $output;
  201.             }else{
  202.                 return false;
  203.             }
  204.         }
  205.         /**
  206.          * @desc            List categories.
  207.          * @return    array    Gallery's Categories
  208.          * @author            Matthias Reuter
  209.          * @sample
  210.          *  <code>
  211.          *  $ipbwi->forum->catList();
  212.          *  </code>
  213.          * @since            2.0
  214.          */
  215.         public function catList(){
  216.             if($this->installed === true){
  217.                 if($cache $this->ipbwi->cache->get('listGalleryCategories''1')){
  218.                     return $cache;
  219.                 }else{
  220.                     $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '.$this->ipbwi->board['sql_tbl_prefix'].'gallery_categories WHERE parent = "0"');
  221.                     $cat array();
  222.                     while($row $this->ipbwi->ips_wrapper->DB->fetch()){
  223.                         $row['last_pic_name'$this->ipbwi->properXHTML($row['last_pic_name']);
  224.                         $row['name'$this->ipbwi->properXHTML($row['name']);
  225.                         $row['description'$this->ipbwi->properXHTML($row['description']);
  226.                         $cat[$row['id']] $row;
  227.                     }
  228.                     $this->ipbwi->cache->save('listGalleryCategories''1'$cat);
  229.                     return $cat;
  230.                 }
  231.             }else{
  232.                 return false;
  233.             }
  234.         }
  235.  
  236.         public function info($imgID){
  237.             if($this->installed === true){
  238.                 // get image info
  239.                 $query $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '.$this->ipbwi->board['sql_tbl_prefix'].'gallery_images WHERE id="'.intval($imgID).'"');
  240.                 if($this->ipbwi->ips_wrapper->DB->getTotalRows($query== 0){
  241.                     return false;
  242.                 }
  243.                 $data array();
  244.                 while($row $this->ipbwi->ips_wrapper->DB->fetch($query)){
  245.                     $row['caption']            $this->ipbwi->properXHTML($this->ipbwi->bbcode->bbcode2html($this->ipbwi->bbcode->html2bbcode($row['caption']),false));
  246.                     $row['description']        $this->ipbwi->properXHTML($this->ipbwi->bbcode->bbcode2html($this->ipbwi->bbcode->html2bbcode($row['description']),false));
  247.                     $row['copyright']        $this->ipbwi->properXHTML($this->ipbwi->bbcode->bbcode2html($this->ipbwi->bbcode->html2bbcode($row['copyright']),false));
  248.                     $data $row;
  249.                 }
  250.                 return $data;
  251.             }else{
  252.                 return false;
  253.             }
  254.         }
  255.     }
  256. ?>

Documentation generated on Sat, 23 Oct 2010 23:35:51 +0200 by phpDocumentor 1.4.3