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


PHP Media::getByID方法代码示例

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


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

示例1: renderBody

 public function renderBody()
 {
     if (empty($this->Data['MediaID']) || !($Media = Media::getByID($this->Data['MediaID']))) {
         return '';
     } else {
         return '<div class="content-item content-media" id="contentItem-' . $this->ID . '">' . static::getMediaMarkup($Media) . '</div>';
     }
 }
开发者ID:nbey,项目名称:Emergence-Skeleton,代码行数:8,代码来源:CMS_MediaContent.class.php

示例2: handlePhotoDeleteRequest

 public static function handlePhotoDeleteRequest()
 {
     $GLOBALS['Session']->requireAuthentication();
     $User = static::_getRequestedUser();
     if (empty($_REQUEST['MediaID']) || !is_numeric($_REQUEST['MediaID'])) {
         return static::throwInvalidRequestError();
     }
     if (!($Media = Media::getByID($_REQUEST['MediaID']))) {
         return static::throwNotFoundError();
     }
     if ($Media->ContextClass != $User->getRootClass() || $Media->ContextID != $User->ID) {
         return static::throwUnauthorizedError();
     }
     if ($User->PrimaryPhotoID == $Media->ID) {
         $User->PrimaryPhotoID = null;
         $User->save();
     }
     $Media->destroy();
     return static::respond('profilePhotoDeleted', array('success' => true, 'data' => $Media));
 }
开发者ID:Akujin,项目名称:emergence-skeleton-v2,代码行数:20,代码来源:ProfileRequestHandler.class.php

示例3: handleThumbnailRequest

 public static function handleThumbnailRequest()
 {
     // send caching headers
     $expires = 60 * 60 * 24 * 365;
     header("Cache-Control: public, max-age={$expires}");
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $expires));
     header('Pragma: public');
     // thumbnails are immutable for a given URL, so no need to actually check anything if the browser wants to revalidate its cache
     if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
         header('HTTP/1.0 304 Not Modified');
         exit;
     }
     // get context
     if (!is_numeric(static::peekPath())) {
         $contextClass = static::shiftPath();
         $contextID = is_numeric(static::peekPath()) ? static::shiftPath() : false;
         $mediaID = false;
     } else {
         $contextClass = false;
         $contextID = false;
         $mediaID = static::shiftPath();
     }
     // get format
     if (preg_match('/^(\\d+)x(\\d+)(x([0-9A-F]{6})?)?$/i', static::peekPath(), $matches)) {
         static::shiftPath();
         $maxWidth = $matches[1];
         $maxHeight = $matches[2];
         $fillColor = !empty($matches[4]) ? $matches[4] : false;
     } else {
         $maxWidth = static::$defaultThumbnailWidth;
         $maxHeight = static::$defaultThumbnailHeight;
         $fillColor = false;
     }
     if (static::peekPath() == 'cropped') {
         static::shiftPath();
         $cropped = true;
     } else {
         $cropped = false;
     }
     // load media
     try {
         if ($mediaID) {
             if (!($Media = Media::getByID($mediaID))) {
                 return static::throwNotFoundError('Media not found');
             }
         } elseif ($contextClass && $contextID) {
             if (!($Media = Media::getByContext($contextClass, $contextID))) {
                 $Media = Media::getBlank($contextClass);
             }
         } elseif ($contextClass) {
             if (!($Media = Media::getBlank($contextClass))) {
                 return static::throwNotFoundError('Media not found');
             }
         } else {
             return static::throwError('Invalid request');
         }
         // get thumbnail
         $thumbPath = $Media->getThumbnail($maxWidth, $maxHeight, $fillColor, $cropped);
     } catch (Exception $e) {
         \Emergence\Logger::general_warning('Caught exception while creating thumbnail for media, returning server error', array('exceptionClass' => get_class($e), 'exceptionMessage' => $e->getMessage(), 'exceptionCode' => $e->getCode(), 'recordData' => $Media->getData(), 'thumbFormat' => array('maxWidth' => $maxWidth, 'maxHeight' => $maxHeight, 'fillColor' => $fillColor, 'cropped' => $cropped)));
         return static::throwServerError('Thumbnail unavailable');
     }
     // dump it out
     header("ETag: media-{$Media->ID}-{$maxWidth}-{$maxHeight}-{$fillColor}-{$cropped}");
     header("Content-Type: {$Media->ThumbnailMIMEType}");
     header('Content-Length: ' . filesize($thumbPath));
     readfile($thumbPath);
     exit;
 }
开发者ID:nbey,项目名称:Emergence-Skeleton,代码行数:69,代码来源:MediaRequestHandler.class.php

示例4: onRecordSaved

 protected static function onRecordSaved(CMS_Content $Content, $requestData)
 {
     $responseData = array();
     // save items
     if (is_array($requestData['items'])) {
         $responseData['changedItems'] = array();
         $responseData['newItems'] = array();
         $responseData['deletedItems'] = array();
         $responseData['invalidItems'] = array();
         $responseData['phantomsMap'] = array();
         // sort and save items
         foreach ($requestData['items'] as $itemData) {
             if (!empty($itemData['ID']) && is_numeric($itemData['ID'])) {
                 // modify an existing item
                 $Item = CMS_ContentItem::getByID($itemData['ID']);
                 $Item->setFields($itemData);
                 if ($Item->validate()) {
                     $Item->save();
                     $responseData['changedItems'][$Item->ID] = $Item;
                 } else {
                     $responseData['invalidItems'][] = $Item;
                 }
             } else {
                 // create a new item
                 if (!empty($itemData['Class']) && in_array($itemData['Class'], CMS_ContentItem::$subClasses)) {
                     $className = $itemData['Class'];
                 } else {
                     $className = CMS_ContentItem::$defaultClass;
                 }
                 $itemData['ContentID'] = $Content->ID;
                 $Item = $className::create($itemData);
                 if ($Item->validate()) {
                     $Item->save();
                     $responseData['newItems'][$Item->ID] = $Item;
                     if ($itemData['ID']) {
                         $responseData['phantomsMap'][$itemData['ID']] = $Item->ID;
                     }
                 } else {
                     $responseData['invalidItems'][] = $Item;
                 }
             }
         }
         // remove deleted items
         $currentItemIDs = array_merge(array_keys($responseData['changedItems']), array_keys($responseData['newItems']));
         $responseData['deletedItems'] = array_filter($Content->Items, function ($Item) use($currentItemIDs) {
             return !in_array($Item->ID, $currentItemIDs);
         });
         if ($responseData['deletedItems']) {
             foreach ($responseData['deletedItems'] as $Item) {
                 $Item->Status = 'Deleted';
                 $Item->save();
             }
             $Content->Items = array_filter($Content->Items, function ($Item) {
                 return $Item->Status != 'Deleted';
             });
         }
         // update layout if there were phantoms
         if (is_array($requestData['LayoutConfig']['itemOrder'])) {
             foreach ($requestData['LayoutConfig']['itemOrder'] as &$column) {
                 if (!is_array($column)) {
                     continue;
                 }
                 foreach ($column as &$itemID) {
                     if (array_key_exists($itemID, $responseData['phantomsMap'])) {
                         $itemID = $responseData['phantomsMap'][$itemID];
                     } else {
                         $itemID = (int) $itemID;
                     }
                 }
             }
             $Content->LayoutConfig = $requestData['LayoutConfig'];
         }
     }
     // assign context to media
     if (is_array($requestData['contextMedia'])) {
         foreach ($requestData['contextMedia'] as $mediaID) {
             if (!is_numeric($mediaID)) {
                 continue;
             }
             if (!($Media = Media::getByID($mediaID))) {
                 continue;
             }
             if ($Media->Context) {
                 continue;
             }
             $Media->Context = $Content;
             $Media->save();
         }
     }
     // assign tags
     if (is_array($requestData['tags'])) {
         Tag::setTags($Content, $requestData['tags']);
     }
     // save any page changes
     $Content->save();
 }
开发者ID:nbey,项目名称:Emergence-Skeleton,代码行数:96,代码来源:CMS_ContentRequestHandler.class.php


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