/**
  * Takes the path to an asset (image, js file, css file, etc) and prepends the webroot.
  */
 function SmartAsset($Destination = '', $WithDomain = FALSE, $AddVersion = FALSE)
 {
     $Destination = str_replace('\\', '/', $Destination);
     if (substr($Destination, 0, 7) == 'http://' || substr($Destination, 0, 8) == 'https://') {
         $Result = $Destination;
     } else {
         $Parts = array(StaticRequest('WebRoot', $WithDomain), $Destination);
         if (!$WithDomain) {
             array_unshift($Parts, '/');
         }
         $Result = CombinePaths($Parts, '/');
     }
     if ($AddVersion) {
         if (strpos($Result, '?') === FALSE) {
             $Result .= '?';
         } else {
             $Result .= '&';
         }
         // Figure out which version to put after the asset.
         $Version = APPLICATION_VERSION;
         if (preg_match('`^/([^/]+)/([^/]+)/`', $Destination, $Matches)) {
             $Type = $Matches[1];
             $Key = $Matches[2];
             static $ThemeVersion = NULL;
             switch ($Type) {
                 case 'plugins':
                     $PluginInfo = Gdn::PluginManager()->GetPluginInfo($Key);
                     $Version = GetValue('Version', $PluginInfo, $Version);
                     break;
                 case 'themes':
                     if ($ThemeVersion === NULL) {
                         $ThemeInfo = Gdn::ThemeManager()->GetThemeInfo(Theme());
                         if ($ThemeInfo !== FALSE) {
                             $ThemeVersion = GetValue('Version', $ThemeInfo, $Version);
                         } else {
                             $ThemeVersion = $Version;
                         }
                     }
                     $Version = $ThemeVersion;
                     break;
             }
         }
         $Result .= 'v=' . urlencode($Version);
     }
     return $Result;
 }
 /**
  * Generates a normalized URI for the given path.
  *
  * @param string $path A path to use instead of the current one
  *
  * @return string The normalized URI for the path
  *
  * @api
  */
 function GetUriForPath($path)
 {
     return StaticRequest('SchemeAndHttpHost') . StaticRequest('BaseUrl') . $path;
 }
 /** 
  * Send email message.
  */
 function SendEmailMessage($Options)
 {
     static $Defaults = array('To' => '', 'Cc' => '', 'Bcc' => '', 'SingleTo' => True, 'Subject' => '', 'Charset' => 'utf-8', 'WordWrap' => 0, 'ContentType' => 'text/plain', 'Encoding' => '8bit', 'Message' => '', 'bHtml' => False, 'BaseDirectory' => Null, 'Attachment' => '', 'Attachments' => array(), 'FromEmail' => '', 'FromName' => '', 'Priority' => 3, 'Sender' => '', 'ReplyTo' => '', 'ErrorsTo' => '', 'ReturnPath' => '', 'From' => '', 'Name' => array(), 'ConfirmReadingTo' => '', 'Organisation' => '', 'Date' => '', 'AbuseContact' => '', 'ThrowExceptions' => True);
     $Options = array_merge($Defaults, (array) $Options);
     extract($Options, EXTR_SKIP);
     $PhpMailer = new PHPMailer($ThrowExceptions);
     $PhpMailer->Priority = $Priority;
     $PhpMailer->ContentType = $ContentType;
     $PhpMailer->CharSet = $Charset;
     $PhpMailer->WordWrap = $WordWrap;
     $PhpMailer->SingleTo = $SingleTo;
     if (!$From) {
         if (!$FromEmail) {
             $FromEmail = C('Garden.Email.SupportAddress', '');
         }
         if (!$FromEmail) {
             $FromEmail = 'noreply@';
             if (class_exists('Gdn')) {
                 $FromEmail .= Gdn::Request()->Host();
             } else {
                 $FromEmail .= StaticRequest('Host');
             }
         }
         if (!$FromName) {
             $FromName = C('Garden.Email.SupportName', C('Garden.Title', ''));
         }
         $From = array('Name' => $FromName, 'Email' => $FromEmail);
     }
     $From = EmailRecipient($From);
     $PhpMailer->From = $From['Email'];
     $PhpMailer->FromName = $From['Name'];
     if ($Sender) {
         $PhpMailer->Sender = $Sender;
     } else {
         $PhpMailer->Sender = $PhpMailer->From;
     }
     if ($ConfirmReadingTo) {
         $PhpMailer->ConfirmReadingTo = $ConfirmReadingTo;
     }
     $PhpMailer->Subject = $Subject;
     if ($bHtml) {
         if ($BaseDirectory == Null) {
             $BaseDirectory = '.';
         }
         $PhpMailer->MsgHtml($Message, $BaseDirectory);
     } else {
         $PhpMailer->Body = $Message;
     }
     if ($Attachment) {
         foreach ((array) $Attachment as $File) {
             $PhpMailer->AddAttachment($File);
         }
     }
     foreach (EmailRecipient($To, True) as $Recipient) {
         $PhpMailer->AddAddress($Recipient['Email'], $Recipient['Name']);
     }
     if ($Cc) {
         foreach (EmailRecipient($Cc, True) as $Recipient) {
             $PhpMailer->AddCC($Recipient['Email'], $Recipient['Name']);
         }
     }
     if ($Bcc) {
         foreach (EmailRecipient($Bcc, True) as $Recipient) {
             $PhpMailer->AddBCC($Recipient['Email'], $Recipient['Name']);
         }
     }
     if ($ReplyTo) {
         foreach (EmailRecipient($ReplyTo, True) as $Recipient) {
             $PhpMailer->AddReplyTo($Recipient['Email'], $Recipient['Name']);
         }
     }
     $PhpMailer->AltBody = '';
     $PhpMailer->Send();
 }