public function action_add_album() { $user = $this->is_logged(); if ($user === false) { return Redirect::to_action('login'); } else { $album = new Album(); if ($_POST['name'] != "") { $album->set_name_album($_POST['name']); } else { $this->_error_msg = "Il y a une erreur dans le nom de l'album."; $this->_error_form = true; } if (is_numeric($_POST['anneeF']) and preg_match("/^[0-2][0-9]{3}+\$/", $_POST['anneeF']) == 1) { $album->set_date_prod_album($_POST['anneeF']); } else { $this->_error_msg .= "<br>Il y a une erreur dans l\\'année de production (Format : AAAA)."; $this->_error_form = true; } if ($this->_error_form == false) { $album->set_id_user_lif($user->get_id_user_lif()); $album->set_id_band($_POST['band']); $album->add(); return Redirect::to_action('album'); } else { return Redirect::to_action('album@add')->with('error', true)->with('form', $_POST)->with('error_msg', $this->_error_msg); } } }
list($url, $params) = explode('?', $url, 2); $method = $_SERVER['REQUEST_METHOD']; list($script, $section, $id, $action) = explode('/', $url, 4); //Находим объект и тип действия try { switch ($section) { 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); }
private function addAlbum() { Module::dependencies(isset($_POST['title'])); $album = new Album($this->database, $this->plugins, $this->settings, null); echo $album->add($_POST['title']); }
public function server($path, $albumID = 0) { # Check dependencies self::dependencies(isset($this->database, $this->plugins, $this->settings)); # Parse path if (!isset($path)) { $path = LYCHEE_UPLOADS_IMPORT; } if (substr($path, -1) === '/') { $path = substr($path, 0, -1); } if (is_dir($path) === false) { Log::error($this->database, __METHOD__, __LINE__, 'Given path is not a directory (' . $path . ')'); return 'Error: Given path is not a directory!'; } # Skip folders of Lychee if ($path === LYCHEE_UPLOADS_BIG || $path . '/' === LYCHEE_UPLOADS_BIG || $path === LYCHEE_UPLOADS_MEDIUM || $path . '/' === LYCHEE_UPLOADS_MEDIUM || $path === LYCHEE_UPLOADS_THUMB || $path . '/' === LYCHEE_UPLOADS_THUMB) { Log::error($this->database, __METHOD__, __LINE__, 'The given path is a reserved path of Lychee (' . $path . ')'); return 'Error: Given path is a reserved path of Lychee!'; } $error = false; $contains['photos'] = false; $contains['albums'] = false; # Call plugins # Note that updated albumId and path explicitly passed, rather # than using func_get_args() which will only return original ones $this->plugins(__METHOD__, 0, array($albumID, $path)); # Get all files $files = glob($path . '/*'); foreach ($files as $file) { # It is possible to move a file because of directory permissions but # the file may still be unreadable by the user if (!is_readable($file)) { $error = true; Log::error($this->database, __METHOD__, __LINE__, 'Could not read file or directory: ' . $file); continue; } if (@exif_imagetype($file) !== false) { # Photo $contains['photos'] = true; if (!$this->photo($file, $albumID)) { $error = true; Log::error($this->database, __METHOD__, __LINE__, 'Could not import file: ' . $file); continue; } } else { if (is_dir($file)) { # Folder $album = new Album($this->database, $this->plugins, $this->settings, null); $newAlbumID = $album->add('[Import] ' . basename($file)); $contains['albums'] = true; if ($newAlbumID === false) { $error = true; Log::error($this->database, __METHOD__, __LINE__, 'Could not create album in Lychee (' . $newAlbumID . ')'); continue; } $import = $this->server($file . '/', $newAlbumID); if ($import !== true && $import !== 'Notice: Import only contains albums!') { $error = true; Log::error($this->database, __METHOD__, __LINE__, 'Could not import folder. Function returned warning.'); continue; } } } } # Call plugins # Note that updated albumId and path explicitly passed, rather # than using func_get_args() which will only return original ones $this->plugins(__METHOD__, 1, array($albumID, $path)); # The following returns will be caught in the front-end if ($contains['photos'] === false && $contains['albums'] === false) { return 'Warning: Folder empty or no readable files to process!'; } if ($contains['photos'] === false && $contains['albums'] === true) { return 'Notice: Import only contained albums!'; } if ($error === true) { return false; } return true; }
public function server($path, $albumID = 0) { # Check dependencies self::dependencies(isset($this->settings)); # Parse path if (!isset($path)) { $path = LYCHEE_UPLOADS_IMPORT; } if (substr($path, -1) === '/') { $path = substr($path, 0, -1); } if (is_dir($path) === false) { return 'Error: Given path is not a directory!'; } # Skip folders of Lychee if ($path === LYCHEE_UPLOADS_BIG || $path . '/' === LYCHEE_UPLOADS_BIG || $path === LYCHEE_UPLOADS_MEDIUM || $path . '/' === LYCHEE_UPLOADS_MEDIUM || $path === LYCHEE_UPLOADS_THUMB || $path . '/' === LYCHEE_UPLOADS_THUMB) { return 'Error: Given path is a reserved path of Lychee!'; } $error = false; $contains['photos'] = false; $contains['albums'] = false; # Get all files $files = glob($path . '/*'); foreach ($files as $file) { # It is possible to move a file because of directory permissions but # the file may still be unreadable by the user if (!is_readable($file)) { $error = true; continue; } if (@exif_imagetype($file) !== false) { # Photo $contains['photos'] = true; if (!$this->photo($file, $albumID)) { $error = true; continue; } } else { if (is_dir($file)) { # Folder $album = new Album($this->settings, null); $newAlbumID = $album->add('[Import] ' . basename($file)); $contains['albums'] = true; if ($newAlbumID === false) { $error = true; continue; } $import = $this->server($file . '/', $newAlbumID); if ($import !== true && $import !== 'Notice: Import only contains albums!') { $error = true; continue; } } } } # The following returns will be caught in the front-end if ($contains['photos'] === false && $contains['albums'] === false) { return 'Warning: Folder empty or no readable files to process!'; } if ($contains['photos'] === false && $contains['albums'] === true) { return 'Notice: Import only contained albums!'; } if ($error === true) { return false; } return true; }
public function for_song() { $error = array(); $song_clem = DB::connection('clem')->query('SELECT title, album, artist, albumartist, year, genre, filename,track FROM songs'); foreach ($song_clem as $value) { /* AJOUT D'ARTISTES */ if (trim($value->artist) != '') { $band = new Band(null, 1, utf8_encode($value->artist), null, null); try { $band->add(); } catch (Exception $e) { $this->_error_msg .= 'artiste :' . $e->getMessage() . '<br>'; break; } } /* AJOUT D'ALBUM */ if (trim($value->album) != '') { $name_band = Band::from_name_band(utf8_encode($value->artist)); $album = new Album(null, $name_band[0]->id_band, 1, utf8_encode($value->album), $value->year); try { $album->add(); } catch (Exception $e) { $this->_error_msg .= 'album: ' . $e->getMessage() . '<br>'; break; } } if (trim($value->title) != '') { $album = Album::from_name_album(utf8_encode($value->album)); $song = new song(null, 1, utf8_encode($value->title), $value->year, null, $value->filename, $value->track); $song->set_id_kind(explode(';', $value->genre)); $song->id_album = $album[0]->id_album; try { $song->add(); } catch (Exception $e) { $this->_error_msg .= 'chanson: ' . $e->getMessage() . '<br>'; break; } } } // var_dump($song_clem); }
static function server($albumID = 0, $path) { global $database, $plugins, $settings; # Parse path if (!isset($path)) { $path = LYCHEE_UPLOADS_IMPORT; } if (substr($path, -1) === '/') { $path = substr($path, 0, -1); } if (is_dir($path) === false) { Log::error($database, __METHOD__, __LINE__, 'Given path is not a directory (' . $path . ')'); return 'Error: Given path is not a directory!'; } # Skip folders of Lychee if ($path === LYCHEE_UPLOADS_BIG || $path . '/' === LYCHEE_UPLOADS_BIG || $path === LYCHEE_UPLOADS_MEDIUM || $path . '/' === LYCHEE_UPLOADS_MEDIUM || $path === LYCHEE_UPLOADS_THUMB || $path . '/' === LYCHEE_UPLOADS_THUMB) { Log::error($database, __METHOD__, __LINE__, 'The given path is a reserved path of Lychee (' . $path . ')'); return 'Error: Given path is a reserved path of Lychee!'; } $error = false; $contains['photos'] = false; $contains['albums'] = false; # Invoke plugins directly, as instance method not valid here # Note that updated albumId and path explicitly passed, rather # than using func_get_args() which will only return original ones $plugins->activate(__METHOD__ . ":before", array($albumID, $path)); # Get all files $files = glob($path . '/*'); foreach ($files as $file) { # It is possible to move a file because of directory permissions but # the file may still be unreadable by the user if (!is_readable($file)) { $error = true; Log::error($database, __METHOD__, __LINE__, 'Could not read file or directory: ' . $file); continue; } if (@exif_imagetype($file) !== false) { # Photo if (!Import::photo($database, $plugins, $settings, $file, $albumID)) { $error = true; Log::error($database, __METHOD__, __LINE__, 'Could not import file: ' . $file); continue; } $contains['photos'] = true; } else { if (is_dir($file)) { # Folder $name = mysqli_real_escape_string($database, basename($file)); $album = new Album($database, null, null, null); $newAlbumID = $album->add('[Import] ' . $name); $contains['albums'] = true; if ($newAlbumID === false) { $error = true; Log::error($database, __METHOD__, __LINE__, 'Could not create album in Lychee (' . $newAlbumID . ')'); continue; } $import = Import::server($newAlbumID, $file . '/'); if ($import !== true && $import !== 'Notice: Import only contains albums!') { $error = true; Log::error($database, __METHOD__, __LINE__, 'Could not import folder. Function returned warning'); continue; } } } } # Invoke plugins directly, as instance method not valid here # Note that updated albumId and path explicitly passed, rather # than using func_get_args() which will only return original ones $plugins->activate(__METHOD__ . ":after", array($albumID, $path)); if ($contains['photos'] === false && $contains['albums'] === false) { return 'Warning: Folder empty or no readable files to process!'; } if ($contains['photos'] === false && $contains['albums'] === true) { return 'Notice: Import only contains albums!'; } return true; }
static function server($albumID = 0, $path, $useTemp = false) { global $database, $plugins, $settings; # Parse path if (!isset($path)) { $path = LYCHEE_UPLOADS_IMPORT; } if (substr($path, -1) === '/') { $path = substr($path, 0, -1); } if (is_dir($path) === false) { Log::error($database, __METHOD__, __LINE__, 'Given path is not a directory (' . $path . ')'); return 'Error: Given path is not a directory!'; } # Skip folders of Lychee if ($path === LYCHEE_UPLOADS_BIG || $path . '/' === LYCHEE_UPLOADS_BIG || $path === LYCHEE_UPLOADS_THUMB || $path . '/' === LYCHEE_UPLOADS_THUMB) { Log::error($database, __METHOD__, __LINE__, 'Given path is a reserved path of Lychee (' . $path . ')'); return 'Error: Given path is a reserved path of Lychee!'; } /*if ($useTemp===true) { $path = Import::move($database, $path); if ($path===false) { Log::error($database, __METHOD__, __LINE__, 'Failed to move import to temporary directory'); return false; } }*/ $error = false; $contains['photos'] = false; $contains['albums'] = false; # Get all files $files = glob($path . '/*'); foreach ($files as $file) { # It is possible to move a file because of directory permissions but # the file may still be unreadable by the user if (!is_readable($file)) { $error = true; Log::error($database, __METHOD__, __LINE__, 'Could not read file or directory: ' . $file); continue; } if (@exif_imagetype($file) !== false) { # Photo if (!Import::photo($database, $plugins, $settings, $file, $albumID)) { $error = true; Log::error($database, __METHOD__, __LINE__, 'Could not import file: ' . $file); continue; } $contains['photos'] = true; } else { if (is_dir($file)) { # Folder $name = mysqli_real_escape_string($database, basename($file)); $album = new Album($database, null, null, null); $newAlbumID = $album->add('[Import] ' . $name); $contains['albums'] = true; if ($newAlbumID === false) { $error = true; Log::error($database, __METHOD__, __LINE__, 'Could not create album in Lychee (' . $newAlbumID . ')'); continue; } $import = Import::server($newAlbumID, $file . '/', false); if ($import !== true && $import !== 'Notice: Import only contains albums!') { $error = true; Log::error($database, __METHOD__, __LINE__, 'Could not import folder. Function returned warning'); continue; } } } } # Delete tmpdir if import was successful /*if ($error===false&&$useTemp===true&&file_exists(LYCHEE_DATA . $tmpdirname)) { if (@rmdir(LYCHEE_DATA . $tmpdirname)===false) Log::error($database, __METHOD__, __LINE__, 'Could not delete temp-folder (' . LYCHEE_DATA . $tmpdirname . ') after successful import'); }*/ if ($contains['photos'] === false && $contains['albums'] === false) { return 'Warning: Folder empty or no readable files to process!'; } if ($contains['photos'] === false && $contains['albums'] === true) { return 'Notice: Import only contains albums!'; } return true; }