blackGallery - FolderGallery next Generation

Hier landen ältere Beiträge aus dem Forum "Module & Templates" sowie den dazugehörigen Unterforen. Ruhig auch mal reinschauen.
Benutzeravatar
Morpheus
Beiträge: 1054
Registriert: Do 8. Aug 2013, 10:49
Kontaktdaten:

Re: blackGallery - FolderGallery next Generation

Beitrag von Morpheus »

Äh, in welcher Datei :oops:
Keiner ist unnütz, er kann immer noch als schlechtes Beispiel dienen!
Benutzeravatar
shadowcat
Administrator
Beiträge: 5348
Registriert: Di 5. Feb 2013, 10:36
Kontaktdaten:

Re: blackGallery - FolderGallery next Generation

Beitrag von shadowcat »

Verzeihung. inc/blackGallery.inc.php

Code: Alles auswählen

        public static function bgGetImages($section_id,$cat_id=NULL,$all=false)
        {
            global $database;
            $imgs = array();
            $sql  = $all
                  ? ''
                  : ' AND `t1`.`is_active`="1"'
                  ;
            $sql  .= $cat_id
                  ? sprintf(' AND `t1`.`cat_id`="%d"',$cat_id)
                  : ''
                  ;

            $q    = sprintf(
                  'SELECT `t1`.*, `t2`.`folder_name` FROM `:prefix:mod_blackgallery_images` AS t1 '
                . 'RIGHT OUTER JOIN `:prefix:mod_blackgallery_categories` AS t2 '
                . 'ON `t1`.`cat_id`=`t2`.`cat_id` '
                . 'WHERE `t1`.`section_id`="%d"%s ORDER BY `t1`.`position`',
                $section_id, $sql
            );
            $r    = $database->query($q);
            if( $r && $r->numRows() )
                while( false !== ( $row = $r->fetchRow(MYSQL_ASSOC) ) )
                    $imgs[$row['file_name'].'#'.$row['cat_id']] = $row;
            return $imgs;
        }   // end function bgGetImages()
My software never has bugs, it just develops random features.
If it’s not broken, keep fixing it until it is
Benutzeravatar
Morpheus
Beiträge: 1054
Registriert: Do 8. Aug 2013, 10:49
Kontaktdaten:

Re: blackGallery - FolderGallery next Generation

Beitrag von Morpheus »

Ich bin zu doof :( Klappt nicht

hier mal der geänderte Code:

Code: Alles auswählen

<?php

/**
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or (at
 *   your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful, but
 *   WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *   General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 *   @author          BlackBird Webprogrammierung
 *   @copyright       2014, BlackBird Webprogrammierung
 *   @link            http://www.webbird.de
 *   @license         http://www.gnu.org/licenses/gpl.html
 *   @category        CAT_Modules
 *   @package         blackGallery
 *
 */

if (defined('CAT_PATH')) {
    if (defined('CAT_VERSION')) include(CAT_PATH.'/framework/class.secure.php');
} elseif (file_exists($_SERVER['DOCUMENT_ROOT'].'/framework/class.secure.php')) {
    include($_SERVER['DOCUMENT_ROOT'].'/framework/class.secure.php');
} else {
    $subs = explode('/', dirname($_SERVER['SCRIPT_NAME']));    $dir = $_SERVER['DOCUMENT_ROOT'];
    $inc = false;
    foreach ($subs as $sub) {
        if (empty($sub)) continue; $dir .= '/'.$sub;
        if (file_exists($dir.'/framework/class.secure.php')) {
            include($dir.'/framework/class.secure.php'); $inc = true;    break;
        }
    }
    if (!$inc) trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}

require_once CAT_PATH.'/framework/wblib/wbList.php';

if(!class_exists('blackGallery',false))
{
    class blackGallery extends CAT_Object
    {

        public static $bg_settings = array();

        /**
         *
         * @access public
         * @return
         **/
        public static function bgCheckSettings($media_folder)
        {
            $selected = blackGallery::$bg_settings;
            $lboxes   = blackGallery::bgGetLightboxes();
            if(isset(blackGallery::$bg_settings['exclude_dirs']) && blackGallery::$bg_settings['exclude_dirs']!=='')
            {
                $dirs = explode(',',blackGallery::$bg_settings['exclude_dirs']);
                $selected['exclude_dirs'] = array();
                foreach( $dirs as $dir )
                {
                    $selected['exclude_dirs'][$dir] = 1;
                }
            }
            foreach(array('thumb_bgcolor','thumb_overlay') as $key)
            {
                if(!isset(blackGallery::$bg_settings[$key]))
                    blackGallery::$bg_settings[$key] = '';
            }
            blackGallery::$bg_settings['arr_root_dir']     = array_merge( array($media_folder), CAT_Helper_Directory::getDirectories( CAT_PATH.$media_folder, CAT_PATH ));
            blackGallery::$bg_settings['arr_exclude_dirs'] = CAT_Helper_Directory::getInstance()
                                                             ->setSkipDirs(array(blackGallery::$bg_settings['thumb_foldername']))
                                                             ->getDirectories( CAT_PATH.$selected['root_dir'], CAT_PATH );
            blackGallery::$bg_settings['cat_pic']          = array('random','first','last');
            blackGallery::$bg_settings['allowed_suffixes'] = CAT_Helper_Mime::getAllowedFileSuffixes('image/*');
            if(!isset(blackGallery::$bg_settings['suffixes']))
                blackGallery::$bg_settings['suffixes']     = blackGallery::$bg_settings['allowed_suffixes'];
            if(!is_array(blackGallery::$bg_settings['suffixes']))
                blackGallery::$bg_settings['suffixes']     = explode(',',blackGallery::$bg_settings['suffixes']);
            blackGallery::$bg_settings['arr_lboxes']       = array_keys($lboxes);
            foreach( blackGallery::$bg_settings['arr_exclude_dirs'] as $i => $item )
            {
                blackGallery::$bg_settings['arr_exclude_dirs'][$i] = utf8_encode($item);
            }
            foreach( blackGallery::$bg_settings['arr_root_dir'] as $i => $item )
            {
                blackGallery::$bg_settings['arr_root_dir'][$i] = utf8_encode($item);
            }
            return $selected;
        }   // end function bgCheckSettings()

        /**
         *
         * @access public
         * @return
         **/
        public static function bgCountImages($cat_id)
        {
            global $database;
            $r = $database->query(sprintf(
                'SELECT COUNT(`pic_id`) AS cnt FROM `:prefix:mod_blackgallery_images` WHERE `cat_id`="%d"',
                $cat_id
            ));
            if( $r && $r->numRows() )
            {
                $row = $r->fetchRow(MYSQL_ASSOC);
                return $row['cnt'];
            }
            return '-';
        }   // end function bgCountImages()

        /**
         * get details for an image
         *
         * @access public
         * @param  integer  $pic_id
         * @return array
         **/
        public static function bgGetImage($pic_id)
        {
            global $database;
            $q = sprintf(
                'SELECT `folder_name`, `file_name` FROM `:prefix:mod_blackgallery_images` AS t1
                RIGHT OUTER JOIN `:prefix:mod_blackgallery_categories` AS t2
                ON `t1`.`cat_id`=`t2`.`cat_id`
                WHERE `pic_id`="%d"',
                $pic_id
            );
            $r = $database->query($q);
            if($r->numRows())
                return $r->fetchRow(MYSQL_ASSOC);
        }   // end function bgGetImage()

        /**
         * get images
         *
         * @access public
         * @param  integer $section_id
         * @param  integer $cat_id
         * @param  boolean $all - active only (default) or all (for backend)
         * @return array
         **/
		 
               public static function bgGetImages($section_id,$cat_id=NULL,$all=false)
        {
            global $database;
            $imgs = array();
            $sql  = $all
                  ? ''
                  : ' AND `t1`.`is_active`="1"'
                  ;
            $sql  .= $cat_id
                  ? sprintf(' AND `t1`.`cat_id`="%d"',$cat_id)
                  : ''
                  ;

            $q    = sprintf(
                  'SELECT `t1`.*, `t2`.`folder_name` FROM `:prefix:mod_blackgallery_images` AS t1 '
                . 'RIGHT OUTER JOIN `:prefix:mod_blackgallery_categories` AS t2 '
                . 'ON `t1`.`cat_id`=`t2`.`cat_id` '
                . 'WHERE `t1`.`section_id`="%d"%s ORDER BY `t1`.`position`',
                $section_id, $sql
            );
            $r    = $database->query($q);
            if( $r && $r->numRows() )
                while( false !== ( $row = $r->fetchRow(MYSQL_ASSOC) ) )
                    $imgs[$row['file_name'].'#'.$row['cat_id']] = $row;
            return $imgs;
        }   // end function bgGetImages()

        /**
         *
         * @access public
         * @return
         **/
        public static function bgGetAllImageData($section_id,$cat_id)
        {
            global $database;
            $imgs = array();
            $r    = $database->query(sprintf(
                'SELECT `pic_id`, `folder_name`, `file_name`, `file_size`, `t1`.`position`, `caption`, `t1`.`description`, `t1`.`is_active`, `t2`.`cat_name`
                FROM `:prefix:mod_blackgallery_images` AS t1
                RIGHT OUTER JOIN `:prefix:mod_blackgallery_categories` AS t2
                ON `t1`.`cat_id`=`t2`.`cat_id`
                WHERE `t1`.`section_id`="%d" AND `t1`.`cat_id`="%d" ORDER BY `t1`.`position`',
                $section_id, $cat_id
            ));
            if( $r && $r->numRows() )
            {
                while( false !== ( $row = $r->fetchRow(MYSQL_ASSOC) ) )
                {
                    $row['_has_thumb']
                        = ( file_exists(CAT_Helper_Directory::sanitizePath(
                              CAT_PATH.'/'.self::$bg_settings['root_dir'].'/'.utf8_decode($row['folder_name']).'/'
                              .self::$bg_settings['thumb_foldername'].'/thumb_'.utf8_decode($row['file_name'])))
                          )
                        ? true
                        : false;
                    $imgs[$row['file_name']] = $row;
                }
            }
            return $imgs;
        }   // end function bgGetAllImageData()


        /**
         * get category list
         *
         * @access public
         * @param  $section_id
         * @param  boolean $all     - get active only (false;default) or all (true)
         * @param  boolean $fe_only - get only categories where FE upload is allowed
         * @param  integer $parent
         * @return
         **/
        public static function bgGetCategories($section_id,$all=false,$fe_only=false,$parent=0)
        {
            global $database;
            $cats = array();
            $sql  = $all
                  ? ''
                  : ' AND `t1`.`is_active`="1"'
                  ;
            $sql  .= $fe_only
                  ? ' AND `allow_fe_upload`="1"'
                  : ''
                  ;
            $sql  .= $parent
                  ? sprintf(' AND `parent`="%d"', $parent)
                  : ''
                  ;
            $sql .= ( !$all && self::$bg_settings['show_empty']==0)
                  ? sprintf(' AND `is_empty`="0"')
                  : ''
                  ;
            $query = sprintf(
                'SELECT `t1`.*, count(`t2`.`pic_id`) AS cnt
                FROM `:prefix:mod_blackgallery_categories` AS t1
                LEFT OUTER JOIN `:prefix:mod_blackgallery_images` AS t2
                ON t1.cat_id=t2.cat_id
                WHERE `t1`.`section_id`="%d"%s
                GROUP BY `t1`.`cat_id`
                ORDER BY `position`,`level`',
                $section_id, $sql
            );
            $r    = $database->query($query);
            if( $r && $r->numRows() )
                while( false !== ( $row = $r->fetchRow(MYSQL_ASSOC) ) )
                    $cats[$row['folder_name']] = $row;
            return $cats;
        }   // end function bgGetCategories()

        /**
         * get category details
         *
         * @access public
         * @param  string  $path   - folder name
         * @param  boolean $is_id - $path is the cat_id, not the folder name
         * @return
         **/
        public static function bgGetCat($path,$is_id=false)
        {
            global $database;
            $q = sprintf(
                'SELECT * FROM `:prefix:mod_blackgallery_categories` WHERE `%s`="%s"',
                ($is_id ? 'cat_id' : 'folder_name' ), $path
            );
            $r = $database->query($q);
            if( $r && $r->numRows() )
            {
                $row = $r->fetchRow(MYSQL_ASSOC);
                return $row;
            }
            return NULL;
        }   // end function bgGetCat()

        /**
         *
         * @access public
         * @return
         **/
        public static function bgGetCatDetail($cat_id,$key)
        {
            global $database;
            $r    = $database->query(sprintf(
                'SELECT `%s` FROM `:prefix:mod_blackgallery_categories` WHERE `cat_id`="%d"',
                $key, $cat_id
            ));
            if( $r && $r->numRows() )
            {
                $row = $r->fetchRow(MYSQL_ASSOC);
                return $row[$key];
            }
            return NULL;
        }   // end function bgGetCatDetail()

        /**
         *
         * @access public
         * @return
         **/
        public static function bgGetCatName($cat_id)
        {
            return self::bgGetCatDetail($cat_id,'cat_name');
        }   // end function bgGetCatName()

        /**
         *
         * @access public
         * @return
         **/
        public static function bgGetCatPath($cat_id)
        {
            return self::bgGetCatDetail($cat_id,'folder_name');
        }   // end function bgGetCatPath()

        /**
         *
         * @access public
         * @return
         **/
        public static function bgGetLightbox($lbox)
        {
            global $database;
            if(!$lbox) $lbox = 'Slimbox2';
            $data = array($lbox=>array());
            $q = sprintf(
                'SELECT * FROM `:prefix:mod_blackgallery_lboxes` WHERE `lbox_name`="%s"',
                $lbox
            );
            $r = $database->query($q);
            if($r->numRows())
            {
                $row = $r->fetchRow(MYSQL_ASSOC);
                $data[$lbox] = $row;
                if(isset($row['lbox_js']) && $row['lbox_js']!='')
                    $data[$lbox]['js'] = unserialize($row['lbox_js']);
                else
                    $data[$lbox]['js'] = array();
                if(isset($row['lbox_css']) && $row['lbox_css']!='')
                    $data[$lbox]['css'] = unserialize($row['lbox_css']);
                else
                    $data[$lbox]['css'] = array();
            }
            return $data[$lbox];
        }   // end function bgGetLightbox()

        /**
         *
         * @access public
         * @return
         **/
        public static function bgGetLightboxes()
        {
            global $database;
            $b = array();
            $q = 'SELECT * FROM `:prefix:mod_blackgallery_lboxes`';
            $r = $database->query($q);
            if($r->numRows())
                while( false !== ( $row = $r->fetchRow(MYSQL_ASSOC) ) )
                    $b[$row['lbox_name']] = 1;
            return $b;
        }   // end function bgGetLightboxes()

        /**
         *
         * @access public
         * @return
         **/
        public static function bgSetLightboxTpl()
        {
            $lbox = blackGallery::bgGetLightbox(blackGallery::$bg_settings['lightbox']);
            if($lbox['lbox_use_default'] == 'N' && $lbox['lbox_template'] != '')
            {
                $fh = fopen(CAT_PATH.'/modules/blackGallery/templates/default/lightbox.tpl','w');
                fwrite($fh,$lbox['lbox_template']);
                fclose($fh);
            }
            elseif($lbox['lbox_use_default'] == 'Y')
            {
                copy(CAT_PATH.'/modules/blackGallery/templates/default/lightbox_default.tpl', CAT_PATH.'/modules/blackGallery/templates/default/lightbox.tpl');
            }
        }   // end function bgSetLightboxTpl()
        

        /**
         *
         * @access public
         * @return
         **/
        public static function bgSyncAllImages($root_dir,$allowed)
        {
            global $section_id;
            $files = CAT_Helper_Directory::getInstance($root_dir,$allowed)
                         ->setSuffixFilter($allowed)
                         ->getFiles(
                             CAT_Helper_Directory::sanitizePath($root_dir),
                             utf8_decode($root_dir)
                           );
            if(count($files))
            {
                $images = blackGallery::bgGetImages($section_id,NULL,true);
                return self::bgUpdateImages($images,$files,$root_dir);
            }
        }   // end function bgSyncAllImages()

        /**
         * sync categories (=folders)
         *
         * @access public
         * @param  integer  $section_id
         * @return
         **/
        public static function bgSyncCategories($section_id)
        {
            global $database;

            $root_dir = CAT_Helper_Directory::sanitizePath(CAT_PATH.'/'.self::$bg_settings['root_dir']);
            $dirs     = CAT_Helper_Directory::getInstance()
                        ->setSkipDirs(array(self::$bg_settings['thumb_foldername']))
                        ->getDirectories( CAT_PATH.self::$bg_settings['root_dir'], CAT_PATH.self::$bg_settings['root_dir'] );

            // add root dir
            array_unshift($dirs,'/');

            $skip     = explode(',',self::$bg_settings['exclude_dirs']);
            $errors   = 0;

            if(count($skip))
                for($i=count($dirs)-1;$i>=0;$i--)
                    if(in_array($dirs[$i],$skip))
                        unset($dirs[$i]);

            // sort dirs by length; this makes sure we get the parents first
            usort($dirs,array('blackGallery','lensort'));
            if(count($dirs))
            {
                $categories     = blackGallery::bgGetCategories($section_id,true);
                $root_dir_depth = count(explode('/', CAT_Helper_Directory::sanitizePath(self::$bg_settings['root_dir'])))-1;
                $allowed        = CAT_Helper_Mime::getAllowedFileSuffixes('image/*');
                $is_new         = false;
                $root_cat       = $categories[key($categories)]['cat_id'];

                foreach($dirs as $dir)
                {
                    $fulldir = CAT_Helper_Directory::sanitizePath(CAT_PATH.self::$bg_settings['root_dir'].$dir);
                    $dir     = str_ireplace(CAT_Helper_Directory::sanitizePath(CAT_PATH.self::$bg_settings['root_dir']),'',$fulldir);
                    $cat_id  = NULL;
                    if($dir == '') // root directory
                        continue;
                    if(!array_key_exists(utf8_encode($dir),$categories))
                    {
                        // parent
                        $path   = pathinfo($dir,PATHINFO_DIRNAME);
                        $parent = 0;
                        if(strlen($path)>1 && array_key_exists(utf8_encode($path),$categories))
                            $parent = $categories[utf8_encode($path)]['cat_id'];
                        else
                            $parent = $root_cat;
                        // id, section_id, folder_name, cat_name, cat_pic, cat_pic_method, description, parent, position, level, subdirs, is_active, is_empty, allow_fe_upload
                        $q = sprintf(
                            'INSERT INTO `:prefix:mod_blackgallery_categories` VALUES ( NULL, "%d", "%s", "%s", "", "", "", "%d", 0, "%d", "%d", "0", "0", "0" )',
                            $section_id, utf8_encode($dir), utf8_encode(pathinfo($dir,PATHINFO_BASENAME)), $parent, 0, 0
                        );
                        $database->query($q);
                        if($database->isError())
                            $errors++;
                        else
                            $cat_id = $database->insert_id(); $is_new = true;
                        // reload
                        $categories = blackGallery::bgGetCategories($section_id,true);
                    }
                    else
                    {
                        $cat_id = $categories[utf8_encode($dir)]['cat_id'];
                    }

                    if($cat_id)
                    {
                        // always update subdir count, image count and level
                        // get level
                        $level    = explode('/', str_ireplace(self::$bg_settings['root_dir'],'',CAT_Helper_Directory::sanitizePath($dir)));
                        // number of subdirs
                        $subs     = CAT_Helper_Directory::getDirectories($fulldir);
                        // images
                        $imgcount = self::bgSyncImagesForCat($cat_id,$root_dir,$allowed,true);
                        $q = sprintf(
                            'UPDATE `:prefix:mod_blackgallery_categories` SET `level`="%d", `subdirs`="%d", `is_empty`="%d" WHERE `cat_id`="%d"',
                            (count($level)-$root_dir_depth), count($subs), ( (count($subs)+$imgcount) > 0 ? 0 : 1 ), $cat_id
                        );
                        $database->query($q);
                        if($database->isError())
                        {
                            $errors++;
                        }
                        else
                        {
                            if($is_new)
                            {
                                $q = sprintf(
                                    'UPDATE `:prefix:mod_blackgallery_categories` SET `is_active`="%d" WHERE `cat_id`="%d"',
                                    ( (count($subs)+$imgcount) > 0 ? 1 : 0 ), $cat_id
                                );
                                $database->query($q);
                                if($database->isError())
                                    $errors++;
                            }
                        }
                    }
                }
                // removed folders
                foreach(array_keys($categories) as $dir)
                {
                    $fulldir = CAT_Helper_Directory::sanitizePath(CAT_PATH.self::$bg_settings['root_dir'].$dir);
                    if(!CAT_Helper_Directory::isDir($fulldir))
                    {
                        $q = sprintf(
                            'DELETE FROM `:prefix:mod_blackgallery_categories` WHERE `section_id`="%d" AND `folder_name`="%s"',
                            $section_id, $dir
                        );
                        $database->query($q);
                        if($database->isError())
                            $errors++;
                    }
                }
            }

            return $errors;
        }   // end function bgSyncCategories()

        /**
         * reads available image files from the file system; uses allowed
         * suffixes as filter
         *
         * @access public
         * @param  integer $cat_id    - category to check
         * @param  string  $root_dir  - root folder
         * @param  array   $allowd    - list of allowed suffixes
         * @param  boolean $checkonly - (optional) true means do not update DB
         * @return
         **/
        public static function bgSyncImagesForCat($cat_id,$root_dir,$allowed,$checkonly=false)
        {
            global $section_id;

            $cat_path = self::bgGetCatPath($cat_id);
            $files    = CAT_Helper_Directory::getInstance()
                            ->setSuffixFilter($allowed)
                            ->setRecursion(false)
                            ->getFiles(
                                CAT_Helper_Directory::sanitizePath(
                                    utf8_decode($root_dir).'/'.utf8_decode($cat_path)
                                ),
                                utf8_decode($root_dir)
                            );

            if(count($files))
            {
                if($checkonly) return(count($files));
                $images     = blackGallery::bgGetImages($section_id,$cat_id,true);
                return self::bgUpdateImages($images,$files,$root_dir);
            }
            else
            {
                if($checkonly) return(count($files));
                else           return false;
            }
        }   // end function bgSyncImagesForCat()

        /**
         * update image info in the DB
         *
         * @access public
         * @param  array   $images   - images in DB
         * @param  array   $files    - files in folders
         * @param  string  $root_dir - root directory
         * @return
         **/
        public static function bgUpdateImages($images,$files,$root_dir)
        {
            global $section_id, $database;

            $categories = blackGallery::bgGetCategories($section_id,true);
            $new        = 0;
            $removed    = 0;
            $errors     = 0;

            // map DB files to paths
            $img_map = array();
            foreach($images as $img)
            {
                $filename = CAT_Helper_Directory::sanitizePath($img['folder_name'].'/'.$img['file_name']);
                $img_map[$filename] = $img['pic_id'];
            }

            // find files that are in the DB but not in the file system
            $to_del = array_diff(array_keys($img_map),$files);

            // find files that are in the file system but not in the DB
            $to_add = array_diff($files,array_keys($img_map));

            // remove additional
            foreach($to_del as $file)
            {
                $id = $img_map[$file];
                $q = sprintf(
                    'DELETE FROM `:prefix:mod_blackgallery_images` WHERE `pic_id`="%d"',
                    $id
                );
                $r = $database->query($q);
                if($database->isError())
                    $errors++;
                else
                    $removed++;
            }

            // add missing
            foreach($to_add as $item)
            {
                $path     = str_replace('\\', '/', pathinfo($item,PATHINFO_DIRNAME));
                $file     = pathinfo($item,PATHINFO_BASENAME);
                $path     = str_ireplace($root_dir,"",$path); // remove root_dir from path
                $fullpath = CAT_Helper_Directory::sanitizePath(CAT_PATH.self::$bg_settings['root_dir'].$item);
                $size     = filesize($fullpath);                  // get the size
                // get category by file path
                if(!array_key_exists(utf8_encode($path),$categories))
                    continue;
                else
                    $cat_id = $categories[utf8_encode($path)]['cat_id'];
                $r = $database->query(sprintf(
                    'INSERT INTO `:prefix:mod_blackgallery_images` VALUES (NULL,"%d","%d","%s","%s",0,"","",1)',
                    $section_id, $cat_id, utf8_encode($file), $size
                ));
                if($database->isError())
                    $errors++;
                else
                    $new++;
            }

            return array('added'=>$new,'removed'=>$removed,'errors'=>$errors);

        }   // end function bgUpdateImages()

        /**
         * update thumbs
         *
         * to recreate (delete and generate new) thumbs, set $recreate to true;
         * default is false
         *
         * @access public
         * @param  integer $cat_id
         * @param  boolean $recreate
         * @return
         **/
        public static function bgUpdateThumbs($cat_id,$recreate=false)
        {
            global $section_id;

            $root_dir  = CAT_Helper_Directory::sanitizePath(CAT_PATH.'/'.blackGallery::$bg_settings['root_dir']);
            $thumb_dir = blackGallery::$bg_settings['thumb_foldername'];
            $allowed   = CAT_Helper_Mime::getAllowedFileSuffixes('image/*');
            $cat_path  = blackGallery::bgGetCatPath($cat_id);
            $base_path = CAT_Helper_Directory::sanitizePath($root_dir.'/'.utf8_decode($cat_path));
            $result    = CAT_Helper_Directory::getInstance()
                         ->setSuffixFilter($allowed)
                         ->setSkipDirs(array(blackGallery::$bg_settings['thumb_foldername']))
                         ->setRecursion(false)
                         ->getFiles($base_path,$root_dir);

            if(count($result))
            {
                $images = blackGallery::bgGetImages($section_id,$cat_id,true);
                if(!is_dir($base_path.'/'.$thumb_dir))
                    CAT_Helper_Directory::createDirectory($base_path.'/'.$thumb_dir,NULL,true);
                foreach($result as $item)
                {
                    $path  = pathinfo($item,PATHINFO_DIRNAME);
                    $file  = pathinfo($item,PATHINFO_BASENAME);
                    $item  = CAT_Helper_Directory::sanitizePath($base_path.'/'.$file);
                    $thumb = $base_path.'/'.$thumb_dir.'/thumb_'.$file;
                    if($recreate || !file_exists($thumb))
                        CAT_Helper_Image::getInstance()->make_thumb(
                            $item,
                            $thumb,
                            blackGallery::$bg_settings['thumb_width'],
                            blackGallery::$bg_settings['thumb_height'],
                            blackGallery::$bg_settings['thumb_method']
                        );
                }
            }
        }   // end function bgUpdateThumbs()

        /**
         *
         * @access public
         * @return
         **/
        public static function bgUpdateSettings($section_id)
        {
            global $database;

            $thumb_settings_changed = false;

            foreach(blackGallery::$bg_settings as $key => $value)
            {
                $new = CAT_Helper_Validate::sanitizePost($key);
                if( is_scalar($value) && is_scalar($new) && $value != $new )
                {
                    $database->query(sprintf(
                        'UPDATE `:prefix:mod_blackgallery_settings` SET `set_value`="%s" WHERE `section_id`="%d" AND `set_name`="%s"',
                        $new, $section_id, $key
                    ));
                    // root dir changed?
                    if($key == 'root_dir')
                    {
// --------------------------TODO-----------------------------------------------
// remove all data
// maybe we should not allow this...?
// --------------------------TODO-----------------------------------------------
                    }
                    // thumb folder name changed?
                    if($key == 'thumb_foldername')
                    {
                        // find all folders with old name
                        $old_thumb_folders = CAT_Helper_Directory::getInstance()
                                             ->showHidden(true)
                                             ->findDirectories(blackGallery::$bg_settings['thumb_foldername'],CAT_PATH.'/'.blackGallery::$bg_settings['root_dir']);
                        // rename all
                        if(count($old_thumb_folders))
                        {
                            foreach($old_thumb_folders as $folder)
                            {
                                $new_folder_name = pathinfo($folder,PATHINFO_DIRNAME).'/'.$new;
                                rename($folder,$new_folder_name);
                            }
                        }
                    }
                    if($key == "thumb_height" || $key == "thumb_width" || $key == "thumb_method")
                        $thumb_settings_changed = true;
                }
                elseif( is_array($value) || is_array($new) )
                {
                    if(is_array($new))   { sort($new);   } else { $new = array($new);     }
                    if(is_array($value)) { sort($value); } else { $value = array($value); }
                    $new   = implode(',',$new);
                    $value = implode(',',$value);
                    if( $value != $new )
                    {
                        $database->query(sprintf(
                            'UPDATE `:prefix:mod_blackgallery_settings` SET `set_value`="%s" WHERE `section_id`="%d" AND `set_name`="%s"',
                            $new, $section_id, $key
                        ));
                    }
                }
            }
            if($thumb_settings_changed)
            {
                // reload settings
                fgGetSettings();
                // get categories
                $categories = self::bgGetCategories($section_id,true);
                // update thumbs per category
                foreach($categories as $cat)
                {
                    $cat_id = $cat['cat_id'];
                    blackGallery::bgUpdateThumbs($cat_id,true);
                }
            }
        }   // end function bgUpdateSettings()

        /**
         *
         * @access public
         * @return
         **/
        public static function lensort($a,$b)
        {
            $la = strlen( $a); $lb = strlen( $b);
            if( $la == $lb) {
                return strcmp( $a, $b);
            }
            return $la - $lb;
        }   // end function lensort()


    }
}
War doch die richtige Stelle, oder mach ich was falsch.

Code: Alles auswählen

] emitted in [C:\xampp\htdocs\black\framework\CAT\Helper\DB.php] line [266] [ :(46) ]
2014-12-10 12:45:27 - CRIT --> [exceptionHandler()] [PDOException] [SQL Error] SELECT `t1`.*, `t2`.`folder_name` FROM `cat_mod_blackgallery_images` AS t1 RIGHT OUTER JOIN `cat_mod_blackgallery_categories` AS t2 ON `t1`.`cat_id`=`t2`.`cat_id` WHERE `t1`.`section_id`="5" AND `is_active`="1" AND `t1`.`cat_id`="1" ORDER BY `t1`.`position`

[ :(105) ] 
Keiner ist unnütz, er kann immer noch als schlechtes Beispiel dienen!
Benutzeravatar
shadowcat
Administrator
Beiträge: 5348
Registriert: Di 5. Feb 2013, 10:36
Kontaktdaten:

Re: blackGallery - FolderGallery next Generation

Beitrag von shadowcat »

Hm... hast Du vielleicht einen Mix aus alten und neuen Dateien? Ich habe zwar die upgrade.php befüllt, aber vielleicht habe ich was vergessen. Oder hast Du neu installiert?
My software never has bugs, it just develops random features.
If it’s not broken, keep fixing it until it is
Benutzeravatar
Morpheus
Beiträge: 1054
Registriert: Do 8. Aug 2013, 10:49
Kontaktdaten:

Re: blackGallery - FolderGallery next Generation

Beitrag von Morpheus »

Nee, das Modul hatte ich nicht neu installiert.
Mach ich gleich mal.
Keiner ist unnütz, er kann immer noch als schlechtes Beispiel dienen!
Benutzeravatar
Morpheus
Beiträge: 1054
Registriert: Do 8. Aug 2013, 10:49
Kontaktdaten:

Re: blackGallery - FolderGallery next Generation

Beitrag von Morpheus »

So, klappt.

Modul deinst.
Datei geändert
neu gezippt
Modul installiert
Keiner ist unnütz, er kann immer noch als schlechtes Beispiel dienen!
Benutzeravatar
shadowcat
Administrator
Beiträge: 5348
Registriert: Di 5. Feb 2013, 10:36
Kontaktdaten:

Re: blackGallery - FolderGallery next Generation

Beitrag von shadowcat »

Dabei könnt ich schwören ich hab's noch im ZIP geändert bevor ich es hochgeladen hab... *grmpf*
My software never has bugs, it just develops random features.
If it’s not broken, keep fixing it until it is
Benutzeravatar
shadowcat
Administrator
Beiträge: 5348
Registriert: Di 5. Feb 2013, 10:36
Kontaktdaten:

Re: blackGallery - FolderGallery next Generation

Beitrag von shadowcat »

So, in Version 0.10 gibt es einen größeren Sprung. Damit Ihr schon mal Eure Meinung äußern könnt, hier ein paar Infos dazu:

Umstellung auf wblib

Diese wird im Modul enthalten sein, verwendet wird hauptsächlich der Formbuilder. Das bedeutet, daß das Einstellungen-Formular anders aussehen wird.

Entfallen(d)e Einstellungen
  • 'Verzeichnisse ausnehmen' - da man nicht erwünschte / anzuzeigende Verzeichnisse deaktivieren kann, ist das quasi doppelt, auch wenn die Funktionsweise unterschiedlich ist
  • 'Hauptüberschrift' - wie besprochen, kann man per WYSIWYG lösen (oder ins Template schreiben)
  • 'Albumüberschrift' - desgleichen
  • 'Überschrift Bilderliste' - dito
Sonstiges

Colorpicker bei den Farboptionen
My software never has bugs, it just develops random features.
If it’s not broken, keep fixing it until it is
Benutzeravatar
Morpheus
Beiträge: 1054
Registriert: Do 8. Aug 2013, 10:49
Kontaktdaten:

Re: blackGallery - FolderGallery next Generation

Beitrag von Morpheus »

Das klingt cool!

Vor allen die Versionsnummer 0.10, wohl eher 1.0 :lol:
Keiner ist unnütz, er kann immer noch als schlechtes Beispiel dienen!
Benutzeravatar
shadowcat
Administrator
Beiträge: 5348
Registriert: Di 5. Feb 2013, 10:36
Kontaktdaten:

Re: blackGallery - FolderGallery next Generation

Beitrag von shadowcat »

Schön wär's, aber es fehlen ja noch Funktionen. :lol:
Dateianhänge
2014-12-11_182834.png
2014-12-11_182834.png (66.81 KiB) 6929 mal betrachtet
My software never has bugs, it just develops random features.
If it’s not broken, keep fixing it until it is
Antworten