Exemplo n.º 1
0
/**
 * 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;
}
echo ' value="1">' . gettext('most recent');
echo '</option>';
echo "\n<option";
if ($showThumb) {
    echo " class=\"thumboption\" value=\"\" style=\"background-color:#B1F7B6\"";
}
echo " selected=\"selected\"";
echo ' value="">' . gettext('randomly selected');
echo '</option>';
foreach ($imagelist as $imagepath) {
    $pieces = explode('/', $imagepath);
    $filename = array_pop($pieces);
    $folder = implode('/', $pieces);
    $albumx = new Album($gallery, $folder);
    $image = newImage($albumx, $filename);
    if (is_valid_image($filename)) {
        echo "\n<option class=\"thumboption\"";
        if ($showThumb) {
            echo " style=\"background-image: url(" . $image->getThumb() . "); background-repeat: no-repeat;\"";
        }
        echo " value=\"" . $imagepath . "\"";
        echo ">" . $image->getTitle();
        echo " ({$imagepath})";
        echo "</option>";
    }
}
?>
		</select></td>
	</tr>
	<tr>
		<td><?php 
Exemplo n.º 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);
Exemplo n.º 4
0
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 
            }
        }
    }
}
Exemplo n.º 5
0
function mystique_update_options()
{
    check_admin_referer('theme-settings');
    // enable theme settings for lower level users, but with limitations
    if (!current_user_can('switch_themes')) {
        wp_die(__('You are not authorised to perform this operation.', 'mystique'));
    }
    $options = get_option('mystique');
    foreach (mystique_default_settings() as $key => $value) {
        $options[$key] = stripslashes((string) $_POST[$key]);
        if ($key == 'exclude_pages' && $_POST[$key] != '') {
            $options[$key] = implode(',', $_POST[$key]);
        }
        // else $options['exclude_pages'] = '';
        if ($key == 'exclude_categories' && $_POST[$key] != '') {
            $options[$key] = implode(',', $_POST[$key]);
        }
        // else $options['exclude_categories'] = '';
        // filter potentially malicious html/css (eg <script>, onclick, css expressions etc)
        if (!current_user_can('unfiltered_html')) {
            $options[$key] = mystique_strip_tags_attributes($options[$key]);
        }
    }
    // build dimensions array
    $dimensions = get_mystique_option('dimensions');
    foreach ($dimensions as $layout_size => $layout_types) {
        foreach ($layout_types as $layout => $values) {
            $options['dimensions'][$layout_size][$layout] = $_POST['dimensions_' . $layout_size . '_' . $layout];
        }
    }
    if (isset($_POST['remove-logo'])) {
        $options['logo'] = '';
        $options['logo_size'] = '';
    } elseif ($_FILES["file-logo"]["type"]) {
        $valid = is_valid_image('file-logo');
        if ($valid) {
            $options['logo'] = get_upload_dir('baseurl') . "/" . $_FILES["file-logo"]["name"];
            $options['logo_size'] = $valid;
        }
    }
    if (isset($_POST['remove-background'])) {
        $options['background'] = '';
    } elseif ($_FILES["file-background"]["type"]) {
        $valid = is_valid_image('file-background');
        if ($valid) {
            $options['background'] = get_upload_dir('baseurl') . "/" . $_FILES["file-background"]["name"];
        }
    }
    update_option('mystique', $options);
    // reset?
    if (isset($_POST['reset'])) {
        mystique_setup_options();
    }
    wp_redirect(admin_url('themes.php?page=theme-settings&updated=true'));
}
Exemplo n.º 6
0
?>
			</div>
			<div class="module">
				<?php 
$selector = getOption('Mini_slide_selector');
?>
				<ul id="randomlist">
					<?php 
switch ($selector) {
    case 'Recent images':
        if (function_exists('getImageStatistic')) {
            echo '<h2>' . gettext('Recent images') . '</h2>';
            $images = getImageStatistic(12, "latest");
            $c = 0;
            foreach ($images as $image) {
                if (is_valid_image($image->filename)) {
                    if ($c++ < 6) {
                        echo "<li><table><tr><td>\n";
                        $imageURL = html_encode(getURL($image));
                        if ($image->getWidth() >= $image->getHeight()) {
                            $iw = 44;
                            $ih = NULL;
                            $cw = 44;
                            $ch = 33;
                        } else {
                            $iw = NULL;
                            $ih = 44;
                            $ch = 44;
                            $cw = 33;
                        }
                        echo '<a href="' . $imageURL . '" title="' . gettext("View image:") . ' ' . html_encode($image->getTitle()) . '"><img src="' . html_encode($image->getCustomImage(NULL, $iw, $ih, $cw, $ch, NULL, NULL, true)) . '" alt="' . html_encode($image->getTitle()) . "\"/></a>\n";
Exemplo n.º 7
0
 /**
  * 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);
     }
 }
 // Attach Virtual Tour Video URL Post Meta
 if (isset($_POST['video-url'])) {
     update_post_meta($property_id, 'REAL_HOMES_tour_video_url', trim($_POST['video-url']));
 }
 // Attach Property as Featured Post Meta
 $featured = isset($_POST['featured']) ? 1 : 0;
 update_post_meta($property_id, 'REAL_HOMES_featured', $featured);
 $tour_video_image_id = get_post_meta($property_id, 'REAL_HOMES_tour_video_image', true);
 if (!empty($tour_video_image_id)) {
     $tour_video_image_src = wp_get_attachment_image_src($tour_video_image_id, 'property-detail-video-image');
     $tour_video_image = $tour_video_image_src[0];
 }
 /* Upload Images */
 if ($_FILES) {
     foreach ($_FILES as $submitted_file => $file_array) {
         if (is_valid_image($_FILES[$submitted_file]['name'])) {
             $size = intval($_FILES[$submitted_file]['size']);
             if ($size > 0) {
                 if ($submitted_file == 'featured_image') {
                     /* Featured Image */
                     $uploaded_file_id = insert_attachment($submitted_file, $property_id, true);
                     /* Virtual Tour Image */
                     if (empty($tour_video_image) && !empty($_POST['video-url'])) {
                         update_post_meta($property_id, 'REAL_HOMES_tour_video_image', $uploaded_file_id);
                     }
                 } else {
                     /* Gallery Images */
                     $uploaded_file_id = insert_attachment($submitted_file, $property_id);
                     add_post_meta($property_id, 'REAL_HOMES_property_images', $uploaded_file_id);
                 }
             }
Exemplo n.º 9
0
/**
 * 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;
}
Exemplo n.º 10
0
/**
 * Returns  a randomly selected image from the album or its subalbums. (May be NULL if none exists)
 *
 * @param mixed $rootAlbum optional album object/folder from which to get the image.
 * @param bool $daily set to true to change picture only once a day.
 * @param bool $showunpublished set true to consider all images
 *
 * @return object
 */
function getRandomImagesAlbum($rootAlbum = NULL, $daily = false, $showunpublished = false)
{
    global $_zp_current_album, $_zp_gallery, $_zp_current_search;
    if (empty($rootAlbum)) {
        $album = $_zp_current_album;
    } else {
        if (is_object($rootAlbum)) {
            $album = $rootAlbum;
        } else {
            $album = new Album($_zp_gallery, $rootAlbum);
        }
    }
    if ($daily && ($potd = getOption('picture_of_the_day:' . $album->name))) {
        $potd = unserialize($potd);
        if (date('Y-m-d', $potd['day']) == date('Y-m-d')) {
            $rndalbum = new Album($_zp_gallery, $potd['folder']);
            $image = newImage($rndalbum, $potd['filename']);
            if ($image->exists) {
                return $image;
            }
        }
    }
    $image = NULL;
    if ($album->isDynamic()) {
        $images = $album->getImages(0);
        shuffle($images);
        while (count($images) > 0) {
            $result = array_pop($images);
            if (is_valid_image($result['filename'])) {
                $image = newImage(new Album(new Gallery(), $result['folder']), $result['filename']);
            }
        }
    } else {
        $albumfolder = $album->getFolder();
        if ($album->isMyItem(LIST_RIGHTS) || $showunpublished) {
            $imageWhere = '';
            $albumNotWhere = '';
            $albumInWhere = '';
        } else {
            $imageWhere = " AND " . prefix('images') . ".show=1";
            $albumNotWhere = getProtectedAlbumsWhere();
            $albumInWhere = prefix('albums') . ".show=1";
        }
        $query = "SELECT id FROM " . prefix('albums') . " WHERE ";
        if ($albumInWhere) {
            $query .= $albumInWhere . ' AND ';
        }
        $query .= "folder LIKE " . db_quote($albumfolder . '%');
        $result = query_full_array($query);
        if (is_array($result) && count($result) > 0) {
            $albumInWhere = prefix('albums') . ".id in (";
            foreach ($result as $row) {
                $albumInWhere = $albumInWhere . $row['id'] . ", ";
            }
            $albumInWhere = ' AND ' . substr($albumInWhere, 0, -2) . ')';
            $c = 0;
            while (is_null($image) && $c < 10) {
                $result = query_single_row('SELECT COUNT(*) AS row_count ' . ' FROM ' . prefix('images') . ', ' . prefix('albums') . ' WHERE ' . prefix('albums') . '.folder!="" AND ' . prefix('images') . '.albumid = ' . prefix('albums') . '.id ' . $albumInWhere . $albumNotWhere . $imageWhere);
                $rand_row = rand(0, $result['row_count'] - 1);
                $result = query_single_row('SELECT ' . prefix('images') . '.filename, ' . prefix('albums') . '.folder ' . ' FROM ' . prefix('images') . ', ' . prefix('albums') . ' WHERE ' . prefix('images') . '.albumid = ' . prefix('albums') . '.id  ' . $albumInWhere . $albumNotWhere . $imageWhere . ' LIMIT ' . $rand_row . ', 1');
                $imageName = $result['filename'];
                if (is_valid_image($imageName)) {
                    $image = newImage(new Album(new Gallery(), $result['folder']), $imageName);
                }
                $c++;
            }
        }
    }
    if ($daily && is_object($image)) {
        $potd = array('day' => time(), 'folder' => $result['folder'], 'filename' => $result['filename']);
        setThemeOption('picture_of_the_day:' . $album->name, serialize($potd));
    }
    return $image;
}
/**
 * Returns  a randomly selected image from the album or its subalbums. (May be NULL if none exists)
 *
 * @param string $rootAlbum optional album folder from which to get the image.
 *
 * @return object
 */
function getRandomImagesAlbum($rootAlbum = null)
{
    global $_zp_current_album, $_zp_gallery, $_zp_current_search;
    if (empty($rootAlbum)) {
        $album = $_zp_current_album;
    } else {
        $album = new Album($_zp_gallery, $rootAlbum);
    }
    if ($album->isDynamic()) {
        $search = $album->getSearchEngine();
        $images = $search->getImages(0);
        $image = NULL;
        shuffle($images);
        while (count($images) > 0) {
            $randomImage = array_pop($images);
            if (is_valid_image($randomImage['filename'])) {
                $image = newImage(new Album(new Gallery(), $randomImage['folder']), $randomImage['filename']);
                return $image;
            }
        }
    } else {
        if (zp_loggedin()) {
            $imageWhere = '';
            $albumNotWhere = '';
        } else {
            $imageWhere = " AND " . prefix('images') . ".show=1";
            $albumNotWhere = getProtectedAlbumsWhere();
        }
        $albumInWhere = '';
        $albumfolder = $album->getFolder();
        $query = "SELECT id FROM " . prefix('albums') . " WHERE " . prefix('albums') . ".show = 1 AND folder LIKE '" . mysql_real_escape_string($albumfolder) . "%'";
        $result = query_full_array($query);
        $albumInWhere = prefix('albums') . ".id in (";
        foreach ($result as $row) {
            $albumInWhere = $albumInWhere . $row['id'] . ", ";
        }
        $albumInWhere = ' AND ' . substr($albumInWhere, 0, -2) . ')';
        $c = 0;
        while ($c < 10) {
            $result = query_single_row('SELECT COUNT(*) AS row_count ' . ' FROM ' . prefix('images') . ', ' . prefix('albums') . ' WHERE ' . prefix('albums') . '.folder!="" AND ' . prefix('images') . '.albumid = ' . prefix('albums') . '.id ' . $albumInWhere . $albumNotWhere . $imageWhere);
            $rand_row = rand(1, $result['row_count']);
            $result = query_single_row('SELECT ' . prefix('images') . '.filename, ' . prefix('albums') . '.folder ' . ' FROM ' . prefix('images') . ', ' . prefix('albums') . ' WHERE ' . prefix('images') . '.albumid = ' . prefix('albums') . '.id  ' . $albumInWhere . $albumNotWhere . $imageWhere . ' LIMIT ' . $rand_row . ', 1');
            $imageName = $result['filename'];
            if (is_valid_image($imageName)) {
                $image = newImage(new Album(new Gallery(), $result['folder']), $imageName);
                return $image;
            }
            $c++;
        }
    }
    return null;
}
Exemplo n.º 12
0
/**
 * 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));
        }
    }
}