|
From: Lo?c C. <lo...@us...> - 2001-05-07 21:13:47
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/lib
In directory usw-pr-cvs1:/tmp/cvs-serv18619/chat/lib
Modified Files:
smilies.lib.php3
Log Message:
Take into account a max number of smilies
Index: smilies.lib.php3
===================================================================
RCS file: /cvsroot/phpmychat/phpMyChat-0.15/chat/lib/smilies.lib.php3,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** smilies.lib.php3 2001/04/30 19:40:05 1.10
--- smilies.lib.php3 2001/05/07 21:13:45 1.11
***************
*** 10,13 ****
--- 10,16 ----
// | This library allows to transform some text codes to graphical smilies. |
// | |
+ // | The limitation of the number of graphical smilies per message is based |
+ // | on a piece of code from Tomas Haluza <th...@ki...>. |
+ // | |
// | It is called by the tutorials, the 'chat/help_popup.php3' script and all |
// | the scripts that put messages in the database (main 'input' scripts and |
***************
*** 22,26 ****
// $Id$
//
! // Transform some text codes to graphical smilies.
//
--- 25,29 ----
// $Id$
//
! // Replace smilies text codes by their associated icons.
//
***************
*** 39,43 ****
* Note that the code ':mine:' is reserved: it will be replace by a gif smiley
* which name is the nick of the user if you put such one inside the
! * 'chat/image/smilies' subdirectory and if the usrs is a registered one.
*/
$smilies = array(
--- 42,47 ----
* Note that the code ':mine:' is reserved: it will be replace by a gif smiley
* which name is the nick of the user if you put such one inside the
! * 'chat/image/smilies/reserved' subdirectory and if the user is a registered
! * one.
*/
$smilies = array(
***************
*** 71,74 ****
--- 75,113 ----
/**
+ * Add some special smilies that may be used inside message
+ *
+ * @global array the smilies array
+ * @global array the session data
+ *
+ * @access private
+ */
+ function pmcAddSmilies()
+ {
+ global $smilies;
+ global $dbSessionVars;
+
+ // Add the 'reserved' smiley if required
+ if (isset($dbSessionVars) && !empty($dbSessionVars['pwdHash'])
+ && !ereg('[/:\*?"<>|]', $dbSessionVars['nick'])
+ && ($prop = @getImageSize('./images/smilies/reserved/' . $dbSessionVars['nick'] . '.gif')))
+ {
+ $smilies[':mine:'] = array('reserved/' . $dbSessionVars['nick'], $prop[0], $prop[1]);
+ }
+
+ // '<' and '>' characters may have been converted to their html entities
+ // inside messages
+ reset($smilies);
+ while (list($key, $prop) = each($smilies))
+ {
+ if (strpos(' ' . $key, '>') + strpos(' ' . $key, '<') > 0)
+ {
+ $modifiedKey = str_replace('>', '>', str_replace('<', '<', $key));
+ $smilies[$modifiedKey] = $prop;
+ }
+ }
+ } // end of the 'pmcAddSmilies()' function
+
+
+ /**
* Special sorting function for the smilies array
*
***************
*** 98,120 ****
-
-
/**
- * Slashes ' and \ characters after the " character has been tranformed to its
- * html entity
- *
- * @param string the text code to be slashed
- *
- * @return string the slashed string
- *
- * @access private
- */
- function specialSlash($str = '')
- {
- return addslashes(str_replace('"', '"', $str));
- } // end of the 'specialSlash()' function
-
-
- /**
* Replace smilies code by gif URLs in messages
*
--- 137,141 ----
***************
*** 129,134 ****
* @access public
*
* @todo ensure all invalid characters for file names have been checked
! * before to use the 'getImageSize()' function
*/
function pmcCheckForSmilies(&$string)
--- 150,157 ----
* @access public
*
+ * @see pmcAddSmilies()
+ *
* @todo ensure all invalid characters for file names have been checked
! * before to use the 'getImageSize()' function (line 173)
*/
function pmcCheckForSmilies(&$string)
***************
*** 137,151 ****
global $dbSessionVars;
// Sort the smilies array in a convenient order
reset($smilies);
uksort($smilies, 'pmcSmiliesCmp');
! $tmp = split('<a href|</a>', ' ' . $string . ' ');
! $arrayCnt = count($tmp);
reset($tmp);
! for ($i = 0; $i < $arrayCnt; $i++)
{
$substring = $tmp[$i];
!
// $substring is one of the trailing spaces added above -> do nothing
if ($substring == ' ')
--- 160,177 ----
global $dbSessionVars;
+ pmcAddSmilies();
+
// Sort the smilies array in a convenient order
reset($smilies);
uksort($smilies, 'pmcSmiliesCmp');
! $tmp = split('<a href|</a>', ' ' . $string . ' ');
! $arrayCnt = count($tmp);
! $replacedCnt = 0;
reset($tmp);
! for ($i = 0; $i < $arrayCnt && $replacedCnt < C_MAX_GSMILIES; $i++)
{
$substring = $tmp[$i];
!
// $substring is one of the trailing spaces added above -> do nothing
if ($substring == ' ')
***************
*** 153,186 ****
// void
}
// $substring is not an HTTP link -> do the work for smilies
! else if (($i % 2) == 0)
{
- // trick for smilies at the beginning or the end of the string
$substring = ' ' . $substring . ' ';
reset($smilies);
! while (list($key, $prop) = each($smilies))
{
! $substring = str_replace(' ' . $key . ' ', ' <img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] . '" alt="' . str_replace('"', '"', stripslashes($key)) . '" /> ', $substring);
! // '<' and '>' characters may have been converted to html entities
! if (strpos(' ' . $key, '>') + strpos(' ' . $key, '<') > 0)
{
! $modifiedKey = str_replace('>', '>', str_replace('<', '<', $key));
! $substring = str_replace(' ' . $modifiedKey . ' ', ' <img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] . '" alt="' . str_replace('"', '"', stripslashes($key)) . '" /> ', $substring);
}
}
- // Reserved smilies for registered users
- if (!empty($dbSessionVars['pwdHash'])
- && !ereg('[/:\*?"<>|]', $dbSessionVars['nick'])
- && ($prop = @getImageSize('./images/smilies/' . $dbSessionVars['nick'] . '.gif')))
- {
- $substring = str_replace(' :mine: ', ' <img src="images/smilies/' . $dbSessionVars['nick'] . '.gif" width="' . $prop[0] . '" height="' . $prop[1] . '" alt="' . str_replace('"', '"', $dbSessionVars['nick']) . '" /> ', $substring);
- }
$tmp[$i] = substr($substring, 1, strlen($substring) - 2);
}
- // $substring is an HTTP link -> just restore HTML tags for links
- else
- {
- $tmp[$i] = '<a href' . $substring . '</a>';
- }
}
$string = trim(join('', $tmp));
--- 179,215 ----
// void
}
+ // $substring is an HTTP link -> just restore HTML tags for links
+ else if (($i % 2) != 0)
+ {
+ $tmp[$i] = '<a href' . $substring . '</a>';
+ }
// $substring is not an HTTP link -> do the work for smilies
! else
{
$substring = ' ' . $substring . ' ';
reset($smilies);
! while ((list($key, $prop) = each($smilies)) && ($replacedCnt < C_MAX_GSMILIES))
{
! $pos = 0;
! $substrDone = '';
! while (strlen($substring) > 2 && $replacedCnt < C_MAX_GSMILIES)
{
! $pos = strpos(' ' . $substring, ' ' . $key . ' ');
! if ($pos > 0)
! {
! $substrDone .= substr($substring, 0, $pos)
! . '<img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] . '" alt="' . str_replace('"', '"', stripslashes($key)) . '" /> ';
! $substring = substr($substring, $pos + strlen($key));
! $replacedCnt++;
! }
! else
! {
! break;
! }
}
+ $substring = $substrDone . $substring;
}
$tmp[$i] = substr($substring, 1, strlen($substring) - 2);
}
}
$string = trim(join('', $tmp));
***************
*** 219,228 ****
if ($target == 'help')
! $str1 .= "\t\t" . '<td align="center" width="'. $maxWidth . '" height="' . $maxHeight . '"><a href="#" onclick="pmcSmiley2Input(\'' . specialSlash($key) . '\'); return false"><img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] .'" border="0" alt="' . str_replace('"', '"', $key) . '" /></a></td>' . "\n";
else
$str1 .= "\t\t" . '<td align="center" width="'. $maxWidth . '" height="' . $maxHeight . '"><img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] .'" border="0" alt="' . str_replace('"', '"', $key) . '" /></td>' . "\n";
!
! $str2 .= "\t\t" . '<td align="center" nowrap="nowrap">' . $key . '</td>' . "\n";
!
if (is_integer($i / $perLines) || $i == $smilCnt)
{
--- 248,260 ----
if ($target == 'help')
! {
! $str1 .= "\t\t" . '<td align="center" width="'. $maxWidth . '" height="' . $maxHeight . '"><a href="#" onclick="pmcSmiley2Input(\'' . addslashes(str_replace('"', '"', $key)) . '\'); return false"><img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] .'" border="0" alt="' . str_replace('"', '"', $key) . '" /></a></td>' . "\n";
! $str2 .= "\t\t" . '<td align="center" nowrap="nowrap" class="tabTitle"><span class="success">' . $key . '</span></td>' . "\n";
! }
else
+ {
$str1 .= "\t\t" . '<td align="center" width="'. $maxWidth . '" height="' . $maxHeight . '"><img src="images/smilies/' . $prop[0] . '" width="' . $prop[1] . '" height="' . $prop[2] .'" border="0" alt="' . str_replace('"', '"', $key) . '" /></td>' . "\n";
! $str2 .= "\t\t" . '<td align="center" nowrap="nowrap">' . $key . '</td>' . "\n";
! }
if (is_integer($i / $perLines) || $i == $smilCnt)
{
|