Skip to content

Commit

Permalink
fixes for xml requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Parziphal committed Oct 27, 2013
1 parent 5f3030c commit 14229e7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/controllers/ForumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function index()
} 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");
}

Expand Down
21 changes: 8 additions & 13 deletions app/controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function index()
{
$this->set_title('Tags');

# TODO: convert to nagato
if ($this->params()->limit === "0")
$limit = null;
elseif (!$this->params()->limit)
Expand Down Expand Up @@ -105,21 +104,17 @@ public function index()
'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();
Expand Down
6 changes: 4 additions & 2 deletions app/models/ForumPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public function api_attributes()
'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)
];
}

Expand All @@ -132,7 +134,7 @@ public function asJson(array $params = [])

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()]));
}

/* } */
Expand Down
21 changes: 9 additions & 12 deletions app/models/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,15 @@ public function asJson(array $params = [])
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 { */

Expand Down
2 changes: 1 addition & 1 deletion app/models/WikiPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function rename($new_title)

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()
Expand Down

0 comments on commit 14229e7

Please sign in to comment.