Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
3 lars 1
<?php
2
// +------------------------------------------------------------------------+
3
// | Email_Safe                                                             |
4
// +------------------------------------------------------------------------+
5
// | Copyright (c) 2000-2007 Markus Niewerth                                |
6
// | Email         markus@niewerth.com                                      |
7
// | Web           http://www.gamerzzone.de                                 |
8
// | Mirror        http://rapidtemplates.immony.de                          |
9
// +------------------------------------------------------------------------+
10
// | This source file is subject to version 3.00 of the PHP License,        |
11
// | that is available at http://www.php.net/license/3_0.txt.               |
12
// | If you did not receive a copy of the PHP license and are unable to     |
13
// | obtain it through the world-wide-web, please send a note to            |
14
// | license@php.net so we can mail you a copy immediately.                 |
15
// +------------------------------------------------------------------------+
16
// | License Informations                                                   |
17
// +------------------------------------------------------------------------+
18
// | Copyright (c) 2000-2007,Markus Niewerth                                |
19
// | All rights reserved.                                                   |
20
// |                                                                        |
21
// | Redistribution and use in source and binary forms, with or without     |
22
// | modification, are permitted provided that the following conditions     |
23
// | are met:                                                               |
24
// |                                                                        |
25
// | o Redistributions of source code must retain the above copyright       |
26
// |   notice, this list of conditions and the following disclaimer.        |
27
// | o Redistributions in binary form must reproduce the above copyright    |
28
// |   notice, this list of conditions and the following disclaimer in the  |
29
// |   documentation and/or other materials provided with the distribution. |
30
// | o The names of the authors may not be used to endorse or promote       |
31
// |   products derived from this software without specific prior written   |
32
// |   permission.                                                          |
33
// |                                                                        |
34
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    |
35
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      |
36
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  |
37
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   |
38
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  |
39
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       |
40
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  |
41
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  |
42
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    |
43
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  |
44
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   |
45
// |                                                                        |
46
// +------------------------------------------------------------------------+
47
// | Author: Markus Niewerth <markus@niewerth.com>                          |
48
// +------------------------------------------------------------------------+
49
 
50
/**
51
 * This file is part of the Content-Active CMS System.
52
 * This class is available in other abstractions.
53
 *
54
 * This class handles template formates written in
55
 * Rapid_Template syntax. The syntax is shown in the
56
 * method itself. Or you could have a look in the
57
 * templates folder {@see templates/}.
58
 *
59
 * PHP versions 4 and 5
60
 *
61
 * LICENSE: This source file is subject to version 3.0 of the PHP license
62
 * that is available through the world-wide-web at the following URI:
63
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
64
 * the PHP License and are unable to obtain it through the web, please
65
 * send a note to license@php.net so we can mail you a copy immediately.
66
 *
67
 * @category   crypt
68
 * @package    Email_Safe
69
 * @author     Markus Niewerth <markus@weban.de>
70
 * @copyright  1997-2005 The PHP Group
71
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
72
 * @since      File available since Release 1.0.1
73
 */
74
 
75
 
76
// {{{ constants
77
define("EMAIL_SAFE_ERROR_MESSAGE"				, "Can't read config file: %s");
78
define("EMAIL_SAFE_DEFAULT_CONFIG"				, "local_s/__classes/emailconfig.default.inc.php");
79
 
80
// Image Einstellungen und Verzeichniskonfigurationen
81
define('EMAIL_SAFE_EMAIL_IMAGE_CONTENT_TYPE'	, "image/png");
82
define('EMAIL_SAFE_DIRECTORY'					, "/usr/share/php/module/Email_Safe");
83
define('EMAIL_SAFE_IMAGE_POPUP_TAG'				, file_get_contents(EMAIL_SAFE_DIRECTORY."/templates/image.htm", true));
84
define('EMAIL_SAFE_IMAGE_EMAIL_INPUT'			, EMAIL_SAFE_DIRECTORY."/images/inp_email_200x37.jpg");
85
define('EMAIL_SAFE_GD_TTF_FONT_DIR'				, EMAIL_SAFE_DIRECTORY."/fonts/ttf/");
86
define('EMAIL_SAFE_IMAGE_SYMLINK'				, EMAIL_SAFE_DIRECTORY."/mailimage.php");
87
 
88
// }}}
89
// {{{ GLOBALS
90
 
91
// vorhandene Schriften
92
$GLOBALS['fonts'] = array
93
(
94
	'VERDANA_0.TTF',
95
	'He__h___.TTF',
96
	'framd.ttf',
97
	'slipf.ttf',
98
	'artro.ttf',
99
	'FRG55__C.TTF',
100
	'FRANKC__.TTF',
101
	'He__h__o.TTF',
102
	'frank.ttf',
103
	'fesf____.ttf',
104
	'denmark.ttf',
105
	'Headache.TTF',
106
	'Swz921n.ttf',
107
	'FRABK.TTF',
108
	'Marlbo.ttf',
109
	'FRADM.TTF',
110
	'Swz924n.ttf',
111
	'swissc.ttf',
112
	'FRAHV.TTF',
113
	'OfficinaSerifCTT.ttf',
114
	'FRAHVIT.TTF',
115
	'arial.ttf',
116
	'adbxtra.TTF',
117
	'ariblk.ttf',
118
	'HE______.TTF',
119
	'adbxtsc.TTF',
120
	'adbecnd.TTF',
121
	'tahomabd.ttf',
122
	'Marlboc.ttf',
123
	'OFFSETUP.TTF',
124
	'Marlbow.ttf',
125
	'adbxtrab.TTF',
126
	'ARIALBD.TTF',
127
	'ARIALBI.TTF',
128
	'adbecsc.TTF',
129
	'AARVC___.ttf',
130
	'erasure.ttf',
131
	'Sw721bci.ttf',
132
	'Sw721bco.ttf',
133
	'FRANST_U.TTF',
134
	'HELIOB.TTF',
135
	'HE_CH___.TTF',
136
	'OfficinaSansCTT.ttf',
137
	'FRADMCN.TTF',
138
	'Swz911uc.ttf',
139
	'He__l___.TTF',
140
	'He_ch__o.TTF',
141
	'adbnorm.TTF',
142
	'He__l__o.TTF',
143
	'xfiles.ttf',
144
	'FRAMDCN.TTF',
145
	'Frakturn.ttf',
146
	'dexgothn.ttf',
147
	'FRADMIT.TTF',
148
	'GALSBOLD.TTF',
149
	'HE___ULT.TTF',
150
	'dotmatrix.ttf',
151
	'He___eex.TTF',
152
	'SWZ911XC.TTF',
153
	'GALSLIGH.TTF',
154
	'He_____b.TTF',
155
	'He_____o.TTF',
156
	'HE__CMPR.TTF',
157
	'FLX_GIRL.TTF',
158
	'FRG65__C.TTF',
159
	'He____bo.TTF',
160
	'Swz721bc.ttf',
161
	'Swz721be.ttf',
162
	'Swz721bi.ttf',
163
	'Swz721bo.ttf',
164
	'TAHOMA.TTF',
165
	'Swz721br.ttf',
166
	'Swz721ci.ttf',
167
	'Sw721kci.ttf',
168
	'PupularScript.ttf',
169
	'Swz721k2.ttf',
170
	'trebucbd.TTF',
171
	'Swz721hi.ttf',
172
	'trebucbi.TTF',
173
	'framdit0.ttf',
174
	'Swz721kc.ttf',
175
	'Swz721ke.ttf',
176
	'Swz721ki.ttf',
177
	'Swz721lc.ttf',
178
	'trebuc.ttf',
179
	'Swz721ko.ttf',
180
	'Swz721le.ttf',
181
	'Swz721kr.ttf',
182
	'Swz721li.ttf',
183
	'Swz721mi.ttf',
184
	'boombox.ttf',
185
	'earth.ttf',
186
	'He_cl___.TTF',
187
	'adbcond.TTF',
188
	'trebucit.TTF',
189
	'He_cl__o.TTF',
190
	'Sw721lci.ttf',
191
	'framdit.ttf',
192
	'swisscb.ttf',
193
	'swisscbi.ttf',
194
	'swissci.ttf',
195
	'swisscbo.ttf',
196
	'swissck.ttf',
197
	'swisscl.ttf',
198
	'hoog0555_cyr.TTF',
199
	'Swz721ti.ttf',
200
	'TAHOMA_0.TTF',
201
	'Swz721b.ttf',
202
	'Swz721c.ttf',
203
	'Swz721e.ttf',
204
	'RADIOSTA.TTF',
205
	'Swz721h.ttf',
206
	'Swz721i.ttf',
207
	'Swz721k.ttf',
208
	'Swz721l.ttf',
209
	'Swz721m.ttf',
210
	'Swz721n.ttf',
211
	'Swz721t.ttf',
212
	'swisscki.ttf',
213
	'HE_CN__B.TTF',
214
	'swisscli.ttf',
215
	'AGENO___.ttf',
216
	'adbscaps.TTF',
217
	'FRABKIT.TTF'
218
);
219
 // -------------------
220
 // IF any put in here!
221
 // -------------------
222
function listTTFFonts($dir) {
223
	if ($handle = opendir($dir)) {
224
		$fontArray = "
225
		\$fonts = array (
226
			%s
227
		);
228
		";
229
		/* Das ist der korrekte Weg, ein Verzeichnis zu durchlaufen. */
230
		while (false !== ($file = readdir($handle))) {
231
			if (eregi(".ttf",$file)) {
232
				$buf[] = "'".$file."'";
233
			}
234
		}
235
		$buf = implode(
236
		",
237
		", $buf);
238
 
239
		closedir($handle);
240
		return sprintf($fontArray,$buf);
241
	}
242
}
243
// }}}
244
// {{{ Email_Safe
245
 
246
/**
247
 * This file is part of the Content-Active CMS System.
248
 * This class is available in other abstractions.
249
 *
250
 * This class handles template formates written in
251
 * Rapid_Template syntax. The syntax is shown in the
252
 * method itself. Or you could have a look in the
253
 * templates folder {@see templates/}.
254
 *
255
 * PHP versions 4 and 5
256
 *
257
 * LICENSE: This source file is subject to version 3.0 of the PHP license
258
 * that is available through the world-wide-web at the following URI:
259
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
260
 * the PHP License and are unable to obtain it through the web, please
261
 * send a note to license@php.net so we can mail you a copy immediately.
262
 *
263
 * @category   crypt
264
 * @package    Email_Safe
265
 * @author     Markus Niewerth <markus@weban.de>
266
 * @copyright  1997-2005 The PHP Group
267
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
268
 * @since      File available since Release 1.0.1
269
 */
270
 
271
class Email_Safe {
272
 
273
	// {{{ properties
274
 
275
	/**
276
	* @var   array    $configContents    Contents from email config
277
	*/
278
 
279
	var $configContents;
280
	var $configFile;
281
 
282
	// }}}
283
	// {{{ Email_Safe()
284
	/**
285
	* Email_Safe
286
	*
287
	* Email_Safe Basis Constructor
288
	*
289
	* @param     int      $contextId    Id for multi site parsing
290
	*                                   (needed for e.g. portal sites)
291
	*
292
	* @access    public
293
	*/
294
 
295
	function Email_Safe($configFile=false)
296
	{
297
		if ($configFile) {
298
			$this->configFile = $configFile;
299
			$this->read($this->configFile);
300
		}
301
	}
302
	// }}}
303
	// {{{ read()
304
 
305
	/**
306
	* read
307
	*
308
	* Liest die Konfiguration in den Speicher.
309
	*
310
	* @param     string  email
311
	*
312
	* @access    public
313
	*/
314
	function read($configFile=false)
315
	{
316
		if (isset($GLOBALS['email_config'])) {
317
			unset($GLOBALS['email_config']);
318
		}
319
		if ($configFile) {
320
			$this->configFile = $configFile;
321
		}
322
		if (file_exists($this->configFile) && is_readable($this->configFile)) {
323
			// read the config ontents
324
			$this->configContents = file($this->configFile);
325
		} else {
326
			return false;
327
		}
328
		return true;
329
	}
330
	// }}}
331
	// {{{ copyConfig()
332
 
333
	/**
334
	* copyConfig
335
	*
336
	* Kopiert die Konfiguration eines Templates.
337
	*
338
	* @param     string  email
339
	*
340
	* @access    public
341
	*/
342
	function copyConfig($destFile=false,$baseConfig=EMAIL_SAFE_DEFAULT_CONFIG)
343
	{
344
		if (!$destFile) {
345
			$destFile = $this->configFile;
346
		}
347
		if (!$destFile) {
348
			return false;
349
		}
350
		$stdConf 	= $this->readStdConfig($baseConfig);
351
		$filler = array
352
		(
353
			'file'	 	=> $destFile,
354
			'date' 		=> date("Y/m/d h:i:s"),
355
			'config' 	=> "\$GLOBALS['email_config'] = array();\r\n"
356
		);
357
		$newConf = sprintf
358
		(
359
			$stdConf,
360
			$filler['file'],
361
			$filler['date'],
362
			$filler['config']
363
		);
364
 
365
		$pathinfo = pathinfo($this->configFile);
366
 
367
		// --------
368
		// Temporaere Datei erzeugen
369
		// Und config schreiben
370
		$tmpf 	= tempnam ("/tmp", "EMAIL_CONF");
371
		$hnd 	= fopen($tmpf, "w");
372
		fwrite($hnd, $newConf);
373
		fclose($hnd);
374
 
375
		if (!copy($tmpf,$filler['file'])) {
376
			unlink($tmpf);
377
			return false;
378
		}
379
 
380
		// Symlink erzeugen
381
		symlink (EMAIL_SAFE_IMAGE_SYMLINK, $pathinfo["dirname"]."/mailimage.php" );
382
 
383
		unlink($tmpf);
384
		// --------
385
		return true;
386
	}
387
	// }}}
388
	// {{{ readStdConfig()
389
	/**
390
	* add
391
	*
392
	* Adds an email address to config file
393
	*
394
	* @param     string  email
395
	*
396
	* @access    public
397
	*/
398
	function readStdConfig($baseConfig) {
399
		return file_get_contents($baseConfig);
400
	}
401
	// }}}
402
	// {{{ add()
403
 
404
	/**
405
	* add
406
	*
407
	* Hinzufuegen einer Email zur Konfiguration.
408
	*
409
	* @param     string  email
410
	*
411
	* @access    public
412
	*/
413
	function add($email)
414
	{
415
		if (!$email) {
416
			return $this->read($this->configFile);
417
		}
418
		$this->read($this->configFile);
419
		// copy last tag
420
		$endTag = $this->configContents[sizeof($this->configContents)-1];
421
		$this->configContents[sizeof($this->configContents)-1] = "// added on: ".date("Y/m/d h:i:s")."\r\n";
422
		$this->configContents[sizeof($this->configContents)]   = "\$GLOBALS['email_config']['".md5($email)."'] = \"$email\";\r\n";
423
		$this->configContents[sizeof($this->configContents)]   = $endTag;
424
 
425
		$newContents = implode("",$this->configContents);
426
		if ($this->writeContentsToFile($newContents)) {
427
			$this->read($this->configFile);
428
			return $this->configContents;
429
		}
430
	}
431
	// }}}
432
	// {{{ writeContentsToFile()
433
 
434
	/**
435
	* add
436
	*
437
	* Schreibt den uebermittelten Inhalt in
438
	* die Konfigurations Datei. Wenn nichts uebergeben
439
	* wird, so wird die Konfigurations- Voreinstellung
440
	* des Konstruktors uebernommen.
441
	* {@see $this->configFile}
442
	*
443
	*
444
	* @param     string  contents
445
	*
446
	* @access    public
447
	*/
448
	function writeContentsToFile($contents=false)
449
	{
450
		if (!$contents || !is_writable($this->configFile)) {
451
			return false;
452
		}
453
		if (is_array($contents)) {
454
			$contents = implode("",$contents);
455
		}
456
		$fp = fopen($this->configFile,"w");
457
		if (!fwrite($fp,$contents)) {
458
			fclose($fp);
459
			return false;
460
		}
461
		fclose($fp);
462
		return true;
463
	}
464
	// }}}
465
	// {{{ remove()
466
 
467
	/**
468
	* remove
469
	*
470
	* Entfernen einer Email Adresse von der
471
	* Konfiguration.
472
	*
473
	* @param     string  email
474
	*
475
	* @access    public
476
	*/
477
	function remove($email)
478
	{
479
		$key = md5($email);
480
		$this->read($this->configFile);
481
		foreach (array_keys($this->configContents) as $aKey) {
482
			if (eregi("$key",$this->configContents[$aKey])) {
483
				unset($this->configContents[$aKey-1]);
484
				unset($this->configContents[$aKey]);
485
			}
486
		}
487
 
488
		if ($this->writeContentsToFile($this->configContents)) {
489
			$this->read($this->configFile);
490
			return $this->configContents;
491
		}
492
	}
493
	// }}}
494
	// {{{ createEmailImage()
495
	/**
496
	* createEmailImage
497
	*
498
	* Erstellt ein Bild zu einer angegebenen Adresse.
499
	* Sieht einem Formular Textfeld sehr aehnlich.
500
	*
501
	* @param     string  email
502
	*
503
	* @access    public
504
	*/
505
	function createEmailImage ($code, $fontSize=8, $fontType=0, $fontColor='255,255,255', $backColor='0,0,0',$createFromImage=true)
506
	{
507
		if (file_exists($_SERVER['DOCUMENT_ROOT']."/emailconfig.default.inc.php"))
508
		{
509
			include($_SERVER['DOCUMENT_ROOT']."/emailconfig.default.inc.php");
510
		} else {
511
			return false;
512
		}
513
 
514
		if (eregi("[a-z0-9]{32}",$code))
515
		{
516
			$email = $GLOBALS['email_config'][$code];
517
		} else {
518
			$email = $code;
519
		}
520
 
521
		$fontColor = explode(",",$fontColor);
522
		$backColor = explode(",",$backColor);
523
 
524
		$code = md5($email);
525
 
526
		header ("Content-type: ".EMAIL_SAFE_EMAIL_IMAGE_CONTENT_TYPE);
527
 
528
		if ($createFromImage){
529
			$cp_im = imagecreatefromjpeg(EMAIL_SAFE_IMAGE_EMAIL_INPUT);
530
		} else {
531
			$cp_im = imagecreate ( ((100)+(strlen($email)*($fontSize/4))) , $fontSize+(10));
532
		}
533
 
534
		$back = ImageColorAllocate ($cp_im, $backColor[0], $backColor[1], $backColor[2]);
535
		$font = ImageColorAllocate ($cp_im, $fontColor[0], $fontColor[1], $fontColor[2]);
536
 
537
		$y = $fontSize+(5);
538
		$x = 2;
539
 
540
		imagettftext ($cp_im , $fontSize , 0, $x, $y, $font, EMAIL_SAFE_GD_TTF_FONT_DIR.$GLOBALS['fonts'][$fontType], $email);
541
 
542
		imagepng 	 ($cp_im);
543
		imagedestroy ($cp_im);
544
 
545
		return true;
546
	}
547
	// }}}
548
}
549
// }}}
550
 
551
/*
552
 * Local variables:
553
 * tab-width: 4
554
 * c-basic-offset: 4
555
 * c-hanging-comment-ender-p: nil
556
 * End:
557
 */
558
?>