From: <tr...@us...> - 2012-12-23 20:25:44
|
Revision: 10530 http://sourceforge.net/p/xoops/svn/10530 Author: trabis Date: 2012-12-23 20:25:39 +0000 (Sun, 23 Dec 2012) Log Message: ----------- Adding first version of comments module Added Paths: ----------- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/about.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_delete.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_edit.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_post.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/header.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/index.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/main.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/menu.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/blocks/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/blocks/comments_blocks.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/blocks/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/comment.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/commentrenderer.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/comments.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/form/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/form/comment.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/form/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/plugin/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/plugin/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/plugin/interface.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/comment_delete.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/comment_edit.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/comment_new.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/comment_post.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/comment_reply.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/icons/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/icons/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/icons/logo_large.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/icons/logo_small.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/images/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/images/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/images/logo.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/include/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/include/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/include/install.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/english/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/english/admin.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/english/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/english/mail_template/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/english/mail_template/comment_notify.tpl XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/english/mail_template/commentsubmit_notify.tpl XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/english/mail_template/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/english/main.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/english/modinfo.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/language/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/preloads/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/preloads/core.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/preloads/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/sql/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/sql/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/sql/mysql.sql XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/admin/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/admin/comments.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/admin/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/blocks/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/blocks/comments.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/blocks/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/comment.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/comments.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/comments_flat.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/comments_nest.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/comments_thread.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/templates/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/xoops_version.php Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/about.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/about.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/about.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,27 @@ +<?php +/* + 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 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Comments + * @author trabis <lus...@gm...> + * @version $Id$ + */ + +include dirname(__FILE__) . '/header.php'; + +$xoops = Xoops::getInstance(); +$xoops->header(); +$aboutAdmin = new XoopsModuleAdmin(); +$aboutAdmin->displayNavigation('about.php'); +$aboutAdmin->displayAbout('6KJ7RW5DR3VTJ', true); +$xoops->footer(); \ No newline at end of file Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/about.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Rev URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_delete.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_delete.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_delete.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,24 @@ +<?php +/* + 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 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Comments + * @author trabis <lus...@gm...> + * @version $Id$ + */ + +include dirname(__FILE__) . '/header.php'; +//there is no way to override current tabs when using system menu +//this dirty hack will have to do it +$_SERVER['REQUEST_URI'] = "admin/main.php"; +Comments::getInstance()->displayDelete(); \ No newline at end of file Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_delete.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Rev URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_edit.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_edit.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_edit.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,24 @@ +<?php +/* + 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 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Comments + * @author trabis <lus...@gm...> + * @version $Id$ + */ + +include dirname(__FILE__) . '/header.php'; +//there is no way to override current tabs when using system menu +//this dirty hack will have to do it +$_SERVER['REQUEST_URI'] = "admin/main.php"; +Comments::getInstance()->displayEdit(); \ No newline at end of file Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_edit.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Rev URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_post.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_post.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_post.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,24 @@ +<?php +/* + 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 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Comments + * @author trabis <lus...@gm...> + * @version $Id$ + */ + +include dirname(__FILE__) . '/header.php'; +//there is no way to override current tabs when using system menu +//this dirty hack will have to do it +$_SERVER['REQUEST_URI'] = "admin/main.php"; +Comments::getInstance()->displayPost(); \ No newline at end of file Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/comment_post.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Rev URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/header.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/header.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/header.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,26 @@ +<?php +/* + 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 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Comments + * @author trabis <lus...@gm...> + * @version $Id$ + */ + + +include dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php'; +require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/include/cp_header.php'; + +$xoops = Xoops::getInstance(); +XoopsLoad::load('system', 'system'); +$system = System::getInstance(); \ No newline at end of file Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/header.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Rev URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/index.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/index.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/index.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,29 @@ +<?php +/* + 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 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Comments + * @author trabis <lus...@gm...> + * @version $Id$ + */ + +include dirname(__FILE__) . '/header.php'; + +$xoops = Xoops::getInstance(); +$xoops->header(); + +$indexAdmin = new XoopsModuleAdmin(); +$indexAdmin->displayNavigation('index.php'); +$indexAdmin->displayIndex(); + +$xoops->footer(); \ No newline at end of file Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/index.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Rev URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/main.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/main.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/main.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,303 @@ +<?php +/* + 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. +*/ + +/** + * Comments Manager + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @author Kazumi Ono (AKA onokazu) + * @package comments + * @version $Id$ + */ + +include dirname(__FILE__) . '/header.php'; + +// Get main instance +$xoops = Xoops::getInstance(); +$system = System::getInstance(); +$helper = Comments::getInstance(); + +// Get Action type +$op = $system->cleanVars($_REQUEST, 'op', 'default', 'string'); +// Call Header +$xoops->header('comments.html'); +// Define Stylesheet +$xoops->theme()->addStylesheet('media/jquery/ui/' . $xoops->getModuleConfig('jquery_theme', 'system') . '/ui.all.css'); +// Define scripts +$xoops->theme()->addScript('modules/system/js/admin.js'); + +$admin_page = new XoopsModuleAdmin(); +$admin_page->renderNavigation('main.php'); + +$limit_array = array(20, 50, 100); +$status_array = + array(COMMENTS_PENDING => _MD_COMMENTS_PENDING, COMMENTS_ACTIVE => _MD_COMMENTS_ACTIVE, COMMENTS_HIDDEN => _MD_COMMENTS_HIDDEN); +$status_array2 = array( + COMMENTS_PENDING => '<span style="text-decoration: none; font-weight: bold; color: #008000;">' . _MD_COMMENTS_PENDING . '</span>', + COMMENTS_ACTIVE => '<span style="text-decoration: none; font-weight: bold; color: #ff0000;">' . _MD_COMMENTS_ACTIVE . '</span>', + COMMENTS_HIDDEN => '<span style="text-decoration: none; font-weight: bold; color: #0000ff;">' . _MD_COMMENTS_HIDDEN . '</span>' +); +$start = 0; +$status_array[0] = _AM_COMMENTS_FORM_ALL_STATUS; + +$comments = array(); +$status = (!isset($_REQUEST['status']) || !in_array(intval($_REQUEST['status']), array_keys($status_array))) ? 0 + : intval($_REQUEST['status']); + +$module = !isset($_REQUEST['module']) ? 0 : intval($_REQUEST['module']); + +$modules_array = array(); +$module_handler = $xoops->getHandlerModule(); +$available_plugins = Xoops_Plugin::getAvailablePlugins('comments'); +if (!empty($available_plugins)) { + $criteria = new Criteria('dirname', "('" . implode("','", array_keys($available_plugins)). "')" , 'IN'); + $module_array = $module_handler->getNameList($criteria); +} + +$module_array[0] = _AM_COMMENTS_FORM_ALL_MODS; + +$comment_handler = $helper->getHandlerComment(); + +switch ($op) { + + case 'comments_jump': + $id = $system->cleanVars($_GET, 'item_id', 0, 'int'); + if ($id > 0) { + $comment = $comment_handler->get($id); + if (is_object($comment)) { + /* @var $plugin CommentsPluginInterface */ + $module = $module_handler->getById($comment->getVar('modid')); + $plugin = Xoops_Plugin::getPlugin($module->getVar('dirname'), 'comments'); + header('Location: ' . XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/' . $plugin->pageName() . '?' . $plugin->itemName() . '=' . $comment->getVar('itemid') . '&id=' . $comment->getVar('id') . '&rootid=' . $comment->getVar('rootid') . '&mode=thread&' . str_replace('&', '&', $comment->getVar('exparams')) . '#comment' . $comment->getVar('id')); + exit(); + } + } + $helper->redirect('admin/main.php', 1, _AM_COMMENTS_NO_COMMENTS); + break; + + case 'comments_form_purge': + //Affichage du formulaire de purge + $form_purge = new XoopsThemeForm(_AM_COMMENTS_FORM_PURGE, 'form', $helper->url('admin/main.php'), 'post', true); + + $form_purge->addElement(new XoopsFormTextDateSelect(_AM_COMMENTS_FORM_PURGE_DATE_AFTER, 'comments_after', '15')); + $form_purge->addElement(new XoopsFormTextDateSelect(_AM_COMMENTS_FORM_PURGE_DATE_BEFORE, 'comments_before', '15')); + + //user + $form_purge->addElement(new XoopsFormSelectUser(_AM_COMMENTS_FORM_PURGE_USER, "comments_userid", false, @$_REQUEST['comments_userid'], 5, true)); + + //groups + $groupe_select = new XoopsFormSelectGroup(_AM_COMMENTS_FORM_PURGE_GROUPS, "comments_groupe", false, '', 5, true); + $groupe_select->setExtra("style=\"width:170px;\" "); + $form_purge->addElement($groupe_select); + + //Status + $status = new XoopsFormSelect(_AM_COMMENTS_FORM_PURGE_STATUS, "comments_status", ''); + $options = $status_array; + $status->addOptionArray($options); + $form_purge->addElement($status, true); + + //Modules + $modules = new XoopsFormSelect(_AM_COMMENTS_FORM_PURGE_MODULES, "comments_modules", ''); + $options = $module_array; + $modules->addOptionArray($options); + $form_purge->addElement($modules, true); + $form_purge->addElement(new XoopsFormHidden("op", "comments_purge")); + $form_purge->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit")); + $xoops->tpl()->assign('form', $form_purge->render()); + break; + + case 'comments_purge': + $criteria = new CriteriaCompo(); + $verif = false; + if (isset($_POST['comments_after']) && isset($_POST['comments_before'])) { + if ($_POST['comments_after'] != $_POST['comments_before']) { + $after = $system->cleanVars($_POST, 'comments_after', time(), 'date'); + $before = $system->cleanVars($_POST, 'comments_before', time(), 'date'); + if ($after) { + $criteria->add(new Criteria('created', $after, ">")); + } + if ($before) { + $criteria->add(new Criteria('created', $before, "<")); + } + $verif = true; + } + } + $modid = $system->cleanVars($_POST, 'comments_modules', 0, 'int'); + if ($modid > 0) { + $criteria->add(new Criteria('modid', $modid)); + $verif = true; + } + $comments_status = $system->cleanVars($_POST, 'comments_status', 0, 'int'); + if ($comments_status > 0) { + $criteria->add(new Criteria('status', $_POST['comments_status'])); + $verif = true; + } + $comments_userid = $system->cleanVars($_POST, 'comments_userid', '', 'string'); + if ($comments_userid != '') { + foreach ($_REQUEST['comments_userid'] as $del) { + $criteria->add(new Criteria('uid', $del), 'OR'); + } + $verif = true; + } + $comments_groupe = $system->cleanVars($_POST, 'comments_groupe', '', 'string'); + if ($comments_groupe != '') { + foreach ($_POST['comments_groupe'] as $del => $u_name) { + $member_handler = $xoops->getHandlerMember(); + $members = $member_handler->getUsersByGroup($u_name, true); + $mcount = count($members); + if ($mcount > 4000) { + $helper->redirect('admin/main.php', 2, _AM_COMMENTS_DELETE_LIMIT); + } + for ($i = 0; $i < $mcount; $i++) { + $criteria->add(new Criteria('uid', $members[$i]->getVar('uid')), 'OR'); + } + } + $verif = true; + } + if (isset($_POST['commentslist_id'])) { + $commentslist_count = (!empty($_POST['commentslist_id']) && is_array($_POST['commentslist_id'])) + ? count($_POST['commentslist_id']) : 0; + if ($commentslist_count > 0) { + for ($i = 0; $i < $commentslist_count; $i++) { + $criteria->add(new Criteria('id', $_REQUEST['commentslist_id'][$i]), 'OR'); + } + } + $verif = true; + } + if ($verif == true) { + if ($comment_handler->deleteAll($criteria)) { + $helper->redirect("admin/main.php", 3, _AM_SYSTEM_DBUPDATED); + } + } else { + $helper->redirect("admin/main.php", 3, _AM_SYSTEM_DBUPDATED); + } + break; + + default: + $admin_page->addTips(_AM_COMMENTS_NAV_TIPS); + $admin_page->renderTips(); + // Display comments + $myts = MyTextSanitizer::getInstance(); + $comments_Handler = $helper->getHandlerComment(); + $comments_module = ''; + $comments_status = ''; + + $criteria = new CriteriaCompo(); + $comments_module = $system->cleanVars($_REQUEST, 'comments_module', 0, 'int'); + if ($comments_module > 0) { + $criteria->add(new Criteria('modid', $comments_module)); + $comments_module = $_REQUEST['comments_module']; + } + $comments_status = $system->cleanVars($_REQUEST, 'comments_status', 0, 'int'); + if ($comments_status > 0) { + $criteria->add(new Criteria('status', $comments_status)); + $comments_status = $_REQUEST['comments_status']; + } + + $criteria->setSort('created'); + $criteria->setOrder('DESC'); + + $comments_count = $comments_Handler->getCount($criteria); + + $xoops->tpl()->assign('comments_count', $comments_count); + + $comments_arr = array(); + $comments_start = 0; + $comments_limit = 0; + if ($comments_count > 0) { + $comments_start = $system->cleanVars($_REQUEST, 'comments_start', 0, 'int'); + $comments_limit = $system->cleanVars($_REQUEST, 'comments_limit', 0, 'int'); + if (!in_array($comments_limit, $limit_array)) { + $comments_limit = $helper->getConfig('com_pager'); + } + $criteria->setLimit($comments_limit); + $criteria->setStart($comments_start); + + $comments_arr = $comments_Handler->getObjects($criteria, true); + } + + $url = $helper->url('admin/main.php'); + $form = '<form action="' . $url . '" method="post"> + <select name="comments_module">'; + + foreach ($module_array as $k => $v) { + $sel = ''; + if ($k == $module) { + $sel = ' selected="selected"'; + } + $form .= '<option value="' . $k . '"' . $sel . '>' . $v . '</option>'; + } + $form .= '</select> <select name="comments_status">'; + + foreach ($status_array as $k => $v) { + $sel = ''; + if (isset($status) && $k == $status) { + $sel = ' selected="selected"'; + } + $form .= '<option value="' . $k . '"' . $sel . '>' . $v . '</option>'; + } + + + $form .= '</select> <select name="comments_limit">'; + foreach ($limit_array as $k) { + $sel = ''; + if (isset($limit) && $k == $limit) { + $sel = ' selected="selected"'; + } + $form .= '<option value="' . $k . '"' . $sel . '>' . $k . '</option>'; + } + $form .= '</select> <input type="submit" value="' . _GO . '" name="selsubmit" /></form>'; + + $xoops->tpl()->assign('form_sort', $form); + $xoops->tpl()->assign('php_selft', $_SERVER['PHP_SELF'] . '?op=comments_purge'); + + if ($comments_count > 0) { + foreach (array_keys($comments_arr) as $i) { + $id = $comments_arr[$i]->getVar('id'); + $comments_poster_uname = $xoops->getConfig('anonymous'); + if ($comments_arr[$i]->getVar('uid') > 0) { + $poster = $member_handler->getUser($comments_arr[$i]->getVar('uid')); + if (is_object($poster)) { + $comments_poster_uname = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $comments_arr[$i]->getVar('uid') . '">' . $poster->getVar('uname') . '</a>'; + } + } + + $comments_icon = ($comments_arr[$i]->getVar('icon') == '') ? '/images/icons/no_posticon.gif' + : '/images/subject/' . htmlspecialchars($comments_arr[$i]->getVar('icon'), ENT_QUOTES); + $comments_icon = '<img src="' . XOOPS_URL . $comments_icon . '" alt="" />'; + + $comments['comments_id'] = $id; + $comments['comments_poster'] = $comments_poster_uname; + $comments['comments_icon'] = $comments_icon; + $comments['comments_title'] = '<a href="main.php?op=comments_jump&item_id=' . $comments_arr[$i]->getVar("id") . '">' . $comments_arr[$i]->getVar("title") . '</a>'; + $comments['comments_ip'] = $comments_arr[$i]->getVar('ip'); + $comments['comments_date'] = XoopsLocal::formatTimeStamp($comments_arr[$i]->getVar('created')); + $comments['comments_text'] = $myts->undoHtmlSpecialChars($comments_arr[$i]->getVar('text')); + $comments['comments_status'] = @$status_array2[$comments_arr[$i]->getVar('status')]; + $comments['comments_date_created'] = XoopsLocal::formatTimestamp($comments_arr[$i]->getVar('created'), 'm'); + $comments['comments_modid'] = @$module_array[$comments_arr[$i]->getVar('modid')]; + //$comments['comments_view_edit_delete'] = '<img class="cursorpointer" onclick="display_dialog('.$id.', true, true, \'slide\', \'slide\', 300, 500);" src="images/icons/view.png" alt="'._AM_COMMENTS_VIEW.'" title="'._AM_COMMENTS_VIEW.'" /><a href="admin/comments/comment_edit.php?id='.$id.'"><img src="./images/icons/edit.png" border="0" alt="'._EDIT.'" title="'._EDIT.'"></a><a href="admin/comments/comment_delete.php?id='.$id.'"><img src="./images/icons/delete.png" border="0" alt="'._DELETE.'" title="'._DELETE.'"></a>'; + + $xoops->tpl()->append_by_ref('comments', $comments); + $xoops->tpl()->append_by_ref('comments_popup', $comments); + unset($comments); + } + + if ($comments_count > $comments_limit) { + $nav = new XoopsPageNav($comments_count, $comments_limit, $comments_start, 'comments_start', 'comments_module=' . $comments_module . '&comments_status=' . $comments_status); + $xoops->tpl()->assign('nav', $nav->renderNav()); + } + } + break; +} +// Call Footer +$xoops->footer(); \ No newline at end of file Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/main.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Rev URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/menu.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/menu.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/menu.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,35 @@ +<?php +/* + 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 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Comments + * @author trabis <lus...@gm...> + * @version $Id$ + */ + +$adminmenu = array(); + +$i = 1; +$adminmenu[$i]['title'] = _MI_COMMENTS_INDEX; +$adminmenu[$i]['link'] = "admin/index.php"; +$adminmenu[$i]['icon'] = 'home.png'; + +$i++; +$adminmenu[$i]['title'] = _MI_COMMENTS_MANAGE; +$adminmenu[$i]['link'] = "admin/main.php"; +$adminmenu[$i]['icon'] = 'manage.png'; + +$i++; +$adminmenu[$i]['title'] = _MI_COMMENTS_ABOUT; +$adminmenu[$i]['link'] = 'admin/about.php'; +$adminmenu[$i]['icon'] = 'about.png'; \ No newline at end of file Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/admin/menu.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Rev URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/blocks/comments_blocks.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/blocks/comments_blocks.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/blocks/comments_blocks.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,94 @@ +<?php +/* + 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 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Comments + * @author trabis <lus...@gm...> + * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ + * @version $Id$ + */ + +defined('XOOPS_ROOT_PATH') or die('Restricted access'); + +function b_comments_show($options) +{ + $xoops = Xoops::getInstance(); + $helper = Comments::getInstance(); + + $block = array(); + $available_modules = Xoops_Plugin::getAvailablePlugins('comments'); + if (empty($available_modules)) { + return $block; + } + + $comment_handler = $helper->getHandlerComment(); + $criteria = new CriteriaCompo(new Criteria('status', COMMENTS_ACTIVE)); + $criteria->setLimit(intval($options[0])); + $criteria->setSort('created'); + $criteria->setOrder('DESC'); + + // Check modules permissions + $moduleperm_handler = $xoops->getHandlerGroupperm(); + $gperm_groupid = $xoops->isUser() ? $xoops->user->getGroups() : array(XOOPS_GROUP_ANONYMOUS); + $criteria1 = new CriteriaCompo(new Criteria('gperm_name', 'module_read', '=')); + $criteria1->add(new Criteria('gperm_groupid', '(' . implode(',', $gperm_groupid) . ')', 'IN')); + $perms = $moduleperm_handler->getObjects($criteria1, true); + $modIds = array(); + foreach ($perms as $item) { + $modIds[] = $item->getVar('gperm_itemid'); + } + if (count($modIds) > 0) { + $modIds = array_unique($modIds); + $criteria->add(new Criteria('modid', '(' . implode(',', $modIds) . ')', 'IN')); + } else { + return $block; + } + + $comments = $comment_handler->getObjects($criteria, true); + $member_handler = $xoops->getHandlerMember(); + $module_handler = $xoops->getHandlerModule(); + $modules = $module_handler->getObjectsArray(new Criteria('dirname', "('" . implode("'", array_keys($available_modules)) ."')", 'IN'), true); + $comment_config = array(); + foreach (array_keys($comments) as $i) { + $mid = $comments[$i]->getVar('modid'); + $com['module'] = '<a href="' . XOOPS_URL . '/modules/' . $modules[$mid]->getVar('dirname') . '/">' . $modules[$mid]->getVar('name') . '</a>'; + if (!isset($comment_config[$mid])) { + $comment_config[$mid] = Xoops_Plugin::getPlugin($modules[$mid]->getVar('dirname'), 'comments'); + } + $com['id'] = $i; + $com['title'] = '<a href="' . XOOPS_URL . '/modules/' . $modules[$mid]->getVar('dirname') . '/' . $comment_config[$mid]->pageName() . '?' . $comment_config[$mid]->itemName() . '=' . $comments[$i]->getVar('itemid') . '&com_id=' . $i . '&com_rootid=' . $comments[$i]->getVar('rootid') . '&' . htmlspecialchars($comments[$i]->getVar('exparams')) . '#comment' . $i . '">' . $comments[$i]->getVar('title') . '</a>'; + $com['icon'] = htmlspecialchars($comments[$i]->getVar('icon'), ENT_QUOTES); + $com['icon'] = ($com['icon'] != '') ? $com['icon'] : 'icon1.gif'; + $com['time'] = XoopsLocal::formatTimestamp($comments[$i]->getVar('created'), 'm'); + if ($comments[$i]->getVar('uid') > 0) { + $poster = $member_handler->getUser($comments[$i]->getVar('uid')); + if (is_object($poster)) { + $com['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $comments[$i]->getVar('uid') . '">' . $poster->getVar('uname') . '</a>'; + } else { + $com['poster'] = $xoops->getConfig('anonymous'); + } + } else { + $com['poster'] = $xoops->getConfig('anonymous'); + } + $block['comments'][] = $com; + unset($com); + } + return $block; +} + +function b_comments_edit($options) +{ + $inputtag = "<input type='text' name='options[]' value='" . intval($options[0]) . "' />"; + $form = sprintf(_MB_SYSTEM_DISPLAYC, $inputtag); + return $form; +} \ No newline at end of file Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/blocks/comments_blocks.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Rev URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/blocks/index.html =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/blocks/index.html (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/blocks/index.html 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1 @@ + <script>history.go(-1);</script> \ No newline at end of file Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/comment.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/comment.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/comment.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,258 @@ +<?php +/* + 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 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Comments + * @author trabis <lus...@gm...> + * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ + * @version $Id$ + */ + +defined('XOOPS_ROOT_PATH') or die('Restricted access'); + +/** + * A Comment + * + * @author Kazumi Ono <on...@xo...> + * @copyright copyright (c) 2000-2003 XOOPS.org + */ +class CommentsComment extends XoopsObject +{ + + /** + * Constructor + **/ + public function __construct() + { + $this->initVar('id', XOBJ_DTYPE_INT, 0, false); + $this->initVar('pid', XOBJ_DTYPE_INT, 0, false); + $this->initVar('modid', XOBJ_DTYPE_INT, null, false); + $this->initVar('icon', XOBJ_DTYPE_OTHER, '', false); + $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, true, 255, true); + $this->initVar('text', XOBJ_DTYPE_TXTAREA, '', true, null, true); + $this->initVar('created', XOBJ_DTYPE_INT, 0, false); + $this->initVar('modified', XOBJ_DTYPE_INT, 0, false); + $this->initVar('uid', XOBJ_DTYPE_INT, 0, true); + $this->initVar('ip', XOBJ_DTYPE_OTHER, null, false); + $this->initVar('sig', XOBJ_DTYPE_INT, 0, false); + $this->initVar('itemid', XOBJ_DTYPE_INT, 0, false); + $this->initVar('rootid', XOBJ_DTYPE_INT, 0, false); + $this->initVar('status', XOBJ_DTYPE_INT, 0, false); + $this->initVar('exparams', XOBJ_DTYPE_OTHER, null, false, 255); + $this->initVar('dohtml', XOBJ_DTYPE_INT, 0, false); + $this->initVar('dosmiley', XOBJ_DTYPE_INT, 1, false); + $this->initVar('doxcode', XOBJ_DTYPE_INT, 1, false); + $this->initVar('doimage', XOBJ_DTYPE_INT, 1, false); + $this->initVar('dobr', XOBJ_DTYPE_INT, 1, false); + //not in db + $this->initVar('noname', XOBJ_DTYPE_INT, 0, false); + } + + /** + * @return bool + */ + public function isRoot() + { + return ($this->getVar('id') == $this->getVar('rootid')); + } +} + +/** + * Comment handler class. + * + * @author Kazumi Ono <on...@xo...> + * @copyright copyright (c) 2000-2003 XOOPS.org + */ +class CommentsCommentHandler extends XoopsPersistableObjectHandler +{ + /** + * Constructor + * + * @param XoopsDatabase|null $db {@link XoopsDatabase} + */ + public function __construct(XoopsDatabase $db = null) + { + parent::__construct($db, 'comments', 'CommentsComment', 'id', 'title'); + } + + /** + * Retrieves comments for an item + * + * @param int $module_id Module ID + * @param int $item_id Item ID + * @param string $order Sort order + * @param int $status Status of the comment + * @param int $limit Max num of comments to retrieve + * @param int $start Start offset + * + * @return array Array of {@link CommentsComment} objects + **/ + public function getByItemId($module_id, $item_id, $order = null, $status = null, $limit = null, $start = 0) + { + $criteria = new CriteriaCompo(new Criteria('modid', intval($module_id))); + $criteria->add(new Criteria('itemid', intval($item_id))); + if (isset($status)) { + $criteria->add(new Criteria('status', intval($status))); + } + if (isset($order)) { + $criteria->setOrder($order); + } + if (isset($limit)) { + $criteria->setLimit($limit); + $criteria->setStart($start); + } + return $this->getObjects($criteria); + } + + /** + * Gets total number of comments for an item + * + * @param int $module_id Module ID + * @param int $item_id Item ID + * @param int $status Status of the comment + * + * @return array Array of {@link CommentsComment} objects + **/ + public function getCountByItemId($module_id, $item_id, $status = null) + { + $criteria = new CriteriaCompo(new Criteria('modid', intval($module_id))); + $criteria->add(new Criteria('itemid', intval($item_id))); + if (isset($status)) { + $criteria->add(new Criteria('status', intval($status))); + } + return $this->getCount($criteria); + } + + /** + * @param int $module_id + * @param int|null $item_id + * @return int + */ + public function getCountByModuleId($module_id, $item_id = null) + { + $criteria = new CriteriaCompo(new Criteria('modid', intval($module_id))); + if (isset($item_id)) { + $criteria->add(new Criteria('itemid', intval($item_id))); + } + return $this->getCount($criteria); + } + + /** + * Get the top {@link CommentsComment}s + * + * @param int $module_id + * @param int $item_id + * @param string $order + * @param int $status + * + * @return array Array of {@link CommentsComment} objects + **/ + public function getTopComments($module_id, $item_id, $order, $status = null) + { + $criteria = new CriteriaCompo(new Criteria('modid', intval($module_id))); + $criteria->add(new Criteria('itemid', intval($item_id))); + $criteria->add(new Criteria('pid', 0)); + if (isset($status)) { + $criteria->add(new Criteria('status', intval($status))); + } + $criteria->setOrder($order); + return $this->getObjects($criteria); + } + + /** + * Retrieve a whole thread + * + * @param int $comment_rootid + * @param int $comment_id + * @param int $status + * + * @return array Array of {@link CommentsComment} objects + **/ + public function getThread($comment_rootid, $comment_id, $status = null) + { + $criteria = new CriteriaCompo(new Criteria('rootid', intval($comment_rootid))); + $criteria->add(new Criteria('id', intval($comment_id), '>=')); + if (isset($status)) { + $criteria->add(new Criteria('status', intval($status))); + } + return $this->getObjects($criteria); + } + + /** + * Update + * + * @param CommentsComment $comment {@link CommentsComment} object + * @param string $field_name Name of the field + * @param mixed $field_value Value to write + * + * @return bool + **/ + public function updateByField(CommentsComment $comment, $field_name, $field_value) + { + $comment->unsetNew(); + $comment->setVar($field_name, $field_value); + return $this->insert($comment); + } + + /** + * Delete all comments for one whole module + * + * @param int $module_id ID of the module + * @return bool + **/ + public function deleteByModule($module_id) + { + return $this->deleteAll(new Criteria('modid', intval($module_id))); + } + + /** + * @param int $module_id + * @param int $item_id + * @return bool + */ + function deleteByItemId($module_id, $item_id) + { + $module_id = intval($module_id); + $item_id = intval($item_id); + if ($module_id > 0 && $item_id > 0) { + $comments = $this->getByItemId($module_id, $item_id); + if (is_array($comments)) { + $count = count($comments); + $deleted_num = array(); + for ($i = 0; $i < $count; $i++) { + if (false != $this->delete($comments[$i])) { + // store poster ID and deleted post number into array for later use + $poster_id = $comments[$i]->getVar('uid'); + if ($poster_id != 0) { + $deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1 + : ($deleted_num[$poster_id] + 1); + } + } + } + + $member_handler = Xoops::getInstance()->getHandlerMember(); + foreach ($deleted_num as $user_id => $post_num) { + // update user posts + /* @var $member_handler XoopsMemberHandler */ + $poster = $member_handler->getUser($user_id); + if (is_object($poster)) { + $member_handler->updateUserByField($poster, 'posts', $poster->getVar('posts') - $post_num); + } + } + return true; + } + } + return false; + } + +} \ No newline at end of file Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/comment.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Rev URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/commentrenderer.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/commentrenderer.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/comments/class/commentrenderer.php 2012-12-23 20:25:39 UTC (rev 10530) @@ -0,0 +1,442 @@ +<?php +/* + 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 The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Comments + * @author trabis <lus...@gm...> + * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ + * @version $Id$ + */ + +defined('XOOPS_ROOT_PATH') or die('Restricted access'); + +/** + * Display comments + * + * @author Kazumi Ono <on...@xo...> + * @package class + */ +class CommentsCommentRenderer +{ + /** + * @var XoopsTpl + */ + private $_tpl; + + /** + * @var array + */ + private $_comments = array(); + + /** + * @var bool + */ + private $_useIcons = true; + + /** + * @var bool + */ + private $_doIconCheck = false; + + /** + * @var array + */ + private $_statusText; + + /** + * Constructor + * + * @param XoopsTpl $tpl + * @param boolean $use_icons + * @param boolean $do_iconcheck + */ + public function __construct(XoopsTpl $tpl, $use_icons = true, $do_iconcheck = false) + { + $this->_tpl = $tpl; + $this->_useIcons = $use_icons; + $this->_doIconCheck = $do_iconcheck; + $this->_statusText = array( + COMMENTS_PENDING => '<span style="text-decoration: none; font-weight: bold; color: #00ff00;">' . _MD_COMMENTS_PENDING . '</span>', + COMMENTS_ACTIVE => '<span style="text-decoration: none; font-weight: bold; color: #ff0000;">' . _MD_COMMENTS_ACTIVE . '</span>', + COMMENTS_HIDDEN => '<span style="text-decoration: none; font-weight: bold; color: #0000ff;">' . _MD_COMMENTS_HIDDEN . '</span>' + ); + } + + /** + * Access the only instance of this class + * + * @param XoopsTpl $tpl reference to a {@link XoopsTpl} object + * @param boolean $use_icons + * @param boolean $do_iconcheck + * + * @return CommentsCommentRenderer + */ + static public function getInstance(XoopsTpl $tpl, $use_icons = true, $do_iconcheck = false) + { + static $instance; + if (!isset($instance)) { + $class = __CLASS__; + $instance = new $class($tpl, $use_icons, $do_iconcheck); + } + return $instance; + } + + /** + * Accessor + * + * @param array $comments_arr array of {@link XoopsComment} objects + */ + public function setComments(&$comments_arr) + { + if (isset($this->_comments)) { + unset($this->_comments); + } + $this->_comments =& $comments_arr; + } + + /** + * Render the comments in flat view + * + * @param boolean $admin_view + */ + public function renderFlatView($admin_view = false) + { + foreach ($this->_comments as $i => $comment) { + /* @var $comment XoopsComment */ + if (false != $this->_useIcons) { + $title = $this->_getTitleIcon($comment->getVar('icon')) . ' ' . $comment->getVar('title'); + } else { + $title = $comment->getVar('title'); + } + $poster = $this->_getPosterArray($comment->getVar('uid')); + if (false != $admin_view) { + $text = $comment->getVar('text') . '<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">' . _MD_COMMENTS_STATUS . ': ' . $this->_statusText[$comment->getVar('status')] . '<br />IP: <span style="font-weight: bold;">' . $comment->getVar('ip') . '</span></div>'; + } else { + // hide comments that are not active + if (COMMENTS_ACTIVE != $comment->getVar('status')) { + continue; + } else { + $text = $comment->getVar('text'); + } + } + $this->_comments[$i] = $comment; + $this->_tpl->append('comments', array( + 'id' => $comment->getVar('id'), + 'title' => $title, + 'text' => $text, + 'date_posted' => XoopsLocal::formatTimestamp($comment->getVar('created'), 'm'), + 'date_modified' => XoopsLocal::formatTimestamp($comment->getVar('modified'), 'm'), + 'poster' => $poster + )); + } + } + + /** + * Render the comments in thread view + * This method calls itself recursively + * + * @param integer $comment_id Should be "0" when called by client + * @param boolean $admin_view + * @param boolean $show_nav + */ + public function renderThreadView($comment_id = 0, $admin_view = false, $show_nav = true) + { + // construct comment tree + $xot = new XoopsObjectTree($this->_comments, 'id', 'pid', 'rootid'); + $tree = $xot->getTree(); + + if (false != $this->_useIcons) { + $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('icon')) . ' ' . $tree[$comment_id]['obj']->getVar('title'); + } else { + $title = $tree[$comment_id]['obj']->getVar('title'); + } + if (false != $show_nav && $tree[$comment_id]['obj']->getVar('pid') != 0) { + $this->_tpl->assign('lang_top', _MD_COMMENTS_TOP); + $this->_tpl->assign('lang_parent', _MD_COMMENTS_PARENT); + $this->_tpl->assign('show_threadnav', true); + } else { + $this->_tpl->assign('show_threadnav', false); + } + if (false != $admin_view) { + // admins can see all + $text = $tree[$comment_id]['obj']->getVar('text') . '<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">' . _MD_COMMENTS_STATUS . ': ' . $this->_statusText[$tree[$comment_id]['obj']->getVar('status')] . '<br />IP: <span style="font-weight: bold;">' . $tree[$comment_id]['obj']->getVar('ip') . '</span></div>'; + } else { + // hide comments that are not active + if (COMMENTS_ACTIVE != $tree[$comment_id]['obj']->getVar('status')) { + // if there are any child comments, display them as root comments + if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) { + foreach ($tree[$comment_id]['child'] as $child_id) { + $this->renderThreadView($child_id, $admin_view, false); + } + } + return; + } else { + $text = $tree[$comment_id]['obj']->getVar('text'); + } + } + $replies = array(); + $this->_renderThreadReplies($tree, $comment_id, $replies, ' ', $admin_view); + $show_replies = (count($replies) > 0) ? true : false; + $this->_tpl->append('comments', array( + 'pid' => $tree[$comment_id]['obj']->getVar('pid'), + 'id' => $tree[$comment_id]['obj']->getVar('id'), + 'itemid' => $tree[$comment_id]['obj']->getVar('itemid'), + 'rootid' => $tree[$comment_id]['obj']->getVar('rootid'), + 'title' => $title, + 'text' => $text, + 'date_posted' => XoopsLocal::formatTimestamp($tree[$comment_id]['obj']->getVar('created'), 'm'), + 'date_modified' => XoopsLocal::formatTimestamp($tree[$comment_id]['obj']->getVar('modified'), 'm'), + 'poster' => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('uid')), + 'replies' => $replies, + 'show_replies' => $show_replies + )); + } + + /** + * Render replies to a thread + * + * @param array $thread + * @param int $key + * @param array $replies + * @param string $prefix + * @param bool $admin_view + * @param integer $depth + * @param string $current_prefix + * + * @access private + */ + private function _renderThreadReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0, $current_prefix = '') + { + if ($depth > 0) { + if (false != $this->_useIcons) { + $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('icon')) . ' ' . $thread[$key]['obj']->getVar('title'); + } else { + $title = $thread[$key]['obj']->getVar('title'); + } + $title = (false != $admin_view) ? $title . ' ' . $this->_statusText[$thread[$key]['obj']->getVar('status')] : $title; + $replies[] = array( + 'id' => $key, + 'prefix' => $current_prefix, + 'date_posted' => XoopsLocal::formatTimestamp($thread[$key]['obj']->getVar('created'), 'm'), + 'title' => $title, + 'root_id' => $thread[$key]['obj']->getVar('rootid'), + 'status' => $this->_statusText[$thread[$key]['obj']->getVar('status')], + 'poster' => $this->_getPosterName($thread[$key]['obj']->getVar('uid')) + ); + $current_prefix .= $prefix; + } + if (isset($thread[$key]['child']) && !empty($thread[$key]['child'])) { + $depth++; + foreach ($thread[$key]['child'] as $childkey) { + if (!$admin_view && $thread[$childkey]['obj']->getVar('status') != COMMENTS_ACTIVE) { + // skip this comment if it is not active and continue on processing its child comments instead + if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) { + foreach ($thread[$childkey]['child'] as $childchildkey) { + $this->_renderThreadReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth); + } + } + } else { + $this->_renderThreadReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth, $current_prefix); + } + } + } + } + + /** + * Render comme... [truncated message content] |