initial commit
This commit is contained in:
commit
20f4ba629c
6 changed files with 194 additions and 0 deletions
13
LICENSE
Normal file
13
LICENSE
Normal file
|
@ -0,0 +1,13 @@
|
|||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
8
README.md
Normal file
8
README.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
# ShaarGem
|
||||
|
||||
[Shaarli](https://github.com/shaarli/Shaarli/) plugin for Gemini capsules shaaring.
|
||||
|
||||
## Manual
|
||||
|
||||
1. Activate plugin.
|
||||
2. Share a gemini:// IRI.
|
BIN
languages/fr/LC_MESSAGES/shaargem.mo
Normal file
BIN
languages/fr/LC_MESSAGES/shaargem.mo
Normal file
Binary file not shown.
21
languages/fr/LC_MESSAGES/shaargem.po
Normal file
21
languages/fr/LC_MESSAGES/shaargem.po
Normal file
|
@ -0,0 +1,21 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: ShaarGem plugin\n"
|
||||
"POT-Creation-Date: 2017-08-19 10:45+0200\n"
|
||||
"PO-Revision-Date: 2021-02-27 16:27+0100\n"
|
||||
"Language-Team: shaargem\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: Poedit 2.4.1\n"
|
||||
"X-Poedit-Basepath: ../../..\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
"X-Poedit-KeywordsList: ;shaargem_plugin_t:1,2;shaargem_plugin_t\n"
|
||||
"X-Poedit-SourceCharset: UTF-8\n"
|
||||
"Last-Translator: \n"
|
||||
"Language: fr_FR\n"
|
||||
"X-Poedit-SearchPath-0: .\n"
|
||||
|
||||
#: shaargem.php:108
|
||||
msgid "Provides Gemini protocol support."
|
||||
msgstr "Provides Gemini protocol support."
|
1
shaargem.meta
Normal file
1
shaargem.meta
Normal file
|
@ -0,0 +1 @@
|
|||
description="Provides Gemini protocol support."
|
151
shaargem.php
Normal file
151
shaargem.php
Normal file
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
/**
|
||||
* shaargem
|
||||
*
|
||||
* This plugin provides gemini support
|
||||
*/
|
||||
|
||||
use Shaarli\Config\ConfigManager;
|
||||
use Shaarli\Plugin\PluginManager;
|
||||
use Shaarli\Render\TemplatePage;
|
||||
|
||||
/**
|
||||
* In the footer hook, there is a working example of a translation extension for Shaarli.
|
||||
*
|
||||
* The extension must be attached to a new translation domain (i.e. NOT 'shaarli').
|
||||
* Use case: any custom theme or non official plugin can use the translation system.
|
||||
*
|
||||
* See the documentation for more information.
|
||||
*/
|
||||
const EXT_TRANSLATION_DOMAIN = 'shaargem';
|
||||
|
||||
/*
|
||||
* This is not necessary, but it's easier if you don't want Poedit to mix up your translations.
|
||||
*/
|
||||
function shaargem_plugin_t($text, $nText = '', $nb = 1)
|
||||
{
|
||||
return t($text, $nText, $nb, EXT_TRANSLATION_DOMAIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization function.
|
||||
* It will be called when the plugin is loaded.
|
||||
* This function can be used to return a list of initialization errors.
|
||||
*
|
||||
* @param $conf ConfigManager instance.
|
||||
*
|
||||
* @return array List of errors (optional).
|
||||
*/
|
||||
function shaargem_plugin_init($conf)
|
||||
{
|
||||
if (! $conf->exists('translation.extensions.shaargem')) {
|
||||
// Custom translation with the domain 'shaargem'
|
||||
$conf->set('translation.extensions.shaargem', 'plugins/shaargem/languages/');
|
||||
$conf->write(true);
|
||||
}
|
||||
|
||||
$errors[] = 'This a shaargem init error.';
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook render_editlink.
|
||||
*
|
||||
* Template placeholders:
|
||||
* - field_plugin: add link fields after tags.
|
||||
*
|
||||
* @param array $data data passed to plugin
|
||||
*
|
||||
* @return array altered $data.
|
||||
*/
|
||||
function hook_shaargem_render_editlink($data)
|
||||
{
|
||||
$ret=preg_match(",gemini://(.*)?/?(.*),", $data['link']['url'] ,$domain);
|
||||
|
||||
error_log("ret:".$ret);
|
||||
if ($ret)
|
||||
{
|
||||
$stream_context = stream_context_create([ 'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed' => true,
|
||||
'verify_depth' => 0 ]]);
|
||||
|
||||
$fp = stream_socket_client("tls://".$domain[1].":1965", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $stream_context);
|
||||
|
||||
if (!$fp) {
|
||||
error_log("$errstr ($errno)");
|
||||
} else {
|
||||
fwrite($fp, $data['link']['url']."\r\n");
|
||||
$header = fgets($fp,1024);
|
||||
error_log("header:".$header);
|
||||
if (strstr($header, "20 text/gemini"))
|
||||
{
|
||||
$data['link']['title'] = substr(fgets($fp,1024),2,-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log("[shaargem] invalid response:".$header);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook savelink.
|
||||
*
|
||||
* Triggered when a link is save (new or edit).
|
||||
* All new links now contain a 'stuff' value.
|
||||
*
|
||||
* @param array $data contains the new link data.
|
||||
*
|
||||
* @return array altered $data.
|
||||
*/
|
||||
function hook_shaargem_save_link($data)
|
||||
{
|
||||
// ugly hack to get scheme
|
||||
if(isset($_POST['lf_url'])) {
|
||||
if(strstr($_POST['lf_url'],"gemini://"))
|
||||
{
|
||||
$new_url = str_replace("http://","gemini://",$data['url']);
|
||||
$data['url'] = $new_url;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook render_linklist.
|
||||
*
|
||||
* Template placeholders:
|
||||
* - action_plugin: next to 'private only' button.
|
||||
* - plugin_start_zone: page start
|
||||
* - plugin_end_zone: page end
|
||||
* - link_plugin: icons below each links.
|
||||
*
|
||||
* Data:
|
||||
* - _LOGGEDIN_: true/false
|
||||
*
|
||||
* @param array $data data passed to plugin
|
||||
*
|
||||
* @return array altered $data.
|
||||
*/
|
||||
function hook_shaargem_render_linklist($data)
|
||||
{
|
||||
foreach ($data['links'] as &$value) {
|
||||
$value['description'] = preg_replace(',gemini://([\d\w\.\+\-@\:%._\~#=/]+),','<a href="gemini://\1">gemini://\1</a>',$value['description']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is never called, but contains translation calls for GNU gettext extraction.
|
||||
*/
|
||||
function shaargem_dummy_translation()
|
||||
{
|
||||
// meta
|
||||
t('Provides Gemini protocol support.');
|
||||
}
|
||||
|
Loading…
Reference in a new issue