2012-02-09 22:15:41 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: Yourls
|
2018-01-20 14:57:41 +01:00
|
|
|
* Description: Defines a YourLS url shortener for the Statusnet & Twitter addons
|
2012-02-09 22:15:41 +01:00
|
|
|
* Version: 1.0
|
|
|
|
* Author: Keith Fernie <http://friendika.me4.it/profile/keith>
|
|
|
|
*
|
|
|
|
*/
|
2018-01-17 01:51:12 +01:00
|
|
|
use Friendica\Core\Addon;
|
2017-11-07 00:55:24 +01:00
|
|
|
use Friendica\Core\Config;
|
2018-01-22 20:03:11 +01:00
|
|
|
use Friendica\Core\L10n;
|
2017-11-07 00:55:24 +01:00
|
|
|
|
2012-02-09 22:15:41 +01:00
|
|
|
function yourls_install() {
|
2018-01-20 14:57:41 +01:00
|
|
|
Addon::registerHook('addon_settings', 'addon/yourls/yourls.php', 'yourls_addon_settings');
|
|
|
|
Addon::registerHook('addon_settings_post', 'addon/yourls/yourls.php', 'yourls_addon_settings_post');
|
2012-02-09 22:15:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function yourls_uninstall() {
|
2018-01-20 14:57:41 +01:00
|
|
|
Addon::unregisterHook('addon_settings', 'addon/yourls/yourls.php', 'yourls_addon_settings');
|
|
|
|
Addon::unregisterHook('addon_settings_post', 'addon/yourls/yourls.php', 'yourls_addon_settings_post');
|
2017-11-07 00:55:24 +01:00
|
|
|
Config::set('yourls','url1',trim($_POST['']));
|
|
|
|
Config::set('yourls','username1',trim($_POST['']));
|
|
|
|
Config::set('yourls','password1',trim($_POST['']));
|
|
|
|
Config::set('yourls','ssl1',trim($_POST['']));
|
2012-02-09 22:15:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function yourls_addon_settings(&$a,&$s) {
|
|
|
|
|
|
|
|
|
|
|
|
if(! is_site_admin())
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Add our stylesheet to the page so we can make our settings look nice */
|
|
|
|
|
2012-02-09 23:08:15 +01:00
|
|
|
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/yourls/yourls.css' . '" media="all" />' . "\r\n";
|
2012-02-09 22:15:41 +01:00
|
|
|
|
|
|
|
|
2017-11-07 00:55:24 +01:00
|
|
|
$yourls_url = Config::get('yourls','url1');
|
|
|
|
$yourls_username = Config::get('yourls','username1');
|
|
|
|
$yourls_password = Config::get('yourls', 'password1');
|
|
|
|
$ssl_enabled = Config::get('yourls','ssl1');
|
2012-02-09 23:08:15 +01:00
|
|
|
$ssl_checked = (($ssl_enabled) ? ' checked="checked" ' : '');
|
2012-02-09 22:15:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-07 00:55:24 +01:00
|
|
|
$yourls_ssl = Config::get('yourls', 'ssl1');
|
2012-02-09 22:15:41 +01:00
|
|
|
|
2013-11-30 21:27:20 +01:00
|
|
|
$s .= '<span id="settings_yourls_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_yourls_expanded\'); openClose(\'settings_yourls_inflated\');">';
|
2018-01-22 20:03:11 +01:00
|
|
|
$s .= '<h3>' . L10n::t('YourLS') . '</h3>';
|
2013-11-30 21:27:20 +01:00
|
|
|
$s .= '</span>';
|
|
|
|
$s .= '<div id="settings_yourls_expanded" class="settings-block" style="display: none;">';
|
|
|
|
$s .= '<span class="fakelink" onclick="openClose(\'settings_yourls_expanded\'); openClose(\'settings_yourls_inflated\');">';
|
2018-01-22 20:03:11 +01:00
|
|
|
$s .= '<h3>' . L10n::t('YourLS') . '</h3>';
|
2013-11-30 21:27:20 +01:00
|
|
|
$s .= '</span>';
|
|
|
|
|
2012-02-09 23:08:15 +01:00
|
|
|
$s .= '<div id="yourls-url-wrapper">';
|
2018-01-22 20:03:11 +01:00
|
|
|
$s .= '<label id="yourls-url-label" for="yourls-url">' . L10n::t('URL: http://') . '</label>';
|
2012-02-09 23:08:15 +01:00
|
|
|
$s .= '<input id="yourls-url" type="text" name="yourls_url" value="' . $yourls_url .'" />';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
2012-02-09 22:15:41 +01:00
|
|
|
|
2012-02-09 23:08:15 +01:00
|
|
|
$s .= '<div id="yourls-username-wrapper">';
|
2018-01-22 20:03:11 +01:00
|
|
|
$s .= '<label id="yourls-username-label" for="yourls-username">' . L10n::t('Username:') . '</label>';
|
2012-02-09 23:08:15 +01:00
|
|
|
$s .= '<input id="yourls-username" type="text" name="yourls_username" value="' . $yourls_username .'" />';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
2012-02-09 22:15:41 +01:00
|
|
|
|
2012-02-09 23:08:15 +01:00
|
|
|
$s .= '<div id="yourls-password-wrapper">';
|
2018-01-22 20:03:11 +01:00
|
|
|
$s .= '<label id="yourls-password-label" for="yourls-password">' . L10n::t('Password:') . '</label>';
|
2012-02-09 23:08:15 +01:00
|
|
|
$s .= '<input id="yourls-password" type="password" name="yourls_password" value="' . $yourls_password .'" />';
|
|
|
|
$s .= '</div><div class="clear"></div>';
|
2012-02-09 22:15:41 +01:00
|
|
|
|
|
|
|
$s .= '<div id="yourls-ssl-wrapper">';
|
2018-01-22 20:03:11 +01:00
|
|
|
$s .= '<label id="yourls-ssl-label" for="yourls-ssl">' . L10n::t('Use SSL ') . '</label>';
|
2012-02-18 00:31:15 +01:00
|
|
|
$s .= '<input id="yourls-ssl" type="checkbox" name="yourls_ssl" value="1" ' . $ssl_checked . ' />';
|
2012-02-09 23:08:15 +01:00
|
|
|
$s .= '</div><div class="clear"></div>';
|
2012-02-09 22:15:41 +01:00
|
|
|
|
2018-01-22 20:03:11 +01:00
|
|
|
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="yourls-submit" name="yourls-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
|
2012-02-09 22:15:41 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function yourls_addon_settings_post(&$a,&$b) {
|
|
|
|
|
|
|
|
if(! is_site_admin())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if($_POST['yourls-submit']) {
|
2017-11-07 00:55:24 +01:00
|
|
|
Config::set('yourls','url1',trim($_POST['yourls_url']));
|
|
|
|
Config::set('yourls','username1',trim($_POST['yourls_username']));
|
|
|
|
Config::set('yourls','password1',trim($_POST['yourls_password']));
|
|
|
|
Config::set('yourls','ssl1',intval($_POST['yourls_ssl']));
|
2018-01-22 20:03:11 +01:00
|
|
|
info(L10n::t('yourls Settings saved.') . EOL);
|
2012-02-09 22:15:41 +01:00
|
|
|
}
|
|
|
|
}
|