コード例 #1
0
ファイル: SocialShare.php プロジェクト: Sywooch/forums
 public function publishAsNeeded($optionId, bdSocialShare_Shareable_Abstract $shareable, $key = false)
 {
     extract($this->_getTargets($optionId, $key));
     $shareQueueModel = $this->_getShareQueueModel();
     $preConfiguredTargets = $shareable->getPreConfiguredTargets();
     if (!empty($included)) {
         if (!empty($targets) and $shareQueueModel->canQueue() and $shareQueueModel->insertQueue($shareable, $targets, $default)) {
             // good, queued now
         } else {
             // unable to queue, publish asap
             $shareQueueModel->publish($shareable, $targets, $default);
         }
     }
     if (!empty($preConfiguredTargets)) {
         $userModel = $this->_controller->getModelFromCache('XenForo_Model_User');
         $viewingUserGuest = $userModel->getVisitingGuestUser();
         $userModel->bdSocialShare_prepareViewingUser($viewingUserGuest);
         if ($shareQueueModel->canQueue() and $shareQueueModel->insertQueue($shareable, $preConfiguredTargets, false, $viewingUserGuest)) {
             // good, queued now
         } else {
             // unable to queue, publish asap
             $shareQueueModel->publish($shareable, $preConfiguredTargets, false, $viewingUserGuest);
         }
     }
 }
コード例 #2
0
ファイル: StaffShare.php プロジェクト: Sywooch/forums
 public function getUserText(XenForo_Model $model)
 {
     if (isset($this->_data['userText'])) {
         return $this->_data['userText'];
     }
     return parent::getUserText($model);
 }
コード例 #3
0
ファイル: Media.php プロジェクト: Sywooch/forums
 public function getImage(XenForo_Model $model)
 {
     $attachment = $this->_getAttachment($model);
     if (!empty($attachment)) {
         return $this->_getImageForAttachment($attachment, $model);
     }
     return parent::getImageDataPath($model);
 }
コード例 #4
0
ファイル: Medal.php プロジェクト: Sywooch/forums
 public function getImage(XenForo_Model $model)
 {
     $imageUrl = bdMedal_Model_Medal::getImageUrl($this->_medal);
     if (!empty($imageUrl)) {
         return XenForo_Link::convertUriToAbsoluteUri($imageUrl, true);
     }
     return parent::getImage($model);
 }
コード例 #5
0
ファイル: Entry.php プロジェクト: Sywooch/forums
 public function getImage(XenForo_Model $model)
 {
     $entry = $this->_entryDw->getMergedData();
     $image = $this->_getImageFromBbCodeMessage($model, $entry, 'blog_entry', $entry['entry_id']);
     if (!empty($image)) {
         return $image;
     }
     return parent::getImage($model);
 }
コード例 #6
0
ファイル: Twitter.php プロジェクト: Sywooch/forums
 public function publish($targetId, bdSocialShare_Shareable_Abstract $shareable, $token)
 {
     $statusText = false;
     $userText = $shareable->getUserText($this);
     $title = $shareable->getTitle($this);
     $description = $shareable->getDescription($this);
     $userText = strval($userText);
     $title = strval($title);
     $description = strval($description);
     if (!empty($userText)) {
         $statusText = $userText;
     }
     if ($statusText === false) {
         if (!empty($title)) {
             $statusText = $title;
         }
         if (!empty($description)) {
             if (!empty($statusText)) {
                 $statusText .= ': ' . $description;
             } else {
                 $statusText = $description;
             }
         }
     }
     $link = $shareable->getLink($this);
     if (!empty($link)) {
         // minus short url length
         // minus one for the ellipsis character
         // minus another one for the space character
         $status = XenForo_Helper_String::wholeWordTrim($statusText, 140 - $this->getShortUrlLengthHttps($token) - 2, 0, '…') . ' ' . $link;
     } else {
         // minus one for the ellipsis character
         $status = XenForo_Helper_String::wholeWordTrim($statusText, 140 - 1, 0, '…');
     }
     $response = bdSocialShare_Helper_Twitter::statusesUpdate($token['oauth_token'], $token['oauth_token_secret'], $status);
     if (isset($response['id_str'])) {
         return $response;
     } else {
         throw new bdSocialShare_Exception_Interrupted(serialize(array($status, $response)));
     }
 }
コード例 #7
0
ファイル: Resource.php プロジェクト: Sywooch/forums
 public function getPreConfiguredTargets()
 {
     $resource = $this->_resourceDw->getMergedData();
     $visitor = XenForo_Visitor::getInstance();
     if ($resource['user_id'] == $visitor['user_id'] and $visitor->hasPermission('general', 'bdSocialShare_resourceAut')) {
         $option = bdSocialShare_Option::get('resourceAddAuto');
         if (is_array($option)) {
             return $option;
         }
     }
     return parent::getPreConfiguredTargets();
 }
コード例 #8
0
ファイル: Video.php プロジェクト: Sywooch/forums
 public function getImageDataPath(XenForo_Model $model)
 {
     $video = $this->_videoDw->getMergedData();
     $videoData = $this->_getVideoData($model);
     if (!empty($videoData)) {
         $path = $model->getModelFromCache('sonnb_XenGallery_Model_VideoData')->getContentDataFile($videoData);
         if (!file_exists($path)) {
             // TODO: remove this?
             $path = $model->getModelFromCache('sonnb_XenGallery_Model_VideoData')->getContentDataLargeThumbnailFile($videoData);
         }
         return $path;
     }
     return parent::getImageDataPath($model);
 }
コード例 #9
0
ファイル: Photo.php プロジェクト: Sywooch/forums
 public function getImageDataPath(XenForo_Model $model)
 {
     $photo = $this->_photoDw->getMergedData();
     $photoData = $this->_getPhotoData($model);
     if (!empty($photoData)) {
         $photoDataModel = $model->getModelFromCache('sonnb_XenGallery_Model_PhotoData');
         if (method_exists($photoDataModel, 'getPhotoDataFile')) {
             // sonnb - XenGallery v1.0.0
             return $photoDataModel->getPhotoDataFile($photoData);
         } else {
             // sonnb - XenGallery v2.0.0
             return $photoDataModel->getContentDataFile($photoData);
         }
     }
     return parent::getImageDataPath($model);
 }
コード例 #10
0
ファイル: Item.php プロジェクト: Sywooch/forums
 public function getImage(XenForo_Model $model)
 {
     $item = $this->_itemDw->getMergedData();
     if ($item['attach_count'] > 0) {
         if ($this->_image === false) {
             $item = $model->getModelFromCache('NFLJ_Showcase_Model_Item')->getAndMergeAttachmentsIntoItem($item);
             if (!empty($item['cover_image'])) {
                 $this->_image = XenForo_Link::convertUriToAbsoluteUri($item['cover_image']['thumbnailUrl'], true);
             } else {
                 $this->_image = '';
             }
         }
         if (!empty($this->_image)) {
             return $this->_image;
         }
     }
     return parent::getImage($model);
 }
コード例 #11
0
ファイル: Resource.php プロジェクト: Sywooch/forums
 public function bdSocialShare_actionIcon(XenResource_DataWriter_Resource $resourceDw)
 {
     $resource = $resourceDw->getMergedData();
     $queueDate = $resource['resource_date'] + bdSocialShare_Shareable_XenResource_Resource::SECONDS_WAIT_FOR_ICON;
     $shareQueueModel = $this->getModelFromCache('bdSocialShare_Model_ShareQueue');
     $queue = $shareQueueModel->getQueueAt($queueDate);
     if (!empty($queue)) {
         foreach ($queue as $id => $record) {
             $data = bdSocialShare_Helper_Common::unserializeOrFalse($record, 'queue_data');
             if (!empty($data) and !empty($data['shareable'])) {
                 $shareable = bdSocialShare_Shareable_Abstract::createFromRecoveryData($data['shareable']);
                 if ($shareable instanceof bdSocialShare_Shareable_XenResource_Resource and $shareable->getId() == $resource['resource_id']) {
                     $shareQueueModel->reInsertQueue($record, XenForo_Application::$time);
                 }
             }
         }
     }
     unset($GLOBALS[bdSocialShare_Listener::XENRESOURCE_CONTROLLERPUBLIC_RESOURCE_ICON]);
 }
コード例 #12
0
ファイル: Status.php プロジェクト: Sywooch/forums
 public function getPreConfiguredTargets()
 {
     $profilePost = $this->_profilePostDw->getMergedData();
     if ($profilePost['user_id'] != $profilePost['profile_user_id']) {
         // not a status
         return parent::getPreConfiguredTargets();
     }
     if (isset($profilePost['message_state']) and $profilePost['message_state'] !== 'visible') {
         // not visible, no auto share
         return parent::getPreConfiguredTargets();
     }
     $visitor = XenForo_Visitor::getInstance();
     if ($profilePost['user_id'] == $visitor['user_id'] and $visitor->hasPermission('general', 'bdSocialShare_statusAuto')) {
         $option = bdSocialShare_Option::get('statusAuto');
         if (is_array($option)) {
             return $option;
         }
     }
     return parent::getPreConfiguredTargets();
 }
コード例 #13
0
ファイル: Recover.php プロジェクト: Sywooch/forums
 public function recover($target, $recovery = false)
 {
     if ($recovery === false) {
         $recovery = $this->loadRecoveryData();
     }
     // reset recovery asap, it will be updated later
     $this->_getPublisherModel()->saveRecoveryData();
     $recovered = true;
     if (empty($recovery) or empty($recovery['shareable']) or empty($recovery['targets'])) {
         return false;
     }
     if (empty($recovery['targets'][$target])) {
         return false;
     }
     $targetId = $recovery['targets'][$target];
     $shareable = bdSocialShare_Shareable_Abstract::createFromRecoveryData($recovery['shareable']);
     if (empty($shareable)) {
         return false;
     }
     try {
         $this->_getPublisherModel()->publish($target, $targetId, $shareable);
         $this->_getPublisherModel()->postPublish($shareable);
         $recovered = true;
     } catch (bdSocialShare_Exception_Abstract $e) {
         if (XenForo_Application::debugMode()) {
             XenForo_Error::logException($e, false);
         }
     }
     if ($recovered) {
         // remove the target from the queue
         unset($recovery['targets'][$target]);
     }
     if (!empty($recovery['targets'])) {
         // still have something in queue, set recovery...
         $this->_getPublisherModel()->saveRecoveryData($recovery['shareable'], $recovery['targets']);
     }
 }
コード例 #14
0
ファイル: Facebook.php プロジェクト: Sywooch/forums
 public function publish($targetId, bdSocialShare_Shareable_Abstract $shareable, $accessToken)
 {
     try {
         $link = $shareable->getLink($this);
         $imageDataPath = $shareable->getImageDataPath($this);
         $userText = $shareable->getUserText($this);
         $title = $shareable->getTitle($this);
         $description = $shareable->getDescription($this);
         $image = $shareable->getImage($this);
         $userText = strval($userText);
         $title = strval($title);
         $description = strval($description);
         $sendLinkData = (bdSocialShare_Option::get('facebookSendLinkData') or $shareable instanceof bdSocialShare_Shareable_StaffShare);
         if ($sendLinkData and !empty($imageDataPath)) {
             // upload as a new photo in the app album
             $client = XenForo_Helper_Http::getClient(sprintf('https://graph.facebook.com/v2.0/%s/photos', $targetId));
             $client->setFileUpload($imageDataPath, 'source');
             $parts = array();
             if (!empty($title)) {
                 $parts[] = $title;
             }
             if (empty($parts)) {
                 if (!empty($description)) {
                     $parts[] = $description;
                 }
             }
             if (!empty($link)) {
                 $parts[] = $link;
             }
             if (!empty($parts)) {
                 $client->setParameterPost('message', implode("\n", $parts));
             }
         }
         if (empty($client) and !empty($link)) {
             // publish as a link
             $client = XenForo_Helper_Http::getClient(sprintf('https://graph.facebook.com/v2.0/%s/feed', $targetId));
             $client->setParameterPost('link', $link);
             if ($sendLinkData and !empty($title)) {
                 // send link data
                 $client->setParameterPost('name', $title);
                 if (!empty($image)) {
                     $client->setParameterPost('picture', $image);
                 }
                 if (!empty($description)) {
                     $client->setParameterPost('description', $description);
                 }
             }
             if (!empty($userText)) {
                 $client->setParameterPost('message', $userText);
             }
         }
         if (empty($client) and !empty($userText)) {
             // publish as a status
             $client = XenForo_Helper_Http::getClient(sprintf('https://graph.facebook.com/v2.0/%s/feed', $targetId));
             if (!empty($link)) {
                 // merge user text and link
                 $client->setParameterPost('message', sprintf('%s %s', $userText, $link));
             } else {
                 $client->setParameterPost('message', $userText);
             }
         }
         if (empty($client)) {
             return false;
         }
         $client->setParameterPost('access_token', $accessToken);
         $response = $client->request('POST');
         $responseBody = $response->getBody();
         $responseArray = json_decode($responseBody, true);
         if (isset($responseArray['id'])) {
             return $responseArray;
         } else {
             throw new bdSocialShare_Exception_Interrupted($responseBody);
         }
     } catch (Zend_Http_Client_Exception $e) {
         throw new bdSocialShare_Exception_HttpClient($e->getMessage());
     }
     // MUST NOT REACH HERE!!!!
 }
コード例 #15
0
ファイル: Publisher.php プロジェクト: Sywooch/forums
 protected function _postPublish_getUserOptionChanges(bdSocialShare_Shareable_Abstract $shareable, array $viewingUser = null)
 {
     $this->standardizeViewingUserReference($viewingUser);
     $changes = array();
     if (bdSocialShare_Option::hasPermissionFacebook($viewingUser)) {
         $optionFacebookNeeded = false;
         if ($shareable->isPublished('facebook')) {
             $published = $shareable->getPublishedExtraData('facebook');
             // notice the use of original_target_id instead of target_id here
             // sometimes (page posting), target_id will be extracted from original_target_id
             // through a series of parsing. The original is the important bit that worth
             // saving.
             $optionFacebookNeeded = $published['original_target_id'];
         } else {
             $optionFacebookNeeded = '';
         }
         if (!isset($viewingUser['bdsocialshare_facebook']) or strval($viewingUser['bdsocialshare_facebook']) !== strval($optionFacebookNeeded)) {
             $changes['bdsocialshare_facebook'] = $optionFacebookNeeded;
         }
     }
     if (bdSocialShare_Option::hasPermissionTwitter($viewingUser)) {
         $optionTwitterNeeded = false;
         if ($shareable->isPublished('twitter')) {
             $published = $shareable->getPublishedExtraData('twitter');
             // the usage of original_target_id is similar to Facebook routine above
             $optionTwitterNeeded = $published['original_target_id'];
         } else {
             $optionTwitterNeeded = '';
         }
         if (!isset($viewingUser['bdsocialshare_twitter']) or strval($viewingUser['bdsocialshare_twitter']) !== strval($optionTwitterNeeded)) {
             $changes['bdsocialshare_twitter'] = $optionTwitterNeeded;
         }
     }
     return $changes;
 }
コード例 #16
0
ファイル: Post.php プロジェクト: Sywooch/forums
 public function getPreConfiguredTargets()
 {
     $post = $this->_postDw->getMergedData();
     if (isset($post['message_state']) and $post['message_state'] !== 'visible') {
         // not visible, no auto share
         return parent::getPreConfiguredTargets();
     }
     if ($post['position'] == 0) {
         $visitor = XenForo_Visitor::getInstance();
         if ($post['user_id'] == $visitor['user_id'] and $visitor->hasPermission('general', 'bdSocialShare_threadAuto')) {
             $threadDw = $this->_postDw->getDiscussionDataWriter();
             if (!empty($threadDw)) {
                 $forumData = $threadDw->bdSocialShare_getForumData();
                 $forumDataThreadAuto = bdSocialShare_Helper_Common::unserializeOrFalse($forumData, 'bdsocialshare_threadauto');
                 if ($forumDataThreadAuto !== false) {
                     // forum configuration takes precedence
                     return $forumDataThreadAuto;
                 } else {
                     // use system configuration
                     $option = bdSocialShare_Option::get('threadAuto');
                     if (is_array($option)) {
                         return $option;
                     }
                 }
             }
         }
     }
     return parent::getPreConfiguredTargets();
 }
コード例 #17
0
ファイル: ShareQueue.php プロジェクト: Sywooch/forums
 public function runQueue($targetRunTime = 0)
 {
     $s = microtime(true);
     $db = $this->_getDb();
     do {
         $queue = $this->getQueue($targetRunTime ? 20 : 0);
         foreach ($queue as $id => $record) {
             if (!$db->delete('xf_bdsocialshare_share_queue', 'share_queue_id = ' . $db->quote($id))) {
                 // already been deleted - run elsewhere
                 continue;
             }
             $data = bdSocialShare_Helper_Common::unserializeOrFalse($record, 'queue_data');
             if (empty($data) or empty($data['shareable'])) {
                 if (XenForo_Application::debugMode()) {
                     XenForo_Error::logException(new XenForo_Exception('Insufficient data'), false);
                 }
                 continue;
             }
             $shareable = bdSocialShare_Shareable_Abstract::createFromRecoveryData($data['shareable']);
             if (empty($shareable)) {
                 if (XenForo_Application::debugMode()) {
                     XenForo_Error::logException(new XenForo_Exception('Unable to create shareable from recovery data'), false);
                 }
                 return false;
             }
             $userModel = $this->getModelFromCache('XenForo_Model_User');
             if (!empty($data['user_id'])) {
                 $viewingUser = $userModel->getVisitingUserById($data['user_id']);
             } else {
                 $viewingUser = $userModel->getVisitingGuestUser();
             }
             if (empty($viewingUser)) {
                 if (XenForo_Application::debugMode()) {
                     XenForo_Error::logException(new XenForo_Exception('User could not be found'), false);
                 }
                 return false;
             }
             $userModel->bdSocialShare_prepareViewingUser($viewingUser);
             $this->publish($shareable, $data['targets'], !empty($data['default']), $viewingUser);
             if ($targetRunTime && microtime(true) - $s > $targetRunTime) {
                 $queue = false;
                 break;
             }
         }
     } while ($queue);
     return $this->hasQueue();
 }