예제 #1
0
 function display($tpl = null)
 {
     $layout = $this->getLayout();
     if ($layout == 'multisubscription') {
         $this->newsletters = array();
         if (isset($this->mmsg)) {
             jincimport('utility.servicelocator');
             $servicelocator = ServiceLocator::getInstance();
             $logger = $servicelocator->getLogger();
             jincimport('core.newsletterfactory');
             $ninstance = NewsletterFactory::getInstance();
             foreach ($this->mmsg as $news_id => $text) {
                 if ($newsletter = $ninstance->loadNewsletter($news_id, true)) {
                     $this->newsletters[$news_id] = $newsletter;
                 }
             }
         }
     } else {
         $news_id = JRequest::getInt('id', 0);
         jincimport('core.newsletterfactory');
         $ninstance = NewsletterFactory::getInstance();
         if ($newsletter = $ninstance->loadNewsletter($news_id, true)) {
             $this->newsletter = $newsletter;
         }
     }
     parent::display($tpl);
 }
예제 #2
0
 /**
  * Update method to register message sending events.
  *
  * @access	public
  * @param $args['news_id'] Newsletter identifier refferring to the event.
  * * @param $args['msg_id'] Message identifier refferring to the event.
  * @return  false if something wrong.
  * @since	0.6
  */
 function update(&$args)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     if (!isset($args['news_id']) || !isset($args['msg_id'])) {
         return false;
     }
     $news_id = (int) $args['news_id'];
     $msg_id = (int) $args['msg_id'];
     $dbo =& JFactory::getDBO();
     $query = 'UPDATE #__jinc_newsletter SET lastsent = now() ' . 'WHERE id = ' . (int) $news_id;
     $dbo->setQuery($query);
     $logger->debug('SentMsgEvent: executing query: ' . $query);
     if (!$dbo->query()) {
         $logger->error('SentMsgEvent: error updating last newsletter dispatch date');
         return false;
     }
     $query = 'UPDATE #__jinc_message SET datasent = now() ' . 'WHERE id = ' . (int) $msg_id;
     $dbo->setQuery($query);
     $logger->debug('SentMsgEvent: executing query: ' . $query);
     if (!$dbo->query()) {
         $logger->error('SentMsgEvent: error updating last message dispatch date');
         return false;
     }
     return true;
 }
예제 #3
0
 /**
  * The newsletter importer. It imports newsletter subscribers from a CSV file.
  *
  * @access	public
  * @param	integer $newsletter a newsletter object.
  * @param	string  $csvfile_name the CSV file name.
  * @return  array containing import results.
  * @since	0.6
  * @see     Newsletter
  */
 function ImportFromCSV($newsletter, $csvfile_name)
 {
     jincimport('utility.jincjoomlahelper');
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     if (!($handle = @fopen($csvfile_name, "r"))) {
         $logger->finer('NewsletterImporter: unable to open ' . $csvfile_name);
         return false;
     }
     $result = array();
     while (($data = fgetcsv($handle, $this->_LINE_MAX_LENGTH, ",")) !== FALSE) {
         $logger->finer('NewsletterImporter: importing ' . implode(', ', $data));
         $info = $newsletter->getSubscriptionInfo();
         $subscriber_info = array();
         $attributes = array();
         for ($i = 0; $i < count($info); $i++) {
             $prefix = substr($info[$i], 0, 5);
             if ($prefix == 'attr_') {
                 $suffix = substr($info[$i], 5);
                 $attributes[$suffix] = isset($data[$i]) ? $data[$i] : '';
             } else {
                 $subscriber_info[$info[$i]] = $data[$i];
             }
         }
         $sub_result = array();
         $sub_result['data'] = implode(', ', $subscriber_info);
         switch ($newsletter->getType()) {
             case NEWSLETTER_PUBLIC_NEWS:
                 $subscriber_info['noptin'] = true;
                 break;
             case NEWSLETTER_PRIVATE_NEWS:
                 $user_id = $subscriber_info['user_id'];
                 $user_info = JINCJoomlaHelper::getUserInfo($user_id);
                 if (empty($user_info)) {
                     $user_info = JINCJoomlaHelper::getUserInfoByUsername($user_id);
                     if (empty($user_info)) {
                         $user_info = JINCJoomlaHelper::getUserInfoByUsermail($user_id);
                         if (!empty($user_info)) {
                             $subscriber_info['user_id'] = $user_info['id'];
                         }
                     } else {
                         $subscriber_info['user_id'] = $user_info['id'];
                     }
                 }
                 break;
             default:
                 break;
         }
         if ($newsletter->subscribe($subscriber_info, $attributes)) {
             $sub_result['result'] = 'OK';
         } else {
             $sub_result['result'] = $newsletter->getError();
         }
         array_push($result, $sub_result);
     }
     fclose($handle);
     return $result;
 }
예제 #4
0
 /**
  * Redefine setError method inherited from Joomla! JObject class
  *
  * @access	public
  * @since	0.6
  */
 function setError($error)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $logger->finer(get_class($this) . ': ' . JText::_($error));
     parent::setError($error);
 }
예제 #5
0
    function setTemplate($id)
    {
        if (empty($id)) {
            return;
        }
        $app = JFactory::getApplication();
        $cssurl = rtrim(JURI::root(), '/') . '/' . 'administrator/index.php?option=com_jinc&task=templatecss.loadcss&format=css&id=' . $id . '&time=' . time();
        $filepath = JPATH_COMPONENT_ADMINISTRATOR . DS . 'assets' . DS . 'templates' . DS . $id . '.css';
        $filepath = str_replace('/', DS, $filepath);
        $name = $this->myEditor->get('_name');
        if ($name == 'tinymce') {
            $this->editorConfig = array('content_css_custom' => $cssurl, 'content_css' => '0');
        } elseif ($name == 'jckeditor' || $name == 'fckeditor') {
            $this->editorConfig = array('content_css_custom' => $filepath, 'content_css' => '0', 'editor_css' => '0');
        } else {
            $fileurl = 'administrator/components/com_jinc/assets/templates/' . $id . '.css';
            $this->editorConfig = array('custom_css_url' => $cssurl, 'custom_css_file' => $fileurl, 'custom_css_path' => $filepath);
            JRequest::setVar('jinc_cssfile', $fileurl);
            if ($name == 'jce') {
                $jcepath = JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_jce' . DS . 'models' . DS;
                if (file_exists($jcepath . 'editor.php')) {
                    jimport('joomla.filesystem.file');
                    $content = JFile::read($jcepath . 'editor.php');
                    if (!strpos($content, 'jinc_cssfile')) {
                        $jinccode = '
			if(JRequest::getCmd(\'option\') == \'com_jinc\'){
				$jinc_cssfile = JRequest::getString(\'jinc_cssfile\');
				if(!empty($jinc_cssfile)) $settings[\'content_css\'] = $jinc_cssfile;
			}
			';
                        $content = preg_replace('#(\\$settings\\[\'content_css\'\\][^=]*= *\\$this->getStyleSheets\\(\\);)#', '$1' . $jinccode, $content);
                        jincimport('utility.servicelocator');
                        $servicelocator = ServiceLocator::getInstance();
                        $logger = $servicelocator->getLogger();
                        if (strpos($content, 'jinc_cssfile')) {
                            if (!file_exists($jcepath . 'editor_jbackup.php')) {
                                if (JFile::copy($jcepath . 'editor.php', $jcepath . 'editor_jbackup.php') !== true) {
                                    $logger->info('JINCEditor - Could not copy the file from ' . $jcepath . 'editor.php to ' . $jcepath . 'editor_jbackup.php', 'error');
                                }
                            }
                            if (JFile::write($jcepath . 'editor.php', $content) !== true) {
                                $logger->info('Could not write in ' . $jcepath . 'editor.php <br/> Please make sure this folder is writable', 'error');
                            }
                        }
                    }
                }
            }
        }
    }
예제 #6
0
 /**
  * Update method to register statistical events.
  *
  * @access	public
  * @param $args['news_id'] Newsletter identifier refferring to the event.
  * @return  false if something wrong.
  * @since	0.6
  */
 function update(&$args)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     if ($this->_type < 0 || !isset($args['news_id'])) {
         return false;
     }
     $query = 'INSERT INTO `#__jinc_stats_event` ' . '(`type`, `date`, `news_id`) VALUES ' . '(' . (int) $this->_type . ', now(), ' . (int) $args['news_id'] . ')';
     $logger->debug('StatisticalEvent: Executing query: ' . $query);
     $dbo =& JFactory::getDBO();
     $dbo->setQuery($query);
     if (!$dbo->query()) {
         return false;
     }
     return true;
 }
예제 #7
0
 /**
  * Method to get a single record.
  *
  * @param	integer	The id of the primary key.
  *
  * @return	mixed	Object on success, false on failure.
  */
 public function getItem($pk = null)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     $item = parent::getItem($pk);
     if (strlen($item->cssfile) > 0) {
         $item->cssfile_abs = JPATH_COMPONENT_ADMINISTRATOR . DS . 'assets' . DS . 'templates' . DS . $item->cssfile;
         $logger->debug('JINCModelTemplate - Reading CSS file ' . $item->cssfile_abs);
         $item->cssfile_content = is_readable($item->cssfile_abs) ? file_get_contents($item->cssfile_abs) : false;
         if (!$item->cssfile_content) {
             $logger->debug('JINCModelTemplate - Error reading CSS file ' . $item->cssfile_abs);
         }
     }
     return $item;
 }
예제 #8
0
 function getMessages()
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $id = JRequest::getInt('id', 0, 'GET');
     $result = array();
     $ninstance = NewsletterFactory::getInstance();
     if ($newsletter = $ninstance->loadNewsletter($id, true)) {
         $max_msg = (int) $newsletter->get('front_max_msg');
         if ($max_msg > 0) {
             $query = 'SELECT id, subject, body, datasent, attachment ' . 'FROM #__jinc_message ' . 'WHERE news_id = ' . (int) $id . ' ' . 'AND UNIX_TIMESTAMP(datasent) > 0 ' . 'ORDER BY datasent DESC';
             $logger->debug('NewslettersModelNewsletter: Executing query: ' . $query);
             $result = $this->_getList($query, 0, $max_msg);
         }
     }
     return $result;
 }
예제 #9
0
 /**
  * Update method to register subscription notify event.
  *
  * @access	public
  * @param $args['news_name'] Newsletter name refferring to the event.
  * @param $args['subs_name'] Name of the subscriber just registered.
  * @return  false if something wrong.
  * @since	0.8
  */
 function update(&$args)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     if (isset($args['news_notify']) && $args['news_notify']) {
         $logger->finer('SubscriptionNotifyEvent: Notifying subscription for ' . $args['news_name']);
         if (!isset($args['subs_name']) || !isset($args['news_name'])) {
             return false;
         }
         $news_name = $args['news_name'];
         $subs_name = $args['subs_name'];
         $dbo =& JFactory::getDBO();
         //get all super administrator
         $query = 'SELECT name, email, sendEmail FROM `#__users` u INNER JOIN ' . '`#__user_usergroup_map` m on u.id = m.user_id INNER JOIN ' . '`#__usergroups` g on m.group_id = g.id ' . 'WHERE lower(g.title) = "super users"';
         $logger->debug('SubscriptionNotifyEvent: executing query: ' . $query);
         $dbo->setQuery($query);
         if ($rows = $dbo->loadObjectList()) {
             // Sending notification to all administrators
             $subject = sprintf(JText::_('COM_JINC_MAIL_NOTIFY_SUBJECT'), $news_name);
             $subject = html_entity_decode($subject, ENT_QUOTES);
             foreach ($rows as $row) {
                 if ($row->sendEmail) {
                     $body = sprintf(JText::_('COM_JINC_MAIL_NOTIFY_BODY'), $row->name, $news_name, $subs_name);
                     $body = html_entity_decode($body, ENT_QUOTES);
                     $message =& JFactory::getMailer();
                     $message->setSubject($subject);
                     $message->setBody($body);
                     $message->addRecipient($row->email);
                     $logger->finer('SubscriptionNotifyEvent: Sending notification mail to ' . $row->email);
                     $message->send();
                 }
             }
         }
     }
     return true;
 }
예제 #10
0
 /**
  * Check if every mandatory attribute are avaivalable for subscription purpose.
  *
  * @access	protected
  * @param   integer $attributes list of attribute values
  * @since	0.7
  * @abstract
  */
 function checkMandatoryAttributes($attributes)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $news_attributes = $this->attributes;
     foreach ($news_attributes->toArray() as $attr_name => $attr_cardinality) {
         if ($attr_cardinality == ATTRIBUTE_MANDATORY) {
             if (!in_array($attr_name, array_keys($attributes)) || strlen(trim($attributes[$attr_name])) == 0) {
                 $logger->finer("Newsletter. Mandatory attribute not defined: " . $attr_name);
                 return false;
             }
         }
     }
     return true;
 }
예제 #11
0
파일: Model.php 프로젝트: loncool/yaf-admin
 /**
  * @param string $dbServiceName
  * @return Medoo
  */
 public function getDb($dbServiceName = 'db')
 {
     return $this->db = ServiceLocator::getInstance()->get($dbServiceName);
 }
예제 #12
0
 /**
  * Joomla! user finder. It finds user id by mail address
  *
  * @access	public
  * @param	integer $usermail the user mail.
  * @return  array Containing username, name and email. An empty array is
  *                something wrong.
  * @since	0.8
  */
 function getUserInfoByUsermail($usermail)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $dbo =& JFactory::getDBO();
     $query = 'SELECT id, username, name, email FROM #__users WHERE email = ' . $dbo->quote($usermail);
     $dbo->setQuery($query);
     $logger->debug('JINCJoomlaHelper: executing query: ' . $query);
     $infos = array();
     if ($user_info = $dbo->loadObjectList()) {
         if (!empty($user_info)) {
             $user = $user_info[0];
             $infos['id'] = $user->id;
             $infos['username'] = $user->username;
             $infos['name'] = $user->name;
             $infos['email'] = $user->email;
         }
     }
     return $infos;
 }
예제 #13
0
 function storeAttributeForm()
 {
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     jincimport('utility.servicelocator');
     jincimport('utility.jsonresponse');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $dbo = $this->getDbo();
     $query = $dbo->getQuery(true);
     $query->select('name, description, type, name_i18n');
     $query->from('`#__jinc_attribute`');
     $dbo->setQuery($query);
     $logger->debug('JINCModelAttributes: Executing query: ' . $query->__toString());
     $xmlstring = '<?xml version="1.0" encoding="utf-8"?>';
     $xmlstring .= '<form>';
     $xmlstring .= '   <fields name="attribs">';
     $xmlstring .= '      <fieldset name="addictional" label="COM_JINC_ATTRIBUTES">';
     if ($attributes = $dbo->loadAssocList()) {
         foreach ($attributes as $key => $attribute) {
             $xmlstring .= '         <field name="' . $attribute['name'] . '" type="list" label="' . $attribute['name_i18n'] . '"';
             $xmlstring .= '            description="' . $attribute['description'] . '" Default="">';
             $xmlstring .= '            <option value="">COM_JINC_ATTRIBUTE_NONE</option>';
             $xmlstring .= '            <option value="1">COM_JINC_ATTRIBUTE_MANDATORY</option>';
             $xmlstring .= '            <option value="2">COM_JINC_ATTRIBUTE_OPTIONAL</option>';
             $xmlstring .= '         </field>';
             $xmlstring .= '';
         }
     }
     $xmlstring .= '      </fieldset>';
     $xmlstring .= '   </fields>';
     $xmlstring .= '</form>';
     $filename = JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'forms' . DIRECTORY_SEPARATOR . 'attributes.xml';
     if ($fh = fopen($filename, 'w+')) {
         $logger->debug('Recreating file ' . $filename);
         fwrite($fh, $xmlstring);
         fclose($fh);
     } else {
         $logger->error('Unable to write file ' . $filename);
     }
 }
예제 #14
0
파일: message.php 프로젝트: sulicz/JINC_J30
 function emogrify($toemogrify)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $body = $toemogrify;
     if ($newsletter = $this->loadNewsletter()) {
         if ($this->tem_id != 0) {
             $template = $this->loadTemplate();
             if (!empty($template)) {
                 $logger->debug(get_class($this) . ': emogrifing message.');
                 jincimport('utility.emogrifier');
                 $emogrifier = new Emogrifier($body, $template->getCSSFileContent());
                 $body = $emogrifier->emogrify();
             }
         }
     }
     return $body;
 }
예제 #15
0
파일: message.php 프로젝트: sulicz/JINC_J30
 function deleteReport($proc_id)
 {
     jincimport('core.messagefactory');
     jincimport('utility.jsonresponse');
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $response = new JSONResponse();
     $minstance = MessageFactory::getInstance();
     if ($minstance->deleteReport($proc_id)) {
         $response->set('status', 0);
     } else {
         $response->set('status', -1);
     }
     $logger->debug('JSON: ' . $response->toString());
     return $response->toString();
 }
예제 #16
0
 /**
  * Retrieve total subscribers number. It overrides the abstract method
  * defined in SubsRetriever Class, implementing a concrete method of the
  * strategy pattern.
  *
  * @access	public
  * @return	integer The total number of subscribers or -1 if something wrong.
  * @since	0.6
  */
 function countSubscribers()
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $query = 'SELECT COUNT(u.email) AS num_subs ' . 'FROM #__jinc_newsletter n ' . 'LEFT JOIN #__jinc_subscriber s ON n.id = s.news_id ' . 'LEFT JOIN #__users u ON s.user_id = u.id ' . 'WHERE n.id = ' . (int) $this->getNewsId();
     $dbo =& JFactory::getDBO();
     $dbo->setQuery($query);
     $logger->debug('JContactInfoRetriever: executing query ' . $query);
     if ($result = $dbo->loadObjectList()) {
         $nsubs = $result[0];
     } else {
         return -1;
     }
     return $nsubs->num_subs;
 }
예제 #17
0
 /**
  * Play the process. It execute the next process step sending the message
  * to the next subscriber(s)
  *
  * @param string $client_id Client identifier
  * @return false if something wrong
  * @since 0.7
  */
 function play($client_id = '', $restart = false, $continue_on_error = false)
 {
     jincimport('core.messagefactory');
     jincimport('utility.jsonresponse');
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $dbo = JFactory::getDBO();
     if ($this->status == PROCESS_STATUS_RUNNING && $this->client_id != $client_id) {
         $this->setError('COM_JINC_ERR042');
         return false;
     }
     $start_time = 0;
     if ($this->status != PROCESS_STATUS_RUNNING) {
         if ($this->client_id == '') {
             $start_time = time();
             $this->start_time = $start_time;
         }
         if ($this->status == PROCESS_STATUS_STOPPED) {
             $start_time = time();
             $this->start_time = $start_time;
             $this->last_subscriber_time = 0;
             $this->last_update_time = 0;
             $this->sent_messages = 0;
             $this->sent_success = 0;
         }
         if ($this->client_id != $client_id) {
             if (!$this->updateStatus(PROCESS_STATUS_RUNNING, $client_id)) {
                 return false;
             }
         }
     }
     $msg_id = $this->msg_id;
     $minstance = MessageFactory::getInstance();
     if ($message = $minstance->loadMessage($msg_id)) {
         if ($newsletter = $message->loadNewsletter()) {
             $this->tot_recipients = $newsletter->countSubscribers();
             if ($this->tot_recipients < 0) {
                 $this->setError('COM_JINC_ERR007');
                 return false;
             }
         } else {
             $this->setError('COM_JINC_ERR001');
             return false;
         }
     } else {
         $this->setError('COM_JINC_ERR035');
         return false;
     }
     $logger->finer('Sending process: ' . $this->last_subscriber_time . ' - ' . $this->last_subscriber_id);
     $news_id = $newsletter->get('id');
     if ($send_result = $message->send($this->last_subscriber_time, $this->last_subscriber_id, $continue_on_error)) {
         $this->storeReportData($message->reported_recipients);
         $last_time = $send_result['last_time'];
         $last_id = $send_result['last_id'];
         $this->sent_messages = $this->sent_messages + $send_result['nmessages'];
         $this->sent_success = $this->sent_success + $send_result['nsuccess'];
         if ($send_result['nmessages'] == 0) {
             $this->updateStatus(PROCESS_STATUS_FINISHED);
             $logger->finer('Process: triggering message sent event');
             $dispatcher = JDispatcher::getInstance();
             $params = array('news_id' => $news_id, 'msg_id' => $msg_id);
             $result = $dispatcher->trigger('jinc_sent', $params);
         }
         $query = 'UPDATE #__jinc_process ' . 'SET last_subscriber_time = FROM_UNIXTIME(' . $last_time . '), ' . 'last_update_time = NOW(), ' . 'last_subscriber_id = ' . $last_id . ', ' . 'sent_success = ' . $this->sent_success . ', ' . 'sent_messages = ' . $this->sent_messages . ' ';
         if ($start_time > 0) {
             $query .= ', start_time = FROM_UNIXTIME(' . $start_time . ') ';
         }
         $query .= 'WHERE id = ' . $this->id;
         $dbo->setQuery($query);
         $logger->debug('Process: executing query: ' . $query);
         if (!$dbo->query()) {
             $this->setError('COM_JINC_ERR039');
             return false;
         }
         if (!$this->reloadStatus()) {
             $this->setError('COM_JINC_ERR039');
             return false;
         }
         $this->last_subscriber_time = $last_time;
         $this->last_subscriber_id = $last_id;
         $this->mail_system_error = $message->get('mail_system_error');
     } else {
         $this->storeReportData($message->reported_recipients);
         $logger->finer('StandardProcess: Error sending messages.');
         if (!$this->updateStatus(PROCESS_STATUS_PAUSED)) {
             $this->setError('COM_JINC_ERR040');
         }
         $this->setError($message->getError());
         $this->mail_system_error = $message->get('mail_system_error');
         return false;
     }
     return true;
 }
예제 #18
0
 /**
  * It ussubscribes just deleted user from every newsletters.
  *
  * @param array   $user   Array of user info
  * @param boolean $succes true if user is created successfully
  * @param string  $msg    User deletion message
  */
 public function onUserAfterDelete($user, $succes, $msg)
 {
     if (!$succes) {
         return;
     }
     if (is_array($user)) {
         $user_id = $user['id'];
         $user_email = $user['email'];
     } elseif (is_object($user)) {
         $user_id = $user->id;
         $user_email = $user->email;
     } else {
         return;
     }
     jincimport('core.newsletterfactory');
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $query = 'SELECT id FROM #__jinc_newsletter n ' . 'WHERE type = ' . (int) NEWSLETTER_PRIVATE_NEWS;
     $logger->debug('plgUserJINCSubscription: Executing query: ' . $query);
     $dbo =& JFactory::getDBO();
     $dbo->setQuery($query);
     // Unsubscribing user from every JINC newsletter
     if ($result = $dbo->loadAssocList()) {
         foreach ($result as $row) {
             $news_id = (int) $row['id'];
             $ninstance = NewsletterFactory::getInstance();
             if ($newsletter = $ninstance->loadNewsletter($news_id, false)) {
                 $subscriber_info = array('user_id' => $user_id);
                 $newsletter->unsubscribe($subscriber_info);
             }
         }
     }
 }
예제 #19
0
<?php

if ($argc != 2 || in_array($argv[1], ['--help', '-help', '-h', '-?'])) {
    ?>

  Generates orders and stores them in mongoDB.

  Usage: <?php 
    echo $argv[0];
    ?>
 total

    total    number of orders to generate

<?php 
    exit(1);
}
require_once 'bootstrap.php';
use Zend\ProgressBar\ProgressBar;
use Zend\ProgressBar\Adapter\Console;
$orderGenerator = ServiceLocator::getInstance()->get('order_generator');
$orderRepository = ServiceLocator::getInstance()->get('order_repository');
$total = (int) $argv[1];
$progressBar = new ProgressBar(new Console(), 0, $total);
while ($total) {
    $orderRepository->add($orderGenerator->generate());
    $total--;
    $progressBar->next();
}
예제 #20
0
 /**
  * Method to unsubscribe a newsletter user.
  *
  * @access	public
  * @param   array $subscriber_info Subscriber info based on newsletter type.
  * @return  true if successfully unsubscribed. false if something wrong.
  * @since	0.6
  * @abstract
  */
 function unsubscribe($subscriber_info)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $query = '';
     if (isset($subscriber_info['subs_id'])) {
         $id = (int) $subscriber_info['subs_id'];
         $query = 'DELETE FROM #__jinc_subscriber ' . 'WHERE id = ' . (int) $id . ' ' . 'AND news_id = ' . (int) $this->get('id');
     }
     if (isset($subscriber_info['user_id'])) {
         $id = (int) $subscriber_info['user_id'];
         $query = 'DELETE FROM #__jinc_subscriber ' . 'WHERE user_id = ' . (int) $id . ' ' . 'AND news_id = ' . (int) $this->get('id');
     }
     if (strlen($query) > 0) {
         $logger->debug('PrivateNewsletter: Executing query: ' . $query);
         $dbo =& JFactory::getDBO();
         $dbo->setQuery($query);
         if (!$dbo->query()) {
             $this->setError('COM_JINC_ERR025');
             return false;
         }
         if (isset($subscriber_info['subs_id'])) {
             $this->removeAttributeOnUnsubscription($id);
         }
     }
     // Triggering unsubscription event
     $dispatcher =& JDispatcher::getInstance();
     $params = array('news_id' => $this->get('id'), 'news_name' => $this->get('name'), 'news_notify' => $this->get('notify'));
     $result = $dispatcher->trigger('jinc_unsubscribe', $params);
     return true;
 }
예제 #21
0
 /**
  * Send a bulk message. It overrides the abstract method defined in Message
  * class.
  *
  * Hint: it starts to send messages from the the $start-th subscribers of
  * the message
  *
  * @access	public
  * @param	int $start_time subscription time to begin to
  * @param	int $start_id subscriber identifier to begin to
  * @return  array containing next suscription time, subscriber id and number of sent messages
  * @since	0.6
  */
 function send($start_time = 0, $start_id = 0, $continue_on_error = false)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     jincimport('utility.parameterprovider');
     $mailmsg = JFactory::getMailer();
     $root_uri = JURI::root();
     $sleeptime = ParameterProvider::getMailTimeInterval();
     $max_mails = ParameterProvider::getMaxXStep();
     $max_bulk_bcc = ParameterProvider::getMailMaxBcc();
     $send_mail = ParameterProvider::getSendMail();
     $logger->finer('BulkMessage: Sleep time ' . $sleeptime . ' - Max mails ' . $max_mails . ' Max BCC ' . $max_bulk_bcc . ' Send mail ' . $send_mail);
     $last_time = $start_time;
     $last_id = $start_id;
     $nmessages = 0;
     $nsuccess = 0;
     if ($newsletter = $this->loadNewsletter()) {
         ob_start();
         $logger->finer('BulkMessage: Newsletter loaded');
         $msg = $this->get('body') . $newsletter->get('disclaimer');
         // Newsletter info substitution in message body
         $msg = preg_replace('/\\[SENDER\\]/s', $newsletter->get('sendername'), $msg);
         $msg = preg_replace('/\\[SENDERMAIL\\]/s', $newsletter->get('senderaddr'), $msg);
         $msg = preg_replace('/\\[NEWSLETTER\\]/s', $newsletter->get('name'), $msg);
         $news_id = $newsletter->get('id');
         $unsub_link = JURI::root() . 'index.php?option=com_jinc&view=newsletter&layout=unsubscription&id=' . $news_id;
         $msg = preg_replace('/\\[UNSUBSCRIPTIONURL\\]/s', $unsub_link, $msg);
         $msg = preg_replace('#src[ ]*=[ ]*\\"(?!https?://)(?:\\.\\./|\\./|/)?#', 'src="' . $root_uri, $msg);
         $msg = preg_replace('#href[ ]*=[ ]*\\"(?!https?://)(?!mailto?:)(?!tel?:)(?:\\.\\./|\\./|/)?#', 'href="' . $root_uri, $msg);
         $msg = preg_replace('#url[ ]*\\(\'(?!https?://)(?:\\.\\./|\\./|/)?#', 'url(\'' . $root_uri, $msg);
         $subject = $this->get('subject');
         $subject = preg_replace('/\\[SENDER\\]/s', $newsletter->get('sendername'), $subject);
         $subject = preg_replace('/\\[SENDERMAIL\\]/s', $newsletter->get('senderaddr'), $subject);
         $subject = preg_replace('/\\[NEWSLETTER\\]/s', $newsletter->get('name'), $subject);
         // Setting message general properties
         $mailmsg->ContentType = $this->get('plaintext') ? "text/plain" : "text/html";
         $mailmsg->setSubject($subject);
         if (strlen($newsletter->get('senderaddr')) > 0) {
             $mailmsg->setSender(array($newsletter->get('senderaddr'), $newsletter->get('sendername')));
         }
         if (strlen($newsletter->get('replyto_addr')) > 0) {
             $mailmsg->addReplyTo(array($newsletter->get('replyto_addr'), $newsletter->get('replyto_name')));
         }
         $path_abs_root = JPATH_ROOT;
         $msg_attachment = $this->get('attachment');
         $arr_attachment = $msg_attachment->toArray();
         foreach ($arr_attachment as $key => $value) {
             $attachment = str_replace('/', DIRECTORY_SEPARATOR, $value);
             if (strlen($attachment)) {
                 $logger->finer('BulkMessage: adding attachment ' . $path_abs_root . DIRECTORY_SEPARATOR . $attachment);
                 $mailmsg->addAttachment($path_abs_root . DIRECTORY_SEPARATOR . $attachment);
             }
         }
         $logger->finer('BulkMessage: going to add recipients');
         $recipients = $newsletter->getSubscribersList($start_time, $start_id, $max_bulk_bcc);
         $nrecips = count($recipients);
         $logger->finer('BulkMessage: found ' . $nrecips . ' subscribers');
         $success = true;
         ob_end_clean();
         for ($i = 0; $i < $nrecips && $success; $i += $max_bulk_bcc) {
             ob_start();
             $ndest = 0;
             for ($j = 0; $j < $max_bulk_bcc && $j + $i < $nrecips; $j++) {
                 $current = $recipients[$j + $i];
                 $this->reported_recipients[$current['id']] = 0;
                 if (!$mailmsg->addBCC($current['email'])) {
                     $this->reported_recipients[$current['id']] = 1;
                 }
                 $ndest = $ndest + 1;
                 $last_time = $current['last_time'];
                 $last_id = $current['last_id'];
             }
             $mailmsg->setBody($this->emogrify($msg));
             $nmessages = $nmessages + $ndest;
             if ($send_mail) {
                 $success = $mailmsg->Send();
                 if ($success === true) {
                     $nsuccess = $nsuccess + $ndest * $success;
                     $logger->finer('BulkMessage: success sending mail.');
                 } else {
                     $logger->warning('BulkMessage: error sending mail.');
                     $this->mail_system_error = ob_get_contents();
                     $logger->warning('BulkMessage: error sending mail. MSG = ' . $this->mail_system_error);
                     for ($j = 0; $j < $max_bulk_bcc && $j + $i < $nrecips; $j++) {
                         $current = $recipients[$j + $i];
                         $this->reported_recipients[$current['id']] = 2;
                     }
                     if (!$continue_on_error) {
                         $success = false;
                     }
                 }
             } else {
                 $bcc_addresses = array();
                 foreach ($mailmsg->bcc as $number_variable => $variable) {
                     array_push($bcc_addresses, $mailmsg->bcc[$number_variable][0]);
                 }
                 $logger->info('BulkMessage: simulate sending mail. BCC = ' . implode(', ', $bcc_addresses));
                 $logger->info('BulkMessage: simulate sending mail. Body = ' . $msg);
                 $nsuccess = $nsuccess + $ndest;
             }
             // socket_select($read = NULL, $write = NULL, $sock = array(socket_create (AF_INET, SOCK_RAW, 0)), 0, $sleeptime);
             usleep($sleeptime);
             $mailmsg->ClearAllRecipients();
             ob_end_clean();
         }
     } else {
         $this->setError('COM_JINC_ERR001');
         return false;
     }
     return array('last_time' => $last_time, 'last_id' => $last_id, 'nmessages' => $nmessages, 'nsuccess' => $nsuccess);
 }
예제 #22
0
 /**
  * The notice loader. It loads a notice from its identifier.
  *
  * @access	public
  * @param	integer $id the notice identifier.
  * @return  The notice object or false if something wrong.
  * @since	0.9
  * @see     Newsletter
  */
 function loadNotice($id)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $query = 'SELECT name, title, bdesc, conditions ' . 'FROM #__jinc_notice nt ' . 'WHERE id = ' . (int) $id;
     $logger->debug('NewsletterFactory: Executing query: ' . $query);
     $dbo =& JFactory::getDBO();
     $dbo->setQuery($query);
     // Loading notice information from database
     if ($result = $dbo->loadAssocList()) {
         if (empty($result)) {
             // Newsletter not found in database
             $logger->finer('NewsletterFactory: Notice not found');
             return false;
         }
         $notice = $result[0];
     } else {
         return false;
     }
     $ntObj = new Notice($id);
     // Setting newsletter properties
     $ntObj->set('name', $notice['name']);
     $ntObj->set('title', $notice['title']);
     $ntObj->set('bdesc', $notice['bdesc']);
     $ntObj->set('conditions', $notice['conditions']);
     return $ntObj;
 }
예제 #23
0
파일: process.php 프로젝트: sulicz/JINC_J30
 /**
  * Stores report data
  *
  * @param $report_data The report data to store
  * @return false if something wrong
  * @since 1.0
  */
 function storeReportData($report_data)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $dbo = JFactory::getDBO();
     if (is_array($report_data)) {
         foreach ($report_data as $subs_id => $error_code) {
             $query = 'INSERT IGNORE INTO `#__jinc_report` (proc_id, subs_id, error_code) VALUES ' . '(' . $this->id . ', ' . $subs_id . ', ' . $error_code . ')';
             $logger->debug('Process: executing query ' . $query);
             $dbo->setQuery($query);
             if (!$dbo->query()) {
                 $this->setError('COM_JINC_ERR050');
                 $logger->warning($this->getError());
             }
         }
     }
     return true;
 }
예제 #24
0
 /**
  * It deletes report data related to a process identifier
  *
  * @access	public
  * @param	integer $proc_id the process identifier.
  * @return  boolean false if something wrong
  * @since	1.0
  * @see     Process
  */
 function deleteReport($proc_id)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $query = 'DELETE FROM `#__jinc_report` ' . 'WHERE proc_id = ' . (int) $proc_id;
     $logger->debug('MessageFactory: Executing query: ' . $query);
     $dbo = JFactory::getDBO();
     $dbo->setQuery($query);
     if ($dbo->query()) {
         return true;
     }
     return false;
 }
예제 #25
0
 /**
  * Confirming public unsubscription using string sent by Opt-in
  *
  * @param string $usermail
  * @param string $optinstr
  * @return boolean true if subscription is successfully confirmed
  */
 function confirmUnsubscription($usermail, $optinstr)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     if (strlen($optinstr) == 0) {
         return false;
     }
     $news_id = $this->get('id');
     $dbo =& JFactory::getDBO();
     $query = 'DELETE FROM #__jinc_subscriber ' . 'WHERE email = ' . $dbo->quote($usermail) . ' ' . 'AND news_id = ' . (int) $news_id . ' AND ' . 'random = ' . $dbo->quote($optinstr);
     $logger->debug('PublicNewsletter: Executing query: ' . $query);
     $dbo->setQuery($query);
     $dbo->query();
     if ($dbo->getAffectedRows() > 0) {
         $logger->finer('PublicNewsletter: generating unsubscription event after user confirmation.');
         // Triggering unsubscription event
         $dispatcher =& JDispatcher::getInstance();
         $params = array('news_id' => $this->get('id'), 'news_name' => $this->get('name'), 'news_notify' => $this->get('notify'));
         $result = $dispatcher->trigger('jinc_unsubscribe', $params);
         return true;
     }
     return false;
 }