|
From: <zy...@us...> - 2013-05-14 02:42:55
|
Revision: 11540
http://sourceforge.net/p/xoops/svn/11540
Author: zyspec
Date: 2013-05-14 02:42:51 +0000 (Tue, 14 May 2013)
Log Message:
-----------
Incomplete - task : xoopspoll 'extras' files not included in initial branch creation
Added Paths:
-----------
XoopsModules/xoopspoll/branches/zyspec/extras/
XoopsModules/xoopspoll/branches/zyspec/extras/index.html
XoopsModules/xoopspoll/branches/zyspec/extras/marquee/
XoopsModules/xoopspoll/branches/zyspec/extras/marquee/plugins/
XoopsModules/xoopspoll/branches/zyspec/extras/marquee/plugins/xoopspoll.php
XoopsModules/xoopspoll/branches/zyspec/extras/marquee/readme.txt
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/index.html
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/class/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/class/post.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/class/userlanguage.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/language/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/language/english/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/language/english/main.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/polls.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/templates/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/templates/css/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/templates/css/language/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/templates/css/language/english/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/templates/css/language/english/style.css
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/templates/css/language/persian/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/templates/css/language/persian/style.css
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/templates/newbb_poll_results.html
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/templates/newbb_poll_view.html
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/templates/newbb_viewtopic.html
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/topicmanager.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/viewtopic.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/votepolls.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/readme.txt
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/class/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/class/post.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/language/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/language/main.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/polls.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/templates/
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/templates/newbb_poll_results.html
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/templates/newbb_poll_view.html
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/topicmanager.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/viewtopic.php
XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/trunk_4_00/votepolls.php
XoopsModules/xoopspoll/branches/zyspec/extras/smartclone/
XoopsModules/xoopspoll/branches/zyspec/extras/smartclone/plugins/
XoopsModules/xoopspoll/branches/zyspec/extras/smartclone/plugins/xoopspoll.php
XoopsModules/xoopspoll/branches/zyspec/extras/smartclone/readme.txt
Added: XoopsModules/xoopspoll/branches/zyspec/extras/index.html
===================================================================
--- XoopsModules/xoopspoll/branches/zyspec/extras/index.html (rev 0)
+++ XoopsModules/xoopspoll/branches/zyspec/extras/index.html 2013-05-14 02:42:51 UTC (rev 11540)
@@ -0,0 +1 @@
+ <script>history.go(-1);</script>
\ No newline at end of file
Added: XoopsModules/xoopspoll/branches/zyspec/extras/marquee/plugins/xoopspoll.php
===================================================================
--- XoopsModules/xoopspoll/branches/zyspec/extras/marquee/plugins/xoopspoll.php (rev 0)
+++ XoopsModules/xoopspoll/branches/zyspec/extras/marquee/plugins/xoopspoll.php 2013-05-14 02:42:51 UTC (rev 11540)
@@ -0,0 +1,58 @@
+<?php
+/**
+ * ****************************************************************************
+ * Marquee - MODULE FOR XOOPS
+ * Copyright (c) Herv\xE9 Thouzard (http://www.herve-thouzard.com)
+ *
+ * You may not change or alter any portion of this comment or credits
+ * of supporting developers from this source code or any supporting source code
+ * which is considered copyrighted (c) material of the original comment or credit authors.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * ****************************************************************************
+ *
+ * @copyright:: {@link http://www.herve-thouzard.com Herv\xE9 Thouzard}
+ * @license:: {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
+ * @author:: Herv\xE9 Thouzard (http://www.herve-thouzard.com)
+ * @package:: marquee
+ * @subpackage:: plugins
+ * @version:: $Id: $
+ */
+/**
+ * Script to list the recent polls from the xoopspoll module version 1.40
+ */
+function b_marquee_xoopspoll($limit, $dateformat, $itemssize)
+{
+ include_once $GLOBALS['xoops']->path('modules'
+ . DIRECTORY_SEPARATOR . 'marquee'
+ . DIRECTORY_SEPARATOR . 'include'
+ . DIRECTORY_SEPARATOR . 'functions.php'
+ );
+ $block = array();
+ $myts =& MyTextSanitizer::getInstance();
+ $poll_handler =& xoops_getmodulehandler('poll', 'xoopspoll');
+ $criteria = new CriteriaCompo();
+ $criteria->add (new Criteria('start_time', time(), '<='));
+ $criteria->add (new Criteria('end_time', time(), '>'));
+ $criteria->setLimit(intval($limit));
+ $criteria->setSort('start_time');
+ $criteria->setOrder('DESC');
+ $pollFields = array('poll_id', 'question', 'start_time', 'user_id');
+ $pollObjs = $poll_handler->getAll($criteria, $pollFields);
+ foreach($pollObjs as $pollObj) {
+ $pollValues = $pollObj->getValues();
+ $title = $myts->htmlSpecialChars($pollValues['question']);
+ if (intval($itemssize) > 0) {
+ $title = xoops_substr($title, 0, $itemssize+3);
+ }
+ $xuStartTimestamp = xoops_getUserTimestamp($pollValues['start_time']);
+ $block[]=array( 'date' => formatTimestamp($xuStartTimestamp, $dateformat),
+ 'category' => '',
+ 'author' => $pollValues['user_id'],
+ 'title' => $title,
+ 'link' => "<a href='" . $GLOBALS['xoops']->url('modules/xoopspoll/index.php') . "?poll_id={$pollValues['poll_id']}'>{$title}</a>");
+ unset ($pollValues);
+ }
+ return $block;
+}
\ No newline at end of file
Added: XoopsModules/xoopspoll/branches/zyspec/extras/marquee/readme.txt
===================================================================
--- XoopsModules/xoopspoll/branches/zyspec/extras/marquee/readme.txt (rev 0)
+++ XoopsModules/xoopspoll/branches/zyspec/extras/marquee/readme.txt 2013-05-14 02:42:51 UTC (rev 11540)
@@ -0,0 +1,6 @@
+Marquee Usage
+=============
+
+Copy the ./xoopspoll/extras/marquee/plugins/xoopspoll.php to the
+./marquee/plugins folder to enable xoopspoll support within the XOOPS Marquee
+module.
\ No newline at end of file
Added: XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/index.html
===================================================================
--- XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/index.html (rev 0)
+++ XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/index.html 2013-05-14 02:42:51 UTC (rev 11540)
@@ -0,0 +1 @@
+ <script>history.go(-1);</script>
\ No newline at end of file
Added: XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/class/post.php
===================================================================
--- XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/class/post.php (rev 0)
+++ XoopsModules/xoopspoll/branches/zyspec/extras/newbb_4x/irmtfan/class/post.php 2013-05-14 02:42:51 UTC (rev 11540)
@@ -0,0 +1,1091 @@
+<?php
+// $Id: post.php,v 1.3 2005/10/19 17:20:32 phppp Exp $
+// ------------------------------------------------------------------------ //
+// XOOPS - PHP Content Management System //
+// Copyright (c) 2000 XOOPS.org //
+// <http://www.xoops.org/> //
+// ------------------------------------------------------------------------ //
+// This program is free software; you can redistribute it and/or modify //
+// it under the terms of the GNU General Public License as published by //
+// the Free Software Foundation; either version 2 of the License, or //
+// (at your option) any later version. //
+// //
+// You may not change or alter any portion of this comment or credits //
+// of supporting developers from this source code or any supporting //
+// source code which is considered copyrighted (c) material of the //
+// original comment or credit authors. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program; if not, write to the Free Software //
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
+// ------------------------------------------------------------------------ //
+// Author: phppp (D.J., in...@gm...) //
+// URL: http://xoopsforge.com, http://xoops.org.cn //
+// Project: Article Project //
+// ------------------------------------------------------------------------ //
+
+if (!defined("XOOPS_ROOT_PATH")) {
+ exit("Restricted Access");
+}
+
+defined("NEWBB_FUNCTIONS_INI") || include XOOPS_ROOT_PATH.'/modules/newbb/include/functions.ini.php';
+newbb_load_object();
+
+class Post extends ArtObject {
+//class Post extends XoopsObject {
+ var $attachment_array = array();
+
+ function Post()
+ {
+ $this->ArtObject("bb_posts");
+ //$this->XoopsObject();
+ $this->initVar('post_id', XOBJ_DTYPE_INT);
+ $this->initVar('topic_id', XOBJ_DTYPE_INT, 0, true);
+ $this->initVar('forum_id', XOBJ_DTYPE_INT, 0, true);
+ $this->initVar('post_time', XOBJ_DTYPE_INT, 0, true);
+ $this->initVar('poster_ip', XOBJ_DTYPE_INT, 0);
+ $this->initVar('poster_name', XOBJ_DTYPE_TXTBOX, "");
+ $this->initVar('subject', XOBJ_DTYPE_TXTBOX, "", true);
+ $this->initVar('pid', XOBJ_DTYPE_INT, 0);
+ $this->initVar('dohtml', XOBJ_DTYPE_INT, 0);
+ $this->initVar('dosmiley', XOBJ_DTYPE_INT, 1);
+ $this->initVar('doxcode', XOBJ_DTYPE_INT, 1);
+ $this->initVar('doimage', XOBJ_DTYPE_INT, 1);
+ $this->initVar('dobr', XOBJ_DTYPE_INT, 1);
+ $this->initVar('uid', XOBJ_DTYPE_INT, 1);
+ $this->initVar('icon', XOBJ_DTYPE_TXTBOX, "");
+ $this->initVar('attachsig', XOBJ_DTYPE_INT, 0);
+ $this->initVar('approved', XOBJ_DTYPE_INT, 1);
+ $this->initVar('post_karma', XOBJ_DTYPE_INT, 0);
+ $this->initVar('require_reply', XOBJ_DTYPE_INT, 0);
+ $this->initVar('attachment', XOBJ_DTYPE_TXTAREA, "");
+ $this->initVar('post_text', XOBJ_DTYPE_TXTAREA, "");
+ $this->initVar('post_edit', XOBJ_DTYPE_TXTAREA, "");
+ }
+
+ // ////////////////////////////////////////////////////////////////////////////////////
+ // attachment functions TODO: there should be a file/attachment management class
+ function getAttachment()
+ {
+ if (count($this->attachment_array)) return $this->attachment_array;
+ $attachment = $this->getVar('attachment');
+ if (empty($attachment)) $this->attachment_array = null;
+ else $this->attachment_array = @unserialize(base64_decode($attachment));
+ return $this->attachment_array;
+ }
+
+ function incrementDownload($attach_key)
+ {
+ if (!$attach_key) return false;
+ $this->attachment_array[strval($attach_key)]['num_download'] ++;
+ return $this->attachment_array[strval($attach_key)]['num_download'];
+ }
+
+ function saveAttachment()
+ {
+ if (is_array($this->attachment_array) && count($this->attachment_array) > 0)
+ $attachment_save = base64_encode(serialize($this->attachment_array));
+ else $attachment_save = '';
+ $this->setVar('attachment', $attachment_save);
+ $sql = "UPDATE " . $GLOBALS["xoopsDB"]->prefix("bb_posts") . " SET attachment=" . $GLOBALS["xoopsDB"]->quoteString($attachment_save) . " WHERE post_id = " . $this->getVar('post_id');
+ if (!$result = $GLOBALS["xoopsDB"]->queryF($sql)) {
+ //xoops_error($GLOBALS["xoopsDB"]->error());
+ return false;
+ }
+ return true;
+ }
+
+ function deleteAttachment($attach_array = null)
+ {
+ $attach_old = $this->getAttachment();
+ if (!is_array($attach_old) || count($attach_old) < 1) return true;
+ $this->attachment_array = array();
+
+ if ($attach_array === null) $attach_array = array_keys($attach_old); // to delete all!
+ if (!is_array($attach_array)) $attach_array = array($attach_array);
+
+ foreach ($attach_old as $key => $attach) {
+ if (in_array($key, $attach_array)) {
+ @unlink(XOOPS_ROOT_PATH . '/' . $GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attach['name_saved']);
+ @unlink(XOOPS_ROOT_PATH . '/' . $GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/thumbs/' . $attach['name_saved']); // delete thumbnails
+ continue;
+ }
+ $this->attachment_array[$key] = $attach;
+ }
+ if (is_array($this->attachment_array) && count($this->attachment_array) > 0)
+ $attachment_save = base64_encode(serialize($this->attachment_array));
+ else $attachment_save = '';
+ $this->setVar('attachment', $attachment_save);
+ return true;
+ }
+
+ function setAttachment($name_saved = '', $name_display = '', $mimetype = '', $num_download = 0)
+ {
+ static $counter=0;
+ $this->attachment_array = $this->getAttachment();
+ if ($name_saved) {
+ $key = strval(time()+$counter++);
+ $this->attachment_array[$key] = array('name_saved' => $name_saved,
+ 'name_display' => isset($name_display)?$name_display:$name_saved,
+ 'mimetype' => $mimetype,
+ 'num_download' => isset($num_download)?intval($num_download):0
+ );
+ }
+ if (is_array($this->attachment_array)) {
+ $attachment_save = base64_encode(serialize($this->attachment_array));
+ } else {
+ $attachment_save = null;
+ }
+ $this->setVar('attachment', $attachment_save);
+ return true;
+ }
+
+ /**
+ * TODO: refactor
+ */
+ function displayAttachment($asSource = false)
+ {
+ $post_attachment = '';
+ $attachments = $this->getAttachment();
+ if (is_array($attachments) && count($attachments) > 0) {
+ $icon_handler = newbb_getIconHandler();
+ $mime_path = $icon_handler->getPath("mime");
+ include_once $GLOBALS['xoops']->path("modules/" . $GLOBALS['xoopsModule']->getVar("dirname", "n") . "/include/functions.image.php");
+ $image_extensions = array("jpg", "jpeg", "gif", "png", "bmp"); // need improve !!!
+ $post_attachment .= '<br /><strong>' . _MD_ATTACHMENT . '</strong>:';
+ $post_attachment .= "<div style='margin: 1em 0em; border-top: 1px solid;'></div>\n";
+// $post_attachment .= '<br /><hr style="height: 1px;" noshade="noshade" /><br />';
+ foreach ($attachments as $key => $att) {
+ $file_extension = ltrim(strrchr($att['name_saved'], '.'), '.');
+ $filetype = $file_extension;
+ if (file_exists($GLOBALS['xoops']->path("{$mime_path}/{$filetype}.gif"))) {
+ $icon_filetype = $GLOBALS['xoops']->url("{$mime_path}/{$filetype}.gif");
+ } else {
+ $icon_filetype = $GLOBALS['xoops']->url("{$mime_path}/unknown.gif");
+ }
+ $file_size = @filesize($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $att['name_saved']));
+ $file_size = number_format ($file_size / 1024, 2)." KB";
+ if (in_array(strtolower($file_extension), $image_extensions) && $GLOBALS['xoopsModuleConfig']['media_allowed']) {
+ $post_attachment .= '<br /><img src="' . $icon_filetype . '" alt="' . $filetype . '" /><strong> ' . $att['name_display'] . '</strong> <small>('.$file_size.')</small>';
+ $post_attachment .= '<br />' . newbb_attachmentImage($att['name_saved']);
+ $isDisplayed = true;
+ } else {
+ if (empty($GLOBALS['xoopsModuleConfig']['show_userattach'])) {
+ $post_attachment .= "<a href='" . $GLOBALS['xoops']->url("/modules/" . $GLOBALS['xoopsModule']->getVar("dirname", "n") . "/dl_attachment.php?attachid={$key}&post_id=" . $this->getVar('post_id')) . "'> <img src='{$icon_filetype}' alt='{$filetype}' /> {$att['name_display']}</a> " . _MD_FILESIZE . ": {$file_size}; " . _MD_HITS . ": {$att['num_download']}";
+ } elseif ((($GLOBALS['xoopsUser'] instanceof XoopsUser) && $GLOBALS['xoopsUser']->uid() > 0 && $GLOBALS['xoopsUser']->isActive()) ) {
+ $post_attachment .= "<a href='" . $GLOBALS['xoops']->url("/modules/" . $GLOBALS['xoopsModule']->getVar("dirname", "n") . "/dl_attachment.php?attachid={$key}&post_id=" . $this->getVar('post_id')) . "'> <img src='" . $icon_filetype . "' alt='{$filetype}' /> {$att['name_display']}</a> " . _MD_FILESIZE . ": {$file_size}; " . _MD_HITS . ": {$att['num_download']}";
+ } else {
+ $post_attachment .= _MD_NEWBB_SEENOTGUEST;
+ }
+ }
+ $post_attachment .= '<br />';
+ }
+ }
+ return $post_attachment;
+ }
+ // attachment functions
+ // ////////////////////////////////////////////////////////////////////////////////////
+
+ function setPostEdit($poster_name = '',$post_editmsg='')
+ {
+ if ( empty($GLOBALS['xoopsModuleConfig']['recordedit_timelimit'])
+ || (time()-$this->getVar('post_time'))< $GLOBALS['xoopsModuleConfig']['recordedit_timelimit'] * 60
+ || $this->getVar('approved') < 1
+ ) {
+ return true;
+ }
+ if (($GLOBALS['xoopsUser'] instanceof XoopsUser) && $GLOBALS['xoopsUser']->isActive()) {
+ if ($GLOBALS['xoopsModuleConfig']['show_realname'] && $GLOBALS['xoopsUser']->getVar('name')) {
+ $edit_user = $GLOBALS['xoopsUser']->getVar('name');
+ } else {
+ $edit_user = $GLOBALS['xoopsUser']->getVar('uname');
+ }
+ }
+ $post_edit = array();
+ $post_edit['edit_user'] = $edit_user; // The proper way is to store uid instead of name. However, to save queries when displaying, the current way is ok.
+ $post_edit['edit_time'] = time();
+ $post_edit['edit_msg'] = $post_editmsg;
+
+ $post_edits = $this->getVar('post_edit');
+ if (!empty($post_edits)) $post_edits = unserialize(base64_decode($post_edits));
+ if (!is_array($post_edits)) $post_edits = array();
+ $post_edits[] = $post_edit;
+ $post_edit = base64_encode(serialize($post_edits));
+ unset($post_edits);
+ $this->setVar('post_edit', $post_edit);
+ return true;
+ }
+
+ function displayPostEdit()
+ {
+ global $myts;
+
+ if ( empty($GLOBALS['xoopsModuleConfig']['recordedit_timelimit']) ) return false;
+
+ $post_edit = '';
+ $post_edits = $this->getVar('post_edit');
+ if (!empty($post_edits)) $post_edits = unserialize(base64_decode($post_edits));
+ if (!isset($post_edits) || !is_array($post_edits)) $post_edits = array();
+ if (is_array($post_edits) && count($post_edits) > 0) {
+ foreach ($post_edits as $postedit) {
+ $edit_time = intval($postedit['edit_time']);
+ $edit_user = $myts->stripSlashesGPC($postedit['edit_user']);
+ $edit_msg = (!empty($postedit['edit_msg'])) ? $myts->stripSlashesGPC($postedit['edit_msg']) : '';
+ // Start irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred)
+ if ( empty($GLOBALS['xoopsModuleConfig']['do_latestedit']) ) {
+ $post_edit = '';
+ }
+ // End irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred)
+ // START hacked by irmtfan
+ // display/save all edit records.
+ $post_edit .= _MD_EDITEDBY . " " . $edit_user . " " . _MD_ON . " " . newbb_formatTimestamp(intval($edit_time))."<br />";
+ // if reason is not empty
+ if ($edit_msg != "") {
+ $post_edit .= _MD_EDITEDMSG . " " .$edit_msg."<br />";
+ }
+ // START hacked by irmtfan
+ }
+ }
+ return $post_edit;
+ }
+
+
+ function &getPostBody()
+ {
+ global $myts;
+ $GLOBALS['xoopsModuleConfig'] = newbb_load_config(); // irmtfan load all newbb configs - newbb config in blocks activated in some modules like profile
+ mod_loadFunctions("user", "newbb");
+ mod_loadFunctions("render", "newbb");
+
+ $uid = ($GLOBALS['xoopsUser'] instanceof XoopsUser)? $GLOBALS['xoopsUser']->getVar('uid') : 0;
+ $karma_handler =& xoops_getmodulehandler('karma', 'newbb');
+ $user_karma = $karma_handler->getUserKarma();
+
+
+ $post = array();
+ $post['attachment'] = false;
+ $post_text = newbb_displayTarea($this->vars['post_text']['value'], $this->getVar('dohtml'), $this->getVar('dosmiley'), $this->getVar('doxcode'), $this->getVar('doimage'), $this->getVar('dobr'));
+ if (newbb_isAdmin($this->getVar('forum_id')) or $this->checkIdentity()) {
+ $post['text'] = $post_text. '<br />' .$this->displayAttachment();
+ } elseif ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $this->getVar('post_karma') > $user_karma) {
+ $post['text'] = sprintf(_MD_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma'));
+ } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $this->getVar('require_reply') && (!$uid || !isset($viewtopic_users[$uid]))) {
+ $post['text'] = _MD_REPLY_REQUIREMENT;
+ } else {
+ $post['text'] = $post_text. '<br />' .$this->displayAttachment();
+ }
+ $member_handler =& xoops_gethandler('member');
+ $eachposter =& $member_handler->getUser($this->getVar('uid'));
+ if (is_object($eachposter) && $eachposter->isActive()) {
+ if ($GLOBALS['xoopsModuleConfig']['show_realname'] && $eachposter->getVar('name')) {
+ $post['author'] = $eachposter->getVar('name');
+ } else {
+ $post['author'] = $eachposter->getVar('uname');
+ }
+ unset($eachposter);
+ } else {
+ $post['author'] = $this->getVar('poster_name')?$this->getVar('poster_name'):$GLOBALS['xoopsConfig']['anonymous'];
+ }
+
+ $post['subject'] = newbb_htmlSpecialChars($this->vars['subject']['value']);
+ $post['date'] = $this->getVar('post_time');
+ return $post;
+ }
+
+ function isTopic()
+ {
+ return !$this->getVar('pid');
+ }
+
+ function checkTimelimit($action_tag = 'edit_timelimit')
+ {
+ $newbb_config = newbb_load_config();
+ if (empty($newbb_config["edit_timelimit"])) {
+ return true;
+ }
+ return ($this->getVar('post_time') > time() - $newbb_config[$action_tag] * 60);
+ }
+
+ function checkIdentity($uid = -1)
+ {
+ $uid = ($uid > -1) ? $uid : (($GLOBALS['xoopsUser'] instanceof XoopsUser)? $GLOBALS['xoopsUser']->getVar('uid') : 0);
+ if ($this->getVar('uid') > 0) {
+ $user_ok = ($uid == $this->getVar('uid')) ? true : false;
+ } else {
+ static $user_ip;
+ if (!isset($user_ip)) {
+ $user_ip = XoopsUserUtility::getIP();
+ }
+ $user_ok = ($user_ip == $this->getVar('poster_ip')) ? true : false;
+ }
+ return $user_ok;
+ }
+
+ // TODO: cleaning up and merge with post hanldings in viewpost.php
+ function showPost($isadmin)
+ {
+ global $myts;
+ global $forumUrl, $forumImage;
+ global $viewtopic_users, $viewtopic_posters, $forum_obj, $topic_obj, $online, $user_karma, $viewmode, $order, $start, $total_posts, $topic_status;
+ static $post_NO = 0;
+ static $name_anonymous;
+
+ if (!isset($name_anonymous)) {
+ $name_anonymous = $myts->htmlSpecialChars($GLOBALS["xoopsConfig"]['anonymous']);
+ }
+
+ mod_loadFunctions("time", "newbb");
+ mod_loadFunctions("render", "newbb");
+ mod_loadFunctions("text", "newbb"); // irmtfan add text functions
+
+ $post_id = $this->getVar('post_id');
+ $topic_id = $this->getVar('topic_id');
+ $forum_id = $this->getVar('forum_id');
+
+ $query_vars = array("status", "order", "start", "mode", "viewmode");
+ $query_array = array();
+ $query_array["topic_id"] = "topic_id={$topic_id}";
+ foreach ($query_vars as $var) {
+ if (!empty($_GET[$var])) {
+ $query_array[$var] = "{$var}={$_GET[$var]}";
+ }
+ }
+ $page_query = htmlspecialchars( implode("&", array_values($query_array)) );
+
+ $uid = ($GLOBALS['xoopsUser'] instanceof XoopsUser) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
+
+ $post_NO++;
+ if (strtolower($order) == "desc") {
+ $post_no = $total_posts - ($start + $post_NO) + 1;
+ } else {
+ $post_no = $start + $post_NO;
+ }
+
+ if ($isadmin || $this->checkIdentity()) {
+ $post_text = $this->getVar('post_text');
+ $post_attachment = $this->displayAttachment();
+ } elseif ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $this->getVar('post_karma') > $user_karma) {
+ $post_text = "<div class='karma'>" . sprintf(_MD_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')) . "</div>";
+ $post_attachment = '';
+ } elseif (
+ $GLOBALS['xoopsModuleConfig']['allow_require_reply']
+ && $this->getVar('require_reply')
+ && (
+ !$uid
+ || !in_array($uid, $viewtopic_posters)
+ )
+ ) {
+ $post_text = "<div class='karma'>" . _MD_REPLY_REQUIREMENT . "</div>\n";
+ $post_attachment = '';
+ } else {
+ $post_text = $this->getVar('post_text');
+ $post_attachment = $this->displayAttachment();
+ }
+ // START irmtfan add highlight feature
+ // Hightlighting searched words
+ $post_title = $this->getVar('subject');
+ if (isset($_GET['keywords']) && !empty($_GET['keywords'])) {
+ $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
+ $post_text = newbb_highlightText($post_text, $keywords);
+ $post_title = newbb_highlightText($post_title, $keywords);
+ }
+ // END irmtfan add highlight feature
+ if ( isset($viewtopic_users[$this->getVar('uid')]) ) {
+ $poster = $viewtopic_users[$this->getVar('uid')];
+ } else {
+ $name = ($post_name = $this->getVar('poster_name')) ? $post_name : $name_anonymous;
+ $poster = array(
+ 'poster_uid' => 0,
+ 'name' => $name,
+ 'link' => $name
+ );
+ }
+
+ if ($posticon = $this->getVar('icon')) {
+ $post_image = "<a name='{$post_id}'><img src='" . $GLOBALS['xoops']->url("images/subject/{$posticon}") . "' alt='' /></a>";
+ } else {
+ $post_image = "<a name='{$post_id}'><img src='" . $GLOBALS['xoops']->url("images/icons/posticon.gif") . "' alt='' /></a>";
+ }
+
+ $thread_buttons = array();
+ $mod_buttons = array();
+
+ if ($isadmin
+ && (($GLOBALS['xoopsUser'] instanceof XoopsUser)
+ && $GLOBALS['xoopsUser']->getVar('uid') != $this->getVar('uid'))
+ && ($this->getVar('uid') > 0))
+ {
+ $mod_buttons['bann']['image'] = newbb_displayImage('p_bann', _MD_SUSPEND_MANAGEMENT);
+ $mod_buttons['bann']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/moderate.php?forum={$forum_id}&fuid=" . $this->getVar('uid'));
+ $mod_buttons['bann']['name'] = _MD_SUSPEND_MANAGEMENT;
+ $thread_buttons['bann']['image'] = newbb_displayImage('p_bann', _MD_SUSPEND_MANAGEMENT);
+ $thread_buttons['bann']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/moderate.php?forum={$forum_id}&fuid=" . $this->getVar('uid'));
+ $thread_buttons['bann']['name'] = _MD_SUSPEND_MANAGEMENT;
+ }
+
+ if ($GLOBALS["xoopsModuleConfig"]['enable_permcheck']) {
+ $topic_handler = xoops_getmodulehandler('topic', 'newbb');
+ $topic_status = $topic_obj->getVar('topic_status');
+ if ($topic_handler->getPermission($forum_id, $topic_status, "edit")) {
+ $edit_ok = ( $isadmin || ($this->checkIdentity() && $this->checkTimelimit('edit_timelimit')) );
+ if ($edit_ok) {
+ $thread_buttons['edit']['image'] = newbb_displayImage('p_edit', _EDIT);
+ $thread_buttons['edit']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/edit.php?{$page_query}");
+ $thread_buttons['edit']['name'] = _EDIT;
+ $mod_buttons['edit']['image'] = newbb_displayImage('p_edit', _EDIT);
+ $mod_buttons['edit']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/edit.php?{$page_query}");
+ $mod_buttons['edit']['name'] = _EDIT;
+ }
+ }
+
+ if ($topic_handler->getPermission($forum_id, $topic_status, "delete")) {
+ $delete_ok = ( $isadmin || ($this->checkIdentity() && $this->checkTimelimit('delete_timelimit')) );
+
+ if ($delete_ok) {
+ $thread_buttons['delete']['image'] = newbb_displayImage('p_delete', _DELETE);
+ $thread_buttons['delete']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/delete.php?{$page_query}");
+ $thread_buttons['delete']['name'] = _DELETE;
+ $mod_buttons['delete']['image'] = newbb_displayImage('p_delete', _DELETE);
+ $mod_buttons['delete']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/delete.php?{$page_query}");
+ $mod_buttons['delete']['name'] = _DELETE;
+ }
+ }
+ if ($topic_handler->getPermission($forum_id, $topic_status, "reply")) {
+ $thread_buttons['reply']['image'] = newbb_displayImage('p_reply', _MD_REPLY);
+ $thread_buttons['reply']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/reply.php?{$page_query}");
+ $thread_buttons['reply']['name'] = _MD_REPLY;
+
+ $thread_buttons['quote']['image'] = newbb_displayImage('p_quote', _MD_QUOTE);
+ $thread_buttons['quote']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/reply.php?{$page_query}&quotedac=1");
+ $thread_buttons['quote']['name'] = _MD_QUOTE;
+ }
+
+ } else {
+
+ $mod_buttons['edit']['image'] = newbb_displayImage('p_edit', _EDIT);
+ $mod_buttons['edit']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/edit.php?{$page_query}");
+ $mod_buttons['edit']['name'] = _EDIT;
+
+ $mod_buttons['delete']['image'] = newbb_displayImage('p_delete', _DELETE);
+ $mod_buttons['delete']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/delete.php?{$page_query}");
+ $mod_buttons['delete']['name'] = _DELETE;
+
+ $thread_buttons['reply']['image'] = newbb_displayImage('p_reply', _MD_REPLY);
+ $thread_buttons['reply']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/reply.php?{$page_query}");
+ $thread_buttons['reply']['name'] = _MD_REPLY;
+
+ }
+
+ if (!$isadmin && $GLOBALS['xoopsModuleConfig']['reportmod_enabled']) {
+ $thread_buttons['report']['image'] = newbb_displayImage('p_report', _MD_REPORT);
+ $thread_buttons['report']['link'] = $GLOBALS['xoops']->url("modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/report.php?{$page_query}");
+ $thread_buttons['report']['name'] = _MD_REPORT;
+ }
+
+ $thread_action = array();
+ // irmtfan add pdf permission
+ if (file_exists($GLOBALS['xoops']->path("Frameworks/tcpdf/tcpdf.php")) && $topic_handler->getPermission($forum_id, $topic_status, "pdf") ) {
+ $thread_action['pdf']['image'] = newbb_displayImage('pdf', _MD_PDF);
+ $thread_action['pdf']['link'] = $GLOBALS['xoops']->url("modules/newbb/makepdf.php?type=post&pageid=0");
+ $thread_action['pdf']['name'] = _MD_PDF;
+ $thread_action['pdf']['target'] = '_blank';
+ }
+ // irmtfan add print permission
+ if ($topic_handler->getPermission($forum_id, $topic_status, "print") ) {
+ $thread_action['print']['image'] = newbb_displayImage('printer', _MD_PRINT);
+ $thread_action['print']['link'] = $GLOBALS['xoops']->url("modules/newbb/print.php?form=2&forum={$forum_id}&topic_id={$topic_id}");
+ $thread_action['print']['name'] = _MD_PRINT;
+ $thread_action['print']['target'] = '_blank';
+ }
+
+ if ($GLOBALS['xoopsModuleConfig']['show_sociallinks']) {
+
+ $full_title = $this->getVar('subject');
+ $clean_title =preg_replace('/[^A-Za-z0-9-]+/', '+', $this->getVar('subject'));
+ $full_link = $GLOBALS['xoops']->url("modules/newbb/viewtopic.php?post_id={$post_id}");
+
+ $thread_action['social_twitter']['image'] = newbb_displayImage('twitter', _MD_SHARE_TWITTER);
+ $thread_action['social_twitter']['link'] = "http://twitter.com/share?text={$clean_title}&url={$full_link}";
+ $thread_action['social_twitter']['name'] = _MD_SHARE_TWITTER;
+ $thread_action['social_twitter']['target'] = '_blank';
+
+ $thread_action['social_facebook']['image'] = newbb_displayImage('facebook', _MD_SHARE_FACEBOOK);
+ $thread_action['social_facebook']['link'] = "http://www.facebook.com/sharer.php?u={$full_link}";
+ $thread_action['social_facebook']['name'] = _MD_SHARE_FACEBOOK;
+ $thread_action['social_facebook']['target'] = '_blank';
+
+ $thread_action['social_gplus']['image'] = newbb_displayImage('googleplus', _MD_SHARE_GOOGLEPLUS);
+ $thread_action['social_gplus']['link'] = "https://plusone.google.com/_/+1/confirm?hl=en&url={$full_link}";
+ $thread_action['social_gplus']['name'] = _MD_SHARE_GOOGLEPLUS;
+ $thread_action['social_gplus']['target'] = '_blank';
+
+ $thread_action['social_linkedin']['image'] = newbb_displayImage('linkedin', _MD_SHARE_LINKEDIN);
+ $thread_action['social_linkedin']['link'] = "http://www.linkedin.com/shareArticle?mini=true&title={$full_title}&url={$full_link}";
+ $thread_action['social_linkedin']['name'] = _MD_SHARE_LINKEDIN;
+ $thread_action['social_linkedin']['target'] = '_blank';
+
+ $thread_action['social_delicious']['image'] = newbb_displayImage('delicious', _MD_SHARE_DELICIOUS);
+ $thread_action['social_delicious']['link'] = "http://del.icio.us/post?title={$full_title}&url={$full_link}";
+ $thread_action['social_delicious']['name'] = _MD_SHARE_DELICIOUS;
+ $thread_action['social_delicious']['target'] = '_blank';
+
+ $thread_action['social_digg']['image'] = newbb_displayImage('digg', _MD_SHARE_DIGG);
+ $thread_action['social_digg']['link'] = "http://digg.com/submit?phase=2&title={$full_title}&url={$full_link}";
+ $thread_action['social_digg']['name'] = _MD_SHARE_DIGG;
+ $thread_action['social_digg']['target'] = '_blank';
+
+ $thread_action['social_reddit']['image'] = newbb_displayImage('reddit', _MD_SHARE_REDDIT);
+ $thread_action['social_reddit']['link'] = "http://reddit.com/submit?title={$full_title}&url={$full_link}";
+ $thread_action['social_reddit']['name'] = _MD_SHARE_REDDIT;
+ $thread_action['social_reddit']['target'] = '_blank';
+
+ $thread_action['social_wong']['image'] = newbb_displayImage('wong', _MD_SHARE_MRWONG);
+ $thread_action['social_wong']['link'] = "http://www.mister-wong.de/index.php?action=addurl&bm_url=$full_link}";
+ $thread_action['social_wong']['name'] = _MD_SHARE_MRWONG;
+ $thread_action['social_wong']['target'] = '_blank';
+
+ }
+
+ $post = array(
+ 'post_id' => $post_id,
+ 'post_parent_id' => $this->getVar('pid'),
+ 'post_date' => newbb_formatTimestamp($this->getVar('post_time')),
+ 'post_image' => $post_image,
+ 'post_title' => $post_title, // irmtfan $post_title to add highlight keywords
+ 'post_text' => $post_text,
+ 'post_attachment' => $post_attachment,
+ 'post_edit' => $this->displayPostEdit(),
+ 'post_no' => $post_no,
+ 'post_signature' => ($this->getVar('attachsig')) ? @$poster["signature"] : "",
+ 'poster_ip' => ($isadmin && $GLOBALS['xoopsModuleConfig']['show_ip']) ? long2ip($this->getVar('poster_ip')) : "",
+ 'thread_action' => $thread_action,
+ 'thread_buttons' => $thread_buttons,
+ 'mod_buttons' => $mod_buttons,
+ 'poster' => $poster,
+ 'post_permalink' => "<a href='" . $GLOBALS['xoops']->url("/modules/" . $GLOBALS['xoopsModule']->getVar('dirname') . "/viewtopic.php?post_id={$post_id}") . "'></a>"
+ );
+
+ unset($thread_buttons);
+ unset($mod_buttons);
+ unset($eachposter);
+
+ return $post;
+ }
+
+}
+
+class NewbbPostHandler extends ArtObjectHandler
+//class NewbbPostHandler extends XoopsPersistableObjectHandler
+{
+ function __construct(&$db)
+ {
+ parent::__construct($db, 'bb_posts', 'Post', 'post_id', 'subject');
+ }
+
+ function NewbbPostHandler(&$db)
+ {
+ $this->__construct($db);
+ }
+
+
+ function &get($id)
+ {
+ $id = intval($id);
+ $post = null;
+ $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('bb_posts') . ' p LEFT JOIN ' . $this->db->prefix('bb_posts_text') . ' t ON p.post_id=t.post_id WHERE p.post_id=' . $id;
+ if ($array = $this->db->fetchArray($this->db->query($sql))) {
+ $post =& $this->create(false);
+ $post->assignVars($array);
+ }
+
+ return $post;
+ }
+
+
+ function &getByLimit($topic_id, $limit, $approved = 1)
+ {
+ $sql = 'SELECT p.*, t.*, tp.topic_status FROM ' . $this->db->prefix('bb_posts') . ' p LEFT JOIN ' . $this->db->prefix('bb_posts_text') . ' t ON p.post_id=t.post_id LEFT JOIN ' . $this->db->prefix('bb_topics') . ' tp ON tp.topic_id=p.topic_id WHERE p.topic_id=' . $topic_id . ' AND p.approved ='. $approved .' ORDER BY p.post_time DESC';
+ $result = $this->db->query($sql, $limit, 0);
+ $ret = array();
+ while ($myrow = $this->db->fetchArray($result)) {
+ $post =& $this->create(false);
+ $post->assignVars($myrow);
+
+ $ret[$myrow['post_id']] = $post;
+ unset($post);
+ }
+ return $ret;
+ }
+
+ function getPostForPDF(&$post)
+ {
+ return $post->getPostBody(true);
+ }
+
+ function getPostForPrint(&$post)
+ {
+ return $post->getPostBody();
+ }
+
+ function approve(&$post, $force = false)
+ {
+ if (empty($post)) {
+ return false;
+ }
+ if (is_numeric($post)) {
+ $post =& $this->get($post);
+ }
+ $post_id = $post->getVar("post_id");
+
+ $wasApproved = $post->getVar("approved");
+ // irmtfan approve post if the approved = 0 (pending) or -1 (deleted)
+ if (empty($force) && $wasApproved > 0) {
+ return true;
+ }
+ $post->setVar("approved", 1);
+ $this->insert($post, true);
+
+ $topic_handler =& xoops_getmodulehandler("topic", "newbb");
+ $topic_obj =& $topic_handler->get($post->getVar("topic_id"));
+ if ($topic_obj->getVar("topic_last_post_id") < $post->getVar("post_id")) {
+ $topic_obj->setVar("topic_last_post_id", $post->getVar("post_id"));
+ }
+ if ($post->isTopic()) {
+ $topic_obj->setVar("approved", 1);
+ } else {
+ $topic_obj->setVar("topic_replies", $topic_obj->getVar("topic_replies")+1);
+ }
+ $topic_handler->insert($topic_obj, true);
+
+ $forum_handler =& xoops_getmodulehandler("forum", "newbb");
+ $forum_obj =& $forum_handler->get($post->getVar("forum_id"));
+ if ($forum_obj->getVar("forum_last_post_id") < $post->getVar("post_id")) {
+ $forum_obj->setVar("forum_last_post_id", $post->getVar("post_id"));
+ }
+ $forum_obj->setVar("forum_posts", $forum_obj->getVar("forum_posts")+1);
+ if ($post->isTopic()) {
+ $forum_obj->setVar("forum_topics", $forum_obj->getVar("forum_topics")+1);
+ }
+ $forum_handler->insert($forum_obj, true);
+
+ // Update user stats
+ if ($post->getVar('uid') > 0) {
+ $member_handler =& xoops_gethandler('member');
+ $poster =& $member_handler->getUser($post->getVar('uid'));
+ if (is_object($poster) && $post->getVar('uid') == $poster->getVar("uid")) {
+ $poster->setVar('posts', $poster->getVar('posts') + 1);
+ $res = $member_handler->insertUser($poster, true);
+ unset($poster);
+ }
+ }
+
+ // Update forum stats
+ $stats_handler =& xoops_getmodulehandler('stats', 'newbb');
+ $stats_handler->update($post->getVar("forum_id"), "post");
+ if ($post->isTopic()) {
+ $stats_handler->update($post->getVar("forum_id"), "topic");
+ }
+
+ return true;
+ }
+
+ function insert(&$post, $force = true)
+ {
+ // Set the post time
+ // The time should be "publish" time. To be adjusted later
+ if (!$post->getVar("post_time")) {
+ $post->setVar("post_time", time());
+ }
+
+ $topic_handler =& xoops_getmodulehandler("topic", "newbb");
+ // Verify the topic ID
+ if ($topic_id = $post->getVar("topic_id")) {
+ $topic_obj =& $topic_handler->get($topic_id);
+ // Invalid topic OR the topic is no approved and the post is not top post
+ if ( !$topic_obj
+// || (!$post->isTopic() && $topic_obj->getVar("approved") < 1)
+ ) {
+ return false;
+ }
+ }
+ if (empty($topic_id)) {
+ $post->setVar("topic_id", 0);
+ $post->setVar("pid", 0);
+ $post->setNew();
+ $topic_obj =& $topic_handler->create();
+ }
+ $text_handler =& xoops_getmodulehandler("text", "newbb");
+ $post_text_vars = array("post_text", "post_edit", "dohtml", "doxcode", "dosmiley", "doimage", "dobr");
+ if ($post->isNew()) {
+ if (!$topic_id = $post->getVar("topic_id")) {
+ $topic_obj->setVar("topic_title", $post->getVar("subject", "n"));
+ $topic_obj->setVar("topic_poster", $post->getVar("uid"));
+ $topic_obj->setVar("forum_id", $post->getVar("forum_id"));
+ $topic_obj->setVar("topic_time", $post->getVar("post_time"));
+ $topic_obj->setVar("poster_name", $post->getVar("poster_name"), true);
+ $topic_obj->setVar("approved", $post->getVar("approved"), true);
+
+ if (!$topic_id = $topic_handler->insert($topic_obj, $force)) {
+ $post->deleteAttachment();
+ $post->setErrors("insert topic error");
+ //xoops_error($topic_obj->getErrors());
+ return false;
+ }
+ $post->setVar('topic_id', $topic_id);
+
+ $pid = 0;
+ $post->setVar("pid", 0);
+ } elseif (!$post->getVar("pid")) {
+ $pid = $topic_handler->getTopPostId($topic_id);
+ $post->setVar("pid", $pid);
+ }
+
+ $text_obj =& $text_handler->create();
+ foreach ($post_text_vars as $key) {
+ $text_obj->vars[$key] = $post->vars[$key];
+ }
+ $post->destoryVars($post_text_vars);
+ if (!$post_id = parent::insert($post, $force)) {
+ return false;
+ }
+ $text_obj->setVar("post_id", $post_id);
+ if (!$text_handler->insert($text_obj, $force)) {
+ $this->delete($post);
+ $post->setErrors("post text insert error");
+ //xoops_error($text_obj->getErrors());
+ return false;
+ }
+ if ($post->getVar("approved") > 0) {
+ $this->approve($post, true);
+ }
+ $post->setVar('post_id', $post_id);
+ } else {
+ if ($post->isTopic()) {
+ if ($post->getVar("subject") != $topic_obj->getVar("topic_title")) {
+ $topic_obj->setVar("topic_title", $post->getVar("subject", "n"));
+ }
+ if ($post->getVar("approved") != $topic_obj->getVar("approved")) {
+ $topic_obj->setVar("approved", $post->getVar("approved"));
+ }
+ $topic_obj->setDirty();
+ if (!$result = $topic_handler->insert($topic_obj, $force)) {
+ $post->setErrors("update topic error");
+// xoops_error($topic_obj->getErrors());
+ return false;
+ }
+ }
+ $text_obj =& $text_handler->get($post->getVar("post_id"));
+ $text_obj->setDirty();
+ foreach ($post_text_vars as $key) {
+ $text_obj->vars[$key] = $post->vars[$key];
+ }
+ $post->destoryVars($post_text_vars);
+ if (!$post_id = parent::insert($post, $force)) {
+// xoops_error($post->getErrors());
+ return false;
+ }
+ if (!$text_handler->insert($text_obj, $force)) {
+ $post->setErrors("update post text error");
+// xoops_error($text_obj->getErrors());
+ return false;
+ }
+ }
+ return $post->getVar('post_id');
+ }
+
+ function delete(&$post, $isDeleteOne = true, $force = false)
+ {
+ $retVal = false;
+ if (($post instanceof Post) && ($post->getVar('post_id') > 0)) {
+ if ($isDeleteOne) {
+ if ($post->isTopic()) {
+ $criteria = new CriteriaCompo(new Criteria("topic_id", $post->getVar('topic_id')));
+ $criteria->add(new Criteria('approved', 1));
+ $criteria->add(new Criteria('pid', 0, ">"));
+ if (!$this->getPostCount($criteria) > 0) {
+ $retVal = $this->_delete($post, $force);
+ }
+ } else {
+ $retVal = $this->_delete($post, $force);
+ }
+ } else { // want to delete multiple posts
+ //@TODO: test replacement of XoopsTree with XoopsObjectTree
+ require_once $GLOBALS['xoops']->path("class/tree.php");
+ // get tree with this object as the root
+ $myObjTree = new XoopsObjectTree($this->getAll(), "post_id", "pid", $post->getVar('post_id'));
+ $arr = $myObjtree->getAllChild(); // get all children of this object
+/*
+ require_once $GLOBALS['xoops']->path("class/xoopstree.php");
+ $mytree = new XoopsTree($this->db->prefix("bb_posts"), "post_id", "pid");
+ $arr = $mytree->getAllChild($post->getVar('post_id'));
+*/
+ // irmtfan - delete children in a reverse order
+ $success = true;
+ for ($i = count($arr) - 1; $i >= 0 ; $i--) {
+ $childpost =& $this->create(false);
+ $childpost->assignVars($arr[$i]);
+ $thisSuccess = $this->_delete($childpost, $force);
+ $success = $success && $thisSuccess;
+ unset($childpost);
+ }
+ if ($success) {
+ // if we successfully deleted all children then try and delete this post
+ $retVal = $this->_delete($post, $force);
+ } else {
+ // did not successfully delte all children so don't delete this post
+ $retVal = false;
+ }
+ }
+ }
+ return $retVal;
+ }
+
+ function _delete(&$post, $force = false)
+ {
+ if ((!$post instanceof Post) || (0 == $post->getVar('post_id'))) {
+ return false;
+ }
+
+ /* Set active post as deleted */
+ if (($post->getVar("approved") > 0) && empty($force)) {
+ $sql = "UPDATE " . $this->db->prefix("bb_posts") . " SET approved = -1 WHERE post_id = ".$post->getVar("post_id");
+ if (!$result = $this->db->queryF($sql)) {
+ //@TODO: add error check here
+ }
+ } else { /* delete pending post directly */
+ $sql = sprintf("DELETE FROM %s WHERE post_id = %u", $this->db->prefix("bb_posts"), $post->getVar('post_id'));
+ if (!$result = $this->db->queryF($sql)) {
+ $post->setErrors("delte post error: ".$sql);
+ return false;
+ }
+ $post->deleteAttachment();
+
+ $sql = sprintf("DELETE FROM %s WHERE post_id = %u", $this->db->prefix("bb_posts_text"), $post->getVar('post_id'));
+ if (!$result = $this->db->queryF($sql)) {
+ $post->setErrors("Could not remove post text: " . $sql);
+ return false;
+ }
+ }
+
+ if ($post->isTopic()) {
+ $topic_handler =& xoops_getmodulehandler('topic', 'newbb');
+ $topic_obj =& $topic_handler->get($post->getVar('topic_id'));
+ if (is_object($topic_obj) && $topic_obj->getVar("approved")>0 && empty($force)) {
+ $topiccount_toupdate = 1;
+ $topic_obj->setVar("approved", -1);
+ $topic_handler->insert($topic_obj);
+ xoops_notification_deletebyitem ($GLOBALS['xoopsModule']->getVar('mid'), 'thread', $post->getVar('topic_id'));
+ } else {
+ if (is_object($topic_obj)) {
+ if ($topic_obj->getVar("approved") > 0) {
+ xoops_notification_deletebyitem ($GLOBALS['xoopsModule']->getVar('mid'), 'thread', $post->getVar('topic_id'));
+ }
+
+ $poll_id = $topic_obj->getVar("poll_id");
+ $module_handler =& xoops_gethandler( 'module' );
+ if ($poll_id > 0) {
+ $poll_module_handler =& $module_handler->getByDirname('xoopspoll');
+ if (($poll_module_handler instanceof XoopsModuleHandler) && $poll_module_handler->isactive()) {
+ $poll_handler =& xoops_getmodulehandler('poll', 'xoopspoll');
+ if (false !== $poll_handler->deleteAll(new Criteria('poll_id', $poll_id, '='))) {
+ $option_handler =& xoops_getmodulehandler('option', 'xoopspoll');
+ $option_handler->deleteAll(new Criteria('poll_id', $poll_id, '='));
+ $log_handler =& xoops_getmodulehandler('log', 'xoopspoll');
+ $log_handler->deleteAll(new Criteria('poll_id', $poll_id, '='));
+ xoops_comment_delete($GLOBALS['xoopsModule']->getVar('mid'), $poll_id);
+ }
+ } else {
+ $poll_module_handler =& $module_handler->getByDirname('umfrage');
+ if (($poll_module_handler instanceof XoopsModuleHandler) && $poll_module_handler->isactive()) {
+ include_once $GLOBALS['xoops']->path("modules/umfrage/class/umfrage.php");
+ include_once $GLOBALS['xoops']->path("modules/umfrage/class/umfrageoption.php");
+ include_once $GLOBALS['xoops']->path("modules/umfrage/class/umfragelog.php");
+ include_once $GLOBALS['xoops']->path("modules/umfrage/class/umfragerenderer.php");
+
+ $poll = new Umfrage($poll_id);
+ if (false !== $poll->delete()) {
+ UmfrageOption::deleteByPollId($poll_id);
+ UmfrageLog::deleteByPollId($poll_id);
+ xoops_comment_delete($GLOBALS['xoopsModule']->getVar('mid'), $poll_id);
+ }
+ }
+ }
+ }
+ }
+
+ $sql = sprintf("DELETE FROM %s WHERE topic_id = %u", $this->db->prefix("bb_topics"), $post->getVar('topic_id'));
+ if (!$result = $this->db->queryF($sql)) {
+// xoops_error($this->db->error());
+ }
+ $sql = sprintf("DELETE FROM %s WHERE topic_id = %u", $this->db->prefix("bb_votedata"), $post->getVar('topic_id'));
+ if (!$result = $this->db->queryF($sql)) {
+// xoops_error($this->db->error());
+ }
+ }
+ } else {
+ $sql = "UPDATE ".$this->db->prefix("bb_topics")." t "
+ . "LEFT JOIN ".$this->db->prefix("bb_posts")." p ON p.topic_id = t.topic_id "
+ . "SET t.topic_last_post_id = p.post_id "
+ . "WHERE t.topic_last_post_id = " . $post->getVar('post_id') ." "
+ . "AND p.post_id = (SELECT MAX(post_id) FROM " . $this->db->prefix("bb_posts") . " "
+ . "WHERE topic_id=t.topic_id)";
+ if (!$result = $this->db->queryF($sql)) {
+ //@TODO: add error checking here
+ }
+ }
+
+ $postcount_toupdate = $post->getVar("approved");
+
+ if ($postcount_toupdate > 0) {
+ // Update user stats
+ if ($post->getVar('uid') > 0) {
+ $member_handler =& xoops_gethandler('member');
+ $poster =& $member_handler->getUser($post->getVar('uid'));
+ if (is_object($poster) && $post->getVar('uid') == $poster->getVar("uid")) {
+ $poster->setVar('posts', $poster->getVar('posts') - 1);
+ $res = $member_handler->insertUser($poster, true);
+ unset($poster);
+ }
+ }
+ // irmtfan - just update the pid for approved posts when the post is not topic (pid=0)
+ if (!$post->isTopic()) {
+ $sql = "UPDATE " . $this->db->prefix("bb_posts") . " SET pid = " . $post->getVar('pid') . " WHERE approved=1 AND pid=" . $post->getVar('post_id');
+ if (!$result = $this->db->queryF($sql)) {
+// xoops_error($this->db->error());
+ }
+ }
+ }
+
+ return true;
+ }
+
+// START irmtfan enhance getPostCount when there is join (read_mode = 2)
+ function getPostCount($criteria = null, $join = null)
+ {
+ // If not join get the count from XOOPS/class/model/stats as before
+ if (empty($join)) {
+ return parent::getCount($criteria);
+ }
+
+ $sql = "SELECT COUNT(*) AS count" . " "
+ . "FROM " . $this->db->prefix('bb_posts') . " AS p" . " "
+ . "LEFT JOIN " . $this->db->prefix('bb_posts_text') . " "
+ . "AS t ON t.post_id = p.post_id";
+ // LEFT JOIN
+ $sql .= $join;
+ // WHERE
+ if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
+ $sql .= " " . $criteria->renderWhere();
+ }
+ if (!$result = $this->db->query($sql)) {
+// xoops_error($this->db->error().'<br />'.$sql);
+ return null;
+ }
+ $myrow = $this->db->fetchArray($result);
+ $count = $myrow['count'];
+ return $count;
+ }
+// END irmtfan enhance getPostCount when there is join (read_mode = 2)
+
+ /*
+ *@TODO: combining viewtopic.php
+ */
+ function &getPostsByLimit($criteria = null, $limit = 1, $start = 0, $join = null)
+ {
+ $ret = array();
+ $sql = "SELECT p.*, t.* "
+ . "FROM " . $this->db->prefix('bb_posts') . " AS p "
+ . "LEFT JOIN " . $this->db->prefix('bb_posts_text') . " AS t ON t.post_id = p.post_id";
+ if (!empty($join)) {
+ $sql ...
[truncated message content] |