summaryrefslogtreecommitdiff
path: root/test/manual/etags/php-src
diff options
context:
space:
mode:
Diffstat (limited to 'test/manual/etags/php-src')
-rw-r--r--test/manual/etags/php-src/lce_functions.php699
-rw-r--r--test/manual/etags/php-src/ptest.php18
-rw-r--r--test/manual/etags/php-src/sendmail.php527
3 files changed, 1244 insertions, 0 deletions
diff --git a/test/manual/etags/php-src/lce_functions.php b/test/manual/etags/php-src/lce_functions.php
new file mode 100644
index 00000000000..65738134593
--- /dev/null
+++ b/test/manual/etags/php-src/lce_functions.php
@@ -0,0 +1,699 @@
+<?php
+if(!defined("LCE_FUNCTIONS"))
+{
+ define("LCE_FUNCTIONS", 1);
+ include("base.php");
+ include("lce_config.php");
+
+ // Unknown line class
+ define("LCE_UNKNOWN", 0);
+ // pure whitespace
+ define("LCE_WS", 1);
+ // a unqualified comment
+ define("LCE_COMMENT", 2);
+ // a user/translator comment
+ define("LCE_COMMENT_USER", 3);
+ // a tool-generated comment
+ define("LCE_COMMENT_TOOL", 4);
+ // A line containing a MSGID
+ define("LCE_MSGID", 5);
+ // A line containing a MSGSTR
+ define("LCE_MSGSTR", 6);
+ // A quoted text string
+ define("LCE_TEXT", 7);
+
+ define("STATE_ABORT", 0);
+ define("STATE_OK", 1);
+ define("STATE_LOOP", 2);
+
+ class POEntryAD extends AD
+ {
+ function validate($value)
+ {
+ // print '"<pre>' . $value . '"<br></pre>';
+ $result = AD::validate(trim($value));
+ //return $result;
+ if($result[0])
+ {
+ $lines = explode("\n", ereg_replace("\r", "", $result[1]));
+ //$lines = explode("\n", $result[1]);
+ /* print "<pre>";
+ print_r($lines);
+ print "</pre>";*/
+ $res = array();
+ for($i = 0; $i < count($lines); $i++)
+ {
+ if(trim($lines[$i]) != "")
+ $res[] = $lines[$i];
+ }
+ $result[1] = join("\n", $res);
+ /* print "<pre>";
+ print_r($result[1]);
+ print "</pre>";*/
+
+ $result[0] = $this->checkQuotation($result[1]);
+ }
+ return $result;
+ }
+
+ function checkQuotation($str)
+ {
+ $rex = "\\\\n|\\\\t|\\\\r|\\\\\"";
+ $str = ereg_replace($rex, "", $str);
+ $str = ereg_replace("\\\\\\\\", "", $str);
+ return !(strstr($str, "\"")
+ || strstr($str, "\\"));
+ }
+ }
+
+
+ class CommentAD extends AD
+ {
+ var $prefix;
+ function CommentAD(
+ $name, // the name of the variable
+ $not_null = 0,
+ $type = "", // as returned by gettype
+ $prefix = "# ")
+ {
+ $this->prefix = $prefix;
+ AD::AD($name, $not_null, $type);
+ }
+
+ function validate($value)
+ {
+ $res = AD::validate($value);
+ return $res;
+ if($res[0] && $res[1] != "")
+ {
+ $mod_lines = array();
+ $lines = explode("\n", $res[1]);
+
+ for($i = 0; $i < count($lines); $i++)
+ {
+ $line = $lines[$i];
+ if(substr($line, 0, 1) != "#")
+ $line = $this->prefix . $line;
+ $mod_lines[] = $line;
+ }
+ $res[1] = join("\n", $mod_lines);
+ }
+ return $res;
+ }
+ }
+
+ class POEntry extends HtmlValidator
+ {
+ var $msgid;
+ var $msgstr;
+ var $user_comment;
+ var $sys_comment;
+ var $unk_comment;
+
+ var $msgid_lc = 0;
+ var $msgstr_lc = 0;
+ var $user_comment_lc = 0;
+ var $sys_comment_lc = 0;
+ var $unk_comment_lc = 0;
+
+ function POEntry()
+ {
+ $this->atts = array(
+ new AD("msgid"),
+ new POEntryAD("msgstr", REQUIRED_ATTRIBUTE),
+ new CommentAD("user_comment"),
+ new POEntryAD("sys_comment"),
+ new POEntryAD("unk_comment"),
+ new AD("msgid_lc", NOT_REQUIRED_ATTRIBUTE, 0),
+ new AD("msgstr_lc", NOT_REQUIRED_ATTRIBUTE, 0),
+ new AD("user_comment_lc", NOT_REQUIRED_ATTRIBUTE, 0),
+ new AD("sys_comment_lc", NOT_REQUIRED_ATTRIBUTE, 0),
+ new AD("unk_comment_lc", NOT_REQUIRED_ATTRIBUTE, 0)
+ );
+ }
+
+ function lineCount($entry)
+ {
+ $lc = count(explode("\n", $entry));
+ return $lc;
+ }
+
+ function serializeToVars($prefix)
+ {
+ $this->user_comment_lc = $this->lineCount($this->user_comment);
+ $this->unk_comment_lc = $this->lineCount($this->sys_comment);
+ $this->sys_comment_lc = $this->lineCount($this->unk_comment);
+ $this->msgid_lc = $this->lineCount($this->msgid);
+ $this->msgstr_lc = $this->lineCount($this->msgstr);
+ return HtmlValidator::serializeToVars($prefix);
+ }
+
+ function write()
+ {
+ $content = "";
+ $content .= $this->user_comment . "\n";
+ $content .= $this->unk_comment . "\n";
+ $content .= $this->sys_comment . "\n";
+ $content .= "msgid \"" . $this->msgid . "\"\n";
+ $content .= 'msgstr "' . join("\"\n\"", explode("\n", $this->msgstr)) . "\"" . "\n\n";
+ return $content;
+ }
+ }
+
+ class POReader extends HTMLValidator
+ {
+ var $msgid;
+ var $msgstr;
+ var $user_comment;
+ var $sys_comment;
+ var $unk_comment;
+ var $state;
+ var $ignore_ws;
+ var $po_entries;
+ var $poe_num;
+ var $filename;
+ var $domain;
+
+ function gettext($msgid)
+ {
+ if(isset($this->po_entries[$msgid]))
+ {
+ $po = $this->po_entries[$msgid];
+ return StripCSlashes(join("", explode("\n", $po->msgstr)));
+ //return $po->msgstr;
+ }
+ return $msgid;
+ }
+
+
+ function parseFromVars($prefix)
+ {
+ $res = HtmlValidator::parseFromVars($prefix);
+ if($res[0])
+ {
+ $poe_res = true;
+ $this->po_entries = array();
+ for($i = 0; $i < $this->poe_num; $i++)
+ {
+ $poe = new POEntry;
+ $res = $poe->parseFromVars($prefix . "_POE$i");
+ if($res[0])
+ {
+ $msgid = $prefix . "_POE" . $i . "_MSGID";
+ $msgid = $$msgid;
+ $this->po_entries[$prefix . "_POE" . $i . "_MSGID"] = $res[1];
+ }
+ else
+ $poe_res = false;
+ }
+ }
+ if(!$poe_res)
+ $GLOBALS[$prefix . "_ERR"] = 1;
+ return array($poe_res, $this);
+ }
+
+ function serializeToVars($prefix)
+ {
+ HtmlValidator::serializeToVars($prefix);
+ reset($this->po_entries);
+ $i = 0;
+ while($poe = each($this->po_entries))
+ {
+ $poe = $poe[1];
+ $poe->serializeToVars($prefix . "_POE$i");
+ $i++;
+ }
+ }
+
+
+ function POReader($domain, $filename)
+ {
+ $this->domain = $domain;
+ $this->filename = $filename;
+ $this->ignore_ws = true;
+ $this->po_entries = array();
+ $this->atts = array(
+ new AD("domain", REQUIRED_ATTRIBUTE),
+ new AD("filename", REQUIRED_ATTRIBUTE),
+ new AD("poe_num", REQUIRED_ATTRIBUTE, 0)
+ );
+ }
+
+
+ function read()
+ {
+ if($fh = fopen($this->filename, "r"))
+ {
+ $this->lines = array();
+ while (!feof ($fh))
+ {
+ $line = fgets($fh, 4096);
+ $this->lines[] = $line;
+ }
+ fclose($fh);
+ }
+ $this->createPOEntries();
+ $this->poe_num = count($this->po_entries);
+ }
+
+ function write($save="yes")
+ {
+ reset($this->po_entries);
+ $content = "";
+ while($poe = each($this->po_entries))
+ {
+ $poe = $poe[1];
+ $content .= $poe->write();
+ }
+
+ if(($fh = fopen($this->filename, "w"))
+ && $save == "yes")
+ {
+ fwrite($fh, $content);
+ }
+ return $content;
+ }
+
+ function isComment($class)
+ {
+ if($class == LCE_COMMENT || $class == LCE_COMMENT_USER || $class == LCE_COMMENT_TOOL)
+ return true;
+ return false;
+ }
+
+ function comment($line, $class)
+ {
+ if($this->isComment($class))
+ {
+ if($class == LCE_COMMENT_USER)
+ $this->user_comment .= $line;
+ else if($class == LCE_COMMENT_TOOL)
+ $this->sys_comment .= $line;
+ else
+ $this->unk_comment .= $line;
+ return STATE_OK;
+ }
+ if($class == LCE_MSGID)
+ {
+ $this->state = "msgid";
+ return STATE_LOOP;
+ }
+ return STATE_ABORT;
+ }
+
+ function msgid($line, $class)
+ {
+ if($class == LCE_MSGID || $class == LCE_TEXT)
+ {
+ $line = $this->stripLine($line, LCE_MSGID);
+ $this->msgid .= $line;
+ return STATE_OK;
+ }
+ if($class == LCE_MSGSTR)
+ {
+ $this->state = "msgstr";
+ return STATE_LOOP;
+ }
+ return STATE_ABORT;
+ }
+
+ function msgstr($line, $class)
+ {
+ if($class == LCE_MSGSTR || $class == LCE_TEXT)
+ {
+ $line = $this->stripLine($line, $class);
+ $this->msgstr .= $line;
+ return STATE_OK;
+ }
+ // We have a different state, so we have to create a POEntry
+ $poe = new POEntry;
+ $poe->user_comment = trim($this->user_comment);
+ $poe->sys_comment = trim($this->sys_comment);
+ $poe->unk_comment = trim($this->unk_comment);
+ $poe->msgid = trim($this->msgid);
+ $poe->msgstr = trim($this->msgstr);
+ $this->po_entries[trim($this->msgid)] = $poe;
+ $this->state = "start";
+ return STATE_LOOP;
+ }
+
+ function start($line, $class)
+ {
+ $this->user_comment = "";
+ $this->sys_comment = "";
+ $this->unk_comment = "";
+ $this->msgid = "";
+ $this->msgstr = "";
+ if($this->isComment($class))
+ {
+ $this->state = "comment";
+ return STATE_LOOP;
+ }
+ if($class == LCE_MSGID)
+ {
+ $this->state = "msgid";
+ return STATE_LOOP;
+ }
+ return STATE_OK;
+ }
+
+ function createPOEntries()
+ {
+ $this->msgid = "";
+ $this->msgstr = "";
+ $this->user_comment = "";
+ $this->sys_comment = "";
+ $this->state = "start";
+
+ reset($this->lines);
+ for($i = 0; $i < count($this->lines); $i++)
+ {
+ $line = $this->lines[$i];
+ $class = $this->classifyLine($line);
+ if($class != LCE_WS || !$this->ignore_ws)
+ {
+ $state_ret = STATE_LOOP;
+ while($state_ret == STATE_LOOP)
+ {
+ $state = $this->state;
+ //print "$this->state $class:$line <br>";
+ $state_ret = $this->$state($line, $class);
+ }
+ //print "state_ret = $state_ret <br>";
+ }
+ if($state_ret == STATE_ABORT)
+ break;
+ }
+ // Get the last entry
+ if($state_ret != STATE_ABORT)
+ {
+ $this->msgstr("", LCE_UNKNOWN);
+ }
+ }
+
+ function stripLine($line, $class)
+ {
+ switch($class)
+ {
+ case LCE_TEXT:
+ ereg('^"(.*)"', $line, $regs);
+ $line = $regs[1] . "\n";
+ break;
+ case LCE_MSGID:
+ if(substr($line, strlen("msgid")) == "msgid")
+ {
+ $line = substr($line, strlen("msgid") + 1);
+ }
+ ereg('"(.*)"', $line, $regs);
+ $line = $regs[1];
+ break;
+ case LCE_MSGSTR:
+ // TODO: Check if ^ can be removed
+ $line = substr($line, strlen("msgstr") + 1);
+ ereg('^"(.*)"', $line, $regs);
+ $line = $regs[1] . "\n";
+ break;
+
+ }
+ return $line;
+ }
+
+ function printClassification()
+ {
+ reset($this->lines);
+ for($i = 0; $i < count($this->lines); $i++)
+ {
+ $line = $this->lines[$i];
+ $class = $this->classifyLine($line);
+ print "#$i: $class $line<br>";
+ }
+ }
+
+ function classifyLine($line)
+ {
+ if(ereg("^[ \n\r\t]*$", $line))
+ return LCE_WS;
+ if(ereg("^#.*\$", $line))
+ {
+ if(ereg("^[,:-~].*", substr($line, 1)))
+ {
+ return LCE_COMMENT_TOOL;
+ }
+ if(ereg("^[ \n\r\t].*", substr($line, 1)))
+ {
+ return LCE_COMMENT_USER;
+ }
+ return LCE_COMMENT;
+ }
+ if(ereg("^msgid (.*)\$", $line, $regs))
+ {
+ $line = $regs[1];
+ if($this->classifyLine($line) == LCE_TEXT)
+ return LCE_MSGID;
+ }
+ if(ereg("^msgstr (.*)\$", $line, $regs))
+ {
+ $line = $regs[1];
+ if($this->classifyLine($line) == LCE_TEXT)
+ return LCE_MSGSTR;
+ }
+ if(ereg('^".*"', $line))
+ {
+ // TODO: Check correct escapes
+ return LCE_TEXT;
+ }
+
+ return LCE_UNKNOWN;
+ }
+ }
+
+
+ function getTextDomains($lines)
+ {
+ $default_domain = "";
+ $domains = array();
+ while($gl = each($GLOBALS))
+ {
+ $gname = $gl[0];
+ global $$gname;
+ }
+ for($i = 0; $i < count($lines); $i++)
+ {
+ if(ereg("bindtextdomain\(([^,]+),([^\)]+)\)", $lines[$i], $regs))
+ {
+ //print "Line:" . $lines[$i] . " <br>";
+ $name = $regs[1];
+ $ev = "\$directory = ". $regs[2] . ";";
+ print $ev;
+ eval($ev);
+ $domains[] = array($name, $directory);
+ }
+ if(ereg("textdomain\(([^\)]+)\)", $lines[$i], $regs))
+ $default_domain = $regs[1];
+ }
+ return array($default_domain, $domains);
+ }
+
+
+ class PORManager extends HtmlValidator
+ {
+ var $por_a;
+
+ function PORManager()
+ {
+ $this->por_a = array();
+ }
+
+ function addPOReader($d_name, &$por)
+ {
+ $this->por_a[$d_name] = &$por;
+ }
+
+ function &getPOReader($domain)
+ {
+ return $this->por_a[$domain];
+ }
+
+ function getDomainNames()
+ {
+ return array_keys($this->por_a);
+ }
+ }
+
+ function &loadPORManager()
+ {
+ global $LCE_PORMAN;
+ if(!isset($LCE_PORMAN))
+ {
+ $LCE_PORMAN = new PORManager();
+ }
+ return $LCE_PORMAN;
+ }
+
+
+ // More or less intelligent filename joining
+ // As available in PYTHONs os.path
+ function fileJoin()
+ {
+ $numargs = func_num_args();
+ $args = func_get_args();
+ for($i = 0; $i < $numargs - 1; $i++)
+ {
+ if(substr($args[$i], -1) != "/")
+ $args[$i] = $args[$i] . "/";
+ if($i > 0)
+ {
+ if(substr($args[$i],0 , 1) == "/")
+ $args[$i] = substr($args[$i], 1);
+ }
+
+ }
+ return join("", $args);
+ }
+
+ if(defined("LCE_TESTSERVER"))
+ {
+
+ function lce_bindtextdomain($d_name, $d_path)
+ {
+ global $LANG, $LC_MESSAGES, $LC_ALL, $LCE_LANG;
+ global $LCE_ERR;
+ global $LCE_PO_SUFFIX;
+ global $LCE_MANAGER;
+
+ $path_orig = $d_path;
+ // This is not complete and reflects
+ // my not very far going understanding of the
+ // different $LC_x thingies.
+ if(isset($LC_MESSAGES))
+ {
+ //print "LC_MESSAGES<br>";
+ $lang_suffix = $LC_MESSAGES;
+ }
+ else if(isset($LC_ALL))
+ {
+ //print "LC_ALL<br>";
+ $lang_suffix = $LC_ALL;
+ }
+ else if(isset($LANG))
+ {
+ //print "LANG<br>";
+ $lang_suffix = $LANG;
+ }
+ else
+ {
+ //print "LCE_LANG<br>";
+ $lang_suffix = $LCE_LANG;
+ }
+
+ //print "LangSuffix: $lang_suffix \n";
+ //print "D_Path: " . fileJoin($d_path, $lang_suffix, "LC_MESSAGES", $d_name . $LCE_PO_SUFFIX) . "<br>";
+ // First try: the whole lang_suffix
+
+ if(file_exists(fileJoin($d_path, $lang_suffix, "LC_MESSAGES", $d_name . $LCE_PO_SUFFIX)))
+ $d_path = fileJoin($d_path, $lang_suffix, "LC_MESSAGES", $d_name . $LCE_PO_SUFFIX);
+ else
+ {
+ $lang_suffix = substr($lang_suffix, 0, 2);
+ if(file_exists(fileJoin($d_path, $lang_suffix, "LC_MESSAGES", $d_name. $LCE_PO_SUFFIX)))
+ $d_path = fileJoin(fileJoin($d_path, $lang_suffix, "LC_MESSAGES", $d_name . $LCE_PO_SUFFIX));
+ else
+ {
+ $LCE_ERR = "No PO-file found";
+ return false;
+ }
+ }
+ //print "D_Path: $d_path \n";
+ $por = new POReader($d_name, $d_path, $path_orig);
+ $por->read();
+ $porman =& loadPORManager();
+ $porman->addPOReader($d_name, $por);
+ return true;
+ }
+
+ function lce_textdomain($domain)
+ {
+ global $LCE_DOMAIN;
+ $LCE_DOMAIN = $domain;
+ }
+
+ function lce_gettext($msgid)
+ {
+ global $LCE_DOMAIN;
+ return lce_dgettext($LCE_DOMAIN, $msgid);
+ }
+
+ function lce_dgettext($domain, $msgid)
+ {
+ $porman =& loadPORManager();
+ if($por = &$porman->getPOReader($domain))
+ return $por->gettext($msgid);
+ return $msgid;
+ }
+
+ function lce()
+ {
+ global $LCE_LCEDITLOC;
+ $porman =& loadPORManager();
+ $domains = $porman->getDomainNames();
+ for($i = 0; $i < count($domains); $i++)
+ {
+ $por =& $porman->getPOReader($domains[$i]);
+ $domain = "domain=" . urlencode($por->domain);
+ $filename = "filename=" . urlencode($por->filename);
+ $url = $LCE_LCEDITLOC . "?" . $domain . "&" . $filename;
+ print "<a target=\"_blank\" href=\"" . $url . "\">Domain: $por->domain</a><br>";
+ }
+ }
+ }
+ else
+ {
+ function lce_bindtextdomain($domain, $path)
+ {
+ bindtextdomain($domain, $path);
+ }
+
+ function lce_textdomain($domain)
+ {
+ textdomain($domain);
+ }
+
+ function lce_gettext($msgid)
+ {
+ return gettext($msgid);
+ }
+
+ function lce_dgettext($domain, $msgid)
+ {
+ return dgettext($domain, $msgid);
+ }
+ function lce()
+ {
+ }
+ }
+
+
+ function lce_geteditcode($type, $name, $text, $rows=2)
+ {
+ global $LCE_EDIT_LEVEL;
+ $level_map = array("msgid" => 4,
+ "sys_comment" => 3,
+ "user_comment" => 2,
+ "msgstr" => 1
+ );
+ if($level_map[$type] > $LCE_EDIT_LEVEL)
+ {
+ return "<input type=\"hidden\" name=\"" . $name . "\" value=\"" . $text . "\"><pre>\n" . $text . "\n</pre>";
+ }
+ else
+ {
+ return "<textarea name=\"" . $name . "\" rows=\"" . $rows . "\" cols=\"60\">" . $text . "</textarea>";
+ }
+ }
+}
+/*
+ ;;; Local Variables: ***
+ ;;; mode:C ***
+ ;;; End: ***
+*/
+?>
diff --git a/test/manual/etags/php-src/ptest.php b/test/manual/etags/php-src/ptest.php
new file mode 100644
index 00000000000..9893839b493
--- /dev/null
+++ b/test/manual/etags/php-src/ptest.php
@@ -0,0 +1,18 @@
+define("TEST", 0);
+
+class
+test
+extends base
+{
+ // use --member to tag
+ var $member;
+ var $memassign="hallo";
+ var $memassign_space ="hallo";
+ // Syntactical wrong, but tagged
+ var $test
+}
+
+function
+foo()
+{
+}
diff --git a/test/manual/etags/php-src/sendmail.php b/test/manual/etags/php-src/sendmail.php
new file mode 100644
index 00000000000..1d15e4ad9f6
--- /dev/null
+++ b/test/manual/etags/php-src/sendmail.php
@@ -0,0 +1,527 @@
+<?php
+
+/*
+ Classe creata da Santoro Diego.
+ Per aiuti nella programmazione in PHP, PERL, C e ECMAScript contattatemi
+ e-Mail vincenza.tralice@tiscali.it oppure santoro.diego@3000.it
+ La classe ? ancora in fase beta.
+*/
+
+final class sendMail {
+
+ const eMailAddressErrorMessage="L' e-Mail indicata non rispetta un formato valido.";
+ const defaultSubject="this is the subject.";
+ const defaultTextMessage="this is text message.";
+ const defaultHtmlMessage="this is html message.";
+ const defaultHeaderMessage="this is a multi-part message in MIME format.";
+
+ private static $messageProperties=array(
+ "charset" => array(
+ "modifiable" => true,
+ "values" => array(
+ "iso-8859-1",
+ "iso-8859-15",
+ "utf-8",
+ "utf-16"
+ )
+ ),
+ "content-transfer-encoding" => array(
+ "modifiable" => true,
+ "values" => array(
+ "7bit",
+ "8bit",
+ "quoted-printable"
+ )
+ )
+ );
+
+ private $attachmentProperties=array(
+ "content-type" => array(
+ "modifiable" => false,
+ "values" => array(
+ "application/octet-stream"
+ )
+ ),
+ "content-transfer-encoding" => array(
+ "modifiable" => false,
+ "values" => array(
+ "base64"
+ )
+ ),
+ "content-disposition" => array(
+ "modifiable" => true,
+ "values" => array(
+ "attachment",
+ "inline"
+ )
+ )
+ );
+
+ private static $relatedProperties=array(
+ "content-transfer-encoding" => array(
+ "modifiable" => false,
+ "values" => array(
+ "base64"
+ )
+ )
+ );
+
+ private $html;
+ private $text;
+
+ private $related;
+ private $attachments;
+
+ public static function valid_eMailAddress($eMailAddress) {
+ if(ereg("^[^@ ]+@[^@ ]+\.[^@ ]+$", $eMailAddress))
+ return true;
+ else
+ return false;
+ }
+
+ public static function validContentId($contentId) {
+ if(ereg("^[a-zA-Z0-9]+$", $contentId))
+ return true;
+ else
+ return false;
+ }
+
+ public static function validContentKey($contentKey) {
+ if(ereg("^[a-zA-Z0-9]+$", $contentKey))
+ return true;
+ else
+ return false;
+ }
+
+ public static function mime_content_type($filename) {
+ $mime=array(
+ '.3dmf' => 'x-world/x-3dmf',
+ '.a' => 'application/octet-stream',
+ '.aab' => 'application/x-authorware-bin',
+ '.xwd' => 'image/x-xwd',
+ '.xyz' => 'chemical/x-pdb',
+ '.z' => 'application/x-compressed',
+ '.zip' => 'application/x-zip-compressed',
+ '.zoo' => 'application/octet-stream',
+ '.zsh' => 'text/x-script.zsh',
+ '.css' => 'text/css'
+ );
+ return $mime[strrchr($filename, '.')];
+ }
+
+ private $from;
+ private $to;
+ private $subject;
+
+ private $finalized;
+
+ private $headerMessage;
+ private $bodyMessage;
+
+ private $boundaries;
+
+ public function __construct($from, $to, $subject=self::defaultSubject) {
+
+ // set from
+ if(!self::valid_eMailAddress($from))
+ die(self::eMailAddressErrorMessage);
+ else
+ $this->from=$from;
+
+ // set to
+ if(!self::valid_eMailAddress($to))
+ die(self::eMailAddressErrorMessage);
+ else
+ $this->to=$to;
+
+ // set subject
+ $this->subject=$subject;
+
+ // set text
+ $this->text=array(
+ "message" => self::defaultTextMessage,
+ "properties" => array(
+ "charset" => self::$messageProperties["charset"]["values"][0],
+ "content-transfer-encoding" => self::$messageProperties["content-transfer-encoding"]["values"][0]
+ )
+ );
+
+ // set html
+ $this->html=array(
+ "message" => self::defaultHtmlMessage,
+ "properties" => array(
+ "charset" => self::$messageProperties["charset"]["values"][0],
+ "content-transfer-encoding" => self::$messageProperties["content-transfer-encoding"]["values"][1]
+ )
+ );
+
+ // set related and attachments
+ $this->related=array();
+ $this->attachments=array();
+
+ // set finalizater counter
+ $this->finalized=false;
+
+ $this->headerMessage="";
+ $this->bodyMessage="";
+
+ $this->boundaries=array(
+ "multipart/alternative" => md5(uniqid(microtime())),
+ "multipart/related" => md5(uniqid(microtime())),
+ "multipart/mixed" => md5(uniqid(microtime()))
+ );
+
+ }
+
+ public function setTo($to, &$errorString) {
+ if(self::valid_eMailAddress($to)) {
+ $this->to=$to;
+ return true;
+ } else {
+ $errorString=eMailAddressErrorMessage;
+ return false;
+ }
+ }
+
+ public function setFrom($from, &$errorString) {
+ if(self::valid_eMailAddress($from)) {
+ $this->from=$from;
+ return true;
+ } else {
+ $errorString=eMailAddressErrorMessage;
+ return false;
+ }
+ }
+
+ public function setSubject($subject=self::defaultSubject) {
+ $this->subject=$subject;
+ }
+
+ public function setTextMessage($textMessage=self::defaultTextMessage) {
+ $this->text["message"]=$textMessage;
+ }
+
+ public function setTextMessageProperty($key, $value, &$errorString) {
+
+ $key=strtolower($key);
+ $value=strtolower($value);
+
+ if(isset(self::$messageProperties[$key])) {
+ if(in_array($value, self::$messageProperties[$key]["values"])) {
+ if(self::$messageProperties[$key]["modifiable"]) {
+ $this->text["properties"][$key]=$value;
+ return true;
+ } else {
+ $errorString="Il valore della propriet? indicata non ? modificabile.";
+ return false;
+ }
+ } else {
+ $errorString="Il valore indicato per questa propriet? non ? valido.";
+ return false;
+ }
+ } else {
+ $errorString="Non esiste questa propriet? per i messaggi html.";
+ return false;
+ }
+ }
+
+ public function setHtmlMessage($htmlMessage=self::defaultHtmlMessage) {
+ $this->html["message"]=$htmlMessage;
+ }
+
+ public function setHtmlMessageProperty($key, $value, &$errorString) {
+
+ $key=strtolower($key);
+ $value=strtolower($value);
+
+ if(isset(self::$messageProperties[$key])) {
+ if(in_array($value, self::$messageProperties[$key]["values"])) {
+ if(self::$messageProperties[$key]["modifiable"]) {
+ $this->html["properties"][$key]=$value;
+ return true;
+ } else {
+ $errorString="Il valore della propriet? indicata non ? modificabile.";
+ return false;
+ }
+ } else {
+ $errorString="Il valore indicato per questa propriet? non ? valido.";
+ return false;
+ }
+ } else {
+ $errorString="Non esiste questa propriet? per i messaggi html.";
+ return false;
+ }
+ }
+
+ public function addRelated($fileName, $relatedKey, $contentId, &$errorString) {
+ if(is_file($fileName)) {
+ if($fileHandle=fopen($fileName, "r")) {
+ if(self::validContentId($contentId)) {
+ if(!isset($this->related[$relatedKey])) {
+ if(self::validContentKey($relatedKey)) {
+ $this->related[$relatedKey]=array(
+ "fileName" => basename($fileName),
+ "properties" => array(
+ "content-type" => self::mime_content_type($fileName),
+ "content-transfer-encoding" => self::$relatedProperties["content-transfer-encoding"]["values"][0],
+ "content-id" => $contentId
+ ),
+ "source" => base64_encode(
+ fread($fileHandle, filesize($fileName))
+ )
+ );
+ return true;
+ } else {
+ $errorString="L' id specificato non ? valido.";
+ return false;
+ }
+ } else {
+ $errorString="La chiave specificata ? gi? associata ad un altro related.";
+ return false;
+ }
+ } else {
+ $errorString="La chiave specificata per il related non ? valida.";
+ return false;
+ }
+ } else {
+ $errorString="Non ? possibile aprire il file indicato.";
+ return false;
+ }
+ } else {
+ $errorString="Il nome del file indicato non ? valido.";
+ return false;
+ }
+ }
+
+ public function setRelatedProperty($relatedKey, $key, $value, &$errorString) {
+
+ $key=strtolower($key);
+ $value=strtolower($value);
+
+ if(isset(self::$relatedProperties[$key])) {
+ if(in_array($value, self::$relatedProperties[$key]["values"])) {
+ if(self::$relatedProperties[$key]["modifiable"]) {
+ if(isset($this->related[$relatedKey])) {
+ $this->related[$relatedKey]["properties"][$key]=$value;
+ return true;
+ } else {
+ $errorString="Il related indicato non esiste.";
+ return false;
+ }
+ } else {
+ $errorString="Il valore della propriet? indicata non ? modificabile.";
+ return false;
+ }
+ } else {
+ $errorString="Il valore indicato per questa propriet? non ? valido.";
+ return false;
+ }
+ } else {
+ $errorString="Non esiste questa propriet? per i related.";
+ return false;
+ }
+ }
+
+ public function addAttachment($fileName, $attachmentKey, &$errorString) {
+ if(is_file($fileName)) {
+ if($fileHandle=fopen($fileName, "r")) {
+ if(self::validContentKey($attachmentKey)) {
+ if(!isset($this->attachments[$attachmentKey])) {
+ $this->attachments[$attachmentKey]=array(
+ "fileName" => basename($fileName),
+ "properties" => array(
+ "content-type" => self::$attachmentProperties["content-type"]["values"][0],
+ "content-disposition" => self::$attachmentProperties["content-disposition"]["values"][0],
+ "content-transfer-encoding" => self::$attachmentProperties["content-transfer-encoding"]["values"][0]
+ ),
+ "source" => base64_encode(
+ fread($fileHandle, filesize($fileName))
+ )
+ );
+ return true;
+ } else {
+ $errorString="La chiave specificata ? gi? associata ad un altro allegato.";
+ return false;
+ }
+ } else {
+ $errorString="La chiave specificata per l'allegato non ? valida.";
+ return false;
+ }
+ } else {
+ $errorString="Non ? possibile aprire il file indicato.";
+ return false;
+ }
+ } else {
+ $errorString="Il nome del file indicato non ? valido.";
+ return false;
+ }
+ }
+
+ public function setAttachmentProperty($attachmentKey, $key, $value, &$errorString) {
+
+ $key=strtolower($key);
+ $value=strtolower($value);
+
+ if(isset(self::$attachmentProperties[$key])) {
+ if(in_array($value, self::$attachmentProperties[$key]["values"])) {
+ if(self::$attachmentProperties[$key]["modifiable"]) {
+ if(isset($this->attachments[$attachmentKey])) {
+ $this->attachments[$attachmentKey]["properties"][$key]=$value;
+ return true;
+ } else {
+ $errorString="L'allegato indicato non esiste.";
+ return false;
+ }
+ } else {
+ $errorString="Il valore della propriet? indicata non ? modificabile.";
+ return false;
+ }
+ } else {
+ $errorString="Il valore indicato per questa propriet? non ? valido.";
+ return false;
+ }
+ } else {
+ $errorString="Non esiste questa propriet? per gli allegati.";
+ return false;
+ }
+ }
+
+ public function finalize(&$errorString) {
+ if(!$this->finalized) {
+ $this->headerMessage="from: ".($this->from)."\n";
+ $this->headerMessage.="to: ".($this->to)."\n";
+ $this->headerMessage.="subject: ".($this->subject)."\n";
+ $this->headerMessage.="mime-version: 1.0\n";
+
+ if(($countAttachments=count($this->attachments))>0) {
+ $this->headerMessage.="content-type: multipart/mixed; boundary=\"".($this->boundaries["multipart/mixed"])."\"\n\n";
+ $this->headerMessage.=self::defaultHeaderMessage;
+ $this->headerMessage.="\n\n";
+
+ $this->bodyMessage="--".($this->boundaries["multipart/mixed"])."\n";
+
+ if(($countRelated=count($this->related))>0) {
+ $this->bodyMessage.="content-type: multipart/related; type=\"multipart/alternative\"; boundary=\"".($this->boundaries["multipart/related"])."\"\n\n";
+
+ $this->bodyMessage.="--".($this->boundaries["multipart/related"])."\n";
+
+ $this->bodyMessage.="content-type: multipart/alternative; boundary=\"".($this->boundaries["multipart/alternative"])."\"\n\n";
+ $this->createMultipartAlternativeMessage($this->boundaries["multipart/alternative"]);
+ $this->bodyMessage.="--".($this->boundaries["multipart/alternative"])."--\n\n";
+
+ // aggiungere i related e chiudere
+
+ $relatedCounter=0;
+ while(list($key,)=each($this->related)) {
+ $relatedCounter++;
+
+ $this->bodyMessage.="--".$this->boundaries["multipart/related"]."\n";
+ $this->createMultipartRelatedMessage($key);
+ if($relatedCounter!=$countRelated) $this->bodyMessage.="--".($this->boundaries["multipart/related"])."\n";
+ else $this->bodyMessage.="--".($this->boundaries["multipart/related"])."--\n\n";
+ }
+ } else {
+ $this->bodyMessage.="content-type: multipart/alternative; boundary=\"".($this->boundaries["multipart/alternative"])."\"\n\n";
+ $this->createMultipartAlternativeMessage();
+ $this->bodyMessage.="--".($this->boundaries["multipart/alternative"])."--\n\n";
+ }
+
+ $attachmentsCounter=0;
+ while(list($key,)=each($this->attachments)) {
+ $attachmentsCounter++;
+ $this->bodyMessage.="--".($this->boundaries["multipart/mixed"])."\n";
+ $this->createMultipartMixedMessage($key);
+ if($attachmentsCounter!=$countAttachments) $this->bodyMessage.="--".($this->boundaries["multipart/mixed"])."\n";
+ else $this->bodyMessage.="--".($this->boundaries["multipart/mixed"])."--\n\n";
+ }
+ } else {
+ if(($countRelated=count($this->related))>0) {
+ $this->headerMessage.="content-type: multipart/related; type=\"multipart/alternative\"; boundary=\"".($this->boundaries["multipart/related"])."\"\n\n";
+ $this->headerMessage.=self::defaultHeaderMessage;
+ $this->headerMessage.="\n\n";
+
+ $this->bodyMessage="--".($this->boundaries["multipart/related"])."\n";
+ $this->bodyMessage.="content-type: multipart/alternative; boundary=\"".($this->boundaries["multipart/alternative"])."\"\n\n";
+ $this->createMultipartAlternativeMessage();
+ $this->bodyMessage.="--".($this->boundaries["multipart/alternative"])."--\n\n";
+
+ $relatedCounter=0;
+ while(list($key,)=each($this->related)) {
+ $relatedCounter++;
+ $this->bodyMessage.="--".$this->boundaries["multipart/related"]."\n";
+ $this->createMultipartRelatedMessage($key);
+ if($relatedCounter!=$countRelated) $this->bodyMessage.="--".($this->boundaries["multipart/related"])."\n";
+ else $this->bodyMessage.="--".($this->boundaries["multipart/related"])."--\n\n";
+ }
+ } else {
+ $this->headerMessage.="content-type: multipart/alternative; boundary=\"".($this->boundaries["multipart/alternative"])."\"\n\n";
+ $this->headerMessage.=self::defaultHeaderMessage;
+ $this->headerMessage.="\n\n";
+
+ $this->createMultipartAlternativeMessage();
+ $this->bodyMessage.="--".($this->boundaries["multipart/alternative"])."--";
+
+ }
+ }
+ $this->finalized=true;
+ return true;
+ } else {
+ $errorString="Al momento non ? possibile finalizzare.";
+ return false;
+ }
+ }
+
+ private function createMultipartAlternativeMessage() {
+ $multipartAlternativeBoundary=$this->boundaries["multipart/alternative"];
+ $this->bodyMessage.="--$multipartAlternativeBoundary\n";
+ $this->bodyMessage.="content-type: text/plain; charset=\"".($this->text["properties"]["charset"])."\"\n";
+ $this->bodyMessage.="content-transfer-encoding: ".($this->text["properties"]["content-transfer-encoding"])."\n\n";
+ $this->bodyMessage.=$this->text["message"];
+ $this->bodyMessage.="\n\n";
+ $this->bodyMessage.="--$multipartAlternativeBoundary\n";
+ $this->bodyMessage.="content-type: text/html; charset=\"".($this->html["properties"]["charset"])."\"\n";
+ $this->bodyMessage.="content-transfer-encoding: ".($this->html["properties"]["content-transfer-encoding"])."\n\n";
+ $this->bodyMessage.=$this->html["message"];
+ $this->bodyMessage.="\n\n";
+ }
+
+ private function createMultipartRelatedMessage($key) {
+ $obj=$this->related[$key];
+ $this->bodyMessage.="content-type: ".($obj["properties"]["content-type"])."; name=\"".($obj["fileName"])."\"\n";
+ $this->bodyMessage.="content-transfer-encoding: ".($obj["properties"]["content-transfer-encoding"])."\n";
+ $this->bodyMessage.="content-id: <".($obj["properties"]["content-id"]).">\n\n";
+ $this->bodyMessage.=$obj["source"];
+ $this->bodyMessage.="\n\n";
+ }
+
+ private function createMultipartMixedMessage($key) {
+ $obj=$this->attachments[$key];
+ $this->bodyMessage.="content-type: ".($obj["properties"]["content-type"])."; name=\"".($obj["fileName"])."\"\n";
+ $this->bodyMessage.="content-transfer-encoding: ".($obj["properties"]["content-transfer-encoding"])."\n";
+ $this->bodyMessage.="content-disposition: ".($obj["properties"]["content-disposition"])."; filename=\"".($obj["fileName"])."\"\n\n";
+ $this->bodyMessage.=$obj["source"];
+ $this->bodyMessage.="\n\n";
+ }
+
+ public function getSource(&$errorString) {
+ if($this->finalized) {
+ return ($this->headerMessage).($this->bodyMessage);
+ } else {
+ $errorString="Ancora non ? avvenuta la finalizzazione.";
+ return false;
+ }
+ }
+
+ public function sendMail(&$errorString) {
+ if($this->finalized) {
+ mail($this->to, $this->subject, $this->bodyMessage, $this->headerMessage);
+ $this->finalized=false;
+ return true;
+ } else {
+ $errorString="Ancora non ? avvenuta la finalizzazione.";
+ return false;
+ }
+ }
+}
+
+?>