Beispiel #1
0
 /**
  * prepareRender
  *
  * @return  void
  */
 protected function prepareRender()
 {
     \Windwalker\Helper\LanguageHelper::loadLanguage('com_content');
     // Fix for 3.3.6
     JHtml::addIncludePath(\Windwalker\Helper\PathHelper::getSite('com_content') . '/helpers');
     parent::prepareRender();
 }
 /**
  * translateAlias
  *
  * @return  void
  */
 public static function translateAlias()
 {
     $easyset = \Ezset::getInstance();
     $input = \JFactory::getApplication()->input;
     // Set translate language
     $SourceLan = $easyset->params->get('originLan');
     $ResultLan = $easyset->params->get('tranLan', 'en');
     // Get query
     $jform = $input->post->getRaw('jform', array());
     if (!isset($jform) || !isset($jform['alias']) || !isset($jform['title'])) {
         return;
     }
     $alias = $jform['alias'];
     $title = $jform['title'];
     $titleTmp = explode('::', $jform['title']);
     if (!empty($titleTmp[1])) {
         $title = $titleTmp[0];
         $alias = \JFilterOutput::stringURLSafe($titleTmp[1]);
     }
     if ('' == (string) trim($alias)) {
         $alias = LanguageHelper::translate($title, $SourceLan, $ResultLan);
         $alias = trim($alias);
         $alias = \JFilterOutput::stringURLSafe($alias);
         $alias = strtr($alias, static::$replace);
         $alias = trim($alias, '-');
     }
     $jform['alias'] = $alias;
     $jform['title'] = $title;
     $input = \JFactory::getApplication()->input;
     $input->post->set('jform', $jform, 'method', true);
     $input->request->set('jform', $jform);
 }
Beispiel #3
0
 /**
  * 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));
 }
 /**
  * Method to run this controller.
  *
  * @return  mixed
  */
 protected function doExecute()
 {
     // Init Variables
     $data = $this->input->get($this->input->get('formctrl'), array(), 'array');
     $result = new \JRegistry();
     $result->set('Result', false);
     $model_name = $this->input->get('model_name');
     $component = $this->input->get('component');
     $extension = $this->input->get('extension');
     // Include Needed Classes
     \JModelLegacy::addIncludePath(JPATH_BASE . "/components/com_{$component}/models");
     \JForm::addFormPath(JPATH_BASE . "/components/com_{$component}/models/forms");
     \JForm::addFieldPath(JPATH_BASE . "/components/com_{$component}/models/fields");
     \JTable::addIncludePath(JPATH_BASE . "/components/com_{$component}/tables");
     LanguageHelper::loadLanguage($extension, null);
     // Get Model
     $model = \JModelLegacy::getInstance(ucfirst($model_name), ucfirst($component) . 'Model', array('ignore_request' => true));
     // For WindWalker Component only
     if (is_callable(array($model, 'getFieldsName'))) {
         $fields_name = $model->getFieldsName();
         $data = ArrayHelper::pivotToTwoDimension($data, $fields_name);
     }
     // Get Form
     $form = $model->getForm($data, false);
     if (!$form) {
         $result->set('errorMsg', $model->getError());
         jexit($result);
     }
     // Test whether the data is valid.
     $validData = $model->validate($form, $data);
     // Check for validation errors.
     if ($validData === false) {
         // Get the validation messages.
         $errors = $model->getErrors();
         $errorMsg = is_string($errors[0]) ? $errors[0] : $errors[0]->getMessage();
         $result->set('errorMsg', $errorMsg);
         jexit($result);
     }
     // Do Save
     if (!$model->save($validData)) {
         // Return Error Message.
         $result->set('errorMsg', \JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()));
         jexit($result);
     }
     // Set ID
     $data['id'] = $model->getstate($model_name . '.id');
     // Set Result
     $result->set('Result', true);
     $result->set('data', $data);
     jexit($result);
 }
 /**
  * Prepare hook of this component.
  *
  * Do some customize initialise through extending this method.
  *
  * @return void
  */
 public function prepare()
 {
     if (JDEBUG) {
         Debugger::registerWhoops();
     }
     // Register provider
     $this->container->registerServiceProvider(new QuickcontentProvider());
     // Load language
     $lang = $this->container->get('language');
     LanguageHelper::loadAll($lang->getTag(), $this->option);
     // Load asset
     $asset = $this->container->get('helper.asset');
     $asset->windwalker();
     // Register tasks
     TaskMapper::register($this);
     parent::prepare();
 }
 /**
  * Prepare hook of this component.
  *
  * Do some customize initialise through extending this method.
  *
  * @return void
  */
 public function prepare()
 {
     if (JDEBUG) {
         Debugger::registerWhoops();
     }
     // Register provider
     $this->container->registerServiceProvider(new RemoteimageProvider());
     // Load language
     $lang = $this->container->get('language');
     LanguageHelper::loadAll($lang->getTag(), $this->option);
     // Load asset
     $asset = $this->container->get('helper.asset');
     $asset->windwalker();
     // Register tasks
     TaskMapper::register($this);
     include_once JPATH_ADMINISTRATOR . '/includes/toolbar.php';
     parent::prepare();
 }
Beispiel #7
0
 /**
  * Prepare hook of this component.
  *
  * Do some customize initialise through extending this method.
  *
  * @return void
  */
 public function prepare()
 {
     if (JDEBUG) {
         Debugger::registerWhoops();
     }
     // Register provider
     $this->container->registerServiceProvider(new UserxtdProvider());
     // Load language
     $lang = $this->container->get('language');
     LanguageHelper::loadAll($lang->getTag(), $this->option);
     // Load asset
     $asset = $this->container->get('helper.asset');
     $asset->windwalker();
     // Register tasks
     TaskMapper::register($this);
     // Load Users language
     \Windwalker\Helper\LanguageHelper::loadLanguage('com_users', 'site');
     \Windwalker\Helper\LanguageHelper::loadLanguage('com_users', 'admin');
     parent::prepare();
 }
Beispiel #8
0
 /**
  * Add an quick add button & modal
  *
  * @return mixed
  */
 public function quickadd()
 {
     // Prepare Element
     $readonly = $this->getElement('readonly', false);
     $disabled = $this->getElement('disabled', false);
     if ($readonly || $disabled) {
         return;
     }
     $task = $this->getElement('task', $this->view_item . '.ajax.quickadd');
     $quickadd = $this->getElement('quickadd', false);
     $table_name = $this->getElement('table', '#__' . $this->component . '_' . $this->view_list);
     $key_field = $this->getElement('key_field', 'id');
     $value_field = $this->getElement('value_field', 'title');
     $formpath = $this->getElement('quickadd_formpath', "administrator/components/{$this->extension}/model/form/{$this->view_item}.xml");
     $quickadd_handler = $this->getElement('quickadd_handler', $this->extension);
     $title = $this->getElement('quickadd_label', 'LIB_WINDWALKER_QUICKADD_TITLE');
     $qid = $this->id . '_quickadd';
     if (!$quickadd) {
         return '';
     }
     // Set AKQuickAddOption
     $config['task'] = $task;
     $config['quickadd_handler'] = $quickadd_handler;
     $config['extension'] = $this->extension;
     $config['component'] = $this->component;
     $config['table'] = $table_name;
     $config['model_name'] = $this->view_item;
     $config['key_field'] = $key_field;
     $config['value_field'] = $value_field;
     $config['joomla3'] = JVERSION >= 3;
     WindwalkerScript::quickadd('#' . $qid, $config);
     // Load Language & Form
     LanguageHelper::loadLanguage('com_' . $this->component, null);
     $formpath = str_replace(JPATH_ROOT, '', $formpath);
     $content = ModalHelper::getQuickaddForm($qid, $formpath, (string) $this->element['extension']);
     // Prepare HTML
     $html = '';
     $button_title = $title;
     $modal_title = $button_title;
     $button_class = 'btn btn-small btn-success quickadd_buttons';
     $footer = "<button class=\"btn\" type=\"button\" data-dismiss=\"modal\">" . JText::_('JCANCEL') . "</button>";
     $footer .= "<button class=\"btn btn-primary\" type=\"submit\">" . JText::_('JSUBMIT') . "</button>";
     $html .= ModalHelper::modalLink(JText::_($button_title), $qid, array('class' => $button_class, 'icon' => 'icon-new icon-white'));
     $html .= ModalHelper::renderModal($qid, $content, array('title' => JText::_($modal_title), 'footer' => $footer));
     return $html;
 }
 /**
  * Method to test loadLanguage().
  *
  * @return void
  *
  * @covers Windwalker\Helper\LanguageHelper::loadLanguage
  */
 public function testLoadLanguage()
 {
     $container = Container::getInstance();
     // Set Mock object into container
     $mock = new MockLanguage();
     // Set Mock object into container
     $container->share('mock.language', $mock);
     // Change container key to use mock object
     LanguageHelper::setDIKey('mock.language');
     LanguageHelper::loadLanguage('com_content');
     $this->assertEquals(true, $mock->loadExecuted);
 }
Beispiel #10
0
    /**
     * Add an quick add button & modal
     *
     * @return string
     */
    public function quickadd()
    {
        // Prepare Element
        $readonly = $this->getElement('readonly', false);
        $disabled = $this->getElement('disabled', false);
        if ($readonly || $disabled) {
            return false;
        }
        $task = $this->getElement('task', $this->view_item . '.ajax.quickadd');
        $quickadd = $this->getElement('quickadd', false);
        $table_name = $this->getElement('table', '#__' . $this->component . '_' . $this->view_list);
        $key_field = $this->getElement('key_field', 'id');
        $value_field = $this->getElement('value_field', 'title');
        $formpath = $this->getElement('quickadd_formpath', "administrator/components/{$this->extension}/model/form/{$this->view_item}.xml");
        $quickadd_handler = $this->getElement('quickadd_handler', $this->extension);
        $title = $this->getElement('quickadd_label', 'LIB_WINDWALKER_QUICKADD_TITLE');
        $qid = $this->id . '_quickadd';
        if (!$quickadd) {
            return '';
        }
        // Prepare Script & Styles
        /** @var Windwalker\Helper\AssetHelper $asset */
        $asset = Container::getInstance($quickadd_handler)->get('helper.asset');
        $asset->addJs('js/quickadd.js');
        // Set AKQuickAddOption
        $config['task'] = $task;
        $config['quickadd_handler'] = $quickadd_handler;
        $config['extension'] = $this->extension;
        $config['component'] = $this->component;
        $config['table'] = $table_name;
        $config['model_name'] = $this->view_item;
        $config['key_field'] = $key_field;
        $config['value_field'] = $value_field;
        $config['joomla3'] = JVERSION >= 3;
        $config = HtmlHelper::getJSObject($config);
        $script = <<<QA
        window.addEvent('domready', function(){
            var AKQuickAddOption = {$config} ;
            AKQuickAdd.init('{$qid}', AKQuickAddOption);
        });
QA;
        $asset->internalJS($script);
        // Load Language & Form
        LanguageHelper::loadLanguage('com_' . $this->component, null);
        $formpath = str_replace(JPATH_ROOT, '', $formpath);
        $content = ModalHelper::getQuickaddForm($qid, $formpath, (string) $this->element['extension']);
        // Prepare HTML
        $html = '';
        $button_title = $title;
        $modal_title = $button_title;
        $button_class = 'btn btn-small btn-success delicious green light fltlft quickadd_button';
        $footer = "<button class=\"btn delicious\" type=\"button\" onclick=\"\$\$('#{$qid} input', '#{$qid} select').set('value', '');AKQuickAdd.closeModal('{$qid}');\" data-dismiss=\"modal\">" . JText::_('JCANCEL') . "</button>";
        $footer .= "<button class=\"btn btn-primary delicious blue\" type=\"submit\" onclick=\"AKQuickAdd.submit('{$qid}', event);\">" . JText::_('JSUBMIT') . "</button>";
        $html .= ModalHelper::modalLink(JText::_($button_title), $qid, array('class' => $button_class, 'icon' => 'icon-new icon-white'));
        $html .= ModalHelper::renderModal($qid, $content, array('title' => JText::_($modal_title), 'footer' => $footer));
        return $html;
    }
 /**
  * Method to run this controller.
  *
  * @return  mixed
  */
 protected function doExecute()
 {
     // Init Variables
     $data = $this->input->get($this->input->get('formctrl'), array(), 'array');
     $result = new Registry();
     $result->set('Result', false);
     $model_name = $this->input->get('model_name');
     $component = $this->input->get('component');
     $extension = $this->input->get('extension');
     // Include Needed Classes
     JLoader::registerPrefix(ucfirst($component), JPATH_BASE . "/components/com_{$component}");
     JForm::addFormPath(JPATH_BASE . "/components/com_{$component}/models/forms");
     JForm::addFieldPath(JPATH_BASE . "/components/com_{$component}/models/fields");
     JTable::addIncludePath(JPATH_BASE . "/components/com_{$component}/tables");
     LanguageHelper::loadLanguage($extension, null);
     // Get Model
     /** @var $model CrudModel */
     $model = $this->getModel(ucfirst($model_name), ucfirst($component));
     if (!$model instanceof CrudModel) {
         $result->set('errorMsg', 'Model need extends to \\Windwalker\\Model\\CrudModel.');
         jexit($result);
     }
     // For WindWalker Component only
     if (method_exists($model, 'getFieldsName')) {
         $fields_name = $model->getFieldsName();
         $data = ArrayHelper::pivotToTwoDimension($data, $fields_name);
     }
     // Check for validation errors.
     try {
         // Get Form
         if (method_exists($model, 'getForm')) {
             $form = $model->getForm($data, false);
             if (!$form) {
                 $result->set('errorMsg', 'No form');
                 jexit($result);
             }
             // Test whether the data is valid.
             $validData = $model->validate($form, $data);
         } else {
             $validData = $data;
         }
         // Do Save
         $model->save($validData);
     } catch (ValidateFailException $e) {
         // Get the validation messages.
         $errors = $e->getErrors();
         $errors = array_map(function ($error) {
             return (string) $error->getMessage();
         }, $errors);
         $result->set('errorMsg', $errors);
         exit($result);
     } catch (\Exception $e) {
         // Return Error Message.
         $result->set('errorMsg', \JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $e->getMessage()));
         jexit($result);
     }
     // Set ID
     $data['id'] = $model->getState()->get($model_name . '.id');
     // Set Result
     $result->set('Result', true);
     $result->set('data', $data);
     jexit($result);
 }
Beispiel #12
0
 /**
  * tranAlias
  *
  * @param \stdClass $article
  *
  * @return  void
  */
 public function tranAlias(&$article)
 {
     $config = JFactory::getConfig();
     if ($config->get('unicodeslugs')) {
         return;
     }
     $alias = $article->alias;
     $title = $article->title;
     $titleTmp = explode('::', $title);
     if (!empty($titleTmp[1])) {
         $title = $titleTmp[0];
         $alias = $titleTmp[1];
     }
     $alias = JFilterOutput::stringURLSafe($alias);
     if (trim($alias) == '') {
         $alias = \Windwalker\Helper\LanguageHelper::translate($article->title, null, 'en');
         $alias = trim($alias);
         $alias = JFilterOutput::stringURLSafe($alias);
         $replace = array('aquot' => '', 'a39' => '', '--' => '-');
         $alias = strtr($alias, $replace);
         $alias = trim($alias, '-');
     }
     $article->title = trim($title);
     $article->alias = trim($alias);
 }