[Linpha-cvs] SF.net SVN: linpha: [4537] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <fan...@us...> - 2006-04-14 23:18:43
|
Revision: 4537 Author: fangehrn Date: 2006-04-14 16:18:08 -0700 (Fri, 14 Apr 2006) ViewCVS: http://svn.sourceforge.net/linpha/?rev=4537&view=rev Log Message: ----------- * finished implementing basket checkout features (download, print, mail) print and mail works quite smooth download needs still some improvements (chdir() to album dir to no get relative or absolute paths) Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/admin/settings_all.php trunk/linpha2/install/sql/sql.data.php trunk/linpha2/lib/classes/linpha.filesys.class.php trunk/linpha2/lib/classes/linpha.functions.php trunk/linpha2/lib/classes/linpha.image.class.php trunk/linpha2/lib/classes/linpha.imgview.class.php trunk/linpha2/lib/classes/linpha.import.class.php trunk/linpha2/lib/classes/linpha.sql.class.php trunk/linpha2/lib/modules/module.basket.php trunk/linpha2/templates/default/basket.html.php Added Paths: ----------- trunk/linpha2/docs/dev/external_libraries.txt trunk/linpha2/lib/classes/archiver.class.php trunk/linpha2/lib/classes/archiver.config.php trunk/linpha2/lib/classes/phpmailer.class.php trunk/linpha2/lib/classes/smtp.class.php trunk/linpha2/lib/include/basket_build_mail.php trunk/linpha2/lib/include/basket_build_print.php trunk/linpha2/lib/include/basket_build_zip.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2006-04-14 15:52:03 UTC (rev 4536) +++ trunk/linpha2/ChangeLog 2006-04-14 23:18:08 UTC (rev 4537) @@ -1,3 +1,9 @@ +2006-04-15 flo + * finished implementing basket checkout features (download, print, mail) + print and mail works quite smooth + download needs still some improvements + (chdir() to album dir to no get relative or absolute paths) + 2006-04-14 flo * startet implementing basket checkout features (download, print, mail) * added settings all feature in admin section Modified: trunk/linpha2/admin/settings_all.php =================================================================== --- trunk/linpha2/admin/settings_all.php 2006-04-14 15:52:03 UTC (rev 4536) +++ trunk/linpha2/admin/settings_all.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -17,6 +17,9 @@ 'sys_path_cache_dir', 'sys_path_tmp_dir', + 'sys_basket_mail_max_size', + 'sys_basket_download_limit', + 'sys_style_sortorder', 'sys_style_template', 'sys_style_home_showbrowsebydate', Added: trunk/linpha2/docs/dev/external_libraries.txt =================================================================== --- trunk/linpha2/docs/dev/external_libraries.txt (rev 0) +++ trunk/linpha2/docs/dev/external_libraries.txt 2006-04-14 23:18:08 UTC (rev 4537) @@ -0,0 +1,10 @@ + + +phpmail.class.php + +line 560 + +from + include_once($this->PluginDir . "class.smtp.php"); +to + include_once(LINPHA_DIR . "/lib/classes/smtp.class.php"); \ No newline at end of file Modified: trunk/linpha2/install/sql/sql.data.php =================================================================== --- trunk/linpha2/install/sql/sql.data.php 2006-04-14 15:52:03 UTC (rev 4536) +++ trunk/linpha2/install/sql/sql.data.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -41,6 +41,9 @@ 'sys_path_cache_dir' => $_SESSION['cache_dir'], 'sys_path_tmp_dir' => $_SESSION['tmp_dir'], + 'sys_basket_mail_max_size' => (1024*1024*2), + 'sys_basket_download_limit' => '0', + 'sys_style_sortorder' => 'nameasc', 'sys_style_template' => 'default', 'sys_style_home_showbrowsebydate' => '1', Added: trunk/linpha2/lib/classes/archiver.class.php =================================================================== --- trunk/linpha2/lib/classes/archiver.class.php (rev 0) +++ trunk/linpha2/lib/classes/archiver.class.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -0,0 +1,330 @@ +<?php +/* +* Copyright (c) 2004 Heiko Rutenbeck <bz...@tu...> +* +* 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 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +if(!defined('LINPHA_DIR')) { exit(1); } + +/** +* Class to create album archives for download +* +* This class uses the system tools tar/bzip/zip to create archives +* for download. Using PHP sucks due limitations (runtime and memory limits)... +* +* @author bzrudi +*/ + +class Archive +{ + +var $files; +var $tmpname; +var $sleeptime; +var $ziptype; +var $apps; +var $md5sums; + +/** +* constructor +*/ +function Archive($ziptype,$speed=0) +{ + $this->ziptype = $ziptype; + $this->setDownloadSpeedLimit($speed); + + $this->apps = new Archive_Applications(); + $this->apps->searchApp($ziptype); + + /** + * set tmpname + */ + $this->tmpname = LinFilesys::linTempnam( + 'linpha_download', // prefix + '.'.$this->apps->apps[$this->ziptype]['file_ext'] // suffix + ); +} + +/** +* Method to calculate max download speed rate +* @return integer sleeptime in usec +*/ +function setDownloadSpeedLimit($sleep) +{ + switch($sleep) + { + case "0": $this->sleeptime = "0"; break; + case "4": $this->sleeptime = "900000"; break; + case "8": $this->sleeptime = "450000"; break; + case "12": $this->sleeptime = "335000"; break; + case "16": $this->sleeptime = "225000"; break; + case "32": $this->sleeptime = "115000"; break; + case "64": $this->sleeptime = "56500"; break; + default: $this->sleeptime = "0"; break; + } +} + +/** +* Method to create filelist/path for files to download +* @return string fullpath,path,src_path +*/ +function getImageList($img_ids) +{ + $this->files = ''; + + foreach($img_ids AS $image_id) + { + $full_filename = LinSql::getFullImagePath( $image_id ); + + $this->files .= linEscapeString($full_filename)." "; + + /** + * store md5sum for later use (statistics) + * @todo + */ + //$this->md5sums[] = $data['md5sum']; + } +} + + +/** +* Method to finaly create the archive on HD +*/ +function makeArchive() +{ + $command = $this->apps->GetCommand($this->ziptype); + + /** + * get executable path + */ + $this->apps->searchApp($this->ziptype); + $path = $this->apps->found_apps[$this->ziptype]; + $exec = $this->apps->apps[$this->ziptype]['executable']; + $executable = $path.$exec; + $command = str_replace('{executable}',$executable,$command); + + $command = str_replace('{files}',$this->files,$command); // $this->files is already escaped + $command = str_replace('{archive_name}',linEscapeString($this->tmpname),$command); + + //error_log($command); + + if(!chdir(LINPHA_DIR)) { + echo 'cannot chdir(LINPHA_DIR)!<br />'; + return false; + } + + /** + * delete tempfile first because winrar cannot write into this empty file (created with touch())! + * -> it could be possible that linpha_tempnam() generates now a duplicate tmpname if another user + * is currently using the download mode too + * very unlikely because the session_id is included in tmpname and there is not much time between unlink() and exec() + */ + unlink($this->tmpname); + + exec($command,$array_output=Array(),$return_value=0); + + if(!file_exists($this->tmpname)) { + echo 'Created archive doesnt exists<br />'; + $fail = true; + } + + if($return_value != 0) { + echo 'archive program returned an error!<br />'; + echo 'Return value: '.$return_value.'<br />'; + $fail = true; + } + + if(isset($fail)) + { + echo '<pre>'; + echo $command.'<br />'; + print_r($array_output); + echo '</pre><br />'; + + return false; + } + else + { + return true; + } +} + +/** +* Method to send created archive to client. +* Makes use of additional header defines to let client know about +* content type and length. +*/ +function startDownload() +{ + set_magic_quotes_runtime(0); + /** + * disable zlib compression to avoid broken archives + */ + @ini_set ('zlib.output_compression', 'Off'); + + $mime = $this->apps->apps[$this->ziptype]['mime']; + $ext = $this->apps->apps[$this->ziptype]['file_ext']; + + header("Pragma: public"); + header("Expires: 0"); + header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); + header("Content-Type: ".$mime); + + $user_agent = @strtolower($_SERVER["HTTP_USER_AGENT"]); + + if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win")))) { + header( "Content-Disposition: filename=Linpha_download.".$ext.";" ); + }else{ + header( "Content-Disposition: attachment; filename=Linpha_download.".$ext.";" ); + } + + header("Content-Transfer-Encoding: binary"); + header("Content-Length: ".filesize($this->tmpname)); + + $fp=fopen($this->tmpname, "rb"); + + if($this->sleeptime == 0){ + while(!feof($fp)) { + $sendbuffer=fread($fp, 4096); + echo $sendbuffer; + } + } else { + while(!feof($fp)) { + $sendbuffer=fread($fp, 4096); + usleep($this->sleeptime); + echo $sendbuffer; + } + } + + fclose($fp); + unlink($this->tmpname); +} + +} // end class + +class Archive_Applications +{ + //var $path_delimiter; + var $array_path; + var $apps; + var $found_apps; + + // Constructor + function Archive_Applications() + { + /** + * not use include_once() ! + */ + include(LINPHA_DIR.'/lib/classes/archiver.config.php'); + + $this->array_path = get_PATH('PATH'); + } + + function getCommand($ziptype) + { + return $this->apps[$ziptype]['command']; + } + + /** + * ignoreFileext doesn't mean that these files are exluded from the archive + * but these are excluded from compression, so we get speed improvements + * + * it doesn't make sense to compress already compressed image files + * but it makes sense to compress uncompressed image files like BMP or TIFF + * + * what about movies..?! + */ + function ignoreFileext($prefix,$delimiter) + { + $exts = Array('jpg','JPG','jpeg','JPEG','gif','GIF','png','PNG','mov','MOV','avi','AVI','mpg','MPG','mpeg','MPEG'); + + $str = ''; + foreach($exts AS $value) { + $str .= $prefix.$value.$delimiter; + } + + /** + * remove last delimiter + */ + $str = substr($str,0,strlen($str)-strlen($delimiter)); + + return $str; + } + + function searchApps() + { + foreach($this->apps AS $app=>$value) + { + $this->searchApp($app); + } + } + + function searchApp($app) + { + if(isset($this->apps[$app]['look_for'][0]) && $this->apps[$app]['look_for'][0] == 'no') + { + $this->found_apps[$app] = ''; + return true; + } + + /** + * search file in other (given) locations + * + * get_PATH remove directories not allowed by safemode or open_basedir + */ + $array_lookfor = get_PATH($this->apps[$app]['look_for']); + foreach($array_lookfor AS $value) + { + if(file_exists($value.'/'.$this->apps[$app]['executable'])) + { + /** + * make sure the executable path contains no spaces because this won't work + * this behaviour has only be seen under windows, maybe we have to separate linux and + * windows. but then, we have to escape the executable. + * + * calls like + * $cmd = '"c:/program files/winrar/rar.exe" a "c:/temp/test.rar" "c:/directory with spaces/rar.txt"'; + * exec($cmd); + * don't work! + * + * if somebody finds a solution, please let me know :) + */ + if( strpos($value,' ')!==false ) + { + } + else + { + $this->found_apps[$app] = $value.'/'; + return true; + } + } + } + + /** + * search file in PATH + */ + foreach($this->array_path AS $value) + { + if(file_exists($value.'/'.$this->apps[$app]['executable'])) + { + $this->found_apps[$app] = $value.'/'; + return true; + } + } + + return false; + } +} \ No newline at end of file Added: trunk/linpha2/lib/classes/archiver.config.php =================================================================== --- trunk/linpha2/lib/classes/archiver.config.php (rev 0) +++ trunk/linpha2/lib/classes/archiver.config.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -0,0 +1,199 @@ +<?php +/* +* Copyright (c) 2004 Heiko Rutenbeck <bz...@tu...> +* +* 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 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +if(!defined('LINPHA_DIR')) { exit(1); } + +/** +* you can add own paths or new apps +* +* use only forward slashes ('/') for paths, even under windows +* +* if 'look_for' is an array with the first entry 'no', this app isn't searched +* use this only if you are sure that this app is in the path, like 'tar' which is normally always +* in one of the path variable +* +* {executable}, {archive_name} and {files} will be replaced with the correct parameters +* hint: {executable} will be replaced with the fullpath executable, not only the executable given +* in the array $appps[]['executable'] +* +* the extract commands are used for the integrated filemanager, so don't forget +* +* you cannot use spaces in the executable path!! if you want to use a program which is installed in c:/program files/... +* you have to use c:/progra~1/... +* alternatively you can install it in another place or add the executable path to the PATH variable +* +* and if it works, please mail me a copy of your new entries +* at linpha AT angehrn DOT com +* OR bzrudi AT tuxpower DOT de +*/ + +switch(getOS()) +{ + case 'unix': + // tar + $this->apps['tar'] = Array('look_for' => Array('no'), + 'executable' => 'tar', + 'command' => 'tar -cf {archive_name} {files}', + 'executable_extract' => 'tar', + 'command_extract' => 'tar -xf {archive_name}', + 'file_ext' => 'tar', + 'mime' => 'application/x-tar'); + + // gzip + $this->apps['gzip'] = Array('look_for' => Array('/bin','/usr/bin','/usr/local/bin'), + 'executable' => 'gzip', + 'command' => 'tar -cf - {files} | {executable} -1 > {archive_name}', + 'executable_extract' => 'gzip', + 'command_extract' => '{executable} -d < {archive_name} | tar -xvf -', + 'file_ext' => 'tar.gz', + 'mime' => 'application/x-compressed-tar'); + + // bzip2 + $this->apps['bzip2'] = Array('look_for' => Array('/usr/bin','/bin','/usr/local/bin'), + 'executable' => 'bzip2', + 'command' => 'tar -cf - {files} | {executable} -1 > {archive_name}', + 'executable_extract' => 'bzip2', + 'command_extract' => '{executable} -d < {archive_name} | tar -xvf -', + 'file_ext' => 'tar.bz2', + 'mime' => 'application/x-bzip-compressed-tar'); + + // zip + $this->apps['unixzip'] = Array('look_for' => Array('/usr/bin','/bin','/usr/local/bin'), + 'executable' => 'zip', + 'command' => '{executable} -1jvn '.$this->ignoreFileext('.',':').' {archive_name} {files}', + 'executable_extract' => 'unzip', + 'command_extract' => '{executable} -o -L {archive_name}', + 'file_ext' => 'zip', + 'mime' => 'application/zip'); + + // rar + $this->apps['winrar'] = Array('look_for' => Array('/usr/bin','/bin','/usr/local/bin'), + 'executable' => 'rar', + 'command' => '{executable} a -ms['.$this->ignoreFileext('',',').'] {archive_name} {files}', + 'executable_extract' => 'rar', + 'command_extract' => '{executable} x -y {archive_name}', + 'file_ext' => 'rar', + 'mime' => 'application/x-rar-compressed'); + /** + * @todo arj, ?? + */ + + //$this->path_delimiter = ':'; + break; + case 'win': + // WinZip Command Line Support Add-On + // tested with WinZip version 9.0 + // not working with the evalution mode!! + // not working if cmd string is longer than 2048 chars! + // this problem does not exists with winrar and 7-Zip + $this->apps['winzip'] = Array('look_for' => Array('c:/progra~1/winzip','c:/winzip'), + 'executable' => 'wzzip.exe', + 'command' => '{executable} -ybc {archive_name} {files}', + 'executable_extract' => 'wzunzip.exe', + 'command_extract' => '{executable} -ybc {archive_name}', // x: extract, -y answer always 'yes' (for overwriting) + 'file_ext' => 'zip', + 'mime' => 'application/zip'); + + + // winrar + // tested with winrar version 3.2 + $this->apps['winrar'] = Array('look_for' => Array('c:/progra~1/winrar','c:/winrar'), + 'executable' => 'rar.exe', + 'command' => '{executable} a -ms['.$this->ignoreFileext('',',').'] {archive_name} {files}', + 'executable_extract' => 'rar.exe', + 'command_extract' => '{executable} x -y {archive_name}', // x: extract, -y answer always 'yes' (for overwriting) + 'file_ext' => 'rar', + 'mime' => 'application/x-rar'); + + // PowerArchiver Command Line (PACL) + // tested with PowerArchiver Command Line Version 3.51 + $this->apps['PAcl_zip'] = Array('look_for' => Array('c:/Pacl','c:/progra~1/Pacl'), + 'executable' => 'Pacomp.exe', + 'command' => '{executable} -a {archive_name} {files}', + 'executable_extract' => 'Paext.exe', + 'command_extract' => '{executable} -d {archive_name}', + 'file_ext' => 'zip', + 'mime' => 'application/zip'); + + // pkzip + /* doesn't supported!! pkzip only allows a few images as parameters, use pkzip32 or pkzipc instead! + $this->apps['pkzip'] = Array('look_for' => Array(), + 'executable' => 'pkzip.exe', + 'command' => '{executable} -a {archive_name} {files}', + 'executable_extract' => '', + 'command_extract' => '', + 'file_ext' => 'zip', + 'mime' => 'application/zip'); + */ + + // pkzip32 + /* not yet tested, does pkzip32 still exists..?! + $this->apps['pkzip32'] = Array('look_for' => Array(), + 'executable' => 'pkzip32.exe', + 'command' => '', + 'executable_extract' => '', + 'command_extract' => '{executable} -nofix -ext -dir -overwrite -nozipextension {archive_name} 2>&1'; + 'file_ext' => 'zip', + 'mime' => 'application/zip'); + */ + + // pkzipc PKZIP Command Line + // tested with pkzip cli version 8.0 + $this->apps['pkzipc'] = Array('look_for' => Array('c:/progra~1/pkware/pkzipc'), + 'executable' => 'pkzipc.exe', + 'command' => '{executable} -add {archive_name} {files}', + 'executable_extract' => 'pkzipc.exe', + 'command_extract' => '{executable} -extract -overwrite=all {archive_name}', + 'file_ext' => 'zip', + 'mime' => 'application/zip'); + + // Commandline Ace (ACE f?r DOS) + // tested with Commandline Ace version 2.04 + // no default installation directory + $this->apps['ace'] = Array('look_for' => Array('c:/progra~1/WinAce','c:/ace'), + 'executable' => 'Ace32.exe', + 'command' => '{executable} a {archive_name} {files}', + 'executable_extract' => 'Ace32.exe', + 'command_extract' => '{executable} x -o -y {archive_name}', // -o: overwrite, -y answer always 'yes' + 'file_ext' => 'ace', + 'mime' => 'application/x-ace'); + + // 7-Zip http://www.7-zip.org/ + // tested with Version 3.13 + // thanks to adrian + $this->apps['7Zip'] = Array('look_for' => Array('c:/progra~1/7-Zip','c:/progra~1/xampp/7Zip'), + 'executable' => '7z.exe', + 'command' => '{executable} a -tzip {archive_name} {files}', + 'executable_extract' => '7z.exe', + 'command_extract' => '{executable} e {archive_name}', + 'file_ext' => 'zip', + 'mime' => 'application/Zip'); + + /** + * @todo !Freebyte Zip http://www.freebyte.com/fbzip/#cmd + * @todo Ultimate Zip http://www.ultimatezip.com/download.htm +@todo Arj http://arj.sourceforge.net/ + */ + + //$this->path_delimiter = ';'; + break; +} + + +?> \ No newline at end of file Modified: trunk/linpha2/lib/classes/linpha.filesys.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.filesys.class.php 2006-04-14 15:52:03 UTC (rev 4536) +++ trunk/linpha2/lib/classes/linpha.filesys.class.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -28,6 +28,44 @@ { /** +* returns a unique filename, but different to tempnam() the file doesn't exists +* +* @author flo +* @param string $prefix prefix for the tmp_file +* @param string $suffix suffix for the tmp_file, formerly the file extension +* @return string unique temporary filename +* @package filesys +* +* http://ch.php.net/manual/de/function.uniqid.php +*/ +function linTempnam($prefix,$suffix) +{ + $tmp_dir = LinSql::getPath('tmp'); + if(!is_writable($tmp_dir)) { + error_log("linpha_tempnam: tmp_dir ($tmp_dir) isn't writable! Using /tmp instead"); + $tmp_dir = '/tmp'; + } + + for($i=0; file_exists($tmp_dir.'/'.$prefix.'_'.session_id().'_'.$i.$suffix); $i++) { } + $tmp_file = $tmp_dir.'/'.$prefix.'_'.session_id().'_'.$i.$suffix; + touch($tmp_file); + + return $tmp_file; +} + +/** + * create a unique tmp folder + */ +function createTmpFolder($prefix) +{ + $tmp_dir = $GLOBALS['linpha']->sql->config->value['sys_path_tmp_dir']; + for($i=0; file_exists(LinFilesys::getFullPath($tmp_dir).'/'.$prefix.'_'.session_id().'_'.$i); $i++) { } + $tmp_folder = LinFilesys::getFullPath($tmp_dir).'/'.$prefix.'_'.session_id().'_'.$i; + mkdir($tmp_folder,0700); + return $tmp_folder; +} + +/** * close session before exec() * if exec() is called twice (like on the print preview), apache will hang * on windows Modified: trunk/linpha2/lib/classes/linpha.functions.php =================================================================== --- trunk/linpha2/lib/classes/linpha.functions.php 2006-04-14 15:52:03 UTC (rev 4536) +++ trunk/linpha2/lib/classes/linpha.functions.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -22,8 +22,132 @@ * Just a couple of useful functions * @package Functions */ - + + /** +* get content of the systems PATH variable and remove dirs not in open_basedir and safe_mode_exec_dir (only if activated) +*/ +function get_PATH($array_path) +{ + /** + * use the path variable instead of own array + */ + if($array_path == 'PATH') + { + unset($array_path); + if(!empty($_SERVER['PATH'])) + { + $path = $_SERVER['PATH']; + } + elseif(!empty($_SERVER['Path'])) + { + $path = $_SERVER['Path']; + } + else + { + $path = ''; + } + $array_path = explode(PATH_SEPARATOR,$path); + } + // if we have open_basedir restrictions, take only the paths which are allowed from open_basedir to prevent errors + $open_basedir = ini_get('open_basedir'); + if(!empty($open_basedir)) { + $arr_open_basedir = explode(PATH_SEPARATOR,$open_basedir); + + $array_path = array_intersect($array_path, $arr_open_basedir); + } + + // same with safemode + if(ini_get('safe_mode')) + { + $safe_mode_exec_dir = ini_get('safe_mode_exec_dir'); + if(!empty($safe_mode_exec_dir)) { + + $arr_safe_mode_exec_dir = explode(PATH_SEPARATOR,$safe_mode_exec_dir); + + $array_path = array_intersect($array_path, $arr_safe_mode_exec_dir); + } + } + + return $array_path; +} + +/** + * get the memory limit set in php.ini + * if php was compiled without memory_limit + */ +function getMemoryLimit() +{ + $memlimit=ini_get('memory_limit'); + if(empty($memlimit)) + { + $memlimit = get_cfg_var('memory_limit'); + } + + /** + * mem limit disabled (-1) or not compiled in + */ + if(empty($memlimit) OR $memlimit == -1) + { + return false; + } + else + { + $memlimit=str_replace("M", "", $memlimit); + return $memlimit; + } +} + +/** + * This function formats the filesize (byte) value to kB/MB/GB + */ +function niceFilesize($filesize, $precision) +{ + if ($filesize < 1000) { + $sizeunit = 'Bytes'; + $precision = 0; + } else { + $filesize /= 1024; + $sizeunit = 'KB'; + } + if ($filesize >= 1000) { + $filesize /= 1024; + $sizeunit = 'MB'; + } + if ($filesize >= 1000) { + $filesize /= 1024; + $sizeunit = 'GB'; + } + return number_format($filesize, $precision).' '.$sizeunit; +} + +/** + * cut a string to the given size + */ +function cutString($string,$len,$with_span_title) +{ + $append = '...'; + + if( strlen($string) > ($len+strlen($append)) ) + { + $str_cutted = substr_replace($string, $append, $len); + if($with_span_title) + { + return '<span title="'.$string.'">'.$str_cutted.'</span>'; + } + else + { + return $str_cutted; + } + } + else + { + return $string; + } + +} + +/** * Take care of translation * * This simple method takes care of all translation related stuff. Modified: trunk/linpha2/lib/classes/linpha.image.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.image.class.php 2006-04-14 15:52:03 UTC (rev 4536) +++ trunk/linpha2/lib/classes/linpha.image.class.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -28,13 +28,13 @@ class LinImage { public $error_msg; +public $output_file; private $photo_id, $cached_id; private $img_type; private $mode; private $image_tool; -private $output_file; private $src_file; private $org_width, $org_height, $img_width, $img_height; private $img_quality; @@ -258,9 +258,7 @@ */ if($this->img_type != 0 && $this->img_type != 9999999) { - $array_path = $GLOBALS['linpha']->sql->getFullFilenameFromId( $this->photo_id ); - $album_dir = $GLOBALS['linpha']->sql->getPath('album'); - $this->src_file = $album_dir .'/'. implode('/',$array_path); + $this->src_file = LinSql::getFullImagePath( $this->photo_id ); if(! file_exists($this->src_file)) { Modified: trunk/linpha2/lib/classes/linpha.imgview.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.imgview.class.php 2006-04-14 15:52:03 UTC (rev 4536) +++ trunk/linpha2/lib/classes/linpha.imgview.class.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -287,7 +287,7 @@ } $_SESSION['basket_ref_url'] = $GLOBALS['linpha']->template->URL_full; - $open_basket_link = LINPHA_DIR.'/?cat=basket&ref_id='.$this->id_current; + $open_basket_link = LINPHA_DIR.'/?cat=basket'; switch($this->mode) { @@ -495,8 +495,7 @@ $filename = $photo_value['name']; $md5sum = $photo_value['md5sum']; - $array_files = $GLOBALS['linpha']->sql->getFullFilenameFromId( $photo_value['id'] ); - $full_filename = LinSql::getPath('album').'/'.implode('/',$array_files); + $full_filename = LinSql::getFullImagePath( $photo_value['id'] ); $array_image_infos = MetaData::readInformations( $full_filename, $filename, $md5sum, $flag_nr=13 ); @@ -846,10 +845,9 @@ $data = $query->FetchRow(ADODB_FETCH_NUM); if(isset($data['0'])) { - $array = LinSql::getFullFilenameFromId( $data['0'] ); - $path = LinSql::getPath('album') .'/'. implode('/',$array); + $path = LinSql::getFullImagePath( $data[0] ); - if(file_exists(LinFilesys::getFullPath($path)) && LinSql::photoIsAllowed($data['0'])) + if(file_exists($path) && LinSql::photoIsAllowed($data['0'])) { $GLOBALS['linpha']->template->output['random_images'][] = Array('id'=>$data['0'],'path'=>$path); $i++; @@ -1023,8 +1021,7 @@ */ function viewImgStoreImageInformation() { - $array_files = $GLOBALS['linpha']->sql->getFullFilenameFromId( $this->id_current ); - $this->full_filename = LinSql::getPath('album').'/'.implode('/',$array_files); + $this->full_filename = LinSql::getFullImagePath( $this->id_current ); /** * set image informations Modified: trunk/linpha2/lib/classes/linpha.import.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.import.class.php 2006-04-14 15:52:03 UTC (rev 4536) +++ trunk/linpha2/lib/classes/linpha.import.class.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -45,8 +45,7 @@ } else { - $array = LinSql::getFullFilenameFromId( $parent_id ); - $dirname = LinSql::getPath('album') .'/'. implode('/',$array); + $dirname = LinSql::getFullImagePath( $parent_id ); } if( ! file_exists( $dirname ) ) Modified: trunk/linpha2/lib/classes/linpha.sql.class.php =================================================================== --- trunk/linpha2/lib/classes/linpha.sql.class.php 2006-04-14 15:52:03 UTC (rev 4536) +++ trunk/linpha2/lib/classes/linpha.sql.class.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -587,8 +587,15 @@ return $array_names; } +function getFullImagePath( $photo_id ) +{ + $array_path = $GLOBALS['linpha']->sql->getFullFilenameFromId( $photo_id ); + $album_dir = $GLOBALS['linpha']->sql->getPath('album'); + return $album_dir .'/'. implode('/',$array_path); +} + /** - * returns the correct path to the albums directory + * returns the correct path to the album, cache or tmp directory * pay attention to use this getPath and not access directly 'sys_path_album_dir' ! */ function getPath($what) Added: trunk/linpha2/lib/classes/phpmailer.class.php =================================================================== --- trunk/linpha2/lib/classes/phpmailer.class.php (rev 0) +++ trunk/linpha2/lib/classes/phpmailer.class.php 2006-04-14 23:18:08 UTC (rev 4537) @@ -0,0 +1,1499 @@ +<?php +//////////////////////////////////////////////////// +// PHPMailer - PHP email class +// +// Class for sending email using either +// sendmail, PHP mail(), or SMTP. Methods are +// based upon the standard AspEmail(tm) classes. +// +// Copyright (C) 2001 - 2003 Brent R. Matzelle +// +// License: LGPL, see LICENSE +//////////////////////////////////////////////////// + +/** + * PHPMailer - PHP email transport class + * @package PHPMailer + * @author Brent R. Matzelle + * @copyright 2001 - 2003 Brent R. Matzelle + */ +class PHPMailer +{ + ///////////////////////////////////////////////// + // PUBLIC VARIABLES + ///////////////////////////////////////////////// + + /** + * Email priority (1 = High, 3 = Normal, 5 = low). + * @var int + */ + var $Priority = 3; + + /** + * Sets the CharSet of the message. + * @var string + */ + var $CharSet = "iso-8859-1"; + + /** + * Sets the Content-type of the message. + * @var string + */ + var $ContentType = "text/plain"; + + /** + * Sets the Encoding of the message. Options for this are "8bit", + * "7bit", "binary", "base64", and "quoted-printable". + * @var string + */ + var $Encoding = "8bit"; + + /** + * Holds the most recent mailer error message. + * @var string + */ + var $ErrorInfo = ""; + + /** + * Sets the From email address for the message. + * @var string + */ + var $From = "root@localhost"; + + /** + * Sets the From name of the message. + * @var string + */ + var $FromName = "Root User"; + + /** + * Sets the Sender email (Return-Path) of the message. If not empty, + * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. + * @var string + */ + var $Sender = ""; + + /** + * Sets the Subject of the message. + * @var string + */ + var $Subject = ""; + + /** + * Sets the Body of the message. This can be either an HTML or text body. + * If HTML then run IsHTML(true). + * @var string + */ + var $Body = ""; + + /** + * Sets the text-only body of the message. This automatically sets the + * email to multipart/alternative. This body can be read by mail + * clients that do not have HTML email capability such as mutt. Clients + * that can read HTML will view the normal Body. + * @var string + */ + var $AltBody = ""; + + /** + * Sets word wrapping on the body of the message to a given number of + * characters. + * @var int + */ + var $WordWrap = 0; + + /** + * Method to send mail: ("mail", "sendmail", or "smtp"). + * @var string + */ + var $Mailer = "mail"; + + /** + * Sets the path of the sendmail program. + * @var string + */ + var $Sendmail = "/usr/sbin/sendmail"; + + /** + * Path to PHPMailer plugins. This is now only useful if the SMTP class + * is in a different directory than the PHP include path. + * @var string + */ + var $PluginDir = ""; + + /** + * Holds PHPMailer version. + * @var string + */ + var $Version = "1.73"; + + /** + * Sets the email address that a reading confirmation will be sent. + * @var string + */ + var $ConfirmReadingTo = ""; + + /** + * Sets the hostname to use in Message-Id and Received headers + * and as default HELO string. If empty, the value returned + * by SERVER_NAME is used or 'localhost.localdomain'. + * @var string + */ + var $Hostname = ""; + + ///////////////////////////////////////////////// + // SMTP VARIABLES + ///////////////////////////////////////////////// + + /** + * Sets the SMTP hosts. All hosts must be separated by a + * semicolon. You can also specify a different port + * for each host by using this format: [hostname:port] + * (e.g. "smtp1.example.com:25;smtp2.example.com"). + * Hosts will be tried in order. + * @var string + */ + var $Host = "localhost"; + + /** + * Sets the default SMTP server port. + * @var int + */ + var $Port = 25; + + /** + * Sets the SMTP HELO of the message (Default is $Hostname). + * @var string + */ + var $Helo = ""; + + /** + * Sets SMTP authentication. Utilizes the Username and Password variables. + * @var bool + */ + var $SMTPAuth = false; + + /** + * Sets SMTP username. + * @var string + */ + var $Username = ""; + + /** + * Sets SMTP password. + * @var string + */ + var $Password = ""; + + /** + * Sets the SMTP server timeout in seconds. This function will not + * work with the win32 version. + * @var int + */ + var $Timeout = 10; + + /** + * Sets SMTP class debugging on or off. + * @var bool + */ + var $SMTPDebug = false; + + /** + * Prevents the SMTP connection from being closed after each mail + * sending. If this is set to true then to close the connection + * requires an explicit call to SmtpClose(). + * @var bool + */ + var $SMTPKeepAlive = false; + + /**#@+ + * @access private + */ + var $smtp = NULL; + var $to = array(); + var $cc = array(); + var $bcc = array(); + var $ReplyTo = array(); + var $attachment = array(); + var $CustomHeader = array(); + var $message_type = ""; + var $boundary = array(); + var $language = array(); + var $error_count = 0; + var $LE = "\n"; + /**#@-*/ + + ///////////////////////////////////////////////// + // VARIABLE METHODS + ///////////////////////////////////////////////// + + /** + * Sets message type to HTML. + * @param bool $bool + * @return void + */ + function IsHTML($bool) { + if($bool == true) + $this->ContentType = "text/html"; + else + $this->ContentType = "text/plain"; + } + + /** + * Sets Mailer to send message using SMTP. + * @return void + */ + function IsSMTP() { + $this->Mailer = "smtp"; + } + + /** + * Sets Mailer to send message using PHP mail() function. + * @return void + */ + function IsMail() { + $this->Mailer = "mail"; + } + + /** + * Sets Mailer to send message using the $Sendmail program. + * @return void + */ + function IsSendmail() { + $this->Mailer = "sendmail"; + } + + /** + * Sets Mailer to send message using the qmail MTA. + * @return void + */ + function IsQmail() { + $this->Sendmail = "/var/qmail/bin/sendmail"; + $this->Mailer = "sendmail"; + } + + + ///////////////////////////////////////////////// + // RECIPIENT METHODS + ///////////////////////////////////////////////// + + /** + * Adds a "To" address. + * @param string $address + * @param string $name + * @return void + */ + function AddAddress($address, $name = "") { + $cur = count($this->to); + $this->to[$cur][0] = trim($address); + $this->to[$cur][1] = $name; + } + + /** + * Adds a "Cc" address. Note: this function works + * with the SMTP mailer on win32, not with the "mail" + * mailer. + * @param string $address + * @param string $name + * @return void + */ + function AddCC($address, $name = "") { + $cur = count($this->cc); + $this->cc[$cur][0] = trim($address); + $this->cc[$cur][1] = $name; + } + + /** + * Adds a "Bcc" address. Note: this function works + * with the SMTP mailer on win32, not with the "mail" + * mailer. + * @param string $address + * @param string $name + * @return void + */ + function AddBCC($address, $name = "") { + $cur = count($this->bcc); + $this->bcc[$cur][0] = trim($address); + $this->bcc[$cur][1] = $name; + } + + /** + * Adds a "Reply-to" address. + * @param string $address + * @param string $name + * @return void + */ + function AddReplyTo($address, $name = "") { + $cur = count($this->ReplyTo); + $this->ReplyTo[$cur][0] = trim($address); + $this->ReplyTo[$cur][1] = $name; + } + + + ///////////////////////////////////////////////// + // MAIL SENDING METHODS + ///////////////////////////////////////////////// + + /** + * Creates message and assigns Mailer. If the message is + * not sent successfully then it returns false. Use the ErrorInfo + * variable to view description of the error. + * @return bool + */ + function Send() { + $header = ""; + $body = ""; + $result = true; + + if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) + { + $this->SetError($this->Lang("provide_address")); + return false; + } + + // Set whether the message is multipart/alternative + if(!empty($this->AltBody)) + $this->ContentType = "multipart/alternative"; + + $this->error_count = 0; // reset errors + $this->SetMessageType(); + $header .= $this->CreateHeader(); + $body = $this->CreateBody(); + + if($body == "") { return false; } + + // Choose the mailer + switch($this->Mailer) + { + case "sendmail": + $result = $this->SendmailSend($header, $body); + break; + case "mail": + $result = $this->MailSend($header, $body); + break; + case "smtp": + $result = $this->SmtpSend($header, $body); + break; + default: + $this->SetError($this->Mailer . $this->Lang("mailer_not_supported")); + $result = false; + break; + } + + return $result; + } + + /** + * Sends mail using the $Sendmail program. + * @access private + * @return bool + */ + function SendmailSend($header, $body) { + if ($this->Sender != "") + $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender); + else + $sendmail = sprintf("%s -oi -t", $this->Sendmail); + + if(!@$mail = popen($sendmail, "w")) + { + $this->SetError($this->Lang("execute") . $this->Sendmail); + return false; + } + + fputs($mail, $header); + fputs($mail, $body); + + $result = pclose($mail) >> 8 & 0xFF; + if($result != 0) + { + $this->SetError($this->Lang("execute") . $this->Sendmail); + return false; + } + + return true; + } + + /** + * Sends mail using the PHP mail() function. + * @access private + * @return bool + */ + function MailSend($header, $body) { + $to = ""; + for($i = 0; $i < count($this->to); $i++) + { + if($i != 0) { $to .= ", "; } + $to .= $this->to[$i][0]; + } + + if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1) + { + $old_from = ini_get("sendmail_from"); + ini_set("sendmail_from", $this->Sender); + $params = sprintf("-oi -f %s", $this->Sender); + $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, + $header, $params); + } + else + $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header); + + if (isset($old_from)) + ini_set("sendmail_from", $old_from); + + if(!$rt) + { + $this->SetError($this->Lang("instantiate")); + return false; + } + + return true; + } + + /** + * Sends mail via SMTP using PhpSMTP (Author: + * Chris Ryan). Returns bool. Returns false if there is a + * bad MAIL FROM, RCPT, or DATA input. + * @access private + * @return bool + */ + function SmtpSend($header, $body) { + include_once(LINPHA_DIR . "/lib/classes/smtp.class.php"); + $error = ""; + $bad_rcpt = array(); + + if(!$this->SmtpConnect()) + return false; + + $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender; + if(!$this->smtp->Mail($smtp_from)) + { + $error = $this->Lang("from_failed") . $smtp_from; + $this->SetError($error); + $this->smtp->Reset(); + return false; + } + + // Attempt to send attach all recipients + for($i = 0; $i < count($this->to); $i++) + { + if(!$this->smtp->Recipient($this->to[$i][0])) + $bad_rcpt[] = $this->to[$i][0]; + } + for($i = 0; $i < count($this->cc); $i++) + { + if(!$this->smtp->Recipient($this->cc[$i][0])) + $bad_rcpt[] = $this->cc[$i][0]; + } + for($i = 0; $i < count($this->bcc); $i++) + { + if(!$this->smtp->Recipient($this->bcc[$i][0])) + $bad_rcpt[] = $this->bcc[$i][0]; + } + + if(count($bad_rcpt) > 0) // Create error message + { + for($i = 0; $i < count($bad_rcpt); $i++) + { + if($i != 0) { $error .= ", "; } + $error .= $bad_rcpt[$i]; + } + $error = $this->Lang("recipients_failed") . $error; + $this->SetError($error); + $this->smtp->Reset(); + return false; + } + + if(!$this->smtp->Data($header . $body)) + { + $this->SetError($this->Lang("data_not_accepted")); + $this->smtp->Reset(); + return false; + } + if($this->SMTPKeepAlive == true) + $this->smtp->Reset(); + else + $this->SmtpClose(); + + return true; + } + + /** + * Initiates a connection to an SMTP server. Returns false if the + * operation failed. + * @access private + * @return bool + */ + function SmtpConnect() { + if($this->smtp == NULL) { $this->smtp = new SMTP(); } + + $this->smtp->do_debug = $this->SMTPDebug; + $hosts = explode(";", $this->Host); + $index = 0; + $connection = ($this->smtp->Connected()); + + // Retry while there is no connection + while($index < count($hosts) && $connection == false) + { + if(strstr($hosts[$index], ":")) + list($host, $port) = explode(":", $hosts[$index]); + else + { + $host = $hosts[$index]; + $port = $this->Port; + } + + if($this->smtp->Connect($host, $port, $this->Timeout)) + { + if ($this->Helo != '') + $this->smtp->Hello($this->Helo); + else + $this->smtp->Hello($this->ServerHostname()); + + if($this->SMTPAuth) + { + if(!$this->smtp->Authenticate($this->Username, + $this->Password)) + { + $this->SetError($this->Lang("authenticate")); + $this->smtp->Reset(); + $connection = false; + } + } + $connection = true; + } + $index++; + } + if(!$connection) + $this->SetError($this->Lang("connect_host")); + + return $connection; + } + + /** + * Closes the active SMTP session if one exists. + * @return void + */ + function SmtpClose() { + if($this->smtp != NULL) + { + if($this->smtp->Connected()) + { + $this->smtp->Quit(); + $this->smtp->Close(); + } + } + } + + /** + * Sets the language for all class error messages. Returns false + * if it cannot load the language file. The default language type + * is English. + * @param string $lang_type Type of language (e.g. Portuguese: "br") + * @param string $lang_path Path to the language file directory + * @access public + * @return bool + */ + function SetLanguage($lang_type, $lang_path = "language/") { + if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) + include($lang_path.'phpmailer.lang-'.$lang_type.'.php'); + else if(file_exists($lang_path.'phpmailer.lang-en.php')) + include($lang_path.'phpmailer.lang-en.php'); + else + { + $this->SetError("Could not load language file"); + return false; + } + $this->language = $PHPMAILER_LANG; + + return true; + } + + ///////////////////////////////////////////////// + // MESSAGE CREATION METHODS + ///////////////////////////////////////////////// + + /** + * Creates recipient headers. + * @access private + * @return string + */ + function AddrAppend($type, $addr) { + $addr_str = $type . ": "; + $addr_str .= $this->AddrFormat($addr[0]); + if(count($addr) > 1) + { + for($i = 1; $i < count($addr); $i++) + $addr_str .= ", " . $this->AddrFormat($addr[$i]); + } + $addr_str .= $this->LE; + + return $addr_str; + } + + /** + * Formats an address correctly. + * @access private + * @return string + */ + function AddrFormat($addr) { + if(empty($addr[1])) + $formatted = $addr[0]; + else + { + $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" . + $addr[0] . ">"; + } + + return $formatted; + } + + /** + * Wraps message for use with mailers that do not + * automatically perform wrapping and for quoted-printable. + * Original written by philippe. + * @access private + * @return string + */ + function WrapText($message, $length, $qp_mode = false) { + $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; + + $message = $this->FixEOL($message); + if (substr($message, -1) == $this->LE) + $message = substr($message, 0, -1); + + $line = explode($this->LE, $message); + $message = ""; + for ($i=0 ;$i < count($line); $i++) + { + $line_part = explode(" ", $line[$i]); + $buf = ""; + for ($e = 0; $e<count($line_part); $e++) + { + $word = $line_part[$e]; + if ($qp_mode and (strlen($word) > $length)) + { + $space_left = $length - strlen($buf) - 1; + if ($e != 0) + { + if ($space_left > 20) + { + $len = $space_left; + if (substr($word, $len - 1, 1) == "=") + $len--; + elseif (substr($word, $len - 2, 1) == "=") + $len -= 2; + $part = substr($word, 0, $len); + $word = substr($word, $len); + $buf .= " " . $part; + $message .= $buf . sprintf("=%s", $this->LE); + } + else + { + $message .= $buf . $soft_break; + } + $buf = ""; + } + while (strlen($word) > 0) + { + $len = $length; + if (substr($word, $len - 1, 1) == "=") + $len--; + elseif (substr($word, $len - 2, 1) == "=") + $len -= 2; + $part = substr($word, 0, $len); + $word = substr($word, $len); + + if (strlen($word) > 0) + $message .= $part . sprintf("=%s", $this->LE); + else + $buf = $part; + } + } + else + { + $buf_o = $buf; + $buf .= ($e == 0) ? $word : (" " . $word); + + if (strlen($buf) > $length and $buf_o != "") + { + $message .= $buf_o . $soft_break; + $buf = $word; + } + } + } + $message .= $buf . $this->LE; + } + + return $message; + } + + /** + * Set the body wrapping. + * @access private + * @return void + */ + function SetWordWrap() { + if($this->WordWrap < 1) + return; + + switch($this->message_type) + { + case "alt": + // fall through + case "alt_attachments": + $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); + break; + default: + $this->Body = $this->WrapText($this->Body, $this->WordWrap); + break; + } + } + + /** + * Assembles message header. + * @access private + * @return string + */ + function CreateHeader() { + $result = ""; + + // Set the boundaries + $uniq_id = md5(uniqid(time())); + $this->boundary[1] = "b1_" . $uniq_id; + $this->boundary[2] = "b2_" . $uniq_id; + + $result .= $this->HeaderLine("Date", $this->RFCDate()); + if($this->Sender == "") + $result .= $this->HeaderLine("Return-Path", trim($this->From)); + else + $result .= $this->HeaderLine("Return-Path", trim($this->Sender)); + + // To be created automatically by mail() + if($this->Mailer != "mail") + { + if(count($this->to) > 0) + $result .= $this->AddrAppend("To", $this->to); + else if (count($this->cc) == 0) + $result .= $this->HeaderLine("To", "undisclosed-recipients:;"); + if(count($this->cc) > 0) + $result .= $this->AddrAppend("Cc", $this->cc); + } + + $from = array(); + $from[0][0] = trim($this->From); + $from[0][1] = $this->FromName; + $result .= $this->AddrAppend("From", $from); + + // sendmail and mail() extract Bcc from the header before sending + if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0)) + $result .= $this->AddrAppend("Bcc", $this->bcc); + + if(count($this->ReplyTo) > 0) + $result .= $this->AddrAppend("Reply-to", $this->ReplyTo); + + // mail() sets the subject itself + if($this->Mailer != "mail") + $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject))); + + $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); + $result .= $this->HeaderLine("X-Priority", $this->Priority); + $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]"); + + if($this->ConfirmReadingTo != "") + { + $result .= $this->HeaderLine("Disposition-Notification-To", + "<" . trim($this->ConfirmReadingTo) . ">"); + } + + // Add custom headers + for($index = 0; $index < count($this->CustomHeader); $index++) + { + $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), + $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); + } + $result .= $this->HeaderLine("MIME-Version", "1.0"); + + switch($this->message_type) + { + case "plain": + $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding); + $result .= sprintf("Content-Type: %s; charset=\"%s\"", + $this->ContentType, $this->CharSet); + break; + case "attachments": + // fall through + case "alt_attachments": + if($this->InlineImageExists()) + { + $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", + "multipart/related", $this->LE, $this->LE, + $this->boundary[1], $this->LE); + } + else + { + $result .= $this->HeaderLine("Content-Type", "multipart/mixed;"); + $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); + } + break; + case "alt": + $result .= $this->HeaderLine("Content-Type", "multipart/alternative;"); + $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); + break; + } + + if($this->Mailer != "mail") + $result .= $this->LE.$this->LE; + + return $result; + } + + /** + * Assembles the message body. Returns an empty string on failure. + * @access private + * @return string + */ + function CreateBody() { + $result = ""; + + $this->SetWordWrap(); + + switch($this->message_type) + { + case "alt": + $result .= $this->GetBoundary($this->boundary[1], "", + "text/plain", ""); + $result .= $this->EncodeString($this->AltBody, $this->Encoding); + $result .= $this->LE.$this->LE; + $result .= $this->GetBoundary($this->boundary[1], "", + "text/html", ""); + + $result .= $this->EncodeString($this->Body, $this->Encoding); + $result .= $this->LE.$this->LE; + + $result .= $this->EndBoundary($this->boundary[1]); + break; + case "plain": + $result .= $this->EncodeString($this->Body, $this->Encoding); + break; + case "attachments": + $result .= $this->GetBoundary($this->boundary[1], "", "", ""); + $result .= $this->EncodeString($this->Body, $this->Encoding); + $result .= $this->LE; + + $result .= $this->AttachAll(); + break; + case "alt_attachments": + $result .= sprintf("--%s%s", $this->boundary[1], $this->LE); + $result .= sprintf("Content-Type: %s;%s" . + "\tboundary=\"%s\"%s", + "multipart/alternative", $this->LE, + $this->boundary[2], $this->LE.$this->LE); + + // Create text body + $result .= $this->GetBoundary($this->boundary[2], "", + "text/plain", "") . $this->LE; + + $result .= $this->EncodeString($this->AltBody, $this->Encoding); + $result .= $this->LE.$this->LE; + + // Create the HTML body + $result .= $this->GetBoundary($this->boundary[2], "", + "text/html", "") . $this->LE; + + $result .= $this->EncodeString($this->Body, $this->Encoding); + $result .= $this->LE.$this->LE; + + $result .= $this->EndBoundary($this->boundary[2]); + + $result .= $this->AttachAll(); + break; + } + if($this->IsError()) + $result = ""; + + return $result; + } + + /** + * Returns the start of a message boundary. + * @access private + */ + function GetBoundary($boundary, $charSet, $contentType, $encoding) { + $result = ""; + if($charSet == "") { $charSet = $this->CharSet; } + if($contentType == "") { $contentType = $this->ContentType; } + if($encoding == "") { $encoding = $this->Encoding; } + + $result .= $this->TextLine("--" . $boundary); + $result .= sprintf("Content-Type: %s; charset = \"%s\"", + $contentType, $charSet); + $result .= $this->LE; + $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding); + $result .= $this->LE; + + return $result; + } + + /** + * Returns the end of a message boundary. + * @access private + */ + function EndBoundary($boundary) { + return $this->LE . "--" . $boundary . "--" . $this->LE; + } + + /** + * Sets the message type. + * @access private + * @return void + */ + function SetMessageType() { + if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) + $this->message_type = "plain"; + else + { + if(count($this->attachment) > 0) + $this->message_type = "attachments"; + if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) + $this->message_type = "alt"; + if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) + $this->message_type = "alt_attachments"; + } + } + + /** + * Returns a formatted header line. + * @access private + * @return string + */ + function HeaderLine($name, $value) { + return $name . ": " . $value . $this->LE; + } + + /** + * Returns a formatted mail line. + * @access private + * @return string + */ + function TextLine($value) { + return $value . $this->LE; + } + + ///////////////////////////////////////////////// + // ATTACHMENT METHODS + ///////////////////////////////////////////////// + + /** + * Adds an attachment from a path on the filesystem. + * Returns false... [truncated message content] |