diff --git a/cookienotice/README b/cookienotice/README index 247f53b1..74edd44a 100644 --- a/cookienotice/README +++ b/cookienotice/README @@ -2,8 +2,6 @@ Cookie Notice For server admins only. -Configure, show and handle a simple cookie usage notice. -This absolute annoying but eventually necessary notification about the usage of cookies. -This kind of things you click ok on but don't read. +Configure, show and handle a simple cookie usage notice. This absolute annoying but eventually necessary notification about the usage of cookies. This kind of things you klick ok on but don't read. -Author: Peter Liebetrau +Author: Peter liebetrau diff --git a/cookienotice/cookienotice.php b/cookienotice/cookienotice.php index cc36bc29..376de1ad 100644 --- a/cookienotice/cookienotice.php +++ b/cookienotice/cookienotice.php @@ -5,49 +5,70 @@ * Description: Configure, show and handle a simple cookie notice * Version: 1.0 * Author: Peter Liebetrau + * */ - -use Friendica\App; -use Friendica\Core\Config; use Friendica\Core\Hook; +use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; /** * cookienotice_install * registers hooks - * + * * @return void */ function cookienotice_install() { Hook::register('page_content_top', __FILE__, 'cookienotice_page_content_top'); Hook::register('page_end', __FILE__, 'cookienotice_page_end'); + Hook::register('addon_settings', __FILE__, 'cookienotice_addon_settings'); + Hook::register('addon_settings_post', __FILE__, 'cookienotice_addon_settings_post'); } /** - * cookienotice_addon_admin + * cookienotice_uninstall + * unregisters hooks + * + * @return void +*/ +function cookienotice_uninstall() +{ + Hook::unregister('page_content_top', __FILE__, 'cookienotice_page_content_top'); + Hook::unregister('page_end', __FILE__, 'cookienotice_page_end'); + Hook::unregister('addon_settings', __FILE__, 'cookienotice_addon_settings'); + Hook::unregister('addon_settings_post', __FILE__, 'cookienotice_addon_settings_post'); +} + +/** + * cookienotice_addon_settings + * addon_settings hook * creates the admins config panel - * - * @param App $a + * + * @param \Friendica\App $a * @param string $s The existing config panel html so far - * + * * @return void */ -function cookienotice_addon_admin(App $a, &$s) +function cookienotice_addon_settings(\Friendica\App $a, &$s) { if (!is_site_admin()) { return; } + /* Add our stylesheet to the page so we can make our settings look nice */ + $stylesheetPath = 'addon/cookienotice/cookienotice.css'; + $a->registerStylesheet($stylesheetPath); + $text = Config::get('cookienotice', 'text', L10n::t('This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.')); $oktext = Config::get('cookienotice', 'oktext', L10n::t('OK')); - $t = Renderer::getMarkupTemplate('admin.tpl', __DIR__); + $t = Renderer::getMarkupTemplate("settings.tpl", "addon/cookienotice/"); $s .= Renderer::replaceMacros($t, [ + '$title' => L10n::t('"cookienotice" Settings'), '$description' => L10n::t('Configure your cookie usage notice. It should just be a notice, saying that the website uses cookies. It is shown as long as a user didnt confirm clicking the OK button.'), - '$text' => ['cookienotice-text', L10n::t('Cookie Usage Notice'), $text], - '$oktext' => ['cookienotice-oktext', L10n::t('OK Button Text'), $oktext], + '$text' => ['cookienotice-text', L10n::t('Cookie Usage Notice'), $text, L10n::t('The cookie usage notice')], + '$oktext' => ['cookienotice-oktext', L10n::t('OK Button Text'), $oktext, L10n::t('The OK Button text')], '$submit' => L10n::t('Save Settings') ]); @@ -55,16 +76,16 @@ function cookienotice_addon_admin(App $a, &$s) } /** - * cookienotice_addon_admin_post + * cookienotice_addon_settings_post * addon_settings_post hook * handles the post request from the admin panel - * - * @param App $a + * + * @param \Friendica\App $a * @param string $b - * + * * @return void */ -function cookienotice_addon_admin_post(App $a, &$b) +function cookienotice_addon_settings_post(\Friendica\App $a, &$b) { if (!is_site_admin()) { return; @@ -81,16 +102,16 @@ function cookienotice_addon_admin_post(App $a, &$b) * cookienotice_page_content_top * page_content_top hook * adds css and scripts to the section of the html - * - * @param App $a - * @param string $b unused - the header html incl. nav - * + * + * @param \Friendica\App $a + * @param string $b unnused - the header html incl. nav + * * @return void */ -function cookienotice_page_content_top(App $a, &$b) +function cookienotice_page_content_top(\Friendica\App $a, &$b) { - $stylesheetPath = __DIR__ . '/cookienotice.css'; - $footerscriptPath = __DIR__ . '/cookienotice.js'; + $stylesheetPath = 'addon/cookienotice/cookienotice.css'; + $footerscriptPath = 'addon/cookienotice/cookienotice.js'; $a->registerStylesheet($stylesheetPath); $a->registerFooterScript($footerscriptPath); @@ -100,18 +121,18 @@ function cookienotice_page_content_top(App $a, &$b) * cookienotice_page_end * page_end hook * ads our cookienotice box to the end of the html - * - * @param App $a + * + * @param \Friendica\App $a * @param string $b the page html - * + * * @return void */ -function cookienotice_page_end(App $a, &$b) +function cookienotice_page_end(\Friendica\App $a, &$b) { - $text = (string)Config::get('cookienotice', 'text', L10n::t('This website uses cookies to recognize revisiting and logged in users. You accept the usage of these cookies by continue browsing this website.')); - $oktext = (string)Config::get('cookienotice', 'oktext', L10n::t('OK')); + $text = (string) Config::get('cookienotice', 'text', L10n::t('This website uses cookies to recognize revisiting and logged in users. You accept the usage of these cookies by continue browsing this website.')); + $oktext = (string) Config::get('cookienotice', 'oktext', L10n::t('OK')); - $page_end_tpl = Renderer::getMarkupTemplate('cookienotice.tpl', __DIR__); + $page_end_tpl = Renderer::getMarkupTemplate("cookienotice.tpl", "addon/cookienotice/"); $page_end = Renderer::replaceMacros($page_end_tpl, [ '$text' => $text, diff --git a/cookienotice/templates/admin.tpl b/cookienotice/templates/admin.tpl deleted file mode 100644 index b64b0377..00000000 --- a/cookienotice/templates/admin.tpl +++ /dev/null @@ -1,6 +0,0 @@ -

{{$description nofilter}}

-{{include file="field_textarea.tpl" field=$text}} -{{include file="field_input.tpl" field=$oktext}} -
- -
diff --git a/cookienotice/templates/settings.tpl b/cookienotice/templates/settings.tpl new file mode 100644 index 00000000..99489b9c --- /dev/null +++ b/cookienotice/templates/settings.tpl @@ -0,0 +1,15 @@ + +

{{$title}}

+
+ +
diff --git a/fortunate/README b/fortunate/README new file mode 100644 index 00000000..8297cf41 --- /dev/null +++ b/fortunate/README @@ -0,0 +1,7 @@ +This addon requires a fortune server. You may use the DB supplied here to create one. + +gunzip the fortunate.sql.gz and import into your database. +Copy cookie.php to the top level Friendica directory. +Edit fortunate.php and change FORTUNATE_SERVER definition to your hostname. Change the http in that file to https if your server doesn't support http. + +Many additional options are available if you examine cookie.php - a clever developer can provide a settings page to tailor this to one's liking. Also several languages are supported, and it would be convenient to set this to the current Friendica language if that is amongst those supported. \ No newline at end of file diff --git a/fortunate/cookie.php b/fortunate/cookie.php new file mode 100644 index 00000000..3022776c --- /dev/null +++ b/fortunate/cookie.php @@ -0,0 +1,349 @@ +real_escape_string($_GET['lang']); + +if(strlen($_GET['pattern'])) + $pattern = @$db->real_escape_string(urldecode($_GET['pattern'])); + +if(strlen($_GET['regex'])) + $regex = @$db->real_escape_string(urldecode($_GET['regex'])); + +if(strlen($_GET['db'])) + $table = @$db->real_escape_string(urldecode($_GET['db'])); +else + $table = ''; + +if($length < 0) + $length = 0; +if($numlines < 0) + $numlines = 0; + +function do_query($table,$length,$numlines,$adult,$cat,$limit,$lang,$pattern,$regex,$equal) { + global $db; + $rnd = mt_rand(); + $r = []; + + $typesql = (($table) ? " WHERE `category` = '$table' " : " WHERE 1 "); + $lengthsql = (($length) ? " AND LENGTH(`text`) < $length " : "" ); + + if($adult == 2) + $adultsql = " AND offensive = 1 "; + elseif($adult == 1) + $adultsql = ""; + else + $adultsql = " AND offensive = 0 "; + + + if($numlines) + $lengthsql .= + " AND (LENGTH(`text`) - LENGTH(REPLACE(`text`,\"\n\",\"\"))) <= $numlines "; + + $langsql = " AND lang = '$lang' "; + + $patsql = ''; + if(strlen($pattern)) + $patsql = " AND MATCH text AGAINST ('$pattern' IN BOOLEAN MODE) "; + + $regexsql = ''; + if(strlen($regex)) + $regexsql = " AND text REGEXP '$regex' "; + + $eqsql = ''; + + if($equal) { + $catsavail = []; + $res = @$db->query("SELECT DISTINCT ( `category` ) FROM `fortune` + $typesql + $adultsql + $lengthsql + $langsql + $patsql + $regexsql "); + if($res->num_rows) { + while($x = $res->fetch_array(MYSQL_ASSOC)) + $catsavail[] = $x['category']; + + $eqsql = " AND `category` = '" + . $catsavail[mt_rand(0,$res->num_rows - 1)] . "' "; + } + } + + $result = @$db->query("SELECT `text`, `category` FROM `fortune` + $typesql + $adultsql + $lengthsql + $langsql + $patsql + $regexsql + $eqsql + ORDER BY RAND($rnd) + LIMIT $limit"); + + if($result->num_rows) { + while($x = $result->fetch_array(MYSQL_ASSOC)) + $r[] = fortune_to_html($x['text']) + .(($cat) ? "
[{$x['category']}]
" : ""); + } + return $r; +} + + +function do_stats($table,$length,$numlines,$adult,$cat,$limit,$lang,$pattern,$regex,$equal) { + global $db; + $rnd = mt_rand(); + $r = []; + + $typesql = (($table) ? " WHERE `category` = '$table' " : " WHERE 1 "); + $lengthsql = (($length) ? " AND LENGTH(`text`) < $length " : "" ); + + if($adult == 2) + $adultsql = " AND offensive = 1 "; + elseif($adult == 1) + $adultsql = ""; + else + $adultsql = " AND offensive = 0 "; + + + if($numlines) + $lengthsql .= + " AND (LENGTH(`text`) - LENGTH(REPLACE(`text`,\"\n\",\"\"))) <= $numlines "; + + $langsql = " AND lang = '$lang' "; + + $patsql = ''; + if(strlen($pattern)) + $patsql = " AND MATCH text AGAINST ('$pattern' IN BOOLEAN MODE) "; + + $regexsql = ''; + if(strlen($regex)) + $regexsql = " AND text REGEXP '$regex' "; + + $eqsql = ''; + + $result = @$db->query("SELECT `text`, `category` FROM `fortune` + $typesql + $adultsql + $lengthsql + $langsql + $patsql + $regexsql + $eqsql"); + + + echo '
' . $result->num_rows . ' matching quotations.
'; + + + $res = @$db->query("SELECT DISTINCT ( `category` ) FROM `fortune` + $typesql + $adultsql + $lengthsql + $langsql + $patsql + $regexsql "); + if($res->num_rows) { + echo '
Matching Databases:
'; + while($x = $res->fetch_array(MYSQL_ASSOC)) + echo $x['category'].'
'; + + } + else + echo '
No matching databases using those search parameters - please refine your options.
'; + + +} + + +function fortune_to_html($s) { + + // First pass - escape all the HTML entities, and while we're at it + // get rid of any MS-DOS end-of-line characters and expand tabs to + // 8 non-breaking spaces, and translate linefeeds to
. + // We also get rid of ^G which used to sound the terminal beep or bell + // on ASCII terminals and were humourous in some fortunes. + // We could map these to autoplay a short sound file but browser support + // is still sketchy and then there's the issue of where to locate the + // URL, and a lot of people find autoplay sounds downright annoying. + // So for now, just remove them. + + $s = str_replace( + ["&", + "<", + ">", + '"', + "\007", + "\t", + "\r", + "\n"], + + ["&", + "<", + ">", + """, + "", + "        ", + "", + "
"], + $s); + // Replace pseudo diacritics + // These were used to produce accented characters. For instance an accented + // e would have been encoded by '^He - the backspace moving the cursor + // backward so both the single quote and the e would appear in the same + // character position. Umlauts were quite clever - they used a double quote + // as the accent mark over a normal character. + + $s = preg_replace("/'\010([a-zA-Z])/","&\\1acute;",$s); + $s = preg_replace("/\"\010([a-zA-Z])/","&\\1uml;",$s); + $s = preg_replace("/\`\010([a-zA-Z])/","&\\1grave;",$s); + $s = preg_replace("/\^\010([a-zA-Z])/","&\\1circ;",$s); + $s = preg_replace("/\~\010([a-zA-Z])/","&\\1tilde;",$s); + + // Ignore multiple underlines for the same character. These were + // most useful when sent to a line printer back in the day as it + // would type over the same character a number of times making it + // much darker (e.g. bold). I think there are only one or two + // instances of this in the current (2008) fortune cookie database. + + $s = preg_replace("/(_\010)+/","_\010",$s); + // Map the characters which sit underneath a backspace. + // If you can come up with a regex to do all of the following + // madness - be my guest. + // It's not as simple as you think. We need to take something + // that has been backspaced over an arbitrary number of times + // and wrap a forward looking matching number of characters in + // HTML, whilst deciding if it's intended as an underline or + // strikeout sequence. + + // Essentially we produce a string of '1' and '0' characters + // the same length as the source text. + // Any position which is marked '1' has been backspaced over. + + $cursor = 0; + $dst = $s; + $bs_found = false; + for($x = 0; $x < strlen($s); $x ++) { + if($s[$x] == "\010" && $cursor) { + $bs_found = true; + $cursor --; + $dst[$cursor] = '1'; + $dst[$x] = '0'; + $continue; + } + else { + if($bs_found) { + $bs_found = false; + $cursor = $x; + } + $dst[$cursor] = '0'; + $cursor ++; + } + + } + + $out = ''; + $strike = false; + $bold = false; + + // Underline sequence, convert to bold to avoid confusion with links. + // These were generally used for emphasis so it's a reasonable choice. + // Please note that this logic will fail if there is an underline sequence + // and also a strikeout sequence in the same fortune. + + if(strstr($s,"_\010")) { + $len = 0; + for($x = 0; $x < strlen($s); $x ++) { + if($dst[$x] == '1') { + $len ++; + $bold = true; + } + else { + if($bold) { + $out .= ''; + while($s[$x] == "\010") + $x ++; + $out .= substr($s,$x,$len); + $out .= ''; + $x = $x + $len - 1; + $len = 0; + $bold = false; + } + else + $out .= $s[$x]; + } + } + } + + // These aren't seen very often these days - simulation of + // backspace/replace. You could occasionally see the original text + // on slower terminals before it got replaced. Once modems reached + // 4800/9600 baud in the late 70's and early 80's the effect was + // mostly lost - but if you find a really old fortune file you might + // encounter a few of these. + + else { + for($x = 0; $x < strlen($s); $x ++) { + if($dst[$x] == '1') { + if($strike) + $out .= $s[$x]; + else + $out .= ''.$s[$x]; + $strike = true; + } + else { + if($strike) + $out .= ''; + $strike = false; + $out .= $s[$x]; + } + } + } + + // Many of the underline sequences are also wrapped in asterisks, + // which was yet another way of marking ASCII as 'bold'. + // So if it's an underline sequence, and there are asterisks + // on both ends, strip the asterisks as we've already emboldened the text. + + $out = preg_replace('/\*([^<]*<\/strong>)\*/',"\\1",$out); + + // Finally, remove the backspace characters which we don't need anymore. + + return str_replace("\010","",$out); +} + +$result1 = do_query($table,$length,$numlines,$adult,$cat,1,$lang,$pattern,$regex,$equal); + +if(count($result1)) + echo $result1[0]; + +if($stats) + do_stats($table,$length,$numlines,$adult,$cat,1,$lang,$pattern,$regex,$equal); + + diff --git a/fortunate/fortunate.css b/fortunate/fortunate.css new file mode 100644 index 00000000..61813b7d --- /dev/null +++ b/fortunate/fortunate.css @@ -0,0 +1,7 @@ +.fortunate { + margin-top: 25px; + margin-left: 100px; + margin-bottom: 25px; + color: #000088; + font-size: 14px; +} \ No newline at end of file diff --git a/fortunate/fortunate.php b/fortunate/fortunate.php new file mode 100644 index 00000000..939cbb4b --- /dev/null +++ b/fortunate/fortunate.php @@ -0,0 +1,39 @@ + + * Status: Unsupported + */ +use Friendica\Core\Hook; +use Friendica\Util\Network; + +// IMPORTANT: SET THIS to your fortunate server + +define('FORTUNATE_SERVER', 'hostname.com'); + +function fortunate_install() +{ + Hook::register('page_end', 'addon/fortunate/fortunate.php', 'fortunate_fetch'); + if (FORTUNATE_SERVER == 'hostname.com' && is_site_admin()) { + notice('Fortunate addon requires configuration. See README'); + } +} + +function fortunate_uninstall() +{ + Hook::unregister('page_end', 'addon/fortunate/fortunate.php', 'fortunate_fetch'); +} + + +function fortunate_fetch(&$a, &$b) +{ + $a->page['htmlhead'] .= '' . "\r\n"; + + if (FORTUNATE_SERVER != 'hostname.com') { + $s = Network::fetchUrl('http://' . FORTUNATE_SERVER . '/cookie.php?numlines=2&equal=1&rand=' . mt_rand()); + $b .= '
' . $s . '
'; + } +} diff --git a/fortunate/fortunemod.sql.gz b/fortunate/fortunemod.sql.gz new file mode 100644 index 00000000..2ce0e557 Binary files /dev/null and b/fortunate/fortunemod.sql.gz differ diff --git a/fortunate/lang/C/messages.po b/fortunate/lang/C/messages.po new file mode 100644 index 00000000..e69de29b diff --git a/geonames/README.md b/geonames/README.md index 16b85b37..443ddf3f 100644 --- a/geonames/README.md +++ b/geonames/README.md @@ -3,14 +3,14 @@ Geonames Addon Authors Mike Macgirvin. -Use [Geonames service](https://www.geonames.org) to resolve nearest populated location for given latitude, longitude. +Use Geonames service to resolve nearest populated location for given latitude, longitude. ## Installation -Pre-requisite: Register a username at https://www.geonames.org/login and set it in `config/addon.config.php` +Pre-requisite: Register a username at geonames.org and set in `config/addon.config.php` 'geonames' => [ 'username' => 'your_username' ], -Also visit https://geonames.org/manageaccount and enable access to the free web services. +Also visit http://geonames.org/manageaccount and enable access to the free web services. \ No newline at end of file diff --git a/geonames/geonames.php b/geonames/geonames.php index cc0420f4..1ce6dbfa 100644 --- a/geonames/geonames.php +++ b/geonames/geonames.php @@ -4,148 +4,202 @@ * Description: Use Geonames service to resolve nearest populated location for given latitude, longitude * Version: 1.0 * Author: Mike Macgirvin + * + * + * Pre-requisite: Register a username at geonames.org + * and set in config/addon.config.php + * + * [geonames] + * username = your_username + * + * Also visit http://geonames.org/manageaccount and enable access to the free web services + * + * When addon is installed, the system calls the addon + * name_install() function, located in 'addon/name/name.php', + * where 'name' is the name of the addon. + * If the addon is removed from the configuration list, the + * system will call the name_uninstall() function. + * */ -use Friendica\App; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\PConfig; -use Friendica\Core\Renderer; use Friendica\Util\Config\ConfigFileLoader; use Friendica\Util\Network; use Friendica\Util\XML; -function geonames_install() -{ - Hook::register('load_config', __FILE__, 'geonames_load_config'); +function geonames_install() { - /* Our addon will attach in three places. + Hook::register('load_config', 'addon/geonames/geonames.php', 'geonames_load_config'); + + /** + * + * Our addon will attach in three places. * The first is just prior to storing a local post. + * */ - Hook::register('post_local', __FILE__, 'geonames_post_hook'); + Hook::register('post_local', 'addon/geonames/geonames.php', 'geonames_post_hook'); - /* Then we'll attach into the addon settings page, and also the + /** + * + * Then we'll attach into the addon settings page, and also the * settings post hook so that we can create and update * user preferences. + * */ - Hook::register('addon_settings', __FILE__, 'geonames_addon_settings'); - Hook::register('addon_settings_post', __FILE__, 'geonames_addon_settings_post'); + Hook::register('addon_settings', 'addon/geonames/geonames.php', 'geonames_addon_admin'); + Hook::register('addon_settings_post', 'addon/geonames/geonames.php', 'geonames_addon_admin_post'); + + Logger::log("installed geonames"); } -function geonames_load_config(App $a, ConfigFileLoader $loader) + +function geonames_uninstall() { + + /** + * + * uninstall unregisters any hooks created with register_hook + * during install. It may also delete configuration settings + * and any other cleanup. + * + */ + + Hook::unregister('load_config', 'addon/geonames/geonames.php', 'geonames_load_config'); + Hook::unregister('post_local', 'addon/geonames/geonames.php', 'geonames_post_hook'); + Hook::unregister('addon_settings', 'addon/geonames/geonames.php', 'geonames_addon_admin'); + Hook::unregister('addon_settings_post', 'addon/geonames/geonames.php', 'geonames_addon_admin_post'); + + + Logger::log("removed geonames"); +} + +function geonames_load_config(\Friendica\App $a, ConfigFileLoader $loader) { $a->getConfigCache()->load($loader->loadAddonConfig('geonames')); } -function geonames_post_hook(App $a, array &$item) -{ - /* An item was posted on the local system. +function geonames_post_hook($a, &$item) { + + /** + * + * An item was posted on the local system. * We are going to look for specific items: * - A status post by a profile owner * - The profile owner must have allowed our addon + * */ Logger::log('geonames invoked'); - if (!local_user()) { /* non-zero if this is a logged in user of this system */ + if(! local_user()) /* non-zero if this is a logged in user of this system */ return; - } - if (local_user() != $item['uid']) { /* Does this person own the post? */ + if(local_user() != $item['uid']) /* Does this person own the post? */ return; - } - if ($item['parent']) { /* If the item has a parent, this is a comment or something else, not a status post. */ + if($item['parent']) /* If the item has a parent, this is a comment or something else, not a status post. */ return; - } /* Retrieve our personal config setting */ $geo_account = Config::get('geonames', 'username'); $active = PConfig::get(local_user(), 'geonames', 'enable'); - if (!$geo_account || !$active) { + if((! $geo_account) || (! $active)) return; - } - if (!$item['coord'] || $item['location']) { + if((! $item['coord']) || ($item['location'])) return; - } - $coords = explode(' ', $item['coord']); + $coords = explode(' ',$item['coord']); - /* OK, we're allowed to do our stuff. */ + /** + * + * OK, we're allowed to do our stuff. + * + */ $s = Network::fetchUrl('http://api.geonames.org/findNearbyPlaceName?lat=' . $coords[0] . '&lng=' . $coords[1] . '&username=' . $geo_account); - if (!$s) { + if(! $s) return; - } $xml = XML::parseString($s); - if ($xml->geoname->name && $xml->geoname->countryName) { + if($xml->geoname->name && $xml->geoname->countryName) $item['location'] = $xml->geoname->name . ', ' . $xml->geoname->countryName; - } + +// Logger::log('geonames : ' . print_r($xml,true), Logger::DATA); return; } + + + /** + * * Callback from the settings post function. + * $post contains the $_POST array. * We will make sure we've got a valid user account * and if so set our configuration setting for this person. * - * @param App $a - * @param array $post The $_POST array */ -function geonames_addon_settings_post(App $a, array $post) -{ - if (!local_user() || empty($_POST['geonames-submit'])) { + +function geonames_addon_admin_post($a,$post) { + if(! local_user() || empty($_POST['geonames-submit'])) return; - } + PConfig::set(local_user(),'geonames','enable',intval($_POST['geonames'])); - PConfig::set(local_user(), 'geonames', 'enable', intval($_POST['geonames-enable'])); - - info(L10n::t('Geonames settings updated.')); + info(L10n::t('Geonames settings updated.') . EOL); } + /** + * * Called from the Addon Setting form. * Add our own settings info to the page. * - * @param App $a - * @param string $s - * @throws Exception */ -function geonames_addon_settings(App $a, &$s) -{ - if (!local_user()) { + + + +function geonames_addon_admin(&$a,&$s) { + + if(! local_user()) return; - } $geo_account = Config::get('geonames', 'username'); - if (!$geo_account) { + if(! $geo_account) return; - } /* Add our stylesheet to the page so we can make our settings look nice */ - $stylesheetPath = __DIR__ . '/geonames.css'; - $a->registerStylesheet($stylesheetPath); + + $a->page['htmlhead'] .= '' . "\r\n"; /* Get the current state of our config variable */ - $enabled = intval(PConfig::get(local_user(), 'geonames', 'enable')); - $t = Renderer::getMarkupTemplate('settings.tpl', __DIR__); - $s .= Renderer::replaceMacros($t, [ - '$title' => L10n::t('Geonames Settings'), - '$description' => L10n::t('Replace numerical coordinates by the nearest populated location name in your posts.'), - '$enable' => ['geonames-enable', L10n::t('Enable Geonames Addon'), $enabled], - '$submit' => L10n::t('Save Settings') - ]); + $enabled = PConfig::get(local_user(),'geonames','enable'); + + $checked = (($enabled) ? ' checked="checked" ' : ''); + + /* Add some HTML to the existing form */ + + $s .= '
'; + $s .= '

' . L10n::t('Geonames Settings') . '

'; + $s .= '
'; + $s .= ''; + $s .= ''; + $s .= '
'; + + /* provide a submit button */ + + $s .= '
'; + } diff --git a/geonames/templates/settings.tpl b/geonames/templates/settings.tpl deleted file mode 100644 index 05897b6a..00000000 --- a/geonames/templates/settings.tpl +++ /dev/null @@ -1,14 +0,0 @@ - -

{{$title}}

-
- -
\ No newline at end of file diff --git a/pageheader/pageheader.php b/pageheader/pageheader.php index 9e40d4e7..922f557c 100644 --- a/pageheader/pageheader.php +++ b/pageheader/pageheader.php @@ -8,45 +8,63 @@ * */ -use Friendica\App; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Renderer; function pageheader_install() { - Hook::register('page_content_top', __FILE__, 'pageheader_fetch'); + Hook::register('page_content_top', 'addon/pageheader/pageheader.php', 'pageheader_fetch'); + Hook::register('addon_settings', 'addon/pageheader/pageheader.php', 'pageheader_addon_settings'); + Hook::register('addon_settings_post', 'addon/pageheader/pageheader.php', 'pageheader_addon_settings_post'); + } -function pageheader_addon_admin(App &$a, &$s) -{ - if(! is_site_admin()) { + +function pageheader_uninstall() { + Hook::unregister('page_content_top', 'addon/pageheader/pageheader.php', 'pageheader_fetch'); + Hook::unregister('addon_settings', 'addon/pageheader/pageheader.php', 'pageheader_addon_settings'); + Hook::unregister('addon_settings_post', 'addon/pageheader/pageheader.php', 'pageheader_addon_settings_post'); + + // hook moved, uninstall the old one if still there. + Hook::unregister('page_header', 'addon/pageheader/pageheader.php', 'pageheader_fetch'); + +} + + + + + +function pageheader_addon_settings(&$a,&$s) { + + + if(! is_site_admin()) return; - } /* Add our stylesheet to the page so we can make our settings look nice */ - $stylesheetPath = __DIR__ . '/pageheader.css'; - $a->registerStylesheet($stylesheetPath); + + $a->page['htmlhead'] .= '' . "\r\n"; + $words = Config::get('pageheader','text'); if(! $words) $words = ''; - $t = Renderer::getMarkupTemplate('admin.tpl', __DIR__); + $t = Renderer::getMarkupTemplate("settings.tpl", "addon/pageheader/"); $s .= Renderer::replaceMacros($t, [ - '$title' => L10n::t('"pageheader" Settings'), - '$phwords' => ['pageheader-words', L10n::t('Message'), $words, L10n::t('Message to display on every page on this server (or put a pageheader.html file in your docroot)')], - '$submit' => L10n::t('Save Settings') + '$title' => L10n::t('"pageheader" Settings'), + '$phwords' => ['pageheader-words', L10n::t('Message'), $words, L10n::t('Message to display on every page on this server (or put a pageheader.html file in your docroot)')], + '$submit' => L10n::t('Save Settings') ]); return; + } -function pageheader_addon_admin_post(App $a, &$b) -{ - if(!is_site_admin()) { +function pageheader_addon_settings_post(&$a, &$b) { + + if(!is_site_admin()) return; - } if(!empty($_POST['pageheader-submit'])) { if (isset($_POST['pageheader-words'])) { @@ -56,18 +74,19 @@ function pageheader_addon_admin_post(App $a, &$b) } } -function pageheader_fetch(App $a, &$b) -{ +function pageheader_fetch($a,&$b) { + if(file_exists('pageheader.html')){ $s = file_get_contents('pageheader.html'); } else { $s = Config::get('pageheader', 'text'); } - $stylesheetPath = __DIR__ .'/pageheader.css'; - $a->registerStylesheet($stylesheetPath); + $a->page['htmlhead'] .= '' . "\r\n"; - if ($s) { + if(! $s) + $s = ''; + if ($s != '') $b .= ''; - } } diff --git a/pageheader/templates/admin.tpl b/pageheader/templates/admin.tpl deleted file mode 100644 index 498a9273..00000000 --- a/pageheader/templates/admin.tpl +++ /dev/null @@ -1,5 +0,0 @@ -{{include file="field_textarea.tpl" field=$phwords}} - -
- -
diff --git a/pageheader/templates/settings.tpl b/pageheader/templates/settings.tpl new file mode 100644 index 00000000..db1a4093 --- /dev/null +++ b/pageheader/templates/settings.tpl @@ -0,0 +1,14 @@ + +

{{$title}}

+
+ +
diff --git a/pledgie/README b/pledgie/README new file mode 100644 index 00000000..bcc7fe07 --- /dev/null +++ b/pledgie/README @@ -0,0 +1,11 @@ +Pledgie + +Allows administrators to add a Pledgie-Donation Button to all their friendica pages. +This could be useful f.e. for public nodes that want to raise some money for server +maintenance costs. + +Usage: +Add the campaign number of your pledgie campaign in the first field. To find out the campaign number, +go to your Pledgie campaign webpage. The campaign number is the number at the end of the URL. + +Add a describtion of your campaign in the second field. \ No newline at end of file diff --git a/pledgie/lang/C/messages.po b/pledgie/lang/C/messages.po new file mode 100644 index 00000000..e69de29b diff --git a/pledgie/pledgie.css b/pledgie/pledgie.css new file mode 100644 index 00000000..5195871c --- /dev/null +++ b/pledgie/pledgie.css @@ -0,0 +1,28 @@ +#pledgie-label { + float: left; + width: 300px; + margin-top: 10px; +} + +#pledgie-campaign { + float: left; + margin-top: 10px; + width: 100px; +} + +#pledgie-describe { + float: left; + margin-top: 10px; + width: 300px; +} + +#pledgie-submit { + margin-top: 15px; +} + +.pledgie { + text-align: center; + width: 100%; + margin-top: 25px; + font-size: 20px; +} diff --git a/pledgie/pledgie.php b/pledgie/pledgie.php new file mode 100644 index 00000000..8a4378bc --- /dev/null +++ b/pledgie/pledgie.php @@ -0,0 +1,82 @@ + + * Hauke Altmann + * + */ +use Friendica\Core\Config; +use Friendica\Core\Hook; +use Friendica\Core\L10n; + +function pledgie_install() { + Hook::register('page_end', 'addon/pledgie/pledgie.php', 'pledgie_active'); + Hook::register('addon_settings', 'addon/pledgie/pledgie.php', 'pledgie_addon_settings'); + Hook::register('addon_settings_post', 'addon/pledgie/pledgie.php', 'pledgie_addon_settings_post'); +} + +function pledgie_uninstall() { + Hook::unregister('page_end', 'addon/pledgie/pledgie.php', 'pledgie_active'); + Hook::unregister('addon_settings', 'addon/pledgie/pledgie.php', 'pledgie_addon_settings'); + Hook::unregister('addon_settings_post', 'addon/pledgie/pledgie.php', 'pledgie_addon_settings_post'); +} + +function pledgie_addon_settings(&$a,&$s) { + + if(! is_site_admin()) + return; + + /* Add our stylesheet to the page so we can make our settings look nice */ + + $a->page['htmlhead'] .= '' . "\r\n"; + + $campaign = Config::get('pledgie-campaign','text'); + $describe = Config::get('pledgie-describe','text'); + + if(! $campaign) + $campaign = ''; + + if(! describe) + $describe = ''; + + $s .= '
'; + $s .= '

' . L10n::t('"pledgie" Settings') . '

'; + $s .= '
'; + $s .= ''; + $s .= ''; + $s .= '
'; + + $s .= '
'; + $s .= ''; + $s .= ''; + $s .= '
'; + + $s .= '
'; + + return; +} + +function pledgie_addon_settings_post(&$a,&$b) { + + if(! is_site_admin()) + return; + + if($_POST['pledgie-submit']) { + Config::set('pledgie-describe','text',trim(strip_tags($_POST['pledgie-describe']))); + Config::set('pledgie-campaign','text',trim(strip_tags($_POST['pledgie-campaign']))); + info(L10n::t('pledgie Settings saved.') . EOL); + } +} + +function pledgie_active(&$a,&$b) { + $campaign = Config::get('pledgie-campaign','text'); + $describe = Config::get('pledgie-describe','text'); + $b .= '
'; + $b .= $describe . '
Click here to lend your support to: ' . $describe .  '!
'; +} diff --git a/windowsphonepush/windowsphonepush.php b/windowsphonepush/windowsphonepush.php index 65fcc357..30c6cf60 100644 --- a/windowsphonepush/windowsphonepush.php +++ b/windowsphonepush/windowsphonepush.php @@ -29,11 +29,11 @@ use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; -use Friendica\Core\Authentication; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\PConfig; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model\Item; use Friendica\Model\User; @@ -473,7 +473,7 @@ function windowsphonepush_login(App $a) die('This api requires login'); } - Authentication::setAuthenticatedSessionForUser($record); + Session::setAuthenticatedForUser($a, $record); $_SESSION["allow_api"] = true; Hook::callAll('logged_in', $a->user); }