Salve a tutti, ha da molto tempo che vorrei modificare questo modulo credo che la maggior parte di voi lo conosca.
In pratica vorrei effettuare piccole modifiche sia nel template che nel codice, ma credo siano abbastanza fattibili.
Il modulo in questione è questo
Come risultato vorrei arrivare più o meno a questo (non fate caso alla grafica a me interessa la struttura)
I cambiamenti principali che vorre fare sarebbero mettere la x(cancella messaggio) a sinistra come la foto della shoutbox di forumfree...aggiungere la data a sinistra che già nel codice è presente ma io non sono un esperto, se possibile aggiungere il pulsante B(grassetto), e predisporre la parte inferiore del modulo come quella di forumfree.
Se qualcuno molto abile è disposto a perdere 10 min con me e creare finalmente una shoutbox come si deve ne sarei molto contento. Al max ricompenserei anche chi porta al termine il lavoro ma una ricompensa max di 5€, si tratta alal fine di spostare un po di codice qua e la.
Sotto vi posto il codice del file helper.php,mod_shoutbox.php e il file template del modulo default.php.
HELPER.PHP<?php
defined('_JEXEC') or die('Restricted access');
class modShoutboxHelper {
function addShout($name, $url, $text, $tag, $delshouts)
{
header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header( "Last-Modified: ".gmdate( "D, d M Y H:i:s" )."GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
header( "Content-Type: text/html; charset=utf-8" );
$user =& JFactory::getUser();
$userid = $user->get('id');
if ($name != '' && $text != '' ) {
($tag && $userid == 0) ? $name = '['.$name.']' : $name;
modShoutboxHelper::jal_addData($name, $url, $text, $delshouts);
}
exit();
}
function delShout($id)
{
header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header( "Last-Modified: ".gmdate( "D, d M Y H:i:s" )."GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
header( "Content-Type: text/html; charset=utf-8" );
$db = & JFactory::getDBO();
$query = 'DELETE FROM #__liveshoutbox WHERE id='. (int) $id;
$db->setQuery($query);
if (!$db->query()) {
JError::raiseError( 500, $db->stderr() );
return false;
}
}
function jal_addData($name,$url,$text, $delshouts) {
$db = & JFactory::getDBO();
$ip = $_SERVER['REMOTE_ADDR'];
$name = strip_tags($name);
$name = substr(trim($name), 0,12);
$text = strip_tags($text);
$text = substr($text,0,500);
$text = htmlspecialchars(trim($text));
$name = (empty($name)) ? "Anonymous" : htmlspecialchars($name);
$url = ($url == "http://") ? "" : htmlspecialchars($url);
$date =& JFactory::getDate();
$time = $date->toUnix();
$query = 'INSERT INTO #__liveshoutbox' . ' (time,name,text,url) VALUES ( "'.$time.'", '.$db->quote( $name ).', '.$db->quote( $text ).', '.$db->quote( $url ).' )';
$db->setQuery($query);
if (!$db->query()) {
JError::raiseError( 500, $db->stderr() );
return false;
}
modShoutboxHelper::deleteOld($delshouts);
}
function deleteOld($delshouts) {
$db = & JFactory::getDBO();
$query = 'SELECT * FROM #__liveshoutbox ORDER BY id DESC';
$db->setQuery($query, $delshouts-1, 1);
$row = $db->loadObject();
if(!empty($row)) {
$id = $row->id;
echo $id;
$db->setQuery('DELETE FROM #__liveshoutbox WHERE id < '.$id);
if (!$db->query()) {
JError::raiseError( 500, $db->stderr() );
return false;
}
}
}
function getShouts($shouts) {
global $mainframe;
$db =& JFactory::getDBO();
$query = 'SELECT * FROM #__liveshoutbox ORDER BY id DESC';
$db->setQuery( $query , 0 , $shouts);
$rows = $db->loadObjectList();
if ($db->_errorMsg) {
modShoutboxHelper::install();
}
$i = 0;
$shouts = array();
foreach ( $rows as $row ) {
$shouts[$i]->name = $row->name;
$shouts[$i]->text = $row->text;
$shouts[$i]->text = preg_replace( "`(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?`i", "<a href=\"\\0\">«link»</a>", $shouts[$i]->text);
$shouts[$i]->url = $row->url;
$shouts[$i]->url = (empty($shouts[$i]->url) && $shouts[$i]->url = "http://") ? $shouts[$i]->name : '<a href="'.$shouts[$i]->url.'">'.$shouts[$i]->name.'</a>';
$mainframe->triggerEvent('onSmiley_RenderText', array (& $shouts[$i]->text) );
$shouts[$i]->time = $row->time;
$shouts[$i]->ip = $row->ip;
$i++;
}
return $shouts;
}
function getAjaxShouts($shouts) {
global $mainframe;
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$maydelete = $user->authorize('com_content', 'edit', 'content', 'all');
$jal_lastID = JRequest::getVar( 'jal_lastID', 0 );
$query = 'SELECT * FROM #__liveshoutbox WHERE id > '.$jal_lastID.' ORDER BY id DESC';
$db->setQuery( $query , 0 , $shouts);
$rows = $db->loadObjectList();
$i = 0;
$shouts = array();
foreach ( $rows as $row ) {
$shouts[$i]->id = $row->id;
$shouts[$i]->name = $row->name;
$shouts[$i]->text = $row->text;
$shouts[$i]->text = preg_replace( "`(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?`i", "<a href=\"\\0\">«link»</a>", $shouts[$i]->text);
$mainframe->triggerEvent('onSmiley_RenderText', array (& $shouts[$i]->text) );
if($maydelete)
$shouts[$i]->text = $shouts[$i]->text.' <a href="?mode=delshout&shoutid='.$shouts[$i]->id.'" title="Delete">x</a>';
$shouts[$i]->url = $row->url;
$shouts[$i]->time = $row->time;
$shouts[$i]->ip = $row->ip;
$i++;
}
return $shouts;
}
function install() {
$db =& JFactory::getDBO();
$query = "CREATE TABLE IF NOT EXISTS #__liveshoutbox (
`id` int(11) NOT NULL auto_increment,
`time` int(11) DEFAULT '0' NOT NULL,
`name` varchar(25) NOT NULL,
`text` text NOT NULL,
`url` varchar(225) NOT NULL,
PRIMARY KEY (`id`)
) ; ";
$db->setQuery($query);
$db->query();
$query = "INSERT INTO `#__liveshoutbox` (`time`, `name`, `text`) VALUES
('1124405579', 'Risp', 'Welcome to the shoutbox');";
$db->setQuery($query);
$db->query();
}
function getType()
{
$user = & JFactory::getUser();
return (!$user->get('guest')) ? 'user' : 'guest';
}
function time_since($original) {
// array of time period chunks
$chunks = array(
array(60 * 60 * 24 * 365 , JText::_( 'YEAR'), JText::_( 'YEARS')),
array(60 * 60 * 24 * 30 , JText::_( 'MONTH') , JText::_( 'MONTHS')),
array(60 * 60 * 24 * 7, JText::_( 'WEEK') , JText::_( 'WEEKS')),
array(60 * 60 * 24 , JText::_( 'DAY') , JText::_( 'DAYS')),
array(60 * 60 , JText::_( 'HOUR') , JText::_( 'HOURS')),
array(60 , JText::_( 'MINUTE') , JText::_( 'MINUTES')),
);
$original = $original - 10; // Shaves a second, eliminates a bug where $time and $original match.
$date =& JFactory::getDate();
$today = $date->toUnix(); /* Current unix time */
$since = $today - $original;
// $j saves performing the count function each time around the loop
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
$name = $chunks[$i][1];
$names = $chunks[$i][2];
// finding the biggest chunk (if the chunk fits, break)
if (($count = floor($since / $seconds)) != 0) {
break;
}
}
$print = ($count == 1) ? '1 '.$name : "$count {$names}";
if ($i + 1 < $j) {
// now getting the second item
$seconds2 = $chunks[$i + 1][0];
$name2 = $chunks[$i + 1][1];
$names2 = $chunks[$i + 1][2];
// add second item if it's greater than 0
if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {
$print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$names2}";
}
}
return $print;
}
}
MOD_SHOUTBOX.PHP<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'helper.php' );
$shouts = intval($params->get( 'shouts', 10 ));
$delshouts = intval($params->get( 'delshouts', 50 ));
//$refresh = intval($params->get( 'refresh', 4 ));
$post_guest = $params->get( 'post_guest' );
$tag = $params->get( 'tag' );
$soundopt = $params->get( 'sound' );
$loggedin = modShoutboxHelper::getType();
$user =& JFactory::getUser();
$jal_lastID = isset($_GET['jal_lastID']) ? $_GET['jal_lastID'] : "";
$jalGetChat = isset($_GET['jalGetChat']) ? $_GET['jalGetChat'] : "";
$jalSendChat = isset($_GET['jalSendChat']) ? $_GET['jalSendChat'] : "";
$ips = $params->get( 'ips' );
$iparr = split('[,]', $ips);
$ipaccess = in_array($_SERVER['REMOTE_ADDR'], $iparr);
$name = JRequest::getVar( 'n', '', 'post' );
$url = JRequest::getVar( 'u', '', 'post' );
$text = JRequest::getVar( 'c', '', 'post' );
$homepage = JRequest::getVar( 'h', '', 'post' );
$shoutid = JRequest::getInt( 'shoutid', '', 'get' );
$maydelete = $user->authorize('com_content', 'edit', 'content', 'all');
$sound = '';
$soundbool = false;
if($soundopt) {
$img_sound = (isset($_COOKIE['jalSound']) && $_COOKIE['jalSound'] == 0) ? "sound_0.gif" : "sound_1.gif";
$sound = '<img src="modules/mod_shoutbox/images/'.$img_sound.'" alt="" onclick="setSound();" id="JalSound" title="'.JText::_('TOGGLESOUND').'" />';
$soundbool = true;
}
$mode = JRequest::getCmd('mode');
//$ajaxcall = isset($_SERVER["HTTP_X_REQUESTED_WITH"]) ? ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest") : false;
if(!$ipaccess) {
switch ($mode) {
case 'addshout':
if(empty($homepage)) {
if($post_guest) {
modShoutboxHelper::addShout($name, $url, $text, $tag, $delshouts);
} else {
if($loggedin = 'user') {
modShoutboxHelper::addShout($name, $url, $text, $tag, $delshouts);
}
}
}
break;
case 'delshout':
if($maydelete) {
modShoutboxHelper::delShout($shoutid);
}
break;
}
//getList
if($mode == 'getshouts') {
header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header( "Last-Modified: ".gmdate( "D, d M Y H:i:s" )."GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
header( "Content-Type: text/html; charset=utf-8" );
$loop = '';
$ajaxshouts = modShoutBoxHelper::getAjaxShouts($shouts);
foreach ( $ajaxshouts as $shout ) {
$loop = $shout->id."---".stripslashes($shout->name)."---".stripslashes($shout->text)."---0 minutes ago---".stripslashes($shout->url)."---" . $loop;
// --- is being used to separate the fields in the output
}
if (empty($loop)) {
$loop = "0";
}
echo $loop;
exit;
}
$list = modShoutboxHelper::getShouts($shouts);
if (isset($_POST['shout_no_js'])) {
if ($_POST['shoutboxname'] != '' && $_POST['chatbarText'] != '' && empty($homepage)) {
if($post_guest) {
if($loggedin = 'user') {
$name = $_POST['shoutboxname'];
modShoutboxHelper::jal_addData($name, $_POST['shoutboxurl'], $_POST['chatbarText'], $delshouts);
header('location: '.$_SERVER['HTTP_REFERER']);
} else {
$name = $_POST['shoutboxname'];
($tag) ? $name = '['.$name.']' : $name;
modShoutboxHelper::jal_addData($name, $_POST['shoutboxurl'], $_POST['chatbarText'], $delshouts);
header('location: '.$_SERVER['HTTP_REFERER']);
}
}
} else echo "You must have a name and a comment";
}
}
require(JModuleHelper::getLayoutPath('mod_shoutbox'));
?>
FILE TEMPLATE MODULO (DEFAULT.PHP)<?php
if(!$ipaccess) {
JHTML::_('behavior.mootools');
$module_base = JURI::base() . 'modules/mod_shoutbox/';
$document =& JFactory::getDocument();
$document->addScript($module_base . 'js/fatAjax.js');
if(JPluginHelper::isEnabled('system', 'yvsmiley')) {
if($params->get('post_guest') || $loggedin != 'guest') {
$document->addScript($module_base . 'js/sbsmile.js');
}
}
$document->addStyleSheet($module_base . 'css/mod_shoutbox.css');
}
?>
<?php if ($ipaccess) : ?>
<?php echo JText::_( 'NOIPACC'); ?>
<?php else : ?>
<script type="text/javascript">
var jal_org_timeout = <?php echo intval($params->get( 'refresh', 4 )) * 1000; ?>;
var jal_timeout = jal_org_timeout;
var fadefrom = '<?php echo $params->get("fadefrom"); ?>';
var fadeto = '<?php echo $params->get("fadeto"); ?>';
var soundopt = <?php echo $soundopt; ?>;
</script>
<div id="shoutbox">
<div id="chatoutput">
<?php echo $sound; ?>
<?php $first_time = true; ?>
<?php foreach ($list as $item) : ?>
<?php if ($first_time == true):
$lastID = $item->id; ?>
<div id="lastMessage"><span><?php echo JText::_( 'LAST_MESSAGE'); ?>:</span> <em id="responseTime"><?php echo modShoutboxHelper::time_since($item->time); ?> <?php echo JText::_( 'AGO'); ?></em></div><ul id="outputList">
<?php endif; ?>
<?php if ($maydelete): ?>
<li><a href="?mode=delshout&shoutid=" title="Delete">(x)</a> <span title="<?php echo $item->ip; ?>"><?php echo $item->url; ?> : </span><?php echo $item->text; ?> <?php echo $item->id; ?></li>
<?php else : ?>
<li><span title="<?php echo modShoutboxHelper::time_since($item->time); ?>"><?php echo $item->url; ?> : </span><?php echo $item->text; ?></li>
<?php endif; ?>
<?php $first_time = false; ?>
<?php endforeach; ?>
</ul>
</div>
<?php if(file_exists('components/com_shoutbox')) : ?>
<?php $link = JRoute::_('index.php?option=com_shoutbox'); ?>
<a href="<?php echo $link; ?>"><?php echo JText::_( 'ARCHIVE'); ?></a>
<?php endif; ?>
<?php if ($params->get('tag')) : ?>
<p><?php echo JText::_( 'GUESTTAG');?></p>
<?php endif; ?>
<?php if ($params->get('post_guest') || $loggedin != 'guest') : ?>
<form id="chatForm" name="chatForm" method="post" action="index.php">
<p>
<?php $name = ($params->get("name")) ? $user->get('name') : $user->get('username'); ?>
<?php if($loggedin != 'guest') : /* If they are logged in, then print their nickname */ ?>
<label><?php echo JText::_( 'NAME'); ?> <em><?php echo $name; ?></em></label>
<input type="hidden" name="shoutboxname" id="shoutboxname" class="inputbox" value="<?php echo $name; ?>" />
<?php else: /* Otherwise allow the user to pick their own name */ ?>
<label for="shoutboxname"><?php echo JText::_( 'NAME'); ?></label>
<input type="text" name="shoutboxname" id="shoutboxname" class="inputbox" value="<?php if (isset($_COOKIE['jalUserName'])) { echo $_COOKIE['jalUserName']; } ?>" />
<?php endif; ?>
<?php if (!$params->get('url')) : ?>
<span style="display: none">
<?php endif; ?>
<label for="shoutboxurl">Url:</label>
<input type="text" name="shoutboxurl" id="shoutboxurl" class="inputbox" value="<?php if (isset($_COOKIE['jalUrl'])) { echo $_COOKIE['jalUrl']; } else { echo 'http://'; } ?>" />
<?php if (!$params->get('url')) : ?>
</span>
<?php endif; ?>
<label for="chatbarText"><?php echo JText::_( 'MESSAGE'); ?></label>
<?php if ($params->get('textarea')) : ?>
<textarea rows="4" cols="16" name="chatbarText" id="chatbarText" class="inputbox" onkeypress="return pressedEnter(this,event);"></textarea>
<?php else: ?>
<input type="text" name="chatbarText" id="chatbarText" class="inputbox" onkeypress="return pressedEnter(this,event);"/>
<?php endif; ?>
<input type="text" name="homepage" id="homepage" class="homepage" />
</p>
<?php if(JPluginHelper::isEnabled('system', 'yvsmiley')): ?>
<a id="toggle" href="#" name="toggle"><?php echo JText::_( 'SMILEYS'); ?></a>
<?php
$smilies = '';
$mainframe->triggerEvent('onSmiley_RenderForm', array('document.forms.chatForm.chatbarText', &$smilies, 'sbsmile') );
echo $smilies;
?>
<?php endif; ?>
<input type="hidden" id="jal_lastID" value="<?php echo $lastID + 1; ?>" name="jal_lastID" />
<input type="hidden" name="shout_no_js" value="true" />
<input type="submit" id="submitchat" name="submit" class="button" value="<?php echo JText::_( 'SEND'); ?>" />
</form>
<span id="sbsound"></span>
<?php else: ?>
<p><?php echo JText::_( 'REGISTER_ONLY'); ?></p>
<?php endif; ?>
</div>
<?php endif; ?>