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

Source for file FisheyeBase.php

Documentation is available at FisheyeBase.php

  1. <?php
  2. /**
  3.  * @package fisheye
  4.  */
  5.  
  6. /**
  7.  * required setup
  8.  */
  9. require_onceLIBERTY_PKG_PATH.'LibertyMime.php' );        // FisheyeGallery base class
  10.  
  11. /**
  12.  * @package fisheye
  13.  */
  14. abstract class FisheyeBase extends LibertyMime
  15. {
  16.     // Path of gallery images to get breadcrumbs
  17.     var $mGalleryPath;
  18.  
  19.     abstract public static function getServiceKey();
  20.  
  21.     function FisheyeBase({
  22.         $this->mGalleryPath = '';
  23.         ifget_class$this == 'fisheyegallery' {
  24.             parent::__construct();
  25.         else {
  26.             parent::__construct();
  27.         }
  28.     }
  29.  
  30.     // regular expression to determine if the title was computer generated
  31.     function isMachineName$pString {
  32.         returnpreg_match'/(^[0-9][-0-9 ]*$)|(^[-0-9 ]*(img|dsc|dscn|pict|htg|dscf|p)[-0-9 ][-0-9 ]*.*$)/i'trim$pString ) ) );
  33.     }
  34.  
  35.     // Gets a list of galleries which this item is attached to
  36.     function getParentGalleries$pContentId=NULL {
  37.         if!$this->verifyId$pContentId ) ) {
  38.             $pContentId $this->mContentId;
  39.         }
  40.         $ret NULL;
  41.  
  42.         ifis_numeric$pContentId ) ) {
  43.             $sql "SELECT fg.`gallery_id` AS `hash_key`, fg.*, lc.`title`
  44.                     FROM `".BIT_DB_PREFIX."fisheye_gallery` fg, `".BIT_DB_PREFIX."liberty_content` lc, `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim
  45.                     WHERE fgim.`item_content_id` = ? AND fgim.`gallery_content_id`=fg.`content_id` AND fg.`content_id`=lc.`content_id`";
  46.             $ret $this->mDb->getAssoc$sqlarray$pContentId ) );
  47.         }
  48.         return $ret;
  49.     }
  50.  
  51.     function loadParentGalleries({
  52.         if$this->isValid() ) {
  53.             $this->mInfo['parent_galleries'$this->getParentGalleries();
  54.         }
  55.     }
  56.  
  57.     function updatePosition($pGalleryContentId$newPosition NULL{
  58.         if$pGalleryContentId && $newPosition && $this->verifyId($this->mContentId) ) {
  59.             // SQL optimization to prevent stupid updates of identical data
  60.             if$radixPosition strpos$newPosition'.' ) ) {
  61.                 // clean out newPosition to be a valid float, and nuke all extra . or extra crap
  62.                 $significand substr$newPosition0$radixPosition );
  63.                 $mantissa preg_replace'/[^0-9]/'''substr$newPosition$radixPosition ) );
  64.                 $newPosition $significand.'.'.$mantissa;
  65.             }
  66.             $cleanPosition preg_replace'/\./'''$newPosition );
  67.             $sql "UPDATE `".BIT_DB_PREFIX."fisheye_gallery_image_map` SET `item_position` = ?
  68.                     WHERE `item_content_id` = ? AND `gallery_content_id` = ? AND (`item_position` IS NULL OR `item_position`!=?)";
  69.             $rs $this->mDb->query($sqlarray($newPosition$this->mContentId$pGalleryContentId$newPosition));
  70.         }
  71.     }
  72.  
  73.     function setGalleryPath$pPath {
  74.         $this->setField'gallery_path'rtrim$pPath'/' ) );
  75.     }
  76.  
  77.     function getThumbnailContentId({
  78.         // PURE VIRTUAL
  79.     }
  80.  
  81.     function loadThumbnail$pSize='small'$pContentId=NULL {
  82.         // Default does nothing
  83.     }
  84.  
  85.     // Possible derived read-only object such as Facebook, Instagram, etc.. default is TRUE
  86.     function isEditable({
  87.         return TRUE;
  88.     }
  89.  
  90.     // THis is a function that creates a mack daddy function to get a breadcrumb path with a single query.
  91.     // Do not muck with this query unless you really, truly understand what is going on.
  92. /*
  93. not ready for primetime
  94.     function getPaths() {
  95.         global $gBitDb;
  96.  
  97.         $ret = NULL;
  98.         if( $this->isValid() ) {
  99.             if( $this->mDb->isAdvancedPostgresEnabled() ) {
  100.                 $bindVars = array();
  101.                 $containVars = array();
  102.                 $selectSql = '';
  103.                 $joinSql = '';
  104.                 $whereSql = '';
  105.  
  106.                 $query = "SELECT fg.gallery_id, branch
  107.                           FROM connectby('`".BIT_DB_PREFIX."fisheye_gallery_image_map`', '`gallery_content_id`', '`item_content_id`', ?, 0, '/') AS t(cb_item_content_id int,cb_gallery_content_id int, level int, branch text)
  108.                             INNER JOIN `".BIT_DB_PREFIX."fisheye_gallery` fg ON (fg.`content_id`=cb_item_content_id)
  109.                             INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON(lc.`content_id`=fg.`content_id`)
  110.                           ORDER BY level DESC, branch, lc.`title`";
  111.                 if( $ret = $gBitDb->GetAssoc( $query, array( $this->mContentId ) ) ) {
  112.                 }
  113.             }
  114.         }
  115.         return $ret;
  116.     }
  117. */
  118.  
  119.     function getBreadcrumbLinks$pIncludeSelf FALSE {
  120.         global $gBitSystem;
  121.         //$ret['fisheye'] = $gBitSystem->getConfig('site_title');
  122.         $ret array();
  123.         if!$this->getField'gallery_path' ) ) {
  124.             if$this->isValid(&& $parents $this->getParentGalleries() ) {
  125.                 $gal current$parents );
  126.                 $this->setGalleryPath'/'.$gal['gallery_id');
  127.             }
  128.         }
  129.         if$this->getField'gallery_path' ) ) {
  130.             $path explode'/'ltrim$this->getField'gallery_path' )'/' ) );
  131.             $p 0;
  132.             $c 1;
  133.             $joinSql '';
  134.             $selectSql '';//AS title$g, fg$g.gallery_id AS gallery_id$g";
  135.             $whereSql '';
  136.             $bindVars array();
  137.             // We need to get min_content_status_id
  138.             $pListHash array();
  139.             LibertyContent::prepGetList($pListHash);
  140.             foreach$path as $galleryId {
  141.                 if$galleryId {
  142.                     $p++$c++;
  143.                     $selectSql .= " lc$p.`title` AS `title$p`, fg$p.`gallery_id` AS `gallery_id$p`,";
  144.                     $joinSql .= " `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim$p
  145.                         INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc$p ON(fgim$p.`gallery_content_id`=lc$p.`content_id`)
  146.                         INNER JOIN `".BIT_DB_PREFIX."fisheye_gallery` fg$p ON(fg$p.`content_id`=lc$p.`content_id`),";
  147.                     $whereSql .= " fg$p.`gallery_id`=? AND fgim$p.`item_content_id`=lc$c.`content_id` AND lc$p.`content_status_id` > ? AND";
  148.                     array_push$bindVars$galleryId );
  149.                     array_push$bindVars$pListHash['min_content_status_id']);
  150.                 }
  151.             }
  152. //            $selectSql .= " lc$c.title AS title$c ";//AS title$g, fg$g.gallery_id AS gallery_id$g";
  153.             $joinSql .= " `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim$c
  154.                 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc$c ON(fgim$c.`item_content_id`=lc$c.`content_id`) ";
  155.             $whereSql .= " lc$c.`content_id`=?  AND fgim$c.`gallery_content_id`=lc$p.`content_id` ";
  156.             array_push$bindVars$this->mContentId );
  157.             $rs $this->mDb->query"SELECT ".rtrim$selectSql',')." FROM ".rtrim$joinSql',')." WHERE $whereSql"$bindVars );
  158.             if!empty$rs->fields ) ) {
  159.                 for$i 1$i <= (count$rs->fields 2)$i++ {
  160.                     $ret[$rs->fields['gallery_id'.$i]] $rs->fields['title'.$i];
  161.                 }
  162.             }
  163.         }
  164.         if$this->isValid(&& $pIncludeSelf {
  165.             $ret[$this->mGalleryId$this->getTitle();
  166.         }
  167.  
  168.         return $ret;
  169.     }
  170.  
  171.  
  172.     function addToGalleries$pGalleryArray {
  173.         global $gBitSystem;
  174.         if$this->isValid() ) {
  175.             $inGalleries $this->mDb->getAssoc"SELECT `gallery_id`,`gallery_content_id` FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim INNER JOIN `".BIT_DB_PREFIX."fisheye_gallery` fg ON (fgim.`gallery_content_id`=fg.`content_id`) WHERE `item_content_id` = ?"array$this->mContentId ) );
  176.             $galleries array();
  177.             ifcount$pGalleryArray ) ) {
  178.                 foreach$pGalleryArray as $galleryId {
  179.                     // image has been requested to be put in a new gallery
  180.                     ifempty$inGalleries[$galleryId) ) {
  181.                         ifempty$galleries[$galleryId) ) {
  182.                             $galleries[$galleryIdnew FisheyeGallery$galleryId );
  183.                             $galleries[$galleryId]->load();
  184.                         }
  185.                         if$galleries[$galleryId]->isValid() ) {
  186.                             if$galleries[$galleryId]->hasUserPermission'p_fisheye_upload'TRUEFALSE || $galleries[$galleryId]->isPublic() ) {
  187.                                 if$gBitSystem->isFeatureActive'fisheye_gallery_default_sort_mode' ) ) {
  188.                                     $pos NULL;
  189.                                 else {
  190.                                     $query "SELECT MAX(`item_position`)
  191.                                               FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim
  192.                                                 INNER JOIN `".BIT_DB_PREFIX."fisheye_gallery` fg ON(fgim.`gallery_content_id`=fg.`content_id`)
  193.                                               WHERE fg.`gallery_id`=?";
  194.                                     $pos $this->mDb->getOne$queryarray$galleryId ) ) 10;
  195.                                 }
  196.  
  197.                                 $galleries[$galleryId]->addItem$this->mContentId$pos );
  198.                             else {
  199.                                 $this->mErrors["You do not have permission to attach ".$this->getTitle()." to ".$galleries[$galleryId]->getTitle();
  200.                             }
  201.                         }
  202.                     else {
  203.                         // image already in an existing gallery.
  204.                         unset$inGalleries[$galleryId);
  205.                     }
  206.                 }
  207.             }
  208.             ifcount$inGalleries ) ) {
  209.                 // if we have any left over in the inGalleries array, we should delete them. these were the "unchecked" boxes
  210.                 foreach$inGalleries as $galleryId {
  211.                     $sql "DELETE FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map` WHERE `gallery_content_id` = ? AND `item_content_id` = ?";
  212.                     $rs $this->mDb->query($sqlarray$galleryId$this->mContentId ) );
  213.                 }
  214.             }
  215.         }
  216.     }
  217.  
  218.     function isPublic({
  219.         if$this->isValid() ) {
  220.             return $this->getPreference'is_public' == 'y' );
  221.         }
  222.     }
  223.  
  224.     function isInGallery$pGalleryContentId$pItemContentId NULL{
  225.         if!$this->verifyId$pItemContentId ) ) {
  226.             $pItemContentId $this->mContentId;
  227.         }
  228.         $ret FALSE;
  229.         if is_numeric$this->mGalleryId && is_numeric$pGalleryContentId ) ) {
  230.  
  231.             if$this->mDb->isAdvancedPostgresEnabled() ) {
  232.                 global $gBitDb$gBitSmarty;
  233.                 // This code pulls all branches for the current node and determines if there is a path from this content to the root
  234.                 // without hitting a security_id. If there is clear path it returns TRUE. If there is a security_id, then
  235.                 // it determines if the current user has permission
  236.                 $query "SELECT branch,level,cb_item_content_id,cb_gallery_content_id
  237.                           FROM connectby('`".BIT_DB_PREFIX."fisheye_gallery_image_map`', '`gallery_content_id`', '`item_content_id`', ?, 0, '/') AS t(`cb_gallery_content_id` int,`cb_item_content_id` int, `level` int, `branch` text)
  238.                           WHERE `cb_gallery_content_id`=?
  239.                           ORDER BY branch
  240.                         ";
  241.                 if $this->mDb->getOne($queryarray(  $pItemContentId$pGalleryContentId ) ) ) {
  242.                     $ret TRUE;
  243.                 }
  244.             else {
  245.                 $sql "SELECT count(`item_content_id`) as `item_count`
  246.                         FROM `".BIT_DB_PREFIX."fisheye_gallery_image_map`
  247.                         WHERE `gallery_content_id` = ? AND `item_content_id` = ?";
  248.                 $rs $this->mDb->query($sqlarray($pGalleryContentId$pItemContentId));
  249.                 if ($rs->fields['item_count'0{
  250.                     $ret TRUE;
  251.                 }
  252.             }
  253.         }
  254.         return $ret;
  255.     }
  256.  
  257. }
  258. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:30 +0000 by phpDocumentor 1.5.0-lsces