Example #1
0
        case 'files':
            //Создаем и инициализируем экземпляр класса для работы с файлами
            $sql = new Sql('fotorama');
            $album = new Album($_REQUEST, array('tableName' => 'fotorama', 'files' => array(array('field' => 'full', 'dir' => 'files_original/', 'fit' => true, 'width' => 1200, 'height' => 1200, 'ext' => 'jpg'), array('field' => 'img', 'dir' => 'files_image/', 'fit' => 'contain', 'width' => 800, 'height' => 800, 'ext' => 'jpg'), array('field' => 'thumb', 'dir' => 'files_thumb/', 'fit' => 'cover', 'width' => 160, 'height' => 160, 'ext' => 'png')), 'maxSize' => '4M', 'maxSpace' => '100M', 'maxNumberOfFiles' => 100, 'allowedType' => array('jpeg', 'jpg', 'png', 'gif', 'bmp', 'psd', 'psp', 'ai', 'eps', 'cdr', 'mp3', 'mp4', 'wav', 'aac', 'aiff', 'midi', 'avi', 'mov', 'mpg', 'flv', 'mpa', 'pdf', 'txt', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'djvu', 'djv', 'bat', 'cmd', 'dll', 'inf', 'ini', 'ocx', 'sys', 'htm', 'html', 'write', 'none', 'zip', 'rar', 'dmg', 'sitx')));
            switch ($method) {
                case 'GET':
                    $res = isset($id) ? $album->getOne($id) : $album->get();
                    break;
                case 'PUT':
                    $res = $album->add();
                    break;
                case 'POST':
                    $res = isset($id) ? $album->update($id, $r) : $sql->savesort($r['sort']);
                    break;
                case 'DELETE':
                    $res = $album->delete($id);
                    break;
            }
            break;
        default:
            throw new Exception('Не получен тип действия', 15);
    }
    if (isset($res)) {
        echo json_encode($res);
    }
} catch (Exception $e) {
    Header('HTTP/1.1 503 Service Unavailable');
    echo json_encode(array('error' => array('msg' => $e->getMessage(), 'code' => $e->getCode())));
}
/**
* Класс для работы с файлами
Example #2
0
 function index()
 {
     list($params, $id, $slug) = $this->parse_params(func_get_args());
     $params['auth'] = $this->auth;
     // Create or update
     if ($this->method != 'get') {
         $a = new Album();
         switch ($this->method) {
             case 'post':
             case 'put':
                 if ($this->method == 'put') {
                     if (isset($params['order'])) {
                         $this->_order($params['order']);
                         $this->redirect("/albums");
                     } else {
                         if (is_null($id)) {
                             $this->error('403', 'Required parameter "id" not present.');
                             return;
                         }
                     }
                     // Update
                     $a->get_by_id($id);
                     if (!$a->exists()) {
                         $this->error('404', "Album with ID: {$id} not found.");
                         return;
                     }
                     $a->old_created_on = $a->created_on;
                     $a->old_published_on = $a->published_on;
                     $a->old_visibility = $a->visibility;
                     $a->current_slug = $a->slug;
                 } else {
                     if (isset($_POST['from_directory'])) {
                         // Cache this to prevent tag spillage from IPTC
                         $tags_cache = $_POST['tags'];
                         if (is_dir($_POST['from_directory'])) {
                             $_POST['tags'] = '';
                             $this->load->helper('directory', 1);
                             $files = directory_map($_POST['from_directory']);
                             $content_ids = array();
                             foreach ($files as $file) {
                                 $c = new Content();
                                 $file = $_POST['from_directory'] . DIRECTORY_SEPARATOR . $file;
                                 $filename = basename($file);
                                 list($internal_id, $path) = $c->generate_internal_id();
                                 if (file_exists($file)) {
                                     if ($path) {
                                         $path .= $filename;
                                     } else {
                                         $this->error('500', 'Unable to create directory for upload.');
                                         return;
                                     }
                                     copy($file, $path);
                                     $from = array();
                                     $from['filename'] = $filename;
                                     $from['internal_id'] = $internal_id;
                                     $from['file_modified_on'] = time();
                                     $c->from_array($from, array(), true);
                                     $content_ids[] = $c->id;
                                 }
                             }
                         }
                         $_POST['tags'] = $tags_cache;
                     }
                 }
                 // Don't allow these fields to be saved generically
                 $private = array('parent_id', 'left_id', 'right_id');
                 if ($a->exists()) {
                     $private[] = 'album_type';
                 }
                 if (isset($_REQUEST['reset_internal_id']) && $_REQUEST['reset_internal_id'] && $a->exists()) {
                     array_shift($private);
                     $_POST['internal_id'] = koken_rand();
                 } else {
                     $private[] = 'internal_id';
                 }
                 foreach ($private as $p) {
                     unset($_POST[$p]);
                 }
                 if ($a->has_db_permission('lock tables')) {
                     $s = new Slug();
                     $t = new Tag();
                     $c = new Content();
                     $cat = new Category();
                     $this->db->query("LOCK TABLE {$a->table} WRITE, {$c->table} WRITE, {$s->table} WRITE, {$t->table} WRITE, {$cat->table} WRITE, {$a->db_join_prefix}albums_content READ, {$a->db_join_prefix}albums_categories READ, {$a->db_join_prefix}albums_tags READ");
                     $locked = true;
                 } else {
                     $locked = false;
                 }
                 try {
                     $a->from_array($_POST, array(), true);
                 } catch (Exception $e) {
                     $this->error('400', $e->getMessage());
                     return;
                 }
                 if ($locked) {
                     $this->db->query('UNLOCK TABLES');
                 }
                 if (isset($_POST['tags'])) {
                     $a->_format_tags($_POST['tags']);
                 } else {
                     if ($this->method === 'put' && isset($_POST['visibility'])) {
                         $a->_update_tag_counts();
                     }
                 }
                 $arr = $a->to_array();
                 if ($this->method === 'post') {
                     Shutter::hook('album.create', $arr);
                 } else {
                     Shutter::hook('album.update', $arr);
                 }
                 if (isset($content_ids)) {
                     $clean = new Album();
                     $clean = $clean->get_by_id($a->id);
                     $clean->manage_content(join(',', $content_ids), 'post', true);
                 }
                 $this->redirect("/albums/{$a->id}");
                 break;
             case 'delete':
                 if (is_null($id)) {
                     $this->error('403', 'Required parameter "id" not present.');
                     return;
                 } else {
                     $prefix = preg_replace('/albums$/', '', $a->table);
                     if ($id === 'trash') {
                         $id = array();
                         $trash = new Trash();
                         $trash->like('id', 'album-')->select_func('REPLACE', '@id', 'album-', '', 'actual_id')->get_iterated();
                         foreach ($trash as $item) {
                             $id[] = (int) $item->actual_id;
                         }
                     } else {
                         if (is_numeric($id)) {
                             $id = array($id);
                         } else {
                             $id = explode(',', $id);
                         }
                     }
                     $tags = array();
                     // Need to loop individually here, otherwise tree can break down
                     foreach ($id as $album_id) {
                         $al = new Album();
                         $al->get_by_id($album_id);
                         if ($al->exists()) {
                             $tags = array_merge($tags, $al->tags);
                             $this->db->query("DELETE FROM {$prefix}trash WHERE id = 'album-{$al->id}'");
                             if ($al->right_id - $al->left_id > 1) {
                                 $children = new Album();
                                 $subs = $children->where('deleted', $al->deleted)->where('visibility', $al->visibility)->where('left_id >', $al->left_id)->where('right_id <', $al->right_id)->where('level >', $al->level)->get_iterated();
                                 foreach ($subs as $sub_album) {
                                     Shutter::hook('album.delete', $sub_album->to_array());
                                     $sub_album->delete();
                                 }
                             }
                             $s = new Slug();
                             $this->db->query("DELETE FROM {$s->table} WHERE id = 'album.{$al->slug}'");
                             Shutter::hook('album.delete', $al->to_array());
                             $al->delete();
                         }
                     }
                     $al->update_set_counts();
                 }
                 exit;
                 break;
         }
     }
     $a = new Album();
     // No id, so we want a list
     if (is_null($id) && !$slug) {
         $final = $a->listing($params);
     } else {
         $defaults = array('neighbors' => false, 'include_empty_neighbors' => false);
         $options = array_merge($defaults, $params);
         $with_token = false;
         if (is_numeric($id)) {
             $album = $a->where('deleted', 0)->get_by_id($id);
         } else {
             if ($slug) {
                 $album = $a->where('deleted', 0)->group_start()->where('internal_id', $slug)->or_where('slug', $slug)->or_like('old_slug', ',' . $slug . ',', 'both')->group_end()->get();
             } else {
                 $album = $a->where('deleted', 0)->where('internal_id', $id)->get();
             }
             if ($album->exists() && $album->internal_id === (is_null($id) ? $slug : $id)) {
                 $with_token = true;
             }
         }
         if (!$album->exists()) {
             $this->error('404', 'Album not found.');
             return;
         }
         if ($a->exists()) {
             if ($a->visibility > 0 && !$this->auth && !$with_token) {
                 if ($a->visibility > 1) {
                     // Private content should 404, leave no trace, etc.
                     $this->error('404', 'Album not found.');
                 } else {
                     $this->error('403', 'Private content.');
                 }
                 return;
             }
             $final = $album->to_array($params);
             $final['context'] = $album->context($options, $this->auth);
         } else {
             $this->error('404', "Album with ID: {$id} not found.");
             return;
         }
         // TODO: This history stuff won't work here anymore
         // if ($this->method == 'put')
         // {
         // 	$h = new History();
         // 	$h->message = array( 'album:update',  $a->title );
         // 	$h->save();
         // }
         // else if ($this->method == 'post')
         // {
         // 	$h = new History();
         // 	$h->message = array( 'album:create',  $a->title );
         // 	$h->save();
         // }
     }
     $this->set_response_data($final);
 }
Example #3
0
 private function deleteAlbum()
 {
     Module::dependencies(isset($_POST['albumIDs']));
     $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']);
     echo $album->delete();
 }
$last_name = $user->last_name;
$email = $user->email;
$user_picture = $user->picture;
if ($user->picture) {
    $img_path = $base_url . "/files/" . $user->picture;
} else {
    $img_path = $base_url . "/images/default.jpg";
}
// Image album delete
try {
    if ($_GET['action'] == 'delete_album' && $uid == $_SESSION['user']['id']) {
        $type = "VIDEO_ALBUM";
        $album = new Album($type);
        $album->collection_id = $_GET['alb_id'];
        $album->album_type = $type;
        $album->delete();
    }
} catch (PAException $e) {
    $msg = "{$e->message}";
    $error = TRUE;
}
// deleting images
try {
    if ($_GET['action'] == 'delete') {
        foreach ($_POST as $k => $v) {
            $delete_videos_id[] = $k;
        }
        array_pop($delete_videos_id);
        foreach ($delete_videos_id as $id) {
            $new_image = new Video();
            $new_image->content_id = $id;
Example #5
0
 function topics()
 {
     list($params, $id) = $this->parse_params(func_get_args());
     if ($this->method === 'get') {
         $a = new Album();
         $params['auth'] = $this->auth;
         $params['flat'] = true;
         $final = $a->where_related('text', 'id', $id)->listing($params);
         $this->set_response_data($final);
     } else {
         list($text_id, $album_id) = $id;
         $text = new Text();
         $t = $text->get_by_id($text_id);
         if (is_numeric($album_id)) {
             $album_id = array($album_id);
         } else {
             $album_id = explode(',', $album_id);
         }
         $album = new Album();
         $albums = $album->where_in('id', $album_id)->get_iterated();
         foreach ($albums as $a) {
             if ($this->method === 'post') {
                 $a->save($t);
             } else {
                 $a->delete($t);
             }
         }
         $this->redirect("/text/{$text_id}");
         exit;
     }
 }
Example #6
0
     if (!$api->checkAuth()) {
         //User not authentified/authorized
         return;
     }
     if (!$api->checkScope('admin')) {
         $api->output(403, 'Admin scope is required for deleting album');
         //indicate the requester do not have the required scope for deleting album
         return;
     }
     if (!$api->checkParameterExists('id', $id)) {
         $api->output(400, 'Album identifier must be provided');
         //Album was not provided, return an error
         return;
     }
     $album = new Album($id);
     if (!$album->delete()) {
         $api->output(500, 'Error during album deletion');
         //something gone wrong :(
         return;
     }
     $api->output(204, null);
     break;
 case 'PUT':
     //update album
     if (!$api->checkAuth()) {
         //User not authentified/authorized
         return;
     }
     if (!$api->checkScope('admin')) {
         $api->output(403, 'Admin scope is required for editing album');
         //indicate the requester do not have the required scope for updating album
Example #7
0
 /**
  * Deletes the album in database and their thumbnails associated.
  * Used in /album/actions/executeRefreshAlbumCollection
  *
  * @param Album $album_object
  */
 public static function deleteAlbum($album_object, $user)
 {
     $album_object->delete();
     Util::deleteThumbnail($album_object, $user);
 }
Example #8
0
        $data = $data . $date . "," . $row[4] . "," . $row[5] . ";";
    }
    $stmt->closeCursor();
    $data = convertToUTF8($data);
    echo $data;
}
//partie suppression
if (isset($_GET['action']) && $_GET['action'] == 1) {
    $notarizealbum = new Notarizealbum($_GET['user'], $_GET['id']);
    $notarizealbum->delete($_GET['user'], $_GET['id']);
}
if (isset($_GET['action']) && $_GET['action'] == 2) {
    $notarizeartist = new Notarizeartist($_GET['user'], $_GET['id']);
    $notarizeartist->delete($_GET['user'], $_GET['id']);
}
if (isset($_GET['action']) && $_GET['action'] == 3) {
    $comment = new Comment($_GET['user'], $_GET['id']);
    $comment->delete($_GET['user'], $_GET['id']);
}
if (isset($_GET['type']) && $_GET['type'] == 'artist') {
    $artist = new Artist($_GET['id']);
    $artist->delete($_GET['id']);
}
if (isset($_GET['type']) && $_GET['type'] == 'album') {
    $album = new Album($_GET['id']);
    $album->delete($_GET['id']);
}
if (isset($_GET['type']) && $_GET['type'] == 'song') {
    $song = new Song($_GET['id']);
    $song->delete($_GET['id']);
}