示例#1
0
 /**
  * Get the body content
  *
  * @param string|null $headers Header to edit or null to add the header in the email
  * @return string
  */
 protected function getBody(&$headers = null)
 {
     $body = null;
     //$text = $this->quotePrintable($this->cfg->text);
     $text = $this->cfg->text;
     if ($this->cfg->html) {
         if (empty($this->cfg->text)) {
             //$text = $this->quotePrintable(utils::html2Text($this->cfg->html));
             $text = utils::html2Text($this->cfg->html);
         }
         $boundary = '------------' . $this->getBoundary();
         if ($headers) {
             $headers .= $this->headerLine('Content-Type', 'multipart/alternative;' . $this->cfg->crlf . ' boundary="' . $boundary . '"');
             //$headers.= $this->textLine(' boundary="'.$boundary.'"');
         } else {
             $body .= $this->headerLine('Content-Type', 'multipart/alternative;' . $this->cfg->crlf . ' boundary="' . $boundary . '"');
             //$body.= $this->textLine(' boundary="'.$boundary.'"');
             $body .= $this->textLine('');
         }
         // Text part
         $body .= $this->textLine('This is a multi-part message in MIME format.');
         $body .= $this->textLine('--' . $boundary);
     }
     $body .= $this->headerLine('Content-Type', 'text/plain; charset=' . $this->cfg->charset);
     //$body.= $this->textLine(' charset="'.$this->cfg->charset.'"');
     $body .= $this->headerLine('Content-Transfer-Encoding', $this->cfg->encoding);
     //$body.= $this->headerLine('Content-Disposition', 'inline');
     $body .= $this->textLine(null);
     $body .= $this->textLine($this->encode($this->wrapText($text)));
     if ($this->cfg->html) {
         // HTML part
         $body .= $this->textLine('--' . $boundary);
         $html = $this->cfg->html;
         $inlineImages = false;
         if ($this->cfg->htmlInlineImage) {
             $rootUri = request::get('rootUri');
             preg_match_all('@src="(' . $rootUri . '|/)(.+)"@siU', $html, $matches);
             if (!empty($matches)) {
                 $images = array_unique($matches[2]);
                 $inlineImages = array();
                 $i = 1;
                 foreach ($images as $img) {
                     if (file::webExists($img)) {
                         $file = WEBROOT . str_replace('/', DS, $img);
                         $cid = 'part' . $i . '.' . $this->getBoundary(16) . '@' . $this->cfg->serverName;
                         $inlineImages[] = array('cid' => $cid, 'file' => $file, 'name' => file::name($file), 'type' => file::getType($file));
                         $i++;
                         $html = preg_replace('@src="(' . $rootUri . '|/)(' . $img . ')"@siU', 'src="cid:' . $cid . '"', $html);
                     }
                 }
             }
         }
         if (!empty($inlineImages)) {
             $boundaryRel = '------------' . $this->getBoundary();
             $body .= $this->headerLine('Content-Type', 'multipart/related;' . $this->cfg->crlf . ' boundary="' . $boundaryRel . '"');
             //$body.= $this->textLine(' boundary="'.$boundaryRel.'"');
             $body .= $this->textLine(null);
             $body .= $this->textLine(null);
             $body .= $this->textLine('--' . $boundaryRel);
         }
         $body .= $this->headerLine('Content-Type', 'text/html; charset=' . $this->cfg->charset . '');
         //$body.= $this->textLine(' charset="'.$this->cfg->charset.'"');
         $body .= $this->headerLine('Content-Transfer-Encoding', $this->cfg->encoding);
         //$body.= $this->headerLine('Content-Disposition', 'inline');
         $body .= $this->textLine(null);
         //$body.= $this->textLine($this->quotePrintable($html));
         $body .= $this->textLine($this->encode($this->wrapText($html)));
         if (!empty($inlineImages)) {
             foreach ($inlineImages as $img) {
                 $body .= $this->textLine('--' . $boundaryRel);
                 $body .= $this->headerLine('Content-Type', $img['type']);
                 //.'; name="'.$img['name'].'"');
                 $body .= $this->headerLine('Content-Transfer-Encoding', $this->cfg->fileEncoding);
                 $body .= $this->headerLine('Content-ID', '<' . $img['cid'] . '>');
                 //$body.= $this->headerLine('Content-Disposition', 'inline; filename="'.$img['name'].'"');
                 $body .= $this->textLine(null);
                 $body .= $this->encode(file::read($img['file']), $this->cfg->fileEncoding);
             }
             $body .= $this->textLine('--' . $boundaryRel . '--');
             $body .= $this->textLine(null);
         }
         $body .= '--' . $boundary . '--';
     }
     return $body;
 }
示例#2
0
	/**
	 * Add an include file
	 *
	 * @param array $prm Same parameter as addCss or addJs, with adding:
	 *  - string type File type (js or css) (required)
	 * @return bool True if addedor already added, False if not found
	 * @throws nExecption if type or file not  provided
	 * @see addJs, addCss
	 */
	public function add(array $prm) {
		if (config::initTab($prm, array(
			'type'=>null,
			'file'=>null,
			'dir'=>'nyro',
			'media'=>'screen',
			'condIE'=>false,
			'verifExists'=>true
		))) {
			$ret = false;
			$firstFile = $prm['file'];
			
			if (strpos($firstFile, 'jquery') === 0 && $firstFile != 'jquery')
				$this->addJS('jquery');

			foreach($this->getDepend($prm['file'], $prm['type']) as $d) {
				if (is_array($d))
					$this->add(array_merge($prm, $d));
				else
					$this->add(array_merge($prm, array('file'=>$d)));
			}

            foreach($this->cfg->getInArray($prm['type'], 'alias') as $k=>$a) {
                if (strtolower($prm['file']) == strtolower($k))
                    $prm['file'] = $a;
            }

			$prmType = $this->cfg->get($prm['type']);

			$locDir = $prm['dir'];
			if (!array_key_exists($locDir, $this->incFiles[$prm['type']]))
				$locDir = 'nyro';

			$fileExt = $prm['file'].'.'.$prm['type'];

			if ($prm['verifExists'])
				$fileExists = $locDir == 'web'
					? file::webExists($prmType['dirWeb'].DS.$fileExt)
					: file::nyroExists(array(
								'name'=>'module_'.nyro::getCfg()->compressModule.'_'.$prm['type'].'_'.$prm['file'],
								'type'=>'tpl',
								'tplExt'=>$prm['type']
							));
			else
				$fileExists = true;

			if ($fileExists) {
				if (!isset($this->incFiles[$prm['type']][$locDir][$prm['media']]))
					$this->incFiles[$prm['type']][$locDir][$prm['media']] = array();
				$this->incFiles[$prm['type']][$locDir][$prm['media']][$prm['file']] = $prm;
				if ($prm['type'] == 'css') {
					$c = file::read($fileExists);
					preg_match_all('`@import (url\()?"(.+).css"\)?;`', $c, $matches);
					if (!empty($matches[2])) {
						$prefix = substr($prm['file'], 0, strpos($prm['file'], '_')+1);
						foreach($matches[2	] as $m)
							$this->add(array_merge($prm, array('file'=>$prefix.$m)));
					}
				}
				$ret = true;
			}

			foreach($this->getDepend($firstFile, $prm['type'], true) as $d) {
				if (is_array($d))
					$this->add(array_merge($prm, $d));
				else
					$this->add(array_merge($prm, array('file'=>$d)));
			}

			return $ret;
		} else
			throw new nException('reponse::add: parameters file and/or type not provied');
	}