Skip to content

Commit

Permalink
Merge pull request #217 from JoomJunk/development
Browse files Browse the repository at this point in the history
Merge update for v7.0.0
  • Loading branch information
C-Lodder committed Jan 13, 2016
2 parents d86ea9c + 15a918f commit 5b59e5d
Show file tree
Hide file tree
Showing 34 changed files with 1,704 additions and 842 deletions.
12 changes: 12 additions & 0 deletions changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
- -> Removed
! -> Note

Version 7.0.0
- Added ability for user to edit their shout
- Added option to set the output box height
- Added Russian language files
- Added option for header text colour
- Added option for shout post text colour
- Added option for textarea height
- Added automatic email cloak
- Added French language file (thanks Dominique)
- Fixed error coming from extract() function
- CSS improvements

Version 6.0.4
# Fixed maths question not refreshing after submitted post
# Fixed Dutch language not installing
Expand Down
2 changes: 1 addition & 1 deletion mod_shoutbox/fields/sep.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package JJ_Shoutbox
* @copyright Copyright (C) 2011 - 2015 JoomJunk. All rights reserved.
* @copyright Copyright (C) 2011 - 2016 JoomJunk. All rights reserved.
* @license GPL v3.0 or later http://www.gnu.org/licenses/gpl-3.0.html
*/

Expand Down
198 changes: 170 additions & 28 deletions mod_shoutbox/helper.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package JJ_Shoutbox
* @copyright Copyright (C) 2011 - 2015 JoomJunk. All rights reserved.
* @copyright Copyright (C) 2011 - 2016 JoomJunk. All rights reserved.
* @license GPL v3.0 or later http://www.gnu.org/licenses/gpl-3.0.html
*/

Expand Down Expand Up @@ -59,7 +59,7 @@ public static function submitAjax()
throw new RuntimeException('The message body is empty');
}

$id = $helper->submitPost($post);
$id = $helper->submitPost($post);
$shout = $helper->getAShout($id);

$htmlOutput = $helper->renderPost($shout);
Expand Down Expand Up @@ -239,7 +239,7 @@ public function getAShout($id)
$query = $db->getQuery(true);
$query->select('*')
->from($db->quoteName('#__shoutbox'))
->where($db->quoteName('id') . ' = ' . $id);
->where($db->quoteName('id') . ' = ' . (int)$id);
$db->setQuery($query);

$row = $db->loadObject();
Expand Down Expand Up @@ -391,9 +391,24 @@ public function postFiltering($shout, $user, $swearCounter, $swearNumber, $displ
$name = $nameFilter->clean($name, 'string');
$message = $messageFilter->clean($message, 'string');

// Start the email cloaking process
$searchEmail = '([\w\.\-\+]+\@(?:[a-z0-9\.\-]+\.)+(?:[a-zA-Z0-9\-]{2,10}))';

// Search for plain text [email protected]
$pattern = '~' . $searchEmail . '([^a-z0-9]|$)~i';

while (preg_match($pattern, $message, $regs, PREG_OFFSET_CAPTURE))
{
$mail = $regs[1][0];
$replacement = JHtml::_('email.cloak', $mail);

// Replace the found address with the js cloaked email
$message = substr_replace($message, $replacement, $regs[1][1], strlen($mail));
}

if ($swearCounter == 0 || $swearCounter == 1 && (($nameSwears + $messageSwears) <= $swearNumber))
{
return $this->addShout($name, $message, $ip);
return $this->addShout($shout['type'], $shout['id'], $name, $message, $ip);
}
}

Expand Down Expand Up @@ -588,7 +603,6 @@ public function linkUser($profile, $name, $user_id)
{
$href = $node->getAttribute('href');
}
extract($href);

// Kunena Profile Link
$profile_link = '<a href="' . $href . '">' . $name . '</a>';
Expand Down Expand Up @@ -632,39 +646,63 @@ public function linkUser($profile, $name, $user_id)
/**
* Adds a shout to the database.
*
* @param string $type The type of submission (insert or update)
* @param string $id The id of the post (update only)
* @param string $name The post to be searched.
* @param string $message The name of the user from the database.
* @param string $ip The ip of the user.
*
* @return integer The id of the inserted row
* @return integer The id of the inserted row or true if an update
*
* @since 1.0
*/
public function addShout($name, $message, $ip)
public function addShout($type, $id, $name, $message, $ip)
{
$db = JFactory::getDbo();
$config = JFactory::getConfig();
$columns = array('name', 'when', 'ip', 'msg', 'user_id');
$values = array($db->Quote($name), $db->Quote(JFactory::getDate('now')->toSql(true)),
$db->quote($ip), $db->quote($message), $db->quote(JFactory::getUser()->id));
$query = $db->getQuery(true);

if ($type == 'insert')
{
// Insert a new shout into the database
$query = $db->getQuery(true);
$columns = array('name', 'when', 'ip', 'msg', 'user_id');

$values = array(
$db->quote($name),
$db->quote(JFactory::getDate('now')->toSql(true)),
$db->quote($ip),
$db->quote($message),
$db->quote(JFactory::getUser()->id)
);

$query->insert($db->quoteName('#__shoutbox'))
->columns($db->quoteName($columns))
->values(implode(',', $values));
$query->insert($db->quoteName('#__shoutbox'))
->columns($db->quoteName($columns))
->values(implode(',', $values));

$db->setQuery($query);
$db->setQuery($query);

try
{
$db->execute();
try
{
$db->execute();
}
catch (Exception $e)
{
JLog::add(JText::sprintf('SHOUT_DATABASE_ERROR', $e), JLog::CRITICAL, 'mod_shoutbox');
}

return $db->insertid();
}
catch (Exception $e)
else if ($type == 'update' && $id != '')
{
JLog::add(JText::sprintf('SHOUT_DATABASE_ERROR', $e), JLog::CRITICAL, 'mod_shoutbox');
// Update an existing shout in the database
$object = new stdClass();
$object->id = $id;
$object->msg = $message;

JFactory::getDbo()->updateObject('#__shoutbox', $object, 'id');

return (int)$id;
}

return $db->insertid();
}

/**
Expand All @@ -691,20 +729,29 @@ public function deletepost($id)
/**
* Removes multiple shouts from the database.
*
* @param int $delete The id of the post to be deleted.
* @param int $delete The id of the post to be deleted.
* @param string $dir A string containing either ASC or DESC
*
* @return void
*
* @since 1.2.0
*/
public function deleteall($delete)
public function deleteall($delete, $dir = 'DESC')
{
$dir = strtoupper($dir);

// Ensure the direction is valid. Fallback to the most recent post (for b/c)
if (!in_array($dir, array('DESC', 'ASC')))
{
$dir = 'DESC';
}

$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
->from($db->quoteName('#__shoutbox'))
->order($db->quoteName('id') . ' DESC')
->setLimit($delete, 0);
->order($db->quoteName('id') . ' ' . $dir)
->setLimit($delete);

$db->setQuery($query);

Expand Down Expand Up @@ -1000,7 +1047,7 @@ public function getAvatar($type, $id)
{
$atts = array();

$url = 'http://www.gravatar.com/avatar/';
$url = 'https://www.gravatar.com/avatar/';
$url .= md5(strtolower(trim($email)));
$url .= "?s=30&d=mm&r=g";
$url = '<img src="' . $url . '"';
Expand Down Expand Up @@ -1109,4 +1156,99 @@ private function createErrorMsg($message, $e)

return $shouts;
}
}

/*
* Check the timestamp of the shout is still within limits
*
* @return string The rendered post contents
*
* @since 7.0.0
*/
public static function checkTimestampAjax()
{
$app = JFactory::getApplication();
$post = $app->input->post->get('jjshout', array(), 'array');

// Retrieve required parameter
if (!isset($post['title']))
{
throw new RuntimeException("Couldn't assemble the necessary parameters for the module");
}

$helper = new ModShoutboxHelper($post['title']);
$helper->ajax = true;

$id = 0;

if (isset($post['id']))
{
$id = $post['id'];
}

// Shout data
$shoutData = $helper->getTimestampData($id);

// Shout Unix timestamp
$shoutTimestamp = JFactory::getDate($shoutData[0]->when)->toUnix();

// Current Unix timestamp
$currentTimestamp = JFactory::getDate('now')->toUnix();

// Get difference in time and round to 1 decimal place
$minutes = round(($currentTimestamp - $shoutTimestamp) / 60, 1);

$result = null;

if ($minutes < (int) $helper->getParams()->get('editown-time', 5))
{
$htmlOutput = array();

foreach ($shoutData as $shout)
{
$htmlOutput[] = array(
'id' => $shout->id,
'name' => $shout->name,
'when' => $shout->when,
'ip' => $shout->ip,
'msg' => $shout->msg,
'user_id' => $shout->user_id,
);
}

$result = json_encode($htmlOutput);
}

return $result;
}

/*
* Pull the shout data based on the ID
*
* @param int $id The ID of the shout
*
* @return string The rendered post contents
*
* @since 7.0.0
*/
private function getTimestampData($id)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*')
->from($db->quoteName('#__shoutbox'))
->where($db->quoteName('id') . ' = ' . (int) $id);

$db->setQuery($query);

$result = $db->loadObjectList();

// If we have an error then we'll create an exception
if ($db->getErrorNum())
{
throw new RuntimeException($db->getErrorMsg(), $db->getErrorNum());
}

return $result;
}

}
Loading

0 comments on commit 5b59e5d

Please sign in to comment.