[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Plugin 5 * @subpackage Editors-xtd.image 6 * 7 * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 10 * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 11 */ 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\Object\CMSObject; 17 use Joomla\CMS\Plugin\CMSPlugin; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Editor Image button 25 * 26 * @since 1.5 27 */ 28 class PlgButtonImage extends CMSPlugin 29 { 30 /** 31 * Load the language file on instantiation. 32 * 33 * @var boolean 34 * @since 3.1 35 */ 36 protected $autoloadLanguage = true; 37 38 /** 39 * Display the button. 40 * 41 * @param string $name The name of the button to display. 42 * @param string $asset The name of the asset being edited. 43 * @param integer $author The id of the author owning the asset being edited. 44 * 45 * @return CMSObject|false 46 * 47 * @since 1.5 48 */ 49 public function onDisplay($name, $asset, $author) 50 { 51 $app = Factory::getApplication(); 52 $doc = $app->getDocument(); 53 $user = Factory::getUser(); 54 $extension = $app->input->get('option'); 55 56 // For categories we check the extension (ex: component.section) 57 if ($extension === 'com_categories') { 58 $parts = explode('.', $app->input->get('extension', 'com_content')); 59 $extension = $parts[0]; 60 } 61 62 $asset = $asset !== '' ? $asset : $extension; 63 64 if ( 65 $user->authorise('core.edit', $asset) 66 || $user->authorise('core.create', $asset) 67 || (count($user->getAuthorisedCategories($asset, 'core.create')) > 0) 68 || ($user->authorise('core.edit.own', $asset) && $author === $user->id) 69 || (count($user->getAuthorisedCategories($extension, 'core.edit')) > 0) 70 || (count($user->getAuthorisedCategories($extension, 'core.edit.own')) > 0 && $author === $user->id) 71 ) { 72 $doc->getWebAssetManager() 73 ->useScript('webcomponent.media-select') 74 ->useScript('webcomponent.field-media') 75 ->useStyle('webcomponent.media-select'); 76 77 $doc->addScriptOptions('xtdImageModal', [ 78 $name . '_ImageModal', 79 ]); 80 81 if (count($doc->getScriptOptions('media-picker')) === 0) { 82 $imagesExt = array_map( 83 'trim', 84 explode( 85 ',', 86 ComponentHelper::getParams('com_media')->get( 87 'image_extensions', 88 'bmp,gif,jpg,jpeg,png,webp' 89 ) 90 ) 91 ); 92 $audiosExt = array_map( 93 'trim', 94 explode( 95 ',', 96 ComponentHelper::getParams('com_media')->get( 97 'audio_extensions', 98 'mp3,m4a,mp4a,ogg' 99 ) 100 ) 101 ); 102 $videosExt = array_map( 103 'trim', 104 explode( 105 ',', 106 ComponentHelper::getParams('com_media')->get( 107 'video_extensions', 108 'mp4,mp4v,mpeg,mov,webm' 109 ) 110 ) 111 ); 112 $documentsExt = array_map( 113 'trim', 114 explode( 115 ',', 116 ComponentHelper::getParams('com_media')->get( 117 'doc_extensions', 118 'doc,odg,odp,ods,odt,pdf,ppt,txt,xcf,xls,csv' 119 ) 120 ) 121 ); 122 123 $doc->addScriptOptions('media-picker', [ 124 'images' => $imagesExt, 125 'audios' => $audiosExt, 126 'videos' => $videosExt, 127 'documents' => $documentsExt 128 ]); 129 } 130 131 Text::script('JFIELD_MEDIA_LAZY_LABEL'); 132 Text::script('JFIELD_MEDIA_ALT_LABEL'); 133 Text::script('JFIELD_MEDIA_ALT_CHECK_LABEL'); 134 Text::script('JFIELD_MEDIA_ALT_CHECK_DESC_LABEL'); 135 Text::script('JFIELD_MEDIA_CLASS_LABEL'); 136 Text::script('JFIELD_MEDIA_FIGURE_CLASS_LABEL'); 137 Text::script('JFIELD_MEDIA_FIGURE_CAPTION_LABEL'); 138 Text::script('JFIELD_MEDIA_LAZY_LABEL'); 139 Text::script('JFIELD_MEDIA_SUMMARY_LABEL'); 140 Text::script('JFIELD_MEDIA_EMBED_CHECK_DESC_LABEL'); 141 Text::script('JFIELD_MEDIA_DOWNLOAD_CHECK_DESC_LABEL'); 142 Text::script('JFIELD_MEDIA_DOWNLOAD_CHECK_LABEL'); 143 Text::script('JFIELD_MEDIA_EMBED_CHECK_LABEL'); 144 Text::script('JFIELD_MEDIA_WIDTH_LABEL'); 145 Text::script('JFIELD_MEDIA_TITLE_LABEL'); 146 Text::script('JFIELD_MEDIA_HEIGHT_LABEL'); 147 Text::script('JFIELD_MEDIA_UNSUPPORTED'); 148 Text::script('JFIELD_MEDIA_DOWNLOAD_FILE'); 149 150 $link = 'index.php?option=com_media&view=media&tmpl=component&e_name=' . $name . '&asset=' . $asset . '&mediatypes=0,1,2,3' . '&author=' . $author; 151 152 $button = new CMSObject(); 153 $button->modal = true; 154 $button->link = $link; 155 $button->text = Text::_('PLG_IMAGE_BUTTON_IMAGE'); 156 $button->name = $this->_type . '_' . $this->_name; 157 $button->icon = 'pictures'; 158 $button->iconSVG = '<svg width="24" height="24" viewBox="0 0 512 512"><path d="M464 64H48C21.49 64 0 85.49 0 112v288c0 26.51 21.49 48' 159 . ' 48 48h416c26.51 0 48-21.49 48-48V112c0-26.51-21.49-48-48-48zm-6 336H54a6 6 0 0 1-6-6V118a6 6 0 0 1 6-6h404a6 6' 160 . ' 0 0 1 6 6v276a6 6 0 0 1-6 6zM128 152c-22.091 0-40 17.909-40 40s17.909 40 40 40 40-17.909 40-40-17.909-40-40-40' 161 . 'zM96 352h320v-80l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L192 304l-39.515-39.515c-4.686-4.686-12.284-4' 162 . '.686-16.971 0L96 304v48z"></path></svg>'; 163 $button->options = [ 164 'height' => '400px', 165 'width' => '800px', 166 'bodyHeight' => '70', 167 'modalWidth' => '80', 168 'tinyPath' => $link, 169 'confirmCallback' => 'Joomla.getImage(Joomla.selectedMediaFile, \'' . $name . '\', this)', 170 'confirmText' => Text::_('PLG_IMAGE_BUTTON_INSERT'), 171 ]; 172 173 return $button; 174 } 175 176 return false; 177 } 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |