<commit_before><?php

/**
 * Creates the target url for links
 *
 * PHP Version 5
 *
 * @category  Core
 * @package   URL
 * @author    <NAME> <<EMAIL>>
 * @copyright 2013 cSphere Team
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
 * @link      http://www.csphere.eu
 **/

namespace csphere\core\url;

/**
 * Creates the target url for links
 *
 * PHP Version 5
 *
 * @category  Core
 * @package   URL
 * @author    <NAME> <<EMAIL>>
 * @copyright 2013 cSphere Team
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
 * @link      http://www.csphere.eu
 **/

abstract class Link
{
    /**
     * Checks if options are fetched already
     **/
    private static $_init = false;

    /**
     * Stores if ajax links are activated
     **/
    private static $_ajax = false;

    /**
     * Stores if pretty links are activated
     **/
    private static $_pretty = false;

    /**
     * Stores the request array data
     **/
    private static $_request = '';

    /**
     * Stores the plugin part of links
     **/
    private static $_plugin = '';

    /**
     * Stores the action part of links
     **/
    private static $_action = '';

    /**
     * Stores the key part of links
     **/
    private static $_key = '';

    /**
     * Stores the value part of links
     **/
    private static $_value = '';

    /**
     * Fetch options and set flags
     *
     * @return void
     **/

    private static function _init()
    {
        self::$_request = \csphere\core\http\Request::get();

        // Fetch view options
        $loader = \csphere\core\service\Locator::get();
        $view   = $loader->load('view');

        self::$_ajax   = $view->getOption('links_ajax');
        self::$_pretty = $view->getOption('links_pretty');

        // Set flags
        if (empty(self::$_pretty) AND empty(self::$_ajax)) {

            self::$_plugin = '?plugin=';
            self::$_action = '&amp;action=';
            self::$_key   = '&amp;';
            self::$_value = '=';

        } else {

            self::$_plugin = empty(self::$_ajax) ? '' : '#';
            self::$_action = '/';
            self::$_key   = '/';
            self::$_value = '/';
        }

        self::$_init = true;
    }

    /**
     * Creates a link for the specified parameters
     *
     * @param string $plugin Plugin
     * @param string $action Action
     * @param array  $params Array of key value pairs where value can be empty
     *
     * @return string
     **/

    public static function href($plugin, $action, array $params = array())
    {
        // Check and set options if init is not done yet
        if (self::$_init == false) {

            self::_init();
        }

        // @TODO: Use urlencode on dynamic parts

        // Add plugin and action
        $link = self::$_request['dirname'] . self::$_plugin . $plugin;

        if ($action != '') {

            $link .= self::$_action . $action;
        }

        // Add params
        unset($params['plugin'], $params['action'], $params['']);

        foreach ($params AS $key => $value) {

            $link .= self::$_key . $key . self::$_value . $value;
        }

        return $link;
    }

    /**
     * Creates a link for the current parameters
     *
     * @return string
     **/

    public static function current()
    {
        $plugin = self::$_request['data']['plugin'];
        $action = self::$_request['data']['action'];
        $params = self::$_request['data'];

        // Unset plugin and action from params
        unset($params['plugin'], $params['action']);

        // Proceed with usual link creation now
        $result = self::href($plugin, $action, $params);

        return $result;
    }<commit_msg>hide empty url params again<commit_after><?php

/**
 * Creates the target url for links
 *
 * PHP Version 5
 *
 * @category  Core
 * @package   URL
 * @author    <NAME> <<EMAIL>>
 * @copyright 2013 cSphere Team
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
 * @link      http://www.csphere.eu
 **/

namespace csphere\core\url;

/**
 * Creates the target url for links
 *
 * PHP Version 5
 *
 * @category  Core
 * @package   URL
 * @author    <NAME> <<EMAIL>>
 * @copyright 2013 cSphere Team
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
 * @link      http://www.csphere.eu
 **/

abstract class Link
{
    /**
     * Checks if options are fetched already
     **/
    private static $_init = false;

    /**
     * Stores if ajax links are activated
     **/
    private static $_ajax = false;

    /**
     * Stores if pretty links are activated
     **/
    private static $_pretty = false;

    /**
     * Stores the request array data
     **/
    private static $_request = '';

    /**
     * Stores the plugin part of links
     **/
    private static $_plugin = '';

    /**
     * Stores the action part of links
     **/
    private static $_action = '';

    /**
     * Stores the key part of links
     **/
    private static $_key = '';

    /**
     * Stores the value part of links
     **/
    private static $_value = '';

    /**
     * Fetch options and set flags
     *
     * @return void
     **/

    private static function _init()
    {
        self::$_request = \csphere\core\http\Request::get();

        // Fetch view options
        $loader = \csphere\core\service\Locator::get();
        $view   = $loader->load('view');

        self::$_ajax   = $view->getOption('links_ajax');
        self::$_pretty = $view->getOption('links_pretty');

        // Set flags
        if (empty(self::$_pretty) AND empty(self::$_ajax)) {

            self::$_plugin = '?plugin=';
            self::$_action = '&amp;action=';
            self::$_key   = '&amp;';
            self::$_value = '=';

        } else {

            self::$_plugin = empty(self::$_ajax) ? '' : '#';
            self::$_action = '/';
            self::$_key   = '/';
            self::$_value = '/';
        }

        self::$_init = true;
    }

    /**
     * Creates a link for the specified parameters
     *
     * @param string $plugin Plugin
     * @param string $action Action
     * @param array  $params Array of key value pairs where value can be empty
     *
     * @return string
     **/

    public static function href($plugin, $action, array $params = array())
    {
        // Check and set options if init is not done yet
        if (self::$_init == false) {

            self::_init();
        }

        // @TODO: Use urlencode on dynamic parts

        // Add plugin and action
        $link = self::$_request['dirname'] . self::$_plugin . $plugin;

        if ($action != '') {

            $link .= self::$_action . $action;
        }

        // Add params
        unset($params['plugin'], $params['action'], $params['']);

        foreach ($params AS $key => $value) {

            // Only add params that are not empty
            if ($value != '') {

                $link .= self::$_key . $key . self::$_value . $value;
            }
        }

        return $link;
    }

    /**
     * Creates a link for the current parameters
     *
     * @return string
     **/

    public static function current()
    {
        $plugin = self::$_request['data']['plugin'];
        $action = self::$_request['data']['action'];
        $params = self::$_request['data'];

        // Unset plugin and action from params
        unset($params['plugin'], $params['action']);

        // Proceed with usual link creation now
        $result = self::href($plugin, $action, $params);

        return $result;
    }
{'fraction_non_alphanumeric': 0.1512220624754934, 'fraction_numerical': 0.0026140373807345446, 'mean_word_length': 1.8984848484848484, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '7626863', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2156, 'n_words': 625}