2015-08-08 23:15:12 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
namespace OCA\Files_Sharing\API;
|
|
|
|
|
2015-08-13 11:13:23 +03:00
|
|
|
use Doctrine\DBAL\Connection;
|
2015-08-13 12:06:03 +03:00
|
|
|
use OC\Share\SearchResultSorter;
|
|
|
|
use OCP\Contacts\IManager;
|
2015-08-13 11:13:23 +03:00
|
|
|
use OCP\IDBConnection;
|
2015-08-11 17:22:05 +03:00
|
|
|
use OCP\IGroup;
|
2015-08-08 23:15:12 +03:00
|
|
|
use OCP\IGroupManager;
|
2015-08-13 12:06:03 +03:00
|
|
|
use OCP\ILogger;
|
2015-08-08 23:15:12 +03:00
|
|
|
use OCP\IUserManager;
|
2015-08-12 15:23:48 +03:00
|
|
|
use OCP\IConfig;
|
2015-08-08 23:15:12 +03:00
|
|
|
use OCP\IUserSession;
|
|
|
|
use OCP\IURLGenerator;
|
2015-08-13 12:06:03 +03:00
|
|
|
use OCP\Share;
|
2015-08-08 23:15:12 +03:00
|
|
|
|
|
|
|
class Sharees {
|
|
|
|
|
|
|
|
/** @var IGroupManager */
|
|
|
|
private $groupManager;
|
|
|
|
|
|
|
|
/** @var IUserManager */
|
|
|
|
private $userManager;
|
|
|
|
|
2015-08-13 12:06:03 +03:00
|
|
|
/** @var IManager */
|
2015-08-08 23:15:12 +03:00
|
|
|
private $contactsManager;
|
|
|
|
|
2015-08-12 15:23:48 +03:00
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
2015-08-08 23:15:12 +03:00
|
|
|
|
|
|
|
/** @var IUserSession */
|
|
|
|
private $userSession;
|
|
|
|
|
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
|
|
|
|
2015-08-13 12:06:03 +03:00
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
|
|
|
|
2015-08-13 11:13:23 +03:00
|
|
|
/** @var IDBConnection */
|
|
|
|
private $connection;
|
|
|
|
|
2015-08-08 23:15:12 +03:00
|
|
|
/**
|
|
|
|
* @param IGroupManager $groupManager
|
|
|
|
* @param IUserManager $userManager
|
2015-08-13 12:06:03 +03:00
|
|
|
* @param IManager $contactsManager
|
2015-08-12 15:23:48 +03:00
|
|
|
* @param IConfig $config
|
2015-08-08 23:15:12 +03:00
|
|
|
* @param IUserSession $userSession
|
2015-08-13 12:06:03 +03:00
|
|
|
* @param IURLGenerator $urlGenerator
|
|
|
|
* @param ILogger $logger
|
2015-08-13 11:13:23 +03:00
|
|
|
* @param IDBConnection $connection
|
2015-08-08 23:15:12 +03:00
|
|
|
*/
|
|
|
|
public function __construct(IGroupManager $groupManager,
|
2015-08-11 15:57:51 +03:00
|
|
|
IUserManager $userManager,
|
2015-08-13 12:06:03 +03:00
|
|
|
IManager $contactsManager,
|
2015-08-12 15:23:48 +03:00
|
|
|
IConfig $config,
|
2015-08-08 23:15:12 +03:00
|
|
|
IUserSession $userSession,
|
2015-08-13 12:06:03 +03:00
|
|
|
IURLGenerator $urlGenerator,
|
2015-08-13 11:13:23 +03:00
|
|
|
ILogger $logger,
|
|
|
|
IDBConnection $connection) {
|
2015-08-08 23:15:12 +03:00
|
|
|
$this->groupManager = $groupManager;
|
|
|
|
$this->userManager = $userManager;
|
|
|
|
$this->contactsManager = $contactsManager;
|
2015-08-12 15:23:48 +03:00
|
|
|
$this->config = $config;
|
2015-08-08 23:15:12 +03:00
|
|
|
$this->userSession = $userSession;
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
2015-08-13 12:06:03 +03:00
|
|
|
$this->logger = $logger;
|
2015-08-13 11:13:23 +03:00
|
|
|
$this->connection = $connection;
|
2015-08-08 23:15:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $search
|
|
|
|
* @param bool $shareWithGroupOnly
|
|
|
|
*
|
|
|
|
* @return array possible sharees
|
|
|
|
*/
|
2015-08-12 15:19:34 +03:00
|
|
|
protected function getUsers($search, $shareWithGroupOnly) {
|
2015-08-08 23:15:12 +03:00
|
|
|
$sharees = [];
|
|
|
|
|
|
|
|
$users = [];
|
|
|
|
if ($shareWithGroupOnly) {
|
|
|
|
// Search in all the groups this user is part of
|
2015-08-11 16:43:44 +03:00
|
|
|
$userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser());
|
2015-08-08 23:15:12 +03:00
|
|
|
foreach ($userGroups as $userGroup) {
|
|
|
|
$users = array_merge($users, $this->groupManager->displayNamesInGroup($userGroup, $search));
|
|
|
|
}
|
|
|
|
$users = array_unique($users);
|
|
|
|
} else {
|
|
|
|
// Search in all users
|
|
|
|
$users_tmp = $this->userManager->searchDisplayName($search);
|
|
|
|
|
|
|
|
// Put in array that maps uid => displayName
|
|
|
|
foreach($users_tmp as $user) {
|
|
|
|
$users[$user->getUID()] = $user->getDisplayName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($users as $uid => $displayName) {
|
2015-08-17 13:13:49 +03:00
|
|
|
if ($uid === $this->userSession->getUser()->getUID()) {
|
|
|
|
// Skip the current user
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-08-08 23:15:12 +03:00
|
|
|
$sharees[] = [
|
|
|
|
'label' => $displayName,
|
|
|
|
'value' => [
|
2015-08-13 12:06:03 +03:00
|
|
|
'shareType' => Share::SHARE_TYPE_USER,
|
2015-08-11 17:22:05 +03:00
|
|
|
'shareWith' => $uid,
|
|
|
|
],
|
2015-08-08 23:15:12 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sharees;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $search
|
|
|
|
* @param bool $shareWithGroupOnly
|
|
|
|
*
|
|
|
|
* @return array possible sharees
|
|
|
|
*/
|
2015-08-12 15:19:34 +03:00
|
|
|
protected function getGroups($search, $shareWithGroupOnly) {
|
2015-08-08 23:15:12 +03:00
|
|
|
$sharees = [];
|
|
|
|
$groups = $this->groupManager->search($search);
|
2015-08-11 17:22:05 +03:00
|
|
|
$groups = array_map(function (IGroup $group) { return $group->getGID(); }, $groups);
|
2015-08-08 23:15:12 +03:00
|
|
|
|
2015-08-11 17:22:05 +03:00
|
|
|
if (!empty($groups) && $shareWithGroupOnly) {
|
2015-08-08 23:15:12 +03:00
|
|
|
// Intersect all the groups that match with the groups this user is a member of
|
|
|
|
$userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
|
2015-08-11 17:22:05 +03:00
|
|
|
$userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups);
|
2015-08-08 23:15:12 +03:00
|
|
|
$groups = array_intersect($groups, $userGroups);
|
|
|
|
}
|
|
|
|
|
2015-08-11 17:22:05 +03:00
|
|
|
foreach ($groups as $gid) {
|
2015-08-08 23:15:12 +03:00
|
|
|
$sharees[] = [
|
2015-08-11 17:22:05 +03:00
|
|
|
'label' => $gid,
|
2015-08-08 23:15:12 +03:00
|
|
|
'value' => [
|
2015-08-13 12:06:03 +03:00
|
|
|
'shareType' => Share::SHARE_TYPE_GROUP,
|
2015-08-11 17:22:05 +03:00
|
|
|
'shareWith' => $gid,
|
|
|
|
],
|
2015-08-08 23:15:12 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sharees;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $search
|
|
|
|
*
|
|
|
|
* @return array possible sharees
|
|
|
|
*/
|
2015-08-12 15:19:34 +03:00
|
|
|
protected function getRemote($search) {
|
2015-08-08 23:15:12 +03:00
|
|
|
$sharees = [];
|
|
|
|
|
|
|
|
if (substr_count($search, '@') >= 1) {
|
|
|
|
$sharees[] = [
|
|
|
|
'label' => $search,
|
|
|
|
'value' => [
|
2015-08-13 12:06:03 +03:00
|
|
|
'shareType' => Share::SHARE_TYPE_REMOTE,
|
2015-08-11 17:22:05 +03:00
|
|
|
'shareWith' => $search,
|
|
|
|
],
|
2015-08-08 23:15:12 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search in contacts
|
|
|
|
$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']);
|
|
|
|
foreach ($addressBookContacts as $contact) {
|
|
|
|
if (isset($contact['CLOUD'])) {
|
|
|
|
foreach ($contact['CLOUD'] as $cloudId) {
|
|
|
|
$sharees[] = [
|
|
|
|
'label' => $contact['FN'] . ' (' . $cloudId . ')',
|
|
|
|
'value' => [
|
2015-08-13 12:06:03 +03:00
|
|
|
'shareType' => Share::SHARE_TYPE_REMOTE,
|
2015-08-08 23:15:12 +03:00
|
|
|
'shareWith' => $cloudId
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $sharees;
|
|
|
|
}
|
|
|
|
|
2015-08-12 15:19:34 +03:00
|
|
|
/**
|
|
|
|
* @return \OC_OCS_Result
|
|
|
|
*/
|
2015-08-12 15:23:48 +03:00
|
|
|
public function search() {
|
2015-08-12 16:03:50 +03:00
|
|
|
$search = isset($_GET['search']) ? (string) $_GET['search'] : '';
|
|
|
|
$itemType = isset($_GET['itemType']) ? (string) $_GET['itemType'] : null;
|
2015-08-13 11:13:23 +03:00
|
|
|
$shareIds = isset($_GET['existingShares']) ? (array) $_GET['existingShares'] : [];
|
2015-08-12 18:05:20 +03:00
|
|
|
$page = !empty($_GET['page']) ? max(1, (int) $_GET['page']) : 1;
|
|
|
|
$perPage = !empty($_GET['limit']) ? max(1, (int) $_GET['limit']) : 200;
|
|
|
|
|
|
|
|
$shareTypes = [
|
2015-08-13 12:06:03 +03:00
|
|
|
Share::SHARE_TYPE_USER,
|
|
|
|
Share::SHARE_TYPE_GROUP,
|
|
|
|
Share::SHARE_TYPE_REMOTE,
|
2015-08-12 18:05:20 +03:00
|
|
|
];
|
|
|
|
if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
|
|
|
|
$shareTypes = array_intersect($shareTypes, $_GET['shareType']);
|
|
|
|
sort($shareTypes);
|
|
|
|
|
|
|
|
} else if (isset($_GET['shareType']) && is_numeric($_GET['shareType'])) {
|
|
|
|
$shareTypes = array_intersect($shareTypes, [(int) $_GET['shareType']]);
|
|
|
|
sort($shareTypes);
|
|
|
|
}
|
|
|
|
|
2015-08-13 12:06:03 +03:00
|
|
|
if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes) && !$this->isRemoteSharingAllowed($itemType)) {
|
2015-08-12 18:05:20 +03:00
|
|
|
// Remove remote shares from type array, because it is not allowed.
|
2015-08-13 12:06:03 +03:00
|
|
|
$shareTypes = array_diff($shareTypes, [Share::SHARE_TYPE_REMOTE]);
|
2015-08-12 18:05:20 +03:00
|
|
|
}
|
2015-08-11 19:03:07 +03:00
|
|
|
|
2015-08-12 15:23:48 +03:00
|
|
|
$shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
|
2015-08-12 15:19:34 +03:00
|
|
|
|
2015-08-13 11:13:23 +03:00
|
|
|
return $this->searchSharees($search, $itemType, $shareIds, $shareTypes, $page, $perPage, $shareWithGroupOnly);
|
2015-08-12 18:05:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to get out the static call for better testing
|
|
|
|
*
|
|
|
|
* @param string $itemType
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function isRemoteSharingAllowed($itemType) {
|
|
|
|
try {
|
2015-08-13 12:06:03 +03:00
|
|
|
$backend = Share::getBackend($itemType);
|
|
|
|
return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE);
|
2015-08-12 18:05:20 +03:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-12 15:19:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Testable search function that does not need globals
|
|
|
|
*
|
|
|
|
* @param string $search
|
|
|
|
* @param string $itemType
|
2015-08-13 11:13:23 +03:00
|
|
|
* @param array $shareIds
|
2015-08-12 18:05:20 +03:00
|
|
|
* @param array $shareTypes
|
2015-08-12 15:19:34 +03:00
|
|
|
* @param int $page
|
|
|
|
* @param int $perPage
|
|
|
|
* @param bool $shareWithGroupOnly
|
|
|
|
* @return \OC_OCS_Result
|
|
|
|
*/
|
2015-08-13 11:13:23 +03:00
|
|
|
protected function searchSharees($search, $itemType, array $shareIds, array $shareTypes, $page, $perPage, $shareWithGroupOnly) {
|
2015-08-12 15:19:34 +03:00
|
|
|
|
2015-08-11 19:03:07 +03:00
|
|
|
$sharedUsers = $sharedGroups = [];
|
2015-08-13 11:13:23 +03:00
|
|
|
$existingSharees = $this->getShareesForShareIds($shareIds);
|
|
|
|
|
|
|
|
if (!empty($existingSharees)) {
|
|
|
|
if (!empty($existingSharees[Share::SHARE_TYPE_USER]) &&
|
|
|
|
is_array($existingSharees[Share::SHARE_TYPE_USER])) {
|
|
|
|
$sharedUsers = $existingSharees[Share::SHARE_TYPE_USER];
|
2015-08-11 19:03:07 +03:00
|
|
|
}
|
|
|
|
|
2015-08-13 11:13:23 +03:00
|
|
|
if (!empty($existingSharees[Share::SHARE_TYPE_GROUP]) &&
|
|
|
|
is_array($existingSharees[Share::SHARE_TYPE_GROUP])) {
|
|
|
|
$sharedGroups = $existingSharees[Share::SHARE_TYPE_GROUP];
|
2015-08-11 19:03:07 +03:00
|
|
|
}
|
|
|
|
}
|
2015-08-08 23:15:12 +03:00
|
|
|
|
|
|
|
// Verify arguments
|
2015-08-11 19:03:07 +03:00
|
|
|
if ($itemType === null) {
|
|
|
|
return new \OC_OCS_Result(null, 400, 'missing itemType');
|
2015-08-08 23:15:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$sharees = [];
|
|
|
|
// Get users
|
2015-08-13 12:06:03 +03:00
|
|
|
if (in_array(Share::SHARE_TYPE_USER, $shareTypes)) {
|
2015-08-11 19:03:07 +03:00
|
|
|
$potentialSharees = $this->getUsers($search, $shareWithGroupOnly);
|
|
|
|
$sharees = array_merge($sharees, $this->filterSharees($potentialSharees, $sharedUsers));
|
2015-08-08 23:15:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get groups
|
2015-08-13 12:06:03 +03:00
|
|
|
if (in_array(Share::SHARE_TYPE_GROUP, $shareTypes)) {
|
2015-08-11 19:03:07 +03:00
|
|
|
$potentialSharees = $this->getGroups($search, $shareWithGroupOnly);
|
|
|
|
$sharees = array_merge($sharees, $this->filterSharees($potentialSharees, $sharedGroups));
|
2015-08-08 23:15:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get remote
|
2015-08-13 12:06:03 +03:00
|
|
|
if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes)) {
|
2015-08-08 23:15:12 +03:00
|
|
|
$sharees = array_merge($sharees, $this->getRemote($search));
|
|
|
|
}
|
|
|
|
|
2015-08-09 21:47:49 +03:00
|
|
|
|
|
|
|
// Sort sharees
|
2015-08-13 12:06:03 +03:00
|
|
|
$sorter = new SearchResultSorter($search, 'label', $this->logger);
|
2015-08-11 18:24:54 +03:00
|
|
|
usort($sharees, array($sorter, 'sort'));
|
2015-08-09 21:47:49 +03:00
|
|
|
|
2015-08-08 23:15:12 +03:00
|
|
|
//Pagination
|
2015-08-11 19:03:07 +03:00
|
|
|
$start = ($page - 1) * $perPage;
|
|
|
|
$total = sizeof($sharees);
|
2015-08-08 23:15:12 +03:00
|
|
|
|
2015-08-11 19:03:07 +03:00
|
|
|
$sharees = array_slice($sharees, $start, $perPage);
|
2015-08-08 23:15:12 +03:00
|
|
|
|
2015-08-11 19:03:07 +03:00
|
|
|
$response = new \OC_OCS_Result($sharees);
|
|
|
|
$response->setTotalItems($total);
|
|
|
|
$response->setItemsPerPage($perPage);
|
|
|
|
|
2015-08-13 11:57:08 +03:00
|
|
|
$links = $this->getPaginationLinks($page, $total, [
|
|
|
|
'search' => $search,
|
|
|
|
'itemType' => $itemType,
|
2015-08-13 11:13:23 +03:00
|
|
|
'existingShares' => $shareIds,
|
2015-08-13 11:57:08 +03:00
|
|
|
'shareType' => $shareTypes,
|
|
|
|
'limit' => $perPage,
|
|
|
|
]);
|
2015-08-12 18:05:20 +03:00
|
|
|
|
2015-08-13 11:57:08 +03:00
|
|
|
if (!empty($links)) {
|
|
|
|
$response->addHeader('Link', implode(', ', $links));
|
2015-08-08 23:15:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
2015-08-11 19:03:07 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter out already existing shares from a list of potential sharees
|
|
|
|
*
|
|
|
|
* @param array $potentialSharees
|
|
|
|
* @param array $existingSharees
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-08-12 15:19:34 +03:00
|
|
|
protected function filterSharees($potentialSharees, $existingSharees) {
|
2015-08-13 11:57:08 +03:00
|
|
|
$sharees = array_filter($potentialSharees, function ($sharee) use ($existingSharees) {
|
2015-08-11 19:03:07 +03:00
|
|
|
return in_array($sharee['value']['shareWith'], $existingSharees) ? null : $sharee;
|
2015-08-13 11:57:08 +03:00
|
|
|
});
|
2015-08-11 19:03:07 +03:00
|
|
|
|
2015-08-13 11:57:08 +03:00
|
|
|
return $sharees;
|
|
|
|
}
|
|
|
|
|
2015-08-13 11:13:23 +03:00
|
|
|
/**
|
|
|
|
* Get a list of existing share_with's for the given share IDs (if the current user owns them)
|
|
|
|
*
|
|
|
|
* @param array $shareIds
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getShareesForShareIds($shareIds) {
|
|
|
|
if (empty($shareIds)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$queryBuilder = $this->connection->getQueryBuilder();
|
|
|
|
$exprBuilder = $queryBuilder->expr();
|
|
|
|
|
|
|
|
$queryBuilder->select(['share_type', 'share_with'])
|
|
|
|
->from('share')
|
|
|
|
->where($exprBuilder->in('id', $queryBuilder->createParameter('shareIds')))
|
|
|
|
->andWhere($exprBuilder->eq('uid_owner', $queryBuilder->createParameter('user')))
|
|
|
|
->andWhere($exprBuilder->isNull('parent'))
|
|
|
|
->setParameter('shareIds', $shareIds, Connection::PARAM_INT_ARRAY)
|
|
|
|
->setParameter('user', $this->userSession->getUser()->getUID());
|
|
|
|
$query = $queryBuilder->execute();
|
|
|
|
|
|
|
|
$sharees = [];
|
|
|
|
while ($row = $query->fetch()) {
|
|
|
|
$sharees[$row['share_type']][] = $row['share_with'];
|
|
|
|
}
|
|
|
|
$query->closeCursor();
|
|
|
|
|
|
|
|
return $sharees;
|
|
|
|
}
|
|
|
|
|
2015-08-13 11:57:08 +03:00
|
|
|
/**
|
|
|
|
* Generates a bunch of pagination links for the current page
|
|
|
|
*
|
|
|
|
* @param int $page Current page
|
|
|
|
* @param int $total Number of total items that need to be paginated
|
|
|
|
* @param array $params Parameters for the URL
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getPaginationLinks($page, $total, array $params) {
|
|
|
|
$url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?';
|
|
|
|
|
|
|
|
$links = [];
|
|
|
|
if ($page > 1) {
|
|
|
|
$params['page'] = 1;
|
|
|
|
$links[] = '<' . $url . http_build_query($params) . '>; rel="first"';
|
|
|
|
$params['page'] = $page - 1;
|
|
|
|
$links[] = '<' . $url . http_build_query($params) . '>; rel="prev"';
|
|
|
|
}
|
|
|
|
if ($page * $params['limit'] < $total) {
|
|
|
|
$params['page'] = $page + 1;
|
|
|
|
$links[] = '<' . $url . http_build_query($params) . '>; rel="next"';
|
|
|
|
$params['page'] = ceil($total / $params['limit']);
|
|
|
|
$links[] = '<' . $url . http_build_query($params) . '>; rel="last"';
|
|
|
|
}
|
|
|
|
return $links;
|
2015-08-11 19:03:07 +03:00
|
|
|
}
|
2015-08-08 23:15:12 +03:00
|
|
|
}
|