예제 #1
0
 /**
  * Revokes application access from Facebook
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return	boolean
  */
 public function revoke()
 {
     try {
         $result = parent::api('/me/permissions', 'DELETE', array('access_token' => $this->token));
     } catch (Exception $e) {
         $result = false;
     }
     return $result;
 }
예제 #2
0
파일: helper.php 프로젝트: Tommar/vino2
 /**
  * Shares a new content on Facebook
  **/
 public function share($blog, $message = '', $oauth, $useSystem = false)
 {
     $config = EasyBlogHelper::getConfig();
     $source = $config->get('integrations_facebook_source');
     $content = isset($blog->{$source}) && !empty($blog->{$source}) ? $blog->{$source} : $blog->intro . $blog->content;
     $content = EasyBlogHelper::getHelper('Videos')->strip($content);
     $image = '';
     // @rule: Ensure that only public posts are allowed
     if ($blog->private != 0) {
         return false;
     }
     // @rule: Try to get the blog image.
     if ($blog->getImage()) {
         $image = $blog->getImage()->getSource('frontpage');
     }
     if (empty($image)) {
         // @rule: Match images from blog post
         $pattern = '/<\\s*img [^\\>]*src\\s*=\\s*[\\""\']?([^\\""\'\\s>]*)/i';
         preg_match($pattern, $content, $matches);
         $image = '';
         if ($matches) {
             $image = isset($matches[1]) ? $matches[1] : '';
             if (JString::stristr($matches[1], 'https://') === false && JString::stristr($matches[1], 'http://') === false && !empty($image)) {
                 $image = rtrim(JURI::root(), '/') . '/' . ltrim($image, '/');
             }
         }
     }
     $maxContentLen = $config->get('integrations_facebook_blogs_length');
     $text = strip_tags($content);
     if (!empty($maxContentLen)) {
         $text = JString::strlen($text) > $maxContentLen ? JString::substr($text, 0, $maxContentLen) . '...' : $text;
     }
     $url = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true);
     // If blog post is being posted from the back end and SH404 is installed, we should just use the raw urls.
     $sh404exists = EasyBlogRouter::isSh404Enabled();
     $mainframe = JFactory::getApplication();
     if ($mainframe->isAdmin() && $sh404exists) {
         $url = rtrim(JURI::root(), '/') . '/index.php?option=com_easyblog&view=entry&id=' . $blog->id;
     }
     preg_match('/expires=(.*)/i', $this->_access_token, $expires);
     if (isset($expires[1])) {
         $this->_access_token = str_ireplace('&expires=' . $expires[1], '', $this->_access_token);
     }
     // Remove adsense codes
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'adsense.php';
     $text = EasyBlogGoogleAdsense::stripAdsenseCode($text);
     $jConfig = EasyBlogHelper::getJConfig();
     $params = array('link' => $url, 'name' => $blog->title, 'description' => $text, 'message' => $blog->title, 'access_token' => $this->_access_token);
     if (empty($image)) {
         $params['picture'] = rtrim(JURI::root(), '/') . '/components/com_easyblog/assets/images/default_facebook.png';
         $params['source'] = rtrim(JURI::root(), '/') . '/components/com_easyblog/assets/images/default_facebook.png';
     } else {
         $params['picture'] = $image;
         $params['source'] = $image;
     }
     // @rule: For system messages, we need to see if there's any pages associated.
     if ($oauth->system && $useSystem) {
         if ($config->get('integrations_facebook_impersonate_page') || $config->get('integrations_facebook_impersonate_group')) {
             if ($config->get('integrations_facebook_impersonate_page')) {
                 $pages = JString::trim($config->get('integrations_facebook_page_id'));
                 $pages = explode(',', $pages);
                 $total = count($pages);
                 // @rule: Test if there are any pages at all the user can access
                 $accounts = parent::api('/me/accounts', array('access_token' => $this->_access_token));
                 if (is_array($accounts) && isset($accounts['data'])) {
                     for ($i = 0; $i < $total; $i++) {
                         foreach ($accounts['data'] as $page) {
                             if ($page['id'] == $pages[$i]) {
                                 $params['access_token'] = $page['access_token'];
                                 $query = parent::api('/' . $page['id'] . '/feed', 'post', $params);
                             }
                         }
                     }
                 }
             }
             if ($config->get('integrations_facebook_impersonate_group')) {
                 $groupsId = JString::trim($config->get('integrations_facebook_group_id'));
                 $groupsId = explode(',', $groupsId);
                 $total = count($groupsId);
                 // @rule: Test if there are any groups at all the user can access
                 $accounts = parent::api('/me/groups', 'GET', array('access_token' => $this->_access_token));
                 $params['access_token'] = $this->_access_token;
                 if (is_array($accounts) && isset($accounts['data'])) {
                     for ($i = 0; $i < $total; $i++) {
                         foreach ($accounts['data'] as $group) {
                             if ($group['id'] == $groupsId[$i]) {
                                 $query = parent::api('/' . $group['id'] . '/feed', 'post', $params);
                             }
                         }
                     }
                 }
             }
         } else {
             // @rule: If this is just a normal posting, just post it on their page.
             $query = parent::api('/me/feed', 'post', $params);
         }
     } else {
         // @rule: If this is just a normal posting, just post it on their page.
         $query = parent::api('/me/feed', 'post', $params);
     }
     $success = isset($query['id']) ? true : false;
     return $success;
 }