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
|
2015-02-07 08:51:10 -05:00
|
|
|
* Version: 0.2
|
|
|
|
* Author: Johannes Schwab <https://friendica.jschwab.org/profile/ddorian>
|
2013-08-29 21:00:56 -04:00
|
|
|
*/
|
2018-01-16 19:51:12 -05:00
|
|
|
use Friendica\Core\Addon;
|
2013-08-29 21:00:56 -04:00
|
|
|
|
|
|
|
function smileybutton_install() {
|
2018-01-15 08:15:33 -05:00
|
|
|
//Register hooks
|
2018-01-16 19:51:12 -05:00
|
|
|
Addon::registerHook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button');
|
2018-01-15 08:15:33 -05:00
|
|
|
|
2013-08-29 21:00:56 -04:00
|
|
|
logger("installed smileybutton");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function smileybutton_uninstall() {
|
2015-02-07 08:51:10 -05:00
|
|
|
//Delet registered hooks
|
2018-01-16 19:51:12 -05:00
|
|
|
Addon::unregisterHook('jot_tool', 'addon/smileybutton/smileybutton.php', 'show_button');
|
2015-02-07 08:51:10 -05:00
|
|
|
|
2013-08-29 21:00:56 -04:00
|
|
|
logger("removed smileybutton");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-28 18:39:29 -04:00
|
|
|
function show_button(Friendica\App $a, &$b) {
|
2015-02-07 08:51:10 -05:00
|
|
|
// Disable if theme is quattro
|
|
|
|
// TODO add style for quattro
|
2018-04-28 18:39:29 -04:00
|
|
|
if ($a->getCurrentTheme() == 'quattro')
|
2015-02-07 08:51:10 -05:00
|
|
|
return;
|
2013-08-29 21:00:56 -04:00
|
|
|
|
2015-02-07 08:51:10 -05:00
|
|
|
// Disable for mobile because most mobiles have a smiley key for ther own
|
|
|
|
if ($a->is_mobile || $a->is_tablet)
|
|
|
|
return;
|
2013-08-29 21:00:56 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2015-02-07 08:51:10 -05:00
|
|
|
* I have copied this from /include/text.php, removed doubles
|
|
|
|
* and escaped them.
|
2013-08-29 21:00:56 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-01-15 08:15:33 -05:00
|
|
|
$texts = [
|
|
|
|
'<3',
|
|
|
|
'</3',
|
|
|
|
':-)',
|
|
|
|
';-)',
|
|
|
|
':-(',
|
|
|
|
':-P',
|
|
|
|
':-X',
|
|
|
|
':-D',
|
|
|
|
':-O',
|
|
|
|
'\\\\o/',
|
|
|
|
'O_o',
|
|
|
|
":\'(",
|
|
|
|
":-!",
|
|
|
|
":-/",
|
|
|
|
":-[",
|
2013-08-29 21:00:56 -04:00
|
|
|
"8-)",
|
2018-01-15 08:15:33 -05:00
|
|
|
':beer',
|
|
|
|
':coffee',
|
2013-08-29 21:00:56 -04:00
|
|
|
':facepalm',
|
|
|
|
':like',
|
|
|
|
':dislike',
|
|
|
|
'~friendica',
|
|
|
|
'red#'
|
|
|
|
|
2018-01-15 08:15:33 -05:00
|
|
|
];
|
2013-08-29 21:00:56 -04:00
|
|
|
|
2018-01-15 08:15:33 -05:00
|
|
|
$icons = [
|
2018-10-09 14:13:22 -04:00
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-heart.gif" alt="<3" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-brokenheart.gif" alt="</3" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-smile.gif" alt=":-)" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-wink.gif" alt=";-)" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-frown.gif" alt=":-(" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-tongue-out.gif" alt=":-P" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-kiss.gif" alt=":-X" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-laughing.gif" alt=":-D" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-surprised.gif" alt=":-O" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-Oo.gif" alt="O_o" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-cry.gif" alt=":\'(" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-undecided.gif" alt=":-/" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-embarassed.gif" alt=":-[" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-cool.gif" alt="8-)" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/beer_mug.gif" alt=":beer" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/coffee.gif" alt=":coffee" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/like.gif" alt=":like" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/dislike.gif" alt=":dislike" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/friendica-16.png" alt="~friendica" />',
|
|
|
|
'<img class="smiley" src="' . $a->getBaseURL() . '/images/rhash-16.png" alt="red" />'
|
2018-01-15 08:15:33 -05:00
|
|
|
];
|
|
|
|
|
2015-02-07 08:51:10 -05:00
|
|
|
// Call hooks to get aditional smileies from other addons
|
2018-01-15 08:15:33 -05:00
|
|
|
$params = ['texts' => $texts, 'icons' => $icons, 'string' => ""]; //changed
|
2018-01-21 00:11:18 -05:00
|
|
|
Addon::callHooks('smilie', $params);
|
2013-08-29 21:00:56 -04:00
|
|
|
|
2015-02-07 08:51:10 -05:00
|
|
|
//Generate html for smiley list
|
|
|
|
$s = "<table class=\"smiley-preview\"><tr>\n\t";
|
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
|
|
|
}
|
|
|
|
}
|
2015-02-07 08:51:10 -05:00
|
|
|
$s .= "\t</tr></table>";
|
2013-08-29 21:00:56 -04:00
|
|
|
|
2015-02-07 08:51:10 -05:00
|
|
|
//Add css to header
|
2018-04-28 18:39:29 -04:00
|
|
|
$css_file = 'addon/smileybutton/view/' . $a->getCurrentTheme() . '.css';
|
2018-01-15 08:15:33 -05:00
|
|
|
if (! file_exists($css_file))
|
2015-02-07 08:51:10 -05:00
|
|
|
$css_file = 'addon/smileybutton/view/default.css';
|
2018-10-09 14:13:22 -04:00
|
|
|
$css_url = $a->getBaseURL().'/'.$css_file;
|
2013-09-07 12:35:00 -04:00
|
|
|
|
2015-02-07 08:51:10 -05:00
|
|
|
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.$css_url.'" media="all" />'."\r\n";
|
2013-09-07 12:35:00 -04:00
|
|
|
|
2018-01-15 08:15:33 -05:00
|
|
|
|
2015-02-07 08:51:10 -05:00
|
|
|
//Get the correct image for the theme
|
2018-04-28 18:39:29 -04:00
|
|
|
$image = 'addon/smileybutton/view/' . $a->getCurrentTheme() . '.png';
|
2018-01-15 08:15:33 -05:00
|
|
|
if (! file_exists($image))
|
2015-02-07 08:51:10 -05:00
|
|
|
$image = 'addon/smileybutton/view/default.png';
|
2018-10-09 14:13:22 -04:00
|
|
|
$image_url = $a->getBaseURL().'/'.$image;
|
2015-02-07 08:51:10 -05:00
|
|
|
|
|
|
|
//Add the hmtl and script to the page
|
|
|
|
$b = <<< EOT
|
|
|
|
<div id="profile-smiley-wrapper" style="display: block;" >
|
|
|
|
<img src="$image_url" class="smiley_button" onclick="toggle_smileybutton()" alt="smiley">
|
2016-02-05 15:25:50 -05:00
|
|
|
<div id="smileybutton" style="display:none;">
|
|
|
|
$s
|
|
|
|
</div>
|
2015-02-07 08:51:10 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
var smileybutton_is_shown = 0;
|
|
|
|
function toggle_smileybutton() {
|
|
|
|
if (! smileybutton_is_shown) {
|
|
|
|
$("#smileybutton").show();
|
|
|
|
smileybutton_is_shown = 1;
|
|
|
|
} else {
|
|
|
|
$("#smileybutton").hide();
|
|
|
|
smileybutton_is_shown = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-08-29 21:00:56 -04:00
|
|
|
|
2015-02-07 08:51:10 -05:00
|
|
|
function smileybutton_addsmiley(text) {
|
|
|
|
if(plaintext == "none") {
|
|
|
|
var v = $("#profile-jot-text").val();
|
|
|
|
v = v + text;
|
|
|
|
$("#profile-jot-text").val(v);
|
|
|
|
$("#profile-jot-text").focus();
|
|
|
|
} else {
|
|
|
|
var v = tinymce.activeEditor.getContent();
|
|
|
|
v = v + text;
|
|
|
|
tinymce.activeEditor.setContent(v);
|
|
|
|
tinymce.activeEditor.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
EOT;
|
2013-08-29 21:00:56 -04:00
|
|
|
}
|