예제 #1
0
 protected function EditLibraryMedia()
 {
     $this->response = new ResponseManager();
     $db =& $this->db;
     $user =& $this->user;
     $layoutid = $this->layoutid;
     $regionid = $this->regionid;
     $mediaid = $this->mediaid;
     $userid = $this->user->userid;
     if (!$this->auth->edit) {
         $this->response->SetError('You do not have permission to edit this media.');
         $this->response->keepOpen = false;
         return $this->response;
     }
     // Hand off to the media module
     $mediaObject = new Media($db);
     // Stored As from the XML
     $storedAs = $this->GetOption('uri');
     // File data
     $tmpName = Kit::GetParam('hidFileID', _POST, _STRING);
     $name = Kit::GetParam('name', _POST, _STRING);
     $tags = Kit::GetParam('tags', _POST, _STRING);
     if ($this->auth->modifyPermissions) {
         $this->duration = Kit::GetParam('duration', _POST, _INT, 0, false);
     }
     // Revise this file?
     if ($tmpName != '') {
         Debug::LogEntry('audit', 'Uploading a new revision', 'module', 'EditLibraryMedia');
         // File name and extension (orignial name)
         $fileName = Kit::GetParam('txtFileName', _POST, _STRING);
         if ($name == '') {
             $name = $fileName;
         }
         if (!($new_mediaid = $mediaObject->FileRevise($mediaid, $tmpName, $fileName, $userid))) {
             $this->response->SetError($mediaObject->GetErrorMessage());
             $this->response->keepOpen = true;
             return $this->response;
         }
         // Are we on a region
         if ($regionid != '') {
             $security = new LayoutMediaGroupSecurity($db);
             $security->Copy($layoutid, $regionid, $mediaid, $new_mediaid);
         }
         // Required Attributes
         $this->mediaid = $new_mediaid;
         // Find out what we stored this item as
         try {
             $dbh = PDOConnect::init();
             $sth = $dbh->prepare('SELECT StoredAs FROM `media` WHERE mediaid = :mediaId');
             $sth->execute(array('mediaId' => $new_mediaid));
             $storedAs = Kit::ValidateParam($sth->fetchColumn(0), _FILENAME);
             $this->SetOption('uri', $storedAs);
         } catch (Exception $e) {
             Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__);
             trigger_error(__('Unable to find uploaded file.'), E_USER_ERROR);
         }
         Debug::LogEntry('audit', 'New revision uploaded: ' . $storedAs, 'module', 'EditLibraryMedia');
     }
     // Edit the media record
     if (!$mediaObject->Edit($this->mediaid, $name, $this->duration, $userid, $tags)) {
         $this->response->SetError($mediaObject->GetErrorMessage());
         $this->response->keepOpen = true;
         return $this->response;
     }
     // Should have built the media object entirely by this time
     if ($regionid != '' && $this->showRegionOptions) {
         // This saves the Media Object to the Region
         $this->UpdateRegion();
         $this->response->loadForm = true;
         $this->response->loadFormUri = "index.php?p=timeline&layoutid={$layoutid}&regionid={$regionid}&q=RegionOptions";
     } elseif ($regionid != '' && !$this->showRegionOptions) {
         $this->UpdateRegion();
         $this->response->loadForm = false;
     } else {
         $this->response->message = 'Edited the ' . $this->displayType;
     }
     // Edit from the library - check to see if we are replacing this media in *all* layouts.
     $replaceInLayouts = Kit::GetParam('replaceInLayouts', _POST, _CHECKBOX) == 1;
     $replaceBackgroundImages = Kit::GetParam('replaceBackgroundImages', _POST, _CHECKBOX) == 1;
     if ($mediaid != $this->mediaid && ($replaceInLayouts || $replaceBackgroundImages)) {
         $this->ReplaceMediaInAllLayouts($replaceInLayouts, $replaceBackgroundImages, $mediaid, $this->mediaid, $this->duration);
     }
     // Do we need to delete the old media item?
     if ($tmpName != '' && Kit::GetParam('deleteOldVersion', _POST, _CHECKBOX) == 1) {
         // We pass in the newMediaId as the second parameter so that we can correctly link a prior revision if one exists.
         if (!$mediaObject->Delete($mediaid, $this->mediaid)) {
             $this->response->message .= ' ' . __('Failed to remove old media');
         }
     }
     return $this->response;
 }
예제 #2
0
 /**
  * Delete a Media file from the library
  */
 public function LibraryMediaDelete()
 {
     if (!$this->user->PageAuth('content')) {
         return $this->Error(1, 'Access Denied');
     }
     Kit::ClassLoader('Media');
     $media = new Media();
     $mediaId = $this->GetParam('mediaId', _INT);
     if (!$this->user->MediaAuth($mediaId)) {
         return $this->Error(1, 'Access Denied');
     }
     if (!$media->Delete($mediaId)) {
         return $this->Error($media->GetErrorNumber(), $media->GetErrorMessage());
     }
     return $this->Respond($this->ReturnId('success', true));
 }
예제 #3
0
 /**
  * Removes all expired media files
  */
 public static function removeExpiredFiles()
 {
     $media = new Media();
     // Get a list of all expired files and delete them
     foreach (Media::Entries(NULL, array('expires' => time(), 'allModules' => 1)) as $entry) {
         // If the media type is a module, then pretend its a generic file
         if ($entry->mediaType == 'module') {
             // Find and remove any links to layouts.
             $media->removeModuleFile($entry->mediaId, $entry->storedAs);
         } else {
             // Create a module for it and issue a delete
             include_once 'modules/' . $entry->type . '.module.php';
             $moduleObject = new $entry->type(new database(), new User());
             // Remove it from all assigned layout
             $moduleObject->UnassignFromAll($entry->mediaId);
             // Delete it
             $media->Delete($entry->mediaId);
         }
     }
 }
예제 #4
0
 /**
  * Delete Media from the Database
  * @return
  */
 public function DeleteMedia()
 {
     $db =& $this->db;
     Kit::ClassLoader('Media');
     $mediaObject = new Media($db);
     $layoutid = $this->layoutid;
     $regionid = $this->regionid;
     $mediaid = $this->mediaid;
     // Check permissions
     if (!$this->auth->del) {
         $this->response->SetError('You do not have permission to delete this assignment.');
         $this->response->keepOpen = false;
         return $this->response;
     }
     // Extra work if we are on a layout
     if ($layoutid != '') {
         if (!$this->ApiDeleteRegionMedia($layoutid, $regionid, $mediaid)) {
             $this->response->keepOpen = true;
             $this->response->SetError($this->errorMessage);
             return $this->response;
         }
     }
     // Are we region specific media?
     if (!$this->regionSpecific) {
         $options = Kit::GetParam('options', _POST, _WORD);
         // Unassigning Media needs to remove it from all Layouts the user has permission for.
         if ($options == 'unassignall') {
             if (!$this->UnassignFromAll($mediaid)) {
                 $this->response->SetError($mediaObject->GetErrorMessage());
                 $this->response->keepOpen = true;
                 return $this->response;
             }
         } else {
             if ($options == 'retire') {
                 if (!$mediaObject->Retire($mediaid)) {
                     $this->response->SetError($mediaObject->GetErrorMessage());
                     $this->response->keepOpen = true;
                     return $this->response;
                 }
             } else {
                 if ($options == 'delete') {
                     if (!$mediaObject->Delete($mediaid)) {
                         $this->response->SetError($mediaObject->GetErrorMessage());
                         $this->response->keepOpen = true;
                         return $this->response;
                     }
                 }
             }
         }
         $this->response->message = __('Completed Successfully');
     }
     // We want to load the region timeline form back again
     if ($layoutid != '') {
         $this->response->loadForm = true;
         $this->response->loadFormUri = "index.php?p=timeline&layoutid={$layoutid}&regionid={$regionid}&q=RegionOptions";
     }
     return $this->response;
 }
예제 #5
0
 public function TidyLibrary($tidyOldRevisions, $cleanUnusedFiles)
 {
     // Also run a script to tidy up orphaned media in the library
     $library = Config::GetSetting('LIBRARY_LOCATION');
     $library = rtrim($library, '/') . '/';
     $mediaObject = new Media();
     Debug::Audit('Library Location: ' . $library);
     // Dump the files in the temp folder
     foreach (scandir($library . 'temp') as $item) {
         if ($item == '.' || $item == '..') {
             continue;
         }
         Debug::Audit('Deleting temp file: ' . $item);
         unlink($library . 'temp' . DIRECTORY_SEPARATOR . $item);
     }
     $media = array();
     $unusedMedia = array();
     $unusedRevisions = array();
     // Run a query to get an array containing all of the media in the library
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('
             SELECT media.mediaid, media.storedAs, media.type, media.isedited,
                 SUM(CASE WHEN IFNULL(lklayoutmedia.lklayoutmediaid, 0) = 0 THEN 0 ELSE 1 END) AS UsedInLayoutCount,
                 SUM(CASE WHEN IFNULL(lkmediadisplaygroup.id, 0) = 0 THEN 0 ELSE 1 END) AS UsedInDisplayCount
               FROM `media`
                 LEFT OUTER JOIN `lklayoutmedia`
                 ON lklayoutmedia.mediaid = media.mediaid
                 LEFT OUTER JOIN `lkmediadisplaygroup`
                 ON lkmediadisplaygroup.mediaid = media.mediaid
             GROUP BY media.mediaid, media.storedAs, media.type, media.isedited ');
         $sth->execute(array());
         foreach ($sth->fetchAll() as $row) {
             $media[$row['storedAs']] = $row;
             // Ignore any module files or fonts
             if ($row['type'] == 'module' || $row['type'] == 'font') {
                 continue;
             }
             // Collect media revisions that aren't used
             if ($tidyOldRevisions && $row['UsedInLayoutCount'] <= 0 && $row['UsedInDisplayCount'] <= 0 && $row['isedited'] > 0) {
                 $unusedRevisions[$row['storedAs']] = $row;
             } else {
                 if ($cleanUnusedFiles && $row['UsedInLayoutCount'] <= 0 && $row['UsedInDisplayCount'] <= 0) {
                     $unusedMedia[$row['storedAs']] = $row;
                 }
             }
         }
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
     //Debug::Audit(var_export($media, true));
     //Debug::Audit(var_export($unusedMedia, true));
     // Get a list of all media files
     foreach (scandir($library) as $file) {
         if ($file == '.' || $file == '..') {
             continue;
         }
         if (is_dir($library . $file)) {
             continue;
         }
         // Ignore thumbnails
         if (strstr($file, 'tn_') || strstr($file, 'bg_')) {
             continue;
         }
         // Is this file in the system anywhere?
         if (!array_key_exists($file, $media)) {
             // Totally missing
             Debug::Audit('Deleting file: ' . $file);
             // If not, delete it
             $mediaObject->DeleteMediaFile($file);
         } else {
             if (array_key_exists($file, $unusedRevisions)) {
                 // It exists but isn't being used any more
                 Debug::Audit('Deleting unused revision media: ' . $media[$file]['mediaid']);
                 $mediaObject->Delete($media[$file]['mediaid']);
             } else {
                 if (array_key_exists($file, $unusedMedia)) {
                     // It exists but isn't being used any more
                     Debug::Audit('Deleting unused media: ' . $media[$file]['mediaid']);
                     $mediaObject->Delete($media[$file]['mediaid']);
                 }
             }
         }
     }
     return true;
 }
예제 #6
0
 public static function Run()
 {
     if (key_exists('MJaxUploadPanel_file', $_FILES)) {
         //Check for posted files
         $objMedia = new Media();
         $objMedia->CreDate = QDateTime::Now();
         $objMedia->IdUser = TWAuthDriver::IdUser();
         $objMedia->Save();
         $strType = $_FILES['MJaxUploadPanel_file']['type'];
         switch ($strType) {
             case 'image/gif':
                 $strSufix = 'gif';
                 break;
             case 'image/png':
                 $strSufix = 'png';
                 break;
             case 'image/jpg':
                 $strSufix = 'jpg';
                 break;
         }
         $objMedia->FileLoc = __UPLOAD_DIRECTORY__ . '/' . $objMedia->IdMedia . '.' . $strSufix;
         if (move_uploaded_file($_FILES['MJaxUploadPanel_file']['tmp_name'], $objMedia->FileLoc)) {
             //Set the Businesses idMediaProfilePic Id
             $arrResponse = array('success' => 'true', 'fileLoc' => $objMedia->FileLoc, 'idMedia' => $objMedia->IdMedia);
             echo json_encode($arrResponse);
             $objMedia->Save();
         } else {
             $objMedia->Delete();
         }
     } else {
         //RENDER IFRAME
         require __DOCROOT__ . __TPL_ASSETS__ . '/_core/MJaxUploadPanel.tpl.php';
     }
 }