コード例 #1
0
/**
 * Main zTag functions selector
 *
 * <code>
 * zmemcached_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder);
 * </code>
 *
 * @param integer $tagId array id of current zTag of $arrayTag array
 * @param string $tagFunction name of zTag function
 * @param array $arrayTag array with all compiled zTags
 * @param array $arrayTagId array with all Ids values
 * @param array $arrayOrder array with zTag executing order
 *
 * @since 1.0
 */
function zmemcached_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder)
{
    $arrParam = $arrayTag[$tagId][ztagParam];
    $strId = $arrParam["id"];
    $strHost = $arrParam["host"];
    $strPort = $arrParam["port"];
    $strUse = $arrParam["use"];
    $strVar = $arrParam["var"];
    $strKey = $arrParam["key"];
    $strCompress = $arrParam["compress"];
    $strExpire = $arrParam["expire"];
    $strTimeout = $arrParam["timeout"];
    $strValue = $arrParam["value"];
    if ($arrayTag[$tagId][ztagContentWidth]) {
        $strContent = $arrayTag[$tagId][ztagContent];
    }
    $errorMessage = "";
    switch (strtolower($tagFunction)) {
        /*+
         * Open memcached server connection
         *
         * <code>
         * <zmemcached:open id="memCached" host="localhost" port="11211" timeout="1" />
         * </code>
         *
         * @param string id="menCached" Id of an open connection
         * @param string host="localhost" Point to the host where memcached is listening for connections
         * @param int port="11211" Point to the port where memcached is listening for connections
         * @param int timeout="1" Value in seconds which will be used for connecting to the daemon
         */
        case "open":
            $errorMessage .= ztagParamCheck($arrParam, "id,host,port");
            if (extension_loaded('memcache')) {
                $mcObject = new Memcache();
                if (strlen($strTimeout)) {
                    $mcObject->connect($strHost, $strPort, $strTimeout);
                } else {
                    $mcObject->connect($strHost, $strPort);
                }
                if ($mcObject) {
                    $mcHandle[memcachedHandleHost] = $strHost;
                    $mcHandle[memcachedHandlePort] = $strPort;
                    $mcHandle[memcachedHandleTimeout] = $strTimeout;
                    $mcHandle[memcachedHandleId] = $mcObject;
                    $mcHandle[memcachedHandleState] = dbHandleStateOpen;
                    $arrayTagId[$strId][ztagIdHandle] = $mcHandle;
                    $arrayTagId[$strId][ztagIdType] = idTypeMemCached;
                    $arrayTagId[$strId][ztagIdState] = idStateOpened;
                } else {
                    $errorMessage .= "<br />Could not connect to memcached server {$strHost}:{$strPort}!";
                }
            } else {
                $errorMessage .= "<br />The MemCache extension is not loaded!";
            }
            break;
            /*+
             * Close memcached server connection
             *
             * <code>
             * <zmemcached:close use="memCached" />
             * </code>
             *
             * @param string use="memCached" Id of a open connection
             */
        /*+
         * Close memcached server connection
         *
         * <code>
         * <zmemcached:close use="memCached" />
         * </code>
         *
         * @param string use="memCached" Id of a open connection
         */
        case "close":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $mcObject = $mcHandle[memcachedHandleId];
                    $mcObject->close();
                    $mcHandle[memcachedHandleId] = $mcObject;
                    $arrayTagId[$strUse][ztagIdHandle] = $mcHandle;
                    $arrayTagId[$strUse][ztagIdState] = idStateClosed;
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Add a memcached server to connection pool
             *
             * <code>
             * <zmemcached:addserver use="memCached"host="localhost" port="11211" timeout="1" persistent="true|false|0|1" weight="10" retryinterval="10" status="true|false|0|1" />
             * </code>
             *
             * @param string id="menCached" Id of an open connection
             * @param string host="localhost" Point to the host where memcached is listening for connections
             * @param int port="11211" Point to the port where memcached is listening for connections
             * @param int timeout="1" Value in seconds which will be used for connecting to the daemon. Think twice before changing the default value of 1 second - you can lose all the advantages of caching if your connection is too slow.
             * @param boolean persistent="true|false|0|1" Controls the use of a persistent connection. Default to TRUE.
             * @param int weight="10" Number of buckets to create for this server which in turn control its probability of it being selected. The probability is relative to the total weight of all servers.
             * @param int retryinterval="10" Controls how often a failed server will be retried, the default value is 15 seconds. Setting this parameter to -1 disables automatic retry.
             * @param boolean status="true|false|0|1" Controls if the server should be flagged as online.
             */
        /*+
         * Add a memcached server to connection pool
         *
         * <code>
         * <zmemcached:addserver use="memCached"host="localhost" port="11211" timeout="1" persistent="true|false|0|1" weight="10" retryinterval="10" status="true|false|0|1" />
         * </code>
         *
         * @param string id="menCached" Id of an open connection
         * @param string host="localhost" Point to the host where memcached is listening for connections
         * @param int port="11211" Point to the port where memcached is listening for connections
         * @param int timeout="1" Value in seconds which will be used for connecting to the daemon. Think twice before changing the default value of 1 second - you can lose all the advantages of caching if your connection is too slow.
         * @param boolean persistent="true|false|0|1" Controls the use of a persistent connection. Default to TRUE.
         * @param int weight="10" Number of buckets to create for this server which in turn control its probability of it being selected. The probability is relative to the total weight of all servers.
         * @param int retryinterval="10" Controls how often a failed server will be retried, the default value is 15 seconds. Setting this parameter to -1 disables automatic retry.
         * @param boolean status="true|false|0|1" Controls if the server should be flagged as online.
         */
        case "addserver":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $mcObject = $mcHandle[memcachedHandleId];
                    $mcObject->addserver($strHost, $strPort);
                    $mcHandle[memcachedHandleId] = $mcObject;
                    $arrayTagId[$strUse][ztagIdHandle] = $mcHandle;
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Get Server status
             *
             * <code>
             * <zmemcached:getserverstatus use="memCached" host="localhost" port="11211" var="memcachedStatus" />
             * </code>
             *
             * @param string host="localhost" Point to the host where memcached is listening for connections
             * @param int port="11211" Point to the port where memcached is listening for connections
             */
        /*+
         * Get Server status
         *
         * <code>
         * <zmemcached:getserverstatus use="memCached" host="localhost" port="11211" var="memcachedStatus" />
         * </code>
         *
         * @param string host="localhost" Point to the host where memcached is listening for connections
         * @param int port="11211" Point to the port where memcached is listening for connections
         */
        case "getserverstatus":
            $errorMessage .= ztagParamCheck($arrParam, "use,host,port,var");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $statusValue = $mcObject->getServerStatus($strHost, $strPort);
                    if ($statusValue) {
                        $arrayTagId["\$" . $strVar][ztagIdValue] = $statusValue;
                        $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
                    }
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Get Server version
             *
             * <code>
             * <zmemcached:getversion use="memCached" var="versionVar" />
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             * @param string var="versionVar" Variable where data will be set
             */
        /*+
         * Get Server version
         *
         * <code>
         * <zmemcached:getversion use="memCached" var="versionVar" />
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         * @param string var="versionVar" Variable where data will be set
         */
        case "getversion":
            $errorMessage .= ztagParamCheck($arrParam, "use,var");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $mcObject = $mcHandle[memcachedHandleId];
                    $versionValue = $mcObject->getVersion();
                    if ($versionValue) {
                        $arrayTagId["\$" . $strVar][ztagIdValue] = $versionValue;
                        $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
                    } else {
                        $errorMessage .= "<br />I cannot get the server version from Id {$strId} of host {$strHost}:{$strPort}!";
                    }
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Close memcached server connection
             *
             * Stats array
             * pid - Process id of this server process
             * uptime - Number of seconds this server has been running
             * time - Current UNIX time according to the server
             * version - Version string of this server
             * rusage_user - Accumulated user time for this process
             * rusage_system - Accumulated system time for this process
             * curr_items - Current number of items stored by the server
             * total_items - Total number of items stored by this server ever since it started
             * bytes - Current number of bytes used by this server to store items
             * curr_connections - Number of open connections
             * total_connections - Total number of connections opened since the server started running
             * connection_structures - Number of connection structures allocated by the server
             * cmd_get - Cumulative number of retrieval requests
             * cmd_set - Cumulative number of storage requests
             * get_hits - Number of keys that have been requested and found present
             * get_misses - Number of items that have been requested and not found
             * bytes_read - Total number of bytes read by this server from network
             * bytes_written - Total number of bytes sent by this server to network
             * limit_maxbytes - Number of bytes this server is allowed to use for storage.
             *
             * <code>
             * <zmemcached:getstats use="memCached" var="statsVar" type="reset" slabid="" limit="" />
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             * @param string type="reset" The type of statistics to fetch. Valid values are {reset, malloc, maps, cachedump, slabs, items, sizes}
             * @param string slabid="" Used in conjunction with type set to cachedump to identify the slab to dump from
             * @param int limit="" Used in conjunction with type set to cachedump to limit the number of entries to dump.
             */
        /*+
         * Close memcached server connection
         *
         * Stats array
         * pid - Process id of this server process
         * uptime - Number of seconds this server has been running
         * time - Current UNIX time according to the server
         * version - Version string of this server
         * rusage_user - Accumulated user time for this process
         * rusage_system - Accumulated system time for this process
         * curr_items - Current number of items stored by the server
         * total_items - Total number of items stored by this server ever since it started
         * bytes - Current number of bytes used by this server to store items
         * curr_connections - Number of open connections
         * total_connections - Total number of connections opened since the server started running
         * connection_structures - Number of connection structures allocated by the server
         * cmd_get - Cumulative number of retrieval requests
         * cmd_set - Cumulative number of storage requests
         * get_hits - Number of keys that have been requested and found present
         * get_misses - Number of items that have been requested and not found
         * bytes_read - Total number of bytes read by this server from network
         * bytes_written - Total number of bytes sent by this server to network
         * limit_maxbytes - Number of bytes this server is allowed to use for storage.
         *
         * <code>
         * <zmemcached:getstats use="memCached" var="statsVar" type="reset" slabid="" limit="" />
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         * @param string type="reset" The type of statistics to fetch. Valid values are {reset, malloc, maps, cachedump, slabs, items, sizes}
         * @param string slabid="" Used in conjunction with type set to cachedump to identify the slab to dump from
         * @param int limit="" Used in conjunction with type set to cachedump to limit the number of entries to dump.
         */
        case "getstats":
            $strType = $arrParam["type"];
            $strSlabId = $arrParam["slabid"];
            $strLimit = $arrParam["limit"];
            $errorMessage .= ztagParamCheck($arrParam, "use,var");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $mcObject = $mcHandle[memcachedHandleId];
                    if (strlen($strType) && !strlen($strSlabId)) {
                        $statsValue = $mcObject->getStats($strType);
                    } elseif (strlen($strType) && strlen($strSlabId) && !strlen($strLimit)) {
                        $statsValue = $mcObject->getStats($strType, $strSlabId);
                    } elseif (strlen($strType) && strlen($strSlabId) && strlen($strLimit)) {
                        $statsValue = $mcObject->getStats($strType, $strSlabId, $strLimit);
                    } else {
                        $statsValue = $mcObject->getStats();
                    }
                    if ($statsValue) {
                        $arrayTagId["\$" . $strVar][ztagIdValue] = $statsValue;
                        $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
                    } else {
                        $errorMessage .= "<br />I cannot get stats from Id {$strId} of host {$strHost}:{$strPort}!";
                    }
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Get Server extended status
             *
             * <code>
             * <zmemcached:getextendedstats host="localhost" port="11211" var="memcachedStatus" />
             * </code>
             *
             * @param string host="localhost" Point to the host where memcached is listening for connections
             * @param int port="11211" Point to the port where memcached is listening for connections
             * @param string var="memcachedStatus"
             */
        /*+
         * Get Server extended status
         *
         * <code>
         * <zmemcached:getextendedstats host="localhost" port="11211" var="memcachedStatus" />
         * </code>
         *
         * @param string host="localhost" Point to the host where memcached is listening for connections
         * @param int port="11211" Point to the port where memcached is listening for connections
         * @param string var="memcachedStatus"
         */
        case "getextendedstats":
            $memcache_obj->getExtendedStats();
            /*
             pid: Process id of this server process
             uptime: Number of seconds this server has been running
             time: Current UNIX time according to the server
             version: Version string of this server
             rusage_user: Accumulated user time for this process
             rusage_system: Accumulated system time for this process
             curr_items: Current number of items stored by the server
             total_items: Total number of items stored by this server ever since it started
             bytes: Current number of bytes used by this server to store items
             curr_connections: Number of open connections
             total_connections: Total number of connections opened since the server started running
             connection_structures: Number of connection structures allocated by the server
             cmd_get: Cumulative number of retrieval requests
             cmd_set: Cumulative number of storage requests
             get_hits: Number of keys that have been requested and found present
             get_misses: Number of items that have been requested and not found
             bytes_read: Total number of bytes read by this server from network
             bytes_written: Total number of bytes sent by this server to network
             limit_maxbytes: Number of bytes this server is allowed to use for storage.
            */
            break;
            /*+
             * Return a hash of your key
             *
             * <code>
             * <zmemcached:key key="My key value" var="versionVar" type="md5|base64" />
             * </code>
             *
             * @param string key="My key value"
             * @param string var="versionVar" Variable where data will be set
             * @param string type="md5|base64" Type of your key
             */
        /*+
         * Return a hash of your key
         *
         * <code>
         * <zmemcached:key key="My key value" var="versionVar" type="md5|base64" />
         * </code>
         *
         * @param string key="My key value"
         * @param string var="versionVar" Variable where data will be set
         * @param string type="md5|base64" Type of your key
         */
        case "key":
            $strType = $arrParam["type"];
            $errorMessage .= ztagParamCheck($arrParam, "key,var");
            switch ($strType) {
                case "md5":
                    $keyValue = md5($strKey);
                    break;
                default:
                    $keyValue = base64_encode($strKey);
            }
            $arrayTagId["\$" . $strVar][ztagIdValue] = $keyValue;
            $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
            break;
            /*+
             * Store data at the server
             *
             * <code>
             * <zmemcached:set use="memCached" key="unique Id for this" value="statsVar" compress="1" expire="0" />
             *
             * <zmemcached:set use="memCached" key="" compress="" expire="">
             *   Value to be Cached
             * </zmemcached:set>
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             * @param string key="unique Id for this" The key that will be associated with the item.
             * @param string value="$valueVar" The variable to store. Strings and integers are stored as is, other types are stored serialized.
             * @param string compress="true|false|1|0" Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
             * @param int expire="0" Expiration time of the item. If it's equal to zero, the item will never expire.
             */
        /*+
         * Store data at the server
         *
         * <code>
         * <zmemcached:set use="memCached" key="unique Id for this" value="statsVar" compress="1" expire="0" />
         *
         * <zmemcached:set use="memCached" key="" compress="" expire="">
         *   Value to be Cached
         * </zmemcached:set>
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         * @param string key="unique Id for this" The key that will be associated with the item.
         * @param string value="$valueVar" The variable to store. Strings and integers are stored as is, other types are stored serialized.
         * @param string compress="true|false|1|0" Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
         * @param int expire="0" Expiration time of the item. If it's equal to zero, the item will never expire.
         */
        case "set":
            if (strlen($strContent)) {
                $strValue = $strContent;
                $arrParam["value"] = $strValue;
            }
            $errorMessage .= ztagParamCheck($arrParam, "use,key,value");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    // $resultset = serialize($resultset);
                    if (strlen($strKey) && strlen($strValue) && !strlen($strCompress)) {
                        $setValue = $mcObject->set($strKey, $strValue);
                    } elseif (strlen($strKey) && strlen($strValue) && strlen($strCompress) && !strlen($strExpire)) {
                        if ($strCompress === "true" || $strCompress === 1) {
                            $strCompress = MEMCACHE_COMPRESSED;
                        }
                        $setValue = $mcObject->set($strKey, $strValue, $strCompress);
                    } elseif (strlen($strKey) && strlen($strValue) && strlen($strCompress) && strlen($strExpire)) {
                        $setValue = $mcObject->set($strKey, $strValue, $strCompress, $strExpire);
                    }
                    if (!$setValue) {
                        $errorMessage .= "<br />I cannot set data lenght (" . strlen($strValue) . ") with Key \"{$strKey}\" from to {$strHost}:{$strPort}!";
                    }
                } else {
                    $errorMessage .= "<br />The id {$strUse} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strUse} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Retrieve item from the server
             *
             * <code>
             * <zmemcached:get use="memCached" key="unique Id for this" var="getVar" flags="" />
             *
             * <zmemcached:get use="memCached" var="getVar" flags="">
             *  keys{"Key one"
             *  , "Key two"
             *  , 'Another key'
             *  , 99}
             * </zmemcached:get>
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             * @param string key="unique Id for this" The key that will be associated with the item.
             * @param string var="$getVar" Variable where the data will be return
             * @param string flags="" Where the flag values that was written at Set
             */
        /*+
         * Retrieve item from the server
         *
         * <code>
         * <zmemcached:get use="memCached" key="unique Id for this" var="getVar" flags="" />
         *
         * <zmemcached:get use="memCached" var="getVar" flags="">
         *  keys{"Key one"
         *  , "Key two"
         *  , 'Another key'
         *  , 99}
         * </zmemcached:get>
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         * @param string key="unique Id for this" The key that will be associated with the item.
         * @param string var="$getVar" Variable where the data will be return
         * @param string flags="" Where the flag values that was written at Set
         */
        case "get":
            if (strlen($strContent)) {
                $strKey = $strContent;
            }
            if (strlen($strKey)) {
                $strKey = ztagVars($strKey, $arrayTagId);
            }
            $arrParam["key"] = $strKey;
            $errorMessage .= ztagParamCheck($arrParam, "use,key,var");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    if (strlen($strKey) && !strlen($strFlag)) {
                        $getValue = $mcObject->get($strKey);
                    } elseif (strlen($strKey) && strlen($strFlag)) {
                        $getValue = $mcObject->get($strKey, $strFlag);
                    }
                    if (strlen($strVar) && strlen($getValue)) {
                        $arrayTagId["\$" . $strVar][ztagIdValue] = $getValue;
                        $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
                    } else {
                        $arrayTagId["\$" . $strVar] = array();
                    }
                } else {
                    $errorMessage .= "<br />The id {$strUse} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strUse} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Retrieve item from the server
             *
             * <code>
             * <zmemcached:add use="memCached" key="unique Id for this" var="getVar" flags="" />
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             * @param string key="unique Id for this" The key that will be associated with the item.
             * @param string var="$getVar" Variable where the data will be return
             * @param string flags="" Where the flag values that was written at Set
             */
        /*+
         * Retrieve item from the server
         *
         * <code>
         * <zmemcached:add use="memCached" key="unique Id for this" var="getVar" flags="" />
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         * @param string key="unique Id for this" The key that will be associated with the item.
         * @param string var="$getVar" Variable where the data will be return
         * @param string flags="" Where the flag values that was written at Set
         */
        case "add":
            if (strlen($strContent)) {
                $strValue = $strContent;
            }
            if (strlen($strValue)) {
                $strValue = ztagVars($strValue, $arrayTagId);
            }
            $arrParam["value"] = $strValue;
            $errorMessage .= ztagParamCheck($arrParam, "use,key,value");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    // $resultset = serialize($resultset);
                    if (strlen($strKey) && strlen($strValue) && !strlen($strFlag)) {
                        $addValue = $mcObject->add($strKey, $strValue);
                    } elseif (strlen($strKey) && strlen($strValue) && strlen($strFlag) && !strlen($strExpire)) {
                        if ($strFlag === "true" || $strFlag === 1) {
                            $strFlag = MEMCACHE_COMPRESSED;
                        }
                        $addValue = $mcObject->add($strKey, $strValue, $strFlag);
                    } elseif (strlen($strKey) && strlen($strValue) && strlen($strFlag) && strlen($strExpire)) {
                        $addValue = $mcObject->add($strKey, $strValue, $strFlag, $strExpire);
                    }
                    if (!$addValue) {
                        $errorMessage .= "<br />I cannot add data to Id {$strId} of host {$strHost}:{$strPort}!";
                    }
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Replace value of the existing item
             *
             * <code>
             * <zmemcached:replace use="memCached" key="unique Id for this" value="statsVar" compress="1" expire="0" />
             *
             * <zmemcached:replace use="memCached" key="" compress="1" expire="">
             *   Value to be replaced
             * </zmemcached:replace>
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             * @param string key="unique Id for this" The key that will be associated with the item.
             * @param string value="$valueVar" The variable to store. Strings and integers are stored as is, other types are stored serialized.
             * @param string compress="true|false|1|0" Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
             * @param int expire="0" Expiration time of the item. If it's equal to zero, the item will never expire.
             */
        /*+
         * Replace value of the existing item
         *
         * <code>
         * <zmemcached:replace use="memCached" key="unique Id for this" value="statsVar" compress="1" expire="0" />
         *
         * <zmemcached:replace use="memCached" key="" compress="1" expire="">
         *   Value to be replaced
         * </zmemcached:replace>
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         * @param string key="unique Id for this" The key that will be associated with the item.
         * @param string value="$valueVar" The variable to store. Strings and integers are stored as is, other types are stored serialized.
         * @param string compress="true|false|1|0" Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).
         * @param int expire="0" Expiration time of the item. If it's equal to zero, the item will never expire.
         */
        case "replace":
            if (strlen($strContent)) {
                $strValue = $strContent;
            }
            if (strlen($strValue)) {
                $strValue = ztagVars($strValue, $arrayTagId);
            }
            $arrParam["value"] = $strValue;
            $errorMessage .= ztagParamCheck($arrParam, "use,key,value");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    // $resultset = serialize($resultset);
                    if (strlen($strKey) && strlen($strValue) && !strlen($strFlag)) {
                        $setValue = $mcObject->replace($strKey, $strValue);
                    } elseif (strlen($strKey) && strlen($strValue) && strlen($strFlag) && !strlen($strExpire)) {
                        if ($strFlag === "true" || $strFlag === 1) {
                            $strFlag = MEMCACHE_COMPRESSED;
                        }
                        $setValue = $mcObject->replace($strKey, $strValue, $strFlag);
                    } elseif (strlen($strKey) && strlen($strValue) && strlen($strFlag) && strlen($strExpire)) {
                        $setValue = $mcObject->replace($strKey, $strValue, $strFlag, $strExpire);
                    }
                    if (!$setValue) {
                        $errorMessage .= "<br />I cannot replace data to Id {$strId} of host {$strHost}:{$strPort}!";
                    }
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Delete item from the server
             *
             * <code>
             * <zmemcached:delete use="memCached" key="unique Id for this" timeout="10" />
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             * @param int timeout="0" Execution time of the item. If it's equal to zero, the item will be deleted right away whereas if you set it to 30, the item will be deleted in 30 seconds.
             */
        /*+
         * Delete item from the server
         *
         * <code>
         * <zmemcached:delete use="memCached" key="unique Id for this" timeout="10" />
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         * @param int timeout="0" Execution time of the item. If it's equal to zero, the item will be deleted right away whereas if you set it to 30, the item will be deleted in 30 seconds.
         */
        case "delete":
            $errorMessage .= ztagParamCheck($arrParam, "use,key");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    // $resultset = serialize($resultset);
                    if (strlen($strKey) && !strlen($strTimeout)) {
                        $setValue = $mcObject->delete($strKey);
                    } elseif (strlen($strKey) && strlen($strTimeout)) {
                        $setValue = $mcObject->delete($strKey, $strTimeout);
                    }
                    if (!$setValue) {
                        $errorMessage .= "<br />I cannot delete data to Id {$strId} of host {$strHost}:{$strPort}!";
                    }
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Increment item's value
             *
             * <code>
             * <zmemcached:increment use="memCached" key="unique Id for this" value="1" />
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             * @param int value="1" Value to be incremented
             */
        /*+
         * Increment item's value
         *
         * <code>
         * <zmemcached:increment use="memCached" key="unique Id for this" value="1" />
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         * @param int value="1" Value to be incremented
         */
        case "increment":
            $errorMessage .= ztagParamCheck($arrParam, "use,key");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    if (strlen($strKey) && !strlen($strValue)) {
                        $setValue = $mcObject->increment($strKey);
                    } elseif (strlen($strKey) && strlen($strValue)) {
                        $setValue = $mcObject->increment($strKey, $strValue);
                    }
                    if (!$setValue) {
                        $errorMessage .= "<br />I cannot increment data to Id {$strId} of host {$strHost}:{$strPort}!";
                    }
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Decrement item's value
             *
             * <code>
             * <zmemcached:decrement use="memCached" key="unique Id for this" value="1" />
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             * @param int value="1" Value to be incremented
             */
        /*+
         * Decrement item's value
         *
         * <code>
         * <zmemcached:decrement use="memCached" key="unique Id for this" value="1" />
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         * @param int value="1" Value to be incremented
         */
        case "decrement":
            $errorMessage .= ztagParamCheck($arrParam, "use,key");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    if (strlen($strKey) && !strlen($strValue)) {
                        $setValue = $mcObject->decrement($strKey);
                    } elseif (strlen($strKey) && strlen($strValue)) {
                        $setValue = $mcObject->decrement($strKey, $strValue);
                    }
                    if (!$setValue) {
                        $errorMessage .= "<br />I cannot decrement data to Id {$strId} of host {$strHost}:{$strPort}!";
                    }
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
            /*+
             * Debug
             *
             * <code>
             * <zmemcached:debug use="memCached" />
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             */
        /*+
         * Debug
         *
         * <code>
         * <zmemcached:debug use="memCached" />
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         */
        case "debug":
            for ($i = 0; $i < count($this->connections); $i++) {
                if ($this->connections[$i]->debug($on_off)) {
                    $result = true;
                }
            }
            break;
            /*+
             * Flush all existing items at the server
             *
             * <code>
             * <zmemcached:flush use="memCached" />
             * </code>
             *
             * @param string use="memCached" Id of an open connection
             */
        /*+
         * Flush all existing items at the server
         *
         * <code>
         * <zmemcached:flush use="memCached" />
         * </code>
         *
         * @param string use="memCached" Id of an open connection
         */
        case "flush":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeMemCached) {
                $mcHandle = $arrayTagId[$strUse][ztagIdHandle];
                $mcObject = $mcHandle[memcachedHandleId];
                $strHost = $mcHandle[memcachedHandleHost];
                $strPort = $mcHandle[memcachedHandlePort];
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    // $resultset = serialize($resultset);
                    $setValue = $mcObject->flush();
                    if (!$setValue) {
                        $errorMessage .= "<br />I cannot flush the Id {$strId} of host {$strHost}:{$strPort}!";
                    }
                } else {
                    $errorMessage .= "<br />The id {$strId} of host {$strHost}:{$strPort} is not open!";
                }
            } else {
                $errorMessage .= "<br />The id {$strId} no not refer to a Memcached handler!";
            }
            break;
        default:
            $errorMessage .= "<br />Undefined function \"{$tagFunction}\"";
    }
    ztagError($errorMessage, $arrayTag, $tagId);
}
コード例 #2
0
ファイル: zvar.inc.php プロジェクト: BGCX262/ztag-svn-to-git
/**
 * Main zTag functions selector
 *
 * <code>
 * zvar_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder);
 * </code>
 *
 * @param integer $tagId array id of current zTag of $arrayTag array
 * @param string $tagFunction name of zTag function
 * @param array $arrayTag array with all compiled zTags
 * @param array $arrayTagId array with all Ids values
 * @param array $arrayOrder array with zTag executing order
 *
 * @since 1.0
 */
function zvar_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder)
{
    $arrParam = $arrayTag[$tagId][ztagParam];
    $strId = $arrParam["id"];
    $strUse = $arrParam["use"];
    $strVar = $arrParam["var"];
    $strValue = $arrParam["value"];
    $strTransform = $arrParam["transform"];
    if ($arrayTag[$tagId][ztagContentWidth]) {
        $strContent = $arrayTag[$tagId][ztagContent];
    }
    $errorMessage = "";
    switch (strtolower($tagFunction)) {
        /*+
         * Creates a $var with it's value
         *
         * <code>
         * <zvar:set id="someVar" value="someValue" />
         *
         * <zvar:set id="otherVar">
         *   It's value
         * </zvar:set>
         * </code>
         *
         * @param string id="someVar" Unique Id for the new variable $varName
         * @param string value="someValue" Value to b saved into this variable
         */
        case "set":
            if ($arrayTag[$tagId][ztagContentWidth]) {
                $strValue = ztagVars($arrayTag[$tagId][ztagContent], $arrayTagId);
                $arrParam["value"] = $strValue;
            }
            if (strlen($strVar)) {
                $strId = $strVar;
                $arrParam["id"] = $strId;
            }
            $errorMessage .= ztagParamCheck($arrParam, "value,id");
            if (strlen($strTransform)) {
                $strValue = ztagTransform($strValue, $strTransform);
            }
            $arrayTagId["\$" . $strId][ztagIdValue] = $strValue;
            $arrayTagId["\$" . $strId][ztagIdLength] = strlen($strValue);
            $arrayTagId["\$" . $strId][ztagIdType] = idTypeFVar;
            break;
            /*+
             * Creates an array var $someArray with it´s formated content
             *
             * <code>
             * <zvar:setarray id="someArray">
             *   "index"="value"
             *   , "index2":"value 2"
             *   , 'index3'=>'value 3'
             *   , 99="value"
             *   , "indexn"=99
             * </znosql:setarray>
             *
             * <zvar:setarray id="someArray" value="'index'='value',9='value'" />
             * </code>
             *
             * @param string id="someArray" Unique Id for the new variable $varName
             */
        /*+
         * Creates an array var $someArray with it´s formated content
         *
         * <code>
         * <zvar:setarray id="someArray">
         *   "index"="value"
         *   , "index2":"value 2"
         *   , 'index3'=>'value 3'
         *   , 99="value"
         *   , "indexn"=99
         * </znosql:setarray>
         *
         * <zvar:setarray id="someArray" value="'index'='value',9='value'" />
         * </code>
         *
         * @param string id="someArray" Unique Id for the new variable $varName
         */
        case "setarray":
            if (strlen($strContent)) {
                $contentArray = $strContent;
            }
            if (strlen($strValue)) {
                $contentArray = $strValue;
            }
            if ($contentArray) {
                $contentArray = ztagVars($contentArray, $arrayTagId);
                $arrParam["value"] = $strValue;
            }
            if (!strlen($strContent) && !strlen($strValue)) {
                $errorMessage .= ztagParamCheck($arrParam, "id,value");
            }
            if ($strTransform && $contentArray) {
                $contentArray = ztagTransform($contentArray, $strTransform);
            }
            $contentArray = ltrim($contentArray, "\r\n");
            $contentArray = rtrim($contentArray, "\r\n");
            preg_match_all('%\\s*,?\\s*(?P<index>"[^"]*?"|\'[^\']*?\'|\\d+)\\s*(:|=|=>)\\s*(?P<value>"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|\\d+)%', $contentArray, $Matches, PREG_OFFSET_CAPTURE);
            $arrayContent = array();
            foreach ($Matches[0] as $key => $value) {
                $paramKey = $Matches["index"][$key][0];
                $paramValue = $Matches["value"][$key][0];
                $patternString = '%^(["\'])(.*?)\\1%';
                $paramKey = preg_replace($patternString, "\$2", $paramKey);
                $paramValue = preg_replace($patternString, "\$2", $paramValue);
                $arrayContent[$paramKey] = preg_replace('%\\\\([\'"])%', "\$1", $paramValue);
            }
            $arrayTagId["\$" . $strId][ztagIdValue] = $arrayContent;
            $arrayTagId["\$" . $strId][ztagIdLength] = count($arrayContent);
            $arrayTagId["\$" . $strId][ztagIdType] = idTypeFVar;
            break;
            /*+
             * Creates a $var if the contidion is made with it´s value
             *
             * <code>
             * <zvar:setif use="getFiltro" equal="nome" var="sqlSelect" then="(SELECT CD_PESSOA FROM TB_ENDERECO_PESSOA WHERE NM_PESSOA LIKE '%$getFiltro%')" />
             *
             * <zvar:setif use="CO_CPF" condition="empty()" var="sqlSelect" then="CO_CPF LIKE '%$CO_CPF%'" />
             * </code>
             *
             * @param string use="getFiltro"
             * @param string equal="nome"
             * @param string var="sqlSelect"
             * @param string then="(SELECT CD_PESSOA FROM TB_ENDERECO_PESSOA WHERE NM_PESSOA LIKE '%$getFiltro%')"
             */
        /*+
         * Creates a $var if the contidion is made with it´s value
         *
         * <code>
         * <zvar:setif use="getFiltro" equal="nome" var="sqlSelect" then="(SELECT CD_PESSOA FROM TB_ENDERECO_PESSOA WHERE NM_PESSOA LIKE '%$getFiltro%')" />
         *
         * <zvar:setif use="CO_CPF" condition="empty()" var="sqlSelect" then="CO_CPF LIKE '%$CO_CPF%'" />
         * </code>
         *
         * @param string use="getFiltro"
         * @param string equal="nome"
         * @param string var="sqlSelect"
         * @param string then="(SELECT CD_PESSOA FROM TB_ENDERECO_PESSOA WHERE NM_PESSOA LIKE '%$getFiltro%')"
         */
        case "setif":
            $strEqual = $arrParam["equal"];
            $strNotEqual = $arrParam["notequal"];
            $strThen = $arrParam["then"];
            $strElse = $arrParam["else"];
            $strCondition = $arrParam["condition"];
            $strNotCondition = $arrParam["notcondition"];
            $errorMessage .= ztagParamCheck($arrParam, "use,then,var");
            if ($strUse) {
                $strUse = $arrayTagId["\$" . $strUse][ztagIdValue];
            }
            if ($strEqual) {
                if ($strUse == $strEqual) {
                    $arrayTagId["\$" . $strVar][ztagIdValue] = $strThen;
                } else {
                    if ($strElse) {
                        $arrayTagId["\$" . $strVar][ztagIdValue] = $strElse;
                    }
                }
            }
            if ($strNotEqual) {
                if ($strUse != $strNotEqual) {
                    $arrayTagId["\$" . $strVar][ztagIdValue] = $strThen;
                } else {
                    if ($strElse) {
                        $arrayTagId["\$" . $strVar][ztagIdValue] = $strElse;
                    }
                }
            }
            if ($strCondition) {
                $strCondition = ztagTransform($strUse, $strCondition);
                if ($strCondition) {
                    $arrayTagId["\$" . $strVar][ztagIdValue] = $strThen;
                } else {
                    if ($strElse) {
                        $arrayTagId["\$" . $strVar][ztagIdValue] = $strElse;
                    }
                }
            }
            if ($strNotCondition) {
                $strNotCondition = ztagTransform($strUse, $strNotCondition);
                if (!$strNotCondition) {
                    $arrayTagId["\$" . $strVar][ztagIdValue] = $strThen;
                } else {
                    if ($strElse) {
                        $arrayTagId["\$" . $strVar][ztagIdValue] = $strElse;
                    }
                }
            }
            break;
            /*+
             * Unset a variable
             *
             * <code>
             * <zvar:unset use="getFiltro" />
             * </code>
             *
             * @param string use="getFiltro"
             */
        /*+
         * Unset a variable
         *
         * <code>
         * <zvar:unset use="getFiltro" />
         * </code>
         *
         * @param string use="getFiltro"
         */
        case "unset":
            /*+
             * Reset a variable
             *
             * <code>
             * <zvar:reset use="getFiltro" />
             * </code>
             *
             * @param string use="getFiltro"
             */
        /*+
         * Reset a variable
         *
         * <code>
         * <zvar:reset use="getFiltro" />
         * </code>
         *
         * @param string use="getFiltro"
         */
        case "reset":
            $errorMessage = ztagParamCheck($arrParam, "use");
            if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) {
                $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!";
            }
            $arrayTagId["\$" . $strUse] = array();
            break;
            /*+
             * Update a $var with it's value
             *
             * <code>
             * <zvar:update use="someVar" value="someValue" />
             *
             * <zvar:set use="otherVar">
             *   It's value
             * </zvar:set>
             * </code>
             *
             * @param string use="someVar" Unique Id of a variable $varName
             * @param string value="someValue" Value to b saved into this variable
             */
        /*+
         * Update a $var with it's value
         *
         * <code>
         * <zvar:update use="someVar" value="someValue" />
         *
         * <zvar:set use="otherVar">
         *   It's value
         * </zvar:set>
         * </code>
         *
         * @param string use="someVar" Unique Id of a variable $varName
         * @param string value="someValue" Value to b saved into this variable
         */
        case "update":
            if ($arrayTag[$tagId][ztagContentWidth]) {
                $strValue = ztagVars($arrayTag[$tagId][ztagContent], $arrayTagId);
                $arrParam["value"] = $strValue;
            }
            $errorMessage .= ztagParamCheck($arrParam, "value,use");
            if (strlen($strUse)) {
                $arrayTagId["\$" . $strUse][ztagIdValue] = $strValue;
                $arrayTagId["\$" . $strUse][ztagIdLength] = strlen($strValue);
                $arrayTagId["\$" . $strUse][ztagIdType] = idTypeFVar;
            }
            break;
            /*+
             * Get and return a variable value
             *
             * <code>
             * <zvar:get use="getFiltro" />
             * </code>
             *
             * @param string use="getFiltro"
             */
        /*+
         * Get and return a variable value
         *
         * <code>
         * <zvar:get use="getFiltro" />
         * </code>
         *
         * @param string use="getFiltro"
         */
        case "get":
            /*+
             * Show variable value
             *
             * <code>
             * <zvar:show use="getFiltro" />
             * </code>
             *
             * @param string use="getFiltro"
             */
        /*+
         * Show variable value
         *
         * <code>
         * <zvar:show use="getFiltro" />
         * </code>
         *
         * @param string use="getFiltro"
         */
        case "show":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            preg_match_all('%^(?P<var>\\w+)\\[(?P<index>[^\\]]+)\\]$%', $strUse, $Matches, PREG_OFFSET_CAPTURE);
            if (count($Matches[0][0])) {
                $var = $Matches["var"][0][0];
                $index = $Matches["index"][0][0];
                $varValue = $arrayTagId["\$" . $var][ztagIdValue];
                $varValue = $varValue[$index];
            } else {
                if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) {
                    $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!";
                }
                $varValue = $arrayTagId["\$" . $strUse][ztagIdValue];
            }
            if (strlen($strTransform)) {
                $varValue = ztagTransform($varValue, $strTransform);
            }
            $arrayTag[$tagId][ztagResult] = $varValue;
            break;
            /*+
             * Creates a $arrayVar for var parameters, applying the pattern using use var content.
             *
             * <code>
             * <zvar:regex pattern='%title="(?P<title>.*?)" href="(?P<url>/\d+/\d+_\w+/(?P<id>\d+)/[\w-]+.htm)%' use="urlAssunto" var="arrayAssunto" />
             * </code>
             *
             * @param string pattern='%title="(?P<title>.*?)" href="(?P<url>/\d+/\d+_\w+/(?P<id>\d+)/[\w-]+.htm)%'
             * @param string use="urlAssunto"
             * @param string value="$arrayValue"
             * @param string var="arrayAssunto"
             * @param string error="errorVar"
             */
        /*+
         * Creates a $arrayVar for var parameters, applying the pattern using use var content.
         *
         * <code>
         * <zvar:regex pattern='%title="(?P<title>.*?)" href="(?P<url>/\d+/\d+_\w+/(?P<id>\d+)/[\w-]+.htm)%' use="urlAssunto" var="arrayAssunto" />
         * </code>
         *
         * @param string pattern='%title="(?P<title>.*?)" href="(?P<url>/\d+/\d+_\w+/(?P<id>\d+)/[\w-]+.htm)%'
         * @param string use="urlAssunto"
         * @param string value="$arrayValue"
         * @param string var="arrayAssunto"
         * @param string error="errorVar"
         */
        case "regex":
            $strPattern = $arrParam["pattern"];
            $strError = $arrParam["error"];
            $errorMessage .= ztagParamCheck($arrParam, "pattern,var");
            if ($strUse) {
                $strValue = $arrayTagId["\$" . $strUse][ztagIdValue];
            }
            preg_match_all($strPattern, $strValue, $Matches, PREG_SET_ORDER);
            $arrayResult = array();
            foreach ($Matches as $keyMatches => $valueMatches) {
                foreach ($valueMatches as $key => $value) {
                    if (is_string($key) || $key) {
                        $arrayMatches[$key] = $value;
                    }
                }
                $arrayResult[] = $arrayMatches;
            }
            if (preg_last_error() && strlen($strError)) {
                $arrayTagId["\$" . $strError][ztagIdValue] = preg_last_error();
                $arrayTagId["\$" . $strError][ztagIdLength] = count(preg_last_error());
                $arrayTagId["\$" . $strError][ztagIdType] = idTypeFVar;
            } else {
                $arrayTagId["\$" . $strError] = array();
            }
            if (strlen($strVar) && count($arrayResult)) {
                $arrayTagId["\$" . $strVar][ztagIdValue] = $arrayResult;
                $arrayTagId["\$" . $strVar][ztagIdLength] = count($arrayResult);
                $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
            } else {
                $arrayTagId["\$" . $strVar] = array();
            }
            break;
            /*+
             * Decrement a variable value
             *
             * <code>
             * <zvar:decrement use="getFiltro" />
             * </code>
             *
             * @param string use="getFiltro"
             */
        /*+
         * Decrement a variable value
         *
         * <code>
         * <zvar:decrement use="getFiltro" />
         * </code>
         *
         * @param string use="getFiltro"
         */
        case "decrement":
            /*+
             * Decrement a variable value
             *
             * <code>
             * <zvar:dec use="getFiltro" />
             * </code>
             *
             * @param string use="getFiltro"
             */
        /*+
         * Decrement a variable value
         *
         * <code>
         * <zvar:dec use="getFiltro" />
         * </code>
         *
         * @param string use="getFiltro"
         */
        case "dec":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            preg_match_all('%^(?P<var>\\w+)\\[(?P<index>[^\\]]+)\\]$%', $strUse, $Matches, PREG_OFFSET_CAPTURE);
            if (count($Matches[0][0])) {
                $var = $Matches["var"][0][0];
                $index = $Matches["index"][0][0];
                $varValue = $arrayTagId["\$" . $var][ztagIdValue];
                $arrayTagId["\$" . $var][ztagIdValue] = $varValue[$index]--;
            } else {
                if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) {
                    $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!";
                }
                $arrayTagId["\$" . $strUse][ztagIdValue]--;
            }
            break;
            /*+
             * Increment a variable value
             *
             * <code>
             * <zvar:increment use="getFiltro" />
             * </code>
             *
             * @param string use="getFiltro"
             */
        /*+
         * Increment a variable value
         *
         * <code>
         * <zvar:increment use="getFiltro" />
         * </code>
         *
         * @param string use="getFiltro"
         */
        case "increment":
            /*+
             * Increment a variable value
             *
             * <code>
             * <zvar:inc use="getFiltro" />
             * </code>
             *
             * @param string use="getFiltro"
             */
        /*+
         * Increment a variable value
         *
         * <code>
         * <zvar:inc use="getFiltro" />
         * </code>
         *
         * @param string use="getFiltro"
         */
        case "inc":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            preg_match_all('%^(?P<var>\\w+)\\[(?P<index>[^\\]]+)\\]$%', $strUse, $Matches, PREG_OFFSET_CAPTURE);
            if (count($Matches[0][0])) {
                $var = $Matches["var"][0][0];
                $index = $Matches["index"][0][0];
                $varValue = $arrayTagId["\$" . $var][ztagIdValue];
                $arrayTagId["\$" . $var][ztagIdValue] = $varValue[$index]++;
            } else {
                if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) {
                    $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!";
                }
                $arrayTagId["\$" . $strUse][ztagIdValue]++;
            }
            break;
        default:
            $errorMessage .= "<br />Undefined function \"{$tagFunction}\"";
    }
    ztagError($errorMessage, $arrayTag, $tagId);
}
コード例 #3
0
ファイル: zForm.inc.php プロジェクト: BGCX262/ztag-svn-to-git
/**
 * Main zTag functions selector
 *
 * <code>
 * zform_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder);
 * </code>
 *
 * @param integer $tagId array id of current zTag of $arrayTag array
 * @param string $tagFunction name of zTag function
 * @param array $arrayTag array with all compiled zTags
 * @param array $arrayTagId array with all Ids values
 * @param array $arrayOrder array with zTag executing order
 *
 * @since 1.0
 */
function zform_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder)
{
    $arrParam = $arrayTag[$tagId][ztagParam];
    $strId = $arrParam["id"];
    $strTagId = $arrParam["tagid"];
    $strName = $arrParam["name"];
    $strCaption = $arrParam["caption"];
    $strValue = $arrParam["value"];
    $strValues = $arrParam["values"];
    if ($arrayTag[$tagId][ztagContentWidth]) {
        $strContent = $arrayTag[$tagId][ztagContent];
    }
    if (!$strTagId) {
        $strTagId = $strName;
    }
    $arrParam["id"] = $strTagId;
    $arrParam["for"] = $strTagId;
    if ($strCaption) {
        if (strpos(" {$strCaption}", "&")) {
            $labelAccessKey = preg_match("%&(.)%i", $strCaption);
            if (!$labelAccessKey) {
                $labelAccessKey = substr($strCaption, 1, 1);
            }
            $arrParam["accesskey"] = $labelAccessKey;
            $strCaption = preg_replace("%^(.*)&(.)(.*)\$%i", "\$1<u>\$2</u>\$3", $strCaption);
        }
    }
    $errorMessage = "";
    switch (strtolower($tagFunction)) {
        /*+
         * Input Text
         *
         * <code>
         * <zform:input type="text" name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string type="text"
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "input":
            $errorMessage = ztagParamCheck($arrParam, "type,name");
            $strParam = ztagParam($arrParam, "type,id,name,value,style,required,readonly,disabled,autocomplete,maxlength,size,tabindex,datebr");
            $arrayTag[$tagId][ztagResult] = "<input{$strParam} />";
            break;
            /*+
             * Input Text
             *
             * <code>
             * <zform:inputtext name="fieldName" tagid="fieldId" value="fieldValue" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Input Text
         *
         * <code>
         * <zform:inputtext name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "inputtext":
            $arrParam["type"] = "text";
            $errorMessage = ztagParamCheck($arrParam, "type,name");
            $strParam = ztagParam($arrParam, "type,id,name,value,style,required,readonly,disabled,autocomplete,maxlength,size,tabindex,title,datebr");
            $arrayTag[$tagId][ztagResult] = "<input{$strParam} />";
            break;
            /*+
             * Input Hidden
             *
             * <code>
             * <zform:inputhidden name="fieldName" tagid="fieldId" value="fieldValue" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Input Hidden
         *
         * <code>
         * <zform:inputhidden name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "inputhidden":
            $arrParam["type"] = "hidden";
            $errorMessage = ztagParamCheck($arrParam, "type,name");
            $strParam = ztagParam($arrParam, "type,id,name,value");
            $arrayTag[$tagId][ztagResult] = "<input{$strParam} />";
            break;
            /*+
             * Input Password
             *
             * <code>
             * <zform:inputpassword name="fieldName" tagid="fieldId" value="fieldValue" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Input Password
         *
         * <code>
         * <zform:inputpassword name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "inputpassword":
            $arrParam["type"] = "password";
            $errorMessage = ztagParamCheck($arrParam, "type,name");
            $strParam = ztagParam($arrParam, "type,id,name,value,style,required,readonly");
            $arrayTag[$tagId][ztagResult] = "<input{$strParam} />";
            break;
            /*+
             * Input Checkbox
             *
             * <code>
             * <zform:inputcheckbox name="fieldName" tagid="fieldId" value="fieldValue" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Input Checkbox
         *
         * <code>
         * <zform:inputcheckbox name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "inputcheckbox":
            $arrParam["type"] = "checkbox";
            $arrValues = explode(";", $strValues);
            if ($arrValues[0] == $strValue) {
                $strChecked = " checked=\"checked\"";
            }
            $errorMessage = ztagParamCheck($arrParam, "type,name,values");
            $strParam = ztagParam($arrParam, "type,id,name,value,style,required,readonly");
            $arrayTag[$tagId][ztagResult] = "<input{$strParam}{$strChecked} />";
            break;
            /*+
             * Text Area
             *
             * <code>
             * <zform:textarea name="fieldName" tagid="fieldId" value="fieldValue" />
             *
             * <zform:textarea name="fieldName" tagid="fieldId" filename="fileSave.txt" filetype="txt">
             * Text Area value
             * </zform:textarea>
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @param string filename="/Alianca8/File.txt"
             * @param string filetype="txt"
             * @param string show="0"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Text Area
         *
         * <code>
         * <zform:textarea name="fieldName" tagid="fieldId" value="fieldValue" />
         *
         * <zform:textarea name="fieldName" tagid="fieldId" filename="fileSave.txt" filetype="txt">
         * Text Area value
         * </zform:textarea>
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @param string filename="/Alianca8/File.txt"
         * @param string filetype="txt"
         * @param string show="0"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "textarea":
            $strFileName = $arrParam["filename"];
            $strFileType = $arrParam["filetype"];
            $strShow = strtolower($arrParam["show"]);
            if (strlen($strContent)) {
                $arrParam["value"] = $strContent;
            }
            $strValue = $arrParam["value"];
            if (strlen($strValue)) {
                $strValue = ztagVars($strValue, $arrayTagId);
                $strValue = ztagRun($strValue, 0, $arrayTagId);
            }
            $arrParam["type"] = "textarea";
            $errorMessage = ztagParamCheck($arrParam, "type,name");
            $strParam = ztagParam($arrParam, "type,id,name,style,required,readonly,disabled,cols,rows,tabindex,title");
            $arrayTag[$tagId][ztagResult] = "<textarea{$strParam} />{$strValue}</textarea>";
            $blnShow = $strShow === "true" || $strShow === "1" || !strlen($strShow);
            if ($strFileName) {
                $strFileName = str_replace("\\", "/", $strFileName);
                if (substr($strFileName, 0, 1) === "/") {
                    $strFileName = substr($strFileName, 1);
                }
                $strFileName = SiteRootDir . $strFileName;
                if (!($handleFile = fopen($strFileName, "w"))) {
                    $errorMessage .= "\r\nCannot open file ({$strFileName})";
                }
            }
            if ($handleFile && fwrite($handleFile, $strValue) === FALSE) {
                if (!$errorMessageTemp) {
                    $errorMessage .= $errorMessageTemp = "\r\nCannot write to file ({$strFileName})";
                }
            }
            if ($handleFile) {
                fclose($handleFile);
            }
            break;
            /*+
             * Select
             *
             * <code>
             * <zform:select name="textNameSelect" tagid="textIdSelect" value="tagOptionValue1,tagOptionCaption1;tagOptionValue2,tagOptionCaption2;tagOptionValue3,tagOptionCaption3" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Select
         *
         * <code>
         * <zform:select name="textNameSelect" tagid="textIdSelect" value="tagOptionValue1,tagOptionCaption1;tagOptionValue2,tagOptionCaption2;tagOptionValue3,tagOptionCaption3" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "select":
            $strOptions = $arrParam["options"];
            if ($strOptions) {
                $arrOptions = explode(";", $strOptions);
                foreach ($arrOptions as $keyOptions => $valueOptions) {
                    $strSelected = "";
                    $arrOption = explode(",", $valueOptions);
                    if ($strValue == $arrOption[0]) {
                        $strSelected = " selected=\"selected\"";
                    }
                    if (!$arrOption[1]) {
                        $arrOption[1] = $arrOption[0];
                    }
                    $strOptions .= "<option value=\"{$arrOption['0']}\"{$strSelected}>{$arrOption['1']}</option>";
                }
            }
            $errorMessage = ztagParamCheck($arrParam, "name,options");
            $strParam = ztagParam($arrParam, "type,id,name,style,required,readonly,disabled,cols,rows,tabindex,title");
            $arrayTag[$tagId][ztagResult] = "<select{$strParam} />{$strOptions}</select>";
            break;
            /*+
             * Input Submit
             *
             * <code>
             * <zform:inputsubmit name="fieldName" tagid="fieldId" value="fieldValue" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Input Submit
         *
         * <code>
         * <zform:inputsubmit name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "inputsubmit":
            $arrParam["type"] = "submit";
            $errorMessage = ztagParamCheck($arrParam, "type,name,value");
            $strParam = ztagParam($arrParam, "type,id,name,value");
            $arrayTag[$tagId][ztagResult] = "<input{$strParam} />";
            break;
            /*+
             * Box
             *
             * <code>
             * <zform:box type="text" caption="caption" name="fieldName" tagid="fieldId" value="fieldValue" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Box
         *
         * <code>
         * <zform:box type="text" caption="caption" name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "box":
            $errorMessage = ztagParamCheck($arrParam, "type,caption,name");
            $strLabel = ztagParam($arrParam, "accesskey,for");
            $strParam = ztagParam($arrParam, "type,id,name,value,style,required,readonly,disabled,autocomplete,maxlength,size,tabindex,title,datebr");
            $arrayTag[$tagId][ztagResult] = "<label{$strLabel}>{$strCaption}<br /><input{$strParam} /></label>";
            break;
            /*+
             * Box Text
             *
             * <code>
             * <zform:boxtext caption="caption" name="fieldName" tagid="fieldId" value="fieldValue" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Box Text
         *
         * <code>
         * <zform:boxtext caption="caption" name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "boxtext":
            $arrParam["type"] = "text";
            $errorMessage = ztagParamCheck($arrParam, "type,caption,name");
            $strLabel = ztagParam($arrParam, "accesskey,for");
            $strParam = ztagParam($arrParam, "type,id,name,value,style,required,readonly,disabled,autocomplete,maxlength,size,tabindex,title,datebr");
            $arrayTag[$tagId][ztagResult] = "<label{$strLabel}>{$strCaption}<br /><input{$strParam} /></label>";
            break;
            /*+
             * Box Password
             *
             * <code>
             * <zform:boxpassword name="fieldName" tagid="fieldId" value="fieldValue" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Box Password
         *
         * <code>
         * <zform:boxpassword name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "boxpassword":
            $arrParam["type"] = "password";
            $errorMessage = ztagParamCheck($arrParam, "type,caption,name");
            $strLabel = ztagParam($arrParam, "accesskey,for");
            $strParam = ztagParam($arrParam, "type,id,name,value,style,required,readonly");
            $arrayTag[$tagId][ztagResult] = "<label{$strLabel}>{$strCaption}<br /><input{$strParam} /></label>";
            break;
            /*+
             * Box Checkbox
             *
             * <code>
             * <zform:boxcheckbox caption="&CheckBox" name="checkboxNameBox" tagid="checkboxIdBox"  value="checkboxValueOn" values="checkboxValueOn;checkboxValueOff" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Box Checkbox
         *
         * <code>
         * <zform:boxcheckbox caption="&CheckBox" name="checkboxNameBox" tagid="checkboxIdBox"  value="checkboxValueOn" values="checkboxValueOn;checkboxValueOff" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "boxcheckbox":
            $arrParam["type"] = "checkbox";
            $arrValues = explode(";", $strValues);
            if ($arrValues[0] == $strValue) {
                $arrParam["checked"] = "checked";
            }
            $errorMessage = ztagParamCheck($arrParam, "type,name,value,values");
            $strParam = ztagParam($arrParam, "type,id,name,value,style,required,readonly");
            $arrayTag[$tagId][ztagResult] = "<label{$strLabel}><input{$strParam} /> {$strCaption}</label>";
            break;
            /*+
             * Box Radio
             *
             * <code>
             * <zform:boxradio caption="Processos com GTOs duplicadas" name="FL_CONTA_MEDICA_Estado" tagid="FL_DATA_Consulta" value="1" checked="$FL_GTO_DUPLICADACheck" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Box Radio
         *
         * <code>
         * <zform:boxradio caption="Processos com GTOs duplicadas" name="FL_CONTA_MEDICA_Estado" tagid="FL_DATA_Consulta" value="1" checked="$FL_GTO_DUPLICADACheck" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "boxradio":
            $arrParam["type"] = "radio";
            $arrValues = explode(";", $strValues);
            if ($arrValues[0] == $strValue) {
                $arrParam["checked"] = "checked";
            }
            $errorMessage = ztagParamCheck($arrParam, "type,name,value,values");
            $strParam = ztagParam($arrParam, "type,id,name,value,style,required,readonly");
            $arrayTag[$tagId][ztagResult] = "<label{$strLabel}><input{$strParam} /> {$strCaption}</label>";
            break;
            /*+
             * Box Text Area
             *
             * <code>
             * <zform:boxtextarea name="fieldName" tagid="fieldId" value="fieldValue" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Box Text Area
         *
         * <code>
         * <zform:boxtextarea name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "boxtextarea":
            $arrParam["type"] = "textarea";
            $errorMessage = ztagParamCheck($arrParam, "type,caption,name,value");
            $strLabel = ztagParam($arrParam, "accesskey,for");
            $strParam = ztagParam($arrParam, "type,id,name,style,required,readonly,disabled,cols,rows,tabindex,title");
            $arrayTag[$tagId][ztagResult] = "<label{$strLabel}>{$strCaption}<br /><textarea{$strParam} />{$strValue}</textarea></label>";
            break;
            /*+
             * Box Select
             *
             * <code>
             * <zform:boxselect caption="&Text" name="textNameBox" tagid="textIdBox" value="textValueBox" options="tagOptionValue1,tagOptionCaption1;tagOptionValue2,tagOptionCaption2;tagOptionValue3,tagOptionCaption3" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Box Select
         *
         * <code>
         * <zform:boxselect caption="&Text" name="textNameBox" tagid="textIdBox" value="textValueBox" options="tagOptionValue1,tagOptionCaption1;tagOptionValue2,tagOptionCaption2;tagOptionValue3,tagOptionCaption3" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "boxselect":
            $strOptions = $arrParam["options"];
            if ($strOptions) {
                $arrOptions = explode(";", $strOptions);
                $strOptions = "";
                foreach ($arrOptions as $keyOptions => $valueOptions) {
                    $strSelected = "";
                    $arrOption = explode(",", $valueOptions);
                    if ($strValue == $arrOption[0]) {
                        $strSelected = " selected=\"selected\"";
                    }
                    if (!$arrOption[1]) {
                        $arrOption[1] = $arrOption[0];
                    }
                    $strOptions .= "<option value=\"{$arrOption['0']}\"{$strSelected}>{$arrOption['1']}</option>";
                }
            }
            $errorMessage = ztagParamCheck($arrParam, "name,options");
            $strLabel = ztagParam($arrParam, "accesskey,for");
            $strParam = ztagParam($arrParam, "type,id,name,style,required,readonly,disabled,cols,rows,tabindex,title");
            $arrayTag[$tagId][ztagResult] = "<label{$strLabel}>{$strCaption}<br /><select{$strParam} />{$strOptions}</select></label>";
            break;
            /*+
             * Button
             *
             * <code>
             * <zform:button name="fieldName" tagid="fieldId" value="fieldValue" />
             * </code>
             *
             * @param string name="fieldName"
             * @param string tagid="fieldId"
             * @param string value="fieldValue"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Button
         *
         * <code>
         * <zform:button name="fieldName" tagid="fieldId" value="fieldValue" />
         * </code>
         *
         * @param string name="fieldName"
         * @param string tagid="fieldId"
         * @param string value="fieldValue"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "button":
            break;
        default:
            $errorMessage .= "<br />Undefined function \"{$tagFunction}\"";
    }
    ztagError($errorMessage, $arrayTag, $tagId);
}
コード例 #4
0
ファイル: zdbal.inc.php プロジェクト: BGCX262/ztag-svn-to-git
function zdbal_Execute($tagId, &$arrayTag, &$arrayTagId, $arrayOrder)
{
    $arrParam = $arrayTag[$tagId][ztagParam];
    $strId = $arrParam["id"];
    $strUse = $arrParam["use"];
    $errorMessage .= ztagParamCheck($arrParam, "use");
    if ($arrayTag[$tagId][ztagContentWidth]) {
        $strContent = ztagVars($arrayTag[$tagId][ztagContent], $arrayTagId);
        $strLocalId = $strUse;
        if ($strId) {
            $strLocalId = $strId;
            $arrayTagId[$strId][ztagIdValue] = $strContent;
            $arrayTagId[$strId][ztagIdLength] = strlen($strContent);
            $arrayTagId[$strId][ztagIdType] = idTypeExecute;
            $arrayTagId[$strId][ztagIdHandle] = $arrayTagId[$strUse][ztagIdHandle];
        }
        // echo "<br />strContent=$strContent";
        $dbStatement = $arrayTagId[$strLocalId][ztagIdHandle]->executeQuery($strContent);
    } else {
        $errorMessage .= "<br />Tag Execute cannot be empty!";
    }
    ztagError($errorMessage, $arrayTag, $tagId);
}
コード例 #5
0
ファイル: zhtml.inc.php プロジェクト: BGCX262/ztag-svn-to-git
/**
 * Main zTag functions selector
 *
 * <code>
 * zhtml_zexecute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder);
 * </code>
 *
 * @param integer $tagId array id of current zTag of $arrayTag array
 * @param string $tagFunction name of zTag function
 * @param array $arrayTag array with all compiled zTags
 * @param array $arrayTagId array with all Ids values
 * @param array $arrayOrder array with zTag executing order
 *
 * @since 1.0
 */
function zhtml_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder)
{
    $arrParam = $arrayTag[$tagId][ztagParam];
    $strId = $arrParam["id"];
    $strTagId = $arrParam["tagid"];
    $strValue = $arrParam["value"];
    $strTransform = $arrParam["transform"];
    $strContent = $arrayTag[$tagId][ztagContent];
    if (strlen($strContent)) {
        $strContent = ztagVars($strContent, $arrayTagId);
    }
    if (strlen($strValue)) {
        $strContent = $strValue;
    }
    $arrParam["value"] = $strContent;
    if (!$strTagId) {
        $strTagId = $strName;
    }
    $arrParam["id"] = $strTagId;
    $strTag = strtolower($tagFunction);
    $errorMessage = "";
    switch (strtolower($tagFunction)) {
        /*+
         * Cell
         *
         * <code>
         * <zhmtl:cell value="text" />
         * </code>
         *
         * @param string value="text"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "cell":
            $strTag = "td";
            $errorMessage = ztagParamCheck($arrParam, "value");
            $strParam = ztagParam($arrParam, "alt,align,border,height,width,id,class,style,nowrap,colspan");
            if ($strTransform) {
                $strContent = ztagTransform($strContent, $strTransform);
            }
            $arrayTag[$tagId][ztagResult] = "<{$strTag}{$strParam}>{$strContent}</{$strTag}>";
            break;
            /*+
             * Echo
             *
             * <code>
             * <zhmtl:echo value="text" />
             * </code>
             *
             * @param string value="text"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Echo
         *
         * <code>
         * <zhmtl:echo value="text" />
         * </code>
         *
         * @param string value="text"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "echo":
            $strParam = ztagParam($arrParam, "value");
            $errorMessage = ztagParamCheck($arrParam, "value");
            $arrayTag[$tagId][ztagResult] = $strValue;
            break;
            /*+
             * Img
             *
             * <code>
             * <zhmtl:img value="text" />
             * </code>
             *
             * @param string value="text"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Img
         *
         * <code>
         * <zhmtl:img value="text" />
         * </code>
         *
         * @param string value="text"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "img":
            $strParam = ztagParam($arrParam, "src,alt,align,border,height,width,id,class,style");
            $errorMessage = ztagParamCheck($arrParam, "src,alt");
            $arrayTag[$tagId][ztagResult] = "<{$strTag}{$strParam} />";
            break;
            /*+
             * Base Font
             *
             * <code>
             * <zhmtl:basefont value="text" />
             * </code>
             *
             * @param string value="text"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Base Font
         *
         * <code>
         * <zhmtl:basefont value="text" />
         * </code>
         *
         * @param string value="text"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "basefont":
            $strParam = ztagParam($arrParam, "color,face,size");
            $arrayTag[$tagId][ztagResult] = "<{$strTag}{$strParam} />";
            break;
            /*+
             * Base
             *
             * <code>
             * <zhmtl:base value="text" />
             * </code>
             *
             * @param string value="text"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Base
         *
         * <code>
         * <zhmtl:base value="text" />
         * </code>
         *
         * @param string value="text"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "base":
            $strParam = ztagParam($arrParam, "href,target");
            $errorMessage = ztagParamCheck($arrParam, "href");
            $arrayTag[$tagId][ztagResult] = "<{$strTag}{$strParam} />";
            break;
            /*+
             * Link
             *
             * <code>
             * <zhmtl:link value="text" />
             * </code>
             *
             * @param string value="text"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Link
         *
         * <code>
         * <zhmtl:link value="text" />
         * </code>
         *
         * @param string value="text"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "link":
            $strParam = ztagParam($arrParam, "href,target,id,class,style");
            $errorMessage = ztagParamCheck($arrParam, "href");
            $arrayTag[$tagId][ztagResult] = "<a{$strParam}>{$strContent}</a>";
            break;
            /*+
             * Commment
             *
             * <code>
             * <zhmtl:commment value="text" />
             * </code>
             *
             * @param string value="text"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * Commment
         *
         * <code>
         * <zhmtl:commment value="text" />
         * </code>
         *
         * @param string value="text"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "commment":
            if ($strTransform) {
                $strContent = ztagTransform($strContent, $strTransform);
            }
            $arrayTag[$tagId][ztagResult] = "<!-- {$strContent} -->";
            break;
            /*+
             * H1
             *
             * <code>
             * <zhtml:h1 value="tagValueH1" style="tagStle" />
             * </code>
             *
             * @param string value="tagValueH1"
             * @param string style="tagStle"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * H1
         *
         * <code>
         * <zhtml:h1 value="tagValueH1" style="tagStle" />
         * </code>
         *
         * @param string value="tagValueH1"
         * @param string style="tagStle"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "h1":
            /*+
             * H2
             *
             * <code>
             * <zhtml:h2 value="tagValueH2" style="tagStle" />
             * </code>
             *
             * @param string value="tagValueH2"
             * @param string style="tagStle"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * H2
         *
         * <code>
         * <zhtml:h2 value="tagValueH2" style="tagStle" />
         * </code>
         *
         * @param string value="tagValueH2"
         * @param string style="tagStle"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "h2":
            /*+
             * H3
             *
             * <code>
             * <zhtml:h3 value="tagValueH3" style="tagStle" />
             * </code>
             *
             * @param string value="tagValueH3"
             * @param string style="tagStle"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * H3
         *
         * <code>
         * <zhtml:h3 value="tagValueH3" style="tagStle" />
         * </code>
         *
         * @param string value="tagValueH3"
         * @param string style="tagStle"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "h3":
            /*+
             * H4
             *
             * <code>
             * <zhtml:h4 value="tagValueH4" style="tagStle" />
             * </code>
             *
             * @param string value="tagValueH4"
             * @param string style="tagStle"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * H4
         *
         * <code>
         * <zhtml:h4 value="tagValueH4" style="tagStle" />
         * </code>
         *
         * @param string value="tagValueH4"
         * @param string style="tagStle"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "h4":
            /*+
             * H5
             *
             * <code>
             * <zhtml:h5 value="tagValueH5" style="tagStle" />
             * </code>
             *
             * @param string value="tagValueH5"
             * @param string style="tagStle"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * H5
         *
         * <code>
         * <zhtml:h5 value="tagValueH5" style="tagStle" />
         * </code>
         *
         * @param string value="tagValueH5"
         * @param string style="tagStle"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "h5":
            /*+
             * H6
             *
             * <code>
             * <zhtml:h6 value="tagValueH6" style="tagStle" />
             * </code>
             *
             * @param string value="tagValueH6"
             * @param string style="tagStle"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * H6
         *
         * <code>
         * <zhtml:h6 value="tagValueH6" style="tagStle" />
         * </code>
         *
         * @param string value="tagValueH6"
         * @param string style="tagStle"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "h6":
            $strParam = ztagParam($arrParam, "align,id,style");
            if ($strTransform) {
                $strContent = ztagTransform($strContent, $strTransform);
            }
            $arrayTag[$tagId][ztagResult] = "<{$tagFunction}{$strParam}>{$strContent}</{$tagFunction}>";
            break;
            /*+
             * A
             *
             * <code>
             * <zhtml:a href="tagURI" value="tagValue" target="tagTarget" />
             * </code>
             *
             * @param string href="tagURI"
             * @param string value="tagValue"
             * @param string target="tagTarget"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * A
         *
         * <code>
         * <zhtml:a href="tagURI" value="tagValue" target="tagTarget" />
         * </code>
         *
         * @param string href="tagURI"
         * @param string value="tagValue"
         * @param string target="tagTarget"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "a":
            $strParam = ztagParam($arrParam, "href,target,id,class,style");
            if ($strTransform) {
                $strContent = ztagTransform($strContent, $strTransform);
            }
            $arrayTag[$tagId][ztagResult] = "<a{$strParam}>{$strContent}</a>";
            break;
            /*+
             * PRE
             *
             * <code>
             * <zhtml:pre value="tagValue" target="tagTarget" />
             * </code>
             *
             * @param string value="tagValue"
             * @param string target="tagTarget"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * PRE
         *
         * <code>
         * <zhtml:pre value="tagValue" target="tagTarget" />
         * </code>
         *
         * @param string value="tagValue"
         * @param string target="tagTarget"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "pre":
            $strParam = ztagParam($arrParam, "id,class,style");
            if ($strTransform) {
                $strContent = ztagTransform($strContent, $strTransform);
            }
            $arrayTag[$tagId][ztagResult] = "<a{$strParam}>{$strContent}</a>";
            break;
            /*+
             * CODE
             *
             * <code>
             * <zhtml:code value="tagValue" target="tagTarget" />
             * </code>
             *
             * @param string value="tagValue"
             * @param string target="tagTarget"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * CODE
         *
         * <code>
         * <zhtml:code value="tagValue" target="tagTarget" />
         * </code>
         *
         * @param string value="tagValue"
         * @param string target="tagTarget"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "code":
            // @TODO Include Documentation for all zTags
        // @TODO Include Documentation for all zTags
        case "title":
        case "code":
        case "u":
        case "b":
        case "s":
        case "i":
        case "em":
        case "cite":
        case "sup":
        case "sub":
        case "center":
        case "kbd":
        case "ins":
        case "dfn":
        case "del":
        case "address":
        case "p":
        case "span":
        case "div":
            $strParam = ztagParam($arrParam, "align,style,class");
            if ($strTransform) {
                $strContent = ztagTransform($strContent, $strTransform);
            }
            $arrayTag[$tagId][ztagResult] = "<{$strTag}{$strParam}>{$strContent}</{$strTag}>";
            break;
            /*+
             * FRAME
             *
             * <code>
             * <zhtml:frame name="Body" src="$strSession" scrolling="auto" marginheight="0" marginwidth="0" />
             * </code>
             *
             * @param string name="Body" src="$strSession"
             * @param string scrolling="auto"
             * @param string marginheight="0"
             * @param string marginwidth="0"
             *
             * @author Ruben Zevallos Jr. <*****@*****.**>
             */
        /*+
         * FRAME
         *
         * <code>
         * <zhtml:frame name="Body" src="$strSession" scrolling="auto" marginheight="0" marginwidth="0" />
         * </code>
         *
         * @param string name="Body" src="$strSession"
         * @param string scrolling="auto"
         * @param string marginheight="0"
         * @param string marginwidth="0"
         *
         * @author Ruben Zevallos Jr. <*****@*****.**>
         */
        case "frame":
            $strParam = ztagParam($arrParam, "src,name,scrolling,marginheight,marginwidth");
            $arrayTag[$tagId][ztagResult] = "<{$strTag}{$strParam}>{$strContent}>";
            break;
        default:
            $errorMessage .= "<br />Undefined function \"{$tagFunction}\"";
    }
    ztagError($errorMessage, $arrayTag, $tagId);
}
コード例 #6
0
/**
 * Main zTag functions selector
 *
 * <code>
 * znosql_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder);
 * </code>
 *
 * @param integer $tagId array id of current zTag of $arrayTag array
 * @param string $tagFunction name of zTag function
 * @param array $arrayTag array with all compiled zTags
 * @param array $arrayTagId array with all Ids values
 * @param array $arrayOrder array with zTag executing order
 *
 * @since 1.0
 */
function znosql_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder)
{
    $arrParam = $arrayTag[$tagId][ztagParam];
    $strId = $arrParam["id"];
    $strUse = $arrParam["use"];
    $strDatabase = $arrParam["database"];
    $strCollection = $arrParam["collection"];
    $strName = $arrParam["name"];
    $strValue = $arrParam["value"];
    $strVar = $arrParam["var"];
    $strTransform = $arrParam["transform"];
    if ($arrayTag[$tagId][ztagContentWidth]) {
        $strContent = $arrayTag[$tagId][ztagContent];
    }
    $errorMessage = "";
    switch (strtolower($tagFunction)) {
        /*+
         * Open connection to a NoSQL Server
         *
         * <code>
         * <znosql:open id="mongoDB" driver="Mongo" host="username:password@mongodb.zyc.com.br:27017" database="Direito2" collection="pubPaginas" />
         * <znosql:open id="mongoDB" driver="Mongo" host="mongodb.zyc.com.br" username="******" password="******" port="27017" database="Direito2" collection="pubPaginas" />
         * </code>
         *
         * @param string id="mongoDB"
         * @param string driver="Mongo"
         * @param string host="username:password@mongodb.zyc.com.br:27017" <-- mongodb://[username:password@]host1[:port1][,host2[:port2:],...]
         * @param string username="******"
         * @param string password="******"
         * @param int port="27017"
         * @param string options="option=value;option2=value2"
         * @param string database="Direito2"
         * @param string collection="pubPaginas"
         * @param boolean persist="0|1|true|false|x"
         */
        case "open":
            $strDriver = $arrParam["driver"];
            $strHost = $arrParam["host"];
            $strUsername = $arrParam["username"];
            $strPassword = $arrParam["password"];
            $strPort = $arrParam["port"];
            $strPersist = $arrParam["persist"];
            $strOptions = $arrParam["options"];
            ztagReturnConstant($strHost);
            ztagReturnConstant($strDatabase);
            ztagReturnConstant($strUsername);
            ztagReturnConstant($strPassword);
            ztagReturnConstant($strPort);
            $errorMessage .= ztagParamCheck($arrParam, "id,driver,host");
            $strDriver = constant("nosql{$strDriver}");
            if (strlen($strUsername) && strlen($strPassword)) {
                $strHost = "{$strUsername}:{$strPassword}@{$strHost}";
            }
            if (strlen($strPort)) {
                $strHost = "{$strHost}:{$strPort}";
            }
            if (strlen($strOptions)) {
                $strHost = "{$strHost}?{$strOptions}";
            }
            if (extension_loaded('mongo')) {
                try {
                    $nosqlHandle = array();
                    if ($strPersist === "true" || $strPersist === "1" || ($strPersist = "x")) {
                        $dbHandle = new Mongo($strHost, array("persist" => "x"));
                    } else {
                        $dbHandle = new Mongo($strHost);
                    }
                    if ($strDatabase) {
                        $nosqlDB = $nosqlHandle->selectDB($strDatabase);
                    }
                } catch (MongoConnectionException $e) {
                    $errorMessage .= "<br />Cannot connect to {$strDriver} (" . $e->getMessage() . ")";
                }
                if (strlen($strCollection)) {
                    $nosqlColection = $nosqlDB->selectCollection($strCollection);
                }
            } else {
                $errorMessage .= "<br />{$strDriver} extention is not installed!";
            }
            // Set all NoSQL handler structure
            $nosqlHandle[nosqlHandleDriver] = $strDriver;
            $nosqlHandle[nosqlHandleHost] = $strHost;
            $nosqlHandle[nosqlHandleDatabaseName] = $dbDatabase;
            $nosqlHandle[nosqlHandleUser] = $strUsername;
            $nosqlHandle[nosqlHandlePassword] = $strPassword;
            $nosqlHandle[nosqlHandlePort] = $strPort;
            $nosqlHandle[nosqlHandleId] = $dbHandle;
            $nosqlHandle[nosqlHandleState] = dbHandleStateOpen;
            $arrayTagId[$strId][ztagIdHandle] = $nosqlHandle;
            $arrayTagId[$strId][ztagIdType] = idTypeNoSQL;
            $arrayTagId[$strId][ztagIdState] = idStateOpened;
            break;
            /*+
             * Close a Opened NoSQL Handle connection
             *
             * <code>
             * <znosql:close use="mongoDB">
             * </code>
             *
             * @param string use="mongoDB"
             *
             */
        /*+
         * Close a Opened NoSQL Handle connection
         *
         * <code>
         * <znosql:close use="mongoDB">
         * </code>
         *
         * @param string use="mongoDB"
         *
         */
        case "close":
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    $dbHandle = $nosqlHandle[nosqlHandleId];
                    $dbHandle->close();
                    $arrayTagId[$strUse][ztagIdHandle] = $dbHandle;
                    $arrayTagId[$strUse][ztagIdState] = idStateClosed;
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Do an Insert in currente Collection
             *
             * </code>
             * <znosql:insert use="mongoDB">
             *  pagCodigo="1"
             *  , pagNome="Page \"title\""
             *  , pagResumo='Page \'resume\''
             *  , pagDescricao:"Page body"
             *  , pagPalavrasChave:{"example","NoSQL"}
             *  , pagInclusao='2010/10/10'
             *  , pagAtivo=1
             * </znosql:insert>
             *
             * <znosql:insert use="mongoDB" value="$varInsert" />
             * </code>
             *
             *  @param string use="mongoDB"
             *  @param boolean safe="true|false|1|0"
             *  @param boolean fsync="true|false|1|0"
             */
        /*+
         * Do an Insert in currente Collection
         *
         * </code>
         * <znosql:insert use="mongoDB">
         *  pagCodigo="1"
         *  , pagNome="Page \"title\""
         *  , pagResumo='Page \'resume\''
         *  , pagDescricao:"Page body"
         *  , pagPalavrasChave:{"example","NoSQL"}
         *  , pagInclusao='2010/10/10'
         *  , pagAtivo=1
         * </znosql:insert>
         *
         * <znosql:insert use="mongoDB" value="$varInsert" />
         * </code>
         *
         *  @param string use="mongoDB"
         *  @param boolean safe="true|false|1|0"
         *  @param boolean fsync="true|false|1|0"
         */
        case "insert":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleCollection]) {
                        $dbHandle = $nosqlHandle[nosqlHandleId];
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $strCollection = $nosqlHandle[nosqlHandleCollectionName];
                        $dbHandleCollection = $nosqlHandle[nosqlHandleCollection];
                        // Prepare the tag content
                        if (strlen($strContent)) {
                            $contentArray = $strContent;
                        }
                        if (strlen($strValue)) {
                            $contentArray = $strValue;
                        }
                        if (strlen($contentArray)) {
                            $contentArray = ztagVars($contentArray, $arrayTagId);
                        }
                        if (strlen($contentArray)) {
                            $contentArray = ztagRun($contentArray, 0, $arrayTagId);
                        }
                        if (!strlen($strContent) && !strlen($strValue)) {
                            $errorMessage .= ztagParamCheck($arrParam, "value");
                        }
                        if (strlen($strTransform) && strlen($contentArray)) {
                            $contentArray = ztagTransform($contentArray, $strTransform);
                        }
                        $contentArray = znosql_lib_Content2Array($contentArray);
                        // @TODO Think how to manage the safe option and it's MongoCursorException
                        try {
                            $dbResult = $dbHandleCollection->insert($contentArray);
                            // echo "<br /><pre>".print_r($contentArray, 1)."</pre>";
                            if (!strlen($dbResult)) {
                                $errorMessage .= "<br />Cannot insert into collection {$strCollection} at database {$strDatabase}  <pre>" . print_r($dbResult, 1) . "</pre>";
                            }
                        } catch (MongoException $e) {
                            $errorMessage .= "<br />Cannot insert into collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")";
                        }
                        $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Execute a NoSQL commands
             *
             * <code>
             * <znosql:get use="mongoDB">
             *   Commands
             * </znosql:get>
             * </code>
             *
             * @param string use="mongoDB"
             *
             */
        /*+
         * Execute a NoSQL commands
         *
         * <code>
         * <znosql:get use="mongoDB">
         *   Commands
         * </znosql:get>
         * </code>
         *
         * @param string use="mongoDB"
         *
         */
        case "getone":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleCollection]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $strCollection = $nosqlHandle[nosqlHandleCollectionName];
                        $dbHandleCollection = $nosqlHandle[nosqlHandleCollection];
                        // Prepare the tag content
                        if (strlen($strContent)) {
                            $contentArray = $strContent;
                        }
                        if (strlen($strValue)) {
                            $contentArray = $strValue;
                        }
                        if (strlen($contentArray)) {
                            $contentArray = ztagVars($contentArray, $arrayTagId);
                        }
                        if (!strlen($strContent) && !strlen($strValue)) {
                            $errorMessage .= ztagParamCheck($arrParam, "value");
                        }
                        if (strlen($strTransform) && strlen($contentArray)) {
                            $contentArray = ztagTransform($contentArray, $strTransform);
                        }
                        $contentArray = ltrim($contentArray, "\r\n");
                        $contentArray = rtrim($contentArray, "\r\n");
                        preg_match_all("%criteria\\s*{(?P<criteria>(?:\\}|[^}])*?)}(\\s*,\\s*fields\\s*{(?P<fields>(?:\\}|[^}])*?)})?%", $contentArray, $Matches, PREG_OFFSET_CAPTURE);
                        $arrayCriteria = znosql_lib_Content2Array($Matches["criteria"][0][0]);
                        if ($Matches["fields"][0][0]) {
                            $arrayFields = znosql_lib_Content2Array($Matches["fields"][0][0], 1);
                        }
                        // @TODO Think how to manage the safe option and it's MongoCursorException
                        try {
                            if (count($arrayFields)) {
                                $dbResult = $dbHandleCollection->findOne($arrayCriteria, $arrayFields);
                            } else {
                                $dbResult = $dbHandleCollection->findOne($arrayCriteria);
                            }
                            if (strlen($strVar) && count($dbResult)) {
                                $arrayTagId["\$" . $strVar][ztagIdValue] = $value;
                                $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
                            }
                        } catch (MongoConnectionException $e) {
                            $errorMessage .= "<br />Cannot find the criteria into collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")";
                        }
                        $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Execute a NoSQL commands
             *
             * <code>
             * <znosql:get use="mongoDB">
             *   Commands
             * </znosql:execute>
             * </code>
             *
             * $query - the evaluation or "where" expression
             * $orderby - sort order desired
             * $hint - hint to query optimizer
             * $explain - if true, return explain plan results instead of query results
             * $snapshot - if true, "snapshot mode"
             */
        /*+
         * Execute a NoSQL commands
         *
         * <code>
         * <znosql:get use="mongoDB">
         *   Commands
         * </znosql:execute>
         * </code>
         *
         * $query - the evaluation or "where" expression
         * $orderby - sort order desired
         * $hint - hint to query optimizer
         * $explain - if true, return explain plan results instead of query results
         * $snapshot - if true, "snapshot mode"
         */
        case "getall":
            /*$errorMessage .= ztagParamCheck($arrParam, "use");
            	    // $cursor = $this->collection->find($f);
            
            	    $k = array();
            	    $i = 0;
            
            	    while( $cursor->hasNext())
            	    {
            	        $k[$i] = $cursor->getNext();
            	      $i++;
            	    }
            
            	    // return $k;
            	     *
            	     */
            break;
            /*+
             * Do an Update in currente Collection
             *
             * <code>
             * <znosql:update use="mongoDB">
             *  criteria{pagCodigo="1"}
             *  , set{pagNome="Page \"title\" Updated"
             *  , pagResumo='Page \'resume\''
             *  , pagDescricao:"Page body"
             *  , pagPalavrasChave:{"example","NoSQL"}
             *  , pagInclusao='2010/10/10'
             *  , pagAtivo=1
             *  }
             * </znosql:update>
             *
             * <znosql:update use="mongoDB" criteria="$varCriteria" value="$varInsert" />
             * </code>
             *
             * @param string use="mongoDB"
             * @param boolean upsert="true|false|1|0"
             * @param boolean multiple="true|false|1|0"
             * @param boolean safe="true|false|1|0"
             * @param boolean fsync="true|false|1|0"
             */
        /*+
         * Do an Update in currente Collection
         *
         * <code>
         * <znosql:update use="mongoDB">
         *  criteria{pagCodigo="1"}
         *  , set{pagNome="Page \"title\" Updated"
         *  , pagResumo='Page \'resume\''
         *  , pagDescricao:"Page body"
         *  , pagPalavrasChave:{"example","NoSQL"}
         *  , pagInclusao='2010/10/10'
         *  , pagAtivo=1
         *  }
         * </znosql:update>
         *
         * <znosql:update use="mongoDB" criteria="$varCriteria" value="$varInsert" />
         * </code>
         *
         * @param string use="mongoDB"
         * @param boolean upsert="true|false|1|0"
         * @param boolean multiple="true|false|1|0"
         * @param boolean safe="true|false|1|0"
         * @param boolean fsync="true|false|1|0"
         */
        case "update":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleCollection]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $strCollection = $nosqlHandle[nosqlHandleCollectionName];
                        $dbHandleCollection = $nosqlHandle[nosqlHandleCollection];
                        // Prepare the tag content
                        if (strlen($strContent)) {
                            $contentArray = $strContent;
                        }
                        if (strlen($strValue)) {
                            $contentArray = $strValue;
                        }
                        if (strlen($contentArray)) {
                            $contentArray = ztagVars($contentArray, $arrayTagId);
                        }
                        if (!strlen($strContent) && !strlen($strValue)) {
                            $errorMessage .= ztagParamCheck($arrParam, "value");
                        }
                        if (strlen($strTransform) && strlen($contentArray)) {
                            $contentArray = ztagTransform($contentArray, $strTransform);
                        }
                        $contentArray = ltrim($contentArray, "\r\n");
                        $contentArray = rtrim($contentArray, "\r\n");
                        preg_match_all("%criteria\\s*{(?P<criteria>(?:\\}|[^}])*?)}\\s*,\\s*set\\s*{(?P<set>(?:\\}|[^}])*?)}%", $contentArray, $Matches, PREG_OFFSET_CAPTURE);
                        // echo "<br /><pre>".print_r($Matches, 1)."</pre>";
                        $arrayCriteria = znosql_lib_Content2Array($Matches["criteria"][0][0]);
                        $arraySet = array('$set' => znosql_lib_Content2Array($Matches["set"][0][0]));
                        // @TODO Think how to manage the safe option and it's MongoCursorException
                        try {
                            $dbResult = $dbHandleCollection->update($arrayCriteria, $arraySet);
                            // echo "<br /><pre>".print_r($contentArray, 1)."</pre>";
                            if (!$dbResult) {
                                $errorMessage .= "<br />Cannot update the criteria into collection {$strCollection} at database {$strDatabase}  <pre>" . print_r($dbResult, 1) . "</pre>";
                            }
                        } catch (InvalidArgumentException $e) {
                            $errorMessage .= "<br />Cannot update the criteria into collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")";
                        }
                        $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Delete a criteria at current collection
             *
             * <code>
             * <znosql:delete use="mongoDB">
             *  pagCodigo="1"
             * </znosql:delete>
             *
             * <znosql:delete use="mongoDB" criteria="$varCriteria" />
             * </code>
             *
             * @param string use="mongoDB"
             * @param boolean justone="true|false|1|0"
             * @param boolean safe="true|false|1|0"
             * @param boolean fsync="true|false|1|0"
             */
        /*+
         * Delete a criteria at current collection
         *
         * <code>
         * <znosql:delete use="mongoDB">
         *  pagCodigo="1"
         * </znosql:delete>
         *
         * <znosql:delete use="mongoDB" criteria="$varCriteria" />
         * </code>
         *
         * @param string use="mongoDB"
         * @param boolean justone="true|false|1|0"
         * @param boolean safe="true|false|1|0"
         * @param boolean fsync="true|false|1|0"
         */
        case "delete":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleCollection]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $strCollection = $nosqlHandle[nosqlHandleCollectionName];
                        $dbHandleCollection = $nosqlHandle[nosqlHandleCollection];
                        // Prepare the tag content
                        if (strlen($strContent)) {
                            $contentArray = $strContent;
                        }
                        if (strlen($strValue)) {
                            $contentArray = $strValue;
                        }
                        if (strlen($contentArray)) {
                            $contentArray = ztagVars($contentArray, $arrayTagId);
                        }
                        if (!strlen($strContent) && !strlen($strValue)) {
                            $errorMessage .= ztagParamCheck($arrParam, "value");
                        }
                        if (strlen($strTransform) && strlen($contentArray)) {
                            $contentArray = ztagTransform($contentArray, $strTransform);
                        }
                        $contentArray = znosql_lib_Content2Array($contentArray);
                        // echo "<br /><pre>contentArray=".print_r($contentArray, 1)."</pre>";
                        // @TODO Think how to manage the safe option and it's MongoCursorException
                        try {
                            $dbResult = $dbHandleCollection->remove($contentArray);
                            // echo "<br /><pre>dbResult=".print_r($dbResult, 1)."</pre>";
                            if (!$dbResult) {
                                $errorMessage .= "<br />Cannot delete the criteria into collection {$strCollection} at database {$strDatabase}  <pre>" . print_r($dbResult, 1) . "</pre>";
                            }
                        } catch (InvalidArgumentException $e) {
                            $errorMessage .= "<br />Cannot delete the criteria into collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")";
                        }
                        $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Execute a NoSQL commands
             *
             * <code>
             * <znosql:execute use="mongoDB">
             *   Commands
             * </znosql:execute>
             * </code>
             *
             * @param string use="mongoDB"
             *
             */
        /*+
         * Execute a NoSQL commands
         *
         * <code>
         * <znosql:execute use="mongoDB">
         *   Commands
         * </znosql:execute>
         * </code>
         *
         * @param string use="mongoDB"
         *
         */
        case "execute":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            // Execute Close, but I don't know yet!
            $arrayTagId[$strUse][ztagIdState] = idStateClosed;
            // mongo->execute($cmd);
            break;
            /*+
             * Set a database for current Opened NoSQL connection
             *
             * <code>
             * <znosql:setdatabase use="mongoDB" name="Direito2" />
             * </code>
             *
             * @param string use="mongoDB"
             * @param string name="Direito2" The database name.
             */
        /*+
         * Set a database for current Opened NoSQL connection
         *
         * <code>
         * <znosql:setdatabase use="mongoDB" name="Direito2" />
         * </code>
         *
         * @param string use="mongoDB"
         * @param string name="Direito2" The database name.
         */
        case "setdatabase":
            $errorMessage .= ztagParamCheck($arrParam, "use,name");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    $dbHandle = $nosqlHandle[nosqlHandleId];
                    try {
                        $dbHandleDatabase = $dbHandle->selectDB($strName);
                        $nosqlHandle[nosqlHandleDatabaseName] = $strName;
                        $nosqlHandle[nosqlHandleDatabase] = $dbHandleDatabase;
                    } catch (InvalidArgumentException $e) {
                        $errorMessage .= "<br />Invalid database name {$strName} (" . $e->getMessage() . ")";
                    }
                    $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * List all databases
             *
             * <code>
             * <znosql:listdatabases use="mongoDB" id="mongoDBlist" var="databasesList" total="databasesTotalSize">
             *   <br /><znosql:field use="mongoDBlist" name="name" /> - <znosql:field use="mongoDBlist" name="sizeOnDisk" /> - <znosql:field use="mongoDBlist" name="empty" />
             * </znosql:listdatabases>
             * </code>
             *
             * @param string use="mongoDB" A NoSQL handle
             * @param string id="mongoDBlist" Id with array of each line
             * @param string var="databasesList" Variable with array of each line
             * @param string total="databasesTotalSize" Variable with total size
             */
        /*+
         * List all databases
         *
         * <code>
         * <znosql:listdatabases use="mongoDB" id="mongoDBlist" var="databasesList" total="databasesTotalSize">
         *   <br /><znosql:field use="mongoDBlist" name="name" /> - <znosql:field use="mongoDBlist" name="sizeOnDisk" /> - <znosql:field use="mongoDBlist" name="empty" />
         * </znosql:listdatabases>
         * </code>
         *
         * @param string use="mongoDB" A NoSQL handle
         * @param string id="mongoDBlist" Id with array of each line
         * @param string var="databasesList" Variable with array of each line
         * @param string total="databasesTotalSize" Variable with total size
         */
        case "listdatabases":
            $strTotal = $arrParam["total"];
            $errorMessage .= ztagParamCheck($arrParam, "use,id");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    $dbHandle = $nosqlHandle[nosqlHandleId];
                    $arrayDatabases = $dbHandle->listDBs();
                    $totalDbSize = $arrayDatabases['totalSize'];
                    foreach ($arrayDatabases["databases"] as $key => $value) {
                        if (strlen($strId)) {
                            $arrayTagId[$strId][ztagIdValue] = $arrayDatabases["databases"][$key];
                            $arrayTagId[$strId][ztagIdType] = idTypeValue;
                        }
                        if (strlen($strVar)) {
                            $arrayTagId["\$" . $strVar][ztagIdValue] = $arrayDatabases["databases"][$key];
                            $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
                        }
                        $strResult = ztagRun($strContent, 0, $arrayTagId);
                        $arrayTag[$tagId][ztagResult] .= $strResult;
                    }
                    if (strlen($strTotal)) {
                        $arrayTagId["\$" . $strTotal][ztagIdValue] = $arrayDatabases[totalSize];
                        $arrayTagId["\$" . $strTotal][ztagIdType] = idTypeFVar;
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Return the server Stats
             *
             * <code>
             * <znosql:getstats use="mongoDB" var="mongoStats" />
             * </code>
             *
             * @param string use="mongoDB"
             * @param string var="mongoStats"
             */
        /*+
         * Return the server Stats
         *
         * <code>
         * <znosql:getstats use="mongoDB" var="mongoStats" />
         * </code>
         *
         * @param string use="mongoDB"
         * @param string var="mongoStats"
         */
        case "getstats":
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    $dbHandle = $nosqlHandle[nosqlHandleId];
                    $arrayDatabases = $dbHandle->listDBs();
                    $dbHandleAdmin = $dbHandle->selectDB('admin');
                    $arrayReturn = array_merge($dbHandleAdmin->command(array('buildinfo' => 1)), $dbHandleAdmin->command(array('serverStatus' => 1)));
                    $profile = $dbHandleAdmin->command(array('profile' => -1));
                    $arrayReturn['profilingLevel'] = $profile['was'];
                    $arrayReturn['mongoDbTotalSize'] = round($totalDbSize / 1000000) . 'mb';
                    $prevError = $dbHandleAdmin->command(array('getpreverror' => 1));
                    if (!$prevError['n']) {
                        $arrayReturn['previousDbErrors'] = 'None';
                    } else {
                        $arrayReturn['previousDbErrors']['error'] = $prevError['err'];
                        $arrayReturn['previousDbErrors']['numberOfOperationsAgo'] = $prevError['nPrev'];
                    }
                    $arrayReturn['globalLock']['totalTime'] .= ' &#0181;Sec';
                    $arrayReturn['uptime'] = round($arrayReturn['uptime'] / 60) . ':' . str_pad($arrayReturn['uptime'] % 60, 2, '0', STR_PAD_LEFT) . ' minutes';
                    $arrayUnshift['mongo'] = $arrayReturn['version'] . ' (' . $arrayReturn['bits'] . '-bit)';
                    $arrayUnshift['mongoPhpDriver'] = Mongo::VERSION;
                    $arrayUnshift['phpMoAdmin'] = '1.0.8';
                    $arrayUnshift['php'] = PHP_VERSION . ' (' . (PHP_INT_MAX > 2200000000.0 ? 64 : 32) . '-bit)';
                    $arrayUnshift['gitVersion'] = $arrayReturn['gitVersion'];
                    unset($arrayReturn['ok'], $arrayReturn['version'], $arrayReturn['gitVersion'], $arrayReturn['bits']);
                    $arrayReturn = array_merge(array('version' => $arrayUnshift), $arrayReturn);
                    $iniIndex = array(-1 => 'Unlimited', 'Off', 'On');
                    $phpIni = array('allow_persistent', 'auto_reconnect', 'chunk_size', 'cmd', 'default_host', 'default_port', 'max_connections', 'max_persistent');
                    foreach ($phpIni as $ini) {
                        $key = 'php_' . $ini;
                        $arrayReturn[$key] = ini_get('mongo.' . $ini);
                        if (isset($iniIndex[$arrayReturn[$key]])) {
                            $arrayReturn[$key] = $iniIndex[$arrayReturn[$key]];
                        }
                    }
                    if (strlen($strVar)) {
                        $arrayTagId["\$" . $strVar][ztagIdValue] = $arrayReturn;
                        $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Repair the current Database
             *
             * <code>
             * <znosql:repairdatabase use="mongoDB" preserveclonedfiles="true" backuporiginalfiles="true" />
             * </code>
             *
             * @param boolean preserveclonedfiles="true|false|1|0"
             * @param boolean backuporiginalfiles="true|false|1|0"
             */
        /*+
         * Repair the current Database
         *
         * <code>
         * <znosql:repairdatabase use="mongoDB" preserveclonedfiles="true" backuporiginalfiles="true" />
         * </code>
         *
         * @param boolean preserveclonedfiles="true|false|1|0"
         * @param boolean backuporiginalfiles="true|false|1|0"
         */
        case "repairdatabase":
            $strPreserveClonedFiles = $arrParam["preserveclonedfiles"];
            $strBackupOriginalFiles = $arrParam["backuporiginalfiles"];
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleDatabase]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $dbHandleDatabase = $nosqlHandle[nosqlHandleDatabase];
                        try {
                            if ($strPreserveClonedFiles === "true" || $strPreserveClonedFiles === "1") {
                                $strPreserveClonedFiles = true;
                            }
                            if ($strBackupOriginalFiles === "true" || $strBackupOriginalFiles === "1") {
                                $strBackupOriginalFiles = true;
                            }
                            if (strlen($strPreserveClonedFiles) && !strlen($strBackupOriginalFiles)) {
                                $dbResult = $dbHandleDatabase->repair($strPreserveClonedFiles);
                            } elseif (strlen($strBackupOriginalFiles)) {
                                $dbResult = $dbHandleDatabase->repair($strPreserveClonedFiles, $strBackupOriginalFiles);
                            } else {
                                $dbResult = $dbHandleDatabase->repair();
                            }
                            if ($dbResult["ok"] != 1) {
                                $errorMessage .= "<br />Cannot repair the {$strDatabase} <pre>" . print_r($dbResult, 1) . "</pre>";
                            }
                        } catch (InvalidArgumentException $e) {
                            $errorMessage .= "<br />Invalid database name {$strDatabase} (" . $e->getMessage() . ")";
                        }
                        $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Drop current database
             *
             * <code>
             * <znosql:dropdatabase use="mongoDB" />
             * </code>
             *
             * @param string use="mongoDB"
             */
        /*+
         * Drop current database
         *
         * <code>
         * <znosql:dropdatabase use="mongoDB" />
         * </code>
         *
         * @param string use="mongoDB"
         */
        case "dropdatabase":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleDatabase]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $dbHandleDatabase = $nosqlHandle[nosqlHandleDatabase];
                        try {
                            $dbResult = $dbHandleDatabase->drop();
                            if ($dbResult["ok"] == 1) {
                                $nosqlHandle[nosqlHandleDatabaseName] = null;
                                $nosqlHandle[nosqlHandleDatabase] = null;
                            } else {
                                $errorMessage .= "<br />Cannot drop the database {$strDatabase} <pre>" . print_r($dbResult, 1) . "</pre>";
                            }
                        } catch (InvalidArgumentException $e) {
                            $errorMessage .= "<br />Cannot drop the database {$strDatabase} (" . $e->getMessage() . ")";
                        }
                        $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Set a collection for current database
             *
             * <code>
             * <znosql:setcollection use="mongoDB" name="pubPaginas" />
             * </code>
             *
             * @param string use="mongoDB"
             * @param string name="pubPaginas"
             */
        /*+
         * Set a collection for current database
         *
         * <code>
         * <znosql:setcollection use="mongoDB" name="pubPaginas" />
         * </code>
         *
         * @param string use="mongoDB"
         * @param string name="pubPaginas"
         */
        case "setcollection":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleDatabase]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $dbHandleDatabase = $nosqlHandle[nosqlHandleDatabase];
                        try {
                            $dbHandleCollection = $dbHandleDatabase->selectCollection($strName);
                            $nosqlHandle[nosqlHandleCollectionName] = $strName;
                            $nosqlHandle[nosqlHandleCollection] = $dbHandleCollection;
                        } catch (InvalidArgumentException $e) {
                            $errorMessage .= "<br />Invalid collection name {$strName} at database {$strDatabase} (" . $e->getMessage() . ")";
                        }
                        $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * List all databases
             *
             * <code>
             * <znosql:listcollections use="mongoDB" id="mongoDBlist" var="databasesList" total="databasesTotalSize">
             *   <br /><znosql:field use="mongoDBlist" name="name" /> - <znosql:field use="mongoDBlist" name="sizeOnDisk" /> - <znosql:field use="mongoDBlist" name="empty" />
             * </znosql:listcollections>
             * </code>
             *
             * @param string use="mongoDB" A NoSQL handle
             * @param string id="mongoDBlist" Id with array of each line
             * @param string var="databasesList" Variable with array of each line
             * @param string total="databasesTotalSize" Variable with total size
             */
        /*+
         * List all databases
         *
         * <code>
         * <znosql:listcollections use="mongoDB" id="mongoDBlist" var="databasesList" total="databasesTotalSize">
         *   <br /><znosql:field use="mongoDBlist" name="name" /> - <znosql:field use="mongoDBlist" name="sizeOnDisk" /> - <znosql:field use="mongoDBlist" name="empty" />
         * </znosql:listcollections>
         * </code>
         *
         * @param string use="mongoDB" A NoSQL handle
         * @param string id="mongoDBlist" Id with array of each line
         * @param string var="databasesList" Variable with array of each line
         * @param string total="databasesTotalSize" Variable with total size
         */
        case "listcollections":
            $strTotal = $arrParam["total"];
            $errorMessage .= ztagParamCheck($arrParam, "use,id");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleDatabase]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $dbHandleDatabase = $nosqlHandle[nosqlHandleDatabase];
                        $arrayCollections = $dbHandleDatabase->listCollections();
                        foreach ($arrayCollections as $dbHandleCollecion) {
                            if ($strId) {
                                $arrayTagId[$strId][ztagIdValue] = array("name" => $dbHandleCollecion->getName());
                                $arrayTagId[$strId][ztagIdType] = idTypeValue;
                            }
                            if ($strVar) {
                                $arrayTagId["\$" . $strVar][ztagIdValue] = array("name" => $dbHandleCollecion->getName());
                                $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
                            }
                            $strResult = ztagRun($strContent, 0, $arrayTagId);
                            $arrayTag[$tagId][ztagResult] .= $strResult;
                        }
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Drop a collection for current database
             *
             * <code>
             * <znosql:dropcollection use="mongoDB" />
             * </code>
             *
             * @param string use="mongoDB"
             */
        /*+
         * Drop a collection for current database
         *
         * <code>
         * <znosql:dropcollection use="mongoDB" />
         * </code>
         *
         * @param string use="mongoDB"
         */
        case "dropcollection":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleCollection]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $strCollection = $nosqlHandle[nosqlHandleCollectionName];
                        $dbHandleCollection = $nosqlHandle[nosqlHandleCollection];
                        try {
                            $dbResult = $dbHandleCollection->drop();
                            if ($dbResult["ok"] == 1) {
                                $nosqlHandle[nosqlHandleCollectionName] = null;
                                $nosqlHandle[nosqlHandleCollection] = null;
                            } else {
                                $errorMessage .= "<br />Cannot drop the collection {$strCollection} at database {$strDatabase}  <pre>" . print_r($dbResult, 1) . "</pre>";
                            }
                        } catch (InvalidArgumentException $e) {
                            $errorMessage .= "<br />Cannot drop the collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")";
                        }
                        $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Create a collection for current database
             *
             * </code>
             * <znosql:createcollection use="mongoDB" name="pubPaginas" />
             * </code>
             *
             * @param string use="mongoDB"
             * @param string name="pubPaginas" The name of the collection.
             * @param boolean capped="true|false|1|0" If the collection should be a fixed size.
             * @param int  size="10000000" If the collection is fixed size, its size in bytes.
             * @param int max="1000" If the collection is fixed size, the maximum number of elements to store in the collection.
             */
        /*+
         * Create a collection for current database
         *
         * </code>
         * <znosql:createcollection use="mongoDB" name="pubPaginas" />
         * </code>
         *
         * @param string use="mongoDB"
         * @param string name="pubPaginas" The name of the collection.
         * @param boolean capped="true|false|1|0" If the collection should be a fixed size.
         * @param int  size="10000000" If the collection is fixed size, its size in bytes.
         * @param int max="1000" If the collection is fixed size, the maximum number of elements to store in the collection.
         */
        case "createcollection":
            $errorMessage .= ztagParamCheck($arrParam, "use,name");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleDatabase]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $dbHandleDatabase = $nosqlHandle[nosqlHandleDatabase];
                        try {
                            $dbHandleCollection = $dbHandleDatabase->createCollection($strName);
                            $nosqlHandle[nosqlHandleCollectionName] = $strName;
                            $nosqlHandle[nosqlHandleCollection] = $dbHandleCollection;
                        } catch (InvalidArgumentException $e) {
                            $errorMessage .= "<br />Cannot create the collection {$strName} at database {$strDatabase} (" . $e->getMessage() . ")";
                        }
                        $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Create a collection for current database
             *
             * <code>
             * <znosql:createcollection use="mongoDB" from="pubPaginas" to="pubPaginasOld"/>
             * </code>
             *
             * @param string use="mongoDB"
             * @param string from="pubPaginas"
             * @param string to="pubPaginasOld"
             */
        /*+
         * Create a collection for current database
         *
         * <code>
         * <znosql:createcollection use="mongoDB" from="pubPaginas" to="pubPaginasOld"/>
         * </code>
         *
         * @param string use="mongoDB"
         * @param string from="pubPaginas"
         * @param string to="pubPaginasOld"
         */
        case "renamecollection":
            $strFrom = $arrParam["from"];
            $strTo = $arrParam["to"];
            $errorMessage .= ztagParamCheck($arrParam, "use,name");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    $dbHandle = $nosqlHandle[nosqlHandleId];
                    if ($nosqlHandle[nosqlHandleDatabase]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $dbResult = $dbHandle->selectDB('admin')->command(array('renameCollection' => "{$strDatabase}.{$strFrom}", 'to' => "{$strDatabase}.{$strTo}"));
                        echo "<pre>" . print_r($dbResult, 1) . "</pre>";
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * List all indexes for a Collection
             *
             * <code>
             * <znosql:listindexes use="mongoDB" collection="pubPaginas" />
             * </code>
             *
             * @param string use="mongoDB"
             * @param string collection="pubPaginas"
             */
        /*+
         * List all indexes for a Collection
         *
         * <code>
         * <znosql:listindexes use="mongoDB" collection="pubPaginas" />
         * </code>
         *
         * @param string use="mongoDB"
         * @param string collection="pubPaginas"
         */
        case "listindexes":
            return $this->mongo->selectCollection($collection)->getIndexInfo();
            break;
            /*+
             * Ensure a index of current collection
             *
             * <code>
             * <znosql:ensureindex use="mongoDB" />
             * </code>
             *
             * @param string use="mongoDB"
             */
        /*+
         * Ensure a index of current collection
         *
         * <code>
         * <znosql:ensureindex use="mongoDB" />
         * </code>
         *
         * @param string use="mongoDB"
         */
        case "ensureindex":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            if ($arrayTagId[$strUse][ztagIdType] === idTypeNoSQL) {
                if ($arrayTagId[$strUse][ztagIdState] === idStateOpened) {
                    $nosqlHandle = $arrayTagId[$strUse][ztagIdHandle];
                    if ($nosqlHandle[nosqlHandleCollection]) {
                        $strDatabase = $nosqlHandle[nosqlHandleDatabaseName];
                        $strCollection = $nosqlHandle[nosqlHandleCollectionName];
                        $dbHandleCollection = $nosqlHandle[nosqlHandleCollection];
                        try {
                            $dbResult = $dbHandleCollection->ensureIndex();
                            $unique = $unique ? true : false;
                            //signature requires a bool in both Mongo v. 1.0.1 and 1.2.0
                            // mongo->selectCollection($collection)->ensureIndex($indexes, $unique);
                            if ($dbResult["ok"] == 1) {
                                $nosqlHandle[nosqlHandleCollectionName] = null;
                                $nosqlHandle[nosqlHandleCollection] = null;
                            } else {
                                $errorMessage .= "<br />Cannot drop the collection {$strCollection} at database {$strDatabase}  <pre>" . print_r($dbResult, 1) . "</pre>";
                            }
                        } catch (InvalidArgumentException $e) {
                            $errorMessage .= "<br />Cannot drop the collection {$strCollection} at database {$strDatabase} (" . $e->getMessage() . ")";
                        }
                        $arrayTagId[$strUse][ztagIdHandle] = $nosqlHandle;
                    } else {
                        $errorMessage .= "<br />The {$strUse} NoSQL handler do not have a database defined!";
                    }
                } else {
                    $errorMessage .= "<br />The {$strUse} NoSQL handler is not Open!";
                }
            } else {
                $errorMessage .= "<br />The {$strUse} type is not a NoSQL!";
            }
            break;
            /*+
             * Delete a index for a Collection
             *
             * <code>
             * <znosql:deleteindex use="mongoDB" collection="pubPaginas" index="pagNome"/>
             * </code>
             *
             * @param string use="mongoDB"
             * @param string collection="pubPaginas"
             * @param string index="pagNome"
             *
             */
        /*+
         * Delete a index for a Collection
         *
         * <code>
         * <znosql:deleteindex use="mongoDB" collection="pubPaginas" index="pagNome"/>
         * </code>
         *
         * @param string use="mongoDB"
         * @param string collection="pubPaginas"
         * @param string index="pagNome"
         *
         */
        case "deleteindex":
            // mongo->selectCollection($collection)->deleteIndex($index);
            break;
            /*+
             * Return the content of name field of current record
             *
             * </code>
             * <zdb:field use="mongoDBlist" name="name" />
             * </code>
             *
             * @param string use="mongoDBlist" - The Id Handle from current array
             * @param string name="name"
             */
        /*+
         * Return the content of name field of current record
         *
         * </code>
         * <zdb:field use="mongoDBlist" name="name" />
         * </code>
         *
         * @param string use="mongoDBlist" - The Id Handle from current array
         * @param string name="name"
         */
        case "field":
            $strVar = $arrParam["var"];
            $errorMessage .= ztagParamCheck($arrParam, "use,name");
            $fieldArray = $arrayTagId[$strUse][ztagIdValue];
            $fieldValue = $fieldArray[$strName];
            if (strlen($strTransform)) {
                $fieldValue = ztagTransform($fieldValue, $strTransform);
            }
            if (strlen($strVar)) {
                $arrayTagId["\$" . $strVar][ztagIdValue] = $fieldValue;
                $arrayTagId["\$" . $strVar][ztagIdType] = idTypeField;
            }
            $arrayTag[$tagId][ztagResult] = $fieldValue;
            break;
        default:
            $errorMessage .= "<br />Undefined function \"{$tagFunction}\"";
    }
    ztagError($errorMessage, $arrayTag, $tagId);
}
コード例 #7
0
ファイル: ztag.php プロジェクト: BGCX262/ztag-svn-to-git
/**
 * Processa as variáveis de todos os parâmetros da matriz
 *
 * <code>
 * ztagVarsParam($arrParam, $arrayTagId);
 * </code>
 *
 * @param array $arrParam array com os parâmetros
 * @param array $arrayTagId matriz com todas as variáveis
 *
 * @return array matriz $arrParam atualizada
 *
 * @since 1.0
 */
function ztagVarsParam($arrParam, $arrayTagId)
{
    /* @TODO incluir o transform nas varíaveis no momento da leitura incluindo o -> mais os comandos, como:
     * $pagNome->upper()spacify()
     * $pagNome->lower->spacify->truncate()
     * $pagNome->lower->truncate(30)->spacify()
     * $pagNome->lower->spacify->truncate(30:, ". . .")
     *
     * Novas:
     * capitalize - mesmo que o sentence
     * count(blnSpaces=1) - Conta caracteres blnSpaces = false, não inclui espaços
     * cat("Concaternar") - Concatena o texto na variável
     * countP() ou countParagraphs - Conta parágrafos
     * countS() ou countSentences - Conta sentenças
     * countW() ou countWords - Conta palavras
     * dateFormat("formato") - Formata data como no PHP
     * default(valor default) - Valor default para uma variável
     * escape() - retorna os caracteres deixando a apresentação do HTML contido
     * indent()(quantidade, "caracter) - indenta a "quantidade" de caracteres, sendo 4 o padrão e " " o padrão do caracter
     * lower() ou toLower - converte todas as letras para minúculas
     * upper() ou toUpper - converte todas as letras para minúsculas
     * nl2br() - converte todos os \r\n para <br />
     * nl2p() - converte todos os \r\n para <p>conteúdo da linha</p>
     * nl2Tag("tag") - converte todos os \r\n para a <tag>conteúdo da linha</tag> ou somente <tag>
     * regexReplate(expressão, resultado) - executa o replace usando regEx
     * replace(find, replace) - executa o replace
     * spacify(int, caracter) - inclui espaços entre cada caracter da variável
     * stringFormtat("string no formato do printf") - formata a string com o formato do printf
     * strip("caracter") troca \s+ \n+ \t+ pelo caracter definido
     * stripTags() - some com todas as tags <...>
     * truncate(limit, "texto adicional", blnWord=0) - trunca os caracteres no limite e poderá incluir o texto adicional e/ou truncar na palavra.
     * wordWrap(limit, "\n") - inclui no limite \n sempre no limite definido ou com a string definida
     *
     * <zconfig:Load file="Arquivo" section="Sessão" />
     *
     * <zc:foreach from="array" item="" key="chave" var="variável do for each">
     * <foreach:first /> - se estiver na 1a
     * <foreach:last /> - se for a última
     * </zc:foreach>
     *
     * <foreach:total /> - número de iterações do foreach
     *
     * <zc:if expression="Expressão">
     *   Conteúdo que será executado/apresentado no then
     *   <zc:elseif expression="Expressão" />
     *   Conteúdo que será apresentado no else
     *   <zc:else />
     *   Conteúdo que será apresentado no else
     * </zc:if>
     *
     * <zc:switch expression="expressão">
     *   <zc:case expression="expressão" />
     *     Valor que será executado no case
     *
     *   <zc:case expression="expressão" />
     *     Valor que será executado no case
     *
     *   <zc:defaiçt />
     *     Valor que será executado no caso de nenhum case ter dado
     * </zc:switch>
     *
     * <zliteral:create id="id">
     *   Bloco que será apresentado sem processamento
     * </zliteral:create>
     *
     * <zcounter:set id="Nome do contador" />
     *
     * Ou talvez usando o {$varInt++}
     * Ou talvez usando o {$varInt--}
     *
     * Define uma variável cíclica... todas as vezes que você usar o valor, ele trocará o valor circularmente
     * <zvar:cicle id="bgColor" cicles="gray,lightgray,yellow" />
     * <tr bgcolor="$bgColor"> <-- Mostra o gray
     * <tr bgcolor="$bgColor"> <-- Mostra o lightgray
     * <tr bgcolor="$bgColor"> <-- Mostra o yellow
     *
     * <zeval />
     *
     * <ztextformat:set wrap="valor" indent="4">
     * </ztextformat:set>
     *
     *
     * @TODO Estudar uma forma de colocar no código variáveis e fórmulas
     *
     * Talvez usando o
     * Mostrar {$nomeVariavel}
     * Operações {$nomeVariavel * $nomeVariavel}
     * Atribuição {$variavelString = "Conteúdo"}
     * Atribuição {$variavelInt1  = 1}
     * Atribuição {$variavelInt2  = 2}
     * Comparação {$variavelInt1 === $variavelInt2}
     * Transformação {$variavelString->sentence()->substr(1, 2)}
     */
    if (is_array($arrParam)) {
        foreach ($arrParam as $keyParam => $valueParam) {
            // Seleciona somente os parâmetros que tiveram variáveis
            preg_match_all("%(?P<var>(?P<type>[\$@#!])[\\w_-]+)(?P<param>(\\[([\"]?.*?[\"]?|['].*?['])?\\])*)?%si", $valueParam, $Matches, PREG_OFFSET_CAPTURE);
            if (preg_last_error()) {
                debugError("<b>preg_last_error</b>:" . preg_last_error());
            }
            $patterns = array();
            $replacements = array();
            $i = 0;
            foreach ($Matches[0] as $key => $value) {
                $strVar = $Matches["var"][$key][0];
                $strType = $Matches["type"][$key][0];
                $patterns[$i] = "/\\{$strVar}/";
                if ($strType === "#") {
                    $replacements[$i++] = ztagReturnConstant($strVar);
                } else {
                    if ($strType === "!") {
                        $replacements[$i++] = $_SESSION[substr($strVar, 1, strlen($strVar))];
                    } else {
                        $strParam = $Matches["param"][$key][0];
                        // Processa as matrizes
                        if ($strParam) {
                            // Recupera a array que será utilizada
                            $varVar = $arrayTagId[$strVar][ztagIdValue];
                            if (is_array($varVar)) {
                                // Localiza cada um dos parâmetros para o processamento
                                preg_match_all("%\\[(?P<inner>[\"']?(?P<param>.+?)[\"']?)\\]%si", $strParam, $MatchesParam, PREG_OFFSET_CAPTURE);
                                // debugError($MatchesParam, 1);
                                $strEval = "return \$varVar";
                                $strPaternParam = "";
                                foreach ($MatchesParam[0] as $keyInner => $valueInner) {
                                    $strParamContent = ztagVars($MatchesParam["param"][$keyInner][0], $arrayTagId);
                                    if (preg_match("/\\d+/", $strParamContent)) {
                                        $strEval .= "[{$strParamContent}]";
                                    } else {
                                        $strEval .= "[\"{$strParamContent}\"]";
                                    }
                                    $strPaternParam .= "\\[" . $MatchesParam["inner"][$keyInner][0] . "\\]";
                                }
                                $strEval .= ";";
                                $patterns[$i] = "/\\{$strVar}{$strPaternParam}/";
                                $replacements[$i++] = eval($strEval);
                            } else {
                                return "The {$strVar} is not a array!";
                            }
                        } else {
                            $replacements[$i++] = $arrayTagId[$strVar][ztagIdValue];
                        }
                    }
                }
            }
            $arrParam[$keyParam] = preg_replace($patterns, $replacements, $valueParam);
        }
    }
    return $arrParam;
}
コード例 #8
0
ファイル: zctrl.inc.php プロジェクト: BGCX262/ztag-svn-to-git
/**
 * Main zTag functions selector
 *
 * <code>
 * zctrl_execute($tagId, $tagFunction, $arrayTag, $arrayTagId, $arrayOrder);
 * </code>
 *
 * @param integer $tagId array id of current zTag of $arrayTag array
 * @param string $tagFunction name of zTag function
 * @param array $arrayTag array with all compiled zTags
 * @param array $arrayTagId array with all Ids values
 * @param array $arrayOrder array with zTag executing order
 *
 * @since 1.0
 */
function zctrl_zexecute($tagId, $tagFunction, &$arrayTag, &$arrayTagId, $arrayOrder)
{
    global $ztagExit;
    $arrParam = $arrayTag[$tagId][ztagParam];
    $strId = $arrParam["id"];
    $strUse = $arrParam["use"];
    $strValue = $arrParam["value"];
    $strKey = $arrParam["key"];
    $strTransform = $arrParam["transform"];
    $strMessage = $arrParam["message"];
    if ($arrayTag[$tagId][ztagContentWidth]) {
        $strContent = $arrayTag[$tagId][ztagContent];
    }
    $errorMessage = "";
    switch (strtolower($tagFunction)) {
        /*+
         * Iterate over arrays executing it's content many time as it's content.
         *
         * <code>
         * <zctrl:foreach use="getAll" value="value">
         *   <zhtml:b value="$key" />: <zvar:show use="$value" /><br />
         * </zctrl:foreach>
         *
         * <zctrl:foreach use="getAll" key="key" value="value">
         *   <zhtml:b value="$key" />: <zvar:show use="$value" /><br />
         * </zctrl:foreach>
         * </code>
         *
         * @param string use="getAll" Variable array
         * @param string key="key" Variable where the array Key with saved
         * @param string value="value" Variable where the array Value with saved
         * @param string filename="/Alianca8/File.txt"
         * @param string filetype="txt"
         * @param string show="0"
         */
        case "foreach":
            $strFileName = $arrParam["filename"];
            $strFileType = $arrParam["filetype"];
            $strShow = strtolower($arrParam["show"]);
            $errorMessage .= ztagParamCheck($arrParam, "use,value");
            if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) {
                $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!";
            }
            // $strArray = $arrayTagId["$".$strUse][ztagIdValue];
            preg_match_all('%^(?P<var>\\w+)\\[(?P<index>[^\\]]+)\\]$%', $strUse, $Matches, PREG_OFFSET_CAPTURE);
            if (count($Matches[0][0])) {
                $var = $Matches["var"][0][0];
                $index = $Matches["index"][0][0];
                $strArray = $arrayTagId["\$" . $var][ztagIdValue];
                $strArray = $strArray[$index];
            } else {
                if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) {
                    $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!";
                }
                $strArray = $arrayTagId["\$" . $strUse][ztagIdValue];
            }
            if (is_array($strArray)) {
                if (strlen($strValue) && !strlen($strKey)) {
                    foreach ($strArray as $value) {
                        $arrayTagId["\$" . $strValue][ztagIdValue] = $value;
                        $arrayTagId["\$" . $strValue][ztagIdType] = idTypeFVar;
                        $arrayTag[$tagId][ztagResult] .= ztagRun($strContent, 0, $arrayTagId);
                        if ($ztagExit) {
                            break;
                        }
                    }
                } else {
                    foreach ($strArray as $key => $value) {
                        $arrayTagId["\$" . $strKey][ztagIdValue] = $key;
                        $arrayTagId["\$" . $strKey][ztagIdType] = idTypeFVar;
                        $arrayTagId["\$" . $strValue][ztagIdValue] = $value;
                        $arrayTagId["\$" . $strValue][ztagIdType] = idTypeFVar;
                        $arrayTag[$tagId][ztagResult] .= ztagRun($strContent, 0, $arrayTagId);
                        if ($ztagExit) {
                            break;
                        }
                    }
                }
                if ($strFileName) {
                    $strFileName = str_replace("\\", "/", $strFileName);
                    if (substr($strFileName, 0, 1) === "/") {
                        $strFileName = substr($strFileName, 1);
                    }
                    $strFileName = SiteRootDir . $strFileName;
                    if (!($handleFile = fopen($strFileName, "w"))) {
                        $errorMessage .= "\r\nCannot open file ({$strFileName})";
                    } else {
                        if (fwrite($handleFile, $arrayTag[$tagId][ztagResult]) === FALSE) {
                            $errorMessage .= "\r\nCannot write to file ({$strFileName})";
                        }
                    }
                    fclose($handleFile);
                }
                if ($strShow === "false" || $strShow === "0") {
                    $arrayTag[$tagId][ztagResult] = "";
                }
            }
            break;
            /*+
             * Define a conditional execution of code fragments.
             *
             * <code>
             * <zctrl:if value="$urlAssunto0" operator="e|ne|gt|gte|lt|lte" with="0" var="ifVar" >
             * </zctrl:if>
             *
             * <zctrl:if value="$urlAssunto0" function="empty()|true()|false()|len()">
             * </zctrl:if>
             *
             * <zctrl:if value="$urlAssunto0" transform="substr(1, 3)" operator="=|<>|>|>=|<|=" with="test">
             * </zctrl:if>
             * </code>
             *
             * @param string value="value" Variable or value to be used.
             * @param string operator="e|ne|gt|gte|lt|lte" operator to be used
             * @param string with="0" second part of an boolean expression
             * @param string transform="substr(1, 3)" Tranform the value's content
             * @param string function="empty()|true()|false()|len()" Apply a function to value's content and check if result is true
             * @param string var="ifVar" Variable to save all if result
             * @param string show="1|0|true|false" False to not show the If result content
             */
        /*+
         * Define a conditional execution of code fragments.
         *
         * <code>
         * <zctrl:if value="$urlAssunto0" operator="e|ne|gt|gte|lt|lte" with="0" var="ifVar" >
         * </zctrl:if>
         *
         * <zctrl:if value="$urlAssunto0" function="empty()|true()|false()|len()">
         * </zctrl:if>
         *
         * <zctrl:if value="$urlAssunto0" transform="substr(1, 3)" operator="=|<>|>|>=|<|=" with="test">
         * </zctrl:if>
         * </code>
         *
         * @param string value="value" Variable or value to be used.
         * @param string operator="e|ne|gt|gte|lt|lte" operator to be used
         * @param string with="0" second part of an boolean expression
         * @param string transform="substr(1, 3)" Tranform the value's content
         * @param string function="empty()|true()|false()|len()" Apply a function to value's content and check if result is true
         * @param string var="ifVar" Variable to save all if result
         * @param string show="1|0|true|false" False to not show the If result content
         */
        case "if":
            $strOperator = $arrParam["operator"];
            $strWith = $arrParam["with"];
            $strFunction = $arrParam["function"];
            $strVar = $arrParam["var"];
            $strShow = $arrParam["show"];
            if (strlen($strOperator)) {
                $errorMessage .= ztagParamCheck($arrParam, "value,operator,with");
                if (strlen($strTransform)) {
                    $strValue = ztagTransform($strValue, $strTransform);
                }
                switch (strtolower($strOperator)) {
                    case "e":
                        $strOperator = "==";
                        break;
                    case "ne":
                        $strOperator = "<>";
                        break;
                    case "gt":
                        $strOperator = ">";
                        break;
                    case "gte|lt|lte":
                        $strOperator = ">=";
                        break;
                    case "lt|lte":
                        $strOperator = "<";
                        break;
                    case "lte":
                        $strOperator = "<=";
                        break;
                    default:
                        $errorMessage .= "<br />Operator \"{$strOperator}\" does not exist!";
                }
                $strEVal = "if(\$strValue {$strOperator} \$strWith) {return 1;} else {return 0;}";
                $strValue = eval($strEVal);
            } else {
                if (strlen($strFunction)) {
                    $errorMessage .= ztagParamCheck($arrParam, "value,function");
                    if (strlen($strTransform)) {
                        $strValue = ztagTransform($strValue, $strTransform);
                    }
                    if (strlen($strFunction)) {
                        $strValue = ztagTransform($strValue, $strFunction);
                    }
                } else {
                    $errorMessage .= ztagParamCheck($arrParam, "value,function");
                }
            }
            if ($strValue) {
                $getValue .= ztagRun($strContent, 0, $arrayTagId);
                if (($strShow != "false" || $strShow != "0") && strlen($getValue)) {
                    $arrayTag[$tagId][ztagResult] = $getValue;
                }
                if (strlen($strVar) && strlen($getValue)) {
                    $arrayTagId["\$" . $strVar][ztagIdValue] = $getValue;
                    $arrayTagId["\$" . $strVar][ztagIdLength] = strlen($getValue);
                    $arrayTagId["\$" . $strVar][ztagIdType] = idTypeFVar;
                }
            }
            break;
            /*+
             * Output a message and terminate the current script.
             *
             * <code>
             * <zctrl:die message="The script die here!" />
             *
             * <zctrl:die>
             *   The script die here!
             * </zctrl:die>
             * </code>
             *
             * @param string message="value" Variable or value to be printed
             */
        /*+
         * Output a message and terminate the current script.
         *
         * <code>
         * <zctrl:die message="The script die here!" />
         *
         * <zctrl:die>
         *   The script die here!
         * </zctrl:die>
         * </code>
         *
         * @param string message="value" Variable or value to be printed
         */
        case "die":
            /*+
             * Output a message and terminate the current script.
             *
             * <code>
             * <zctrl:exit message="The script exited here!" />
             *
             * <zctrl:exit>
             *   The script exit here!
             * </zctrl:exit>
             * </code>
             *
             * @param string message="value" Variable or value to be printed
             */
        /*+
         * Output a message and terminate the current script.
         *
         * <code>
         * <zctrl:exit message="The script exited here!" />
         *
         * <zctrl:exit>
         *   The script exit here!
         * </zctrl:exit>
         * </code>
         *
         * @param string message="value" Variable or value to be printed
         */
        case "exit":
            $ztagExit = 1;
            if (strlen($strContent)) {
                $strMessage = ztagVars($strContent, $arrayTagId);
            }
            if (strlen($strMessage)) {
                $arrayTag[$tagId][ztagResult] = $strMessage;
            }
            break;
            /*+
             * Output a string
             *
             * <code>
             * <zctrl:echo message="This an echo message" />
             *
             * <zctrl:echo>
             * This an echo message
             * </zctrl:echo>
             * </code>
             *
             * @param string message="value" Variable or value to be used
             */
        /*+
         * Output a string
         *
         * <code>
         * <zctrl:echo message="This an echo message" />
         *
         * <zctrl:echo>
         * This an echo message
         * </zctrl:echo>
         * </code>
         *
         * @param string message="value" Variable or value to be used
         */
        case "echo":
            /*+
             * Output a string
             *
             * <code>
             * <zctrl:print message="This a print message" />
             *
             * <zctrl:print>
             * This a print message
             * </zctrl:print>
             * </code>
             *
             * @param string message="value" Variable or value to be used
             */
        /*+
         * Output a string
         *
         * <code>
         * <zctrl:print message="This a print message" />
         *
         * <zctrl:print>
         * This a print message
         * </zctrl:print>
         * </code>
         *
         * @param string message="value" Variable or value to be used
         */
        case "print":
            if (strlen($strContent)) {
                $strMessage = ztagVars($strContent, $arrayTagId);
                $arrParam["message"] = $strMessage;
            }
            $errorMessage .= ztagParamCheck($arrParam, "message");
            if (strlen($strTransform) && strlen($strMessage)) {
                $strMessage = ztagTransform($strMessage, $strTransform);
            }
            if (strlen($strMessage)) {
                ztagError($strMessage, $arrayTag, $tagId);
            }
            break;
            /*+
             * Dumps information about a variable
             *
             * <code>
             * <zctrl:dump message="<b>arrayDump</b>=" use="arrayDump" />
             * </code>
             *
             * @param string use="arrayDump" Variable to be dumped
             * @param string message="Message" Message to complement the Dump
             */
        /*+
         * Dumps information about a variable
         *
         * <code>
         * <zctrl:dump message="<b>arrayDump</b>=" use="arrayDump" />
         * </code>
         *
         * @param string use="arrayDump" Variable to be dumped
         * @param string message="Message" Message to complement the Dump
         */
        case "dump":
            $errorMessage .= ztagParamCheck($arrParam, "use");
            // echo "<hr><pre>".print_r($strUse,1)."</pre>";
            // echo "<hr><pre>".print_r($arrayTagId["$".$strUse][ztagIdValue],1)."</pre>";
            ztagError($strMessage . var_dump($arrayTagId["\$" . $strUse][ztagIdValue]), $arrayTag, $tagId);
            break;
            /*+
             * Prints human-readable information about a variable
             *
             * <code>
             * <zctrl:printr message="<b>arrayDump</b>=" use="arrayDump" />
             * </code>
             *
             * @param string use="arrayDump" Variable to be printed
             * @param string message="Message" Message to complement the Dump
             */
        /*+
         * Prints human-readable information about a variable
         *
         * <code>
         * <zctrl:printr message="<b>arrayDump</b>=" use="arrayDump" />
         * </code>
         *
         * @param string use="arrayDump" Variable to be printed
         * @param string message="Message" Message to complement the Dump
         */
        case "printr":
            ztagError(print_r($arrayTagId, 1), $arrayTag, $tagId);
            $errorMessage .= ztagParamCheck($arrParam, "use");
            ztagError($strMessage . print_r($arrayTagId["\$" . $strUse][ztagIdValue], 1), $arrayTag, $tagId);
            break;
            /*+
             * Iterate over arrays executing it's content many time as it's content.
             *
             * <code>
             * <zctrl:while value="$urlAssunto0" operator="e|ne|gt|gte|lt|lte" with="0" var="ifVar" >
             * </zctrl:while>
             *
             * <zctrl:while value="$urlAssunto0" function="empty()|true()|false()|len()">
             * </zctrl:while>
             *
             * <zctrl:while value="$urlAssunto0" transform="substr(1, 3)" operator="=|<>|>|>=|<|=" with="test">
             * </code>
             *
             * @param string use="getAll" Variable array
             * @param string key="key" Variable where the array Key with saved
             * @param string value="value" Variable where the array Value with saved
             */
        /*+
         * Iterate over arrays executing it's content many time as it's content.
         *
         * <code>
         * <zctrl:while value="$urlAssunto0" operator="e|ne|gt|gte|lt|lte" with="0" var="ifVar" >
         * </zctrl:while>
         *
         * <zctrl:while value="$urlAssunto0" function="empty()|true()|false()|len()">
         * </zctrl:while>
         *
         * <zctrl:while value="$urlAssunto0" transform="substr(1, 3)" operator="=|<>|>|>=|<|=" with="test">
         * </code>
         *
         * @param string use="getAll" Variable array
         * @param string key="key" Variable where the array Key with saved
         * @param string value="value" Variable where the array Value with saved
         */
        case "while":
            $errorMessage .= ztagParamCheck($arrParam, "use,value");
            if ($arrayTagId["\$" . $strUse][ztagIdType] != idTypeFVar) {
                $errorMessage .= "<br />The handle \"{$strUse}\" is not a var one!";
            }
            $strArray = $arrayTagId["\$" . $strUse][ztagIdValue];
            if (is_array($strArray)) {
                if (strlen($strValue) && !strlen($strKey)) {
                    foreach ($strArray as $value) {
                        $arrayTagId["\$" . $strValue][ztagIdValue] = $value;
                        $arrayTagId["\$" . $strValue][ztagIdType] = idTypeFVar;
                        $arrayTag[$tagId][ztagResult] .= ztagRun($strContent, 0, $arrayTagId);
                        if ($ztagExit) {
                            break;
                        }
                    }
                } else {
                    foreach ($strArray as $key => $value) {
                        $arrayTagId["\$" . $strKey][ztagIdValue] = $key;
                        $arrayTagId["\$" . $strKey][ztagIdType] = idTypeFVar;
                        $arrayTagId["\$" . $strValue][ztagIdValue] = $value;
                        $arrayTagId["\$" . $strValue][ztagIdType] = idTypeFVar;
                        $arrayTag[$tagId][ztagResult] .= ztagRun($strContent, 0, $arrayTagId);
                        if ($ztagExit) {
                            break;
                        }
                    }
                }
            }
            break;
        default:
            $errorMessage .= "<br />Undefined function \"{$tagFunction}\"";
    }
    ztagError($errorMessage, $arrayTag, $tagId);
}