LightPressPlugin($frontend, $args, $dummy_run); if (!$dummy_run) { $this->_db =& $frontend->db; $this->_usertable =& $frontend->tables['users']; $this->_wpcookie = 'wordpressuser_' . md5($frontend->options['wp_url']); } } function hide() { $this->_frontend->tpl->setVar('PLUGIN_ADMINOPTIONS', ''); $this->_frontend->tpl->setVar('PLUGIN_ADMINOPTIONS_EDITPOST', ''); $this->_frontend->tpl->setVar('PLUGIN_ADMINOPTIONS_EDITCOMMENT', ''); } function &getUserData(&$userlogin) { $userdata =& $this->_userdata; if (isset($userdata[$userlogin]['login'])) return $userdata[$userlogin]; // otherwise load the user's data $qry = "SELECT user_login AS login, user_nickname AS nickname, user_level AS level FROM {$this->_usertable} WHERE user_login = '$userlogin'"; if ($this->_db->query($qry) > 0) { $userdata[$userlogin] =& $this->_db->next(); return $userdata[$userlogin]; } } function run($hook, &$post) { if (! $this->active) return; $tpl =& $this->_frontend->tpl; $context =& $this->_frontend->context; if (isset($_COOKIE[$this->_wpcookie])) $user =& $this->getUserData($_COOKIE[$this->_wpcookie]); else $user = false; if (!$user) { // not logged in, show login template, blank out edit templates and disable plugin $tpl->setFile('adminoptions_login', 'plugins/adminoptions_login.xml'); $tpl->parse('PLUGIN_ADMINOPTIONS', 'adminoptions_login'); $tpl->setVar('PLUGIN_ADMINOPTIONS_EDITPOST', ''); $tpl->setVar('PLUGIN_ADMINOPTIONS_EDITCOMMENT', ''); $this->active = false; return; } switch ($hook) { case 'parse_post': // handle post edit links if ($this->_frontend->local_context & (LP_CONTEXT_POST | LP_CONTEXT_STATIC)) { // save post author for comments hook later $this->_post_author = $post['post_author_login']; // check if user can edit this post // (technically users can edit posts of lower level users, but the author's level isn't readily available here...) if (($user['level'] == 10) || (($user['level'] > 1) && ($user['login'] == $post['post_author_login']))) { // edit post link $tpl->setFile('adminoptions_editpost', 'plugins/adminoptions_editpost.xml'); $tpl->setVar('post_id', $post['post_id']); $tpl->parse('PLUGIN_ADMINOPTIONS_EDITPOST', 'adminoptions_editpost'); return; } } // hide template for this post $tpl->setVar('PLUGIN_ADMINOPTIONS_EDITPOST', ''); break; case 'parse_comment': // handle comment edit links if ($this->_frontend->local_context & (LP_CONTEXT_POST | LP_CONTEXT_STATIC)) { // check if user can edit this comment (WordPress allows any user that can edit the post to edit its comments) if (($user['level'] == 10) || ($this->_post_author && ($user['level'] > 1) && ($user['login'] == $this->_post_author))) { // edit comment link $tpl->setFile('adminoptions_editcomment', 'plugins/adminoptions_editcomment.xml'); $tpl->setVar('comment_ID', $post['comment_ID']); $tpl->parse('PLUGIN_ADMINOPTIONS_EDITCOMMENT', 'adminoptions_editcomment'); return; } } // hide template for this comment $tpl->setVar('PLUGIN_ADMINOPTIONS_EDITCOMMENT', ''); break; case 'post_render': // login/logout/admin block $tpl->setFile('adminoptions_login', 'plugins/adminoptions_admin.xml'); $tpl->parse('PLUGIN_ADMINOPTIONS', 'adminoptions_login'); break; } } } ?>