function onUserAfterSave($user, $isnew, $success, $msg)
 {
     if (!$isnew) {
         return;
     }
     $user = (object) $user;
     $db = JFactory::getDbo();
     //Replace message
     $uri = JURI::getInstance();
     $link = $uri->getScheme() . "://" . $uri->getHost();
     $status = $this->params->def('wellcome', '');
     $pattern = '{name}';
     $status = str_replace($pattern, $user->name, $status);
     $pattern = '{site_url}';
     $status = str_replace($pattern, $link, $status);
     $message = $status;
     //Description website
     $description = self::getdataWeb($link);
     $infomation = '';
     if (isset($description['description'])) {
         $infomation = $description['description'];
     } else {
         if (isset($description['title'])) {
             $infomation = $description['title'];
         } else {
             $infomation = $link;
         }
     }
     //Link
     $link = JHtmlBt_Socialpost::getcaseshortlink($link);
     $created_time = JFactory::getDate()->toSql();
     $trigger = 'User Register';
     $title = 'Welcome ' . $user->name;
     $description = $infomation;
     $picture = $this->params->def('logourl', '');
     if ($user->enabled_publishing == 1) {
         if (isset($user->socialId) && $user->socialId != '') {
             switch ($user->loginType) {
                 case 'facebook':
                     $facebook_id = $user->socialId;
                     $url = "https://graph.facebook.com/{$facebook_id}/feed";
                     $token = $user->access_token;
                     $attachment = self::setAttachment($token, $message, $title, $link, $description, $picture);
                     $attachment = $attachment['facebook'];
                     //Post message user
                     $return = JHtmlBt_Socialpost::socialPost($user->loginType, $attachment, $url, $user->name, $user->socialId);
                     $log = $return['log'];
                     $publish = $return['publish'];
                     $socialtype = "facebookprofile";
                     break;
                 case 'twitter':
                     if (!class_exists('TwitterOAuth')) {
                         require_once JPATH_SITE . '/components/com_bt_socialconnect/helpers/html/twitter/twitteroauth.php';
                     }
                     $session = JFactory::getSession();
                     $connection = unserialize($session->get('connection'));
                     $attachment = self::setAttachment('', $message, '', '', '', '');
                     $attachment = $attachment['twitter'];
                     $parameters = array('status' => $message);
                     $updatestatus = $connection->post('statuses/update', $parameters);
                     if (isset($updatestatus->errors)) {
                         $log = $updatestatus->errors[0]->message;
                         $publish = 0;
                     } else {
                         $log = JTEXT::_('Message has sent ' . '<a href="https://twitter.com/' . $user->username . '" style="text-decoration: underline;" target="_blank">' . $user->name . '</a>' . ' successfully');
                         $publish = 1;
                     }
                     $socialtype = "twitterprofile";
                     break;
                 case 'linkedin':
                     $token = '';
                     $attachment = self::setAttachment($token, $message, $title, $link, $description, $picture);
                     $attachment = $attachment['linkedin'];
                     $response = JHtmlBt_Socialpost::fetch($user->access_token, $attachment);
                     $return = JHtmlBt_Socialpost::socialPost($user->loginType, $response['body'], $response['url'], $user->name, $user->socialId);
                     $log = $return['log'];
                     $publish = $return['publish'];
                     $socialtype = "linkedinprofile";
                     break;
                 case 'google':
                     $attachment = '';
                     $socialtype = 'googleprofile';
                     $publish = 1;
                     $log = '';
                     break;
             }
             $newArray = array();
             $newArray['item']->social_id = $user->socialId;
             $newArray['item']->access_token = $user->access_token;
             $newArray['attachment'] = $attachment;
             $message_type = 'profile';
             $seralizedCron = self::setDataOfline($user->loginType, $user->name, $newArray);
             $query = 'INSERT INTO  #__bt_messages (`createdby`,`type`,`title`,`message`,`trigger`,`published`,`log`,`event`,`scron`,`sent_time`,`created_time`,`chanel_id`,`message_type`) VALUES (\'' . Jtext::_('System') . '\',\'' . $socialtype . '\',\'' . $message . '\',\'' . JHtmlBt_Socialpost::processmessage($attachment) . '\',\'' . $trigger . '\',\'' . $publish . '\',\'' . addslashes($log) . '\',\'' . '0' . '\',\'' . $seralizedCron . '\',\'' . $created_time . '\', \'' . $created_time . '\',\'' . $user->id . '\',\'' . $message_type . '\')';
             $db->setQuery($query);
             $db->query();
         }
     }
 }
Beispiel #2
0
 public function processAttachment($name, $sociatype, $title, $link_article, $attachment, $trigger, $created_time, $params, $template, $message, $link, $chanel_id, $message_type, $db)
 {
     $newArray = array();
     $publish = 2;
     $schedule = '';
     $sent_time = '';
     $log = 'Waiting to process in queue';
     $query = 'INSERT INTO  #__bt_messages (`createdby`,`type`,`title`,`url`,`message`,`trigger`,`published`,`log`,`event`,`created_time`,`chanel_id`,`message_type`) VALUES(\'' . $name . '\',\'' . $sociatype . '\',\'' . $db->escape($title) . '\',\'' . $db->escape($link_article) . '\',\'' . $db->escape(JHtmlBt_Socialpost::processmessage($attachment)) . '\', \'' . $trigger . '\', \'' . $publish . '\', \'' . $log . '\',\'' . '0' . '\',\'' . $created_time . '\',\'' . $chanel_id . '\',\'' . $message_type . '\')';
     $db->setQuery($query);
     $db->query();
     $id = $db->insertid();
     //Setlink
     $count_post = $params->get('count_post', 1);
     //Set link
     if ($count_post == 1) {
         $relink = JURI::root() . 'index.php?option=com_bt_socialconnect&task=socialconnect.update&id=' . $id . '&url=' . urlencode($link);
         $link_redirect = JHtmlBt_Socialpost::getcaseshortlink($relink);
     } else {
         $link_redirect = $link;
     }
     $newArray['link'] = $link_redirect;
     $newArray['message'] = $message;
     $newArray['id'] = $id;
     return $newArray;
 }
Beispiel #3
0
 public static function setmessage($params, $author, $article, $link)
 {
     $message = $params;
     $pattern = '{title}';
     $message = str_replace($pattern, $article->title, $message);
     $pattern = '{shorturl}';
     $message = str_replace($pattern, JHtmlBt_Socialpost::getcaseshortlink($link), $message);
     $pattern = '{url}';
     $message = str_replace($pattern, $link, $message);
     $pattern = '{authorname}';
     $message = str_replace($pattern, $author, $message);
     $regex = '/\\{introtext\\:(.*)\\}/Ui';
     preg_match_all($regex, $message, $matches);
     if (!empty($matches[1])) {
         JFilterOutput::cleanText($article->introtext);
         $article->introtext = str_replace("\n", " ", $article->introtext);
         if ((int) $matches[1][0] == 0) {
             $small = $article->introtext;
         } else {
             if (function_exists('mb_substr')) {
                 $small = mb_substr($article->introtext, 0, (int) $matches[1][0]);
             } else {
                 $small = mb_substr($article->introtext, 0, (int) $matches[1][0]);
             }
         }
         $pattern = '{introtext:' . (int) $matches[1][0] . '}';
         $message = str_replace($pattern, $small, $message);
     }
     $pattern = '{fulltext}';
     $message = str_replace($pattern, $article->fulltext, $message);
     return $message;
 }