public static function getMedia($settingName) { $metaValue = (int) self::byName($settingName); $media = new MediaModel(); $media->loadByPK($metaValue); return $media->hasLoaded() ? $media : false; }
public function create_image_records($this_id) { $media_model = new MediaModel(); $media_model->where(array('event_id' => $this_id))->delete(); $match_all = array(); preg_match_all('/thumb600_([^\\"]+)\\"/i', $_POST['description'], $match_all); foreach ($match_all[1] as $url) { $media_model->add(array('url' => $url, 'event_id' => $this_id, 'type' => 'image')); } }
public function getMetaField(MetaModel $meta) { $field = $this->decorationFactory($meta); $field->setType('spatial'); if ($meta->getOption('spatialtype') === 'Image') { $media = new MediaModel(); $media->loadByPK($meta->getOption('media')); $field->setUseImage(true); $field->setLayerImage($this->_uploaddir . $media->get('thumbnail')); } return $field; }
public function typeBtnJson() { $value = Ajde::app()->getRequest()->getPostParam('type'); $id = Ajde::app()->getRequest()->getPostParam('id', false); $model = new MediaModel(); if (!is_array($id)) { $id = [$id]; } foreach ($id as $elm) { $model->loadByPK($elm); $model->set('mediatype', $value); $model->save(); } return ['success' => true, 'message' => Ajde_Component_String::makePlural(count($id), 'media') . ' changed']; }
public function view($id) { $event_model = new EventsModel(); $user_model = new UsersModel(); $recommend_model = new RecommendModel(); $media_model = new MediaModel(); $event = $event_model->find($id); $user = $user_model->find($event['user_id']); $recommended_users = $recommend_model->users_by_event($id); $recommended_events = $recommend_model->events_by_event($id); $images = $media_model->select_images_by_event($id); $this->assign('images', $images); $this->assign('event', $event); $this->assign('user', $user); $this->assign('rec_users', $recommended_users); $this->assign('rec_events', $recommended_events); $this->display(); }
function MediaThumbnail($Media, $Data = FALSE) { $Media = (array) $Media; if (GetValue('ThumbPath', $Media)) { $Src = Gdn_Upload::Url(ltrim(GetValue('ThumbPath', $Media), '/')); } else { $Width = GetValue('ImageWidth', $Media); $Height = GetValue('ImageHeight', $Media); if (!$Width || !$Height) { $Height = MediaModel::ThumbnailHeight(); if (!$Height) { $Height = 100; } SetValue('ThumbHeight', $Media, $Height); return DefaultMediaThumbnail($Media); } $RequiresThumbnail = FALSE; if (MediaModel::ThumbnailHeight() && $Height > MediaModel::ThumbnailHeight()) { $RequiresThumbnail = TRUE; } elseif (MediaModel::ThumbnailWidth() && $Width > MediaModel::ThumbnailWidth()) { $RequiresThumbnail = TRUE; } $Path = ltrim(GetValue('Path', $Media), '/'); if ($RequiresThumbnail) { $Src = Url('/utility/thumbnail/' . GetValue('MediaID', $Media, 'x') . '/' . $Path, TRUE); } else { $Src = Gdn_Upload::Url($Path); } } if ($Data) { $Result = array('src' => $Src, 'width' => GetValue('ThumbWidth', $Media), 'height' => GetValue('ThumbHeight', $Media)); } else { $Result = Img($Src, array('class' => 'ImageThumbnail', 'width' => GetValue('ThumbWidth', $Media), 'height' => GetValue('ThumbHeight', $Media))); } return $Result; }
public function events_by_event($id, $type = 'ngo', $count = 6, $has_image = true) { $geo_weight = 10; $category_weight = 200; $event_model = new EventsModel(); $media_model = new MediaModel(); $event = $event_model->find($id); if (!$event) { return false; } $my_longitude = $event['longitude']; $my_latitude = $event['latitude']; $sql = "select id,name,longitude,latitude,description, {$geo_weight}*(abs(longitude-{$my_longitude})+abs(latitude-{$my_latitude})) score from events where type='{$type}' and longitude is not null order by score limit {$count}"; $result = $event_model->query($sql); if ($has_image) { for ($i = 0; $i < count($result); $i++) { $result[$i]['image'] = $media_model->where(array('event_id' => $result[$i]['id'], 'type' => image))->find(); } } return $result; }
/** * TrashFile function. * * @access protected * @param mixed $FileID * @return void */ protected function TrashFile($FileID) { $Media = $this->MediaModel()->GetID($FileID); if ($Media) { $this->MediaModel()->Delete($Media); $Deleted = FALSE; if (!$Deleted) { $DirectPath = MediaModel::PathUploads() . DS . $Media->Path; if (file_exists($DirectPath)) { $Deleted = @unlink($DirectPath); } } if (!$Deleted) { $CalcPath = FileUploadPlugin::FindLocalMedia($Media, TRUE, TRUE); if (file_exists($CalcPath)) { $Deleted = @unlink($CalcPath); } } } }
public function Delete($Media, $DeleteFile = TRUE) { $MediaID = FALSE; if (is_a($Media, 'stdClass')) { $Media = (array) $Media; } if (is_numeric($Media)) { $MediaID = $Media; } elseif (array_key_exists('MediaID', $Media)) { $MediaID = $Media['MediaID']; } if ($MediaID) { $Media = $this->GetID($MediaID); $this->SQL->Delete($this->Name, array('MediaID' => $MediaID), FALSE); if ($DeleteFile) { $DirectPath = MediaModel::PathUploads() . DS . GetValue('Path', $Media); if (file_exists($DirectPath)) { @unlink($DirectPath); } } } else { $this->SQL->Delete($this->Name, $Media, FALSE); } }
/** * Add a method to the ModerationController to handle merging discussions. * * @param Gdn_Controller $Sender */ public function moderationController_mergeDiscussions_create($Sender) { $Session = Gdn::session(); $Sender->Form = new Gdn_Form(); $Sender->title(t('Merge Discussions')); $DiscussionModel = new DiscussionModel(); $CheckedDiscussions = Gdn::userModel()->getAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) { $CheckedDiscussions = array(); } $DiscussionIDs = $CheckedDiscussions; $CountCheckedDiscussions = count($DiscussionIDs); $Discussions = $DiscussionModel->SQL->whereIn('DiscussionID', $DiscussionIDs)->get('Discussion')->resultArray(); // Make sure none of the selected discussions are ghost redirects. $discussionTypes = array_column($Discussions, 'Type'); if (in_array('redirect', $discussionTypes)) { throw new Gdn_UserException('You cannot merge redirects.', 400); } // Check that the user has permission to edit all discussions foreach ($Discussions as $discussion) { if (!DiscussionModel::canEdit($discussion)) { throw permissionException('@' . t('You do not have permission to edit all of the discussions you are trying to merge.')); } } $Sender->setData('DiscussionIDs', $DiscussionIDs); $Sender->setData('CountCheckedDiscussions', $CountCheckedDiscussions); $Sender->setData('Discussions', $Discussions); // Perform the merge if ($Sender->Form->authenticatedPostBack()) { // Create a new discussion record $MergeDiscussion = false; $MergeDiscussionID = $Sender->Form->getFormValue('MergeDiscussionID'); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { $MergeDiscussion = $Discussion; break; } } $RedirectLink = $Sender->Form->getFormValue('RedirectLink'); if ($MergeDiscussion) { $ErrorCount = 0; // Verify that the user has permission to perform the merge. $Category = CategoryModel::categories($MergeDiscussion['CategoryID']); if ($Category && !$Category['PermsDiscussionsEdit']) { throw permissionException('Vanilla.Discussions.Edit'); } $DiscussionModel->defineSchema(); $MaxNameLength = val('Length', $DiscussionModel->Schema->getField('Name')); // Assign the comments to the new discussion record $DiscussionModel->SQL->update('Comment')->set('DiscussionID', $MergeDiscussionID)->whereIn('DiscussionID', $DiscussionIDs)->put(); $CommentModel = new CommentModel(); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { continue; } // Create a comment out of the discussion. $Comment = arrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse')); $Comment['DiscussionID'] = $MergeDiscussionID; $CommentModel->Validation->results(true); $CommentID = $CommentModel->save($Comment); if ($CommentID) { // Move any attachments (FileUpload plugin awareness) if (class_exists('MediaModel')) { $MediaModel = new MediaModel(); $MediaModel->reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment'); } if ($RedirectLink) { // The discussion needs to be changed to a moved link. $RedirectDiscussion = array('Name' => SliceString(sprintf(t('Merged: %s'), $Discussion['Name']), $MaxNameLength), 'Type' => 'redirect', 'Body' => formatString(t('This discussion has been <a href="{url,html}">merged</a>.'), array('url' => DiscussionUrl($MergeDiscussion))), 'Format' => 'Html'); $DiscussionModel->setField($Discussion['DiscussionID'], $RedirectDiscussion); $CommentModel->updateCommentCount($Discussion['DiscussionID']); $CommentModel->removePageCache($Discussion['DiscussionID']); } else { // Delete discussion that was merged. $DiscussionModel->delete($Discussion['DiscussionID']); } } else { $Sender->informMessage($CommentModel->Validation->resultsText()); $ErrorCount++; } } // Update counts on all affected discussions. $CommentModel->updateCommentCount($MergeDiscussionID); $CommentModel->removePageCache($MergeDiscussionID); // Clear selections Gdn::userModel()->saveAttribute($Session->UserID, 'CheckedDiscussions', false); ModerationController::informCheckedDiscussions($Sender); if ($ErrorCount == 0) { $Sender->jsonTarget('', '', 'Refresh'); } } } $Sender->render('MergeDiscussions', '', 'plugins/SplitMerge'); }
/** * Add a method to the ModerationController to handle merging discussions. * @param Gdn_Controller $Sender */ public function ModerationController_MergeDiscussions_Create($Sender) { $Session = Gdn::Session(); $Sender->Form = new Gdn_Form(); $Sender->Title(T('Merge Discussions')); $DiscussionModel = new DiscussionModel(); $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) { $CheckedDiscussions = array(); } $DiscussionIDs = $CheckedDiscussions; $Sender->SetData('DiscussionIDs', $DiscussionIDs); $CountCheckedDiscussions = count($DiscussionIDs); $Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions); $Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray(); $Sender->SetData('Discussions', $Discussions); // Perform the merge if ($Sender->Form->AuthenticatedPostBack()) { // Create a new discussion record $MergeDiscussion = FALSE; $MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID'); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { $MergeDiscussion = $Discussion; break; } } $RedirectLink = $Sender->Form->GetFormValue('RedirectLink'); if ($MergeDiscussion) { $ErrorCount = 0; // Verify that the user has permission to perform the merge. $Category = CategoryModel::Categories($MergeDiscussion['CategoryID']); if ($Category && !$Category['PermsDiscussionsEdit']) { throw PermissionException('Vanilla.Discussions.Edit'); } $DiscussionModel->DefineSchema(); $MaxNameLength = GetValue('Length', $DiscussionModel->Schema->GetField('Name')); // Assign the comments to the new discussion record $DiscussionModel->SQL->Update('Comment')->Set('DiscussionID', $MergeDiscussionID)->WhereIn('DiscussionID', $DiscussionIDs)->Put(); $CommentModel = new CommentModel(); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { continue; } // Create a comment out of the discussion. $Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse')); $Comment['DiscussionID'] = $MergeDiscussionID; $CommentModel->Validation->Results(TRUE); $CommentID = $CommentModel->Save($Comment); if ($CommentID) { // Move any attachments (FileUpload plugin awareness) if (class_exists('MediaModel')) { $MediaModel = new MediaModel(); $MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment'); } if ($RedirectLink) { // The discussion needs to be changed to a moved link. $RedirectDiscussion = array('Name' => SliceString(sprintf(T('Merged: %s'), $Discussion['Name']), $MaxNameLength), 'Type' => 'redirect', 'Body' => FormatString(T('This discussion has been <a href="{url,html}">merged</a>.'), array('url' => DiscussionUrl($MergeDiscussion))), 'Format' => 'Html'); $DiscussionModel->SetField($Discussion['DiscussionID'], $RedirectDiscussion); $CommentModel->UpdateCommentCount($Discussion['DiscussionID']); $CommentModel->RemovePageCache($Discussion['DiscussionID']); } else { // Delete discussion that was merged. $DiscussionModel->Delete($Discussion['DiscussionID']); } } else { $Sender->InformMessage($CommentModel->Validation->ResultsText()); $ErrorCount++; } } // Update counts on all affected discussions. $CommentModel->UpdateCommentCount($MergeDiscussionID); $CommentModel->RemovePageCache($MergeDiscussionID); // Clear selections Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE); ModerationController::InformCheckedDiscussions($Sender); if ($ErrorCount == 0) { $Sender->JsonTarget('', '', 'Refresh'); } } } $Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge'); }
public static function ThumbnailUrl($Media) { $Width = GetValue('ImageWidth', $Media); $Height = GetValue('ImageHeight', $Media); if (!$Width || !$Height) { return '/plugins/FileUpload/images/file.png'; } $RequiresThumbnail = FALSE; if (self::ThumbnailHeight() && $Height > self::ThumbnailHeight()) { $RequiresThumbnail = TRUE; } elseif (self::ThumbnailWidth() && $Width > self::ThumbnailWidth()) { $RequiresThumbnail = TRUE; } $Path = ltrim(GetValue('Path', $Media), '/'); if ($RequiresThumbnail) { $ThumbPath = MediaModel::PathUploads() . "/thumbnails/{$Path}"; if (file_exists(MediaModel::PathUploads() . "/thumbnails/{$Path}")) { $Result = "/uploads/thumbnails/{$Path}"; } else { $Result = "/utility/thumbnail/{$Path}"; } } else { $Result = "/uploads/{$Path}"; } return $Result; }
/** * * * @todo Refactor into different method to maintain compatibility with base class. * * @param array $Media The media row. * @param array|bool $Options Either a boolean that says whether or not to delete the file or an array with a */ public function delete($Media = [], $Options = []) { if (is_bool($Options)) { $DeleteFile = $Options; } else { $DeleteFile = val('Delete', $Options, true); } $MediaID = false; if (is_a($Media, 'stdClass')) { $Media = (array) $Media; } if (is_numeric($Media)) { $MediaID = $Media; } elseif (array_key_exists('MediaID', $Media)) { $MediaID = $Media['MediaID']; } if ($MediaID) { $Media = $this->getID($MediaID); $this->SQL->delete($this->Name, array('MediaID' => $MediaID), false); if ($DeleteFile) { $DirectPath = MediaModel::pathUploads() . DS . val('Path', $Media); if (file_exists($DirectPath)) { @unlink($DirectPath); } } } else { $this->SQL->delete($this->Name, $Media, false); } }
echo '<div class="FileName">'; if (isset($DownloadUrl)) { echo '<a href="' . $DownloadUrl . '">' . htmlspecialchars($Media->Name) . '</a>'; } else { echo htmlspecialchars($Media->Name); } echo '</div>'; echo '<div class="FileAttributes">'; if ($Media->ImageWidth && $Media->ImageHeight) { echo ' <span class="FileSize">' . $Media->ImageWidth . ' x ' . $Media->ImageHeight . '</span> - '; } echo ' <span class="FileSize">', Gdn_Format::Bytes($Media->Size, 0), '</span>'; echo '</div>'; $Actions = ''; if (StringBeginsWith($this->ControllerName, 'post', TRUE)) { $Actions = ConcatSep(' | ', $Actions, '<a class="InsertImage" href="' . Url(MediaModel::Url($Path)) . '">' . T('Insert Image') . '</a>'); } if (GetValue('ForeignTable', $Media) == 'discussion') { $PermissionName = "Vanilla.Discussions.Edit"; } else { $PermissionName = "Vanilla.Comments.Edit"; } if ($IsOwner || Gdn::Session()->CheckPermission($PermissionName, TRUE, 'Category', $this->Data('Discussion.PermissionCategoryID'))) { $Actions = ConcatSep(' | ', $Actions, '<a class="DeleteFile" href="' . Url("/plugin/fileupload/delete/{$Media->MediaID}") . '"><span>' . T('Delete') . '</span></a>'); } if ($Actions) { echo '<div>', $Actions, '</div>'; } ?> </div> </div>
/** * Delete an uploaded file & its media record. * * @access protected * @param int $MediaID Unique ID on Media table. */ protected function TrashFile($MediaID) { $Media = $this->MediaModel()->GetID($MediaID); if ($Media) { $this->MediaModel()->Delete($Media); $Deleted = FALSE; // Allow interception $this->EventArguments['Parsed'] = Gdn_Upload::Parse($Media->Path); $this->EventArguments['Handled'] =& $Deleted; // Allow skipping steps below $this->FireEvent('TrashFile'); if (!$Deleted) { $DirectPath = MediaModel::PathUploads() . DS . $Media->Path; if (file_exists($DirectPath)) { $Deleted = @unlink($DirectPath); } } if (!$Deleted) { $CalcPath = FileUploadPlugin::FindLocalMedia($Media, TRUE, TRUE); if (file_exists($CalcPath)) { $Deleted = @unlink($CalcPath); } } } }
/** * Delete an uploaded file & its media record. * * @param int $MediaID Unique ID on Media table. */ protected function trashFile($MediaID) { $Media = $this->mediaModel()->getID($MediaID); if ($Media) { $this->mediaModel()->delete($Media); $Deleted = false; // Allow interception $this->EventArguments['Parsed'] = Gdn_Upload::parse($Media->Path); $this->EventArguments['Handled'] =& $Deleted; // Allow skipping steps below $this->fireEvent('TrashFile'); if (!$Deleted) { $DirectPath = MediaModel::pathUploads() . DS . $Media->Path; if (file_exists($DirectPath)) { $Deleted = @unlink($DirectPath); } } if (!$Deleted) { $CalcPath = FileUploadPlugin::findLocalMedia($Media, true, true); if (file_exists($CalcPath)) { @unlink($CalcPath); } } } }
/** * 删除 video 数据 */ function del() { //序列化主键Id为:1,2,3,...以便批量删除 $del_id = $_POST['del_id']; $str = implode($del_id, ','); //实例化 $medias = new MediaModel(); //删除文章 if ($medias->delete($str)) { $this->assign('jumpUrl', __URL__ . '/index'); $this->success('音频删除成功'); } else { $this->assign('jumpUrl', __URL__ . '/index'); $this->error('音频删除失败'); } }
/** * Add a method to the ModerationController to handle merging discussions. * @param Gdn_Controller $Sender */ public function ModerationController_MergeDiscussions_Create($Sender) { $Session = Gdn::Session(); $Sender->Form = new Gdn_Form(); $Sender->Title(T('Merge Discussions')); $DiscussionModel = new DiscussionModel(); $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array()); if (!is_array($CheckedDiscussions)) { $CheckedDiscussions = array(); } $DiscussionIDs = $CheckedDiscussions; $Sender->SetData('DiscussionIDs', $DiscussionIDs); $CountCheckedDiscussions = count($DiscussionIDs); $Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions); $Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray(); $Sender->SetData('Discussions', $Discussions); // Perform the merge if ($Sender->Form->AuthenticatedPostBack()) { // Create a new discussion record $MergeDiscussion = FALSE; $MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID'); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { $MergeDiscussion = $Discussion; break; } } if ($MergeDiscussion) { $ErrorCount = 0; // Verify that the user has permission to perform the merge. $Category = CategoryModel::Categories($MergeDiscussion['CategoryID']); if ($Category && !$Category['PermsDiscussionsEdit']) { throw PermissionException('Vanilla.Discussions.Edit'); } // Assign the comments to the new discussion record $DiscussionModel->SQL->Update('Comment')->Set('DiscussionID', $MergeDiscussionID)->WhereIn('DiscussionID', $DiscussionIDs)->Put(); $CommentModel = new CommentModel(); foreach ($Discussions as $Discussion) { if ($Discussion['DiscussionID'] == $MergeDiscussionID) { continue; } // Create a comment out of the discussion. $Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse')); $Comment['DiscussionID'] = $MergeDiscussionID; $CommentModel->Validation->Results(TRUE); $CommentID = $CommentModel->Save($Comment); if ($CommentID) { // Move any attachments (FileUpload plugin awareness) if (class_exists('MediaModel')) { $MediaModel = new MediaModel(); $MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment'); } // Delete discussion that was merged $DiscussionModel->Delete($Discussion['DiscussionID']); } else { $Sender->InformMessage($CommentModel->Validation->ResultsText()); $ErrorCount++; } } // Update counts on all affected discussions. $CommentModel->UpdateCommentCount($MergeDiscussionID); $CommentModel->RemovePageCache($MergeDiscussionID); // Clear selections Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE); ModerationController::InformCheckedDiscussions($Sender); if ($ErrorCount == 0) { $Sender->RedirectUrl = Url("/discussion/{$MergeDiscussionID}/" . Gdn_Format::Url($MergeDiscussion['Name'])); } } } $Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge'); }
public function getMediaModelFromMetaValue($metaId) { $metaValue = (int) $this->getMetaValue($metaId); $media = new MediaModel(); $media->loadByPK($metaValue); return $media->hasLoaded() ? $media : false; }