コード例 #1
0
ファイル: api.php プロジェクト: netconstructor/forkcms
 /**
  * Get the comments
  *
  * @return	array						An array with the comments
  * @param	string[optional] $status	The type of comments to get. Possible values are: published, moderation, spam.
  * @param	int[optional] $limit		The maximum number of items to retrieve.
  * @param	int[optional] $offset		The offset.
  */
 public static function commentsGet($status = null, $limit = 30, $offset = 0)
 {
     // authorize
     if (API::authorize()) {
         // redefine
         if ($status !== null) {
             $status = (string) $status;
         }
         $limit = (int) $limit;
         $offset = (int) $offset;
         // validate
         if ($limit > 10000) {
             API::output(API::ERROR, array('message' => 'Limit can\'t be larger then 10000.'));
         }
         // get comments
         $comments = (array) BackendBlogModel::getAllCommentsForStatus($status, $limit, $offset);
         // init var
         $return = array('comments' => null);
         // build return array
         foreach ($comments as $row) {
             // create array
             $item['comment'] = array();
             // article meta data
             $item['comment']['article']['@attributes']['id'] = $row['post_id'];
             $item['comment']['article']['@attributes']['lang'] = $row['post_language'];
             $item['comment']['article']['title'] = $row['post_title'];
             $item['comment']['article']['url'] = SITE_URL . BackendModel::getURLForBlock('blog', 'detail', $row['post_language']) . '/' . $row['post_url'];
             // set attributes
             $item['comment']['@attributes']['id'] = $row['id'];
             $item['comment']['@attributes']['created_on'] = date('c', $row['created_on']);
             $item['comment']['@attributes']['status'] = $row['status'];
             // set content
             $item['comment']['text'] = $row['text'];
             $item['comment']['url'] = $item['comment']['article']['url'] . '#comment-' . $row['id'];
             // author data
             $item['comment']['author']['@attributes']['email'] = $row['email'];
             $item['comment']['author']['name'] = $row['author'];
             $item['comment']['author']['website'] = $row['website'];
             // add
             $return['comments'][] = $item;
         }
         // return
         return $return;
     }
 }