Add searching by publicLocation.
This commit is contained in:
@@ -94,4 +94,30 @@ class Api {
|
||||
}
|
||||
}
|
||||
|
||||
public function get_publication_by_public_location(string $url, array $args = []):?stdClass {
|
||||
if (!isset($this->client) || empty($url)) return null;
|
||||
|
||||
if (strpos($url, 'https://') !== 0) {
|
||||
$user = $this->get_user();
|
||||
if (is_null($user) || !property_exists($user, 'username') || empty($user->username)) return null;
|
||||
$url = "https://issuu.com/$user->username/docs/$url";
|
||||
}
|
||||
|
||||
// Remove query params
|
||||
$url = explode('?', $url)[0];
|
||||
|
||||
$page = 1;
|
||||
while (true) {
|
||||
$publications = $this->get_publications(array_merge($args, [
|
||||
'page' => $page++,
|
||||
]));
|
||||
if (is_null($publications) || !$publications->count || empty($publications->results)) break;
|
||||
foreach ($publications->results as $publication) {
|
||||
if (!property_exists($publication, 'publicLocation') || empty($publication->publicLocation)) continue;
|
||||
if ($publication->publicLocation == $url) return $publication;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user