Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/utilities/utility.php

Documentation is available at utility.php

  1. <?php
  2. /**
  3.  * @version        $Id: utility.php 6287 2007-01-16 00:31:17Z Jinx $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    Utilities
  6.  * @copyright    Copyright (C) 2005 - 2007 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. /**
  16.  * JUtility is a utility functions class
  17.  *
  18.  * @static
  19.  * @author        Johan Janssens <[email protected]>
  20.  * @package     Joomla.Framework
  21.  * @subpackage        Utilities
  22.  * @since    1.5
  23.  */
  24.  
  25. class JUtility
  26. {
  27.     /**
  28.       * Mail function (uses phpMailer)
  29.       *
  30.       * @param string $from From e-mail address
  31.       * @param string $fromname From name
  32.       * @param mixed $recipient Recipient e-mail address(es)
  33.       * @param string $subject E-mail subject
  34.       * @param string $body Message body
  35.       * @param boolean $mode false = plain text, true = HTML
  36.       * @param mixed $cc CC e-mail address(es)
  37.       * @param mixed $bcc BCC e-mail address(es)
  38.       * @param mixed $attachment Attachment file name(s)
  39.       * @param mixed $replyto Reply to email address(es)
  40.       * @param mixed $replytoname Reply to name(s)
  41.       * @return boolean True on success
  42.        */
  43.     function sendMail($from$fromname$recipient$subject$body$mode=0$cc=null$bcc=null$attachment=null$replyto=null$replytoname=null )
  44.     {
  45.         jimport('joomla.utilities.mail');
  46.  
  47.          // Get a JMail instance
  48.         $mail =JFactory::getMailer();
  49.  
  50.         $mail->setSender(array($from$fromname));
  51.         $mail->setSubject($subject);
  52.         $mail->setBody($body);
  53.  
  54.         // Are we sending the email as HTML?
  55.         if $mode {
  56.             $mail->IsHTML(true);
  57.         }
  58.  
  59.         $mail->addRecipient($recipient);
  60.         $mail->addCC($cc);
  61.         $mail->addBCC($bcc);
  62.         $mail->addAttachment($attachment);
  63.  
  64.         // Take care of reply email addresses
  65.         ifis_array$replyto ) ) {
  66.             $numReplyTo count($replyto);
  67.             for $i=0$i $numReplyTo$i++){
  68.                 $mail->addReplyToarray($replyto[$i]$replytoname[$i]) );
  69.             }
  70.         elseifisset$replyto ) ) {
  71.             $mail->addReplyToarray$replyto$replytoname ) );
  72.         }
  73.  
  74.         return  $mail->Send();
  75.     }
  76.  
  77.     /**
  78.      * Sends mail to administrator for approval of a user submission
  79.       *
  80.       * @param string $adminName Name of administrator
  81.       * @param string $adminEmail Email address of administrator
  82.       * @param string $email [NOT USED TODO: Deprecate?]
  83.       * @param string $type Type of item to approve
  84.       * @param string $title Title of item to approve
  85.       * @param string $author Author of item to approve
  86.       * @return boolean True on success
  87.       */
  88.     function sendAdminMail$adminName$adminEmail$email$type$title$author$url null )
  89.     {
  90.         $subject JText::_'User Submitted' ." '"$type ."'";
  91.  
  92.         $message sprintf JText::_'MAIL_MSG_ADMIN' )$adminName$type$title$author$url$url'administrator'$type);
  93.         $message .= JText::_'MAIL_MSG'."\n";
  94.  
  95.         eval ("\$message = \"$message\";");
  96.  
  97.         jimport('joomla.utilities.mail');
  98.  
  99.          // Get a JMail instance
  100.         $mail =JFactory::getMailer();
  101.         $mail->addRecipient($adminEmail);
  102.         $mail->setSubject($subject);
  103.         $mail->setBody($message);
  104.  
  105.         return  $mail->Send();
  106.     }
  107.  
  108.     /**
  109.        * Provides a secure hash based on a seed
  110.       *
  111.       * @param string Seed string
  112.       * @return string 
  113.       */
  114.     function getHash$seed )
  115.     {
  116.         $conf =JFactory::getConfig();
  117.         return md5$conf->getValue('config.secret'md5$seed ) );
  118.     }
  119.  
  120.     /**
  121.      * Method to determine a hash for anti-spoofing variable names
  122.      *
  123.      * @return    string    Hashed var name
  124.      * @since    1.5
  125.      * @static
  126.      */
  127.     function getToken($forceNew false)
  128.     {
  129.         $session =JFactory::getSession();
  130.         return $session->getToken($forceNew);
  131.     }
  132.     
  133.     /**
  134.       * Method to extract key/value pairs out of a string with xml style attributes
  135.       *
  136.       * @param    string    $string    String containing xml style attributes
  137.       * @return    array    Key/Value pairs for the attributes
  138.       * @since    1.5
  139.       */
  140.     function parseAttributes$string )
  141.     {
  142.          //Initialize variables
  143.         $attr        array();
  144.         $retarray    array();
  145.  
  146.         // Lets grab all the key/value pairs using a regular expression
  147.         preg_match_all'/([\w]+)[\s]?=[\s]?"([^"]*)"/i'$string$attr );
  148.  
  149.         if (is_array($attr))
  150.         {
  151.             $numPairs count($attr[1]);
  152.             for($i 0$i $numPairs$i++ )
  153.             {
  154.                 $retarray[$attr[1][$i]] $attr[2][$i];
  155.             }
  156.         }
  157.         return $retarray;
  158.     }
  159.  
  160.     /**
  161.      * Method to determine if the host OS is  Windows
  162.      *
  163.      * @return    true if Windows OS
  164.      * @since    1.5
  165.      * @static
  166.      */
  167.     function isWinOS({
  168.         return strtoupper(substr(PHP_OS03)) === 'WIN';
  169.     }
  170. }
  171. ?>

Documentation generated on Mon, 05 Mar 2007 21:30:48 +0000 by phpDocumentor 1.3.1