2013-08-29 21:00:56 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: Smileybutton
|
2013-09-07 12:35:00 -04:00
|
|
|
* Description: Adds a smileybutton to the Inputbox
|
2013-08-29 21:00:56 -04:00
|
|
|
* Version: 0.1
|
2013-09-07 12:35:00 -04:00
|
|
|
* Author: Johannes Schwab <http://friendica.jschwab.mooo.com/profile/ddorian>
|
2013-08-29 21:00:56 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
function smileybutton_install() {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Register hooks for jot_tool and plugin_settings
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
register_hook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button');
|
|
|
|
register_hook('plugin_settings', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings');
|
|
|
|
register_hook('plugin_settings_post', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings_post');
|
|
|
|
|
|
|
|
logger("installed smileybutton");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function smileybutton_uninstall() {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Delet registered hooks
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
unregister_hook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button');
|
|
|
|
unregister_hook('plugin_settings', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings');
|
|
|
|
unregister_hook('plugin_settings_post', 'addon/smileybutton/smileybutton.php', 'smileybutton_settings_post');
|
|
|
|
|
|
|
|
logger("removed smileybutton");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function show_button($a, &$b) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Check if it is a local user and he has enabled smileybutton
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-09-07 12:35:00 -04:00
|
|
|
if(! local_user()) {
|
|
|
|
$nobutton = false;
|
|
|
|
} else {
|
|
|
|
$nobutton = get_pconfig(local_user(), 'smileybutton', 'nobutton');
|
|
|
|
}
|
2013-08-29 21:00:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Prepare the Smilie-Arrays
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2013-09-07 12:35:00 -04:00
|
|
|
* I have copied this from /include/text.php, removed dobles
|
|
|
|
* and some escapes.
|
2013-08-29 21:00:56 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$texts = array(
|
|
|
|
'<3',
|
|
|
|
'</3',
|
|
|
|
':-)',
|
|
|
|
';-)',
|
|
|
|
':-(',
|
|
|
|
':-P',
|
|
|
|
':-X',
|
|
|
|
':-D',
|
|
|
|
':-O',
|
|
|
|
'\\\\o/',
|
|
|
|
'O_o',
|
|
|
|
":\'(",
|
|
|
|
":-!",
|
|
|
|
":-/",
|
|
|
|
":-[",
|
|
|
|
"8-)",
|
|
|
|
':beer',
|
|
|
|
':coffee',
|
|
|
|
':facepalm',
|
|
|
|
':like',
|
|
|
|
':dislike',
|
|
|
|
'~friendica',
|
|
|
|
'red#'
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$icons = array(
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-cool.gif" alt="8-)" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":beer" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/coffee.gif" alt=":coffee" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/like.gif" alt=":like" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/dislike.gif" alt=":dislike" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" />',
|
|
|
|
'<img class="smiley" src="' . $a->get_baseurl() . '/images/rhash-16.png" alt="red" />'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Call hooks to get aditional smileies from other addons
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$params = array('texts' => $texts, 'icons' => $icons, 'string' => ""); //changed
|
2013-08-31 07:50:02 -04:00
|
|
|
call_hooks('smilie', $params);
|
2013-08-29 21:00:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Generate html for smileylist
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-08-31 07:50:02 -04:00
|
|
|
$s = "\t<table class=\"smiley-preview\"><tr>\n";
|
2013-08-29 21:00:56 -04:00
|
|
|
for($x = 0; $x < count($params['texts']); $x ++) {
|
|
|
|
$icon = $params['icons'][$x];
|
|
|
|
$icon = str_replace('/>', 'onclick="smileybutton_addsmiley(\'' . $params['texts'][$x] . '\')"/>', $icon);
|
2013-08-31 07:50:02 -04:00
|
|
|
$icon = str_replace('class="smiley"', 'class="smiley_preview"', $icon);
|
|
|
|
$s .= "<td>" . $icon . "</td>";
|
|
|
|
if (($x+1) % (sqrt(count($params['texts']))+1) == 0) {
|
|
|
|
$s .= "</tr>\n\t<tr>";
|
2013-08-29 21:00:56 -04:00
|
|
|
}
|
|
|
|
}
|
2013-08-31 07:50:02 -04:00
|
|
|
$s .= "\t</tr></table>\n";
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Add css to page
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/smileybutton/smileybutton.css' . '" media="all" />' . "\r\n";
|
2013-08-29 21:00:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Add the button to the Inputbox
|
|
|
|
*
|
|
|
|
*/
|
2013-09-07 12:35:00 -04:00
|
|
|
if (! $nobutton) {
|
|
|
|
$b = "<div id=\"profile-smiley-wrapper\" style=\"display: block;\" >\n";
|
2013-09-08 04:12:53 -04:00
|
|
|
$b .= "\t<img src=\"" . $a->get_baseurl() . "/addon/smileybutton/icon.gif\" onclick=\"toggle_smileybutton()\" alt=\"smiley\">\n";
|
2013-09-07 12:35:00 -04:00
|
|
|
$b .= "\t</div>\n";
|
|
|
|
}
|
2013-08-29 21:00:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2013-09-07 12:35:00 -04:00
|
|
|
* Write the smileies to an (hidden) div
|
2013-08-29 21:00:56 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-09-07 12:35:00 -04:00
|
|
|
if ($nobutton) {
|
|
|
|
$b .= "\t<div id=\"smileybutton\">\n";
|
|
|
|
} else {
|
|
|
|
$b .= "\t<div id=\"smileybutton\" style=\"display:none;\">\n";
|
|
|
|
}
|
2013-08-29 21:00:56 -04:00
|
|
|
$b .= $s . "\n";
|
|
|
|
$b .= "</div>\n";
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Function to show and hide the smiley-list in the hidden div
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$b .= "<script>\n";
|
2013-09-07 12:35:00 -04:00
|
|
|
|
|
|
|
if (! $nobutton) {
|
|
|
|
$b .= " smileybutton_show = 0;\n";
|
|
|
|
$b .= " function toggle_smileybutton() {\n";
|
|
|
|
$b .= " if (! smileybutton_show) {\n";
|
|
|
|
$b .= " $(\"#smileybutton\").show();\n";
|
|
|
|
$b .= " smileybutton_show = 1;\n";
|
|
|
|
$b .= " } else {\n";
|
|
|
|
$b .= " $(\"#smileybutton\").hide();\n";
|
|
|
|
$b .= " smileybutton_show = 0;\n";
|
|
|
|
$b .= " }}\n";
|
|
|
|
}
|
2013-08-29 21:00:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Function to add the chosen smiley to the inputbox
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$b .= " function smileybutton_addsmiley(text) {\n";
|
2013-08-31 07:50:02 -04:00
|
|
|
$b .= " if(plaintext == 'none') {\n";
|
|
|
|
$b .= " var v = $(\"#profile-jot-text\").val();\n";
|
|
|
|
$b .= " v = v + text;\n";
|
|
|
|
$b .= " $(\"#profile-jot-text\").val(v);\n";
|
|
|
|
$b .= " $(\"#profile-jot-text\").focus();\n";
|
|
|
|
$b .= " } else {\n";
|
|
|
|
$b .= " var v = tinymce.activeEditor.getContent();\n";
|
|
|
|
$b .= " v = v + text;\n";
|
|
|
|
$b .= " tinymce.activeEditor.setContent(v);\n";
|
|
|
|
$b .= " tinymce.activeEditor.focus();\n";
|
|
|
|
$b .= " }\n";
|
2013-08-29 21:00:56 -04:00
|
|
|
$b .= " }\n";
|
|
|
|
$b .= "</script>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Set the configuration
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
function smileybutton_settings_post($a,$post) {
|
|
|
|
if(! local_user())
|
|
|
|
return;
|
|
|
|
if($_POST['smileybutton-submit'])
|
2013-09-07 12:35:00 -04:00
|
|
|
set_pconfig(local_user(),'smileybutton','nobutton',intval($_POST['smileybutton']));
|
|
|
|
|
2013-08-29 21:00:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Add configuration-dialog to form
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
function smileybutton_settings(&$a,&$s) {
|
|
|
|
|
|
|
|
if(! local_user())
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Add our stylesheet to the page so we can make our settings look nice */
|
|
|
|
|
|
|
|
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/smileybutton/smileybutton.css' . '" media="all" />' . "\r\n";
|
|
|
|
|
|
|
|
/* Get the current state of our config variable */
|
|
|
|
|
2013-09-07 12:35:00 -04:00
|
|
|
$nobutton = get_pconfig(local_user(),'smileybutton','nobutton');
|
|
|
|
$checked = (($nobutton) ? ' checked="checked" ' : '');
|
2013-08-29 21:00:56 -04:00
|
|
|
|
|
|
|
/* Add some HTML to the existing form */
|
|
|
|
|
|
|
|
$s .= '<div class="settings-block">';
|
|
|
|
$s .= '<h3>Smileybutton settings</h3>';
|
|
|
|
$s .= '<div id="smileybutton-enable-wrapper">';
|
2013-09-07 12:35:00 -04:00
|
|
|
|
|
|
|
$s .= 'You can hide the button and show the smilies directly.<br /><br />';
|
|
|
|
|
|
|
|
$s .= '<label id="smileybutton-enable-label" for="smileybutton-nobutton-checkbox">Hide the button</label>';
|
|
|
|
$s .= '<input id="smileybutton-nobutton-checkbox" type="checkbox" name="smileybutton" value="1" ' . $checked . '/>';
|
|
|
|
|
2013-08-29 21:00:56 -04:00
|
|
|
$s .= '</div><div class="clear"></div>';
|
|
|
|
|
|
|
|
/* provide a submit button */
|
|
|
|
|
|
|
|
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="smileybutton-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
|
|
|
|
|
|
|
|
}
|