/**
 * Returns a new "image" object based on the file extension
 *
 * @param object $album the owner album
 * @param string $filename the filename
 * @return object
 */
function newImage(&$album, $filename)
{
    global $_zp_extra_filetypes;
    if ($ext = is_valid_other_type($filename)) {
        $object = $_zp_extra_filetypes[$ext];
        return new $object($album, $filename);
    } else {
        return new _Image($album, $filename);
    }
}
/**
 * Returns a new "image" object based on the file extension
 *
 * @param object $album the owner album
 * @param string $filename the filename
 * @param bool $quiet set true to supress error messages (used by loadimage)
 * @return object
 */
function newImage($album, $filename, $quiet = false)
{
    global $_zp_extra_filetypes;
    if (is_array($filename)) {
        $xalbum = new Album(new Gallery(), $filename['folder']);
        $filename = $filename['filename'];
    } else {
        $xalbum = $album;
    }
    if (!is_object($xalbum) || strtoLower(get_class($xalbum)) != 'album' || !$xalbum->exists) {
        $msg = sprintf(gettext('Bad album object parameter to newImage(%s)'), $filename);
        debugLogBacktrace($msg);
        trigger_error(html_encode($msg), E_USER_NOTICE);
        return NULL;
    }
    if ($ext = is_valid_other_type($filename)) {
        $object = $_zp_extra_filetypes[$ext];
        $image = new $object($xalbum, $filename);
    } else {
        if (is_valid_image($filename)) {
            $image = new _Image($xalbum, $filename);
        } else {
            $image = NULL;
        }
    }
    if ($image) {
        zp_apply_filter('image_instantiate', $image);
        if ($image->exists) {
            return $image;
        } else {
            return NULL;
        }
    }
    if (!$quiet) {
        $msg = sprintf(gettext('Bad filename suffix in newImage(%s)'), $filename);
        debugLogBacktrace($msg);
        trigger_error(html_encode($msg), E_USER_NOTICE);
    }
    return NULL;
}
Beispiel #3
0
         header('Location: ' . FULLWEBPATH . '/' . ZENFOLDER . '/admin.php');
         exit;
     }
 }
 if ($new) {
     mkdir_recursive($targetPath, CHMOD_VALUE);
     $album = new Album($gallery, $folder);
     $album->setShow($_POST['http_publishalbum']);
     $album->setTitle(sanitize($_POST['http_albumtitle']));
     $album->setOwner($_zp_current_admin_obj->getUser());
     $album->save();
 }
 @chmod($targetPath, CHMOD_VALUE);
 $error = zp_apply_filter('check_upload_quota', UPLOAD_ERR_OK, $tempFile);
 if (!$error) {
     if (is_valid_image($name) || is_valid_other_type($name)) {
         $seoname = seoFriendly($name);
         if (strrpos($seoname, '.') === 0) {
             $seoname = sha1($name) . $seoname;
         }
         // soe stripped out all the name.
         $targetFile = $targetPath . '/' . internalToFilesystem($seoname);
         if (file_exists($targetFile)) {
             $append = '_' . time();
             $seoname = stripSuffix($seoname) . $append . '.' . getSuffix($seoname);
             $targetFile = $targetPath . '/' . internalToFilesystem($seoname);
         }
         if (move_uploaded_file($tempFile, $targetFile)) {
             @chmod($targetFile, 0666 & CHMOD_VALUE);
             $album = new Album($gallery, $folder);
             $image = newImage($album, $seoname);
function checkFolder($folder)
{
    global $albums, $gallery, $count, $albumcount;
    $files = scandir(ALBUM_FOLDER_SERVERPATH . '/' . $folder);
    $display = true;
    if (!empty($folder)) {
        $album = new Album($gallery, filesystemToInternal($folder));
    }
    foreach ($files as $file) {
        $file = str_replace('\\', '/', $file);
        $key = str_replace(SERVERPATH . '/', '', $folder . '/' . $file);
        if (is_dir(ALBUM_FOLDER_SERVERPATH . $folder . '/' . $file) && $file != '..' && $file != '.') {
            if (empty($folder)) {
                $albumname = $file;
            } else {
                $albumname = $folder . '/' . $file;
            }
            checkFolder($albumname);
        } else {
            if (is_valid_image($file) || is_valid_other_type($file)) {
                $filename = internalToFilesystem($file);
                $seoname = seoFriendly($filename);
                if ($seoname != $filename) {
                    $old = filesystemToInternal($file);
                    $image = newImage($album, $old);
                    if (!($e = $image->rename($seoname))) {
                        if ($display) {
                            echo '<p>' . filesystemToInternal($folder) . "</p>\n";
                            $display = false;
                        }
                        echo '&nbsp;&nbsp;';
                        printf(gettext('<em>%1$s</em> renamed to <em>%2$s</em>'), $old, $seoname);
                        echo "<br />\n";
                        $count++;
                        ?>
						<script type="text/javascript">
						<!--
							imagecount = <?php 
                        echo $count;
                        ?>
;
						//-->
						</script>
						<?php 
                    }
                }
            }
        }
    }
    if (!empty($folder)) {
        $albumname = internalToFilesystem($folder);
        $file = basename($albumname);
        $seoname = seoFriendly($file);
        if ($seoname != $file) {
            $newname = dirname($albumname);
            if (empty($newname) || $newname == '.') {
                $newname = $seoname;
            } else {
                $newname .= '/' . $seoname;
            }
            if (!$album->rename($newname)) {
                printf(gettext('<em>%1$s</em> renamed to <em>%2$s</em>'), $albumname, $newname);
                echo "<br />\n";
                $albumcount++;
                ?>
				<script type="text/javascript">
				<!--
					albumcount = <?php 
                echo $albumcount;
                ?>
;
				//-->
				</script>
				<?php 
            }
        }
    }
}
 /**
  * Load all of the filenames that are found in this Albums directory on disk.
  * Returns an array with all the names.
  *
  * @param  $dirs Whether or not to return directories ONLY with the file array.
  * @return array
  */
 function loadFileNames($dirs = false)
 {
     if ($this->isDynamic()) {
         // there are no 'real' files
         return array();
     }
     $albumdir = $this->localpath;
     if (!is_dir($albumdir) || !is_readable($albumdir)) {
         if (!is_dir($albumdir)) {
             $msg = sprintf(gettext("Error: The album named %s cannot be found."), $this->name);
         } else {
             $msg = sprintf(gettext("Error: The album %s is not readable."), $this->name);
         }
         zp_error($msg, false);
         return array();
     }
     $dir = opendir($albumdir);
     $files = array();
     $others = array();
     while (false !== ($file = readdir($dir))) {
         $file8 = filesystemToInternal($file);
         if ($dirs && (is_dir($albumdir . $file) && substr($file, 0, 1) != '.' || hasDynamicAlbumSuffix($file))) {
             $files[] = $file8;
         } else {
             if (!$dirs && is_file($albumdir . $file)) {
                 if (is_valid_other_type($file)) {
                     $files[] = $file8;
                     $others[] = $file8;
                 } else {
                     if (is_valid_image($file)) {
                         $files[] = $file8;
                     }
                 }
             }
         }
     }
     closedir($dir);
     if (count($others) > 0) {
         $others_thumbs = array();
         foreach ($others as $other) {
             $others_root = substr($other, 0, strrpos($other, "."));
             foreach ($files as $image) {
                 $image_root = substr($image, 0, strrpos($image, "."));
                 if ($image_root == $others_root && $image != $other && is_valid_image($image)) {
                     $others_thumbs[] = $image;
                 }
             }
         }
         $files = array_diff($files, $others_thumbs);
     }
     if ($dirs) {
         return zp_apply_filter('album_filter', $files);
     } else {
         return zp_apply_filter('image_filter', $files);
     }
 }
/**
 * Unzips an image archive
 *
 * @param file $file the archive
 * @param string $dir where the images go
 */
function unzip($file, $dir)
{
    //check if zziplib is installed
    if (function_exists('zip_open')) {
        $zip = zip_open($file);
        if ($zip) {
            while ($zip_entry = zip_read($zip)) {
                // Skip non-images in the zip file.
                $fname = zip_entry_name($zip_entry);
                $seoname = internalToFilesystem(seoFriendly($fname));
                if (is_valid_image($seoname) || is_valid_other_type($seoname)) {
                    if (zip_entry_open($zip, $zip_entry, "r")) {
                        $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                        $path_file = str_replace("/", DIRECTORY_SEPARATOR, $dir . '/' . $seoname);
                        $fp = fopen($path_file, "w");
                        fwrite($fp, $buf);
                        fclose($fp);
                        clearstatcache();
                        zip_entry_close($zip_entry);
                        $albumname = substr($dir, strlen(ALBUM_FOLDER_SERVERPATH));
                        $album = new Album(new Gallery(), $albumname);
                        $image = newImage($album, $seoname);
                        if ($fname != $seoname) {
                            $image->setTitle($name);
                            $image->save();
                        }
                    }
                }
            }
            zip_close($zip);
        }
    } else {
        require_once dirname(__FILE__) . '/lib-pclzip.php';
        $zip = new PclZip($file);
        if ($zip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
            return false;
        }
    }
    return true;
}
/**
 * Unzips an image archive
 *
 * @param file $file the archive
 * @param string $dir where the images go
 */
function unzip($file, $dir)
{
    //check if zziplib is installed
    if (function_exists('zip_open')) {
        $zip = zip_open($file);
        if ($zip) {
            while ($zip_entry = zip_read($zip)) {
                // Skip non-images in the zip file.
                $fname = zip_entry_name($zip_entry);
                $soename = UTF8toFilesystem(seoFriendlyURL($fname));
                if (is_valid_image($soename) || is_valid_other_type($soename)) {
                    if (zip_entry_open($zip, $zip_entry, "r")) {
                        $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                        $path_file = str_replace("/", DIRECTORY_SEPARATOR, $dir . '/' . $soename);
                        $fp = fopen($path_file, "w");
                        fwrite($fp, $buf);
                        fclose($fp);
                        zip_entry_close($zip_entry);
                        $albumname = substr($dir, strlen(getAlbumFolder()));
                        $album = new Album(new Gallery(), $albumname);
                        $image = newImage($album, $soename);
                        if ($fname != $soename) {
                            $image->setTitle($name);
                            $image->save();
                        }
                    }
                }
            }
            zip_close($zip);
        }
    } else {
        // Use Zlib http://www.phpconcept.net/pclzip/index.en.php
        require_once dirname(__FILE__) . '/lib-pclzip.php';
        $zip = new PclZip($file);
        if ($zip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
            die("Error : " . $zip->errorInfo(true));
        }
    }
}