public function onContentAfterSave($context, $article, $isNew)
 {
     $connten = substr_count($context, 'com_content');
     if ($connten) {
         if (!$isNew) {
             return;
         }
         $caid = 0;
         $caid = JHtmlBt_Socialpost::checkCategory($article->catid, $this->params);
         if ($caid > 0) {
             //Lay image trong default - imageintro - introtext - fulltext
             $image = '';
             $introimage = json_decode($article->images);
             if ($introimage->image_intro != '') {
                 $image = $introimage->image_intro;
             } else {
                 if ($introimage->image_fulltext != '') {
                     $image = $introimage->image_fulltext;
                 } else {
                     preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $article->introtext, $match);
                     if (!empty($match[1])) {
                         $image = $match[1];
                     } else {
                         preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $article->fulltext, $matches);
                         if (!empty($matches[1])) {
                             $image = $matches[1];
                         } else {
                             $image = '';
                         }
                     }
                 }
             }
             $array = array();
             $article->image = $image;
             $article->link = ContentHelperRoute::getArticleRoute($article->id, $article->catid);
             $article->trigger = 'Joomla Content';
             $array['params'] = array('tb_id' => 'id', 'id' => $article->id, 'table' => '#__content', 'published' => 'state =1');
             $parameter = new JRegistry();
             $parameter->loadArray($array['params']);
             $article->params = (string) $parameter;
             $params = JComponentHelper::getParams('com_bt_socialconnect');
             $cronjob = $params->get('enabled_cronjobs', 0);
             //Kiem tra neu la conten
             if ($article->state == 0) {
                 $cronjob = 1;
             }
             Bt_SocialconnectHelperAutoPost::postArticle($article, $cronjob, $this->params);
         }
     }
     return true;
 }
Example #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;
 }
 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();
         }
     }
 }
Example #4
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;
 }