| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: utility.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla.Framework 5 * @subpackage Utilities 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant to the 9 * GNU General Public License, and as distributed it includes or is derivative 10 * of works licensed under the GNU General Public License or other free or open 11 * source software licenses. See COPYRIGHT.php for copyright notices and 12 * details. 13 */ 14 15 // Check to ensure this file is within the rest of the framework 16 defined('JPATH_BASE') or die(); 17 18 /** 19 * JUtility is a utility functions class 20 * 21 * @static 22 * @package Joomla.Framework 23 * @subpackage Utilities 24 * @since 1.5 25 */ 26 class JUtility 27 { 28 /** 29 * Mail function (uses phpMailer) 30 * 31 * @param string $from From e-mail address 32 * @param string $fromname From name 33 * @param mixed $recipient Recipient e-mail address(es) 34 * @param string $subject E-mail subject 35 * @param string $body Message body 36 * @param boolean $mode false = plain text, true = HTML 37 * @param mixed $cc CC e-mail address(es) 38 * @param mixed $bcc BCC e-mail address(es) 39 * @param mixed $attachment Attachment file name(s) 40 * @param mixed $replyto Reply to email address(es) 41 * @param mixed $replytoname Reply to name(s) 42 * @return boolean True on success 43 */ 44 function sendMail($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=null, $bcc=null, $attachment=null, $replyto=null, $replytoname=null ) 45 { 46 // Get a JMail instance 47 $mail =& JFactory::getMailer(); 48 49 $mail->setSender(array($from, $fromname)); 50 $mail->setSubject($subject); 51 $mail->setBody($body); 52 53 // Are we sending the email as HTML? 54 if ( $mode ) { 55 $mail->IsHTML(true); 56 } 57 58 $mail->addRecipient($recipient); 59 $mail->addCC($cc); 60 $mail->addBCC($bcc); 61 $mail->addAttachment($attachment); 62 63 // Take care of reply email addresses 64 if( is_array( $replyto ) ) { 65 $numReplyTo = count($replyto); 66 for ( $i=0; $i < $numReplyTo; $i++){ 67 $mail->addReplyTo( array($replyto[$i], $replytoname[$i]) ); 68 } 69 } elseif( isset( $replyto ) ) { 70 $mail->addReplyTo( array( $replyto, $replytoname ) ); 71 } 72 73 return $mail->Send(); 74 } 75 76 /** 77 * Sends mail to administrator for approval of a user submission 78 * 79 * @param string $adminName Name of administrator 80 * @param string $adminEmail Email address of administrator 81 * @param string $email [NOT USED TODO: Deprecate?] 82 * @param string $type Type of item to approve 83 * @param string $title Title of item to approve 84 * @param string $author Author of item to approve 85 * @return boolean True on success 86 */ 87 function sendAdminMail( $adminName, $adminEmail, $email, $type, $title, $author, $url = null ) 88 { 89 $subject = JText::_( 'User Submitted' ) ." '". $type ."'"; 90 91 $message = sprintf ( JText::_( 'MAIL_MSG_ADMIN' ), $adminName, $type, $title, $author, $url, $url, 'administrator', $type); 92 $message .= JText::_( 'MAIL_MSG') ."\n"; 93 94 // Get a JMail instance 95 $mail =& JFactory::getMailer(); 96 $mail->addRecipient($adminEmail); 97 $mail->setSubject($subject); 98 $mail->setBody($message); 99 100 return $mail->Send(); 101 } 102 103 /** 104 * Provides a secure hash based on a seed 105 * 106 * @param string Seed string 107 * @return string 108 */ 109 function getHash( $seed ) 110 { 111 $conf =& JFactory::getConfig(); 112 return md5( $conf->getValue('config.secret') . $seed ); 113 } 114 115 /** 116 * Method to determine a hash for anti-spoofing variable names 117 * 118 * @return string Hashed var name 119 * @since 1.5 120 * @static 121 */ 122 function getToken($forceNew = false) 123 { 124 $user = &JFactory::getUser(); 125 $session = &JFactory::getSession(); 126 $hash = JUtility::getHash( $user->get( 'id', 0 ).$session->getToken( $forceNew ) ); 127 return $hash; 128 } 129 130 /** 131 * Method to extract key/value pairs out of a string with xml style attributes 132 * 133 * @param string $string String containing xml style attributes 134 * @return array Key/Value pairs for the attributes 135 * @since 1.5 136 */ 137 function parseAttributes( $string ) 138 { 139 //Initialize variables 140 $attr = array(); 141 $retarray = array(); 142 143 // Lets grab all the key/value pairs using a regular expression 144 preg_match_all( '/([\w:-]+)[\s]?=[\s]?"([^"]*)"/i', $string, $attr ); 145 146 if (is_array($attr)) 147 { 148 $numPairs = count($attr[1]); 149 for($i = 0; $i < $numPairs; $i++ ) 150 { 151 $retarray[$attr[1][$i]] = $attr[2][$i]; 152 } 153 } 154 return $retarray; 155 } 156 157 /** 158 * Method to determine if the host OS is Windows 159 * 160 * @return true if Windows OS 161 * @since 1.5 162 * @static 163 */ 164 function isWinOS() { 165 return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; 166 } 167 168 /** 169 * Method to dump the structure of a variable for debugging purposes 170 * 171 * @param mixed A variable 172 * @param boolean True to ensure all characters are htmlsafe 173 * @return string 174 * @since 1.5 175 * @static 176 */ 177 function dump( &$var, $htmlSafe = true ) 178 { 179 $result = var_export( $var, true ); 180 return '<pre>'.( $htmlSafe ? htmlspecialchars( $result ) : $result).'</pre>'; 181 } 182 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |