Firefox PHP

Smiley mod defaults

Posted by Chris Eaton 
Smiley mod defaults
July 22, 2004 05:37PM
I've added some defaults to new installations for the smileys module, so new installs will always have smileys defined. Some of the choices I made may not be that great, because I am not well versed in advanced smiley lore. If you have suggestions to improve it, let me know.

These settings are not added in an upgrade installation, so as to not erase any settings you may already have. If you want to get the smiley settings into an existing installation, run the following query. You can use something like phpMyAdmin to do this.

INSERT INTO `phorum_settings` (`name`, `type`, `data`) VALUES ('mod_smileys','S','a:21:{i:0;a:4:{s:6:\"search\";s:2:\"B)\";s:6:\"smiley\";s:8:\"cool.gif\";s:3:\"alt\";s:11:\"cool smiley\";s:4:\"uses\";s:1:\"2\";}i:1;a:4:{s:6:\"search\";s:2:\":)\";s:6:\"smiley\";s:11:\"smilie1.gif\";s:3:\"alt\";s:14:\"smiling smiley\";s:4:\"uses\";s:1:\"2\";}i:2;a:4:{s:6:\"search\";s:2:\":(\";s:6:\"smiley\";s:11:\"smilie2.gif\";s:3:\"alt\";s:10:\"sad smiley\";s:4:\"uses\";s:1:\"2\";}i:3;a:4:{s:6:\"search\";s:2:\";)\";s:6:\"smiley\";s:11:\"smilie3.gif\";s:3:\"alt\";s:14:\"winking smiley\";s:4:\"uses\";s:1:\"2\";}i:4;a:4:{s:6:\"search\";s:2:\":o\";s:6:\"smiley\";s:11:\"smilie4.gif\";s:3:\"alt\";s:14:\"yawning smiley\";s:4:\"uses\";s:1:\"2\";}i:5;a:4:{s:6:\"search\";s:2:\":D\";s:6:\"smiley\";s:11:\"smilie5.gif\";s:3:\"alt\";s:15:\"grinning smiley\";s:4:\"uses\";s:1:\"2\";}i:6;a:4:{s:6:\"search\";s:2:\":P\";s:6:\"smiley\";s:11:\"smilie6.gif\";s:3:\"alt\";s:26:\"tongue sticking out smiley\";s:4:\"uses\";s:1:\"2\";}i:7;a:4:{s:6:\"search\";s:3:\"B)-\";s:6:\"smiley\";s:11:\"smilie7.gif\";s:3:\"alt\";s:14:\"smoking smiley\";s:4:\"uses\";s:1:\"2\";}i:8;a:4:{s:6:\"search\";s:3:\"8-)\";s:6:\"smiley\";s:11:\"smilie8.gif\";s:3:\"alt\";s:18:\"eye rolling smiley\";s:4:\"uses\";s:1:\"2\";}i:9;a:4:{s:6:\"search\";s:2:\":X\";s:6:\"smiley\";s:11:\"smilie9.gif\";s:3:\"alt\";s:12:\"angry smiley\";s:4:\"uses\";s:1:\"2\";}i:10;a:4:{s:6:\"search\";s:3:\"(:D\";s:6:\"smiley\";s:12:\"smiley12.gif\";s:3:\"alt\";s:23:\"smiling bouncing smiley\";s:4:\"uses\";s:1:\"2\";}i:11;a:4:{s:6:\"search\";s:4:\">:D<\";s:6:\"smiley\";s:12:\"smiley14.gif\";s:3:\"alt\";s:16:\"thumbs up smiley\";s:4:\"uses\";s:1:\"2\";}i:12;a:4:{s:6:\"search\";s:4:\":)-D\";s:6:\"smiley\";s:12:\"smiley15.gif\";s:3:\"alt\";s:17:\"smileys with beer\";s:4:\"uses\";s:1:\"2\";}i:13;a:4:{s:6:\"search\";s:3:\":)o\";s:6:\"smiley\";s:12:\"smiley16.gif\";s:3:\"alt\";s:15:\"drinking smiley\";s:4:\"uses\";s:1:\"2\";}i:14;a:4:{s:6:\"search\";s:2:\":?\";s:6:\"smiley\";s:12:\"smiley17.gif\";s:3:\"alt\";s:12:\"moody smiley\";s:4:\"uses\";s:1:\"2\";}i:15;a:4:{s:6:\"search\";s:4:\"(td)\";s:6:\"smiley\";s:12:\"smiley23.gif\";s:3:\"alt\";s:11:\"thumbs down\";s:4:\"uses\";s:1:\"2\";}i:16;a:4:{s:6:\"search\";s:4:\"(tu)\";s:6:\"smiley\";s:12:\"smiley24.gif\";s:3:\"alt\";s:9:\"thumbs up\";s:4:\"uses\";s:1:\"2\";}i:17;a:4:{s:6:\"search\";s:4:\"(:P)\";s:6:\"smiley\";s:12:\"smiley25.gif\";s:3:\"alt\";s:39:\"spinning smiley sticking its tongue out\";s:4:\"uses\";s:1:\"2\";}i:18;a:4:{s:6:\"search\";s:2:\"X(\";s:6:\"smiley\";s:7:\"hot.gif\";s:3:\"alt\";s:10:\"hot smiley\";s:4:\"uses\";s:1:\"2\";}i:19;a:4:{s:6:\"search\";s:2:\":S\";s:6:\"smiley\";s:12:\"smilie11.gif\";s:3:\"alt\";s:15:\"confused smiley\";s:4:\"uses\";s:1:\"2\";}i:20;a:4:{s:6:\"search\";s:3:\"::o\";s:6:\"smiley\";s:12:\"smilie10.gif\";s:3:\"alt\";s:18:\"eye popping smiley\";s:4:\"uses\";s:1:\"2\";}}');
Re: Smiley mod defaults
November 07, 2004 05:29PM
Hi,
I'm trying out the smiley mod right now.
The problem is, if you have smileys defined like you did with :)-D it's not correctly replaced by .

Instead it looks like -D.

This can be solved by optimizing the order of defined smilies. For me the following works fine:

a:24:{i:0;a:4:{s:6:"search";s:3:"B)-";s:6:"smiley";s:11:"smilie7.gif";s:3:"alt";s:14:"smoking smiley";s:4:"uses";s:1:"0";}i:1;a:4:{s:6:"search";s:2:"B)";s:6:"smiley";s:8:"cool.gif";s:3:"alt";s:11:"cool smiley";s:4:"uses";s:1:"0";}i:2;a:4:{s:6:"search";s:4:":)-D";s:6:"smiley";s:12:"smiley15.gif";s:3:"alt";s:17:"smileys with beer";s:4:"uses";s:1:"0";}i:3;a:4:{s:6:"search";s:3:":)o";s:6:"smiley";s:12:"smiley16.gif";s:3:"alt";s:15:"drinking smiley";s:4:"uses";s:1:"0";}i:4;a:4:{s:6:"search";s:2:":)";s:6:"smiley";s:11:"smilie1.gif";s:3:"alt";s:14:"smiling smiley";s:4:"uses";s:1:"0";}i:5;a:4:{s:6:"search";s:2:":(";s:6:"smiley";s:11:"smilie2.gif";s:3:"alt";s:10:"sad smiley";s:4:"uses";s:1:"0";}i:6;a:4:{s:6:"search";s:2:";)";s:6:"smiley";s:11:"smilie3.gif";s:3:"alt";s:14:"winking smiley";s:4:"uses";s:1:"0";}i:7;a:4:{s:6:"search";s:3:"::o";s:6:"smiley";s:12:"smilie10.gif";s:3:"alt";s:18:"eye popping smiley";s:4:"uses";s:1:"0";}i:8;a:4:{s:6:"search";s:2:":o";s:6:"smiley";s:11:"smilie4.gif";s:3:"alt";s:14:"yawning smiley";s:4:"uses";s:1:"0";}i:9;a:4:{s:6:"search";s:4:">:D<";s:6:"smiley";s:12:"smiley14.gif";s:3:"alt";s:16:"thumbs up smiley";s:4:"uses";s:1:"0";}i:10;a:4:{s:6:"search";s:3:"(:D";s:6:"smiley";s:12:"smiley12.gif";s:3:"alt";s:23:"smiling bouncing smiley";s:4:"uses";s:1:"0";}i:11;a:4:{s:6:"search";s:2:":D";s:6:"smiley";s:11:"smilie5.gif";s:3:"alt";s:15:"grinning smiley";s:4:"uses";s:1:"0";}i:12;a:4:{s:6:"search";s:4:"(:P)";s:6:"smiley";s:12:"smiley25.gif";s:3:"alt";s:39:"spinning smiley sticking its tongue out";s:4:"uses";s:1:"0";}i:13;a:4:{s:6:"search";s:2:":P";s:6:"smiley";s:11:"smilie6.gif";s:3:"alt";s:26:"tongue sticking out smiley";s:4:"uses";s:1:"0";}i:14;a:4:{s:6:"search";s:3:"8-)";s:6:"smiley";s:11:"smilie8.gif";s:3:"alt";s:18:"eye rolling smiley";s:4:"uses";s:1:"0";}i:15;a:4:{s:6:"search";s:2:":X";s:6:"smiley";s:11:"smilie9.gif";s:3:"alt";s:12:"angry smiley";s:4:"uses";s:1:"0";}i:16;a:4:{s:6:"search";s:2:":?";s:6:"smiley";s:12:"smiley17.gif";s:3:"alt";s:12:"moody smiley";s:4:"uses";s:1:"0";}i:17;a:4:{s:6:"search";s:4:"(td)";s:6:"smiley";s:12:"smiley23.gif";s:3:"alt";s:11:"thumbs down";s:4:"uses";s:1:"0";}i:18;a:4:{s:6:"search";s:4:"(tu)";s:6:"smiley";s:12:"smiley24.gif";s:3:"alt";s:9:"thumbs up";s:4:"uses";s:1:"0";}i:19;a:4:{s:6:"search";s:2:"X(";s:6:"smiley";s:7:"hot.gif";s:3:"alt";s:10:"hot smiley";s:4:"uses";s:1:"0";}i:20;a:4:{s:6:"search";s:2:":S";s:6:"smiley";s:12:"smilie11.gif";s:3:"alt";s:15:"confused smiley";s:4:"uses";s:1:"0";}s:6:"prefix";s:8:"smileys/";i:21;a:4:{s:6:"search";s:3:":-)";s:6:"smiley";s:11:"smilie1.gif";s:3:"alt";s:14:"smiling smiley";s:4:"uses";s:1:"0";}i:22;a:4:{s:6:"search";s:3:";-)";s:6:"smiley";s:11:"smilie3.gif";s:3:"alt";s:14:"winking smiley";s:4:"uses";s:1:"0";}}

There's another problem with the smiley >:D<.

It's not correctly replaced because of the brackets, which where changed to &gt; and &lt; before the smiley mod starts to work.

Replacing
$smiley_subject_key[] = $smiley['search'];
and
$smiley_body_key[] = $smiley['search'];
with
$smiley_subject_key[] = htmlentities($smiley['search']);
and
$smiley_body_key[] = htmlentities($smiley['search']);
in the module solves this problem.

--
Clemens Weiß
Webplain.de
Re: Smiley mod defaults
July 15, 2005 10:59AM
The same problems in 5.0.16.

I suggest sorting smiley keys by the length descending before replacing, so that shorter smileys do not get replaced in longer smileys keys.

This goes in smileys.php, just after filling keys and values arrays (line 56 in 5.0.16):

if ($do_body) {
	array_multisort(array_map('strlen', $smiley_subject_key),
		SORT_DESC,
		$smiley_subject_key,
		$smiley_subject_value,
		$smiley_body_key,
		$smiley_body_value);
} else {
	array_multisort(array_map('strlen', $smiley_subject_key),
		SORT_DESC,
		$smiley_subject_key,
		$smiley_subject_value);
}

This way smileys order is still descending after settings change, but of course it would be more efficient to sort them in settings code.



Edited 1 time(s). Last edit at 07/15/2005 11:03AM by kAtremer.
Re: Smiley mod defaults
September 07, 2005 04:16PM
Hi kAtremer.

Your suggestion does cover most of the problem, but you will still have to convert the > and < stuff in smiley definitions. Here is my working copy of smileys.php:

<?php

if(!defined("PHORUM"))
   return;

function phorum_mod_smileys ( $data )
{
   // early out if we're not enabled
   if ( ! isset ( $GLOBALS['PHORUM']['mod_smileys'] ) )
   {
      return $data;
   }
   
   if(isset($GLOBALS['PHORUM']['mod_smileys']['prefix']))
   {
      $prefix = $GLOBALS['PHORUM']['mod_smileys']['prefix']; // quicker than array lookups
   }
   else
   {
      $prefix = "smileys/";
   }
   
   $do_work = $do_subject = $do_body = false;
   $smiley_body_key = $smiley_subject_key = $smiley_body_value = $smiley_subject_value = array();
   
   foreach ( $GLOBALS['PHORUM']['mod_smileys'] as $key=>$smiley )
   {
      if ( ! is_long ( $key ) )
      {
         continue;
      }
      
      $do_work = true;
      
      $smiley['alt'] = htmlspecialchars ( $smiley['alt'] );
      
      switch ( $smiley['uses'] )
      {
      case 1:    // subject only replace
         $do_subject = true;
         $smiley_subject_key[] = $smiley['search'];
         $smiley_subject_value[] = '<img title="'.$smiley['alt'].'" alt="'.$smiley['alt'].'" src="'.$prefix.$smiley['smiley'].'" />';
         break;
         
      case 2:    // both replace
         $do_subject = true;
         $smiley_subject_key[] = $smiley['search'];
         $smiley_subject_value[] = '<img title="'.$smiley['alt'].'" alt="'.$smiley['alt'].'" src="'.$prefix.$smiley['smiley'].'" />';
         // ... continues with body-replace
         
      case 0:      // body only replace
      default:   // in old versions it wasn't set, so body only replace
         $do_body = true;
         $smiley_body_key[] = $smiley['search'];
         $smiley_body_value[] = '<img title="'.$smiley['alt'].'" alt="'.$smiley['alt'].'" src="'.$prefix.$smiley['smiley'].'" />';
      }
      
      unset ( $smiley );
   }
   
   unset ( $smiley, $prefix );
   
   // early out if no smileys actually exist
   if ( $do_work !== true )
   {
      return $data;
   }
   
   
   
   if ($do_subject)
   {
      array_multisort(array_map('strlen', $smiley_subject_key), SORT_DESC,
      $smiley_subject_key,
      $smiley_subject_value);
   }
   if ($do_body)
   {
      array_multisort(array_map('strlen', $smiley_body_key), SORT_DESC,
      $smiley_body_key,
      $smiley_body_value);
   }
   
   // replace smiley codes by smiley images
   foreach ( $data as $key=>$message )
   {
      if ( $do_subject && isset ( $message['subject'] ) )
      {
         $message['subject'] = str_replace (array('&gt;','&lt;'),array('>','<'), $message['subject'] );
         $data[$key]['subject'] = str_replace($smiley_subject_key,$smiley_subject_value,$message['subject']);
      }
      
      if ( $do_body && isset ( $message['body'] ) )
      {
         $message['body'] = str_replace (array('&gt;','&lt;'),array('>','<'), $message['body'] );
         $data[$key]['body'] = str_replace($smiley_body_key,$smiley_body_value,$message['body']);
      }
      
      unset ( $message, $key );
   }
   
   unset ( $message, $key );
   
   return $data;
}

?>

Regards, Ulf Dunkel
Re: Smiley mod defaults
March 13, 2007 05:01PM
I see that the current smiley mod for 5.1.20 uses this sorting by string length. I understand the need for this sort when replacing text. What I would like to see is an option for different sorts when displaying the list of smileys on the mod settings page, and in the editor_tools mod.

I have probably 100 smileys available on my forum, and managing them when they are scrambled up in the admin is a headache. Likewise, as a user, finding the right smiley from a huge list with no seeming order is a challenge.

I would like settings.php to have the option of sorting by filename or replacement string.

I would like the editor_tools to sort by replacement string.

I would like the current sort-by-length to remain in force when replacing text.

I am studying the code to see if I can hack it myself, but if anyone more skilled than me would like to give me a hand, please do.
Re: Smiley mod defaults
March 13, 2007 06:27PM
Before anyone else suggests it, it occurred to me that I could open a ticket on this... but I thought it might be better to discuss the feasability of it first, and what the best way to attack the problem might be.

Also, I should explain my reason for wanting it in the module admin settings more:

As I add new smileys, I want to make sure that I have created replacement text for all of them and not missed anything. I was thinking if the list was sorted by filename it would be easier to compare my directory listing against the replacement list. Perhaps a better solution would be for the module to identify files in the directory which lack an entry?

The other reason is if I want to edit or delete an existing entry, it would be much easier to find on the list if it was sorted alphabetically. (However, Ctrl-F will do in that case)

As for the editor_tools module sorting, I don't know if that is best addressed in that module or the smiley one?
Re: Smiley mod defaults
March 13, 2007 06:36PM
If you want 100 smileys and need CTRL-F to find them in the admin, then you have too many smileys IMO ;-)

I don't think that the core developers will take on the project to get all these wishes implemented in the smileys replacement mod. For editor_tools, there won't be any changes either in the way in which the smileys are ordered (unless things are changed in the core smileys module after all).

For the editor_tools, you can also implement your own smileys button implementation. You can then disable the default editor_tools smileys button and only show your own implementation. The editor_tools module is setup in such way that it is extensible from other modules.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Smiley mod defaults
March 13, 2007 09:16PM
Maurice, I appreciate all of the work you've done, and want to thank you for it. We all use Phorum in different ways. It may seem frivolous to you, but I think this is a reasonable improvement, not requiring a lot of effort. In fact...

I *think* I have come up with a simple hack to smileyslib.php that fixes most of my issues (including the editor_tools) without causing any new ones. It seems to work fine in testing. It consists of re-sorting $modinfo["smileys"] by name just before storing. (but after $modinfo["replacements"] is stored)

Here is my patch for smileyslib.php:

220a221,223
>     // changed to sort by name for better list displays
>     uasort($modinfo["smileys"],'phorum_mod_smileys_sortbyname');
>
225a229,240
>     }
> }
>
> /**
>  * A callback function for sorting smileys by their search string.
>  * usage: uasort($array_of_smileys, 'phorum_mod_smileys_sortbyname');
>  */
> function phorum_mod_smileys_sortbyname($a, $b) {
>     if (isset($a["search"]) && isset($b["search"])) {
>         return strcmp($a["search"], $b["search"]);
>     } else {
>         return 0;
Re: Smiley mod defaults
December 10, 2007 12:59PM
Just a bump/nudge...

I applied this same patch to 5.2.2. It still works great. Maybe it's just been overlooked?
Re: Smiley mod defaults
December 10, 2007 05:56PM
it's just not a hack that is accepted for the smileys mod. What you think is the best sorting mechanism for the smileys might not be what others think is the best one (I disagree on it for example). So ultimately, we should not have hacks like this one, but sortable columns in the admin interface, so the admin can choose a sorting mechanism for himself. For now, if you want the sorting to be different, you'll have to implement this hack in the new code as well.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Sorry, only registered users may post in this forum.

Click here to login