/** * Save changes made in Post editing */ function savePostChanges() { Doo::loadHelper('DooValidator'); $_POST['content'] = trim($_POST['content']); //get defined rules and add show some error messages $validator = new DooValidator(); $validator->checkMode = DooValidator::CHECK_SKIP; if ($error = $validator->validate($_POST, 'post_edit.rules')) { $data['rootUrl'] = Doo::conf()->APP_URL; $data['title'] = 'Error Occured!'; $data['content'] = '<p style="color:#ff0000;">' . $error . '</p>'; $data['content'] .= '<p>Go <a href="javascript:history.back();">back</a> to edit.</p>'; $this->render('admin_msg', $data); } else { Doo::loadModel('Post'); Doo::loadModel('Tag'); $p = new Post($_POST); //delete the previous linked tags first Doo::loadModel('PostTag'); $pt = new PostTag(); $pt->post_id = $p->id; $pt->delete(); //update the post along with the tags if (self::$tags != Null) { $tags = array(); foreach (self::$tags as $t) { $tg = new Tag(); $tg->name = $t; $tags[] = $tg; } $p->relatedUpdate($tags); } else { $p->update(); } //clear the sidebar cache Doo::cache('front')->flushAllParts(); $data['rootUrl'] = Doo::conf()->APP_URL; $data['title'] = 'Post Updated!'; $data['content'] = '<p>Your changes is saved successfully.</p>'; $data['content'] .= '<p>Click <a href="' . $data['rootUrl'] . 'article/' . $p->id . '">here</a> to view the post.</p>'; $this->render('admin_msg', $data); } }