当前位置: 首页>>代码示例>>PHP>>正文


PHP LogHelper::addMessage方法代码示例

本文整理汇总了PHP中LogHelper::addMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP LogHelper::addMessage方法的具体用法?PHP LogHelper::addMessage怎么用?PHP LogHelper::addMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogHelper的用法示例。


在下文中一共展示了LogHelper::addMessage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: subscribe

 /**
  * The method to bind subscriber to J! user.
  * To test <b>?option=com_newsletter&task=subscribe.subscribe&newsletter-name=index.php
  * @return void
  * @since  1.0
  */
 public function subscribe()
 {
     // Initialise variables.
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $db = JFactory::getDbo();
     // Get variables from request
     $name = JRequest::getString('newsletter-name', null);
     $email = JRequest::getString('newsletter-email', null);
     $html = (int) JRequest::getInt('newsletter-html', null);
     $listsIds = DataHelper::toArrayOfInts(JRequest::getVar('newsletter-lists', array()));
     $fbenabled = JRequest::getInt('fbenabled', array());
     //$sendto = JRequest::getVar('sendto');
     // Check token, d_i_e on error.
     JRequest::checkToken() or jexit('Invalid Token');
     if (empty($name) || empty($email) || !in_array($html, array(0, 1)) || empty($listsIds)) {
         jexit('One or more parameters is missing');
     }
     $comParams = JComponentHelper::getComponent('com_newsletter')->params;
     $isNew = false;
     // Let's check if we can create user as confirmed
     $confirmed = $comParams->get('users_autoconfirm') == '1';
     // try to get user data from FB
     $fbAppId = $comParams->get('fbappid');
     $fbSecret = $comParams->get('fbsecret');
     if (!empty($fbAppId) && !empty($fbSecret) && !empty($fbenabled)) {
         $me = SubscriberHelper::getFbMe($fbAppId, $fbSecret);
         if (!empty($me->email) && $me->email == $email) {
             $confirmed = true;
         }
     }
     // If it is a user's email
     $emailsAreEqual = false;
     if (!empty($user->id) && $user->email == $email) {
         $confirmed = true;
         $emailsAreEqual = true;
     }
     // Get from db
     $subscriber = JModel::getInstance('Subscriber', 'NewsletterModelEntity');
     $subscriber->load(array('email' => $email));
     // If subscriber does not exist then create it
     if (!$subscriber->getId()) {
         $subscriber->create(array('name' => $name, 'email' => $email, 'state' => '1', 'html' => $html, 'user_id' => $emailsAreEqual ? $user->id : 0, 'confirmed' => $confirmed));
     } else {
         // Update subscriber
         if ($confirmed == true) {
             // Confirm subscriber and
             // ALL ITS ASSIGNINGS TO LISTS
             $subscriber->confirm();
         }
         if ($emailsAreEqual) {
             // If user is authorized
             $subscriber->user_id = $user->id;
             $subscriber->save();
         }
     }
     // Add subscribers to lists, ignore if already in db
     $assignedListsIds = array();
     foreach ($listsIds as $list) {
         if (!$subscriber->isInList($list)) {
             $subscriber->assignToList($list);
             $assignedListsIds[] = $list;
         }
     }
     // Get lists we assigned
     $listManager = JModel::getInstance('Lists', 'NewsletterModel');
     $lists = $listManager->getItemsByIds($assignedListsIds);
     // Add to history all subscriptions
     foreach ($lists as $list) {
         $history = JTable::getInstance('history', 'NewsletterTable');
         $history->save(array('subscriber_id' => $subscriber->getId(), 'list_id' => $list->list_id, 'newsletter_id' => NULL, 'action' => NewsletterTableHistory::ACTION_SIGNEDUP, 'date' => date('Y-m-d H:i:s'), 'text' => addslashes($list->name)));
         unset($history);
     }
     // Triggering the automailing process.
     $amManager = new NewsletterAutomailingManager();
     $amManager->processSubscription(array('subscriberId' => $subscriber->subscriber_id));
     // If subscriber is confirmed then no need to send emails.
     $message = JText::sprintf('Thank you %s for subscribing to our Newsletter!', $name);
     if (!$subscriber->isConfirmed()) {
         // Let's send newsletters
         $mailer = new MigurMailer();
         foreach ($lists as $list) {
             try {
                 $newsletter = JModel::getInstance('Newsletter', 'NewsletterModelEntity');
                 $newsletter->loadAsWelcoming($list->send_at_reg);
                 PlaceholderHelper::setPlaceholder('listname', $list->name);
                 $res = $mailer->send(array('type' => $newsletter->isFallback() ? 'plain' : $subscriber->getType(), 'subscriber' => $subscriber->toObject(), 'newsletter_id' => $newsletter->newsletter_id, 'tracking' => true));
                 if ($res->state) {
                     $message = JText::sprintf('Thank you %s for subscribing to our Newsletter! You will need to confirm your subscription. There should be an email in your inbox in a few minutes!', $name);
                     LogHelper::addMessage('COM_NEWSLETTER_WELLCOMING_NEWSLETTER_SENT_SUCCESSFULLY', LogHelper::CAT_SUBSCRIPTION, array('Email' => $subscriber->email, 'Newsletter' => $newsletter->name));
                 } else {
                     throw new Exception(json_encode($res->errors));
                 }
             } catch (Exception $e) {
//.........这里部分代码省略.........
开发者ID:Rikisha,项目名称:proj,代码行数:101,代码来源:subscribe.php


注:本文中的LogHelper::addMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。