コード例 #1
0
 /**
  * Generates a pagination URL based on a cursor.
  *
  * @param string $direction The direction of the page: next|previous
  *
  * @return string|null
  *
  * @throws FacebookSDKException
  */
 public function getPaginationUrl($direction)
 {
     $this->validateForPagination();
     // Do we have a paging URL?
     if (isset($this->metaData['paging'][$direction])) {
         // Graph returns the full URL with all the original params.
         // We just want the endpoint though.
         $pageUrl = $this->metaData['paging'][$direction];
         return FacebookUrlManipulator::baseGraphUrlEndpoint($pageUrl);
     }
     // Do we have a cursor to work with?
     $cursorDirection = $direction === 'next' ? 'after' : 'before';
     $cursor = $this->getCursor($cursorDirection);
     if (!$cursor) {
         return null;
     }
     // If we don't know the ID of the parent node, this ain't gonna work.
     if (!$this->parentEdgeEndpoint) {
         return null;
     }
     // We have the parent node ID, paging cursor & original request.
     // These were the ingredients chosen to create the perfect little URL.
     $pageUrl = $this->parentEdgeEndpoint . '?' . $cursorDirection . '=' . urlencode($cursor);
     // Pull in the original params
     $originalUrl = $this->request->getUrl();
     $pageUrl = FacebookUrlManipulator::mergeUrlParams($originalUrl, $pageUrl);
     return FacebookUrlManipulator::forceSlashPrefix($pageUrl);
 }
コード例 #2
0
ファイル: GraphEdge.php プロジェクト: vihoangson/Family
 /**
  * Generates a pagination URL based on a cursor.
  *
  * @param string $direction The direction of the page: next|previous
  *
  * @return string|null
  *
  * @throws FacebookSDKException
  */
 public function getPaginationUrl($direction)
 {
     $this->validateForPagination();
     // Do we have a paging URL?
     if (!isset($this->metaData['paging'][$direction])) {
         return null;
     }
     $pageUrl = $this->metaData['paging'][$direction];
     return FacebookUrlManipulator::baseGraphUrlEndpoint($pageUrl);
 }
コード例 #3
0
 public function testGraphUrlsCanBeTrimmed()
 {
     $fullGraphUrl = 'https://graph.facebook.com/';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/', $baseGraphUrl);
     $fullGraphUrl = 'https://graph.facebook.com/v1.0/';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/', $baseGraphUrl);
     $fullGraphUrl = 'https://graph.facebook.com/me';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/me', $baseGraphUrl);
     $fullGraphUrl = 'https://graph.beta.facebook.com/me';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/me', $baseGraphUrl);
     $fullGraphUrl = 'https://whatever-they-want.facebook.com/v2.1/me';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/me', $baseGraphUrl);
     $fullGraphUrl = 'https://graph.facebook.com/v5.301/1233?foo=bar';
     $baseGraphUrl = FacebookUrlManipulator::baseGraphUrlEndpoint($fullGraphUrl);
     $this->assertEquals('/1233?foo=bar', $baseGraphUrl);
 }