您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ocsclient.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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']=(string)$tmp[$i]->id;
  73. $app['name']=(string)$tmp[$i]->name;
  74. $app['type']=(string)$tmp[$i]->typeid;
  75. $app['typename']=(string)$tmp[$i]->typename;
  76. $app['personid']=(string)$tmp[$i]->personid;
  77. $app['license']=(string)$tmp[$i]->license;
  78. $app['detailpage']=(string)$tmp[$i]->detailpage;
  79. $app['preview']=(string)$tmp[$i]->smallpreviewpic1;
  80. $app['changed']=strtotime($tmp[$i]->changed);
  81. $app['description']=(string)$tmp[$i]->description;
  82. $apps[]=$app;
  83. }
  84. return $apps;
  85. }
  86. /**
  87. * @brief Get an the applications from the OCS server
  88. * @returns array with application data
  89. *
  90. * This function returns an applications from the OCS server
  91. */
  92. public static function getApplication($id){
  93. $url='http://api.apps.owncloud.com/v1/content/data/'.urlencode($id);
  94. $xml=@file_get_contents($url);
  95. if($xml==FALSE){
  96. return NULL;
  97. }
  98. $data=simplexml_load_string($xml);
  99. $tmp=$data->data->content;
  100. $app=array();
  101. $app['id']=$tmp->id;
  102. $app['name']=$tmp->name;
  103. $app['type']=$tmp->typeid;
  104. $app['typename']=$tmp->typename;
  105. $app['personid']=$tmp->personid;
  106. $app['detailpage']=$tmp->detailpage;
  107. $app['preview1']=$tmp->smallpreviewpic1;
  108. $app['preview2']=$tmp->smallpreviewpic2;
  109. $app['preview3']=$tmp->smallpreviewpic3;
  110. $app['changed']=strtotime($tmp->changed);
  111. $app['description']=$tmp->description;
  112. return $app;
  113. }
  114. /**
  115. * @brief Get all the knowledgebase entries from the OCS server
  116. * @returns array with q and a data
  117. *
  118. * This function returns a list of all the knowledgebase entries from the OCS server
  119. */
  120. public static function getKnownledgebaseEntries($page,$pagesize){
  121. $p= (int) $page;
  122. $s= (int) $pagesize;
  123. $url='http://api.apps.owncloud.com/v1/knowledgebase/data?type=150&page='.$p.'&pagesize='.$s;
  124. $kbe=array();
  125. $xml=@file_get_contents($url);
  126. if($xml==FALSE){
  127. return NULL;
  128. }
  129. $data=simplexml_load_string($xml);
  130. $tmp=$data->data->content;
  131. for($i = 0; $i < count($tmp); $i++) {
  132. $kb=array();
  133. $kb['id']=$tmp[$i]->id;
  134. $kb['name']=$tmp[$i]->name;
  135. $kb['description']=$tmp[$i]->description;
  136. $kb['answer']=$tmp[$i]->answer;
  137. $kb['preview1']=$tmp[$i]->smallpreviewpic1;
  138. $kb['detailpage']=$tmp[$i]->detailpage;
  139. $kbe[]=$kb;
  140. }
  141. $total=$data->meta->totalitems;
  142. $kbe['totalitems']=$total;
  143. return $kbe;
  144. }
  145. }