2013-08-30 03:00:56 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: Smileybutton
|
2013-09-07 18:35:00 +02:00
|
|
|
* Description: Adds a smileybutton to the Inputbox
|
2021-02-08 17:02:34 +01:00
|
|
|
* Version: 1.0
|
2015-02-07 14:51:10 +01:00
|
|
|
* Author: Johannes Schwab <https://friendica.jschwab.org/profile/ddorian>
|
2021-02-08 17:02:34 +01:00
|
|
|
* Maintainer: Hypolite Petovan <https://friendica.mrpetovan.com/profile/hypolite>
|
2013-08-30 03:00:56 +02:00
|
|
|
*/
|
2021-02-08 17:02:34 +01:00
|
|
|
|
2022-06-23 07:45:39 +02:00
|
|
|
use Friendica\App;
|
2018-12-26 07:08:41 +01:00
|
|
|
use Friendica\Core\Hook;
|
2019-12-16 01:05:14 +01:00
|
|
|
use Friendica\DI;
|
2013-08-30 03:00:56 +02:00
|
|
|
|
2021-02-08 17:02:34 +01:00
|
|
|
function smileybutton_install()
|
|
|
|
{
|
2018-01-15 14:15:33 +01:00
|
|
|
//Register hooks
|
2021-02-08 17:02:34 +01:00
|
|
|
Hook::register('jot_tool', 'addon/smileybutton/smileybutton.php', 'smileybutton_jot_tool');
|
2013-08-30 03:00:56 +02:00
|
|
|
}
|
|
|
|
|
2023-01-14 03:16:09 +01:00
|
|
|
function smileybutton_jot_tool(string &$body)
|
2021-02-08 17:02:34 +01:00
|
|
|
{
|
2015-02-07 14:51:10 +01:00
|
|
|
// Disable if theme is quattro
|
2023-01-14 03:16:09 +01:00
|
|
|
if (DI::app()->getCurrentTheme() == 'quattro') {
|
2015-02-07 14:51:10 +01:00
|
|
|
return;
|
2021-02-08 17:02:34 +01:00
|
|
|
}
|
2013-08-30 03:00:56 +02:00
|
|
|
|
2021-02-08 17:02:34 +01:00
|
|
|
// Disable for mobile because they have a smiley key of their own
|
|
|
|
if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
|
2015-02-07 14:51:10 +01:00
|
|
|
return;
|
2021-02-08 17:02:34 +01:00
|
|
|
}
|
2013-08-30 03:00:56 +02:00
|
|
|
|
2021-02-08 17:02:34 +01:00
|
|
|
$texts = [
|
2018-01-15 14:15:33 +01:00
|
|
|
'<3',
|
|
|
|
'</3',
|
|
|
|
':-)',
|
|
|
|
';-)',
|
|
|
|
':-(',
|
|
|
|
':-P',
|
|
|
|
':-X',
|
|
|
|
':-D',
|
|
|
|
':-O',
|
|
|
|
'\\\\o/',
|
|
|
|
'O_o',
|
2021-02-08 17:02:34 +01:00
|
|
|
':\'(',
|
|
|
|
':-!',
|
|
|
|
':-/',
|
|
|
|
':-[',
|
|
|
|
'8-)',
|
2018-01-15 14:15:33 +01:00
|
|
|
':beer',
|
|
|
|
':coffee',
|
2013-08-30 03:00:56 +02:00
|
|
|
':facepalm',
|
|
|
|
':like',
|
|
|
|
':dislike',
|
2021-02-08 17:02:34 +01:00
|
|
|
'~friendica',
|
|
|
|
'red#',
|
2018-01-15 14:15:33 +01:00
|
|
|
];
|
2013-08-30 03:00:56 +02:00
|
|
|
|
2018-01-15 14:15:33 +01:00
|
|
|
$icons = [
|
2023-02-18 20:57:09 +01:00
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-heart.gif" alt="<3" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-brokenheart.gif" alt="</3" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-smile.gif" alt=":-)" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-wink.gif" alt=";-)" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-frown.gif" alt=":-(" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-kiss.gif" alt=":-X" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-laughing.gif" alt=":-D" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-surprised.gif" alt=":-O" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-Oo.gif" alt="O_o" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-cry.gif" alt=":\'(" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-undecided.gif" alt=":-/" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-embarassed.gif" alt=":-[" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-cool.gif" alt="8-)" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/beer_mug.gif" alt=":beer" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/coffee.gif" alt=":coffee" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/like.gif" alt=":like" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/dislike.gif" alt=":dislike" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/friendica-16.png" alt="~friendica" />',
|
|
|
|
'<img class="smiley" src="' . DI::baseUrl() . '/images/rhash-16.png" alt="red" />'
|
2018-01-15 14:15:33 +01:00
|
|
|
];
|
|
|
|
|
2015-02-07 14:51:10 +01:00
|
|
|
// Call hooks to get aditional smileies from other addons
|
2021-02-08 17:02:34 +01:00
|
|
|
$params = ['texts' => $texts, 'icons' => $icons, 'string' => '']; //changed
|
2018-12-26 07:08:41 +01:00
|
|
|
Hook::callAll('smilie', $params);
|
2013-08-30 03:00:56 +02:00
|
|
|
|
2015-02-07 14:51:10 +01:00
|
|
|
//Generate html for smiley list
|
2021-02-08 17:02:34 +01:00
|
|
|
$s = '<table class="smiley-preview"><tr>';
|
|
|
|
for ($x = 0; $x < count($params['texts']); $x++) {
|
2013-08-30 03:00:56 +02:00
|
|
|
$icon = $params['icons'][$x];
|
2021-02-08 17:02:34 +01:00
|
|
|
$s .= '<td onclick="smileybutton_addsmiley(\'' . $params['texts'][$x] . '\')">' . $icon . '</td>';
|
2023-10-20 17:50:31 +02:00
|
|
|
if (($x + 1) % (floor(sqrt(count($params['texts']))) + 1) == 0) {
|
2021-02-08 17:02:34 +01:00
|
|
|
$s .= '</tr><tr>';
|
2013-08-30 03:00:56 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-08 17:02:34 +01:00
|
|
|
$s .= '</tr></table>';
|
2013-08-30 03:00:56 +02:00
|
|
|
|
2015-02-07 14:51:10 +01:00
|
|
|
//Add css to header
|
2023-01-14 03:16:09 +01:00
|
|
|
$css_file = __DIR__ . '/view/' . DI::app()->getCurrentTheme() . '.css';
|
2021-02-08 17:02:34 +01:00
|
|
|
if (!file_exists($css_file)) {
|
2021-11-20 10:29:09 +01:00
|
|
|
$css_file = __DIR__ . '/view/default.css';
|
2021-02-08 17:02:34 +01:00
|
|
|
}
|
2013-09-07 18:35:00 +02:00
|
|
|
|
2021-02-08 17:02:34 +01:00
|
|
|
DI::page()->registerStylesheet($css_file);
|
2018-01-15 14:15:33 +01:00
|
|
|
|
2015-02-07 14:51:10 +01:00
|
|
|
//Get the correct image for the theme
|
2023-01-14 03:16:09 +01:00
|
|
|
$image = 'addon/smileybutton/view/' . DI::app()->getCurrentTheme() . '.png';
|
2021-02-08 17:02:34 +01:00
|
|
|
if (!file_exists($image)) {
|
2015-02-07 14:51:10 +01:00
|
|
|
$image = 'addon/smileybutton/view/default.png';
|
2021-02-08 17:02:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-18 20:57:09 +01:00
|
|
|
$image_url = DI::baseUrl() . '/' . $image;
|
2015-02-07 14:51:10 +01:00
|
|
|
|
|
|
|
//Add the hmtl and script to the page
|
2022-06-23 07:45:39 +02:00
|
|
|
$body = <<< EOT
|
2021-02-08 17:02:34 +01:00
|
|
|
<div id="profile-smiley-wrapper">
|
|
|
|
<button type="button" class="btn btn-link smiley_button" onclick="toggle_smileybutton()"><img src="$image_url" alt="smiley"></button>
|
|
|
|
<div id="smileybutton">
|
2016-02-05 21:25:50 +01:00
|
|
|
$s
|
|
|
|
</div>
|
2015-02-07 14:51:10 +01: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-30 03:00:56 +02:00
|
|
|
|
2015-02-07 14:51:10 +01:00
|
|
|
function smileybutton_addsmiley(text) {
|
2021-02-08 17:02:34 +01:00
|
|
|
var v = $("#profile-jot-text").val();
|
|
|
|
v = v + text;
|
|
|
|
$("#profile-jot-text").val(v).focus();
|
2015-02-07 14:51:10 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
EOT;
|
2013-08-30 03:00:56 +02:00
|
|
|
}
|
2021-02-08 17:02:34 +01:00
|
|
|
|