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