本文整理汇总了PHP中UrlHelper::getResourceUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlHelper::getResourceUrl方法的具体用法?PHP UrlHelper::getResourceUrl怎么用?PHP UrlHelper::getResourceUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UrlHelper
的用法示例。
在下文中一共展示了UrlHelper::getResourceUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUploadLogo
/**
* Upload a logo for the admin panel.
*/
public function actionUploadLogo()
{
$this->requireAjaxRequest();
$this->requireAdmin();
// Upload the file and drop it in the temporary folder
$uploader = new \qqFileUploader();
try {
// Make sure a file was uploaded
if ($uploader->file && $uploader->file->getSize()) {
$folderPath = craft()->path->getTempUploadsPath();
IOHelper::ensureFolderExists($folderPath);
IOHelper::clearFolder($folderPath, true);
$fileName = IOHelper::cleanFilename($uploader->file->getName());
$uploader->file->save($folderPath . $fileName);
// Test if we will be able to perform image actions on this image
if (!craft()->images->setMemoryForImage($folderPath . $fileName)) {
IOHelper::deleteFile($folderPath . $fileName);
$this->returnErrorJson(Craft::t('The uploaded image is too large'));
}
craft()->images->cleanImage($folderPath . $fileName);
$constraint = 500;
list($width, $height) = getimagesize($folderPath . $fileName);
// If the file is in the format badscript.php.gif perhaps.
if ($width && $height) {
// Never scale up the images, so make the scaling factor always <= 1
$factor = min($constraint / $width, $constraint / $height, 1);
$html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => UrlHelper::getResourceUrl('tempuploads/' . $fileName), 'width' => round($width * $factor), 'height' => round($height * $factor), 'factor' => $factor));
$this->returnJson(array('html' => $html));
}
}
} catch (Exception $exception) {
$this->returnErrorJson($exception->getMessage());
}
$this->returnErrorJson(Craft::t('There was an error uploading your photo'));
}
示例2: includeCpResources
/**
* Includes the plugin's resources for the Control Panel.
*/
protected function includeCpResources()
{
// Prepare config
$config = [];
$config['iconMapping'] = craft()->config->get('iconMapping', 'redactoriconbuttons');
$iconAdminPath = craft()->path->getConfigPath() . 'redactoriconbuttons/icons.svg';
$iconPublicPath = craft()->config->get('iconFile', 'redactoriconbuttons');
if (IOHelper::fileExists($iconAdminPath)) {
$config['iconFile'] = UrlHelper::getResourceUrl('config/redactoriconbuttons/icons.svg');
} elseif ($iconPublicPath) {
$config['iconFile'] = craft()->config->parseEnvironmentString($iconPublicPath);
} else {
$config['iconFile'] = UrlHelper::getResourceUrl('redactoriconbuttons/icons/redactor-i.svg');
}
// Include JS
$config = JsonHelper::encode($config);
$js = "var RedactorIconButtons = {}; RedactorIconButtons.config = {$config};";
craft()->templates->includeJs($js);
craft()->templates->includeJsResource('redactoriconbuttons/redactoriconbuttons.js');
// Include CSS
craft()->templates->includeCssResource('redactoriconbuttons/redactoriconbuttons.css');
// Add external spritemap support for IE9+ and Edge 12
$ieShim = craft()->config->get('ieShim', 'redactoriconbuttons');
if (filter_var($ieShim, FILTER_VALIDATE_BOOLEAN)) {
craft()->templates->includeJsResource('redactoriconbuttons/lib/svg4everybody.min.js');
craft()->templates->includeJs('svg4everybody();');
}
}
示例3: includeScripts
/**
* Load Required Scripts
*
*/
public function includeScripts($form)
{
// Ajax Submit Script
if ($form->formSettings["ajaxSubmit"] == "1") {
craft()->templates->includeJsFile(UrlHelper::getResourceUrl('formbuilder2/js/ajaxsubmit.js'));
}
$fieldLayout = $form->fieldLayout->getFieldLayout();
$fields = $fieldLayout->getFields();
foreach ($fields as $key => $value) {
$field = $value->getField();
if ($field->type == 'Color') {
// Colorpicker
craft()->templates->includeCssFile(UrlHelper::getResourceUrl('formbuilder2/css/libs/colorpicker.css'));
craft()->templates->includeJsFile(UrlHelper::getResourceUrl('formbuilder2/js/libs/colorpicker.js'));
} elseif ($field->type == 'Date') {
// Date & Time Picker
craft()->templates->includeJsFile(UrlHelper::getResourceUrl('/lib/jquery-ui.min.js'));
craft()->templates->includeJsFile(UrlHelper::getResourceUrl('lib/jquery.timepicker/jquery.timepicker.min.js'));
craft()->templates->includeCssFile(UrlHelper::getResourceUrl('formbuilder2/css/libs/datetimepicker.css'));
} elseif ($field->type == 'RichText') {
// WYSIWYG Editor
craft()->templates->includeCssResource('/lib/redactor/redactor.css');
craft()->templates->includeJsResource('/lib/redactor/redactor.min.js');
} elseif ($field->type == 'Lightswitch') {
// Lightswitch
craft()->templates->includeCssFile(UrlHelper::getResourceUrl('formbuilder2/css/libs/lightswitch.css'));
}
}
return;
}
示例4: includeJs
protected function includeJs()
{
$settings = craft()->plugins->getPlugin('npCloudinary')->getSettings();
$cloudinaryResource = UrlHelper::getResourceUrl('npcloudinary/js/cloudinary-jquery.min.js');
craft()->templates->includeJsFile($cloudinaryResource);
craft()->templates->includeJs('$.cloudinary.config({ cloud_name: "' . $settings['cloudName'] . '", api_key: "' . $settings['apiKey'] . '"});');
craft()->templates->includeJs('$.cloudinary.responsive();');
}
示例5: init
function init()
{
if (craft()->request->isCpRequest()) {
craft()->templates->includeHeadHtml('<link rel="shortcut icon" type="image/x-icon" href="' . UrlHelper::getResourceUrl('dashboardicons/favicon.ico') . '">');
craft()->templates->includeHeadHtml('<link rel="apple-touch-icon" href="' . UrlHelper::getResourceUrl('dashboardicons/apple-touch-icon.png') . '">');
craft()->templates->includeHeadHtml('<link rel="apple-touch-icon" sizes="76x76" href="' . UrlHelper::getResourceUrl('dashboardicons/apple-touch-icon-76x76.png') . '">');
craft()->templates->includeHeadHtml('<link rel="apple-touch-icon" sizes="120x120" href="' . UrlHelper::getResourceUrl('dashboardicons/apple-touch-icon-120x120.png') . '">');
craft()->templates->includeHeadHtml('<link rel="apple-touch-icon" sizes="152x152" href="' . UrlHelper::getResourceUrl('dashboardicons/apple-touch-icon-152x152.png') . '">');
craft()->templates->includeHeadHtml('<link rel="mask-icon" href="' . UrlHelper::getResourceUrl('dashboardicons/mask-icon.svg') . '" color="#DA5A47">');
}
}
示例6: init
public function init()
{
parent::init();
if (!craft()->isConsole()) {
if (craft()->request->isCpRequest() && craft()->request->getSegment(1) == 'mailer') {
//Include JS
craft()->templates->includeJsFile(UrlHelper::getResourceUrl('mailer/mailer.js'));
//Turn Profiler off
craft()->log->removeRoute('WebLogRoute');
craft()->log->removeRoute('ProfileLogRoute');
}
}
}
示例7: init
function init()
{
if (craft()->request->isCpRequest()) {
// Check if IE7 - 9
if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/(?i)msie [7-9]/', $_SERVER['HTTP_USER_AGENT'])) {
// Extend History API
craft()->templates->includeFootHtml('<script type="text/javascript" src="' . UrlHelper::getResourceUrl('compatibility/js/native.history.js') . '"></script>');
craft()->templates->includeFootHtml('<script type="text/javascript">var history = History;</script>');
// CSS fixes
craft()->templates->includeCssResource('compatibility/css/style.css');
}
}
}
示例8: actionUploadSiteImage
/**
* Upload a logo for the admin panel.
*
* @return null
*/
public function actionUploadSiteImage()
{
$this->requireAjaxRequest();
$this->requireAdmin();
$type = craft()->request->getRequiredPost('type');
if (!in_array($type, $this->_allowedTypes)) {
$this->returnErrorJson(Craft::t('That is not an accepted site image type.'));
}
// Upload the file and drop it in the temporary folder
$file = UploadedFile::getInstanceByName('image-upload');
try {
// Make sure a file was uploaded
if ($file) {
$fileName = AssetsHelper::cleanAssetName($file->getName());
if (!ImageHelper::isImageManipulatable($file->getExtensionName())) {
throw new Exception(Craft::t('The uploaded file is not an image.'));
}
$folderPath = craft()->path->getTempUploadsPath();
IOHelper::ensureFolderExists($folderPath);
IOHelper::clearFolder($folderPath, true);
move_uploaded_file($file->getTempName(), $folderPath . $fileName);
// Test if we will be able to perform image actions on this image
if (!craft()->images->checkMemoryForImage($folderPath . $fileName)) {
IOHelper::deleteFile($folderPath . $fileName);
$this->returnErrorJson(Craft::t('The uploaded image is too large'));
}
list($width, $height) = ImageHelper::getImageSize($folderPath . $fileName);
if (IOHelper::getExtension($fileName) != 'svg') {
craft()->images->cleanImage($folderPath . $fileName);
} else {
craft()->images->loadImage($folderPath . $fileName)->saveAs($folderPath . $fileName);
}
$constraint = 500;
// If the file is in the format badscript.php.gif perhaps.
if ($width && $height) {
// Never scale up the images, so make the scaling factor always <= 1
$factor = min($constraint / $width, $constraint / $height, 1);
$html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => UrlHelper::getResourceUrl('tempuploads/' . $fileName), 'width' => round($width * $factor), 'height' => round($height * $factor), 'factor' => $factor, 'constraint' => $constraint, 'fileName' => $fileName));
$this->returnJson(array('html' => $html));
}
}
} catch (Exception $exception) {
$this->returnErrorJson($exception->getMessage());
}
$this->returnErrorJson(Craft::t('There was an error uploading your photo'));
}
示例9: actionUploadLogo
/**
* Upload a logo for the admin panel.
*
* @return null
*/
public function actionUploadLogo()
{
$this->requireAjaxRequest();
$this->requireAdmin();
// Upload the file and drop it in the temporary folder
$file = $_FILES['image-upload'];
try {
// Make sure a file was uploaded
if (!empty($file['name']) && !empty($file['size'])) {
$folderPath = craft()->path->getTempUploadsPath();
IOHelper::ensureFolderExists($folderPath);
IOHelper::clearFolder($folderPath, true);
$fileName = AssetsHelper::cleanAssetName($file['name']);
move_uploaded_file($file['tmp_name'], $folderPath . $fileName);
// Test if we will be able to perform image actions on this image
if (!craft()->images->checkMemoryForImage($folderPath . $fileName)) {
IOHelper::deleteFile($folderPath . $fileName);
$this->returnErrorJson(Craft::t('The uploaded image is too large'));
}
list($width, $height) = ImageHelper::getImageSize($folderPath . $fileName);
if (IOHelper::getExtension($fileName) != 'svg') {
craft()->images->cleanImage($folderPath . $fileName);
} else {
// Resave svg files as png
$newFilename = preg_replace('/\\.svg$/i', '.png', $fileName);
craft()->images->loadImage($folderPath . $fileName, $width, $height)->saveAs($folderPath . $newFilename);
IOHelper::deleteFile($folderPath . $fileName);
$fileName = $newFilename;
}
$constraint = 500;
// If the file is in the format badscript.php.gif perhaps.
if ($width && $height) {
// Never scale up the images, so make the scaling factor always <= 1
$factor = min($constraint / $width, $constraint / $height, 1);
$html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => UrlHelper::getResourceUrl('tempuploads/' . $fileName), 'width' => round($width * $factor), 'height' => round($height * $factor), 'factor' => $factor, 'constraint' => $constraint, 'fileName' => $fileName));
$this->returnJson(array('html' => $html));
}
}
} catch (Exception $exception) {
$this->returnErrorJson($exception->getMessage());
}
$this->returnErrorJson(Craft::t('There was an error uploading your photo'));
}
示例10: getInputHtml
public function getInputHtml($name, $value)
{
// Settings
$settings = $this->getSettings();
$aceBasePath = UrlHelper::getResourceUrl('aceeditor/vendor/ace/');
$inputId = craft()->templates->formatInputId($name);
// Data
$data = (include CRAFT_PLUGINS_PATH . 'aceeditor/data/AceEditorData.php');
// Resources
craft()->templates->includeCssResource('aceeditor/stylesheets/editor.css');
craft()->templates->includeJsFile('https://cloud9ide.github.io/emmet-core/emmet.js');
craft()->templates->includeJsResource('aceeditor/vendor/ace/ace.js');
craft()->templates->includeJsResource('aceeditor/vendor/ace/theme-twilight.js');
craft()->templates->includeJsResource('aceeditor/vendor/ace/ext-emmet.js');
craft()->templates->includeJsResource('aceeditor/vendor/ace/ext-language_tools.js');
craft()->templates->includeJsResource('aceeditor/javascripts/editor.js');
craft()->templates->includeJs('new Craft.AceEditorFT("' . craft()->templates->namespaceInputId($inputId) . '","' . $aceBasePath . '",' . JsonHelper::encode($settings) . ');');
// Template
return craft()->templates->render('aceeditor/_fieldtype/index', array("name" => $name, "id" => $inputId, "value" => $value, "settings" => $settings, "modes" => $data['modes']));
}
示例11: init
public function init()
{
parent::init();
require_once "vendor/class.rc4crypt.php";
require_once "vendor/foxycart.cart_validation.php";
$settings = craft()->plugins->getPlugin('foxycart')->getSettings();
\FoxyCart_Helper::setSecret($settings->apikey);
\FoxyCart_Helper::setCartUrl("https://" . $settings->storedomain . "/cart");
if (craft()->request->isCpRequest()) {
craft()->templates->includeCssFile(UrlHelper::getResourceUrl('foxycart/css/foxycart.css'));
}
craft()->on('users.onSaveUser', function (Event $event) {
if (craft()->getEdition() == Craft::Pro) {
$customerId = craft()->foxyCart->updateFoxyCartCustomer($event->params['user']);
if ($customerId) {
craft()->foxyCart->saveCustomerId($event->params['user'], $customerId);
}
}
});
}
示例12: _normalizeCssUrl
/**
* @access private
* @param $match
* @return string
*/
private function _normalizeCssUrl($match)
{
// ignore root-relative, absolute, and data: URLs
if (preg_match('/^(\\/|https?:\\/\\/|data:)/', $match[3])) {
return $match[0];
}
$url = IOHelper::getFolderName(craft()->request->getPath()) . $match[3];
// Make sure this is a resource URL
$resourceTrigger = craft()->config->get('resourceTrigger');
$resourceTriggerPos = strpos($url, $resourceTrigger);
if ($resourceTriggerPos !== false) {
// Give UrlHelper a chance to add the timestamp
$path = substr($url, $resourceTriggerPos + strlen($resourceTrigger));
$url = UrlHelper::getResourceUrl($path);
}
return $match[1] . $url . $match[4];
}
示例13: getUrlForFile
/**
* Get URL for a file.
*
* @param AssetFileModel $file
* @param string $transform
*
* @return string
*/
public function getUrlForFile(AssetFileModel $file, $transform = null)
{
if (!$transform || !ImageHelper::isImageManipulatable(IOHelper::getExtension($file->filename))) {
$sourceType = craft()->assetSources->getSourceTypeById($file->sourceId);
return AssetsHelper::generateUrl($sourceType, $file);
}
// Get the transform index model
$index = craft()->assetTransforms->getTransformIndex($file, $transform);
// Does the file actually exist?
if ($index->fileExists) {
return craft()->assetTransforms->getUrlForTransformByTransformIndex($index);
} else {
if (craft()->config->get('generateTransformsBeforePageLoad')) {
// Mark the transform as in progress
$index->inProgress = true;
craft()->assetTransforms->storeTransformIndexData($index);
// Generate the transform
craft()->assetTransforms->generateTransform($index);
// Update the index
$index->fileExists = true;
craft()->assetTransforms->storeTransformIndexData($index);
// Return the transform URL
return craft()->assetTransforms->getUrlForTransformByTransformIndex($index);
} else {
// Queue up a new Generate Pending Transforms task, if there isn't one already
if (!craft()->tasks->areTasksPending('GeneratePendingTransforms')) {
craft()->tasks->createTask('GeneratePendingTransforms');
}
// Return the temporary transform URL
return UrlHelper::getResourceUrl('transforms/' . $index->id);
}
}
}
示例14: getSourceById
/**
* Returns a source by its ID.
*
* @param int $sourceId
*
* @return AssetSourceModel|null
*/
public function getSourceById($sourceId)
{
// Temporary source?
if (is_null($sourceId)) {
$source = new AssetSourceModel();
$source->id = $sourceId;
$source->name = TempAssetSourceType::sourceName;
$source->type = TempAssetSourceType::sourceType;
$source->settings = array('path' => craft()->path->getAssetsTempSourcePath(), 'url' => rtrim(UrlHelper::getResourceUrl(), '/') . '/tempassets/');
return $source;
} else {
// If we've already fetched all sources we can save ourselves a trip to the DB for source IDs that don't
// exist
if (!$this->_fetchedAllSources && (!isset($this->_sourcesById) || !array_key_exists($sourceId, $this->_sourcesById))) {
$result = $this->_createSourceQuery()->where('id = :id', array(':id' => $sourceId))->queryRow();
if ($result) {
$source = $this->_populateSource($result);
} else {
$source = null;
}
$this->_sourcesById[$sourceId] = $source;
}
if (!empty($this->_sourcesById[$sourceId])) {
return $this->_sourcesById[$sourceId];
}
}
}
示例15: actionUploadUserPhoto
/**
* Upload a user photo.
*
* @return null
*/
public function actionUploadUserPhoto()
{
$this->requireAjaxRequest();
craft()->userSession->requireLogin();
$userId = craft()->request->getRequiredPost('userId');
if ($userId != craft()->userSession->getUser()->id) {
craft()->userSession->requirePermission('editUsers');
}
// Upload the file and drop it in the temporary folder
$file = $_FILES['image-upload'];
try {
// Make sure a file was uploaded
if (!empty($file['name']) && !empty($file['size'])) {
$user = craft()->users->getUserById($userId);
$userName = AssetsHelper::cleanAssetName($user->username, false);
$folderPath = craft()->path->getTempUploadsPath() . 'userphotos/' . $userName . '/';
IOHelper::clearFolder($folderPath);
IOHelper::ensureFolderExists($folderPath);
$fileName = AssetsHelper::cleanAssetName($file['name']);
move_uploaded_file($file['tmp_name'], $folderPath . $fileName);
// Test if we will be able to perform image actions on this image
if (!craft()->images->checkMemoryForImage($folderPath . $fileName)) {
IOHelper::deleteFile($folderPath . $fileName);
$this->returnErrorJson(Craft::t('The uploaded image is too large'));
}
craft()->images->cleanImage($folderPath . $fileName);
$constraint = 500;
list($width, $height) = getimagesize($folderPath . $fileName);
// If the file is in the format badscript.php.gif perhaps.
if ($width && $height) {
// Never scale up the images, so make the scaling factor always <= 1
$factor = min($constraint / $width, $constraint / $height, 1);
$html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => UrlHelper::getResourceUrl('userphotos/temp/' . $userName . '/' . $fileName), 'width' => round($width * $factor), 'height' => round($height * $factor), 'factor' => $factor, 'constraint' => $constraint));
$this->returnJson(array('html' => $html));
}
}
} catch (Exception $exception) {
Craft::log('There was an error uploading the photo: ' . $exception->getMessage(), LogLevel::Error);
}
$this->returnErrorJson(Craft::t('There was an error uploading your photo.'));
}