Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fValidation::setCSRFTokenField(), allow dashes in HTML attributes #49

Closed
wants to merge 25 commits into from

5 participants

@Tatsh

Please let me know if something is missing here and I will fix it.

Tatsh and others added some commits
@Tatsh Tatsh Added ::setCSRFTokenField() abd4e4e
@Tatsh Tatsh Allow dashes in HTML attributes (HTML 5) 2816a5e
@Tatsh Tatsh Fix variable name 2c3136e
@Tatsh Tatsh Fix checking CSRF token 14fe18d
@Tatsh Tatsh Only check if there is a value set 2f492b8
@Tatsh Tatsh Add makeLinks() method to retrieve HTML instead of printing it 47569c2
@Tatsh Tatsh Make method protected f6dd23f
@jeffturcotte jeffturcotte Fixed an issue in fImage::getImageType where too few bytes were read …
…for certain JPEG image types
33f41c3
@jeffturcotte jeffturcotte Fixed return bug in checkConditionalRules f13fa9e
@khamer khamer Changes to fFile to better handle text filetype detection
Improved the comment

Changes to fFile to better handle text filetype detection

Improved the comment
c81654a
@jeffturcotte jeffturcotte Merge pull request #1 from khamer/master
Changes to fFile to better handle text filetype detection
02eb9ae
@khamer khamer Updated comment 5b25a75
@khamer khamer Merge pull request #3 from khamer/master
Forgot comment
384b98a
@jeffturcotte jeffturcotte Added enhancement for registering static fActiveRecord methods. PHP 5…
….3+ only.
3e1fd3d
@khamer khamer Merge pull request #2 from jeffturcotte/master
Added fORM::registerActiveRecordStaticMethod for "static plugin" support
aa58283
@mattsah mattsah Fix for parsing Accept headers with excess whitespace
This problem is mainly caused by some crazy accept header that's
sent 50% of the time in IE, but it may be caused by other
browsers that add additional whitespace. Not sure if the standard
is clear on whether extra whitespace can or can't exist, but
either way this solves it for non-compliant browsers.
3f6885a
@khamer khamer Merge pull request #5 from mattsah/master
Fix for parsing Accept headers with excess whitespace
50dcedb
@Tatsh Tatsh Remove default -colorspace argument e2a9f26
@Tatsh Tatsh Detect old version of ImageMagick and use old format if necessary; ad…
…just to new version of ImageMagick syntax which defaults to sRGB by default; detect original colorspace in JPEGs and TIFF images
3b112c5
@Tatsh Tatsh Forgot check for Windows 492bbe2
@jeffturcotte jeffturcotte Added getRootPath to fTemplating 06930e1
@Tatsh Tatsh Resolve merge conflict 5c98c39
@Tatsh Tatsh Resolve merge conflicts c3541d0
@Tatsh Tatsh Add method to get the HTML of the links 6cff56f
@Tatsh Tatsh Forgot to register method 9afbd32
@wbond
Owner

So for pull requests to work out, I think you need to create a branch for the specific issue you want pulled, otherwise every commit to your branch gets added to the pull request and it gets overwhelming like here.

So, if you can move this commit to a separate branch and open a pull request on it then I can go through and be sure about what you are asking to merge in.

@wbond wbond closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 27, 2012
  1. @Tatsh

    Added ::setCSRFTokenField()

    Tatsh authored
  2. @Tatsh
  3. @Tatsh

    Fix variable name

    Tatsh authored
Commits on Apr 29, 2012
  1. @Tatsh

    Fix checking CSRF token

    Tatsh authored
Commits on May 2, 2012
  1. @Tatsh
  2. @Tatsh
  3. @Tatsh

    Make method protected

    Tatsh authored
Commits on Jun 5, 2012
  1. @jeffturcotte
Commits on Jun 19, 2012
  1. @jeffturcotte
Commits on Jul 23, 2012
  1. @khamer

    Changes to fFile to better handle text filetype detection

    khamer authored
    Improved the comment
    
    Changes to fFile to better handle text filetype detection
    
    Improved the comment
  2. @jeffturcotte

    Merge pull request #1 from khamer/master

    jeffturcotte authored
    Changes to fFile to better handle text filetype detection
Commits on Jul 25, 2012
  1. @khamer

    Updated comment

    khamer authored
  2. @khamer

    Merge pull request #3 from khamer/master

    khamer authored
    Forgot comment
  3. @jeffturcotte
  4. @khamer

    Merge pull request #2 from jeffturcotte/master

    khamer authored
    Added fORM::registerActiveRecordStaticMethod for "static plugin" support
Commits on Jul 27, 2012
  1. @mattsah

    Fix for parsing Accept headers with excess whitespace

    mattsah authored
    This problem is mainly caused by some crazy accept header that's
    sent 50% of the time in IE, but it may be caused by other
    browsers that add additional whitespace. Not sure if the standard
    is clear on whether extra whitespace can or can't exist, but
    either way this solves it for non-compliant browsers.
  2. @khamer

    Merge pull request #5 from mattsah/master

    khamer authored
    Fix for parsing Accept headers with excess whitespace
Commits on Sep 3, 2012
  1. @Tatsh
  2. @Tatsh

    Detect old version of ImageMagick and use old format if necessary; ad…

    Tatsh authored
    …just to new version of ImageMagick syntax which defaults to sRGB by default; detect original colorspace in JPEGs and TIFF images
  3. @Tatsh

    Forgot check for Windows

    Tatsh authored
Commits on Oct 25, 2012
  1. @jeffturcotte
Commits on Oct 27, 2012
  1. @Tatsh

    Resolve merge conflict

    Tatsh authored
  2. @Tatsh

    Resolve merge conflicts

    Tatsh authored
Commits on Nov 1, 2012
  1. @Tatsh
  2. @Tatsh

    Forgot to register method

    Tatsh authored
This page is out of date. Refresh to see the latest.
View
61 fActiveRecord.php
@@ -10,12 +10,14 @@
* @copyright Copyright (c) 2007-2011 Will Bond, others
* @author Will Bond [wb] <will@flourishlib.com>
* @author Will Bond, iMarc LLC [wb-imarc] <will@imarc.net>
+ * @author Jeff Turcotte [jt] <jeff.turcotte@gmail.com>
* @license http://flourishlib.com/license
*
* @package Flourish
* @link http://flourishlib.com/fActiveRecord
*
- * @version 1.0.0b81
+ * @version 1.0.0b82
+ * @changes 1.0.0b82 Added support for registering methods for __callStatic() [jt, 2011-07-25]
* @changes 1.0.0b81 Fixed a bug with updating a record that contains only an auto-incrementing primary key [wb, 2011-09-06]
* @changes 1.0.0b80 Added support to ::checkCondition() for the `^~` and `$~` operators [wb, 2011-06-20]
* @changes 1.0.0b79 Fixed some bugs in handling relationships between PHP 5.3 namespaced classes [wb, 2011-05-26]
@@ -157,6 +159,14 @@
*/
static protected $replicate_map = array();
+
+ /**
+ * Caches callbacks for static methods
+ *
+ * @var array
+ **/
+ static protected $static_callback_cache = array();
+
/**
* Contains a list of what columns in each class need to be unescaped and what data type they are
*
@@ -164,7 +174,52 @@
*/
static protected $unescape_map = array();
-
+
+ /**
+ * Handles dynamically registered static method callbacks
+ *
+ * Static method callbacks registered through fORM::registerActiveRecordStaticMethod()
+ * will be delegated via this method. Both this and fORM::registerActiveRecordStaticMethod
+ * are available to PHP 5.3+ only.
+ *
+ * @throws fProgrammerException When the method cannot be found
+ * @param string $method_name The name of the method called
+ * @param array $parameters The parameters passed
+ * @return mixed The value returned by the method called
+ */
+ static public function __callStatic($method_name, $parameters)
+ {
+ $class = get_called_class();
+
+ self::forceConfigure($class);
+
+ if (!isset(self::$static_callback_cache[$class][$method_name])) {
+ if (!isset(self::$static_callback_cache[$class])) {
+ self::$static_callback_cache[$class] = array();
+ }
+ $callback = fORM::getActiveRecordStaticMethod($class, $method_name);
+ self::$static_callback_cache[$class][$method_name] = $callback ? $callback : FALSE;
+ }
+
+ if ($callback = self::$static_callback_cache[$class][$method_name]) {
+ return call_user_func_array(
+ $callback,
+ array(
+ $class,
+ $method_name,
+ $parameters
+ )
+ );
+ }
+
+ // Error handler
+ throw new fProgrammerException(
+ 'Unknown static method, %s(), called',
+ $method_name
+ );
+ }
+
+
/**
* Sets a value to the `$values` array, preserving the old value in `$old_values`
*
@@ -2981,4 +3036,4 @@ public function validate($return_messages=FALSE, $remove_column_names=FALSE)
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- */
+ */
View
30 fFile.php
@@ -5,12 +5,14 @@
* @copyright Copyright (c) 2007-2011 Will Bond, others
* @author Will Bond [wb] <will@flourishlib.com>
* @author Will Bond, iMarc LLC [wb-imarc] <will@imarc.net>
+ * @author Kevin Hamer, iMarc LLC [kh] <kevin@imarc.net>
* @license http://flourishlib.com/license
*
* @package Flourish
* @link http://flourishlib.com/fFile
*
- * @version 1.0.0b39
+ * @version 1.0.0b40
+ * @changes 1.0.0b40 Improved ::determineMimeTypeByContents() for text files to focus on the first non-blank line and look for <html. [kh, 2012-07-25]
* @changes 1.0.0b39 Backwards Compatibility Break - ::output() now automatically ends any open output buffering and discards the contents [wb, 2011-08-24]
* @changes 1.0.0b38 Added the Countable interface to the class [wb, 2011-06-03]
* @changes 1.0.0b37 Fixed mime type detection of BMP images [wb, 2011-03-07]
@@ -338,8 +340,15 @@ static private function determineMimeTypeByContents($content, $extension)
}
- // Text files
- if (strpos($content, '<?xml') !== FALSE) {
+ // Better detection for text files based on the first line or so.
+ if (strpos($content, '<?php') !== FALSE || strpos($content, '<?=') !== FALSE) {
+ return 'application/x-httpd-php';
+ }
+
+ preg_match('/(\S.*?)\s*\n/m', $content, $lines);
+ $first_line = count($lines) > 1 ? $lines[1] : '';
+
+ if (strpos($first_line, '<?xml') !== FALSE) {
if (stripos($content, '<!DOCTYPE') !== FALSE) {
return 'application/xhtml+xml';
}
@@ -349,14 +358,17 @@ static private function determineMimeTypeByContents($content, $extension)
if (strpos($content, '<rss') !== FALSE) {
return 'application/rss+xml';
}
- return 'application/xml';
- }
+ return 'application/xml';
+ }
- if (strpos($content, '<?php') !== FALSE || strpos($content, '<?=') !== FALSE) {
- return 'application/x-httpd-php';
+ if (stripos($first_line, '<html') !== FALSE) {
+ return 'text/html';
+ }
+ if (stripos($first_line, '<!DOCTYPE') !== FALSE) {
+ return 'text/html';
}
- if (preg_match('#^\#\![/a-z0-9]+(python|perl|php|ruby)$#mi', $content, $matches)) {
+ if (preg_match('#^\#\![/a-z0-9]+(python|perl|php|ruby)$#mi', $first_line, $matches)) {
switch (strtolower($matches[1])) {
case 'php':
return 'application/x-httpd-php';
@@ -1340,4 +1352,4 @@ public function write($data)
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- */
+ */
View
4 fHTML.php
@@ -174,7 +174,7 @@ static public function prepare($content)
}
// Find all html tags, entities and comments
- $reg_exp = "/<\s*\/?\s*[\w:]+(?:\s+[\w:]+(?:\s*=\s*(?:\"[^\"]*?\"|'[^']*?'|[^'\">\s]+))?)*\s*\/?\s*>|&(?:#\d+|\w+);|<\!--.*?-->/s";
+ $reg_exp = "/<\s*\/?\s*[\w\-:]+(?:\s+[\w\-:]+(?:\s*=\s*(?:\"[^\"]*?\"|'[^']*?'|[^'\">\s]+))?)*\s*\/?\s*>|&(?:#\d+|\w+);|<\!--.*?-->/s";
preg_match_all($reg_exp, $content, $html_matches, PREG_SET_ORDER);
// Find all text
@@ -315,4 +315,4 @@ private function __construct() { }
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- */
+ */
View
121 fImage.php
@@ -1,16 +1,18 @@
<?php
/**
* Represents an image on the filesystem, also provides image manipulation functionality
- *
+ *
* @copyright Copyright (c) 2007-2011 Will Bond, others
* @author Will Bond [wb] <will@flourishlib.com>
* @author Will Bond, iMarc LLC [wb-imarc] <will@imarc.net>
+ * @author Jeff Turcotte, iMarc LLC [jt] <jeff@imarc.net>
* @license http://flourishlib.com/license
- *
+ *
* @package Flourish
* @link http://flourishlib.com/fImage
- *
- * @version 1.0.0b33
+ *
+ * @version 1.0.0b34
+ * @changes 1.0.0b34 Fixed a bug in getImageType() where the fread was not reading enough bytes [jt, 2012-06-05]
* @changes 1.0.0b33 Fixed a method signature [wb, 2011-08-24]
* @changes 1.0.0b32 Added a call to clearstatcache() to ::saveChanges() to solve a bug when fFile::output() is called in the same script execution [wb, 2011-05-23]
* @changes 1.0.0b31 Fixed a bug in using ImageMagick to convert files with a colon in the filename [wb, 2011-03-20]
@@ -157,7 +159,7 @@ static public function create($file_path, $contents)
*
* @return void
*/
- static private function determineProcessor()
+ static protected function determineProcessor()
{
// Determine what processor to use
if (self::$processor === NULL) {
@@ -370,14 +372,14 @@ static protected function getInfo($image_path, $element=NULL)
/**
* Gets the image type from a file by looking at the file contents
- *
+ *
* @param string $image The image path to get the type for
- * @return string|NULL The type of the image - `'jpg'`, `'gif'`, `'png'` or `'tif'` - NULL if not one of those
+ * @return string|NULL The type of the image - `'jpg'`, `'gif'`, `'png'` or `'tif'` - NULL if not one of those
*/
static private function getImageType($image)
{
$handle = fopen($image, 'r');
- $contents = fread($handle, 12);
+ $contents = fread($handle, 32);
fclose($handle);
$_0_8 = substr($contents, 0, 8);
@@ -407,11 +409,11 @@ static private function getImageType($image)
/**
* Checks to make sure the class can handle the image file specified
- *
+ *
* @internal
- *
+ *
* @throws fValidationException When the image specified does not exist
- *
+ *
* @param string $image The image to check for incompatibility
* @return boolean If the image is compatible with the detected image processor
*/
@@ -1105,6 +1107,42 @@ private function processWithGD($output_file, $jpeg_quality)
imagedestroy($gd_res);
}
+ /**
+ * Determines if ImageMagick is of version less than 6.7.5.
+ *
+ * @return boolean `TRUE` if the version is less than 6.7.5, `FALSE` otherwise.
+ */
+ static private function isOldImageMagickVersion() {
+ $command_line = escapeshellarg(self::$imagemagick_dir . 'convert');
+ if (fCore::checkOS('windows')) {
+ $command_line = str_replace(' ', '" "', self::$imagemagick_dir . 'convert.exe');
+ }
+ $command_line .= ' -version';
+
+ fCore::debug(sprintf('Executing "%s"', $command_line));
+ exec($command_line, $output, $return_value);
+
+ if ($return_value !== 0) {
+ throw new fEnvironmentException(
+ "An error occurred running the command, %1\$s, to modify the image. The error output was:\n%2\$s",
+ $command_line,
+ join("\n", $output)
+ );
+ }
+
+ // Example line: Version: ImageMagick 6.7.8-7 2012-08-05 Q32 http://www.imagemagick.org
+ foreach ($output as $line) {
+ $matches = array();
+ if (preg_match('/Version\:\s+ImageMagick\s+6\.7.(\d)/', $line, $matches)) {
+ if ($matches[1] >= 5) {
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
+ }
+
/**
* Processes the current image using ImageMagick
@@ -1116,7 +1154,42 @@ private function processWithGD($output_file, $jpeg_quality)
private function processWithImageMagick($output_file, $jpeg_quality)
{
$type = self::getImageType($this->file);
- if (fCore::checkOS('windows')) {
+ $original_colorspace = NULL;
+ $is_windows = fCore::checkOS('windows');
+ $is_old_version = self::isOldImageMagickVersion();
+ $desaturated = FALSE;
+
+ if (!$is_old_version && in_array($type, array('jpg', 'tif'))) {
+ $identify_command_line = escapeshellarg(self::$imagemagick_dir . 'identify');
+
+ if ($is_windows) {
+ $identify_command_line = str_replace(' ', '" "', self::$imagemagick_dir . 'identify.exe');
+ }
+
+ $identify_command_line .= ' -verbose ';
+ $identify_command_line .= escapeshellarg($this->file);
+
+ fCore::debug(sprintf('Executing "%s"', $identify_command_line));
+ exec($identify_command_line, $output, $return_value);
+
+ if ($return_value !== 0) {
+ throw new fEnvironmentException(
+ "An error occurred running the command, %1\$s, to modify the image. The error output was:\n%2\$s",
+ $identify_command_line,
+ join("\n", $output)
+ );
+ }
+
+ foreach ($output as $line) {
+ $matches = array();
+ if (preg_match('/\s+Colorspace\:\s+([A-Za-z0-9]+)/', $line, $matches)) {
+ $original_colorspace = $matches[1];
+ break;
+ }
+ }
+ }
+
+ if ($is_windows) {
$command_line = str_replace(' ', '" "', self::$imagemagick_dir . 'convert.exe');
} else {
$command_line = escapeshellarg(self::$imagemagick_dir . 'convert');
@@ -1142,6 +1215,10 @@ private function processWithImageMagick($output_file, $jpeg_quality)
$command_line .= ' ' . escapeshellarg(str_replace('tif', 'tiff', $type) . ':' . $file) . ' ';
+ if (!$is_old_version && $original_colorspace) {
+ $command_line .= ' -colorspace '.escapeshellarg($original_colorspace).' ';
+ }
+
// Animated gifs need to be coalesced
if ($this->isAnimatedGif()) {
$command_line .= ' -coalesce ';
@@ -1171,6 +1248,7 @@ private function processWithImageMagick($output_file, $jpeg_quality)
// Perform the desaturate operation
} elseif ($mod['operation'] == 'desaturate') {
$command_line .= ' -colorspace GRAY ';
+ $desaturated = TRUE;
// Perform the rotate operation
} elseif ($mod['operation'] == 'rotate') {
@@ -1178,9 +1256,15 @@ private function processWithImageMagick($output_file, $jpeg_quality)
}
}
- // Default to the RGB colorspace
- if (strpos($command_line, ' -colorspace ') === FALSE) {
- $command_line .= ' -colorspace RGB ';
+ if (!$desaturated) {
+ // Convert if necessary because all browsers support sRGB but not all
+ // support colorspaces like CMYK
+ if (!$is_old_version && $original_colorspace != 'sRGB' && !$desaturated) {
+ $command_line .= ' -colorspace sRGB ';
+ }
+ else if ($is_old_version) {
+ $command_line .= ' -colorspace RGB ';
+ }
}
if ($new_type == 'jpg') {
@@ -1189,8 +1273,9 @@ private function processWithImageMagick($output_file, $jpeg_quality)
$command_line .= ' ' . escapeshellarg($new_type . ':' . $output_file) . ' 2>&1';
+ fCore::debug(sprintf('Executing "%s"', $command_line));
exec($command_line, $output, $return_value);
-
+
if ($return_value !== 0) {
throw new fEnvironmentException(
"An error occurred running the command, %1\$s, to modify the image. The error output was:\n%2\$s",
@@ -1486,4 +1571,6 @@ public function saveChanges($new_image_type=NULL, $jpeg_quality=90, $overwrite=F
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- */
+ */
+
+// kate: replace-tabs:false
View
169 fORM.php
@@ -4,12 +4,14 @@
*
* @copyright Copyright (c) 2007-2011 Will Bond
* @author Will Bond [wb] <will@flourishlib.com>
+ * @author Jeff Turcotte [jt] <jeff.turcotte@gmail.com>
* @license http://flourishlib.com/license
*
* @package Flourish
* @link http://flourishlib.com/fORM
*
- * @version 1.0.0b28
+ * @version 1.0.0b29
+ * @changes 1.0.0b29 Added ::registerActiveRecordStaticMethod() for static hooks in PHP 5.3 [jt, 2012-07-25]
* @changes 1.0.0b28 Updated ::getColumnName() and ::getRecordName() to use fText if loaded [wb, 2011-02-02]
* @changes 1.0.0b27 Added links to the detailed documentation for the parameters passed to hooks [wb, 2010-11-27]
* @changes 1.0.0b26 Added ::getRelatedClass() for handling related classes in PHP 5.3 namespaces [wb, 2010-11-17]
@@ -42,39 +44,40 @@
class fORM
{
// The following constants allow for nice looking callbacks to static methods
- const callHookCallbacks = 'fORM::callHookCallbacks';
- const callInspectCallbacks = 'fORM::callInspectCallbacks';
- const callReflectCallbacks = 'fORM::callReflectCallbacks';
- const checkHookCallback = 'fORM::checkHookCallback';
- const classize = 'fORM::classize';
- const defineActiveRecordClass = 'fORM::defineActiveRecordClass';
- const enableSchemaCaching = 'fORM::enableSchemaCaching';
- const getActiveRecordMethod = 'fORM::getActiveRecordMethod';
- const getClass = 'fORM::getClass';
- const getColumnName = 'fORM::getColumnName';
- const getDatabaseName = 'fORM::getDatabaseName';
- const getRecordName = 'fORM::getRecordName';
- const getRecordSetMethod = 'fORM::getRecordSetMethod';
- const getRelatedClass = 'fORM::getRelatedClass';
- const isClassMappedToTable = 'fORM::isClassMappedToTable';
- const mapClassToDatabase = 'fORM::mapClassToDatabase';
- const mapClassToTable = 'fORM::mapClassToTable';
- const objectify = 'fORM::objectify';
- const overrideColumnName = 'fORM::overrideColumnName';
- const overrideRecordName = 'fORM::overrideRecordName';
- const parseMethod = 'fORM::parseMethod';
- const registerActiveRecordMethod = 'fORM::registerActiveRecordMethod';
- const registerHookCallback = 'fORM::registerHookCallback';
- const registerInspectCallback = 'fORM::registerInspectCallback';
- const registerObjectifyCallback = 'fORM::registerObjectifyCallback';
- const registerRecordSetMethod = 'fORM::registerRecordSetMethod';
- const registerReflectCallback = 'fORM::registerReflectCallback';
- const registerReplicateCallback = 'fORM::registerReplicateCallback';
- const registerScalarizeCallback = 'fORM::registerScalarizeCallback';
- const replicate = 'fORM::replicate';
- const reset = 'fORM::reset';
- const scalarize = 'fORM::scalarize';
- const tablize = 'fORM::tablize';
+ const callHookCallbacks = 'fORM::callHookCallbacks';
+ const callInspectCallbacks = 'fORM::callInspectCallbacks';
+ const callReflectCallbacks = 'fORM::callReflectCallbacks';
+ const checkHookCallback = 'fORM::checkHookCallback';
+ const classize = 'fORM::classize';
+ const defineActiveRecordClass = 'fORM::defineActiveRecordClass';
+ const enableSchemaCaching = 'fORM::enableSchemaCaching';
+ const getActiveRecordMethod = 'fORM::getActiveRecordMethod';
+ const getClass = 'fORM::getClass';
+ const getColumnName = 'fORM::getColumnName';
+ const getDatabaseName = 'fORM::getDatabaseName';
+ const getRecordName = 'fORM::getRecordName';
+ const getRecordSetMethod = 'fORM::getRecordSetMethod';
+ const getRelatedClass = 'fORM::getRelatedClass';
+ const isClassMappedToTable = 'fORM::isClassMappedToTable';
+ const mapClassToDatabase = 'fORM::mapClassToDatabase';
+ const mapClassToTable = 'fORM::mapClassToTable';
+ const objectify = 'fORM::objectify';
+ const overrideColumnName = 'fORM::overrideColumnName';
+ const overrideRecordName = 'fORM::overrideRecordName';
+ const parseMethod = 'fORM::parseMethod';
+ const registerActiveRecordMethod = 'fORM::registerActiveRecordMethod';
+ const registerActiveRecordStaticMethod = 'fORM::registerActiveRecordStaticMethod';
+ const registerHookCallback = 'fORM::registerHookCallback';
+ const registerInspectCallback = 'fORM::registerInspectCallback';
+ const registerObjectifyCallback = 'fORM::registerObjectifyCallback';
+ const registerRecordSetMethod = 'fORM::registerRecordSetMethod';
+ const registerReflectCallback = 'fORM::registerReflectCallback';
+ const registerReplicateCallback = 'fORM::registerReplicateCallback';
+ const registerScalarizeCallback = 'fORM::registerScalarizeCallback';
+ const replicate = 'fORM::replicate';
+ const reset = 'fORM::reset';
+ const scalarize = 'fORM::scalarize';
+ const tablize = 'form::tablize';
/**
@@ -83,7 +86,14 @@ class fORM
* @var array
*/
static private $active_record_method_callbacks = array();
-
+
+ /**
+ * An array of `{static_method} => {callback}` mappings for fActiveRecord
+ *
+ * @var array
+ */
+ static private $active_record_static_method_callbacks = array();
+
/**
* Cache for repetitive computation
*
@@ -468,8 +478,53 @@ static public function getActiveRecordMethod($class, $method)
self::$cache['getActiveRecordMethod'][$class . '::' . $method] = ($callback === NULL) ? FALSE : $callback;
return $callback;
}
+
+ /**
+ * Returns a matching callback for the class and static method specified
+ *
+ * The callback returned will be determined by the following logic:
+ *
+ * 1. If an exact callback has been defined for the method, it will be returned
+ * 2. If a callback in the form `{prefix}*` has been defined that matches the method, it will be returned
+ * 3. `NULL` will be returned
+ *
+ * @internal
+ *
+ * @param string $class The name of the class
+ * @param string $method The method to get the callback for
+ * @return string|null The callback for the method or `NULL` if none exists - see method description for details
+ */
+ static public function getActiveRecordStaticMethod($class, $method)
+ {
+ // This caches method lookups, providing a significant performance
+ // boost to pages with lots of method calls that get passed to
+ // fActiveRecord::__callStatic()
+ if (isset(self::$cache['getActiveRecordStaticMethod'][$class . '::' . $method])) {
+ return (!$method = self::$cache['getActiveRecordStaticMethod'][$class . '::' . $method]) ? NULL : $method;
+ }
+
+ $callback = NULL;
+
+ if (isset(self::$active_record_static_method_callbacks[$class][$method])) {
+ $callback = self::$active_record_static_method_callbacks[$class][$method];
+
+ } elseif (isset(self::$active_record_static_method_callbacks['*'][$method])) {
+ $callback = self::$active_record_static_method_callbacks['*'][$method];
+
+ } elseif (preg_match('#[A-Z0-9]#', $method)) {
+ list($action, $subject) = self::parseMethod($method);
+ if (isset(self::$active_record_static_method_callbacks[$class][$action . '*'])) {
+ $callback = self::$active_record_static_method_callbacks[$class][$action . '*'];
+ } elseif (isset(self::$active_record_static_method_callbacks['*'][$action . '*'])) {
+ $callback = self::$active_record_static_method_callbacks['*'][$action . '*'];
+ }
+ }
+
+ self::$cache['getActiveRecordStaticMethod'][$class . '::' . $method] = ($callback === NULL) ? FALSE : $callback;
+ return $callback;
+ }
-
+
/**
* Takes a class name or class and returns the class name
*
@@ -839,6 +894,48 @@ static public function registerActiveRecordMethod($class, $method, $callback)
self::$cache['getActiveRecordMethod'] = array();
}
+
+ /**
+ * Registers a callback for an fActiveRecord method that falls through to fActiveRecord::__callStatic() or hits a predefined method hook
+ *
+ * Only available to PHP 5.3+ which supports the __callStatic magic method.
+ *
+ * The callback should accept the following parameters:
+ *
+ * - **`&$class`**: The class calling the static method
+ * - **`$method_name`**: The method that was called
+ * - **`&$parameters`**: The parameters passed to the method
+ *
+ * @throws fProgrammerException When the PHP version less than 5.3
+ *
+ * @param mixed $class The class name or instance of the class to register for, `'*'` will register for all classes
+ * @param string $method The method to hook for - this can be a complete method name or `{prefix}*` where `*` will match any column name
+ * @param callback $callback The callback to execute - see method description for parameter list
+ * @return void
+ */
+ static public function registerActiveRecordStaticMethod($class, $method, $callback)
+ {
+ if (!fCore::checkVersion('5.3')) {
+ throw new fProgrammerException(
+ 'fORM::registerActiveRecordStaticMethod is only available to PHP 5.3+',
+ $method_name
+ );
+ };
+
+ $class = self::getClass($class);
+
+ if (!isset(self::$active_record_static_method_callbacks[$class])) {
+ self::$active_record_static_method_callbacks[$class] = array();
+ }
+
+ if (is_string($callback) && strpos($callback, '::') !== FALSE) {
+ $callback = explode('::', $callback);
+ }
+
+ self::$active_record_static_method_callbacks[$class][$method] = $callback;
+ self::$cache['getActiveRecordStaticMethod'] = array();
+ }
+
/**
* Registers a callback for one of the various fActiveRecord hooks - multiple callbacks can be registered for each hook
View
26 fPagination.php
@@ -18,6 +18,7 @@ class fPagination
// The following constants allow for nice looking callbacks to static methods
const defineTemplate = 'fPagination::defineTemplate';
const extend = 'fPagination::extend';
+ const makeRecordSetLinks = 'fPagination::makeRecordSetLinks';
const printRecordSetInfo = 'fPagination::printRecordSetInfo';
const reset = 'fPagination::reset';
const showRecordSetLinks = 'fPagination::showRecordSetLinks';
@@ -186,6 +187,7 @@ static public function defineTemplate($name, $type, $size, $pieces)
*/
static public function extend()
{
+ fORM::registerRecordSetMethod('makeLinks', self::makeRecordSetLinks);
fORM::registerRecordSetMethod('printInfo', self::printRecordSetInfo);
fORM::registerRecordSetMethod('showLinks', self::showRecordSetLinks);
}
@@ -216,6 +218,26 @@ static private function extendRecordSetInfo($data, $class)
/**
+ * Handles the `makeLinks()` method for fRecordSet
+ *
+ * @internal
+ *
+ * @param fRecordSet $object The record set
+ * @param string|array $class The class(es) contained in the record set
+ * @param array &$records The records
+ * @param string $method_name The method that was called
+ * @param array $parameters The parameters passed to the method
+ * @return string Generated HTML of the links
+ */
+ static public function makeRecordSetLinks($object, $class, &$records, $method_name, $parameters)
+ {
+ fBuffer::startCapture();
+ self::showRecordSetLinks($object, $class, $records, $method_name, $parameters);
+ return fBuffer::stopCapture();
+ }
+
+
+ /**
* Handles the `printInfo()` method for fRecordSet
*
* @internal
@@ -712,4 +734,6 @@ public function showLinks($template='default')
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- */
+ */
+
+// kate: remove-trailing-space false; replace-tabs false; replace-tabs-save false; replace-trailing-space-save false;
View
9 fRequest.php
@@ -17,8 +17,9 @@
* @package Flourish
* @link http://flourishlib.com/fRequest
*
- * @version 1.0.0b20
- * @changes 1.0.0b20 Added ::isHead(), fixed ability to call ::set() on `HEAD` requests [wb-imarc, 2011-11-23]
+ * @version 1.0.0b21
+ * @changes 1.0.0b21 Added ::isHead(), fixed ability to call ::set() on `HEAD` requests [wb-imarc, 2011-11-23]
+ * @changes 1.0.0b20 Fixed problem where Accept headers are spaced out and mime-types won't match (mainly from IE)
* @changes 1.0.0b19 Added the `$use_default_for_blank` parameter to ::get() [wb, 2011-06-03]
* @changes 1.0.0b18 Backwards Compatibility Break - ::getBestAcceptType() and ::getBestAcceptLanguage() now return either `NULL`, `FALSE` or a string instead of `NULL` or a string, both methods are more robust in handling edge cases [wb, 2011-02-06]
* @changes 1.0.0b17 Fixed support for 3+ dimensional input arrays, added a fixed for the PHP DoS float bug #53632, added support for type-casted arrays in ::get() [wb, 2011-01-09]
@@ -774,7 +775,7 @@ static private function processAcceptHeader($header_name)
}
$q .= $suffix--;
- $output[$parts[0]] = $q;
+ $output[trim($parts[0])] = $q;
}
arsort($output, SORT_NUMERIC);
@@ -968,4 +969,4 @@ private function __construct() { }
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- */
+ */
View
17 fTemplating.php
@@ -5,12 +5,14 @@
* @copyright Copyright (c) 2007-2011 Will Bond, others
* @author Will Bond [wb] <will@flourishlib.com>
* @author Matt Nowack [mn] <mdnowack@gmail.com>
+ * @author Jeff Turcotte [jt] <jeff@imarc.net>
* @license http://flourishlib.com/license
*
* @package Flourish
* @link http://flourishlib.com/fTemplating
*
- * @version 1.0.0b23
+ * @version 1.0.0b24
+ * @changes 1.0.0b24 Added getRootPath() to retrieve the path fTemplating was instantiated with [jt, 2012-10-24]
* @changes 1.0.0b23 Added a default `$name` for ::retrieve() to mirror ::attach() [wb, 2011-08-31]
* @changes 1.0.0b22 Backwards Compatibility Break - removed the static method ::create(), added the static method ::attach() to fill its place [wb, 2011-08-31]
* @changes 1.0.0b21 Fixed a bug in ::enableMinification() where the minification cache directory was sometimes not properly converted to a web path [wb, 2011-08-31]
@@ -710,7 +712,16 @@ public function get($element, $default_value=NULL)
return $value;
}
-
+
+ /**
+ * Gets the root path
+ *
+ * @return string The root path for the instance
+ */
+ public function getRootPath()
+ {
+ return $this->root;
+ }
/**
* Combines an array of CSS or JS files and places them as a single file
@@ -1516,4 +1527,4 @@ protected function verifyValue($element, $value, $file_type=NULL)
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- */
+ */
View
65 fValidation.php
@@ -2,14 +2,18 @@
/**
* Provides validation routines for standalone forms, such as contact forms
*
- * @copyright Copyright (c) 2007-2011 Will Bond
+ * @copyright Copyright (c) 2007-2011 Will Bond, others
* @author Will Bond [wb] <will@flourishlib.com>
+ * @author Andrew Udvare [au] <andrew@bne1.com>
+ * @author Kerri Gertz [kg] <kerri@imarc.net>
* @license http://flourishlib.com/license
*
* @package Flourish
* @link http://flourishlib.com/fValidation
*
- * @version 1.0.0b12
+ * @version 1.0.0b14
+ * @changes 1.0.0b14 Added ::setCSRFTokenField() [au, 2012-04-27]
+ * @changes 1.0.0b13 Fixed return bug in ::checkConditionalRules [kg, 2010-06-19]
* @changes 1.0.0b12 Fixed some method signatures [wb, 2011-08-24]
* @changes 1.0.0b11 Fixed ::addCallbackRule() to be able to handle multiple rules per field [wb, 2011-06-02]
* @changes 1.0.0b10 Fixed ::addRegexRule() to be able to handle multiple rules per field [wb, 2010-08-30]
@@ -197,6 +201,20 @@ static protected function stringlike($value)
*/
private $valid_values_rules = array();
+ /**
+ * CSRF token URL
+ *
+ * @var string
+ */
+ private $csrf_url = NULL;
+
+ /**
+ * CSRF token field name
+ *
+ * @var string
+ */
+ private $csrf_field = NULL;
+
/**
* All requests that hit this method should be requests for callbacks
@@ -332,6 +350,24 @@ public function addEmailFields($field)
/**
+ * Set the CSRF token field to validate.
+ *
+ * @param string $field A field that should contain a CSRF token string
+ * @param string $url URL to validate with
+ * @return fValidation The validation object, to allow for method chaining
+ */
+ public function setCSRFTokenField($field, $url = NULL)
+ {
+ if (is_null($url)) {
+ $url = fURL::get();
+ }
+ $this->csrf_url = $url;
+ $this->csrf_field = $field;
+ return $this;
+ }
+
+
+ /**
* Adds form fields to be checked for email injection
*
* Every field that is included in email headers should be passed to this
@@ -672,7 +708,7 @@ private function checkConditionalRules(&$messages)
}
if (!$check_for_missing_values) {
- return;
+ continue;
}
foreach ($rule['conditional_fields'] as $conditional_field) {
@@ -711,6 +747,28 @@ private function checkDateFields(&$messages)
/**
+ * Validates the CSRF field
+ *
+ * @param array &$messages The messages to display to the user
+ * @return void
+ */
+ private function checkCSRFField(&$messages)
+ {
+ try {
+ if ($this->csrf_field === NULL) {
+ return;
+ }
+
+ $token = fRequest::get($this->csrf_field);
+ fRequest::validateCSRFToken($token, $this->csrf_url);
+ }
+ catch (fValidationException $e) {
+ $messages[$this->csrf_field] = $e->getMessage();
+ }
+ }
+
+
+ /**
* Checks the file upload validation rules
*
* @param array &$messages The messages to display to the user
@@ -1019,6 +1077,7 @@ public function validate($return_messages=FALSE, $remove_field_names=FALSE)
$this->checkRequiredFields($messages);
$this->checkFileUploadRules($messages);
$this->checkConditionalRules($messages);
+ $this->checkCSRFField($messages);
$this->checkOneOrMoreRules($messages);
$this->checkOnlyOneRules($messages);
$this->checkValidValuesRules($messages);
Something went wrong with that request. Please try again.