Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Dec 6, 2014
2 parents 208c340 + 94ebb1b commit 2d254c3
Show file tree
Hide file tree
Showing 19 changed files with 596 additions and 217 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ JoomJunk Shoutbox - A PHP shoutbox designed for use on Joomla sites
Please see the changelog for detailed information about recent changes

See http://joomjunk.co.uk/products/shoutbox.html for the latest stable version of the code. This github version will contain the latest version of the code - however this may still be a work in progress.

A wiki resource can be found here https://github.com/wilsonge/shoutbox/wiki
5 changes: 5 additions & 0 deletions changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
- -> Removed
! -> Note

Version 2.0.0
^ Changed form names to avoid conflicts with other extensions such as Kunena
# Fix broken recaptcha library since version 1.3.0
+ Add BBCode functionality

Version 1.4.2
# Another timezone bug fix
^ Updated to jQuery 1.11.1
Expand Down
65 changes: 65 additions & 0 deletions mod_shoutbox/fields/check.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* @package JJ_Shoutbox
* @copyright Copyright (C) 2011 - 2014 JoomJunk. All rights reserved.
* @license GPL v3.0 or later http://www.gnu.org/licenses/gpl-3.0.html
*/


defined('JPATH_PLATFORM') or die;

/**
* Form Field to check if Freichat is enabled.
*
* @package JJ_Shoutbox
* @since 2.0.0
*/
class JFormFieldCheck extends JFormField
{
/**
* @var string
*/
protected $type = 'Check';

/**
* @return string
*/
protected function getLabel()
{

// Database query to check id Freichat exists
$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query->select(array('*'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('element') . ' = '. $db->quote('mod_freichatx'));

$db->setQuery($query);
$result = $db->loadObjectList();

if($result)
{
// Detect Joomla version and render the message
if (version_compare(JVERSION, '3.0.0', 'ge'))
{
$application = JFactory::getApplication();
$application->enqueueMessage(JText::_('WARNING_FREICHAT_IS_INSTALLED'), 'warning');
}
else
{
return JError::raiseNotice( 100, JText::_('WARNING_FREICHAT_IS_INSTALLED') );
}
}

}

/**
* @return mixed
*/
protected function getInput()
{
return;
}

}
1 change: 1 addition & 0 deletions mod_shoutbox/fields/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>
166 changes: 105 additions & 61 deletions mod_shoutbox/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,41 @@
*/
class ModShoutboxHelper
{
/**
* Wrapper function for getting the shouts in PHP
*
* @param int $number The number of posts to retrieve from the database.
* @param string $message The error message to return if the database retrieval fails.
*
* @return array The shoutbox posts.
*
* @since 2.0
*/
public static function getShouts($number, $message)
{
try
{
$shouts = self::getShoutData($number);
}
catch (Exception $e)
{
$shouts = self::createErrorMsg($message, $e);
}

return $shouts;
}

/**
* Retrieves the shouts from the database and returns them. Will return an error
* message if the database retrieval fails.
*
* @param int $number The number of posts to retrieve from the database.
* @param string $message The error message to return if the database retrieval fails.
*
* @return array The shoutbox posts.
*
* @since 1.0
*/
public static function getShouts($number, $message)
private static function getShoutData($number)
{
$shouts = array();
$db = JFactory::getDbo();
Expand All @@ -39,29 +62,17 @@ public static function getShouts($number, $message)

if (!JError::$legacy)
{
try
{
// Execute the query.
$rows = $db->loadObjectList();
}
catch (Exception $e)
{
// Assemble Message and add log.
$shouts = self::createErrorMsg();

return $shouts;
}
// If we have an exception then we'll let it propogate up the chain
$rows = $db->loadObjectList();
}
else
{
$rows = $db->loadObjectList();

// If we have an error with JError then we'll create an exception ourselves
if ($db->getErrorNum())
{
// Assemble Message and add log.
$shouts = self::createErrorMsg();

return $shouts;
throw new RuntimeException($db->getErrorMsg(), $db->getErrorNum());
}
}

Expand Down Expand Up @@ -204,58 +215,78 @@ public static function stri_replace($find, $replace, $string)
}

/**
* Replaces all the smileys in the message.
* @var array The available smilies and their paths
* @since 1.2.0
*/
public static $smileys = array(
':)' => 'media/mod_shoutbox/images/icon_e_smile.gif',
':(' => 'media/mod_shoutbox/images/icon_e_sad.gif',
':D' => 'media/mod_shoutbox/images/icon_e_biggrin.gif',
'xD' => 'media/mod_shoutbox/images/icon_e_biggrin.gif',
':p' => 'media/mod_shoutbox/images/icon_razz.gif',
':P' => 'media/mod_shoutbox/images/icon_razz.gif',
';)' => 'media/mod_shoutbox/images/icon_e_wink.gif',
':S' => 'media/mod_shoutbox/images/icon_e_confused.gif',
':@' => 'media/mod_shoutbox/images/icon_mad.gif',
':O' => 'media/mod_shoutbox/images/icon_e_surprised.gif',
'lol' => 'media/mod_shoutbox/images/icon_lol.gif',
);

/**
* Replaces all the bbcode in the message.
*
* @param string $message The message to be searched to add smileys in.
* @param string $message The message to be searched possibly with bbcode in.
*
* @return string $message The message with the smiley code in.
* @return string The message with the replaced bbcode code in.
*
* @since 1.0
* @since 1.5.0
*/
public static function smileyFilter($message)
public static function bbcodeFilter($message)
{
$smileys = array(
':)' => ' <img src="media/mod_shoutbox/images/icon_e_smile.gif" alt=":)">',
':(' => ' <img src="media/mod_shoutbox/images/icon_e_sad.gif" alt=":(">',
':D' => ' <img src="media/mod_shoutbox/images/icon_e_biggrin.gif" alt=":D">',
'xD' => ' <img src="media/mod_shoutbox/images/icon_e_biggrin.gif" alt="xD">',
':p' => ' <img src="media/mod_shoutbox/images/icon_razz.gif" alt=":p">',
':P' => ' <img src="media/mod_shoutbox/images/icon_razz.gif" alt=":P">',
';)' => ' <img src="media/mod_shoutbox/images/icon_e_wink.gif" alt=";)">',
':S' => ' <img src="media/mod_shoutbox/images/icon_e_confused.gif" alt=":S">',
':@' => ' <img src="media/mod_shoutbox/images/icon_mad.gif" alt=":@">',
':O' => ' <img src="media/mod_shoutbox/images/icon_e_surprised.gif" alt=":O">',
'lol' => ' <img src="media/mod_shoutbox/images/icon_lol.gif" alt="lol">',
);

foreach ($smileys as $key => $val)
// Replace the smileys
foreach (static::$smileys as $smile => $url)
{
$message = str_replace($key, $val, $message);
$replace = '<img src="' . $url . '" alt="' . $smile . '">';
$message = str_replace($smile, $replace, $message);
}

// Parse the Bold, Italic, strikes and links
$search = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[url=(?:http(s?):\/\/)?([^\]]+)\]\s*(.*?)\s*\[\/url\]/is'
);

$replace = array(
'<span class="jj-bold">$1</span>',
'<span class="jj-italic">$1</span>',
'<span class="jj-underline">$1</span>',
'<a href="http$1://$2" target="_blank">$3</a>'
);

$message = preg_replace($search, $replace, $message);

return $message;
}

/**
* Displays an array of smilies.
*
* @param string $id The id of the textarea to insert the smiley into
*
* @return array $smilies The smiley images html code.
*
* @since 1.2
*/
public static function smileyshow()
public static function smileyShow($id = 'jj_message')
{
$smilies = '';
$smilies .= '<img class="jj_smiley" src="media/mod_shoutbox/images/icon_e_smile.gif" alt=":)" />';
$smilies .= '<img class="jj_smiley" src="media/mod_shoutbox/images/icon_e_sad.gif" alt=":(" />';
$smilies .= '<img class="jj_smiley" src="media/mod_shoutbox/images/icon_e_biggrin.gif" alt=":D" />';
$smilies .= '<img class="jj_smiley" src="media/mod_shoutbox/images/icon_e_biggrin.gif" alt="xD" />';
$smilies .= '<img class="jj_smiley" src="media/mod_shoutbox/images/icon_razz.gif" alt=":P" />';
$smilies .= '<img class="jj_smiley" src="media/mod_shoutbox/images/icon_e_wink.gif" alt=";)" />';
$smilies .= '<img class="jj_smiley" src="media/mod_shoutbox/images/icon_e_confused.gif" alt=":S" />';
$smilies .= '<img class="jj_smiley" src="media/mod_shoutbox/images/icon_mad.gif" alt=":@" />';
$smilies .= '<img class="jj_smiley" src="media/mod_shoutbox/images/icon_e_surprised.gif" alt=":O" />';
$smilies .= '<img class="jj_smiley" src="media/mod_shoutbox/images/icon_lol.gif" alt="lol" />';

foreach (static::$smileys as $smile => $url)
{
$smilies .= '<img class="jj_smiley" src="' . $url . '" alt="' . $smile . '" onClick="addSmiley(\'' . $smile . '\', \'' . $id . '\')" />';
}

return $smilies;
}
Expand Down Expand Up @@ -325,7 +356,14 @@ public static function linkUser($profile, $name, $user_id)
elseif ($profile == 2)
{
// Kunena Profile Link
$profile_link = '<a href="' . JRoute::_('index.php?option=com_kunena&func=fbprofile&userid=' . $user_id) . '">' . $name . '</a>';
if (class_exists('KunenaFactory') && class_exists('KunenaProfileKunena')) {
$kUser = KunenaFactory::getUser()->userid;
$kLink = KunenaProfileKunena::getProfileURL($kUser);
}
else {
$kLink = null;
}
$profile_link = '<a href="' . $kLink . '">' . $name . '</a>';
}
elseif ($profile == 3)
{
Expand Down Expand Up @@ -495,20 +533,26 @@ public static function randomnumber($digits)
return (rand() % $range + $start);
}

private static function createErrorMsg()
/**
* Creates the error message to display to the user
*
* @param string $message The translated string to show to the user
* @param Exception $e The database exception when trying to retrieve the posts
*
* @return array An array
*/
private static function createErrorMsg($message, $e)
{
$i = 0;

// Output error to shoutbox.
$shouts[$i] = new stdClass;
$shouts[$i]->name = 'Administrator';
$shouts[$i]->when = JFactory::getDate()->format('Y-m-d H:i:s');
$shouts[$i]->msg = $message;
$shouts[$i]->ip = 'System';
$shouts[$i]->user_id = 0;
$shouts[0] = new stdClass;
$shouts[0]->name = 'Administrator';
$shouts[0]->when = JFactory::getDate()->format('Y-m-d H:i:s');
$shouts[0]->msg = $message;
$shouts[0]->ip = 'System';
$shouts[0]->user_id = 0;

// Add error to log.
JLog::add(JText::sprintf('SHOUT_DATABASE_ERROR', $e), JLog::CRITICAL, 'mod_shoutbox');
JLog::add(JText::sprintf('SHOUT_DATABASE_ERROR', $e->getMessage()), JLog::CRITICAL, 'mod_shoutbox');

return $shouts;
}
Expand Down
5 changes: 4 additions & 1 deletion mod_shoutbox/language/en-GB/en-GB.mod_shoutbox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ SHOUT_SMILIES_ON="Enable but dont show"
SHOUT_SMILIES_ON_FIXED="Enable and show"
SHOUT_SMILIES_ON_SLIDE="Enable with slideToggle"
SHOUT_SMILIES_DISABLE="Disable"
SHOUT_BBCODELABEL="BBCode"
SHOUT_BBCODEDESC="Select whether you would like to enable BBCode"
SHOUT_DATABASEERRORSHOUT="There has been a database error"
SHOUT_DATABASEERROR="Apologies - You cannot post at this time due to a database error"
SHOUT_EMPTY="There are no posts in the Shoutbox"
Expand Down Expand Up @@ -95,4 +97,5 @@ SHOUT_NOT_INT="You must delete a integer number of shouts"
SHOUT_SWEAR_FILE_NOT_FOUND="The swear filter file cannot be found"
SHOUT_DATABASE_ERROR="There has been a database error: %s"
SHOUT_MASS_DELETE_OPTION="Mass Delete Button"
SHOUT_MASS_DELETE_OPTION_DESC="Select whether or not you would like to display the Mass Delete function (only admins can see this)"
SHOUT_MASS_DELETE_OPTION_DESC="Select whether or not you would like to display the Mass Delete function (only admins can see this)"
WARNING_FREICHAT_IS_INSTALLED="Freichat appears to exist on your site. There are known conflicts with JJ Shoutbox and Freichat, therefore you cannot have both extensions installed."
1 change: 1 addition & 0 deletions mod_shoutbox/language/it-IT/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><title></title>
Loading

0 comments on commit 2d254c3

Please sign in to comment.