fixes for xml requests
This commit is contained in:
parent
5f3030c089
commit
14229e7a84
@ -153,7 +153,7 @@ class ForumController extends ApplicationController
|
||||
} else {
|
||||
$this->forum_posts = ForumPost::where("parent_id IS NULL")->order("is_sticky desc, updated_at DESC")->paginate($this->page_number(), 30);
|
||||
}
|
||||
|
||||
|
||||
$this->respond_to_list("forum_posts");
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,6 @@ class TagController extends ApplicationController
|
||||
{
|
||||
$this->set_title('Tags');
|
||||
|
||||
# TODO: convert to nagato
|
||||
if ($this->params()->limit === "0")
|
||||
$limit = null;
|
||||
elseif (!$this->params()->limit)
|
||||
@ -105,21 +104,17 @@ class TagController extends ApplicationController
|
||||
'html' => function () use ($order, $query) {
|
||||
$this->can_delete_tags = CONFIG()->enable_tag_deletion && current_user()->is_mod_or_higher();
|
||||
$this->tags = $query->paginate($this->page_number(), 50);
|
||||
// vpe($this->tags);
|
||||
// $this->tags = Tag::paginate(array('order' => $order, 'per_page' => 50, 'conditions' => array_merge(array(implode(' AND ', $conds)), $cond_params), 'page' => $this->page_number()));
|
||||
},
|
||||
'xml' => function () use ($order, $limit, $query) {
|
||||
if (!$this->params()->order)
|
||||
$order = 'id DESC';
|
||||
$conds = implode(" AND ", $conds);
|
||||
if ($conds == "true" && CONFIG()->web_server == "nginx" && file_exists(Rails::publicPath()."/tags.xml")) {
|
||||
# Special case: instead of rebuilding a list of every tag every time, cache it locally and tell the web
|
||||
# server to stream it directly. This only works on Nginx.
|
||||
$this->response()->headers()->add("X-Accel-Redirect", Rails::publicPath() . "/tags.xml");
|
||||
$this->render(array('nothing' => true));
|
||||
} else {
|
||||
// $conds = implode(" AND ", $conds);
|
||||
// if ($conds == "true" && CONFIG()->web_server == "nginx" && file_exists(Rails::publicPath()."/tags.xml")) {
|
||||
// # Special case: instead of rebuilding a list of every tag every time, cache it locally and tell the web
|
||||
// # server to stream it directly. This only works on Nginx.
|
||||
// $this->response()->headers()->add("X-Accel-Redirect", Rails::publicPath() . "/tags.xml");
|
||||
// $this->render(array('nothing' => true));
|
||||
// } else {
|
||||
$this->render(array('xml' => $query->limit($limit)->take(), 'root' => "tags"));
|
||||
}
|
||||
// }
|
||||
},
|
||||
'json' => function ($s) use ($order, $limit, $query) {
|
||||
$tags = $query->limit($limit)->take();
|
||||
|
@ -121,7 +121,9 @@ class ForumPost extends Rails\ActiveRecord\Base
|
||||
'creator_id' => $this->creator_id,
|
||||
'id' => $this->id,
|
||||
'parent_id' => $this->parent_id,
|
||||
'title' => $this->title
|
||||
'title' => $this->title,
|
||||
'updated_at' => $this->updated_at,
|
||||
'pages' => ceil((!$this->response_count ? 1 : $this->response_count) / 30)
|
||||
];
|
||||
}
|
||||
|
||||
@ -132,7 +134,7 @@ class ForumPost extends Rails\ActiveRecord\Base
|
||||
|
||||
public function toXml(array $options = [])
|
||||
{
|
||||
return parent::toXml($this->api_attributes, ['root' => "forum_post"]);
|
||||
return parent::toXml(array_merge($options, ['root' => "forum-post", 'attributes' => $this->api_attributes()]));
|
||||
}
|
||||
|
||||
/* } */
|
||||
|
@ -200,18 +200,15 @@ class Pool extends Rails\ActiveRecord\Base
|
||||
return $this->api_attributes();
|
||||
}
|
||||
|
||||
# iTODO:
|
||||
// public function to_xml(array $options = [])
|
||||
// {
|
||||
// empty($options['indent']) && $options['indent'] = 2;
|
||||
// empty($options['indent']) && $options['indent'] = 2; // ???
|
||||
// $xml = isset($options['builder']) ? $options['builder'] : new Rails_Builder_XmlMarkup(['indent' => $options['indent']]);
|
||||
// # $xml = options['builder'] ||= Builder::XmlMarkup.new('indent' => options['indent']);
|
||||
// $xml->pool($api_attributes, function() {
|
||||
// $xml->description($this->description);
|
||||
// yield options['builder'] if $this->block_given()
|
||||
// })
|
||||
// }
|
||||
public function toXml(array $options = [])
|
||||
{
|
||||
/*empty($options['indent']) && $options['indent'] = 2;*/
|
||||
$xml = isset($options['builder']) ? $options['builder'] : new Rails\ActionView\Xml(/*['indent' => $options['indent']]*/);
|
||||
$xml->pool($this->api_attributes(), function() use ($xml) {
|
||||
$xml->description($this->description);
|
||||
});
|
||||
return $xml->output();
|
||||
}
|
||||
|
||||
/* } NameMethods { */
|
||||
|
||||
|
@ -109,7 +109,7 @@ class WikiPage extends Rails\ActiveRecord\Base
|
||||
|
||||
public function toXml(array $options = [])
|
||||
{
|
||||
return parent::toXml(array_merge($options, ['root' => 'wiki_page']), ['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'title' => $this->title, 'body' => $this->body, 'updater_id' => $this->user_id, 'locked' => $this->is_locked, 'version' => $this->version]);
|
||||
return parent::toXml(array_merge($options, ['root' => 'wiki_page', 'attributes' => ['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'title' => $this->title, 'body' => $this->body, 'updater_id' => $this->user_id, 'locked' => (bool)(int)$this->is_locked, 'version' => $this->version]]));
|
||||
}
|
||||
|
||||
public function asJson()
|
||||
|
Reference in New Issue
Block a user