You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ocsclient.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @author Jakob Sack
  7. * @copyright 2010 Frank Karlitschek karlitschek@kde.org
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public
  20. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. /**
  24. * This class provides an easy way for apps to store config values in the
  25. * database.
  26. */
  27. class OC_OCSClient{
  28. /**
  29. * @brief Get all the categories from the OCS server
  30. * @returns array with category ids
  31. *
  32. * This function returns a list of all the application categories on the OCS server
  33. */
  34. public static function getCategories(){
  35. $url='http://api.apps.owncloud.com/v1/content/categories';
  36. $xml=@file_get_contents($url);
  37. if($xml==FALSE){
  38. return NULL;
  39. }
  40. $data=simplexml_load_string($xml);
  41. $tmp=$data->data;
  42. $cats=array();
  43. foreach($tmp->category as $key=>$value) {
  44. $id= (int) $value->id;
  45. $name= (string) $value->name;
  46. $cats[$id]=$name;
  47. }
  48. return $cats;
  49. }
  50. /**
  51. * @brief Get all the applications from the OCS server
  52. * @returns array with application data
  53. *
  54. * This function returns a list of all the applications on the OCS server
  55. */
  56. public static function getApplications($categories){
  57. if(is_array($categories)) {
  58. $categoriesstring=implode('x',$categories);
  59. }else{
  60. $categoriesstring=$categories;
  61. }
  62. $url='http://api.apps.owncloud.com/v1/content/data?categories='.urlencode($categoriesstring).'&sortmode=new&page=0&pagesize=10';
  63. $apps=array();
  64. $xml=@file_get_contents($url);
  65. if($xml==FALSE){
  66. return NULL;
  67. }
  68. $data=simplexml_load_string($xml);
  69. $tmp=$data->data->content;
  70. for($i = 0; $i < count($tmp); $i++) {
  71. $app=array();
  72. $app['id']=$tmp[$i]->id;
  73. $app['name']=$tmp[$i]->name;
  74. $app['type']=$tmp[$i]->typeid;
  75. $app['typename']=$tmp[$i]->typename;
  76. $app['personid']=$tmp[$i]->personid;
  77. $app['detailpage']=$tmp[$i]->detailpage;
  78. $app['preview']=$tmp[$i]->smallpreviewpic1;
  79. $app['changed']=strtotime($tmp[$i]->changed);
  80. $app['description']=$tmp[$i]->description;
  81. $apps[]=$app;
  82. }
  83. return $apps;
  84. }
  85. /**
  86. * @brief Get an the applications from the OCS server
  87. * @returns array with application data
  88. *
  89. * This function returns an applications from the OCS server
  90. */
  91. public static function getApplication($id){
  92. $url='http://api.apps.owncloud.com/v1/content/data/'.urlencode($id);
  93. $xml=@file_get_contents($url);
  94. if($xml==FALSE){
  95. return NULL;
  96. }
  97. $data=simplexml_load_string($xml);
  98. $tmp=$data->data->content;
  99. $app=array();
  100. $app['id']=$tmp->id;
  101. $app['name']=$tmp->name;
  102. $app['type']=$tmp->typeid;
  103. $app['typename']=$tmp->typename;
  104. $app['personid']=$tmp->personid;
  105. $app['detailpage']=$tmp->detailpage;
  106. $app['preview1']=$tmp->smallpreviewpic1;
  107. $app['preview2']=$tmp->smallpreviewpic2;
  108. $app['preview3']=$tmp->smallpreviewpic3;
  109. $app['changed']=strtotime($tmp->changed);
  110. $app['description']=$tmp->description;
  111. return $app;
  112. }
  113. /**
  114. * @brief Get all the knowledgebase entries from the OCS server
  115. * @returns array with q and a data
  116. *
  117. * This function returns a list of all the knowledgebase entries from the OCS server
  118. */
  119. public static function getKnownledgebaseEntries(){
  120. $url='http://api.apps.owncloud.com/v1/knowledgebase/data?type=150&page=0&pagesize=10';
  121. $kbe=array();
  122. $xml=@file_get_contents($url);
  123. if($xml==FALSE){
  124. return NULL;
  125. }
  126. $data=simplexml_load_string($xml);
  127. $tmp=$data->data->content;
  128. for($i = 0; $i < count($tmp); $i++) {
  129. $kb=array();
  130. $kb['id']=$tmp[$i]->id;
  131. $kb['name']=$tmp[$i]->name;
  132. $kb['description']=$tmp[$i]->description;
  133. $kb['answer']=$tmp[$i]->answer;
  134. $kb['preview1']=$tmp[$i]->smallpreviewpic1;
  135. $kbe[]=$kb;
  136. }
  137. return $kbe;
  138. }
  139. }