Exemplo n.º 1
0
 /**
  * Displays the view.
  *
  * @param  string $tpl the template name
  *
  * @return void
  * @since  1.0
  */
 public function display($tpl = null)
 {
     // Set the document
     $this->setDocument();
     $this->addToolbar();
     // Set main ID first
     $aid = JRequest::getInt('automailing_id');
     $this->assignRef('automailingId', $aid);
     // Get automailing form
     $model = $this->getModel();
     $automailing = $model->getItem();
     $this->assignRef('automailing', $automailing);
     JavascriptHelper::addObject('automailing', $automailing);
     $this->assignRef('form', $this->get('form', 'automailing'));
     // Get item list (series)
     $itemsModel = JModel::getInstance('AutomailingItems', 'NewsletterModel');
     $itemsModel->automailingId = $aid;
     $amList = (object) array('items' => $itemsModel->getNormalizedItems($aid), 'state' => $itemsModel->getState(), 'listOrder' => $itemsModel->getState('list.ordering'), 'listDirn' => $itemsModel->getState('list.direction'), 'pagination' => $itemsModel->getPagination());
     $this->assignRef('automailingItems', $amList);
     // Get targets list
     $targetsModel = JModel::getInstance('AutomailingTargets', 'NewsletterModel');
     $targetsModel->automailingId = $aid;
     if ($tpl != 'details') {
         // Get ids for all available lists
         $listsModel = JModel::getInstance('Lists', 'NewsletterModel');
         $allLists = $listsModel->getAllActive();
         // Find all used lists
         $usedLists = $targetsModel->getRelatedLists($aid);
         // Diff the records
         $usedListIds = DataHelper::getColumnData($usedLists, 'list_id');
         foreach ($allLists as $idx => $item) {
             if (in_array($item->list_id, $usedListIds)) {
                 unset($allLists[$idx]);
             }
         }
         $amTargets = (object) array('items' => $targetsModel->getRelatedLists($aid, 'usePagination'), 'state' => $targetsModel->getState(), 'listOrder' => $targetsModel->getState('list.ordering'), 'listDirn' => $targetsModel->getState('list.direction'), 'pagination' => $targetsModel->getPagination());
         $this->assignRef('automailingTargets', $amTargets);
         $this->assignRef('unusedLists', $allLists);
     }
     if ($tpl == 'details') {
         $this->assignRef('automailingTargets', $targetsModel->getNames($aid));
     }
     parent::display($tpl);
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 /**
  * Get statistics data and set it to JS.
  * 
  * @return void
  * @since  1.0
  */
 protected function setStatisticsData()
 {
     $ids = JRequest::getString('newsletters', '');
     $this->ids = $ids;
     $days = JRequest::getString('days', 30);
     $this->days = $days;
     $ids = !empty($ids) ? explode(',', $ids) : null;
     $data = StatisticsHelper::totalSent($ids);
     JavascriptHelper::addObject('statTotalSent', $data);
     $data = StatisticsHelper::openedActionsCount($ids);
     JavascriptHelper::addObject('statOpenedCount', $data);
     $data = StatisticsHelper::openedNewslettersCount($ids);
     $res = array('newsletters' => empty($data['newsletters']) ? 0 : $data['newsletters'], 'subscribers' => empty($data['subscribers']) ? 0 : $data['subscribers']);
     JavascriptHelper::addObject('statActiveCount', $res);
     $data = StatisticsHelper::totalClicks($ids);
     JavascriptHelper::addObject('statTotalClicks', $data);
     $previousDay = date('Y-m-d 00:00:00', strtotime("-1 day", time()));
     $thisDay = date('Y-m-d 00:00:00');
     $daysIdentifier = $days == 1 ? "-1 day" : "-" . $days . " Days";
     $fiewDaysBefore = date('Y-m-d 00:00:00', strtotime($daysIdentifier, time()));
     $previousHour = date('Y-m-d H:00:00', strtotime("-1 hour", time()));
     $thisHour = date('Y-m-d H:00:00');
     $oneDayBefore = date('Y-m-d H:00:00', strtotime("-1 day", time()));
     JavascriptHelper::addObject('clicksPerDay', StatisticsHelper::activityPerDay($fiewDaysBefore, $thisDay, $ids, NewsletterTableHistory::ACTION_CLICKED));
     JavascriptHelper::addObject('viewsPerDay', StatisticsHelper::activityPerDay($fiewDaysBefore, $thisDay, $ids, NewsletterTableHistory::ACTION_OPENED));
     JavascriptHelper::addObject('clicksPerHour', StatisticsHelper::activityPerHour($oneDayBefore, $thisHour, $ids, NewsletterTableHistory::ACTION_CLICKED));
     JavascriptHelper::addObject('viewsPerHour', StatisticsHelper::activityPerHour($oneDayBefore, $thisHour, $ids, NewsletterTableHistory::ACTION_OPENED));
 }
Exemplo n.º 4
0
 function setStatisticsData()
 {
     $theHour = 3600;
     $theDay = $theHour * 24;
     $days = 30;
     $previousDay = date('Y-m-d 00:00:00', strtotime("-1 day", time()));
     $fiewDaysBefore = date('Y-m-d 00:00:00', strtotime("-30 Days", time()));
     JavascriptHelper::addObject('opensPerDay', StatisticsHelper::openedNewslettersPerDay($fiewDaysBefore, $previousDay, null));
     JavascriptHelper::addObject('subsPerDay', StatisticsHelper::activeSubscribersPerDay($fiewDaysBefore, $previousDay, null));
 }
Exemplo n.º 5
0
 /**
  * Gets the statistics data and set it to JS.
  *
  * @return void
  * @since  1.0
  */
 protected function setStatisticsData()
 {
     $data = StatisticsHelper::totalSent();
     JavascriptHelper::addObject('statTotalSent', $data);
     $data = StatisticsHelper::openedActionsCount();
     JavascriptHelper::addObject('statOpenedCount', $data);
     $data = StatisticsHelper::openedNewslettersCount();
     $res = array('newsletters' => empty($data['newsletters']) ? 0 : $data['newsletters'], 'subscribers' => empty($data['subscribers']) ? 0 : $data['subscribers']);
     JavascriptHelper::addObject('statActiveSubscribersCount', $res);
     $now = date('Y-m-d H:i:s');
     $sevenDaysBefore = date('Y-m-d', strtotime('-7 Days', time())) . " 00:00:00";
     $thirtyDaysBefore = date('Y-m-d', strtotime('-30 Days', time())) . " 00:00:00";
     $ninetyDaysBefore = date('Y-m-d', strtotime('-90 Days', time())) . " 00:00:00";
     $this->totalSubs = array(StatisticsHelper::totalSubscribersCount($sevenDaysBefore, $now), StatisticsHelper::totalSubscribersCount($thirtyDaysBefore, $now), StatisticsHelper::totalSubscribersCount($ninetyDaysBefore, $now));
     $this->newSubs = array(StatisticsHelper::newSubscribersCount($sevenDaysBefore, $now), StatisticsHelper::newSubscribersCount($thirtyDaysBefore, $now), StatisticsHelper::newSubscribersCount($ninetyDaysBefore, $now));
     $this->lostSubs = array(StatisticsHelper::lostSubscribersCount($sevenDaysBefore, $now), StatisticsHelper::lostSubscribersCount($thirtyDaysBefore, $now), StatisticsHelper::lostSubscribersCount($ninetyDaysBefore, $now));
     $this->activeSubs = array(StatisticsHelper::activeSubscribersCount($sevenDaysBefore, $now), StatisticsHelper::activeSubscribersCount($thirtyDaysBefore, $now), StatisticsHelper::activeSubscribersCount($ninetyDaysBefore, $now));
 }
Exemplo n.º 6
0
 /**
  * Calculate the statistics data and add it to the JS
  *
  * @return void
  * @since  1.0
  */
 protected function setStatisticsData()
 {
     $data = StatisticsHelper::totalSent();
     $res = array('no' => empty($data['no']) ? 0 : $data['no'], 'soft' => empty($data['soft']) ? 0 : $data['soft'], 'hard' => empty($data['hard']) ? 0 : $data['hard'], 'total' => empty($data['total']) ? 0 : $data['total']);
     JavascriptHelper::addObject('statTotalSent', $res);
     $data = StatisticsHelper::openedActionsCount();
     $res = array('other' => empty($data['other']) ? 0 : $data['other'], 'opened' => empty($data['opened']) ? 0 : $data['opened'], 'total' => empty($data['total']) ? 0 : $data['total']);
     JavascriptHelper::addObject('statOpenedCount', $res);
     $data = StatisticsHelper::openedNewslettersCount();
     $res = array('newsletters' => empty($data['newsletters']) ? 0 : $data['newsletters'], 'subscribers' => empty($data['subscribers']) ? 0 : $data['subscribers']);
     JavascriptHelper::addObject('statActiveSubscribersCount', $res);
     $theHour = 3600;
     $theDay = $theHour * 24;
     $days = 30;
     $previousDay = date('Y-m-d 00:00:00', time() - $theDay);
     $fiewDaysBefore = date('Y-m-d 00:00:00', time() - $theDay * $days);
     JavascriptHelper::addObject('newSubsPerDay', StatisticsHelper::newSubscribersPerDay($fiewDaysBefore, $previousDay));
 }
Exemplo n.º 7
0
 JPluginHelper::importPlugin('migur');
 $app = JFactory::getApplication();
 $app->triggerEvent('onMigurNewsletterStart');
 // Handle the messages from previous requests
 $sess = JFactory::getSession();
 $msg = $sess->get('migur.queue');
 if ($msg) {
     $sess->set('application.queue', $msg);
     $sess->set('migur.queue', null);
 }
 JFormHelper::addRulePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'rules');
 JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
 JModel::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'entities', 'NewsletterModelEntity');
 // Add the site root and user's ACL to JS
 JavascriptHelper::addStringVar('migurSiteRoot', JUri::root());
 JavascriptHelper::addObject('migurUserAcl', AclHelper::toArray());
 // Setup the cache
 $cache = JFactory::getCache('com_newsletter');
 $cache->setCaching(true);
 $cache->setLifeTime(900);
 // cache to 5 min
 // Get an instance of the controller
 // Here we get full task
 $controller = JController::getInstance('Newsletter');
 // Perform the Request task
 // Here we get only tail of a task
 $controller->execute(JRequest::getCmd('task'));
 // Trigger events after exacution
 $app->triggerEvent('onMigurNewsletterEnd');
 // Redirect if set by the controller
 $controller->redirect();