芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/.trash/administrator.2/components/com_newsfeeds/src/Field/Modal/NewsfeedField.php
* @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Component\Newsfeeds\Administrator\Field\Modal; \defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\Form\FormField; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\LanguageHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Session\Session; use Joomla\Database\ParameterType; /** * Supports a modal newsfeeds picker. * * @since 1.6 */ class NewsfeedField extends FormField { /** * The form field type. * * @var string * @since 1.6 */ protected $type = 'Modal_Newsfeed'; /** * Method to get the field input markup. * * @return string The field input markup. * * @since 1.6 */ protected function getInput() { $allowNew = ((string) $this->element['new'] == 'true'); $allowEdit = ((string) $this->element['edit'] == 'true'); $allowClear = ((string) $this->element['clear'] != 'false'); $allowSelect = ((string) $this->element['select'] != 'false'); $allowPropagate = ((string) $this->element['propagate'] == 'true'); $languages = LanguageHelper::getContentLanguages(array(0, 1), false); // Load language Factory::getLanguage()->load('com_newsfeeds', JPATH_ADMINISTRATOR); // The active newsfeed id field. $value = (int) $this->value ?: ''; // Create the modal id. $modalId = 'Newsfeed_' . $this->id; /** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */ $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); // Add the modal field script to the document head. $wa->useScript('field.modal-fields'); // Script to proxy the select modal function to the modal-fields.js file. if ($allowSelect) { static $scriptSelect = null; if (is_null($scriptSelect)) { $scriptSelect = array(); } if (!isset($scriptSelect[$this->id])) { $wa->addInlineScript(" window.jSelectNewsfeed_" . $this->id . " = function (id, title, object) { window.processModalSelect('Newsfeed', '" . $this->id . "', id, title, '', object); }", [], ['type' => 'module'] ); Text::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED'); $scriptSelect[$this->id] = true; } } // Setup variables for display. $linkNewsfeeds = 'index.php?option=com_newsfeeds&view=newsfeeds&layout=modal&tmpl=component&' . Session::getFormToken() . '=1'; $linkNewsfeed = 'index.php?option=com_newsfeeds&view=newsfeed&layout=modal&tmpl=component&' . Session::getFormToken() . '=1'; $modalTitle = Text::_('COM_NEWSFEEDS_SELECT_A_FEED'); if (isset($this->element['language'])) { $linkNewsfeeds .= '&forcedLanguage=' . $this->element['language']; $linkNewsfeed .= '&forcedLanguage=' . $this->element['language']; $modalTitle .= ' — ' . $this->element['label']; } $urlSelect = $linkNewsfeeds . '&function=jSelectNewsfeed_' . $this->id; $urlEdit = $linkNewsfeed . '&task=newsfeed.edit&id=\' + document.getElementById("' . $this->id . '_id").value + \''; $urlNew = $linkNewsfeed . '&task=newsfeed.add'; if ($value) { $id = (int) $value; $db = Factory::getDbo(); $query = $db->getQuery(true) ->select($db->quoteName('name')) ->from($db->quoteName('#__newsfeeds')) ->where($db->quoteName('id') . ' = :id') ->bind(':id', $id, ParameterType::INTEGER); $db->setQuery($query); try { $title = $db->loadResult(); } catch (\RuntimeException $e) { Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); } } $title = empty($title) ? Text::_('COM_NEWSFEEDS_SELECT_A_FEED') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); // The current newsfeed display field. $html = ''; if ($allowSelect || $allowNew || $allowEdit || $allowClear) { $html .= '
'; } $html .= '
'; // Select newsfeed button if ($allowSelect) { $html .= '
' . '
' . Text::_('JSELECT') . '
'; } // New newsfeed button if ($allowNew) { $html .= '
' . '
' . Text::_('JACTION_CREATE') . '
'; } // Edit newsfeed button if ($allowEdit) { $html .= '
' . '
' . Text::_('JACTION_EDIT') . '
'; } // Clear newsfeed button if ($allowClear) { $html .= '
' . '
' . Text::_('JCLEAR') . '
'; } // Propagate newsfeed button if ($allowPropagate && count($languages) > 2) { // Strip off language tag at the end $tagLength = (int) strlen($this->element['language']); $callbackFunctionStem = substr("jSelectNewsfeed_" . $this->id, 0, -$tagLength); $html .= '
' . '
' . Text::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON') . '
'; } if ($allowSelect || $allowNew || $allowEdit || $allowClear) { $html .= '
'; } // Select newsfeed modal if ($allowSelect) { $html .= HTMLHelper::_( 'bootstrap.renderModal', 'ModalSelect' . $modalId, array( 'title' => $modalTitle, 'url' => $urlSelect, 'height' => '400px', 'width' => '800px', 'bodyHeight' => 70, 'modalWidth' => 80, 'footer' => '
' . Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '
', ) ); } // New newsfeed modal if ($allowNew) { $html .= HTMLHelper::_( 'bootstrap.renderModal', 'ModalNew' . $modalId, array( 'title' => Text::_('COM_NEWSFEEDS_NEW_NEWSFEED'), 'backdrop' => 'static', 'keyboard' => false, 'closeButton' => false, 'url' => $urlNew, 'height' => '400px', 'width' => '800px', 'bodyHeight' => 70, 'modalWidth' => 80, 'footer' => '
' . Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '
' . '
' . Text::_('JSAVE') . '
' . '
' . Text::_('JAPPLY') . '
', ) ); } // Edit newsfeed modal. if ($allowEdit) { $html .= HTMLHelper::_( 'bootstrap.renderModal', 'ModalEdit' . $modalId, array( 'title' => Text::_('COM_NEWSFEEDS_EDIT_NEWSFEED'), 'backdrop' => 'static', 'keyboard' => false, 'closeButton' => false, 'url' => $urlEdit, 'height' => '400px', 'width' => '800px', 'bodyHeight' => 70, 'modalWidth' => 80, 'footer' => '
' . Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '
' . '
' . Text::_('JSAVE') . '
' . '
' . Text::_('JAPPLY') . '
', ) ); } // Add class='required' for client side validation $class = $this->required ? ' class="required modal-value"' : ''; $html .= '
'; return $html; } /** * Method to get the field label markup. * * @return string The field label markup. * * @since 3.4 */ protected function getLabel() { return str_replace($this->id, $this->id . '_name', parent::getLabel()); } }