first commit
This commit is contained in:
147
autoload/savant3/resources/Savant3_Filter_trimwhitespace.php
Normal file
147
autoload/savant3/resources/Savant3_Filter_trimwhitespace.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Filter to remove extra white space within the text.
|
||||
*
|
||||
* @package Savant3
|
||||
*
|
||||
* @author Monte Ohrt <monte@ispi.net>
|
||||
*
|
||||
* @author Contributions from Lars Noschinski <lars@usenet.noschinski.de>
|
||||
*
|
||||
* @author Converted to a Savant3 filter by Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
||||
*
|
||||
* @version $Id: Savant3_Filter_trimwhitespace.php,v 1.4 2005/05/29 15:27:07 pmjones Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Filter to remove extra white space within the text.
|
||||
*
|
||||
* @package Savant3
|
||||
*
|
||||
* @author Monte Ohrt <monte@ispi.net>
|
||||
*
|
||||
* @author Contributions from Lars Noschinski <lars@usenet.noschinski.de>
|
||||
*
|
||||
* @author Converted to a Savant3 filter by Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Savant3_Filter_trimwhitespace extends Savant3_Filter {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Removes extra white space within the text.
|
||||
*
|
||||
* Trim leading white space and blank lines from template source
|
||||
* after it gets interpreted, cleaning up code and saving bandwidth.
|
||||
* Does not affect <pre></pre>, <script></script>, or
|
||||
* <textarea></textarea> blocks.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $buffer The source text to be filtered.
|
||||
*
|
||||
* @return string The filtered text.
|
||||
*
|
||||
*/
|
||||
|
||||
public static function filter($buffer)
|
||||
{
|
||||
// Pull out the script blocks
|
||||
preg_match_all("!<script[^>]+>.*?</script>!is", $buffer, $match);
|
||||
$script_blocks = $match[0];
|
||||
$buffer = preg_replace(
|
||||
"!<script[^>]+>.*?</script>!is",
|
||||
'@@@SAVANT:TRIM:SCRIPT@@@',
|
||||
$buffer
|
||||
);
|
||||
|
||||
// Pull out the pre blocks
|
||||
preg_match_all("!<pre[^>]*>.*?</pre>!is", $buffer, $match);
|
||||
$pre_blocks = $match[0];
|
||||
$buffer = preg_replace(
|
||||
"!<pre[^>]*>.*?</pre>!is",
|
||||
'@@@SAVANT:TRIM:PRE@@@',
|
||||
$buffer
|
||||
);
|
||||
|
||||
// Pull out the textarea blocks
|
||||
preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $buffer, $match);
|
||||
$textarea_blocks = $match[0];
|
||||
$buffer = preg_replace(
|
||||
"!<textarea[^>]+>.*?</textarea>!is",
|
||||
'@@@SAVANT:TRIM:TEXTAREA@@@',
|
||||
$buffer
|
||||
);
|
||||
|
||||
// remove all leading spaces, tabs and carriage returns NOT
|
||||
// preceeded by a php close tag.
|
||||
$buffer = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $buffer));
|
||||
|
||||
// replace script blocks
|
||||
Savant3_Filter_trimwhitespace::replace(
|
||||
"@@@SAVANT:TRIM:SCRIPT@@@",
|
||||
$script_blocks,
|
||||
$buffer
|
||||
);
|
||||
|
||||
// replace pre blocks
|
||||
Savant3_Filter_trimwhitespace::replace(
|
||||
"@@@SAVANT:TRIM:PRE@@@",
|
||||
$pre_blocks,
|
||||
$buffer
|
||||
);
|
||||
|
||||
// replace textarea blocks
|
||||
Savant3_Filter_trimwhitespace::replace(
|
||||
"@@@SAVANT:TRIM:TEXTAREA@@@",
|
||||
$textarea_blocks,
|
||||
$buffer
|
||||
);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Does a simple search-and-replace on the source text.
|
||||
*
|
||||
* @access protected
|
||||
*
|
||||
* @param string $search The string to search for.
|
||||
*
|
||||
* @param string $replace Replace with this text.
|
||||
*
|
||||
* @param string &$buffer The source text.
|
||||
*
|
||||
* @return string The text after search-and-replace.
|
||||
*
|
||||
*/
|
||||
|
||||
protected static function replace($search, $replace, &$buffer)
|
||||
{
|
||||
$len = strlen($search);
|
||||
$pos = 0;
|
||||
$count = count($replace);
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
// does the search-string exist in the buffer?
|
||||
$pos = strpos($buffer, $search, $pos);
|
||||
if ($pos !== false) {
|
||||
// replace the search-string
|
||||
$buffer = substr_replace($buffer, $replace[$i], $pos, $len);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
109
autoload/savant3/resources/Savant3_Plugin_ahref.php
Normal file
109
autoload/savant3/resources/Savant3_Plugin_ahref.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates an <a href="">...</a> tag.
|
||||
*
|
||||
* @package Savant3
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
||||
*
|
||||
* @version $Id: Savant3_Plugin_ahref.php,v 1.4 2005/08/09 12:56:14 pmjones Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates an <a href="">...</a> tag.
|
||||
*
|
||||
* @package Savant3
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Savant3_Plugin_ahref extends Savant3_Plugin {
|
||||
|
||||
/**
|
||||
*
|
||||
* Generate an HTML <a href="">...</a> tag.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $href A string URL for the resulting tag. May
|
||||
* also be an array with any combination of the keys 'scheme',
|
||||
* 'host', 'path', 'query', and 'fragment' (c.f. PHP's native
|
||||
* parse_url() function).
|
||||
*
|
||||
* @param string $text The displayed text of the link.
|
||||
*
|
||||
* @param string|array $attr Any extra attributes for the <a> tag.
|
||||
*
|
||||
* @return string The <a href="">...</a> tag.
|
||||
*
|
||||
*/
|
||||
|
||||
public function ahref($href, $text, $attr = null)
|
||||
{
|
||||
$html = '<a href="';
|
||||
|
||||
if (is_array($href)) {
|
||||
|
||||
// add the HREF from an array
|
||||
$tmp = '';
|
||||
|
||||
if (isset($href['scheme'])) {
|
||||
$tmp .= $href['scheme'] . ':';
|
||||
if (strtolower($href['scheme']) != 'mailto') {
|
||||
$tmp .= '//';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($href['host'])) {
|
||||
$tmp .= $href['host'];
|
||||
}
|
||||
|
||||
if (isset($href['path'])) {
|
||||
$tmp .= $href['path'];
|
||||
}
|
||||
|
||||
if (isset($href['query'])) {
|
||||
$tmp .= '?' . $href['query'];
|
||||
}
|
||||
|
||||
if (isset($href['fragment'])) {
|
||||
$tmp .= '#' . $href['fragment'];
|
||||
}
|
||||
|
||||
$html .= htmlspecialchars($tmp);
|
||||
|
||||
} else {
|
||||
|
||||
// add the HREF from a scalar
|
||||
$html .= htmlspecialchars($href);
|
||||
|
||||
}
|
||||
|
||||
$html .= '"';
|
||||
|
||||
// add attributes
|
||||
if (is_array($attr)) {
|
||||
// from array
|
||||
foreach ($attr as $key => $val) {
|
||||
$key = htmlspecialchars($key);
|
||||
$val = htmlspecialchars($val);
|
||||
$html .= " $key=\"$val\"";
|
||||
}
|
||||
} elseif (! is_null($attr)) {
|
||||
// from scalar
|
||||
$html .= htmlspecialchars(" $attr");
|
||||
}
|
||||
|
||||
// set the link text, close the tag, and return
|
||||
$html .= '>' . $text . '</a>';
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
?>
|
||||
63
autoload/savant3/resources/Savant3_Plugin_htmlAttribs.php
Normal file
63
autoload/savant3/resources/Savant3_Plugin_htmlAttribs.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Plugin to convert an associative array to a string of tag attributes.
|
||||
*
|
||||
* @package Savant3
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
||||
*
|
||||
* @version $Id: Savant3_Plugin_htmlAttribs.php,v 1.3 2005/09/12 17:49:27 pmjones Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Plugin to convert an associative array to a string of tag attributes.
|
||||
*
|
||||
* @package Savant3
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Savant3_Plugin_htmlAttribs extends Savant3_Plugin {
|
||||
|
||||
/**
|
||||
*
|
||||
* Converts an associative array to a string of tag attributes.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array $attribs From this array, each key-value pair is
|
||||
* converted to an attribute name and value.
|
||||
*
|
||||
* @return string The XHTML for the attributes.
|
||||
*
|
||||
*/
|
||||
|
||||
public function htmlAttribs($attribs)
|
||||
{
|
||||
$xhtml = '';
|
||||
foreach ((array) $attribs as $key => $val) {
|
||||
|
||||
if ($val === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($val)) {
|
||||
$val = implode(' ', $val);
|
||||
}
|
||||
|
||||
$key = htmlspecialchars($key);
|
||||
$val = htmlspecialchars($val);
|
||||
|
||||
$xhtml .= " $key=\"$val\"";
|
||||
}
|
||||
return $xhtml;
|
||||
}
|
||||
}
|
||||
?>
|
||||
199
autoload/savant3/resources/Savant3_Plugin_image.php
Normal file
199
autoload/savant3/resources/Savant3_Plugin_image.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Plugin to generate an <img ... /> tag.
|
||||
*
|
||||
* @package Savant3
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
||||
*
|
||||
* @version $Id: Savant3_Plugin_image.php,v 1.7 2005/08/12 14:34:09 pmjones Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Plugin to generate an <img ... /> tag.
|
||||
*
|
||||
* Support for alpha transparency of PNG files in Microsoft IE added by
|
||||
* Edward Ritter; thanks, Edward.
|
||||
*
|
||||
* @package Savant3
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@ciaweb.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Savant3_Plugin_image extends Savant3_Plugin {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* The document root.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
|
||||
protected $documentRoot = null;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* The base directory for images within the document root.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
|
||||
protected $imageDir = null;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Outputs an <img ... /> tag.
|
||||
*
|
||||
* Microsoft IE alpha PNG support added by Edward Ritter.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param string $file The path to the image on the local file system
|
||||
* relative to $this->imageDir.
|
||||
*
|
||||
* @param string $alt Alternative descriptive text for the image;
|
||||
* defaults to the filename of the image.
|
||||
*
|
||||
* @param int $border The border width for the image; defaults to zero.
|
||||
*
|
||||
* @param int $width The displayed image width in pixels; defaults to
|
||||
* the width of the image.
|
||||
*
|
||||
* @param int $height The displayed image height in pixels; defaults to
|
||||
* the height of the image.
|
||||
*
|
||||
* @return string An <img ... /> tag.
|
||||
*
|
||||
*/
|
||||
|
||||
public function image($file, $alt = null, $height = null, $width = null,
|
||||
$attr = null)
|
||||
{
|
||||
// is the document root set?
|
||||
if (is_null($this->documentRoot) && isset($_SERVER['DOCUMENT_ROOT'])) {
|
||||
// no, so set it
|
||||
$this->documentRoot = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
// make sure there's a DIRECTORY_SEPARATOR between the docroot
|
||||
// and the image dir
|
||||
if (substr($this->documentRoot, -1) != DIRECTORY_SEPARATOR &&
|
||||
substr($this->imageDir, 0, 1) != DIRECTORY_SEPARATOR) {
|
||||
$this->documentRoot .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
// make sure there's a separator between the imageDir and the
|
||||
// file name
|
||||
if (substr($this->imageDir, -1) != DIRECTORY_SEPARATOR &&
|
||||
substr($file, 0, 1) != DIRECTORY_SEPARATOR) {
|
||||
$this->imageDir .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
// the image file type code (PNG = 3)
|
||||
$type = null;
|
||||
|
||||
// get the file information
|
||||
$info = false;
|
||||
|
||||
if (strpos($file, '://') === false) {
|
||||
// no "://" in the file, so it's local
|
||||
$file = $this->imageDir . $file;
|
||||
$tmp = $this->documentRoot . $file;
|
||||
$info = @getimagesize($tmp);
|
||||
} else {
|
||||
// don't attempt to get file info from streams, it takes
|
||||
// way too long.
|
||||
$info = false;
|
||||
}
|
||||
|
||||
// did we find the file info?
|
||||
if (is_array($info)) {
|
||||
|
||||
// capture type info regardless
|
||||
$type = $info[2];
|
||||
|
||||
// capture size info where both not specified
|
||||
if (is_null($width) && is_null($height)) {
|
||||
$width = $info[0];
|
||||
$height = $info[1];
|
||||
}
|
||||
}
|
||||
|
||||
// clean up
|
||||
unset($info);
|
||||
|
||||
// is the file a PNG? if so, check user agent, we will need to
|
||||
// make special allowances for Microsoft IE.
|
||||
if (stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && $type === 3) {
|
||||
|
||||
// support alpha transparency for PNG files in MSIE
|
||||
$html = '<span style="position: relative;';
|
||||
|
||||
if ($height) {
|
||||
$html .= ' height: ' . $height . 'px;';
|
||||
}
|
||||
|
||||
if ($width) {
|
||||
$html .= ' width: ' . $width . 'px;';
|
||||
}
|
||||
|
||||
$html .= ' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader';
|
||||
$html .= "(src='" . htmlspecialchars($file) . "',sizingMethod='scale');\"";
|
||||
$html .= ' title="' . htmlspecialchars($alt) . '"';
|
||||
|
||||
$html .= $this->Savant->htmlAttribs($attr);
|
||||
|
||||
// done
|
||||
$html .= '></span>';
|
||||
|
||||
} else {
|
||||
|
||||
// not IE, so build a normal image tag.
|
||||
$html = '<img';
|
||||
$html .= ' src="' . htmlspecialchars($file) . '"';
|
||||
|
||||
// add the alt attribute
|
||||
if (is_null($alt)) {
|
||||
$alt = basename($file);
|
||||
}
|
||||
$html .= ' alt="' . htmlspecialchars($alt) . '"';
|
||||
|
||||
// add the height attribute
|
||||
if ($height) {
|
||||
$html .= ' height="' . htmlspecialchars($height) . '"';
|
||||
}
|
||||
|
||||
// add the width attribute
|
||||
if ($width) {
|
||||
$html .= ' width="' . htmlspecialchars($width) . '"';
|
||||
}
|
||||
|
||||
$html .= $this->Savant->htmlAttribs($attr);
|
||||
|
||||
// done
|
||||
$html .= ' />';
|
||||
|
||||
}
|
||||
|
||||
// done!
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user