Exemple #1
0
/**
 * script for retrieving a JSON array of images/videos in a gallery
 *
 * @return array gallery details
 */
function ImageGallery_galleryGet()
{
    $page_id = (int) @$_REQUEST['id'];
    if ($page_id == 0) {
        Core_quit();
    }
    $image_dir = @$_REQUEST['image_gallery_directory'];
    if ($image_dir != '' && is_dir(USERBASE . '/f' . $image_dir)) {
        // read from KFM
        $dir = preg_replace('/^\\//', '', $image_dir);
        $dir_id = kfm_api_getDirectoryID($dir);
        $images = kfm_loadFiles($dir_id);
        $n = count($images);
        if ($n == 0) {
            die('none');
        }
        $f = array();
        foreach ($images['files'] as $file) {
            array_push($f, array('id' => $file['id'], 'name' => $file['name'], 'width' => $file['width'], 'media' => 'image', 'height' => $file['height'], 'caption' => $file['caption'], 'url' => '/kfmget/' . $file['id']));
        }
    } else {
        // fall back to reading from database
        $files = dbAll('select * from image_gallery where gallery_id=' . $page_id . ' order by position asc');
        $dir = dbOne('select value from page_vars where name="image_gallery_directory"' . 'and page_id=' . $page_id, 'value');
        if ($dir === false) {
            $dir = '/image-galleries/imagegallery-' . $page_id;
        }
        $f = array();
        foreach ($files as $file) {
            $meta = json_decode($file['meta'], true);
            switch ($file['media']) {
                case 'image':
                    // {
                    $arr = array('id' => $file['id'], 'name' => $meta['name'], 'media' => 'image', 'width' => $meta['width'], 'height' => $meta['height'], 'url' => (isset($DBVARS['cdn']) && $DBVARS['cdn'] ? '//' . $DBVARS['cdn'] : '') . '/a/f=getImg/' . $dir . '/' . $meta['name']);
                    if (isset($meta['author'])) {
                        $arr['author'] = $meta['author'];
                    }
                    if (isset($meta['caption'])) {
                        $arr['caption'] = $meta['caption'];
                    }
                    if (isset($meta['description'])) {
                        $arr['description'] = $meta['description'];
                    }
                    if (isset($meta['tags'])) {
                        $arr['tags'] = $meta['tags'];
                    }
                    $f[] = $arr;
                    break;
                    // }
                // }
                case 'video':
                    // {
                    $image = $meta['image'] == '' ? '/ww.plugins/image-gallery/files/video.png' : $meta['image'];
                    array_push($f, array('id' => $file['id'], 'media' => 'video', 'url' => (isset($DBVARS['cdn']) && $DBVARS['cdn'] ? '//' . $DBVARS['cdn'] : '') . '/a/f=getImg/' . $image, 'href' => $meta['href']));
                    break;
                    // }
            }
        }
    }
    // { get gallery data
    $rs = dbAll('select * from page_vars where page_id=' . $page_id . ' and name like "image_gallery_%"', 'name');
    // }
    return array('items' => $f, 'caption-in-slider' => (int) @$rs['image_gallery_captions_in_slider']['value'], 'image-width' => (int) @$rs['image_gallery_image_x']['value'], 'image-height' => (int) @$rs['image_gallery_image_y']['value'], 'frame' => array('type' => @$rs['image_gallery_frame']['value'], 'padding' => @$rs['image_gallery_frame_custom_padding']['value'], 'border' => @$rs['image_gallery_frame_custom_border']['value']));
}
Exemple #2
0
 }
 if (!is_dir(USERBASE . '/ww.cache/image-gallery')) {
     mkdir(USERBASE . '/ww.cache/image-gallery');
 }
 $kfm_do_not_save_session = true;
 require_once KFM_BASE_PATH . '/api/api.php';
 require_once KFM_BASE_PATH . '/initialise.php';
 $new_images = array();
 foreach ($pages as $page) {
     $vars = dbAll('select value from page_vars where page_id=' . $page['id'] . ' and name="image_gallery_directory" or name="gallery-' . 'template"');
     if (!$vars) {
         break;
     }
     $image_dir = $vars[0]['value'];
     $dir = preg_replace('/^\\//', '', $image_dir);
     $dir_id = kfm_api_getDirectoryID($dir);
     $images = kfm_loadFiles($dir_id);
     $n = count($images);
     if ($n == 0) {
         break;
     }
     for ($i = 0; $i < count($images['files']); ++$i) {
         $new = array('id' => $images['files'][$i]['id'], 'gallery_id' => $page['id'], 'position' => $i, 'media' => 'image', 'meta' => addslashes(json_encode(array('name' => $images['files'][$i]['name'], 'width' => $images['files'][$i]['width'], 'height' => $images['files'][$i]['height'], 'caption' => $images['files'][$i]['caption']))));
         array_push($new_images, $new);
     }
     file_put_contents(USERBASE . '/ww.cache/image-gallery/' . $page['id'], @$vars[1]['value']);
 }
 $query = 'insert into image_gallery (id,gallery_id,position,media,meta) values';
 foreach ($new_images as $image) {
     $query .= ' (' . $image['id'] . ',' . $image['gallery_id'] . ',' . $image['position'] . ',' . '"' . $image['media'] . '",' . '"' . $image['meta'] . '"' . '),';
 }