本文整理汇总了PHP中EB::exception方法的典型用法代码示例。如果您正苦于以下问题:PHP EB::exception方法的具体用法?PHP EB::exception怎么用?PHP EB::exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EB
的用法示例。
在下文中一共展示了EB::exception方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validates the quick post submission
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function validate()
{
$content = $this->input->get('content', '', 'default');
if (!$content) {
return EB::exception('COM_EASYBLOG_MICROBLOG_ERROR_EMPTY_CONTENT', 'error');
}
return true;
}
示例2: validate
/**
* Validates the quick post submission
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function validate()
{
$link = $this->input->get('link', '', 'default');
$title = $this->input->get('title', '', 'default');
if (!$link) {
return EB::exception('COM_EASYBLOG_MICROBLOG_ERROR_EMPTY_LINK', 'error');
}
if (!$title) {
return EB::exception('COM_EASYBLOG_MICROBLOG_ERROR_EMPTY_TITLE', 'error');
}
return true;
}
示例3: initDimensions
/**
* Initialize dimensions available
*
* @since 5.0
* @access public
* @param string
* @return
*/
public function initDimensions($imagePath, $size = null)
{
$images = array();
// Ensure that the image really exists on the site.
$exists = JFile::exists($imagePath);
if (!$exists) {
return EB::exception('Invalid file path provided to generate imagesets.', EASYBLOG_MSG_ERROR);
}
// Get the original image resource
$original = EB::simpleimage();
$original->load($imagePath);
// Get the original image file name
$fileName = basename($imagePath);
// Get the original image containing folder
$folder = dirname($imagePath);
// Determines if we should generate a single size or multiple sizes
$sizes = $this->sizes;
if (!is_null($size)) {
$sizes = array($size);
}
// Determines if there's a specific size to generate
foreach ($sizes as $size) {
// Clone the original image to avoid original image width and height being modified
$image = clone $original;
$data = new stdClass();
$data->width = $this->config->get('main_image_' . $size . '_width');
$data->height = $this->config->get('main_image_' . $size . '_height');
$data->quality = $this->config->get('main_image_' . $size . '_quality');
$data->path = $folder . '/' . EBLOG_SYSTEM_VARIATION_PREFIX . '_' . $size . '_' . $fileName;
// Everything should be resized using "resize within" method
$resizeMode = 'resizeWithin';
// Resize the image
$image->{$resizeMode}($data->width, $data->height);
// Save the image
$image->write($data->path, $data->quality);
unset($image);
$images[$size] = $data;
}
unset($original);
return $images;
}
示例4: upload
/**
* Handles uploads from media manager.
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function upload()
{
// Ensure that the user is logged in
EB::requireLogin();
// Only allowed users who are allowed to upload images
if (!$this->acl->get('upload_image')) {
$this->output(EB::exception('COM_EASYBLOG_NOT_ALLOWED', EASYBLOG_MSG_ERROR));
}
// Load up media manager
$mm = EB::mediamanager();
// Get uri
$key = $this->input->getRaw('key');
// Get the target folder
$placeId = EBMM::getUri($key);
// Get the file input
$file = $this->input->files->get('file');
// Check if the file is really allowed to be uploaded to the site.
$state = EB::image()->canUploadFile($file);
if ($state instanceof Exception) {
return $this->output($state);
}
// MM should check if the user really has access to upload to the target folder
$allowed = EBMM::hasAccess($placeId);
if ($allowed instanceof Exception) {
return $this->output($allowed);
}
// Check the image name is it got contain space, if yes need to replace to '-'
$fileName = $file['name'];
$file['name'] = str_replace(' ', '-', $fileName);
// Upload the file now
$file = $mm->upload($file, $placeId);
// Response object is intended to also include
// other properties like status message and status code.
// Right now it only inclues the media item.
$response = new stdClass();
$response->media = EBMM::getMedia($file->uri);
return $this->output($response);
}
示例5: dispatch
/**
* Dispatches pending emails out
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function dispatch($limit = null)
{
if (is_null($limit)) {
$limit = (int) $this->config->get('main_mail_total');
}
$model = EB::model('Mailer');
// Cleanup the mail pool
$model->cleanup();
// Get pending emails
$result = $model->getPendingEmails($limit);
if (!$result) {
return EB::exception('There are no pending emails that needs to be dispatched currently.', EASYBLOG_MSG_INFO);
}
foreach ($result as $row) {
$table = EB::table('MailQueue');
$table->load($row->id);
$table->status = true;
$table->store();
$mailer = JFactory::getMailer();
$mailer->sendMail($table->mailfrom, $table->fromname, $table->recipient, $table->subject, $table->getBody(), true);
}
return EB::exception(JText::sprintf('Processed and sent %1$s emails', count($result)), EASYBLOG_MSG_INFO);
}
示例6: uploadAudio
/**
* Allows uploading of an audio file to the server temporarily.
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function uploadAudio()
{
// Check for request forgeries
// EB::checkToken();
// Ensure that the user is logged in
EB::requireLogin();
// Ensure that the user really has permissions to create blog posts on the site
if (!$this->acl->get('add_entry')) {
EB::exception('COM_EASYBLOG_NO_PERMISSION_TO_CREATE_BLOG', EASYBLOG_MSG_ERROR)->setGlobal();
return $this->ajax->reject();
}
$file = $this->input->files->get('file');
if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
echo JText::_("COM_EASYBLOG_COMPOSER_UNABLE_TO_LOCATE_TEMPORARY_FILE");
exit;
}
// Upload this file into their respective images folder.
$mm = EB::mediamanager();
$path = $mm->getAbsolutePath('/', 'user:' . $this->my->id);
$uri = $mm->getAbsoluteURI('/', 'user:' . $this->my->id);
$result = $mm->upload($file, 'user:' . $this->my->id);
// Get the audio player which needs to be embedded on the composer.
$player = EB::audio()->getPlayer($result->url);
$obj = new stdClass();
$obj->title = $result->title;
$obj->player = $player;
$obj->file = $result->url;
$obj->path = $result->path;
echo json_encode($obj);
exit;
}
示例7: throwAPIException
/**
* Overrides the exception method so that we can silently fail
*
* @since 5.0
* @access public
* @param string
* @return
*/
protected function throwAPIException($result)
{
$e = new EasyBlogFacebookApiException($result);
$message = $e->getMessage();
$exception = EB::exception($message);
throw $exception;
$this->error = $exception;
}
示例8: save
/**
* Saves a quick post item
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function save()
{
// Get the quickpost type
$type = $this->input->get('type', '', 'cmd');
// Test if microblogging is allowed
if (!$this->config->get('main_microblog')) {
$exception = EB::exception(JText::_('COM_EASYBLOG_NO_PERMISSION_TO_CREATE_BLOG'), 'error');
return $this->ajax->reject($exception);
}
// Let's test if the user is a valid user.
if (!$this->acl->get('add_entry') || $this->my->guest) {
$exception = EB::exception(JText::_('COM_EASYBLOG_NO_PERMISSION_TO_CREATE_BLOG'), 'error');
return $this->ajax->reject($exception);
}
// Ensure that the type is provided otherwise we wouldn't know how to process this
if (!$type) {
$exception = EB::exception(JText::_('COM_EASYBLOG_SPECIFY_POST_TYPE'), 'error');
return $this->ajax->reject($exception);
}
// Check if category is set
$category = $this->input->get('category', '', 'int');
if (!$category) {
$exception = EB::exception(JText::_('COM_EASYBLOG_SELECT_CATEGORY_FOR_POST'), 'error');
return $this->ajax->reject($exception);
}
// Get the quickpost object
$quickpost = $this->getQuickpostObject($type);
if ($quickpost === false) {
$exception = EB::exception(JText::_('COM_EASYBLOG_INVALID_POST_TYPE'), 'error');
return $ajax->reject($exception);
}
// Type validations are done here
$state = $quickpost->validate();
if ($state !== true) {
return $this->ajax->reject($state);
}
// Load up the blog object
$data = array();
$arrData = $this->input->getArray('post');
// need to prepare the data before binding with post lib for quick post item
// quick post has limited property. we will just manually assign.
$data['category_id'] = $arrData['category'];
$data['categories'] = array($arrData['category']);
$data['created'] = EB::date()->toSql();
$data['modified'] = EB::date()->toSql();
$data['publish_up'] = EB::date()->toSql();
$data['created_by'] = $this->my->id;
$data['access'] = $this->acl->get('enable_privacy') ? $arrData['privacy'] : 0;
$data['frontpage'] = $this->acl->get('contribute_frontpage') ? true : false;
// If user does not have privilege to store, we need to mark as pending review
if (!$this->acl->get('publish_entry')) {
$data['published'] = EASYBLOG_POST_PENDING;
} else {
$data['published'] = EASYBLOG_POST_PUBLISHED;
}
// quick post is always a sitewide item
$data['source_id'] = 0;
$data['source_type'] = EASYBLOG_POST_SOURCE_SITEWIDE;
// we need to set this as legacy post as the post did not go through composer.
$data['doctype'] = EASYBLOG_POST_DOCTYPE_LEGACY;
$data['tags'] = $arrData['tags'];
// we will let the quickpost adapther to handle the title, content, intro text and .
$data['title'] = isset($arrData['title']) ? $arrData['title'] : '';
$data['content'] = '';
$data['intro'] = '';
$data['posttype'] = '';
$data['allowcomment'] = 1;
$saveOptions = array('applyDateOffset' => false, 'skipCustomFields' => true);
$post = EB::post();
// Create post revision
$post->create($saveOptions);
// binding
$post->bind($data);
// process the content
$quickpost->bind($post);
try {
$post->save($saveOptions);
} catch (EasyBlogException $exception) {
// Reject if there is an error while saving post
return $this->ajax->reject($exception);
}
//save assets * for now only applied to link post
if ($post->posttype == 'link') {
$quickpost->saveAssets($post);
}
$message = $quickpost->getSuccessMessage();
if ($post->isPending()) {
$message = JText::_('COM_EASYBLOG_DASHBOARD_QUICKPOST_SAVED_REQUIRE_MODERATION');
}
return $this->ajax->resolve(EB::exception($message, 'success'));
}
示例9: deleteVariations
/**
* Remove all image variations from the site
*
* @since 5.0
* @access public
* @param string
* @return
*/
public function deleteVariations($uri)
{
// Accepts uri or item.
if (is_string($uri)) {
$item = $this->getItem($uri);
} else {
$item = $uri;
}
$errors = array();
foreach ($item->variations as $key => $variation) {
// Skip original variation
if ($key == 'system/original') {
continue;
}
// Get the variations path
$file = EasyBlogMediaManager::getPath($variation->uri);
if (!JFile::exists($file)) {
$errors[] = $file;
continue;
}
$state = JFile::delete($file);
if (!$state) {
$errors[] = $file;
}
}
if (count($errors)) {
// TODO: Language
return EB::exception('Unable to remove the following image variations: ' . implode(', ', $errors) . '.');
}
return true;
}
示例10: execute
/**
* Imports blog posts from a specific email address
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function execute()
{
// Check if the requirements are set
$state = $this->checkRequirements();
if (!$state) {
return $state;
}
// Get the interval for fetching items
$nextrun = (int) $this->config->get('main_remotepublishing_mailbox_next_run');
$nextrun = EB::date($nextrun)->toUnix();
$now = EB::date()->toUnix();
// Ensure that the processing time is not elapsing
if ($nextrun !== 0 && $now < $nextrun && !$this->debug) {
$time = EB::date($nextrun)->format(JText::_('DATE_FORMAT_LC3'));
// $this->setError('Email service interval is not up yet. Next service is at ' . $time);
return EB::exception('Email service interval is not up yet. Next service is at ' . $time, EASYBLOG_MSG_INFO);
}
// Set the next run time
$this->setNextRunTime();
// Get the mailbox lib
$this->getMailbox();
// Get total emails
$total = $this->mailbox->getMessageCount();
// Check if there are any emails
if ($total < 1) {
$this->mailbox->disconnect();
// TODO: Language
return EB::exception('No emails found in mailbox. Skipping this.', EASYBLOG_MSG_INFO);
}
// Determines if we should fetch emails by specific title
$criteria = $this->config->get('main_remotepublishing_mailbox_prefix');
// Search for messages
$list = $this->search($criteria);
// Go through each items and import them now
$result = array();
$result['success'] = array();
$result['error'] = array();
if ($list === false) {
// TODO: Language
return EB::exception('No emails found in mailbox. Skipping this.', EASYBLOG_MSG_INFO);
}
$total = 0;
foreach ($list as $index) {
$state = $this->import($index);
if ($state === true) {
$total += 1;
}
}
// Disconnect the mailbox when we are done
$this->mailbox->disconnect();
if ($total > 0) {
return EB::exception(JText::sprintf('%1$s emails fetched from mailbox.', $total), EASYBLOG_MSG_INFO);
}
return EB::exception(JText::_('No emails found in mailbox.'), EASYBLOG_MSG_INFO);
}
示例11: cron
/**
* Executes during cron to import items from feeds
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function cron()
{
if (!class_exists('DomDocument')) {
return EB::exception('COM_EASYBLOG_FEEDS_DOMDOCUMENT_MISSING', EASYBLOG_MSG_ERROR);
}
// Get the feeds model
$model = EB::model('Feeds');
$debug = $this->input->get('debug', false, 'bool');
// @TODO: Configurable limit
$limit = 1;
// Get a list of pending feeds
$feeds = $model->getPendingFeeds($limit, $debug);
if (!$feeds) {
return EB::exception('COM_EASYBLOG_FEEDS_NO_FEEDS_TO_IMPORT', EASYBLOG_MSG_INFO);
}
// Determines the total number of feeds imported
$total = 0;
$results = array();
// Import them now
foreach ($feeds as $feed) {
// Update the flag first so that if another cron service is executed, it will not overlap
$feed->flag = 0;
$feed->last_import = EB::date()->toSql();
$feed->store();
// Import them now
$results[] = $this->import($feed);
}
return $results;
}
示例12: save
/**
* Saves a blog post
*
* @since 5.0
* @access public
* @param string
* @return
*/
public function save()
{
try {
$this->verifyAccess();
} catch (EasyBlogException $exception) {
return $this->ajax->reject($exception);
}
// Get uid & data
$uid = $this->input->get('uid');
$data = $this->input->getArray('post');
// Contents needs to be raw
$data['content'] = $this->input->get('content', '', 'raw');
$data['document'] = $this->input->get('document', '', 'raw');
// Load up the post library
$post = EB::post($uid);
$post->bind($data, array());
// Default options
$options = array();
// since this is a form submit and we knwo the date that submited already with the offset timezone. we need to reverse it.
$options['applyDateOffset'] = true;
// check if this is a 'Apply' action or not.
$isApply = $this->input->get('isapply', false, 'bool');
// For autosave requests we do not want to run validation on it.
$autosave = $this->input->get('autosave', false, 'bool');
if ($autosave) {
$options['validateData'] = false;
}
// Notify that post is successfully
$message = $isApply ? 'COM_EASYBLOG_POST_APPLIED_SUCCESS' : 'COM_EASYBLOG_POST_SAVED_SUCCESS';
$state = EASYBLOG_MSG_SUCCESS;
if (!$post->isNew()) {
$message = $isApply ? 'COM_EASYBLOG_POST_APPLIED_SUCCESS' : 'COM_EASYBLOG_POST_UPDATED_SUCCESS';
$state = EASYBLOG_MSG_INFO;
}
// Save post
try {
$post->save($options);
} catch (EasyBlogException $exception) {
// Reject if there is an error while saving post
return $this->ajax->reject($exception);
}
// If this is being submitted for approval
if ($post->isBeingSubmittedForApproval()) {
$message = 'COM_EASYBLOG_POST_SUBMITTED_FOR_APPROVAL';
$state = EASYBLOG_MSG_WARNING;
}
// If this is a draft post.
if ($post->isDraft()) {
$message = 'COM_EASYBLOG_POST_SAVED_FOR_LATER_SUCCESS';
$state = EASYBLOG_MSG_INFO;
}
// For autosave
if ($autosave) {
$date = EB::date();
$date->setTimezone();
$message = JText::sprintf('COM_EASYBLOG_POST_AUTOMATICALLY_SAVED_AT', $date->format(JText::_('COM_EASYBLOG_COMPOSER_AUTOSAVE_TIME_FORMAT'), true));
$state = EASYBLOG_MSG_SUCCESS;
}
$exception = EB::exception($message, $state);
// Resolve with post data
$data = $post->toData();
// Reduces number of slashes.
// TODO: Should this be part of toData();
$data->revision->content = json_decode($data->revision->content);
// Determines if the current page load should be loading from block templates
$postTemplate = EB::table('PostTemplate');
$postTemplate->load($this->input->get('block_template', 0, 'int'));
if (!$postTemplate->id || $postTemplate->id == 1) {
$postTemplate = false;
}
// Generate the revision status html codes
$theme = EB::template();
$theme->set('post', $post);
$theme->set('workingRevision', $post->getWorkingRevision());
$theme->set('revisions', $post->getRevisions());
$theme->set('postTemplate', $postTemplate);
$revisionStatus = $theme->output('site/composer/panel/revisions/list');
// Get the post's edit url
$editLink = $post->getEditLink(false);
// Get the post's preview url
$previewLink = $post->getPreviewLink(false);
return $this->ajax->resolve($data, $exception, $revisionStatus, $editLink, $previewLink);
}
示例13: removeBlankPosts
/**
* Processes the garbage collector on blank posts that already passed 3 days
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function removeBlankPosts()
{
$db = EB::db();
$now = EB::date()->toMySQL();
// Define how long the file will be in database before it gets deleted.
$days = 3;
$query = 'delete a, b from ' . $db->qn('#__easyblog_post') . ' as a';
$query .= ' inner join ' . $db->qn('#__easyblog_revisions') . ' as b on a.' . $db->qn('id') . ' = b.' . $db->qn('post_id');
$query .= ' where a.' . $db->qn('published') . ' = ' . $db->Quote(EASYBLOG_POST_BLANK);
$query .= ' and a.' . $db->qn('created') . ' <= DATE_SUB(' . $db->Quote($now) . ', INTERVAL ' . $days . ' DAY)';
$db->setQuery($query);
$db->query();
return EB::exception('Blank posts removed', EASYBLOG_MSG_INFO);
}
示例14: checkView
/**
* Determines if the current user can view this post or not.
*
* @since 5.0
* @access public
* @param string
* @return
*/
public function checkView()
{
// If the blog post is already deleted, we shouldn't let it to be accessible at all.
if ($this->isTrashed()) {
return EB::exception('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND', 'error');
}
// Check if the blog post is trashed
if (!$this->isPublished() && $this->my->id != $this->created_by && !EB::isSiteAdmin()) {
return EB::exception('COM_EASYBLOG_ENTRY_BLOG_NOT_FOUND', 'error');
}
// Check if the user is allowed to view
if (!$this->checkTeamPrivacy()) {
return EB::exception('COM_EASYBLOG_TEAMBLOG_MEMBERS_ONLY', 'error');
}
// Check if the blog post is accessible.
$accessible = $this->isAccessible();
if (!$accessible->allowed) {
return EB::exception($accessible->error, 'error');
}
return true;
}
示例15: getRevisions
/**
* Retrieves a list of revisions for the post
*
* @since 5.0
* @access public
* @param string
* @return
*/
public function getRevisions()
{
$uid = $this->input->get('uid');
// Load up the post
$post = EB::post($uid);
// Ensure that the user is allowed to edit and view revisions from this post
if (!$post->canEdit()) {
return $this->ajax->reject(EB::exception('You are not allowed to edit this post'));
}
$revisions = $post->getRevisions();
$theme = EB::template();
$theme->set('post', $post);
$theme->set('revisions', $revisions);
$output = $theme->output('site/composer/revisions/list');
return $this->ajax->resolve($output);
}