当前位置: 首页>>代码示例>>PHP>>正文


PHP Media::Add方法代码示例

本文整理汇总了PHP中Media::Add方法的典型用法代码示例。如果您正苦于以下问题:PHP Media::Add方法的具体用法?PHP Media::Add怎么用?PHP Media::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Media的用法示例。


在下文中一共展示了Media::Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: LibraryMediaAdd

 /**
  * Add a media file to the library
  */
 public function LibraryMediaAdd()
 {
     // Does this user have permission to call this webservice method?
     if (!$this->user->PageAuth('content')) {
         return $this->Error(1, 'Access Denied');
     }
     Kit::ClassLoader('Media');
     // Create a media object and gather the required parameters.
     $media = new Media();
     $fileId = $this->GetParam('fileId', _INT);
     $type = $this->GetParam('type', _WORD);
     $name = $this->GetParam('name', _STRING);
     $duration = $this->GetParam('duration', _INT);
     $fileName = $this->GetParam('fileName', _FILENAME);
     // Check permissions
     if (!$this->user->FileAuth($fileId)) {
         return $this->Error(1, 'Access Denied');
     }
     // Add the media.
     if (!($mediaId = $media->Add($fileId, $type, $name, $duration, $fileName, $this->user->userid))) {
         return $this->Error($media->GetErrorNumber(), $media->GetErrorMessage());
     }
     // Return the mediaId.
     return $this->Respond($this->ReturnId('media', $mediaId));
 }
开发者ID:fignew,项目名称:xibo-cms,代码行数:28,代码来源:rest.class.php

示例2: AddLibraryMedia

 /**
  * Adds Library Media
  *  called from inside the FileUpload Handler
  * @param [type] $fileId    [description]
  * @param [type] $mediaName [description]
  * @param [type] $duration  [description]
  * @param [type] $fileName  [description]
  * @return [int] [The ID of the Media Added]
  */
 public function AddLibraryMedia($fileId, $mediaName, $duration, $fileName)
 {
     $this->response = new ResponseManager();
     $db =& $this->db;
     $layoutid = $this->layoutid;
     $regionid = $this->regionid;
     // The media name might be empty here, because the user isn't forced to select it
     if ($mediaName == '') {
         $mediaName = $fileName;
     }
     // Hand off to the media module
     Kit::ClassLoader('media');
     $mediaObject = new Media($db);
     if (!($mediaid = $mediaObject->Add($fileId, $this->type, $mediaName, $duration, $fileName, $this->user->userid))) {
         return $this->SetError($mediaObject->GetErrorMessage());
     }
     Debug::LogEntry('audit', 'Returned MediaId: ' . $mediaid, 'module', 'AddLibraryMedia');
     // Required Attributes
     $this->mediaid = $mediaid;
     $this->duration = $duration;
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('SELECT StoredAs FROM `media` WHERE mediaid = :mediaid');
         $sth->execute(array('mediaid' => $mediaid));
         if (!($row = $sth->fetch())) {
             return $this->SetError(__('Unable to get the storage name'));
         }
         // Find out what we stored this item as
         $storedAs = Kit::ValidateParam($row['StoredAs'], _STRING);
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
     // Any Options
     $this->SetOption('uri', $storedAs);
     // Should have built the media object entirely by this time
     if ($regionid != '') {
         // This saves the Media Object to the Region
         if (!$this->UpdateRegion()) {
             return false;
         }
     }
     // Return the ID of this media
     return $mediaid;
 }
开发者ID:rovak73,项目名称:xibo-cms,代码行数:57,代码来源:module.class.php

示例3: Import

 function Import($zipFile, $layout, $userId, $template, $replaceExisting, $importTags, $delete = true)
 {
     // I think I might add a layout and then import
     if (!file_exists($zipFile)) {
         return $this->SetError(__('File does not exist'));
     }
     // Open the Zip file
     $zip = new ZipArchive();
     if (!$zip->open($zipFile)) {
         return $this->SetError(__('Unable to open ZIP'));
     }
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('SELECT mediaid, storedAs FROM `media` WHERE name = :name AND IsEdited = 0');
         // Get the layout details
         $layoutDetails = json_decode($zip->getFromName('layout.json'), true);
         // Set the layout name
         $layout = $layout != '' ? $layout : $layoutDetails['layout'];
         $description = isset($layoutDetails['description']) ? $layoutDetails['description'] : '';
         // Get the layout xml
         $xml = $zip->getFromName('layout.xml');
         // Add the layout
         if (!($layoutId = $this->Add($layout, $description, NULL, $userId, NULL, NULL, $xml))) {
             return false;
         }
         // Either remove out the tags, or add them to the DB
         if ($importTags) {
             // Pull the tags out of the XML
             $xmlDoc = new DOMDocument();
             $xmlDoc->loadXML($xml);
             $xpath = new DOMXPath($xmlDoc);
             $tagsNode = $xpath->query("//tags");
             foreach ($tagsNode as $tag) {
                 $this->tag($tag->nodeValue, $layoutId);
             }
         } else {
             $this->EditTags($layoutId, array());
         }
         // Are we a template?
         if ($template) {
             $this->tag('template', $layoutId);
         }
         // Tag as imported
         $this->tag('imported', $layoutId);
         // Set the DOM XML
         $this->SetDomXml($layoutId);
         // Set the user on each region
         foreach ($this->DomXml->getElementsByTagName('region') as $region) {
             $region->setAttribute('userId', $userId);
         }
         // Set the user on each media node
         foreach ($this->DomXml->getElementsByTagName('media') as $media) {
             $media->setAttribute('userId', $userId);
         }
         // We will need a file object and a media object
         $fileObject = new File();
         $mediaObject = new Media();
         $currentType = '';
         // Go through each region and add the media (updating the media ids)
         $mappings = json_decode($zip->getFromName('mapping.json'), true);
         foreach ($mappings as $file) {
             Debug::LogEntry('audit', 'Found file ' . json_encode($file));
             // Do we need to recharge our media object
             if ($currentType != '' && $file['type'] != $currentType) {
                 $mediaObject = new Media();
             }
             // Set the current type
             $currentType = $file['type'];
             // Does a media item with this name already exist?
             $sth->execute(array('name' => $file['name']));
             $rows = $sth->fetchAll();
             if (count($rows) > 0) {
                 if ($replaceExisting) {
                     // Alter the name of the file and add it
                     $file['name'] = 'import_' . $layout . '_' . uniqid();
                     // Add the file
                     if (!($fileId = $fileObject->NewFile($zip->getFromName('library/' . $file['file']), $userId))) {
                         return $this->SetError(__('Unable to add a media item'));
                     }
                     // Add this media to the library
                     if (!($mediaId = $mediaObject->Add($fileId, $file['type'], $file['name'], $file['duration'], $file['file'], $userId))) {
                         return $this->SetError($mediaObject->GetErrorMessage());
                     }
                     // Tag it
                     $mediaObject->tag('imported', $mediaId);
                 } else {
                     // Don't add the file, use the one that already exists
                     $mediaObject->mediaId = $rows[0]['mediaid'];
                     $mediaObject->storedAs = $rows[0]['storedAs'];
                 }
             } else {
                 // Add the file
                 if (!($fileId = $fileObject->NewFile($zip->getFromName('library/' . $file['file']), $userId))) {
                     return $this->SetError(__('Unable to add a media item'));
                 }
                 // Add this media to the library
                 if (!($mediaId = $mediaObject->Add($fileId, $file['type'], $file['name'], $file['duration'], $file['file'], $userId))) {
                     return $this->SetError($mediaObject->GetErrorMessage());
                 }
                 // Tag it
//.........这里部分代码省略.........
开发者ID:taphier,项目名称:xibo-cms,代码行数:101,代码来源:layout.data.class.php


注:本文中的Media::Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。