Beispiel #1
0
 /**
  * Renders a module script and returns the results as a string
  *
  * @param	string $name	The name of the module to render
  * @param	array $attribs	Associative array of values
  *
  * @return	string			The output of the script
  * @since   1.0
  */
 public function render($module, $attribs = array(), $content = null)
 {
     // add the environment data to attributes of module
     $registry = JRegistry::getInstance('document.environment');
     $env = $registry->getValue('params', array());
     $attribs = array_merge($env, $attribs);
     if (!is_object($module)) {
         $title = isset($attribs['title']) ? $attribs['title'] : null;
         $module = MigurModuleHelper::getModule($module, $title);
         if (!is_object($module)) {
             if (is_null($content)) {
                 return '';
             } else {
                 /**
                  * If module isn't found in the database but data has been pushed in the buffer
                  * we want to render it
                  */
                 $tmp = $module;
                 $module = new stdClass();
                 $module->params = null;
                 $module->module = $tmp;
                 $module->id = 0;
                 $module->user = 0;
             }
         }
     }
     // get the user and configuration object
     //$user = JFactory::getUser();
     $conf = JFactory::getConfig();
     // set the module content
     if (!is_null($content)) {
         $module->content = $content;
     }
     //get module parameters
     $params = new JRegistry();
     $params->loadJSON($module->params);
     // use parameters from template
     if (isset($attribs['params'])) {
         $template_params = new JRegistry();
         $template_params->loadJSON(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8'));
         $params->merge($template_params);
         $module = clone $module;
         $module->params = (string) $params;
     }
     $contents = '';
     $cachemode = $params->get('cachemode', 'oldstatic');
     // default for compatibility purposes. Set cachemode parameter or use JModuleHelper::moduleCache from within the module instead
     if ($params->get('cache', 0) == 1 && $conf->get('caching') >= 1 && $cachemode != 'id' && $cachemode != 'safeuri') {
         // default to itemid creating mehod and workarounds on
         $cacheparams = new stdClass();
         $cacheparams->cachemode = $cachemode;
         $cacheparams->class = 'JModuleHelper';
         $cacheparams->method = 'renderModule';
         $cacheparams->methodparams = array($module, $attribs);
         $contents = MigurModuleHelper::ModuleCache($module, $params, $cacheparams);
     } else {
         $contents = MigurModuleHelper::renderModule($module, $attribs);
     }
     return $contents;
 }
Beispiel #2
0
 /**
  * Render each module from the list.
  *
  * @param <type> $params - the array(object(widgetId, moduleName, native))
  * @return <type>
  */
 public function renderModules($params)
 {
     MigurModuleHelper::renderModule($module);
     // If can't determine the type of doc...
     if (empty($params['type']) || !in_array($params['type'], array('html', 'plain'))) {
         $this->setError('Type is not defined');
         return false;
     }
     $document = MigurMailerDocument::factory($params['type'], $params);
     //$this->triggerEvent('onMailerBeforeRender');
     $data = $document->render(false, $params);
     //$this->triggerEvent('onMailerAfterRender');
     unset($document);
     return $data;
 }
Beispiel #3
0
 /**
  * Renders multiple modules script and returns the results as a string
  *
  * @param	string	$name		The position of the modules to render
  * @param	array	$params		Associative array of values
  *
  * @return	string	The output of the script
  * @since   1.0
  */
 public function render($position, $params = array(), $content = null)
 {
     $buffer = '';
     $pre = '';
     $post = '';
     // The schmatic view of position areas
     if (!empty($params['renderMode']) && $params['renderMode'] == 'schematic') {
         $pre = '<div name="' . $position . '" class="modules ' . $position . '">';
         // Switch the name of the droppable area
         if (!empty($params['showNames'])) {
             $pre .= '<div style="position:relative;">' . $position . '</div>';
         }
         $post = '</div>';
     }
     foreach (MigurModuleHelper::getModules($position) as $mod) {
         // The default behavior
         $renderer = $this->_doc->loadRenderer('module', $mod->native);
         $buffer .= $renderer->render($mod, $params, $content);
     }
     return $pre . $buffer . $post;
 }
Beispiel #4
0
 /**
  * Displays the view.
  *
  * @param  string $tpl the template name
  * 
  * @return void
  * @since  1.0
  */
 public function display($tpl = null)
 {
     JHTML::_('behavior.modal');
     JHTML::stylesheet('media/com_newsletter/css/admin.css');
     JHTML::stylesheet('media/com_newsletter/css/configuration.css');
     JHTML::script('media/com_newsletter/js/migur/js/core.js');
     JHTML::script('administrator/components/com_newsletter/views/configuration/configuration.js');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     EnvironmentHelper::showWarnings(array('checkJoomla', 'checkImap', 'checkLogs', 'checkAcl'));
     $this->general = JComponentHelper::getParams('com_newsletter');
     //$model = JModel::getInstance('extensions', 'NewsletterModel');
     //$this->modules = $model->getModules();
     //$this->plugins = $model->getPlugins();
     $this->modules = MigurModuleHelper::getSupported();
     $this->plugins = MigurPluginHelper::getSupported();
     $this->form = $this->get('Form');
     $this->addToolbar();
     parent::display($tpl);
 }
Beispiel #5
0
 /**
  * Displays the view.
  *
  * @param  string $tpl the template name
  *
  * @return void
  * @since  1.0
  */
 public function display($tpl = null)
 {
     JHTML::stylesheet('media/com_newsletter/css/admin.css');
     JHTML::stylesheet('media/com_newsletter/css/extension.css');
     JHTML::script('media/com_newsletter/js/migur/js/core.js');
     JHTML::script(JURI::root() . "/administrator/components/com_newsletter/views/extension/submitbutton.js");
     $type = JRequest::getString('type', '');
     $native = JRequest::getInt('native', null);
     $extensionId = JRequest::getInt('extension_id', 0);
     if ($type == 'plugin') {
         $exts = MigurPluginHelper::getSupported(array('extension_id' => $extensionId, 'native' => $native));
     } else {
         $exts = MigurModuleHelper::getSupported(array('extension_id' => $extensionId, 'native' => $native));
     }
     $lang = JFactory::getLanguage();
     $lang->load('com_content', JPATH_ADMINISTRATOR, null, false, false);
     $ext = $exts[0];
     $this->info = $ext->xml;
     if (JRequest::getString('layout') == 'edit') {
         $model = $this->getModel();
         $this->form = $model->getForm(array('module' => $ext->extension, 'native' => $ext->native, 'type' => $ext->type));
     }
     parent::display($tpl);
 }
Beispiel #6
0
 /**
  * Get the template
  *
  * @return	string	The template name
  * @since	1.0
  */
 public function loadLetter($id = false)
 {
     $letter = MailHelper::loadLetter($id);
     // set the letter id for the Helper
     MigurModuleHelper::$itemId = $letter->newsletter_id;
     MigurModuleHelper::$clean = null;
     return $letter;
 }
Beispiel #7
0
 /**
  * Displays the view.
  *
  * @param  string $tpl the template name
  *
  * @return void
  * @since  1.0
  */
 public function display($tpl = null)
 {
     $isNew = !JRequest::getInt('newsletter_id', false);
     if ($isNew && !AclHelper::actionIsAllowed('newsletter.add') || !$isNew && !AclHelper::actionIsAllowed('newsletter.edit')) {
         $msg = $isNew ? 'JLIB_APPLICATION_ERROR_CREATE_RECORD_NOT_PERMITTED' : 'JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED';
         JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_newsletter&view=newsletters', false), JText::_($msg), 'error');
         return;
     }
     //TODO: Need to move css/js to SetDocument
     JHTML::stylesheet('media/com_newsletter/css/admin.css');
     JHTML::stylesheet('media/com_newsletter/css/newsletter.css');
     JHTML::script('media/com_newsletter/js/migur/js/core.js');
     JHTML::script('media/com_newsletter/js/migur/js/ajax.js');
     JHTML::script('media/com_newsletter/js/migur/js/widgets.js');
     JHTML::script('media/com_newsletter/js/migur/js/moodialog/MooDialog.js');
     JHTML::script('media/com_newsletter/js/migur/js/moodialog/MooDialog.Request.js');
     JHTML::script('media/com_newsletter/js/migur/js/moodialog/MooDialog.IFrame.js');
     JHTML::stylesheet('media/com_newsletter/js/migur/js/moodialog/css/MooDialog.css');
     JHTML::script('media/com_newsletter/js/migur/js/autocompleter/Observer.js');
     JHTML::script('media/com_newsletter/js/migur/js/autocompleter/Autocompleter.js');
     JHTML::script('media/com_newsletter/js/migur/js/autocompleter/Autocompleter.Local.js');
     JHTML::stylesheet('media/com_newsletter/js/migur/js/autocompleter/css/Autocompleter.css');
     JHTML::script('media/com_newsletter/js/migur/js/guide.js');
     JHTML::stylesheet('media/com_newsletter/css/guide.css');
     //TODO: Bulk-code. Need to refactor.
     JavascriptHelper::addObject('comParams', JComponentHelper::getParams('com_newsletter')->toArray());
     $nId = JRequest::getInt('newsletter_id');
     $script = $this->get('Script');
     $this->script = $script;
     // Get main form and data for newsletter
     $this->form = $this->get('Form', 'newsletter');
     $this->newsletter = $this->get('Item');
     $smtpModel = JModel::getInstance('SMtpProfile', 'NewsletterModelEntity');
     // Let's add J! profile
     $smtpp = $smtpModel->loadJoomla();
     JavascriptHelper::addObject('joomlaDe', JComponentHelper::getParams('com_newsletter')->toArray());
     // get the SmtpProfiles data
     $smtpprofilesManager = JModel::getInstance('smtpprofiles', 'NewsletterModel');
     $this->assignRef('smtpprofiles', $smtpprofilesManager->getAllItems('withDefault'));
     // get all the Extensions
     $this->modules = MigurModuleHelper::getSupported(array('withoutInfo' => true));
     $this->plugins = MigurPluginHelper::getSupported(array('withoutInfo' => true), 'com_newsletter.newsletter');
     // get the Extensions used in this newsletter
     $model = JModel::getInstance('newsletterext', 'NewsletterModel');
     $this->usedExts = $model->getExtensionsBy($nId);
     // Get a list of all templates
     $this->setModel(JModel::getInstance('templates', 'NewsletterModel'));
     $model = $this->getModel('templates');
     $templs = $model->getItems();
     $path = JPATH_COMPONENT . '/extensions/templates/';
     $filenames = JFolder::files($path, '^.*\\.xml$');
     if ($filenames === false) {
         JError::raiseError(500, implode("\n", array("Path {$path} not found")));
     }
     $this->templates = (object) array('items' => array(), 'path' => $path);
     $this->htmlTemplateId = null;
     foreach ($templs as $item) {
         $xml = new JSimpleXML();
         $xml->loadFile($path . $item->template);
         $str = trim($xml->document->template[0]->_data);
         $str = preg_replace('/<style.*>.*<\\/style>/s', '', $str);
         $str = str_replace('<position', '<div class="drop container-draggables"', $str);
         $id = strtolower(str_replace('.', '-', $item->template) . '-' . $item->t_style_id);
         $item->id = $id;
         $item->filename = $item->template;
         $item->template = $str;
         $this->templates->items[] = $item;
         if ($this->newsletter->t_style_id == $item->t_style_id) {
             $this->htmlTemplateId = $id;
             $this->t_style_id = $item->t_style_id;
         }
         unset($xml);
     }
     //attachments
     $this->attItems = array();
     $this->dynamicData = array('Name' => '[username]', 'Email' => '[useremail]', 'Site name' => '[sitename]', 'Subscription key' => '[subscription key]', 'Unsubscription link' => '[unsubscription link]', 'Confirmation link' => '[confirmation link]');
     $this->attItemslistDirn = "a.filename";
     $this->attItemslistOrder = "asc";
     // getting of an xml from
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     // We don't need toolbar in the modal window.
     if ($this->getLayout() !== 'modal') {
         $this->addToolbar();
     }
     $this->downloads = (array) DownloadHelper::getByNewsletterId($nId);
     JavascriptHelper::addObject('dataStorage', (object) array('htmlTemplate' => (object) array('template' => (object) array('id' => $this->htmlTemplateId), 'extensions' => (array) $this->usedExts), 'templates' => (array) $this->templates->items, 'modules' => (array) $this->modules, 'plugins' => (array) $this->plugins, 'newsletter' => NewsletterHelper::get($nId)));
     // Set the document
     $this->setDocument();
     parent::display($tpl);
 }
Beispiel #8
0
 /**
  * Gets the list of ALL supported modules
  * Or the array with one necessary module if parameters is present
  *
  * @param  array - array with the extension_id AND native flag
  *
  * @return array - the list of supported modules
  * @since  1.0
  */
 public static function getSupported($params = array())
 {
     $extensions = array_merge(self::getNativeSupported(), self::getLocallySupported());
     foreach ($extensions as &$item) {
         // Add the info about module
         if (!isset($params['withoutInfo'])) {
             $item->xml = MigurModuleHelper::getInfo($item->extension, $item->native);
         }
         if (empty($item->params)) {
             $item->params = "{}";
         }
         $item->params = (object) json_decode($item->params, true);
         //HOTFIX: To match the properties with the result object of &_load. Need to implement the MODULE object.
         $item->module = $item->extension;
         //			$result->id = 0;
         //			$result->title = '';
         //			$result->module = $name;
         //			$result->position = '';
         //			$result->content = '';
         //			$result->showtitle = 0;
         //			$result->control = '';
         //			$result->params = '';
         //			$result->user = 0;
         // Try to find only one module
         if (isset($params['extension_id']) && isset($params['native']) && $params['extension_id'] == $item->extension_id && $params['native'] == $item->native) {
             return array($item);
         }
     }
     // If we are here then the necessary module could not found
     if (!empty($params['extension_id']) && !empty($params['native'])) {
         JError::raiseError(E_ERROR, "The module " . $params['extension_id'] . " could not found in the list of supported modules (native = " . $params['native'] . ")");
     }
     return $extensions;
 }
Beispiel #9
0
 /**
  * Render and send the letter to the selected emails
  * Only for preview!!!! This method dont use the DB data.
  * It gets data from REQUEST:
  *	- params,
  *  - title,
  *  - showtitle,
  *  - extension_id(the id of a module in db)
  *  - native
  *
  * @return void
  * @since  1.0
  */
 public function rendermodule()
 {
     $native = JRequest::getString('native');
     $id = JRequest::getString('extension_id');
     $params = JRequest::getVar('params', array(), 'post', 'array');
     $title = JRequest::getString('title');
     $showTitle = JRequest::getString('showtitle');
     $modules = MigurModuleHelper::getSupported(array('extension_id' => $id, 'native' => $native));
     $module = $modules[0];
     // Override needed data
     $module->params = json_encode((object) $params);
     $module->title = $title;
     $module->showtitle = $showTitle;
     $content = MigurModuleHelper::renderModule($modules[0]);
     echo $content;
     die;
 }
Beispiel #10
0
 /**
  * Method to get the data that should be injected in the form.
  *
  * @return	mixed	The data for the form.
  * @since	1.0
  */
 protected function loadFormData()
 {
     // Check the session for previously entered form data.
     $data = JFactory::getApplication()->getUserState('com_newsletter.edit.nextension.data', array());
     if (empty($data)) {
         $form = JRequest::getVar('jform');
         if (!empty($form)) {
             $data = $form;
         } else {
             $id = $this->getState($this->getName() . '.id');
             $native = $this->getState('item.module.native');
             $modules = MigurModuleHelper::getSupported(array('extension_id' => $id, 'native' => $native));
             $data = new JObject($modules[0]);
             if (!empty($data->params)) {
                 $data->setProperties($data->params);
             }
             unset($data->params);
         }
     }
     return $data;
 }
Beispiel #11
0
 /**
  * Get all the modules registered in DB
  * @return array
  * @since  1.0
  */
 public function getModules()
 {
     $res = array();
     $extensions = $this->getItems();
     foreach ($extensions as $item) {
         if ($item->type == NewsletterTableNextension::TYPE_MODULE) {
             $item->xml = MigurModuleHelper::getInfo($item->extension);
             $res[] = $item;
         }
     }
     return $res;
 }