public function comment($title, $content, User $user) { $key = camel2under(get_called_class()); $info = compact('user', 'title', 'content'); $info[$key] = $this; $c = Comment::create($info); $this->update(array('touched=NOW()' => null)); return $c; }
/** * @author ryan <*****@*****.**> */ function comment_action($type, $id) { if (!$GLOBALS['has_login']) { return; } $title = _post('title'); $content = _post('content'); if ($title && $content) { $user = $GLOBALS['user']; $o = new $type($id); $o->comment($title, $content, $user); } $t = camel2under($type); redirect("{$t}/{$id}"); }
/** * @author ryan <*****@*****.**> */ function attitude($type) { if (!$GLOBALS['has_login']) { return; } $class = camel2under($type); $map = array('like' => 1, 'hate' => 0); $target = _req('target'); $action = _req('action'); $info = array($type => $target, 'user' => $GLOBALS['user'], '`like`' => $map[$action]); $at = Attitude::create($info); if ($at) { $info = array('user' => $GLOBALS['user'], 'action' => $action, 'object' => $target); $act = Activity::create($info); // inform author $comment = new $class($target); $info = array('user' => $comment->user, 'activity' => $act); Timeline::create($info); } $o = new $class($target); echo $o->{$action . 'Count'}(); }
public function __call($name, $args) { if (empty($this->info)) { $this->info = $this->info(); } $prop = camel2under($name); if (isset($this->info[$prop])) { $class = ucfirst($name); return new $class($this->info[$prop]); } else { throw new Exception("no {$prop} when call {$name}", 1); } }