function play($stage_id) { $stage = $this->dbUtil->get(new Stage(), new C(Q::eq(Stage::columnId(), $stage_id))); if (!Variable::istype('Stage', $stage)) { $this->_notFound(); return $this->parser(); } $this->setVariable('object', $stage); if ($this->isPost()) { // add comment $this->setVariable('stage_id', $stage->id); if ($this->dbUtil->insert($this->toObject(new Comment()))) { Header::redirect(Rhaco::url('play/' . $stage->id)); } } $stage_file_name = Rhaco::path(sprintf('stages/%d.apif', $stage->id)); $stage_data = unserialize(file_get_contents($stage_file_name)); foreach ($stage_data as &$v) { if (preg_match('/^images.*?gif$/', $v['value'])) { $v['value'] = Rhaco::url($v['value']); } } $this->setVariable('stage_data', $stage_data); $this->setVariable('comments', $this->dbUtil->select(new Comment(), new C(Q::eq(Comment::columnStageId(), $stage->id)))); return $this->parser('play.html'); }