Esempio n. 1
0
function getChannelThumbnail($feed)
{
    $thumbnail_url = null;
    if (preg_match("/\\/domain\\//u", $feed) > 0) {
        $uri = "http://www.reddit.com" . $feed . "/search/.json?restrict_sr=on&sort=top&syntax=cloudsearch&limit=100";
    } else {
        $uri = "http://www.reddit.com" . $feed . "/search/.json?q=%28and+%28or+site%3A%27youtube.com%27+site%3A%27vimeo.com%27+site%3A%27youtu.be%27%29+timestamp%3A" . (time() - 30 * 24 * 60 * 60) . "..%29&restrict_sr=on&sort=top&syntax=cloudsearch&limit=100";
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $uri);
    curl_setopt($ch, CURLOPT_USERAGENT, 'reddit.tv Thumbnail Scraper');
    $file = curl_exec($ch);
    $channel_info = json_decode($file);
    $entries = $channel_info->data->children;
    for ($x = 0; $x < count($entries); $x++) {
        if (isVideo($entries[$x]->data->domain)) {
            if (!empty($entries[$x]->data->media->oembed->thumbnail_url)) {
                $thumbnail_url = $entries[$x]->data->media->oembed->thumbnail_url;
                break;
            }
        }
    }
    return $thumbnail_url;
}
Esempio n. 2
0
 function getVidThumb($src, $preview, $id, $w = 90, $h = 70, $sq = 1, $q = 70, $sh = 1, $tail = false)
 {
     if (strpos($preview, ':') !== false) {
         list($src, $x, $y) = explode(':', $preview);
         $filename = __p(array('src' => $src, 'album_id' => $id, 'width' => $w, 'height' => $h, 'square' => $sq, 'quality' => $q, 'sharpening' => $sh, 'anchor_x' => $x, 'anchor_y' => $y));
     } else {
         if (isVideo($src)) {
             $pos = strrpos($src, '.');
             $ext = strtolower(substr($src, $pos + 1, strlen($src)));
             $filename = DIR_HOST . '/app/webroot/img/default_' . $ext . '.gif';
         } else {
             if (isSwf($src)) {
                 $filename = DIR_HOST . '/app/webroot/img/default_swf.gif';
             }
         }
     }
     return $filename;
 }
function isNotImg($fn)
{
    if (isSwf($fn) || isVideo($fn)) {
        return true;
    } else {
        return false;
    }
}
Esempio n. 4
0
function getMimeType($file)
{
    $file_info = new finfo(FILEINFO_MIME);
    $mime_type = $file_info->buffer(file_get_contents($file));
    return $mime_type;
}
$files = $api->getFileList("files");
?>
 <br>
YouTube Uploader v<?php 
echo $plugin["ytUpload"]["version"];
?>
.
Please choose a video you want to upload:<br>
<?php 
foreach ($files as $file) {
    if (isVideo($file)) {
        ?>
    <a href="<?php 
        echo multiSite2_Link("upload");
        ?>
&file=<?php 
        echo $file;
        ?>
" class="btn btn-primary btn-raised btn-block btn-lg"><?php 
        echo $file;
        ?>
</a>
    <?php 
    }
}
 function image($user_id, $id, $upload_type, $tags = '')
 {
     $this->loadModel('Image');
     $this->loadModel('Account');
     // Make sure this is coming from the flash player and is a POST request
     if (strpos(strtolower(env('HTTP_USER_AGENT')), 'flash') === false && !$this->Session->check('User') || !$this->RequestHandler->isPost()) {
         exit;
     }
     $tags = str_replace(' ', ',', urldecode($tags));
     $tags = ereg_replace("[^,A-Za-z0-9._-]", "", $tags);
     if ($tags == 'null' || $tags == 'undefined') {
         $tags = '';
     }
     define('CUR_USER_ID', $user_id);
     // Make sure permissions are set correctly
     $old_mask = umask(0);
     // Get album
     if ($upload_type > 4) {
         $image = $this->Image->find('first', array('conditions' => array('Image.id' => $id), 'recursive' => -1));
         $id = $image['Image']['aid'];
     }
     $this->Image->Album->id = $id;
     $album = $this->Image->Album->read();
     $account = $this->Account->find('first');
     $album_active = $album['Album']['active'];
     $top = $this->Image->find('first', array('conditions' => "aid = {$id}", 'order' => 'seq DESC', 'recursive' => -1));
     if (empty($top)) {
         $next = 1;
     } else {
         $next = $top['Image']['seq'];
         if ($top['Image']['active']) {
             $next++;
         }
     }
     // Flash uploads crap out when spaces are in the name
     $file = str_replace(" ", "_", $this->params['form']['Filedata']['name']);
     $file = ereg_replace("[^A-Za-z0-9._-]", "_", $file);
     $this->data['Image']['is_video'] = isVideo($file);
     // Get image extensions so we make sure
     // a safe file is uploaded
     $ext = $this->Director->returnExt($file);
     // Paths
     $the_temp = $this->params['form']['Filedata']['tmp_name'];
     $path = ALBUMS . DS . 'album-' . $album['Album']['id'];
     $lg_path = $path . DS . 'lg' . DS . $file;
     $lg_temp = $lg_path . '.tmp';
     $tn_path = $path . DS . 'tn' . DS . $file;
     $tn_temp = $tn_path . '.tmp';
     settype($upload_type, 'integer');
     $this->Director->setAlbumPerms($id);
     if (in_array($ext, a('jpg', 'jpeg', 'gif', 'png', 'mp3')) || isNotImg($file)) {
         switch ($upload_type) {
             // Audio
             case 4:
                 if (is_uploaded_file($the_temp) && $this->Director->setPerms(AUDIO)) {
                     $a_tmp = AUDIO . DS . $file . '.tmp';
                     move_uploaded_file($the_temp, $a_tmp);
                     copy($a_tmp, AUDIO . DS . $file);
                     unlink($a_tmp);
                     $this->Image->Album->saveField('audioFile', $file);
                 }
                 break;
                 // Standard image or custom thumb
             // Standard image or custom thumb
             default:
                 if (is_uploaded_file($the_temp) && move_uploaded_file($the_temp, $lg_temp)) {
                     copy($lg_temp, $lg_path);
                     unlink($lg_temp);
                     list($meta, $captured_on) = $this->Director->imageMetadata($lg_path);
                     $keywords = $this->Director->parseMetaTags('iptc:keywords', $meta);
                     $keywords = str_replace(' ', ',', urldecode($keywords));
                     $keywords = ereg_replace("[^,A-Za-z0-9._-]", "", $keywords);
                     if (!empty($tags)) {
                         $keywords = ' ' . trim($keywords);
                     }
                     $check = $this->Image->find("aid = {$id} AND src = '{$file}'");
                     if (empty($check)) {
                         $this->data['Image']['src'] = $file;
                         $this->data['Image']['aid'] = $id;
                         $this->data['Image']['seq'] = $next;
                         $this->data['Image']['filesize'] = filesize($lg_path);
                         $this->data['Image']['captured_on'] = (int) $captured_on;
                         $this->data['Image']['tags'] = $tags . $keywords;
                         $this->data['Image']['album_active'] = $album_active;
                         if (in_array($upload_type, array(3, 5, 6))) {
                             $this->data['Image']['active'] = 0;
                             $this->data['Image']['seq'] = $next - 1;
                         }
                         $this->Image->save($this->data);
                         $image_id = $this->Image->getLastInsertId();
                         if (isVideo($file)) {
                             $ffmpeg = $this->Director->ffmpeg();
                             if ($ffmpeg) {
                                 $info = pathinfo($file);
                                 $ext = $info['extension'];
                                 exec(FFMPEG_PATH_FINAL . " -i {$lg_path} 2>&1", $out);
                                 foreach ($out as $line) {
                                     if (strpos($line, 'Duration') !== false) {
                                         preg_match('/Duration: ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $line, $matches);
                                         list(, $h, $m, $s) = $matches;
                                         $duration = $h * 60 * 60 + $m * 60 + $s;
                                         continue;
                                     }
                                 }
                                 $duration = $duration - 2;
                                 $bits = ceil($duration / 12);
                                 if ($bits == 0) {
                                     $bits = 1;
                                 }
                                 $rate = 1 / $bits;
                                 if ($rate < 0.1) {
                                     $rate = 0.1;
                                 }
                                 $dir = dirname($lg_path) . DS;
                                 $i = 1;
                                 $cmd = array();
                                 while ($i < $duration) {
                                     $i_str = str_pad($i, 5, '0', STR_PAD_LEFT);
                                     $cmd[] = FFMPEG_PATH_FINAL . " -ss {$i} -r 1 -i \"{$file}\" -vframes 1 -an -f mjpeg \"__vidtn__{$image_id}_{$i_str}.jpg\"";
                                     $i += $bits;
                                 }
                                 chdir($dir);
                                 if (DS == '\\') {
                                     foreach ($cmd as $c) {
                                         exec($c);
                                     }
                                 } else {
                                     $cmd = join(' && ', $cmd);
                                     exec($cmd);
                                 }
                                 $thumbs = glob($dir . DS . "__vidtn__{$image_id}_*.jpg");
                                 $tn_file = $lg_path . '.jpg';
                                 if (!empty($thumbs)) {
                                     copy($thumbs[0], $tn_file);
                                 }
                                 if (file_exists($tn_file)) {
                                     $vdata = array();
                                     $vdata['Image']['src'] = $file . '.jpg';
                                     $vdata['Image']['aid'] = $id;
                                     $vdata['Image']['seq'] = $next;
                                     $vdata['Image']['filesize'] = filesize($tn_file);
                                     $vdata['Image']['active'] = 0;
                                     $vdata['Image']['is_video'] = 0;
                                     $vdata['Image']['album_active'] = $album_active;
                                     $this->Image->create();
                                     $this->Image->save($vdata);
                                     $this->data['Image']['lg_preview_id'] = $this->Image->getLastInsertId();
                                     $this->data['Image']['lg_preview'] = $file . '.jpg:50:50';
                                     $this->Image->create();
                                     $this->Image->id = $image_id;
                                     $this->Image->save($this->data);
                                 }
                             }
                         }
                     } else {
                         $image_id = $check['Image']['id'];
                         $caches = glob(ALBUMS . DS . 'album-' . $check['Album']['id'] . DS . 'cache' . DS . $check['Image']['src'] . '*');
                         if (!empty($caches)) {
                             foreach ($caches as $cache) {
                                 @unlink($cache);
                             }
                         }
                         $this->Image->id = $image_id;
                         $this->data['Image']['captured_on'] = $captured_on;
                         $this->data['Image']['filesize'] = filesize($lg_path);
                         $this->data['Image']['tags'] = $tags;
                         $this->Image->save($this->data);
                     }
                     if ($upload_type == 3) {
                         $album['Album']['aTn'] = "{$file}:{$id}:50:50";
                         $album['Album']['preview_id'] = $image_id;
                         $this->Image->Album->save($album);
                     } else {
                         if ($upload_type > 4) {
                             if ($upload_type == 5) {
                                 $data = array('lg_preview' => "'{$file}:50:50'", 'lg_preview_id' => $image_id);
                             } else {
                                 $data = array('tn_preview' => "'{$file}:50:50'", 'tn_preview_id' => $image_id);
                             }
                             $this->Image->updateAll($data, array('Image.id' => $image['Image']['id']));
                         }
                     }
                     if (is_numeric($account['Account']['archive_w'])) {
                         $this->Kodak->develop($lg_path, $lg_path, $account['Account']['archive_w'], $account['Account']['archive_w'], 100);
                     }
                 }
                 break;
         }
     }
     // Reset umask
     umask($old_mask);
     @unlink(CACHE . DS . DIR_CACHE . DS . 'users.cache');
     // Exit with some empty space so onComplete always fires in flash/Mac
     exit(' ');
 }
Esempio n. 6
0
 function upload()
 {
     if ($this->get) {
         $this->_error('This action is not supported for GET requests.');
     }
     $src = $_FILES['data']['name']['photo'];
     $tmp = $_FILES['data']['tmp_name']['photo'];
     $src = str_replace(" ", "_", $src);
     $src = ereg_replace("[^A-Za-z0-9._-]", "_", $src);
     $this->loadModel('Image');
     $album = $this->Image->Album->read(null, $this->data['Album']['id']);
     $album_active = $album['Album']['active'];
     $dest = ALBUMS . DS . 'album-' . $album['Album']['id'] . DS . 'lg' . DS . $src;
     if (!allowableFile($src)) {
         $this->_error("{$src} is not an allowed file type.");
     }
     $check = $this->Image->find("aid = {$this->data['Album']['id']} AND src = '{$src}'");
     if (is_uploaded_file($tmp) && move_uploaded_file($tmp, $dest)) {
         list($meta, $captured_on) = $this->Director->imageMetadata($dest);
         $keywords = $this->Director->parseMetaTags('iptc:keywords', $meta);
         $keywords = str_replace(' ', ',', urldecode($keywords));
         $keywords = ereg_replace("[^,A-Za-z0-9._-]", "", $keywords);
         if (empty($this->data['Image']['tags'])) {
             $this->data['Image']['tags'] = $keywords;
         }
         if (empty($check)) {
             $top = $this->Image->find('first', array('conditions' => "aid = {$this->data['Album']['id']}", 'order' => 'seq DESC'));
             if (empty($top)) {
                 $next = 0;
             } else {
                 $next = $top['Image']['seq'];
                 if ($top['Image']['active']) {
                     $next++;
                 }
             }
             $data['Image']['title'] = $this->data['Image']['title'];
             $data['Image']['caption'] = $this->data['Image']['caption'];
             $data['Image']['tags'] = $this->data['Image']['tags'];
             $data['Image']['src'] = $src;
             $data['Image']['aid'] = $album['Album']['id'];
             $data['Image']['seq'] = $next;
             $data['Image']['created_by'] = $data['Image']['updated_by'] = $this->data['User']['id'];
             $data['Image']['captured_on'] = $captured_on;
             $data['Image']['filesize'] = filesize($dest);
             $data['Image']['is_video'] = isVideo($src);
             $data['Image']['album_active'] = $album_active;
             $this->Image->save($data);
             $this->Image->Album->reorder($this->data['Album']['id']);
             $this->set('image_id', $this->Image->getLastInsertId());
         } else {
             $image_id = $check['Image']['id'];
             $caches = glob(ALBUMS . DS . 'album-' . $check['Album']['id'] . DS . 'cache' . DS . $check['Image']['src'] . '*');
             if (!empty($caches)) {
                 foreach ($caches as $cache) {
                     @unlink($cache);
                 }
             }
             $this->Image->id = $image_id;
             $data['Image']['captured_on'] = $captured_on;
             $data['Image']['filesize'] = filesize($dest);
             $data['Image']['tags'] = $this->data['Image']['tags'];
             $this->Image->save($this->data);
             $this->set('image_id', $image_id);
         }
         if (is_numeric($this->account['Account']['archive_w'])) {
             $this->Kodak->develop($lg_path, $lg_path, $this->account['Account']['archive_w'], $this->account['Account']['archive_w'], 100);
         }
     }
     $this->render('content/upload.xml');
 }
Esempio n. 7
0
 function edit($id, $tab = 'settings', $part_id = 0)
 {
     $this->cacheAction = 30000;
     $this->pageTitle = __('Albums', true);
     $this->Album->id = $id;
     $this->data = $this->Album->find('first', array('conditions' => array('Album.id' => $id)));
     if (empty($this->data)) {
         $this->redirect('/albums');
     }
     switch ($tab) {
         case 'summary':
             $this->redirect('/albums/edit/' . $id);
             break;
         case 'settings':
             $this->loadModel('Watermark');
             $this->set('watermarks', $this->Watermark->find('all', array('order' => 'main DESC')));
             $this->set('galleries', $this->Album->Tag->Gallery->find('all', array('fields' => 'Gallery.id, Gallery.name, Gallery.description', 'order' => 'Gallery.name', 'conditions' => 'Gallery.smart = 0', 'recursive' => -1)));
             $templates_folder = new Folder(PLUGS . DS . 'links');
             $link_templates = $templates_folder->ls(true, false);
             $this->set('link_templates', $link_templates[1]);
             $custom_templates_folder = new Folder(CUSTOM_PLUGS . DS . 'links');
             $custom_link_templates = $custom_templates_folder->ls(true, array('sample', '.', '..', '.svn'));
             $this->set('custom_link_templates', $custom_link_templates[0]);
             $iptcs = $this->Director->iptcTags;
             natsort($iptcs);
             $exifs = $this->Director->exifTags;
             natsort($exifs);
             $dirs = $this->Director->dirTags;
             if ($this->data['Album']['smart']) {
                 $dirs = array_merge($dirs, $this->Director->smartTags);
             }
             natsort($dirs);
             $this->set('iptcs', $iptcs);
             $this->set('exifs', $exifs);
             $this->set('dirs', $dirs);
             if ($this->data['Album']['smart']) {
                 list($images, ) = $this->_smart_content(unserialize($this->data['Album']['smart_query']));
                 $this->set('images', $images);
             } else {
                 $this->set('images', $this->data['Image']);
             }
             break;
         case 'content':
             $this->set('load_maps_js', true);
             $this->set('mp3s', $this->Director->directory(AUDIO, 'mp3,MP3'));
             if ($this->data['Album']['smart']) {
                 list($images, ) = $this->_smart_content(unserialize($this->data['Album']['smart_query']));
                 $this->set('images', $images);
                 $this->set('options', unserialize($this->data['Album']['smart_query']));
                 $this->set('active_dummies', $this->Album->find('all', array('conditions' => array('smart' => 0, 'active' => '1'), 'order' => 'name', 'recursive' => -1, 'fields' => 'Album.id, Album.name')));
             } else {
                 $this->set('images', $this->data['Image']);
                 $this->set('other_albums', $this->Album->find('all', array('conditions' => array('not' => array('Album.id' => $id, 'Album.smart' => 1)), 'recursive' => -1, 'fields' => 'Album.id, Album.name', 'order' => 'name')));
                 $preview_ids = array();
                 foreach ($this->data['Image'] as $i) {
                     if ($i['is_video']) {
                         if (!empty($i['lg_preview_id'])) {
                             $preview_ids[] = $i['lg_preview_id'];
                         }
                         if (!empty($i['tn_preview_id'])) {
                             $preview_ids[] = $i['tn_preview_id'];
                         }
                     }
                 }
                 $this->set('preview_ids', $preview_ids);
             }
             $this->set('selected_id', $part_id);
             if (function_exists('imagerotate') || $this->Kodak->gdVersion() >= 3) {
                 $rotate = true;
             } else {
                 $rotate = false;
             }
             $this->set('rotate', $rotate);
             break;
         case 'upload':
             if ($this->data['Album']['smart']) {
                 $this->redirect('/albums/edit/' . $this->data['Album']['id'] . '/content');
             }
             $this->set('writable', $this->Director->setAlbumPerms($this->data['Album']['id']));
             $this->set('other_writable', $this->Director->setOtherPerms());
             if (!TRIAL_STATE) {
                 // Check if any new files have been uploaded via FTP
                 $files = $this->Director->directory(ALBUMS . DS . 'album-' . $this->data['Album']['id'] . DS . 'lg', 'accepted');
                 $count = count($this->data['Image']);
                 if (count($files) > $count) {
                     set_time_limit(0);
                     $noobs = array();
                     $n = 1;
                     foreach ($files as $file) {
                         if (strpos($file, '___tn___') === false && strpos($file, '__vidtn__') === false) {
                             $this->Album->Image->recursive = -1;
                             $this->Album->Image->coldSave = true;
                             $img = $this->Album->Image->find(aa('src', $file, 'aid', $id));
                             if (empty($img)) {
                                 $clean = str_replace(" ", "_", $file);
                                 $clean = ereg_replace("[^A-Za-z0-9._-]", "_", $clean);
                                 $path = ALBUMS . DS . 'album-' . $this->data['Album']['id'] . DS . 'lg' . DS . $file;
                                 $clean_path = ALBUMS . DS . 'album-' . $this->data['Album']['id'] . DS . 'lg' . DS . $clean;
                                 if (rename($path, $clean_path)) {
                                     $path = $clean_path;
                                     $file = $clean;
                                 }
                                 list($meta, $captured_on) = $this->Director->imageMetadata($path);
                                 $keywords = $this->Director->parseMetaTags('iptc:keywords', $meta);
                                 $keywords = str_replace(' ', ',', urldecode($keywords));
                                 $keywords = ereg_replace("[^,A-Za-z0-9._-]", "", $keywords);
                                 $new['Image']['tags'] = $keywords;
                                 $new['Image']['aid'] = $id;
                                 $new['Image']['src'] = $file;
                                 $new['Image']['seq'] = $count + $n;
                                 $new['Image']['filesize'] = filesize($path);
                                 $new['Image']['captured_on'] = (int) $captured_on;
                                 $new['Image']['is_video'] = isVideo($file);
                                 $new['Image']['album_active'] = $this->data['Album']['active'];
                                 $this->Album->Image->create();
                                 if ($this->Album->Image->save($new)) {
                                     $noobs[] = $file;
                                     $image_id = $this->Album->Image->getLastInsertId();
                                 }
                                 if (is_numeric($this->account['Account']['archive_w'])) {
                                     $this->Kodak->develop($path, $path, $this->account['Account']['archive_w'], $this->account['Account']['archive_w'], 100);
                                 }
                                 if (isVideo($file)) {
                                     $ffmpeg = $this->Director->ffmpeg();
                                     if ($ffmpeg) {
                                         $info = pathinfo($file);
                                         $ext = $info['extension'];
                                         $lg_path = $path;
                                         exec(FFMPEG_PATH_FINAL . " -i {$lg_path} 2>&1", $out);
                                         foreach ($out as $line) {
                                             if (strpos($line, 'Duration') !== false) {
                                                 preg_match('/Duration: ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $line, $matches);
                                                 list(, $h, $m, $s) = $matches;
                                                 $duration = $h * 60 * 60 + $m * 60 + $s;
                                                 continue;
                                             }
                                         }
                                         $duration = $duration - 2;
                                         $bits = ceil($duration / 12);
                                         if ($bits == 0) {
                                             $bits = 1;
                                         }
                                         $rate = 1 / $bits;
                                         if ($rate < 0.1) {
                                             $rate = 0.1;
                                         }
                                         $dir = dirname($lg_path);
                                         $i = 1;
                                         $cmd = array();
                                         while ($i < $duration) {
                                             $i_str = str_pad($i, 5, '0', STR_PAD_LEFT);
                                             $cmd[] = FFMPEG_PATH_FINAL . " -ss {$i} -r 1 -i {$lg_path} -vframes 1 -an -f mjpeg {$dir}/__vidtn__{$image_id}_{$i_str}.jpg";
                                             $i += $bits;
                                         }
                                         $cmd = join(' && ', $cmd);
                                         exec($cmd);
                                         $thumbs = glob($dir . DS . "__vidtn__{$image_id}_*.jpg");
                                         $tn_file = $lg_path . '.jpg';
                                         if (!empty($thumbs)) {
                                             copy($thumbs[0], $tn_file);
                                         }
                                         if (file_exists($tn_file)) {
                                             $n++;
                                             $vdata = array();
                                             $vdata['Image']['src'] = $file . '.jpg';
                                             $vdata['Image']['aid'] = $id;
                                             $vdata['Image']['seq'] = $count + $n;
                                             $vdata['Image']['filesize'] = filesize($tn_file);
                                             $vdata['Image']['active'] = 0;
                                             $vdata['Image']['is_video'] = 0;
                                             $this->Album->Image->create();
                                             $this->Album->Image->save($vdata);
                                             $pdata = array();
                                             $pdata['Image']['lg_preview_id'] = $this->Album->Image->getLastInsertId();
                                             $pdata['Image']['lg_preview'] = $file . '.jpg:50:50';
                                             $this->Album->Image->create(null);
                                             $this->Album->Image->id = $image_id;
                                             $this->Album->Image->save($pdata);
                                         }
                                     }
                                 }
                                 $n++;
                             }
                             $this->Album->Image->coldSave = false;
                         }
                     }
                     if (count($noobs) > 0) {
                         $this->Album->id = $this->data['Album']['id'];
                         $this->Album->reorder($id);
                         $this->Album->cacheQueries = false;
                         $this->data = $this->Album->read();
                         $this->Album->saveField('images_count', $count + count($noobs));
                         $this->Album->refreshSmartCounts();
                         $this->set('noobs', $noobs);
                     }
                 }
             }
             break;
     }
     $this->set('all_albums', $this->Album->find('all', array('order' => 'name', 'recursive' => -1, 'fields' => 'Album.id, Album.name')));
     $this->set('all_count', $this->Album->find('count', array('conditions' => array('not' => array('Album.id' => $id)), 'recursive' => -1, 'fields' => 'id')));
     $this->set('album', $this->data);
     $this->set('tab', $tab);
 }
 function vandelay()
 {
     $this->checkSession();
     $this->verifyAjax();
     if ($this->data) {
         global $xml_data;
         if (function_exists('set_time_limit')) {
             set_time_limit(0);
         }
         list($account, $users) = $this->Director->fetchAccount();
         $folder = IMPORTS . DS . $this->data['Import']['folder'];
         $xml_file = $folder . DS . 'images.xml';
         $xml_parser = xml_parser_create('UTF-8');
         xml_set_element_handler($xml_parser, a($this, '_startTag'), a($this, '_endTag'));
         xml_set_character_data_handler($xml_parser, a($this, '_contents'));
         $fp = fopen($xml_file, "r");
         $data = fread($fp, filesize($xml_file));
         if (!utf8_encode(utf8_decode($data)) == $data) {
             $data = preg_replace_callback('/"([^"]*)"/', array(&$this, '_encodeForXML'), $data);
         }
         if (!xml_parse($xml_parser, $data, feof($fp))) {
             die("Error on line " . xml_get_current_line_number($xml_parser));
         }
         xml_parser_free($xml_parser);
         fclose($fp);
         $this->loadModel('Gallery');
         $this->data['Gallery']['name'] = $this->data['Import']['folder'];
         $this->Gallery->save($this->data);
         $gallery_id = $this->Gallery->getLastInsertId();
         $order = 1;
         foreach ($xml_data as $album) {
             $album_id = 0;
             $path = '';
             $lg = '';
             $tn = '';
             $director = '';
             $local_path = '';
             $node_count = count($album);
             $a = $album[0];
             $data = array();
             $local_path = isset($a['LGPATH']) ? $a['LGPATH'] : '';
             $local_path = $this->_trimSlashes($local_path);
             $local_fs_path = isset($a['FSPATH']) ? $a['FSPATH'] : '';
             $local_fs_path = $this->_trimSlashes($local_fs_path);
             $local_tn_path = isset($a['TNPATH']) ? $a['TNPATH'] : '';
             $local_tn_path = $this->_trimSlashes($local_tn_path);
             if (is_dir($folder . DS . $local_path) || is_dir($folder . DS . $local_fs_path)) {
                 $data['Album']['active'] = 1;
                 $data['Album']['name'] = isset($a['TITLE']) ? $a['TITLE'] : 'No name';
                 $data['Album']['description'] = isset($a['DESCRIPTION']) ? $a['DESCRIPTION'] : '';
                 $this->Gallery->Tag->Album->create();
                 $this->Gallery->Tag->Album->save($data);
                 $album_id = $this->Gallery->Tag->Album->getLastInsertId();
                 $main = $this->Gallery->find(aa('main', 1));
                 $tag['Tag']['did'] = $main['Gallery']['id'];
                 $tag['Tag']['aid'] = $album_id;
                 $this->Gallery->Tag->save($tag);
                 $path = "album-{$album_id}";
                 $this->Gallery->Tag->Album->id = $album_id;
                 $album_data = $this->Gallery->Tag->Album->read();
                 if ($this->Director->makeDir(ALBUMS . DS . $path) && $this->Director->createAlbumDirs($album_id)) {
                     $lg = ALBUMS . DS . $path . DS . 'lg';
                     // Images
                     for ($i = 1; $i < $node_count; $i++) {
                         $data = array();
                         $img = $album[$i];
                         $original_src = $img['SRC'];
                         $original_src = $this->_trimSlashes($original_src);
                         $file = $folder . DS . $local_path . DS . $original_src;
                         $file_fs = $folder . DS . $local_fs_path . DS . $original_src;
                         if (file_exists($file_fs)) {
                             $file = $file_fs;
                         }
                         if (file_exists($file)) {
                             list(, $captured_on) = $this->Director->imageMetadata($file);
                             $src = basename($file);
                             $data['Image']['aid'] = $album_id;
                             $data['Image']['src'] = $src;
                             $data['Image']['title'] = isset($img['TITLE']) ? $img['TITLE'] : '';
                             $data['Image']['caption'] = isset($img['CAPTION']) ? $img['CAPTION'] : '';
                             $data['Image']['link'] = isset($img['LINK']) ? $img['LINK'] : '';
                             $data['Image']['pause'] = isset($img['PAUSE']) && !empty($img['PAUSE']) ? $img['PAUSE'] : 0;
                             $data['Image']['is_video'] = isVideo($src);
                             $data['Image']['captured_on'] = $captured_on;
                             $data['Image']['seq'] = $i;
                             $this->Gallery->Tag->Album->Image->create();
                             $this->Gallery->Tag->Album->Image->save($data);
                             copy($file, $lg . DS . $src);
                             $new_image_id = $this->Gallery->Tag->Album->Image->getLastInsertId();
                             if (isVideo($file) && isset($img['TN'])) {
                                 $src = $img['TN'];
                                 $file = $folder . DS . $local_tn_path . DS . $src;
                                 list(, $captured_on) = $this->Director->imageMetadata($file);
                                 $data = array();
                                 $data['Image']['aid'] = $album_id;
                                 $data['Image']['src'] = $src;
                                 $data['Image']['is_video'] = 0;
                                 $data['Image']['active'] = 0;
                                 $data['Image']['captured_on'] = $captured_on;
                                 $data['Image']['seq'] = $i + 1;
                                 copy($file, $lg . DS . $src);
                                 $this->Gallery->Tag->Album->Image->create();
                                 $this->Gallery->Tag->Album->Image->save($data);
                                 $preview_id = $this->Gallery->Tag->Album->Image->getLastInsertId();
                                 $preview_str = "{$src}:50:50";
                                 $vdata = array();
                                 $vdata['Image']['lg_preview'] = $vdata['Image']['tn_preview'] = $preview_str;
                                 $vdata['Image']['lg_preview_id'] = $vdata['Image']['tn_preview_id'] = $preview_id;
                                 $this->Gallery->Tag->Album->Image->id = $new_image_id;
                                 $this->Gallery->Tag->Album->Image->save($vdata);
                             }
                         }
                     }
                     // Manage aTn
                     if (isset($a['TN']) && !empty($a['TN'])) {
                         $atn = $this->_trimSlashes($a['TN']);
                         $atn = $folder . DS . $atn;
                         $file = basename($atn);
                         if (!file_exists($lg . DS . $file)) {
                             $this->Gallery->Tag->Album->id = $album_id;
                             $this->Gallery->Tag->Album->saveField('aTn', "{$file}:{$album_id}:50:50");
                             $name = $path . '.' . $this->Director->returnExt($file);
                             copy($atn, $lg . DS . $file);
                             $data = array();
                             $data['Image']['aid'] = $album_id;
                             $data['Image']['src'] = $file;
                             $data['Image']['active'] = 0;
                             $data['Image']['seq'] = 999;
                             $data['Image']['is_video'] = 0;
                             $this->Gallery->Tag->Album->Image->create();
                             $this->Gallery->Tag->Album->Image->save($data);
                             $this->Gallery->Tag->Album->id = $album_id;
                             $this->Gallery->Tag->Album->saveField('preview_id', $this->Gallery->Tag->Album->Image->getLastInsertId());
                         } else {
                             $image = $this->Gallery->Tag->Album->Image->find('first', array('conditions' => array('src' => $file, 'aid' => $album_id)));
                             $this->Gallery->Tag->Album->id = $album_id;
                             $this->Gallery->Tag->Album->saveField('aTn', "{$file}:{$album_id}:50:50");
                             $this->Gallery->Tag->Album->saveField('preview_id', $image['Image']['id']);
                         }
                     }
                     // Audio
                     if (isset($a['AUDIO']) && !empty($a['AUDIO'])) {
                         $audio_file = $this->_trimSlashes($a['AUDIO']);
                         $file = $folder . DS . $audio_file;
                         copy($file, AUDIO . DS . basename($file));
                         $this->Gallery->Tag->Album->saveField('audioFile', basename($file));
                         if (isset($a['AUDIOCAPTION'])) {
                             $this->Gallery->Tag->Album->saveField('audioCap', $a['AUDIOCAPTION']);
                         }
                     }
                     $tag['Tag']['did'] = $gallery_id;
                     $tag['Tag']['aid'] = $album_id;
                     $tag['Tag']['display'] = $order;
                     $this->Gallery->Tag->create();
                     $this->Gallery->Tag->save($tag);
                     $order++;
                 }
             }
         }
         @rename($xml_file, $xml_file . '.done');
         $this->redirect('/galleries/index');
     }
 }