Play images and video from Synology PhotoStation server

query.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /* Copyright (c) 2000-2012 Synology Inc. All rights reserved. */
  3. require_once 'query.inc.php';
  4. class QueryAPI extends WebAPI
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct(SZ_QUERY_API_DESCRIPTION_PATH);
  9. }
  10. protected function Process()
  11. {
  12. if (!strcasecmp($this->method, "query")) {
  13. $this->Query();
  14. }
  15. }
  16. public static function CheckAPIDescription($apiDesc)
  17. {
  18. if (!is_string($apiDesc[SZK_API_PATH]) || !is_int($apiDesc[SZK_API_MIN_VERSION]) || !is_int($apiDesc[SZK_API_MAX_VERSION])) {
  19. return false;
  20. }
  21. return true;
  22. }
  23. public static function GetAPIDescriptions()
  24. {
  25. $allApiDescs = array();
  26. $apiFiles = glob(CONF_API_DESCRIPTION_DIR.'/*.api', GLOB_MARK);
  27. foreach ($apiFiles as $file) {
  28. $jsonString = file_get_contents($file);
  29. $apiDescs = json_decode($jsonString, true);
  30. foreach ($apiDescs as $apiName => $apiDesc) {
  31. if (!self::CheckAPIDescription($apiDesc)) {
  32. WebAPIUtil::Log("API desc error. api=$apiName, desc=$apiDesc");
  33. continue;
  34. }
  35. $allApiDescs[$apiName][SZK_API_PATH] = $apiDesc[SZK_API_PATH];
  36. $allApiDescs[$apiName][SZK_API_MIN_VERSION] = $apiDesc[SZK_API_MIN_VERSION];
  37. $allApiDescs[$apiName][SZK_API_MAX_VERSION] = $apiDesc[SZK_API_MAX_VERSION];
  38. }
  39. }
  40. return $allApiDescs;
  41. }
  42. public function Query()
  43. {
  44. $allApiDescs = self::GetAPIDescriptions();
  45. $queryedApiDescs = array();
  46. if (!isset($_REQUEST['query']) || !strcasecmp($_REQUEST['query'], 'all')) {
  47. $this->SetResponse($allApiDescs);
  48. return;
  49. }
  50. $queries = WebAPIUtil::ParseToArray($_REQUEST['query'], ",");
  51. foreach ($queries as $query) {
  52. $isPrefix = (0 === substr_compare($query, '.', -1, 1)); // end with '.'
  53. if ($isPrefix) {
  54. foreach ($allApiDescs as $apiName => $apiDesc) {
  55. if (!strncmp($apiName, $query, strlen($query))) {
  56. $queryedApiDescs[$apiName] = $apiDesc;
  57. }
  58. }
  59. } else {
  60. if (isset($allApiDescs[$query])) {
  61. $queryedApiDescs[$query] = $allApiDescs[$query];
  62. }
  63. }
  64. }
  65. if (empty($queryedApiDescs)) {
  66. // convert empty array to empty object for json output
  67. $queryedApiDescs = json_decode('{}');
  68. }
  69. $this->SetResponse($queryedApiDescs);
  70. return;
  71. }
  72. }
  73. $api = new QueryAPI();
  74. $api->Run();