ojay wrote: ↑Thu Jan 03, 2019 8:44 pm
ich nutze die
Text2Image-Funktion, die Christoph für mich mal erstellt hat und die auf CMSimple und CMSimple_XH gut funktioniert.
Kann man auch im Kalender (Calendar_XH) Einträge vor Google schützen?
Ich denke nicht, dass man so oder ähnlich ganze Einträge schützen kann. Eventuell kann man aber in Beschreibungen text2image() als Pluginaufruf verwenden? Kommt möglicherweise auf die genaue Version von Calendar_XH an.
Aber warum willst du denn überhaupt Einträge vor Google (und vermutlich anderen Suchmaschinen) verstecken? Wenn es um private Termine geht, dann sollte diese vermutlich auch kein „unbefugter“ Mensch sehen können. Bei Calendar_XH 1.4 könnte man dafür einen zweiten Kalender nutzen, der eben nur auf einer mit Memberpages_XH oder Register_XH geschützten Seite angezeigt wird.
ojay wrote: ↑Thu Jan 03, 2019 8:44 pm
Es wäre super, wenn es die (
cmb)-"Text2Image"-Funktion auch als Plugin gäbe, dann könnte man sie weitergeben.
In aller Regel kann man aus einer Funktion in userfuncs.php leicht ein Plugin machen. Dazu einfach unter plugins/ einen Ordner mit dem Namen der Funktion (eigentlich kann ein beliebiger Name verwendet werden) anlegen, dort eine index.php erstellen, und in diese die Funktion verschieben (dabei muss index.php mit <?php beginnen). Also hier: plugins/text2image/index.php:
Code: Select all
<?php
/**
* Copyright (C) 2016 Christoph M. Becker
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
function text2image($text, $alt = null)
{
global $pth;
// configure the following variables:
$fontfile = "{$pth['folder']['userfiles']}PTC55F.ttf";
$fontsize = 18; // in pt
$padding = 3; // too small values may cause truncation of the text
$color = array(0, 0, 0); // an RGB triple
$angle = 0;
extract(text2image_rectangle($text, $fontsize, $angle, $fontfile, $padding));
$image = imagecreatetruecolor($width, $height);
imagealphablending($image, false);
imagesavealpha($image, true);
$background = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $background);
$foreground = imagecolorallocate($image, $color[0], $color[1], $color[2]);
imagettftext($image, $fontsize, $angle, $x, $y, $foreground, $fontfile, $text);
ob_start();
imagepng($image);
$data = ob_get_clean();
imagedestroy($image);
return sprintf(
'<img class="image2text" src="data:image/png;base64,%s" alt="%s">',
base64_encode($data),
htmlspecialchars(isset($alt) ? $alt : $text, ENT_COMPAT, 'UTF-8')
);
}
function text2image_rectangle($text, $fontsize, $angle, $fontfile, $padding)
{
$bbox = imagettfbbox($fontsize, $angle, $fontfile, $text);
$xs = array($bbox[0], $bbox[2], $bbox[4], $bbox[6]);
$ys = array($bbox[1], $bbox[3], $bbox[5], $bbox[7]);
$xmin = min($xs);
$xmax = max($xs);
$ymin = min($ys);
$ymax = max($ys);
$x = -$xmin + $padding;
$y = -$ymin + $padding;
$width = $xmax - $xmin + 1 + 2 * $padding;
$height = $ymax - $ymin + 1 + 2 * $padding;
return compact('x', 'y', 'width', 'height');
}
Man hat dann zwar noch keine Pluginadministration, aber im Prinzip ist es ein Plugin. Und natürlich kann man auch einfach die userfuncs.php weitergeben; sollte schon eine vorhanden sein, dann muss man die beiden Dateien eben zusammenfassen.