Exemple #1
0
<?php

$GalleryAlbums = new PerchGallery_Albums($API);
$Images = new PerchGallery_Images($API);
$PerchGallery_ImageVersions = new PerchGallery_ImageVersions($API);
$message = false;
$new_image = false;
$HTML = $API->get('HTML');
if (isset($_GET['album_id']) && $_GET['album_id'] != '') {
    $albumID = (int) $_GET['album_id'];
}
if (isset($_GET['id']) && $_GET['id'] != '') {
    $imageID = (int) $_GET['id'];
    $Image = $Images->find($imageID);
    $details = $Image->to_array();
    $heading1 = 'Editing an Image';
    $heading2 = 'Edit Image';
} else {
    $Image = false;
    $imageID = false;
    $details = array();
    $details['albumID'] = $albumID;
    $heading1 = 'Adding a New Image';
    $heading2 = 'Add image';
}
$Template = $API->get('Template');
$Template->set('gallery/image.html', 'gallery');
$result = false;
$Form = $API->get('Form');
$Form->require_field('imageAlt', 'Required');
$Form->set_required_fields_from_template($Template);
<?php

include 'PerchGallery_Albums.class.php';
include 'PerchGallery_Album.class.php';
include 'PerchGallery_Images.class.php';
include 'PerchGallery_Image.class.php';
include 'PerchGallery_ImageVersions.class.php';
include 'PerchGallery_ImageVersion.class.php';
$API = new PerchAPI(1.0, 'perch_gallery');
$Lang = $API->get('Lang');
$Albums = new PerchGallery_Albums($API);
$albums = $Albums->return_all();
$Images = new PerchGallery_Images($API);
$images = $Images->get_recent_for_dashboard(5);
?>
<div class="widget">
	<h2>
		<?php 
echo $Lang->get('Gallery');
?>
		<a href="<?php 
echo PerchUtil::html(PERCH_LOGINPATH . '/addons/apps/perch_gallery/edit/');
?>
" class="add button"><?php 
echo $Lang->get('Add Album');
?>
</a>
	</h2>
	<div class="bd">
		<?php 
if (PerchUtil::count($images)) {
<?php

$Albums = new PerchGallery_Albums($API);
$Images = new PerchGallery_Images($API);
$Versions = new PerchGallery_ImageVersions($API);
$HTML = $API->get('HTML');
$Template = $API->get('Template');
$Template->set('gallery/image.html', 'gallery');
if (!$CurrentUser->has_priv('perch_gallery.image.upload')) {
    die('Your role does not have permission to upload images.');
}
$message = false;
if (isset($_GET['album_id']) && $_GET['album_id'] != '') {
    $albumID = (int) $_GET['album_id'];
}
$apps_php = file_get_contents(PerchUtil::file_path(PERCH_PATH . '/config/apps.php'));
if (!strpos($apps_php, 'perch_gallery')) {
    $message = $HTML->warning_message('You need to add the Gallery app to your %sconfig/apps.php%s file.', '<code>', '</code>');
}
$Form = $API->get('Form');
if ($Form->submitted()) {
    $bucket_name = 'default';
    $Settings = PerchSettings::fetch();
    $bucket_mode = $Settings->get('perch_gallery_bucket_mode')->val();
    if ($bucket_mode == '') {
        $bucket_mode = 'single';
    }
    switch ($bucket_mode) {
        case 'dynamic':
            $Album = $Albums->find($albumID);
            if (is_object($Album)) {
<?php

$GalleryAlbums = new PerchGallery_Albums($API);
$Albums = $GalleryAlbums;
$Images = new PerchGallery_Images($API);
$PerchGallery_ImageVersions = new PerchGallery_ImageVersions($API);
$message = false;
$new_image = false;
$HTML = $API->get('HTML');
if (isset($_GET['album_id']) && $_GET['album_id'] != '') {
    $albumID = (int) $_GET['album_id'];
    $Album = $Albums->find($albumID);
}
if (isset($_GET['id']) && $_GET['id'] != '') {
    $imageID = (int) $_GET['id'];
    $Image = $Images->find($imageID);
    $details = $Image->to_array();
    $heading1 = 'Editing an Image';
    $heading2 = 'Edit Image';
} else {
    $Image = false;
    $imageID = false;
    $details = array();
    $details['albumID'] = $albumID;
    $heading1 = 'Adding a New Image';
    $heading2 = 'Add image';
}
$Template = $API->get('Template');
$Template->set('gallery/image.html', 'gallery');
$result = false;
$Form = $API->get('Form');
function perch_gallery_adjacent_images($imageID, $opts = array(), $return = false)
{
    $default_opts = array('template' => 'b_adjacent_images.html', 'skip-template' => false);
    $opts = array_merge($default_opts, $opts);
    $API = new PerchAPI(1.0, 'perch_gallery');
    $Images = new PerchGallery_Images($API);
    $images = $Images->get_next_and_previous_images($imageID);
    if (PerchUtil::count($images)) {
        $image_data = array();
        foreach ($images as $prevnext => $Image) {
            if (is_object($Image)) {
                $data = $Image->to_array();
                foreach ($data as $key => $val) {
                    $image_data[$prevnext . '-' . $key] = $val;
                    if ($key == '_id') {
                        $image_data[$prevnext . '-id'] = $val;
                        // just to tidy up keys like "prev-_id" to "prev-id"
                    }
                }
            }
        }
        if ($opts['skip-template']) {
            return $image_data;
        }
        $Template = $API->get('Template');
        $Template->set('gallery/' . $opts['template'], 'gallery');
        $r = $Template->render($image_data, true);
        if ($return) {
            return $r;
        }
        echo $r;
    }
}
<?php

$HTML = $API->get('HTML');
// An imageset is a container for the meta information around an image so we can store the original, main and thumb sizes in images.
// In the UI we refer to an image - generally this is really an imageset object unless we are dealing with one image file itself
$Images = new PerchGallery_Images($API);
$GalleryAlbums = new PerchGallery_Albums($API);
if (isset($_GET['id']) && $_GET['id'] != '') {
    $albumID = (int) $_GET['id'];
    $Album = $GalleryAlbums->find($albumID);
    $details = $Album->to_array();
}
$filter = 'images';
$Form = $API->get('Form');
$message = false;
if ($Form->submitted()) {
    $postvars = array('batch', 'action');
    $data = $Form->receive($postvars);
    if ($data['action'] == 'delete') {
        if (PerchUtil::count($data['batch'])) {
            foreach ($data['batch'] as $imageID) {
                $Image = $Images->find($imageID);
                if (is_object($Image)) {
                    $Image->delete();
                    if (is_object($Album)) {
                        $Album->update_image_count();
                    }
                }
            }
            $message = $HTML->success_message('The selected images have been deleted.');
        }
<?php

$GalleryImages = new PerchGallery_Images($API);
$Albums = new PerchGallery_Albums($API);
$HTML = $API->get('HTML');
$Form = $API->get('Form');
$message = false;
if (isset($_GET['id']) && $_GET['id'] != '') {
    $Image = $GalleryImages->find($_GET['id']);
} else {
    PerchUtil::redirect($API->app_path() . '/');
}
if ($Form->submitted()) {
    if (is_object($Image)) {
        $albumID = $Image->albumID();
        $Image->delete();
        $Album = $Albums->find($albumID);
        if (is_object($Album)) {
            $Album->update_image_count();
        }
        PerchUtil::redirect($API->app_path() . '/images/?id=' . $albumID);
    } else {
        $message = $HTML->failure_message('Sorry, the image could not be deleted.');
    }
}
$details = $Image->to_array();
 public function get_image_versions($imageID, $versions = false)
 {
     $sql = 'SELECT * FROM ' . $this->table . ' WHERE imageID=' . $this->db->pdb($imageID);
     $row = $this->db->get_row($sql);
     if (is_array($row)) {
         /* if we have versions is array (otherwise we just return the imageset objects) */
         if (PerchUtil::count($versions)) {
             $PerchGallery_Images = new PerchGallery_Images();
             /* loop though versions array */
             for ($n = 0; $n < sizeOf($versions); $n++) {
                 /* add to row the image objects for versions in the array */
                 $Image = $PerchGallery_Images->get_by_version($row['imageID'], $versions[$n]);
                 $row['image_' . $versions[$n]] = $Image;
             }
         }
         $r = $this->return_instance($row);
         return $r;
     }
     return false;
 }
 public function get_image_count()
 {
     $PerchGallery_Images = new PerchGallery_Images();
     return $PerchGallery_Images->get_count_for_album($this->id());
 }