Exemple #1
0
 public function add(array $item)
 {
     if (isset($item['wp:post_type']) && $item['wp:post_type'] != 'post') {
         return false;
     }
     $post = tpost::i();
     foreach ($this->tagsmap as $key => $val) {
         if (isset($item[$key])) {
             $post->{$val} = $item[$key];
         }
     }
     if (!$this->ignorelink && isset($item['link'])) {
         $post->link = $item['link'];
     }
     if (isset($item['wp:status'])) {
         $post->status = $item['wp:status'] == 'publish' ? 'published' : 'draft';
     }
     if (isset($item['wp:comment_status'])) {
         $post->commentsenabled = $item['wp:comment_status'] == 'open';
     }
     if (isset($item['wp:ping_status'])) {
         $post->pingenabled = $item['wp:ping_status'] == 'open';
     }
     if (isset($item['category'])) {
         $post->categories = $this->getcategories($item['category'], 'category');
         $post->tags = $this->getcategories($item['category'], 'tag');
     }
     if ($this->script != '') {
         eval($this->script);
     }
     return $post;
 }
Exemple #2
0
 private function findsame($idpost)
 {
     $posts = tposts::i();
     $post = tpost::i($idpost);
     if (count($post->categories) == 0) {
         return array();
     }
     $cats = tcategories::i();
     $cats->loadall();
     $same = array();
     foreach ($post->categories as $idcat) {
         if (!isset($cats->items[$idcat])) {
             continue;
         }
         $itemsposts = $cats->itemsposts->getposts($idcat);
         $itemsposts = $posts->stripdrafts($itemsposts);
         foreach ($itemsposts as $id) {
             if ($id == $idpost) {
                 continue;
             }
             $same[$id] = isset($same[$id]) ? $same[$id] + 1 : 1;
         }
     }
     arsort($same);
     return array_slice(array_keys($same), 0, $this->maxcount);
 }
 public function getlink($id)
 {
     $item = $this->getitem($id);
     $word = $item['word'];
     if (isset($this->links[$word])) {
         return $this->links[$word];
     }
     $items = $this->itemsposts->getposts($id);
     $c = count($items);
     if ($c == 0) {
         $result = sprintf('<span class="wikiword">%s</span>', $word);
     } elseif ($c == 1) {
         $post = tpost::i($items[0]);
         $result = sprintf('<a href="%1$s#wikiword-%3$d" title="%2$s">%2$s</a>', $post->link, $word, $id);
     } else {
         $links = array();
         $posts = tposts::i();
         $posts->loaditems($items);
         foreach ($items as $idpost) {
             $post = tpost::i($idpost);
             $links[] = sprintf('<a href="%1$s#wikiword-%3$d" title="%2$s">%2$s</a>', $post->link, $post->title, $id);
         }
         $result = sprintf('<span class="wikiword">%s</span> (%s)', $word, implode(', ', $links));
     }
     $this->links[$word] = $result;
     return $result;
 }
 public function sendpost($id)
 {
     if ($this->host == '' || $this->login == '') {
         return false;
     }
     $post = tpost::i($id);
     ttheme::$vars['post'] = $post;
     $theme = ttheme::i();
     $content = $theme->parse($this->template);
     $date = getdate($post->posted);
     if ($post->status != 'published') {
         return;
     }
     $meta = $post->meta;
     $client = new IXR_Client($this->host, '/interface/xmlrpc');
     //$client = new IXR_Client($this->host, '/rpc.xml');
     if (!$client->query('LJ.XMLRPC.getchallenge')) {
         if (litepublisher::$debug) {
             tfiler::log('live journal: error challenge');
         }
         return false;
     }
     $response = $client->getResponse();
     $challenge = $response['challenge'];
     $args = array('username' => $this->login, 'auth_method' => 'challenge', 'auth_challenge' => $challenge, 'auth_response' => md5($challenge . md5($this->password)), 'ver' => "1", 'event' => $content, 'subject' => $post->title, 'year' => $date['year'], 'mon' => $date['mon'], 'day' => $date['mday'], 'hour' => $date['hours'], 'min' => $date['minutes'], 'props' => array('opt_nocomments' => !$post->commentsenabled, 'opt_preformatted' => true, 'taglist' => $post->tagnames));
     switch ($this->privacy) {
         case "public":
             $args['security'] = "public";
             break;
         case "private":
             $args['security'] = "private";
             break;
         case "friends":
             $args['security'] = "usemask";
             $args['allowmask'] = 1;
     }
     if ($this->community != '') {
         $args['usejournal'] = $this->community;
     }
     if (isset($meta->ljid)) {
         $method = 'LJ.XMLRPC.editevent';
         $args['itemid'] = $meta->ljid;
     } else {
         $method = 'LJ.XMLRPC.postevent';
     }
     if (!$client->query($method, $args)) {
         if (litepublisher::$debug) {
             tfiler::log('Something went wrong - ' . $client->getErrorCode() . ' : ' . $client->getErrorMessage());
         }
         return false;
     }
     if (!isset($meta->ljid)) {
         $response = $client->getResponse();
         $meta->ljid = $response['itemid'];
     }
     return $meta->ljid;
 }
 public function postadded($idpost)
 {
     $post = tpost::i($idpost);
     if ($post->author <= 1) {
         return;
     }
     $useroptions = tuseroptions::i();
     if ('enabled' == $useroptions->getvalue($post->author, 'authorpost_subscribe')) {
         $this->add($idpost, $post->author);
     }
 }
 public function beforepost($id, &$content)
 {
     $post = tpost::i($id);
     if (count($post->files) > 0) {
         $theme = $post->theme;
         $image = $theme->templates['content.post.filelist.image'];
         $theme->templates['content.post.filelist.image'] = str_replace('href="$link"', 'href="$post.link#!prettyPhoto[gallery-$post.id]/$typeindex/"', $image);
         $content .= $post->filelist;
         $theme->templates['content.post.filelist.image'] = $image;
     }
 }
 public function addfile($id)
 {
     $files = tfiles::i();
     $file = $files->getitem($id);
     $posts = $files->itemsposts->getposts($id);
     if (count($posts) == 0) {
         $postlink = litepublisher::$site->url . '/';
     } else {
         $post = tpost::i($posts[0]);
         $postlink = $post->link;
     }
     $item = $this->domrss->AddItem();
     tnode::addvalue($item, 'title', $file['title']);
     tnode::addvalue($item, 'link', $postlink);
     tnode::addvalue($item, 'pubDate', $file['posted']);
     $media = tnode::add($item, 'media:content');
     tnode::attr($media, 'url', $files->geturl($id));
     tnode::attr($media, 'fileSize', $file['size']);
     tnode::attr($media, 'type', $file['mime']);
     tnode::attr($media, 'medium', $file['media']);
     tnode::attr($media, 'expression', 'full');
     if ($file['width'] > 0 && $file['height'] > 0) {
         tnode::attr($media, 'height', $file['height']);
         tnode::attr($media, 'width', $file['width']);
     }
     /*
     if (!empty($file['bitrate'])) tnode::attr($media, 'bitrate', $file['bitrate']);
     if (!empty($file['framerate'])) tnode::attr($media, 'framerate', $file['framerate']);
     if (!empty($file['samplingrate'])) tnode::attr($media, 'samplingrate', $file['samplingrate']);
     if (!empty($file['channels'])) tnode::attr($media, 'channels', $file['channels']);
     if (!empty($file['duration'])) tnode::attr($media, 'duration', $file['duration']);
     */
     $hash = tnode::addvalue($item, 'media:hash', self::hashtomd5($file['hash']));
     tnode::attr($hash, 'algo', "md5");
     if (!empty($file['keywords'])) {
         tnode::addvalue($item, 'media:keywords', $file['keywords']);
     }
     if (!empty($file['description'])) {
         $description = tnode::addvalue($item, 'description', $file['description']);
         tnode::attr($description, 'type', 'html');
     }
     if ($file['preview'] > 0) {
         $idpreview = $file['preview'];
         $preview = $files->getitem($idpreview);
         $thumbnail = tnode::add($item, 'media:thumbnail');
         tnode::attr($thumbnail, 'url', $files->geturl($idpreview));
         if ($preview['width'] > 0 && $preview['height'] > 0) {
             tnode::attr($thumbnail, 'height', $preview['height']);
             tnode::attr($thumbnail, 'width', $preview['width']);
         }
     }
     $this->onitem($item, $file);
 }
 public function processform()
 {
     //  return dumpvar($_POST);
     extract($_POST, EXTR_SKIP);
     $posts = tposts::i();
     $this->basename = 'posts';
     $html = $this->html;
     if ($id == 0) {
         $forum = tforum::i();
         if (!$forum->moderate || litepublisher::$options->ingroup('editor')) {
             $status = 'published';
         } else {
             $status = 'draft';
             // if too many drafts then reject
             $hold = $posts->db->getcount('status = \'draft\' and author = ' . litepublisher::$options->user);
             if ($hold >= 3) {
                 return $html->manydrafts;
             }
         }
         if (empty($title)) {
             $lang = tlocal::i('editor');
             return $html->h4->emptytitle;
         }
     }
     $post = tpost::i((int) $id);
     $post->title = $title;
     $post->categories = array((int) $category);
     if ($post->author == 0) {
         $post->author = litepublisher::$options->user;
     }
     if (isset($files)) {
         $files = trim($files);
         $post->files = $files == '' ? array() : explode(',', $files);
     }
     $post->content = tcontentfilter::remove_scripts($raw);
     if ($id == 0) {
         $post->status = $status;
         $post->comstatus = $forum->comstatus;
         $post->idview = $forum->idview;
         $post->idperm = $forum->idperm;
         $post->url = tlinkgenerator::i()->addurl($post, 'forum');
         $id = $posts->add($post);
         $_GET['id'] = $id;
         $_POST['id'] = $id;
         $this->idpost = $id;
     } else {
         $posts->edit($post);
     }
     return $html->h4->successedit;
 }
 public function getdescription()
 {
     if ($list = $this->getlist()) {
         $result = '';
         foreach ($list as $id) {
             $post = tpost::i($id);
             $result .= $post->title . ' ';
             if (strlen($result) > 250) {
                 break;
             }
         }
         //return tcontentfilter::getexcerpt($result, 300);
         return $result;
     }
     return ttemplate::i()->getdescription();
 }
 private function sendmail($id)
 {
     $item = $this->getitem($id);
     $args = targs::i();
     $args->add($item);
     $args->id = $id;
     $status = dbversion ? $item['status'] : ($item['approved'] ? 'approved' : 'hold');
     $args->localstatus = tlocal::get('commentstatus', $status);
     $args->adminurl = litepublisher::$site->url . '/admin/comments/pingback/' . litepublisher::$site->q . "id={$id}&post={$item['post']}&action";
     $post = tpost::i($item['post']);
     $args->posttitle = $post->title;
     $args->postlink = $post->link;
     tlocal::usefile('mail');
     $lang = tlocal::i('mailcomments');
     $theme = ttheme::i();
     $subject = $theme->parsearg($lang->pingbacksubj, $args);
     $body = $theme->parsearg($lang->pingbackbody, $args);
     tmailer::sendmail(litepublisher::$site->name, litepublisher::$options->fromemail, 'admin', litepublisher::$options->email, $subject, $body);
 }
 public function beforecat(&$result)
 {
     $cats = $this->cats;
     $idcat = $cats->id;
     if (!$idcat) {
         return;
     }
     $result .= $this->getbread($idcat);
     if ($this->showsimilar) {
         $idposts = $cats->getidposts($idcat);
         $list = array();
         foreach ($idposts as $idpost) {
             $list = array_merge($list, tpost::i($idpost)->categories);
         }
         array_clean($list);
         array_delete_value($list, $idcat);
         $result .= $this->getsimilar($list);
     }
     return $result;
 }
 public function pingpost($id)
 {
     if (!isset($id)) {
         return;
     }
     $post = tpost::i((int) $id);
     if (!is_object($post)) {
         return;
     }
     if ($post->status != 'published') {
         return;
     }
     $posturl = $post->link;
     $meta = $post->meta;
     if (!isset($meta->lastpinged) || $meta->lastpinged + 3600 * 24 < time()) {
         $this->pingservices($posturl);
         $meta->lastpinged = time();
     }
     $pinged = isset($meta->pinged) ? unserialize($meta->pinged) : array();
     $links = $this->getlinks($post);
     $m = microtime(true);
     foreach ($links as $link) {
         if (in_array($link, $pinged)) {
             continue;
         }
         if (preg_match('/\\.(zip|gz|js|css|mp3|mp4|wav|mov|flv|avi|mpg|mpeg|jpg|jpeg|png|bmp|gif|ogv|webm|flac)$/i', $link)) {
             continue;
         }
         if (preg_match('/(youtu\\.be|youtube\\.com|facebook\\.com|twitter\\.com|vk\\.com|mail\\.ru|odnoklassniki\\.ru)/i', $link)) {
             continue;
         }
         $this->ping($link, $posturl);
         $pinged[] = $link;
         if (microtime(true) - $m > 120) {
             break;
         }
     }
     if (count($pinged)) {
         $meta->pinged = serialize($pinged);
     }
 }
 public function getcontent()
 {
     $result = parent::getcontent();
     $db = litepublisher::$db;
     $items = $db->res2items($db->query("select id, class from {$db->prefix}codedoc order by class"));
     if (count($items) == 0) {
         return $result;
     }
     tposts::i()->loaditems(array_keys($items));
     $theme = tview::getview($this)->theme;
     $args = new targs();
     $result .= '<ul class="doc_classes">';
     $tml = '<li id="doc-class-$id"><a href="#">$class</a> $post.excerptcontent</li>';
     foreach ($items as $id => $item) {
         $args->add($item);
         ttheme::$vars['post'] = tpost::i($id);
         $result .= $theme->parsearg($tml, $args);
     }
     $result .= '</ul>';
     return $result;
 }
 public function ping($from, $to)
 {
     if (!strbegin($to, litepublisher::$site->url)) {
         return new IXR_Error(0, 'Is there no link to us?');
     }
     $url = substr($to, strlen(litepublisher::$site->url));
     $urlmap = turlmap::i();
     if (!($item = $urlmap->finditem($url))) {
         return $this->xerror(0, 'Is there no link to us?');
     }
     if ($item['class'] != litepublisher::$classes->classes['post']) {
         return $this->xerror(33, 'The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.');
     }
     $post = tpost::i($item['arg']);
     if (!$post->pingenabled || $post->status != 'published') {
         return $this->xerror(33, 'The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.');
     }
     $pingbacks = $post->pingbacks;
     if ($pingbacks->exists($from)) {
         return new IXR_Error(48, 'The pingback has already been registered.');
     }
     if (!($s = http::get($from))) {
         return new IXR_Error(16, 'The source URL does not exist.');
     }
     $s = str_replace('<!DOC', '<DOC', $s);
     $s = preg_replace('/[\\s\\r\\n\\t]+/', ' ', $s);
     // normalize spaces
     if (!preg_match('|<title>([^<]*?)</title>|is', $s, $matchtitle) || empty($matchtitle[1])) {
         return new IXR_Error(32, 'We cannot find a title on that page.');
     }
     $s = strip_tags($s, '<a>');
     if (!preg_match("|<a([^>]+?" . preg_quote($to) . "[^>]*)>[^>]+?</a>|", $s, $match)) {
         return new IXR_Error(17, 'The source URL does not contain a link to the target URL, and so cannot be used as a source.');
     }
     if (preg_match('/nofollow|noindex/is', $match[1])) {
         return new IXR_Error(32, 'The source URL contain nofollow or noindex atribute');
     }
     $pingbacks->add($from, $matchtitle[1]);
     return "Pingback from {$from} to {$to} registered. Keep the web talking! :-)";
 }
 public function processform()
 {
     //dumpvar($_POST);
     $result = '';
     switch ($this->name) {
         case 'views':
             $views = tviews::i();
             $idview = (int) tadminhtml::getparam('idview', 0);
             if (!$idview || !$views->itemexists($idview)) {
                 return '';
             }
             if ($this->action == 'delete') {
                 if ($idview > 1) {
                     $views->delete($idview);
                 }
                 return '';
             }
             $view = tview::i($idview);
             if ($idview > 1) {
                 $view->customsidebar = isset($_POST['customsidebar']);
                 $view->disableajax = isset($_POST['disableajax']);
             }
             $view->name = trim($_POST['name']);
             $view->themename = trim($_POST['theme_idview']);
             $view->menuclass = $_POST['menu'];
             $view->hovermenu = isset($_POST['hovermenu']);
             $this->set_custom($idview);
             if ($idview == 1 || $view->customsidebar) {
                 $widgets = twidgets::i();
                 foreach (range(0, 2) as $index) {
                     $view->sidebars[$index] = array();
                     $idwidgets = explode(',', trim($_POST["sidebar{$index}"]));
                     foreach ($idwidgets as $idwidget) {
                         $idwidget = (int) trim($idwidget);
                         if (!$widgets->itemexists($idwidget)) {
                             continue;
                         }
                         $view->sidebars[$index][] = array('id' => $idwidget, 'ajax' => isset($_POST["inline{$idwidget}"]) ? 'inline' : isset($_POST["ajax{$idwidget}"]));
                     }
                 }
             }
             $view->save();
             break;
         case 'addview':
             $name = trim($_POST['name']);
             if ($name != '') {
                 $views = tviews::i();
                 $id = $views->add($name);
             }
             break;
         case 'spec':
             foreach (self::getspecclasses() as $classname) {
                 $obj = getinstance($classname);
                 $obj->lock();
                 $obj->setidview($_POST["idview-{$classname}"]);
                 if (isset($obj->data['keywords'])) {
                     $obj->keywords = $_POST["keywords-{$classname}"];
                 }
                 if (isset($obj->data['description '])) {
                     $obj->description = $_POST["description-{$classname}"];
                 }
                 if (isset($obj->data['head'])) {
                     $obj->head = $_POST["head-{$classname}"];
                 }
                 $obj->unlock();
             }
             break;
         case 'group':
             switch ($_POST['action']) {
                 case 'posts':
                     $posts = tposts::i();
                     $idview = (int) $_POST['postview'];
                     if (dbversion) {
                         $posts->db->update("idview = '{$idview}'", 'id > 0');
                     } else {
                         foreach ($posts->items as $id => $item) {
                             $post = tpost::i($id);
                             $post->idview = $idview;
                             $post->save();
                             $post->free();
                         }
                     }
                     break;
                 case 'menus':
                     $idview = (int) $_POST['menuview'];
                     $menus = tmenus::i();
                     foreach ($menus->items as $id => $item) {
                         $menu = tmenu::i($id);
                         $menu->idview = $idview;
                         $menu->save();
                     }
                     break;
                 case 'themes':
                     $themename = $_POST['themeview'];
                     $views = tviews::i();
                     $views->lock();
                     foreach ($views->items as $id => $item) {
                         $view = tview::i($id);
                         $view->themename = $themename;
                         $view->save();
                     }
                     $views->unlock();
                     break;
             }
             break;
         case 'defaults':
             $views = tviews::i();
             foreach ($views->defaults as $name => $id) {
                 $views->defaults[$name] = (int) $_POST[$name];
             }
             $views->save();
             break;
         case 'headers':
             $template = ttemplate::i();
             $template->heads = $_POST['heads'];
             $template->save();
             $adminmenus = tadminmenus::i();
             $adminmenus->heads = $_POST['adminheads'];
             $adminmenus->save();
             $ajax = tajaxposteditor::i();
             $ajax->lock();
             $ajax->ajaxvisual = isset($_POST['ajaxvisual']);
             $ajax->visual = trim($_POST['visual']);
             $ajax->unlock();
             litepublisher::$options->show_file_perm = isset($_POST['show_file_perm']);
             break;
         case 'admin':
             return $this->adminoptionsform->processform();
     }
     ttheme::clearcache();
 }
Exemple #16
0
 public function getpostswidgetcontent(array $items, $sidebar, $tml)
 {
     if (count($items) == 0) {
         return '';
     }
     $result = '';
     if ($tml == '') {
         $tml = $this->getwidgetitem('posts', $sidebar);
     }
     foreach ($items as $id) {
         self::$vars['post'] = tpost::i($id);
         $result .= $this->parse($tml);
     }
     unset(self::$vars['post']);
     return str_replace('$item', $result, $this->getwidgetitems('posts', $sidebar));
 }
 public function getcontent()
 {
     $theme = tview::i(tviews::i()->defaults['admin'])->theme;
     $html = tadminhtml::i();
     $html->section = 'editor';
     $lang = tlocal::i('editor');
     $post = tpost::i($this->idpost);
     ttheme::$vars['post'] = $post;
     switch ($_GET['get']) {
         case 'tags':
             $result = $html->getedit('tags', $post->tagnames, $lang->tags);
             $lang->section = 'editor';
             $result .= $html->h4->addtags;
             $items = array();
             $tags = $post->factory->tags;
             $list = $tags->getsorted(-1, 'name', 0);
             foreach ($list as $id) {
                 $items[] = '<a href="" class="posteditor-tag">' . $tags->items[$id]['title'] . "</a>";
             }
             $result .= sprintf('<p>%s</p>', implode(', ', $items));
             break;
         case 'status':
             $args = new targs();
             $args->comstatus = tadminhtml::array2combo(array('closed' => $lang->closed, 'reg' => $lang->reg, 'guest' => $lang->guest, 'comuser' => $lang->comuser), $post->comstatus);
             $args->pingenabled = $post->pingenabled;
             $args->status = tadminhtml::array2combo(array('published' => $lang->published, 'draft' => $lang->draft), $post->status);
             $args->perms = tadminperms::getcombo($post->idperm);
             $args->password = $post->password;
             $result = $html->parsearg('[combo=comstatus]
   [checkbox=pingenabled]
   [combo=status]
   $perms
   [password=password]
   <p>$lang.notepassword</p>', $args);
             break;
         case 'view':
             $result = $this->getviewicon($post->idview, $post->icon);
             break;
         default:
             $result = var_export($_GET, true);
     }
     //tfiler::log($result);
     return turlmap::htmlheader(false) . $result;
 }
 public function postedited($idpost)
 {
     $post = tpost::i($idpost);
     $this->itemsposts->setitems($idpost, $post->files);
 }
 public function add(array $item)
 {
     $post = tpost::i();
     foreach ($this->tagsmap as $key => $val) {
         if (isset($item[$key])) {
             $post->{$val} = $item[$key];
         }
     }
     if ($this->script != '') {
         eval($this->script);
     }
     return $post;
 }
 public function editPost($appkey, $id, $login, $password, $content, $publish)
 {
     $id = (int) $id;
     $this->canedit($login, $password, $id);
     $posts = tposts::i();
     if (!$posts->itemexists($id)) {
         return $this->xerror(404, 'Sorry, no such post.');
     }
     $post = tpost::i($id);
     $post->status = $publish ? 'published' : 'draft';
     $post->title = $this->getposttitle($content);
     $post->content = $this->removepostdata($content);
     $post->categories = $this->getpostcategory($content);
     $posts->edit($post);
     return true;
 }
 public function getmidle()
 {
     $result = '';
     $items = $this->getmidleposts();
     if (!count($items)) {
         return '';
     }
     ttheme::$vars['lang'] = tlocal::i('default');
     ttheme::$vars['home'] = $this;
     $theme = ttheme::i();
     $tml = $theme->templates['content.home.midle.post'];
     foreach ($items as $id) {
         ttheme::$vars['post'] = tpost::i($id);
         $result .= $theme->parse($tml);
         // has $author.* tags in tml
         if (isset(ttheme::$vars['author'])) {
             unset(ttheme::$vars['author']);
         }
     }
     $tml = $theme->templates['content.home.midle'];
     if ($tml) {
         $args = new targs();
         $args->post = $result;
         $args->midletitle = $this->midletitle;
         $result = $theme->parsearg($tml, $args);
     }
     unset(ttheme::$vars['post'], ttheme::$vars['home']);
     return $result;
 }
 public function processform()
 {
     $posts = tposts::i();
     $posts->lock();
     $status = isset($_POST['publish']) ? 'published' : (isset($_POST['setdraft']) ? 'draft' : 'delete');
     if ($this->isauthor && ($r = tauthor_rights::i()->changeposts($status))) {
         return $r;
     }
     $iduser = litepublisher::$options->user;
     foreach ($_POST as $key => $id) {
         if (!is_numeric($id)) {
             continue;
         }
         $id = (int) $id;
         if ($status == 'delete') {
             if ($this->isauthor && $iduser != $posts->db->getvalue('author')) {
                 continue;
             }
             $posts->delete($id);
         } else {
             $post = tpost::i($id);
             if ($this->isauthor && $iduser != $post->author) {
                 continue;
             }
             $post->status = $status;
             $posts->edit($post);
         }
     }
     $posts->unlock();
 }
 public static function canedit($email, $password, $idpost)
 {
     if (litepublisher::$options->auth($email, $password)) {
         if (litepublisher::$options->hasgroup('editor')) {
             return true;
         }
         if (litepublisher::$options->hasgroup('author')) {
             if ($idpost == 0) {
                 return true;
             }
             $post = tpost::i($idpost);
             return $post->author == litepublisher::$options->user;
         }
     }
     throw new Exception('Bad login/pass combination.', 403);
 }
 public function getpost($id)
 {
     return tpost::i($id);
 }
 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 wpnewComment($blog_id, $login, $password, $idpost, $struct)
 {
     $this->auth($login, $password, 'moderator');
     if (is_numeric($idpost)) {
         $idpost = absint($idpost);
     } else {
         $urlmap = turlmap::i();
         if (!($item = $urlmap->finditem($url))) {
             return $this->xerror(404, 'Invalid post ID.');
         }
         if ($item['class'] != litepublisher::$classes->classes['post']) {
             return $this->xerror(404, 'Invalid post ID.');
         }
         $idpost = $item['arg'];
     }
     $post = tpost::i($idpost);
     if (!$post->commentenabled || $post->status != 'published') {
         return $this->xerror(403, 'The specified post cannot be used to commenting');
     }
     $manager = tcommentmanager::i();
     return $manager->add($idpost, isset($struct['author']) ? $struct['author'] : '', isset($struct['author_email']) ? $struct['author_email'] : '', isset($struct['author_url']) ? $struct['author_url'] : '', $struct['content']);
 }
 public function getpermheader(array $shortpost)
 {
     $urlmap = litepublisher::$urlmap;
     $url = $urlmap->url;
     $saveitem = $urlmap->itemrequested;
     $urlmap->itemrequested = $urlmap->getitem($shortpost['idurl']);
     $urlmap->url = $urlmap->itemrequested['url'];
     $post = tpost::i((int) $shortpost['id']);
     $perm = tperm::i($post->idperm);
     // not restore values because perm will be used this values
     return $perm->getheader($post);
 }
 public function processform()
 {
     //dumpvar($_POST);
     $this->basename = 'editor';
     $html = $this->html;
     if (empty($_POST['title'])) {
         return $html->h2->emptytitle;
     }
     $id = (int) $_POST['id'];
     $post = tpost::i($id);
     if ($this->isauthor && ($r = tauthor_rights::i()->editpost($post))) {
         $this->idpost = $post->id;
         return $r;
     }
     $this->set_post($post);
     $posts = tposts::i();
     if ($id == 0) {
         $this->idpost = $posts->add($post);
         $_POST['id'] = $this->idpost;
     } else {
         $posts->edit($post);
     }
     $_GET['id'] = $this->idpost;
     return sprintf($html->p->success, $post->bookmark);
 }
 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 getposttitle()
 {
     $post = tpost::i($this->post);
     return $post->title;
 }