<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 ActionView
 * @subpackage Helpers
 * @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>
 */

require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'javascript_helper.php');

class UrlHelper
{
    function setController(&$controller)
    {
        $this->_controller =& $controller;
    }

    /**
    * Returns the URL for the set of +$options+ provided. This takes the same options 
    * as url_for. For a list, see the documentation for AKActionController::urlFor.
    * Note that it'll set ('only_path' => true) so you'll get /controller/action instead of the 
    * http://example.com/controller/action part (makes it harder to parse httpd log files)
    */
    function url_for($options = array(), $parameters_for_method_reference = null)
    {
        $default_options = array(
        'only_path' => true
        );
        $options = array_merge($default_options, $options);
        return $this->_controller->urlFor($options, $parameters_for_method_reference);
    }


    function modify_current_url($options_to_add = array(), $options_to_exclude = array(), $remove_unnecesary_options = true)
    {
        $options_to_exclude = $remove_unnecesary_options ? array_merge(array('ak','lang',AK_SESSION_NAME,'AK_SESSID','PHPSESSID'), $options_to_exclude) : $options_to_exclude;
        $options_to_add = array_merge(array_merge(array('action'=>$this->_controller->Request->getAction(), 'controller' => $this->_controller->Request->getController()),$this->_controller->Request->getUrlParams()),$options_to_add);
        foreach ($options_to_exclude as $option_to_exclude){
            unset($options_to_add[$option_to_exclude]);
        }
        return $this->url_for($options_to_add);
    }

    /**
    * Creates a link tag of the given +name+ using an URL created by the set of +options+. See the valid options in
    * the documentation for ActionController::urlFor. It's also possible to pass a string instead of an array of options
    * to get a link tag that just points without consideration. If null is passed as a name, the link itself will become 
    * the name.
    *
    * The html_options has three special features. One for creating javascript confirm alerts where if you pass
    * 'confirm' => 'Are you sure?', the link will be guarded with a JS popup asking that question. 
    * If the user accepts, the link is processed, otherwise not.
    *
    * Another for creating a popup window, which is done by either passing 'popup' with true or the options of the window in 
    * Javascript form.
    *
    * And a third for making the link do a POST request (instead of the regular GET) through a dynamically added form 
    * element that is instantly submitted. Note that if the user has turned off Javascript, the request will fall back on 
    * the GET. So its your responsibility to determine what the action should be once it arrives at the controller. <commit_msg>UrlHelper::modify_current_url uses the parsed version of ak=.....<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 ActionView
 * @subpackage Helpers
 * @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>
 */

require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'javascript_helper.php');

class UrlHelper
{
    function setController(&$controller)
    {
        $this->_controller =& $controller;
    }

    /**
    * Returns the URL for the set of +$options+ provided. This takes the same options 
    * as url_for. For a list, see the documentation for AKActionController::urlFor.
    * Note that it'll set ('only_path' => true) so you'll get /controller/action instead of the 
    * http://example.com/controller/action part (makes it harder to parse httpd log files)
    */
    function url_for($options = array(), $parameters_for_method_reference = null)
    {
        $default_options = array(
        'only_path' => true
        );
        $options = array_merge($default_options, $options);
        return $this->_controller->urlFor($options, $parameters_for_method_reference);
    }


    function modify_current_url($options_to_add = array(), $options_to_exclude = array(), $remove_unnecesary_options = true)
    {
        $options_to_exclude = $remove_unnecesary_options ? array_merge(array('ak','lang',AK_SESSION_NAME,'AK_SESSID','PHPSESSID'), $options_to_exclude) : $options_to_exclude;
        $url_params = $this->_controller->Request->getUrlParams();
        if(!empty($options_to_add['ak'])){
            $Router =& AkRouter();
            $url_params = array_merge($url_params, $Router->toParams($options_to_add['ak']));
        }
        $options_to_add = array_merge(array_merge(array('action'=>$this->_controller->Request->getAction(), 'controller' => $this->_controller->Request->getController()),$url_params),$options_to_add);
        foreach ($options_to_exclude as $option_to_exclude){
            unset($options_to_add[$option_to_exclude]);
        }
        return $this->url_for($options_to_add);
    }

    /**
    * Creates a link tag of the given +name+ using an URL created by the set of +options+. See the valid options in
    * the documentation for ActionController::urlFor. It's also possible to pass a string instead of an array of options
    * to get a link tag that just points without consideration. If null is passed as a name, the link itself will become 
    * the name.
    *
    * The html_options has three special features. One for creating javascript confirm alerts where if you pass
    * 'confirm' => 'Are you sure?', the link will be guarded with a JS popup asking that question. 
    * If the user accepts, the link is processed, otherwise not.
    *
    * Another for creating a popup window, which is done by either passing 'popup' with true or the options of the window in 
    * Javascript form.
    *
    * And a third for making the link do a POST request (instead of the regular GET) through a dynamically added form 
    * element that is instantly submitted. Note that if the user has turned off Javascript, the request will fall back on 
    * the GET. So its your responsibility to determine what the action should be once it arrives at the controller. 
{'fraction_non_alphanumeric': 0.16053019145802652, 'fraction_numerical': 0.005087695809345294, 'mean_word_length': 2.6961900049480456, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '3091630', 'n_tokens_mistral': 2097, 'n_tokens_neox': 1990, 'n_words': 680}