<commit_before><?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

// +----------------------------------------------------------------------+
// | Akelos Framework - http://www.akelos.org                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006, Akelos Media, S.L.  & <NAME> |
// | Released under the GNU Lesser General Public License, see LICENSE.txt|
// +----------------------------------------------------------------------+

/**
 * @package AkelosFramework
 * @subpackage Ak
 * @author <NAME> <bermi a.t akelos c.om>
 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
 */

/**
* Define LOG Levels
* @todo Log events
*/
define('AK_LOG_NOTICE', 0);
define('AK_LOG_WARNING', 1);
define('AK_LOG_ERROR', 2);

defined('AK_FRAMEWORK_LANGUAGE') ? null : define('AK_FRAMEWORK_LANGUAGE', 'en');
defined('AK_DEV_MODE') ? null : define('AK_DEV_MODE', false);
defined('AK_AUTOMATIC_CONFIG_VARS_ENCRYPTION') ? null : define('AK_AUTOMATIC_CONFIG_VARS_ENCRYPTION', false);


/**
* Akelos Framework static functions
*
* Ak contains all the Akelos Framework static functions. This
* class acts like a name space to avoid naming collisions
* when PHP gets new functions into its core. And also to provide 
* additional functionality to existing PHP functions mantaining the same interface  
*
* @package AkelosFramework
* @subpackage Ak::static_functions
* @author <NAME> <bermi at akelos com>
* @copyright Copyright (c) 2002-2005, Akelos Media, S.L. http://www.akelos.org
* @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
*/
class Ak
{

    /**
    * Gets an instance of AdoDb database connection
    *
    * Whenever a database connection is required you can get a
    * reference to the default database connection by doing:
    *
    * $db =& Ak:db(); // get an adodb instance
    * 
    * AdoDB manual can be found at http://phplens.com/adodb/
    *
    * @access public
    * @param    string    $dns    A string containing Data Source Name (information
    * regarding database connection)
    * http://phplens.com/adodb/code.initialization.html#dsnsupport
    * @static
    * @return resource Php AdoDb instance.
    */
    function &db($dsn = null, $connection_id = null)
    {
        static $db;

        // In order to retrieve a database connection we just need to provide its identifier
        $connection_id = empty($connection_id) ?
        (empty($dsn) || strstr($dsn,':') ? 'default' : $dsn) :
        $connection_id;

        if(empty($db[$connection_id])){
            require_once(AK_CONTRIB_DIR.DS.'adodb'.DS.'adodb.inc.php');

            if(substr($dsn, 0, 6) == 'mysql:'){
                $dsn = substr_replace($dsn, 'mysqlt:', 0, 6);
            }

            if (!$db[$connection_id] = (AK_DEBUG ? NewADOConnection($dsn) : @NewADOConnection($dsn))){
                trigger_error(Ak::t('Connection to the database failed'), E_USER_ERROR);
                exit;
            }
            $db[$connection_id]->debug = AK_DEBUG == 2;
            defined('AK_DATABASE_CONNECTION_AVAILABLE') ? null : define('AK_DATABASE_CONNECTION_AVAILABLE', true);
            $dsn = '';
        }
        return $db[$connection_id];
    }



    /**
    * Gets a cache object singleton instance
    */
    function &cache()
    {
        static $cache;
        if(!isset($cache)){
            require_once(AK_LIB_DIR.DS.'AkCache.php');
            $cache = new AkCache();
        }
        return $cache;
    }


    function toUrl($options, $set_routes = false)
    {
        static $Map;
        if(empty($Map)){
            if($set_routes){
                $Map = $options;
                return;
            }else{
                require_once(AK_LIB_DIR.DS.'AkRouter.php');
                $Map =& new AkRouter();
                if(is_file(AK_ROUTES_MAPPING_FILE)){
                    include(AK_ROUTES_MAPPING_FILE);
                }
            }
        }
        $Map->debug = true;
        return $Map->toUrl($options);
    }


    /**
    * Translate strings to the current locale.
    *
    * When using Ak::t(), try to put entire sentences and strings
    * in one Ak::t() call.
    * This makes it easier for translators. HTML markup within
    * translation strings<commit_msg>Performance improvement. Routes where parsed on every Ak::toUrl call on PHP4. Now they are parsed only on the first run.<commit_after><?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

// +----------------------------------------------------------------------+
// | Akelos Framework - http://www.akelos.org                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006, Akelos Media, S.L.  & <NAME> |
// | Released under the GNU Lesser General Public License, see LICENSE.txt|
// +----------------------------------------------------------------------+

/**
 * @package AkelosFramework
 * @subpackage Ak
 * @author <NAME> <bermi a.t akelos c.om>
 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
 */

/**
* Define LOG Levels
* @todo Log events
*/
define('AK_LOG_NOTICE', 0);
define('AK_LOG_WARNING', 1);
define('AK_LOG_ERROR', 2);

defined('AK_FRAMEWORK_LANGUAGE') ? null : define('AK_FRAMEWORK_LANGUAGE', 'en');
defined('AK_DEV_MODE') ? null : define('AK_DEV_MODE', false);
defined('AK_AUTOMATIC_CONFIG_VARS_ENCRYPTION') ? null : define('AK_AUTOMATIC_CONFIG_VARS_ENCRYPTION', false);


/**
* Akelos Framework static functions
*
* Ak contains all the Akelos Framework static functions. This
* class acts like a name space to avoid naming collisions
* when PHP gets new functions into its core. And also to provide 
* additional functionality to existing PHP functions mantaining the same interface  
*
* @package AkelosFramework
* @subpackage Ak::static_functions
* @author <NAME> <bermi at akelos com>
* @copyright Copyright (c) 2002-2005, Akelos Media, S.L. http://www.akelos.org
* @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
*/
class Ak
{

    /**
    * Gets an instance of AdoDb database connection
    *
    * Whenever a database connection is required you can get a
    * reference to the default database connection by doing:
    *
    * $db =& Ak:db(); // get an adodb instance
    * 
    * AdoDB manual can be found at http://phplens.com/adodb/
    *
    * @access public
    * @param    string    $dns    A string containing Data Source Name (information
    * regarding database connection)
    * http://phplens.com/adodb/code.initialization.html#dsnsupport
    * @static
    * @return resource Php AdoDb instance.
    */
    function &db($dsn = null, $connection_id = null)
    {
        static $db;

        // In order to retrieve a database connection we just need to provide its identifier
        $connection_id = empty($connection_id) ?
        (empty($dsn) || strstr($dsn,':') ? 'default' : $dsn) :
        $connection_id;

        if(empty($db[$connection_id])){
            require_once(AK_CONTRIB_DIR.DS.'adodb'.DS.'adodb.inc.php');

            if(substr($dsn, 0, 6) == 'mysql:'){
                $dsn = substr_replace($dsn, 'mysqlt:', 0, 6);
            }

            if (!$db[$connection_id] = (AK_DEBUG ? NewADOConnection($dsn) : @NewADOConnection($dsn))){
                trigger_error(Ak::t('Connection to the database failed'), E_USER_ERROR);
                exit;
            }
            $db[$connection_id]->debug = AK_DEBUG == 2;
            defined('AK_DATABASE_CONNECTION_AVAILABLE') ? null : define('AK_DATABASE_CONNECTION_AVAILABLE', true);
            $dsn = '';
        }
        return $db[$connection_id];
    }



    /**
    * Gets a cache object singleton instance
    */
    function &cache()
    {
        static $cache;
        if(!isset($cache)){
            require_once(AK_LIB_DIR.DS.'AkCache.php');
            $cache = new AkCache();
        }
        return $cache;
    }


    function toUrl($options, $set_routes = false)
    {
        static $Map;
        if(empty($Map)){
            if($set_routes){
                $Map = $options;
                return;
            }else{
                require_once(AK_LIB_DIR.DS.'AkRouter.php');
                $Map = new AkRouter();
                if(is_file(AK_ROUTES_MAPPING_FILE)){
                    include(AK_ROUTES_MAPPING_FILE);
                }
            }
        }
        return $Map->toUrl($options);
    }


    /**
    * Translate strings to the current locale.
    *
    * When using Ak::t(), try to put entire sentences and strings
    * in one Ak::t() call.
    * This makes it easier for translators. HTML markup within
    * translation strings
{'fraction_non_alphanumeric': 0.16830247602052198, 'fraction_numerical': 0.007918804372072274, 'mean_word_length': 2.1189565217391304, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '163553', 'n_tokens_mistral': 2776, 'n_tokens_neox': 2621, 'n_words': 694}