Example #1
0
	/**
	 * Parses a string for PHP functions
	 *
	 * @param string $input
	 * @param array  $vars
	 * @return string
	 */
	static public function formatCondition( $input, $vars = array() )
	{
																// \[cb:parse(?: +function="([^"/\[\] ]+)")( +(?: ?[a-zA-Z-_]+="(?:[^"]|\\")+")+)?(?:(?:\s*/])|(?:]((?:[^\[]|\[(?!/?cb:parse[^\]]*])|(?R))+)?\[/cb:parse]))
		$regex												=	'%\[cb:parse(?: +function="([^"/\[\] ]+)")( +(?: ?[a-zA-Z-_]+="(?:[^"]|\\\\")+")+)?(?:(?:\s*/])|(?:]((?:[^\[]|\[(?!/?cb:parse[^\]]*])|(?R))+)?\[/cb:parse]))%i';

		if ( preg_match_all( $regex, $input, $results, PREG_SET_ORDER ) ) {
			foreach( $results as $matches ) {
				$function									=	( isset( $matches[1] ) ? $matches[1] : null );

				if ( $function ) {
					$value									=	( isset( $matches[3] ) ? self::formatCondition( $matches[3], $vars ) : null );
					$options								=	new Registry();

					if ( isset( $matches[2] ) ) {
						if ( preg_match_all( '/(?:([a-zA-Z-_]+)="((?:[^"]|\\\\\\\\")+)")+/i', $matches[2], $optionResults, PREG_SET_ORDER ) ) {
							foreach( $optionResults as $option ) {
								$k							=	( isset( $option[1] ) ? $option[1] : null );
								$v							=	( isset( $option[2] ) ? $option[2] : null );

								if ( $k ) {
									$options->set( $k, $v );
								}
							}
						}
					}

					$method									=	$options->get( 'method' );

					$options->unsetEntry( 'method' );

					switch ( $function ) {
						case 'clean':
							switch( $method ) {
								case 'cmd':
									$input					=	str_replace( $matches[0], Get::clean( $value, GetterInterface::COMMAND ), $input );
									break;
								case 'numeric':
									$input					=	str_replace( $matches[0], Get::clean( $value, GetterInterface::NUMERIC ), $input );
									break;
								case 'unit':
									$input					=	str_replace( $matches[0], Get::clean( $value, GetterInterface::UINT ), $input );
									break;
								case 'int':
								case 'integer':
									$input					=	str_replace( $matches[0], Get::clean( $value, GetterInterface::INT ), $input );
									break;
								case 'bool':
								case 'boolean':
									$input					=	str_replace( $matches[0], Get::clean( $value, GetterInterface::BOOLEAN ), $input );
									break;
								case 'str':
								case 'string':
									$input					=	str_replace( $matches[0], Get::clean( $value, GetterInterface::STRING ), $input );
									break;
								case 'html':
									$input					=	str_replace( $matches[0], Get::clean( $value, GetterInterface::HTML ), $input );
									break;
								case 'float':
									$input					=	str_replace( $matches[0], Get::clean( $value, GetterInterface::FLOAT ), $input );
									break;
								case 'base64':
									$input					=	str_replace( $matches[0], Get::clean( $value, GetterInterface::BASE64 ), $input );
									break;
								case 'tags':
									$input					=	str_replace( $matches[0], strip_tags( $value ), $input );
									break;
							}
							break;
						case 'convert':
							switch( $method ) {
								case 'uppercase':
									$input					=	str_replace( $matches[0], strtoupper( $value ), $input );
									break;
								case 'uppercasewords':
									$input					=	str_replace( $matches[0], ucwords( $value ), $input );
									break;
								case 'uppercasefirst':
									$input					=	str_replace( $matches[0], ucfirst( $value ), $input );
									break;
								case 'lowercase':
									$input					=	str_replace( $matches[0], strtolower( $value ), $input );
									break;
								case 'lowercasefirst':
									$input					=	str_replace( $matches[0], lcfirst( $value ), $input );
									break;
							}
							break;
						case 'math':
							$input							=	str_replace( $matches[0], self::formatMath( $value ), $input );
							break;
						case 'time':
							$input							=	str_replace( $matches[0], ( $options->has( 'time' ) ? strtotime( $options->get( 'time', null, GetterInterface::STRING ), ( is_numeric( $value ) ? (int) $value : strtotime( $value ) ) ) : strtotime( $value ) ), $input );
							break;
						case 'date':
							$offset							=	$options->get( 'offset' );
							$input							=	str_replace( $matches[0], cbFormatDate( ( is_numeric( $value ) ? (int) $value : strtotime( $value ) ), ( $offset ? true : false ), true, $options->get( 'date-format' ), $options->get( 'time-format' ), ( $offset != 'true' ? $offset : null ) ), $input );
							break;
						case 'length':
							$input							=	str_replace( $matches[0], strlen( $value ), $input );
							break;
						case 'replace':
							$input							=	str_replace( $matches[0], ( $options->has( 'count' ) ? str_replace( $options->get( 'search' ), $options->get( 'replace' ), $value, $options->get( 'count', 0, GetterInterface::INT ) ) : str_replace( $options->get( 'search' ), $options->get( 'replace' ), $value ) ), $input );
							break;
						case 'position':
							switch( $options->get( 'occurrence' ) ) {
								case 'last':
									$input					=	str_replace( $matches[0], strrpos( $value, $options->get( 'search' ) ), $input );
									break;
								case 'first':
								default:
									$input					=	str_replace( $matches[0], strpos( $value, $options->get( 'search' ) ), $input );
									break;
							}
							break;
						case 'occurrence':
							$input							=	str_replace( $matches[0], strstr( $value, $options->get( 'search' ) ), $input );
							break;
						case 'repeat':
							$input							=	str_replace( $matches[0], str_repeat( $value, $options->get( 'count', 0, GetterInterface::INT ) ), $input );
							break;
						case 'extract':
							$input							=	str_replace( $matches[0], ( $options->has( 'length' ) ? substr( $value, $options->get( 'start', 0, GetterInterface::INT ), $options->get( 'length', 0, GetterInterface::INT ) ) : substr( $value, $options->get( 'start', 0, GetterInterface::INT ) ) ), $input );
							break;
						case 'trim':
							switch( $options->get( 'direction' ) ) {
								case 'left':
									$input					=	str_replace( $matches[0], ( $options->has( 'characters' ) ? ltrim( $value, $options->get( 'characters', null, GetterInterface::STRING ) ) : ltrim( $value ) ), $input );
									break;
								case 'right':
									$input					=	str_replace( $matches[0], ( $options->has( 'characters' ) ? rtrim( $value, $options->get( 'characters', null, GetterInterface::STRING ) ) : rtrim( $value ) ), $input );
									break;
								default:
									$input					=	str_replace( $matches[0], ( $options->has( 'characters' ) ? trim( $value, $options->get( 'characters', null, GetterInterface::STRING ) ) : trim( $value ) ), $input );
									break;
							}
							break;
						case 'encode':
							switch( $method ) {
								case 'cslashes':
									$input					=	str_replace( $matches[0], addcslashes( $value, $options->get( 'characters', null, GetterInterface::STRING ) ), $input );
									break;
								case 'slashes':
									$input					=	str_replace( $matches[0], addslashes( $value ), $input );
									break;
								case 'entity':
									$input					=	str_replace( $matches[0], htmlentities( $value ), $input );
									break;
								case 'html':
									$input					=	str_replace( $matches[0], htmlspecialchars( $value ), $input );
									break;
								case 'url':
									$input					=	str_replace( $matches[0], urlencode( $value ), $input );
									break;
								case 'base64':
									$input					=	str_replace( $matches[0], base64_encode( $value ), $input );
									break;
								case 'md5':
									$input					=	str_replace( $matches[0], md5( $value ), $input );
									break;
								case 'sha1':
									$input					=	str_replace( $matches[0], sha1( $value ), $input );
									break;
								case 'password':
									$user					=	new UserTable();

									$input					=	str_replace( $matches[0], $user->hashAndSaltPassword( $value ), $input );
									break;
							}
							break;
						case 'decode':
							switch( $method ) {
								case 'cslashes':
									$input					=	str_replace( $matches[0], stripcslashes( $value ), $input );
									break;
								case 'slashes':
									$input					=	str_replace( $matches[0], stripslashes( $value ), $input );
									break;
								case 'entity':
									$input					=	str_replace( $matches[0], html_entity_decode( $value ), $input );
									break;
								case 'html':
									$input					=	str_replace( $matches[0], htmlspecialchars_decode( $value ), $input );
									break;
								case 'url':
									$input					=	str_replace( $matches[0], urldecode( $value ), $input );
									break;
								case 'base64':
									$input					=	str_replace( $matches[0], base64_encode( $value ), $input );
									break;
							}
							break;
						default:
							if ( ! $function ) {
								continue;
							}

							$class							=	$options->get( 'class', null, GetterInterface::STRING );
							$subFunction					=	null;
							$static							=	false;
							$result							=	null;

							if ( strpos( $function, '::' ) !== false ) {
								list( $class, $function )	=	explode( '::', $function, 2 );

								$static						=	true;
							} elseif ( strpos( $class, '::' ) !== false ) {
								$subFunction				=	$function;

								list( $class, $function )	=	explode( '::', $class, 2 );

								$static						=	true;
							}

							if ( $class ) {
								$object						=	null;

								$options->unsetEntry( 'class' );

								if ( isset( $vars[$class] ) && is_object( $vars[$class] ) ) {
									$object					=	$vars[$class];
									$class					=	get_class( $object );
								}

								if ( $static ) {
									if ( $subFunction ) {
										if ( is_callable( array( $class, $function ) ) ) {
											$object			=	call_user_func_array( array( $class, $function ), array() );

											if ( method_exists( $object, $subFunction ) ) {
												$result		=	call_user_func_array( array( $object, $subFunction ), $options->asArray() );
											}
										}
									} else {
										if ( is_callable( array( $class, $function ) ) ) {
											$result			=	call_user_func_array( array( $class, $function ), $options->asArray() );
										}
									}
								} else {
									if ( $object || class_exists( $class ) ) {
										if ( ! $object ) {
											$object			=	new $class();

											if ( $value && method_exists( $object, 'load' ) ) {
												$object->load( $value );
											}
										}

										if ( method_exists( $object, $function ) ) {
											$result			=	call_user_func_array( array( $object, $function ), $options->asArray() );
										}
									}
								}
							} else {
								if ( function_exists( $function ) ) {
									$result					=	call_user_func_array( $function, $options->asArray() );
								}
							}

							if ( $method && is_object( $result ) && method_exists( $result, $method ) ) {
								$result						=	call_user_func_array( array( $result, $method ), $options->asArray() );
							}

							if ( ( ! is_array( $result ) ) && ( ! is_object( $result ) ) ) {
								$input						=	str_replace( $matches[0], $result, $input );
							}
							break;
					}

					// If no replacement is done above then the string still exists; lets just replace the substitution with the found value:
					$input									=	str_replace( $matches[0], $value, $input );
				}
			}

			$input											=	self::formatCondition( $input, $vars );
		}

		return $input;
	}
Example #2
0
 /**
  * loads a plugins params into memory
  *
  * @param null|int              $pluginId
  * @param null|Registry|string  $extraParams
  */
 public function _loadParams($pluginId, $extraParams = null)
 {
     if ($pluginId === null) {
         $pluginId = $this->getPluginId();
     } else {
         $pluginId = (int) $pluginId;
     }
     $plugin = $this->getPluginObject($pluginId);
     if ($plugin === null) {
         return;
     }
     $paramsBase = $this->_getPluginParamsFromTable($plugin);
     if ($extraParams) {
         if (!$extraParams instanceof Registry) {
             /** @noinspection PhpDeprecationInspection */
             if ($extraParams instanceof cbParamsBase) {
                 /** @noinspection PhpDeprecationInspection */
                 $extraParams = new Registry($extraParams->toParamsArray());
             } else {
                 $extraParams = new Registry($extraParams);
             }
         }
         $extraArray = $extraParams->asArray();
         foreach ($extraArray as $k => $v) {
             $paramsBase->set($k, $v);
         }
     }
     $this->params = $paramsBase;
 }
Example #3
0
	/**
	 * Returns an array of all current params
	 *
	 * @return array
	 */
	public function asArray()
	{
		$params					=	parent::asArray();

		$params['source']		=	$this->source;
		$params['user']			=	(int) $this->user->get( 'id' );

		return $params;
	}