/** * Lite Publisher * Copyright (C) 2010 - 2015 Vladimir Yushko http://litepublisher.ru/ http://litepublisher.com/ * Dual licensed under the MIT (mit.txt) * and GPL (gpl.txt) licenses. **/ function tcommentmanagerInstall($self) { $self->data['filterstatus'] = true; $self->data['checkduplicate'] = true; $self->data['defstatus'] = 'approved'; $self->data['sendnotification'] = true; $self->data['trustlevel'] = 2; $self->data['hidelink'] = false; $self->data['redir'] = true; $self->data['nofollow'] = false; $self->data['canedit'] = true; $self->data['candelete'] = true; $self->data['confirmlogged'] = false; $self->data['confirmguest'] = true; $self->data['confirmcomuser'] = true; $self->data['confirmemail'] = false; $self->data['comuser_subscribe'] = true; $self->data['idguest'] = 0; //create user in installer after create users table $groups = litepublisher::$options->groupnames; $self->data['idgroups'] = array($groups['admin'], $groups['editor'], $groups['moderator'], $groups['author'], $groups['commentator']); $self->save(); $comments = tcomments::i(); $comments->lock(); $comments->changed = $self->changed; $comments->added = $self->sendmail; $comments->unlock(); litepublisher::$urlmap->addget('/comusers.htm', get_class($self)); trobotstxt::i()->AddDisallow('/comusers.htm'); }
function trssUninstall($self) { turlmap::unsub($self); tcomments::i()->unbind($self); $meta = tmetawidget::i(); $meta->lock(); $meta->delete('rss'); $meta->delete('comments'); $meta->unlock(); }
private function deleteauthor($uid) { $users = tusers::i(); if (!$users->itemexists($uid)) { return false; } if ('comuser' != $users->getvalue($uid, 'status')) { return false; } $comments = tcomments::i(); $comments->db->delete("author = {$uid}"); $users->setvalue($uid, 'status', 'hold'); return true; }
public function processform(array $values, $confirmed) { $lang = tlocal::i('comment'); if (trim($values['content']) == '') { return $this->geterrorcontent($lang->emptycontent); } if (!$this->checkspam(isset($values['antispam']) ? $values['antispam'] : '')) { return $this->geterrorcontent($lang->spamdetected); } $shortpost = $this->getshortpost(isset($values['postid']) ? (int) $values['postid'] : 0); if ($err = $this->invalidate($shortpost)) { return $err; } if ((int) $shortpost['idperm']) { $post = tpost::i((int) $shortpost['id']); $perm = tperm::i($post->idperm); if (!$perm->hasperm($post)) { return 403; } } $cm = tcommentmanager::i(); if ($cm->checkduplicate && $cm->is_duplicate($shortpost['id'], $values['content'])) { return $this->geterrorcontent($lang->duplicate); } unset($values['submitbutton']); if (!$confirmed) { $values['ip'] = preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']); } if (litepublisher::$options->ingroups($cm->idgroups)) { if (!$confirmed && $cm->confirmlogged) { return $this->request_confirm($values, $shortpost); } $iduser = litepublisher::$options->user; } else { switch ($shortpost['comstatus']) { case 'reg': return $this->geterrorcontent($lang->reg); case 'guest': if (!$confirmed && $cm->confirmguest) { return $this->request_confirm($values, $shortpost); } $iduser = $cm->idguest; break; case 'comuser': //hook in regservices social plugin if ($r = $this->oncomuser($values, $confirmed)) { return $r; } if (!$confirmed && $cm->confirmcomuser) { return $this->request_confirm($values, $shortpost); } if ($err = $this->processcomuser($values)) { return $err; } $users = tusers::i(); if ($iduser = $users->emailexists($values['email'])) { if ('comuser' != $users->getvalue($iduser, 'status')) { return $this->geterrorcontent($lang->emailregistered); } } else { $iduser = $cm->addcomuser($values['name'], $values['email'], $values['url'], $values['ip']); } $cookies = array(); foreach (array('name', 'email', 'url') as $field) { $cookies["comuser_{$field}"] = $values[$field]; } break; } } $user = tusers::i()->getitem($iduser); if ('hold' == $user['status']) { return $this->geterrorcontent($lang->holduser); } if (!$cm->canadd($iduser)) { return $this->geterrorcontent($lang->toomany); } if (!$cm->add($shortpost['id'], $iduser, $values['content'], $values['ip'])) { return $this->geterrorcontent($lang->spamdetected); } //subscribe by email switch ($user['status']) { case 'approved': if ($user['email'] != '') { // subscribe if its first comment if (1 == tcomments::i()->db->getcount("post = {$shortpost['id']} and author = {$iduser}")) { if ('enabled' == tuseroptions::i()->getvalue($iduser, 'subscribe')) { tsubscribers::i()->update($shortpost['id'], $iduser, true); } } } break; case 'comuser': if ('comuser' == $shortpost['comstatus'] && $cm->comuser_subscribe) { tsubscribers::i()->update($shortpost['id'], $iduser, $values['subscribe']); } break; } //$post->lastcommenturl; $shortpost['commentscount']++; if (!litepublisher::$options->commentpages || $shortpost['commentscount'] <= litepublisher::$options->commentsperpage) { $c = 1; } else { $c = ceil($shortpost['commentscount'] / litepublisher::$options->commentsperpage); } $url = litepublisher::$urlmap->getvalue($shortpost['idurl'], 'url'); if ($c > 1 && !litepublisher::$options->comments_invert_order) { $url = rtrim($url, '/') . "/page/{$c}/"; } litepublisher::$urlmap->setexpired($shortpost['idurl']); return $this->sendresult(litepublisher::$site->url . $url, isset($cookies) ? $cookies : array()); }
function ExportComments(tpost $post) { global $wpdb; $comments = tcomments::i($post->id); $comments->lock(); $comusers = tcomusers::i($post->id); $comusers->lock(); $items = $wpdb->get_results("SELECT * FROM {$wpdb->comments} \r\n WHERE comment_post_ID = {$post->id}"); foreach ($items as $item) { $date = strtotime(mysql2date('Ymd\\TH:i:s', $item->comment_date)); $status = $item->comment_approved == '1' ? 'approved' : 'hold'; if ($item->comment_type != '') { addpingback($post->id, $item->comment_author, $item->comment_author_url, $item->comment_author_IP, $date, $status); continue; } $author = $comusers->add($item->comment_author, $item->comment_author_email, $item->comment_author_url, $item->comment_author_IP); $cid = $comments->add($author, $item->comment_content, $status, $item->comment_author_IP); if (dbversion) { $comments->db->setvalue($cid, 'posted', sqldate(min(time(), $date))); } else { $comments->items[$cid]['posted'] = $date; } } $comusers->unlock(); $comments->unlock(); if (dbversion) { $count = $comments->db->getcount("post = {$post->id} and status = 'approved'"); $comments->getdb('posts')->setvalue($post->id, 'commentscount', $count); $count = $comments->getdb('pingbacks')->getcount("post = {$post->id} and status = 'approved'"); $comments->getdb('posts')->setvalue($post->id, 'pingbackscount', $count); } }
private function importcomments(array $items, $idpost) { $comments = tcomments::i($idpost); $comments->lock(); $comusers = tcomusers::i($idpost); $comusers->lock(); foreach ($items as $item) { $status = $item['wp:comment_approved'] == '1' ? 'approved' : 'hold'; $posted = strtotime($item['wp:comment_date']); if ($item['wp:comment_type'] == 'pingback') { $pingbacks = tpingbacks::i($idpost); $pingbacks->import($item['wp:comment_author_url'], $item['wp:comment_author'], $posted, $item['wp:comment_author_IP'], $status); continue; } $idauthor = $comusers->add($item['wp:comment_author'], $item['wp:comment_author_email'], $item['wp:comment_author_url']); $comments->add($idpost, $idauthor, $item['wp:comment_content'], $item['wp:comment_author_IP'], $status, $posted); } $comusers->unlock(); $comments->unlock(); }
public function wpeditComment($blog_id, $login, $password, $id, $struct) { $this->auth($login, $password, 'moderator'); $id = (int) $id; $comments = tcomments::i(); if (!$comments->itemexists($id)) { return $this->xerror(404, 'Invalid comment ID.'); } $comment = $comment->getcomment($id); if (isset($struct['status'])) { if (!preg_match('/^hold|approve|spam$/', $struct['status'])) { return $this->xerror(401, 'Invalid comment status.'); } $comment->status = $struct['status'] == 'approve' ? 'approved' : $struct['status']; } $comusers = tcomusers::i(); $comment->author = $comusers->add(isset($struct['author']) ? $struct['author'] : $comment->name, isset($struct['author_email']) ? $struct['author_email'] : $comment->email, isset($struct['author_url']) ? $struct['author_url'] : $comment->url); if (!empty($struct['date_created_gmt'])) { $comment->posted = $struct['date_created_gmt']->getTimestamp(); } if (isset($struct['content'])) { $comment->rawcontent = $struct['content']; } $comment->save(); return true; }
public function getip() { if (isset($this->data['ip'])) { return $this->data['ip']; } $comments = tcomments::i($this->post); return $comments->raw->getvalue($this->id, 'ip'); }
public function getcomments($idpost) { $result = ''; $idpost = (int) $idpost; $post = tpost::i($idpost); $comments = tcomments::i($idpost); $lang = tlocal::i('comment'); $list = $comments->getcontent(); $theme = $post->theme; $args = new targs(); $args->count = $post->cmtcount; $result .= $theme->parsearg($theme->templates['content.post.templatecomments.comments.count'], $args); $result .= $list; if (litepublisher::$urlmap->page == 1 && $post->pingbackscount > 0) { $pingbacks = tpingbacks::i($post->id); $result .= $pingbacks->getcontent(); } if (!litepublisher::$options->commentsdisabled && $post->comstatus != 'closed') { $args->postid = $post->id; $args->antispam = base64_encode('superspamer' . strtotime("+1 hour")); $cm = tcommentmanager::i(); $result .= sprintf('<?php if (litepublisher::$options->ingroups(array(%s))) {', implode(',', $cm->idgroups)); //add hold list because we need container when comment will be hold $result .= 'if ($ismoder = litepublisher::$options->ingroup(\'moderator\')) { ?>'; $args->comment = ''; $result .= $theme->parsearg($theme->templates['content.post.templatecomments.holdcomments'], $args); $result .= $this->loadhold; $result .= '<?php } ?>'; $mesg = $this->logged; if ($cm->canedit || $cm->candelete) { $mesg .= "\n" . $this->adminpanel; } $args->mesg = $this->fixmesg($mesg, $theme); $result .= $theme->parsearg($theme->templates['content.post.templatecomments.regform'], $args); $result .= $this->getjs($post->idperm == 0 && $cm->confirmlogged, 'logged'); $result .= '<?php } else { ?>'; switch ($post->comstatus) { case 'reg': $mesg = $this->reqlogin; if (litepublisher::$options->reguser) { $mesg .= "\n" . $this->regaccount; } $args->mesg = $this->fixmesg($mesg, $theme); $result .= $theme->parsearg($theme->templates['content.post.templatecomments.regform'], $args); break; case 'guest': $result .= $this->getjs($post->idperm == 0 && $cm->confirmguest, 'guest'); $mesg = $this->guest; if (litepublisher::$options->reguser) { $mesg .= "\n" . $this->regaccount; } $args->mesg = $this->fixmesg($mesg, $theme); $result .= $theme->parsearg($theme->templates['content.post.templatecomments.regform'], $args); break; case 'comuser': $result .= $this->getjs($post->idperm == 0 && $cm->confirmcomuser, 'comuser'); $mesg = $this->comuser; if (litepublisher::$options->reguser) { $mesg .= "\n" . $this->regaccount; } $args->mesg = $this->fixmesg($mesg, $theme); foreach (array('name', 'email', 'url') as $field) { $args->{$field} = "<?php echo (isset(\$_COOKIE['comuser_{$field}']) ? \$_COOKIE['comuser_{$field}'] : ''); ?>"; } $args->subscribe = false; $args->content = ''; $result .= $theme->parsearg($theme->templates['content.post.templatecomments.form'], $args); break; } $result .= '<?php } ?>'; } else { $result .= $theme->parse($theme->templates['content.post.templatecomments.closed']); } return $result; }
public function getcomments($id) { return tcomments::i($id); }
public function is_duplicate($idpost, $content) { $comments = tcomments::i($idpost); $content = trim($content); $hash = basemd5($content); return $comments->raw->findid("hash = '{$hash}'"); }
public function CreateFirstPost() { $html = tadminhtml::i(); $html->section = 'installation'; $lang = tlocal::i(); $theme = ttheme::i(); $post = tpost::i(0); $post->title = $lang->posttitle; $post->catnames = $lang->postcategories; $post->tagnames = $lang->posttags; $post->content = $theme->parse($lang->postcontent); $posts = tposts::i(); $posts->add($post); $icons = ticons::i(); $cats = tcategories::i(); $cats->setvalue($post->categories[0], 'icon', $icons->getid('news')); $cm = tcommentmanager::i(); $users = tusers::i(); $cm->idguest = $users->add(array('email' => '', 'name' => tlocal::get('default', 'guest'), 'status' => 'hold', 'idgroups' => 'commentator')); $cm->save(); $users->setvalue($cm->idguest, 'status', 'approved'); tcomments::i()->add($post->id, $cm->idguest, $lang->postcomment, 'approved', '127.0.0.1'); $plugins = tplugins::i(); $plugins->lock(); $plugins->add('oldestposts'); //$plugins->add('adminlinks'); //$plugins->add('nicedit'); $plugins->unlock(); }
function migratecomments($idpost) { global $data, $users; if (!$data->loadfile('posts' . DIRECTORY_SEPARATOR . $idpost . DIRECTORY_SEPARATOR . 'comments')) { return; } if (!isset($data->data['items'])) { var_dump($idpost, $data->data); exit; } if (!isset($users)) { $users = new tmigratedata(); $users->loadfile('commentusers'); } $comments = tcomments::instance($idpost); $comments->lock(); $comusers = tcomusers::instance($idpost); $comusers->lock(); foreach ($data->data['items'] as $id => $item) { $user = $users->data['items'][$item['uid']]; if ($item['type'] == '') { $author = $comusers->add($user['name'], $user['email'], $user['url'], ''); $cid = $comments->add($author, $item['rawcontent'], $item['status'], ''); if (dbversion) { $comments->db->setvalue($cid, 'posted', sqldate(min(time(), $item['date']))); $comusers->db->setvalue($author, 'cookie', newmd5($user['cookie'])); } else { $comments->items[$cid]['posted'] = $item['date']; $comusers->items[$author]['cookie'] = newmd5($user['cookie']); } } else { addpingback($idpost, $item, $user); } } $comusers->unlock(); $comments->unlock(); if (dbversion) { $count = $comments->db->getcount("post = {$idpost} and status = 'approved'"); $comments->getdb('posts')->setvalue($idpost, 'commentscount', $count); $count = $comments->getdb('pingbacks')->getcount("post = {$idpost} and status = 'approved'"); $comments->getdb('posts')->setvalue($idpost, 'pingbackscount', $count); } }
function tsubscribersUninstall($self) { tcomments::i()->unbind($self); tusers::i()->unbind($self); tposts::i()->unbind($self); }
function trssholdcommentsUninstall($self) { turlmap::unsub($self); tcomments::i()->unbind($self); }
public function GetRSSPostComments($idpost) { $post = tpost::i($idpost); $lang = tlocal::i('comment'); $title = $lang->from . ' '; $this->domrss->CreateRoot($post->rsscomments, "{$lang->onpost} {$post->title}"); $comments = tcomments::i($idpost); $comtable = $comments->thistable; $comment = new tarray2prop(); $recent = $comments->select("{$comtable}.post = {$idpost} and {$comtable}.status = 'approved'", "order by {$comtable}.posted desc limit " . litepublisher::$options->perpage); foreach ($recent as $id) { $comment->array = $comments->getitem($id); $comment->posturl = $post->url; $comment->title = $post->title; $this->AddRSSComment($comment, $title . $comment->name); } }
function tcommentswidgetUninstall($self) { tcomments::i()->unbind($self); }
public function comments_get_hold(array $args) { if (!litepublisher::$options->user) { return $this->forbidden(); } $idpost = (int) $args['idpost']; $comments = tcomments::i($idpost); if (litepublisher::$options->ingroup('moderator')) { $where = ''; } else { $where = "and {$comments->thistable}.author = " . litepublisher::$options->user; } return array('items' => $comments->getcontentwhere('hold', $where)); }
public function processform() { $result = ''; parent::processform(); $comments = tcomments::i(); if (isset($_REQUEST['action'])) { switch ($_REQUEST['action']) { case 'reply': if (!$this->moder) { return $this->html->h4->forbidden; } $item = $comments->getitem($this->idget()); $post = tpost::i((int) $item['post']); $this->manager->reply($this->idget(), $_POST['content']); return litepublisher::$urlmap->redir($post->lastcommenturl); case 'edit': if (!$this->can($id, 'edit')) { return $this->html->h4->forbidden; } $comments->edit($this->idget(), $_POST['content']); return $this->html->h4->successmoderated; } } $status = isset($_POST['approve']) ? 'approved' : (isset($_POST['hold']) ? 'hold' : 'delete'); foreach ($_POST as $key => $id) { if (!is_numeric($id)) { continue; } if (!strbegin($key, 'checkbox-item-')) { continue; } $id = (int) $id; if ($status == 'delete') { if ($this->can($id, 'delete')) { $comments->delete($id); } } else { if ($this->moder) { $comments->setstatus($id, $status); } } } return $this->html->h4->successmoderated; }
public function cronsendmail($id) { $comments = tcomments::i(); try { $item = $comments->getitem($id); } catch (Exception $e) { return; } $subscribers = $this->getitems($item['post']); if (!$subscribers || count($subscribers) == 0) { return; } $comment = $comments->getcomment($id); ttheme::$vars['comment'] = $comment; tlocal::usefile('mail'); $lang = tlocal::i('mailcomments'); $theme = ttheme::i(); $args = new targs(); $subject = $theme->parsearg($lang->subscribesubj, $args); $body = $theme->parsearg($lang->subscribebody, $args); $body .= "\n"; $adminurl = litepublisher::$site->url . '/admin/subscribers/'; $users = tusers::i(); $users->loaditems($subscribers); $list = array(); foreach ($subscribers as $uid) { $user = $users->getitem($uid); if ($user['status'] == 'hold') { continue; } $email = $user['email']; if (empty($email)) { continue; } if ($email == $comment->email) { continue; } if (in_array($email, $this->blacklist)) { continue; } $admin = $adminurl; if ('comuser' == $user['status']) { $admin .= litepublisher::$site->q . 'auth='; if (empty($user['cookie'])) { $user['cookie'] = md5uniq(); $users->setvalue($user['id'], 'cookie', $user['cookie']); } $admin .= rawurlencode($user['cookie']); } $list[] = array('fromname' => litepublisher::$site->name, 'fromemail' => $this->fromemail, 'toname' => $user['name'], 'toemail' => $email, 'subject' => $subject, 'body' => $body . $admin); } if (count($list)) { tmailer::sendlist($list); } }