/** * Prepare data hook. * * @return void */ protected function prepareData() { $data = $this->data; $data->formats = $this->get('Formats'); $data->format_form = $this->get('FormatForm'); $data->params = \Windwalker\System\ExtensionHelper::getParams('com_fbimporter'); }
/** * Prepare data hook. * * @return void */ protected function prepareData() { $input = $this->container->get('input'); $data = $this->getData(); $data->params = $params = \Windwalker\System\ExtensionHelper::getParams('com_remoteimage'); $lang = $this->container->get('language'); $data->langCode = $lang->getTag(); $data->langCode = str_replace('-', '_', $data->langCode); $this->prepareScript(); if ('component' == $input->get('tmpl')) { $params->set('isModal', true); $data->modal = true; } else { $params->set('isModal', false); $data->modal = false; } $params->set('tabs', $data->modal); $params->set('height', $data->modal ? $input->get('height', 380) : 520); $params->set('fieldId', $input->get('fieldid')); $params->set('insertId', $input->get('insert_id')); $data->uploadMax = ini_get('upload_max_filesize'); $data->uploadNum = ini_get('max_file_uploads'); $this->setTitle(\JText::_('COM_REMOTEIMAGE_TITLE_MANAGER')); \JToolbarHelper::preferences('com_remoteimage'); }
/** * Detect is this page are frontpage? * * @return boolean Is frontpage? */ public static function isHome() { $langPath = null; $tag = null; $lang = \JFactory::getLanguage(); // For multi language if (\JPluginHelper::isEnabled('system', 'languagefilter')) { $tag = $lang->getTag(); $langCodes = \JLanguageHelper::getLanguages('lang_code'); $langPath = $langCodes[$tag]->sef; } $uri = \JUri::getInstance(); $root = $uri::root(true); // Get site route $route = StringHelper::substr($uri->getPath(), StringHelper::strlen($root)); // Remove index.php $route = str_replace('index.php', '', $route); // If Multiple language enabled, we check first part of URI is language code or not. if ($langPath) { $params = ExtensionHelper::getParams('plg_system_languagefilter'); if ($tag == $lang->getDefault() && $params->get('remove_default_prefix', 0)) { $langPath = ''; } // If route equals lang path, means it is home route. if (trim($route, '/') == $langPath && !$uri->getVar('option')) { return true; } } else { if (!trim($route, '/') && !$uri->getVar('option')) { return true; } } return false; }
/** * createInfoBox * * @param Container $container * @param \stdClass $article * @param mixed $params * * @return string */ public static function createInfoBox(Container $container, $article, $params = null) { // Include Component Core $param = ExtensionHelper::getParams('com_userxtd'); $doc = \JFactory::getDocument(); $app = $container->get('app'); LanguageHelper::loadLanguage('com_userxtd', 'admin'); // init params $image_field = $param->get('UserInfo_ImageField', 'BASIC_AVATAR'); $website_field = $param->get('UserInfo_WebiteField', 'BASIC_WEBSITE'); $include_css = $param->get('UserInfo_IncludeCSS_Article', 1); // Image params $width = $param->get('UserInfo_ImageWidth', 150); $height = $param->get('UserInfo_ImageHeight', 150); $crop = $param->get('UserInfo_ImageCrop', 1) ? \JImage::CROP_RESIZE : false; // Include CSS if ($include_css) { /** @var $asset \Windwalker\Helper\AssetHelper */ $asset = $container->get('helper.asset'); $asset->addCss('userxtd-userinfo.css', 'com_userxtd'); } $user = \UXFactory::getUser($article->created_by); // Images $image = $user->get($image_field); $thumb = new Thumb(null, 'com_userxtd'); $image = $thumb->resize($image, $width, $height, $crop); // Link $query = array('option' => 'com_users', 'view' => 'profile', 'id' => $user->get('id')); $link = \JRoute::_('index.php?' . http_build_query($query)); //Route::_('com_userxtd.user_id', array('id' => $user->get('id'))); // Website $website_link = $user->get($website_field); // Render return with(new FileLayout('userxtd.content.userinfo', null, array('component' => 'com_userxtd')))->render(array('params' => $param, 'article' => $article, 'link' => $link, 'website_link' => $website_link, 'image' => $image, 'user' => $user)); }
/** * Class init. * * @param string $element The component option name. * @param \JUri $uri The uri object. * @param Registry $option The option of this server. * * @throws \InvalidArgumentException */ public function __construct($element, \JUri $uri, Registry $option = null) { $extracted = ExtensionHelper::extractElement($element); $this->option = $option ?: new Registry(); $this->uri = $uri; if ($extracted['type'] !== 'component') { throw new \InvalidArgumentException('Please give me a component name like `com_flower`.'); } $this->component = $extracted['name']; }
/** * Get component params. * * @return Registry */ public function getParams() { if ($this->params) { return $this->params; } $app = $this->getContainer()->get('app'); $comParams = ExtensionHelper::getParams($this->option); $menuParams = new Registry(); if ($menu = $app->getMenu()->getActive()) { $menuParams->loadString($menu->params); } $menuParams->merge($comParams); return $this->params = $menuParams; }
/** * Prepare data hook. * * @return void */ protected function prepareData() { parent::prepareData(); // Load content language $lang = JFactory::getLanguage(); $lang->load('com_content', JPATH_BASE, null, true, true); $lang->load('com_menus', JPATH_BASE, null, true, true); $data = $this->data; $data->params = \Windwalker\System\ExtensionHelper::getParams('com_quickcontent'); $data->formParams = $this->get('FormParams'); $data->listParams = $this->buildParamsInput('list'); $data->blogParams = $this->buildParamsInput('blog'); $data->articleParams = $this->buildParamsInput('article'); // Set Editor $editor = \JEditor::getInstance($data->params->get('editor', 'tinymce')); $params['mode'] = 2; $this->editor = $editor->display('jform[content]', $data->item->content, '650px', '500px', 650, 500, false, null, null, null, $params); }
/** * Get the path of extension. * * @param string $element The extension element name, example: com_content or plg_group_name * @param string $client Site or administrator. * @param boolean $absolute True to return whole path. * * @return string The found path. */ public static function get($element, $client = null, $absolute = true) { $element = strtolower($element); $extracted = ExtensionHelper::extractElement($element); $extension = $extracted['type']; $name = $extracted['name']; $group = $extracted['group']; // Assign name path. switch ($extension) { case 'component': case 'module': $folder = $element; break; case 'plugin': $folder = $group . '/' . $name; $client = 'site'; break; case 'library': $client = 'site'; default: $folder = $name; break; } // Build path $extension = StringInflector::getInstance()->toPlural($extension); $path = $extension . '/' . $folder; if (!$absolute) { return $path; } // Add absolute path. switch ($client) { case 'site': $path = JPATH_SITE . '/' . $path; break; case 'admin': case 'administrator': $path = JPATH_ADMINISTRATOR . '/' . $path; break; default: $path = JPATH_BASE . '/' . $path; break; } return $path; }
/** * prepareExecute * * @return void */ protected function prepareExecute() { $element = $this->getArgument(1); $client = strtolower($this->getOption('c')); $class = $this->getOption('class'); if ($element) { list($type, $name, $group) = array_values(ExtensionHelper::extractElement($element)); if ($client == 'admin') { $client = 'administrator'; } if ($type == 'plugin') { $client = 'site'; } elseif ($type == 'component') { $client = 'administrator'; } } $path = JPATH_ROOT . '/resources/seeders'; $classPath = $path . '/' . $class . '.php'; if (!file_exists($classPath) && $element) { $path = PathHelper::get($element, $client); $classPath = $path . '/src/' . ucfirst($name) . '/Seed/' . $class . '.php'; } if (file_exists($classPath)) { include_once $classPath; } $className = $class; if (!class_exists($className)) { $className = sprintf('%s\\Seed\\%s', ucfirst($name), ucfirst($class)); } if (!class_exists($className)) { throw new \UnexpectedValueException('Class: ' . $class . ' not found.'); } // Auto include classes $path = dirname(ReflectionHelper::getPath($className)); $files = \JFolder::files($path, '.', false, true); /** @var \SplFileInfo $file */ foreach ($files as $file) { $file = new \SplFileInfo($file); \JLoader::register($file->getBasename('.php'), $file->getPathname()); } $this->app->set('seed.class', $className); }
/** * Execute Component. * * @param string $option Component option name. * @param string $client `admin` or `site`. * @param array $input Input object. * * @return mixed */ public static function executeComponent($option, $client = 'site', $input = array()) { $element = ExtensionHelper::extractElement($option); $input = new \JInput($input); // Prevent class conflict class_alias('JString', 'Joomla\\String\\String'); if (!defined('JPATH_COMPONENT_ADMINISTRATOR')) { define('JPATH_COMPONENT_ADMINISTRATOR', PathHelper::get($option, 'admin')); define('JPATH_COMPONENT_SITE', PathHelper::get($option, 'site')); define('JPATH_COMPONENT', PathHelper::get($option, $client)); } $_SERVER['HTTP_HOST'] = 'windwalker'; if ($client == 'admin') { $client = 'administrator'; } $appClass = 'JApplication' . ucfirst($client); $console = \JFactory::$application; \JFactory::$application = $appClass::getInstance('site', $input); $class = ucfirst($element['name']) . 'Component'; $component = new $class(ucfirst($element['name']), $input, \JFactory::$application); $result = $component->execute(); \JFactory::$application = $console; return $result; }
/** * Utility method to act on a user after it has been saved. * * @param array $data Holds the new user data. * @param boolean $isNew True if a new user is stored. * @param boolean $result True if user was succesfully stored in the database. * @param string $error Message. * * @return void */ public function onUserAfterSave($data, $isNew, $result, $error = null) { $db = JFactory::getDbo(); // don't do anything when activate. $allowTask = array('register', 'save', 'apply', 'save2new', 'user.edit.save'); if (!in_array($this->input->get('task'), $allowTask)) { return; } // Init Framework // =============================================================== $this->initComponent(); $UXParams = \Windwalker\System\ExtensionHelper::getParams('com_userxtd'); // For Upload Event $this->user_data = $data; // Set Category $catid = $UXParams->get('CoreRegistration_Categories', array('*')); if (!is_array($catid)) { $catid = array($catid); } if (!in_array('*', $catid)) { $catid = implode(',', $catid); } else { $catid = null; } // Get Data and handle them $form = \Userxtd\Form\FormHelper::getFieldsByCategory($catid); $form->bind($data); $data['profile'] = $form->getDataForSave('profile'); $userId = JArrayHelper::getValue($data, 'id', 0, 'int'); // Start Building query // =============================================================== if ($userId && $result && isset($data['profile']) && count($data['profile'])) { try { //Sanitize the date // =============================================================== if (!empty($data['profile']['dob'])) { $date = new JDate($data['profile']['dob']); $data['profile']['dob'] = $date->format('Y-m-d'); } $query = $db->getQuery(true); $query->delete('#__userxtd_profiles')->where('user_id = ' . $userId); $db->setQuery($query)->execute(); $tuples = array(); $order = 1; $query = $db->getQuery(true); $query->columns(array($query->qn('user_id'), $query->qn('key'), $query->qn('value'), $query->qn('ordering'))); // Build query // =============================================================== foreach ($data['profile'] as $k => $v) { if (is_array($v) || is_object($v)) { $v = implode(',', (array) $v); } $query->values($userId . ', ' . $query->quote($k) . ', ' . $query->quote($v) . ', ' . $order++); } $query->insert('#__userxtd_profiles'); $db->setQuery($query)->execute(); } catch (RuntimeException $e) { $this->_subject->setError($e->getMessage()); return; } } return; }
/** * Reset cache position. * * @return void */ public function resetCachePosition() { if ($this->extension) { $params = ExtensionHelper::getParams($this->extension); } else { $params = new Registry(); } $this->config = new Registry(); $this->config['path.cache'] = Path::clean(JPATH_ROOT . $params->get('thumb.cache-path', '/cache/thumbs/cache')); $this->config['path.temp'] = Path::clean(JPATH_ROOT . $params->get('thumb.temp-path', '/cache/thumbs/temp')); $this->config['url.cache'] = $params->get('thumb.cache-url', '/cache/thumbs/cache'); $this->config['url.temp'] = $params->get('thumb.temp-url', '/cache/thumbs/cache'); }
/** * Method to auto-populate the model state. */ protected function populateState() { // Get the application object. $user_params = ExtensionHelper::getParams('com_users'); $userxtd_params = ExtensionHelper::getParams('com_userxtd'); $user_params->merge($userxtd_params); // Get the user id. $userId = JFactory::getApplication()->getUserState('com_userxtd.edit.profile.id'); $userId = !empty($userId) ? $userId : (int) JFactory::getUser()->get('id'); // Set the user id. $this->state->set('user.id', $userId); // Load the parameters. $this->state->set('params', $user_params); }
/** * Get config class name by extension name. * * Example: * - Component - Flower\Config\Config * - Module - ModFlower\Config\Config * - Plugin - PlgSystemFlower\Config\Config * - Template - TplFlower\Config\Config * * @param string $element The extension name. * * @throws \LogicException * @throws \DomainException * @return string The config class name. */ public static function getClass($element) { $extracted = ExtensionHelper::extractElement($element); switch ($extracted['type']) { case 'module': $class = 'Mod' . ucfirst($extracted['name']) . '\\Config\\Config'; break; case 'plugin': if (!$extracted['group']) { throw new \LogicException(sprintf('Please give me group name when get plugin config.')); } $class = 'Plg' . ucfirst($extracted['group']) . ucfirst($extracted['name']) . '\\Config\\Config'; break; case 'component': $class = ucfirst($extracted['name']) . '\\Config\\Config'; break; case 'template': $class = 'Tpl' . ucfirst($extracted['name']) . '\\Config\\Config'; break; default: throw new \DomainException(sprintf('Don\'t get config from this extension: %s', $element)); } return $class; }