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://([\d\w\.\+\-@\:%._\~#=]+)/?,", $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\.\+\-@\:%._\~#=/]+),','gemini://\1',$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.'); }