2015-06-11 16:44:52 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Global functions
|
|
|
|
*/
|
|
|
|
|
2015-06-24 16:01:35 -04:00
|
|
|
/**
|
|
|
|
* Check if the user is currently logged in
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function is_logged_in()
|
|
|
|
{
|
|
|
|
return array_key_exists('hummingbird_anime_token', $_SESSION);
|
|
|
|
}
|
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
/**
|
|
|
|
* HTML selection helper function
|
|
|
|
*
|
|
|
|
* @param string $a - First item to compare
|
|
|
|
* @param string $b - Second item to compare
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function is_selected($a, $b)
|
|
|
|
{
|
|
|
|
return ($a === $b) ? 'selected' : '';
|
|
|
|
}
|
|
|
|
|
2015-06-16 11:11:35 -04:00
|
|
|
/**
|
|
|
|
* Inverse of selected helper function
|
|
|
|
*
|
|
|
|
* @param string $a - First item to compare
|
|
|
|
* @param string $b - Second item to compare
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function is_not_selected($a, $b)
|
|
|
|
{
|
|
|
|
return ($a !== $b) ? 'selected' : '';
|
|
|
|
}
|
|
|
|
|
2015-06-24 16:01:35 -04:00
|
|
|
/**
|
|
|
|
* Get the base url for css/js/images
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-06-26 13:24:55 -04:00
|
|
|
function asset_url(/*...*/)
|
|
|
|
{
|
|
|
|
global $config;
|
2015-06-24 16:01:35 -04:00
|
|
|
|
2015-06-26 13:24:55 -04:00
|
|
|
$args = func_get_args();
|
|
|
|
$base_url = rtrim($config->asset_path, '/');
|
2015-06-24 16:01:35 -04:00
|
|
|
|
2015-06-26 13:24:55 -04:00
|
|
|
array_unshift($args, $base_url);
|
2015-06-24 16:01:35 -04:00
|
|
|
|
2015-06-26 13:24:55 -04:00
|
|
|
return implode("/", $args);
|
|
|
|
}
|
2015-06-24 16:01:35 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the base url from the config
|
|
|
|
*
|
|
|
|
* @param string $type - (optional) The controller
|
2015-06-26 13:24:55 -04:00
|
|
|
# @param object $config - (optional) Config
|
2015-06-24 16:01:35 -04:00
|
|
|
* @return string
|
|
|
|
*/
|
2015-06-26 13:24:55 -04:00
|
|
|
function base_url($type="anime", $config=NULL)
|
2015-06-24 16:01:35 -04:00
|
|
|
{
|
2015-06-26 13:24:55 -04:00
|
|
|
if (is_null($config)) global $config;
|
|
|
|
|
2015-06-24 16:01:35 -04:00
|
|
|
|
|
|
|
$config_path = trim($config->{"{$type}_path"}, "/");
|
|
|
|
$config_host = $config->{"{$type}_host"};
|
|
|
|
|
|
|
|
// Set the appropriate HTTP host
|
|
|
|
$host = ($config_host !== '') ? $config_host : $_SERVER['HTTP_HOST'];
|
|
|
|
$path = ($config_path !== '') ? $config_path : "";
|
|
|
|
|
|
|
|
return implode("/", ['/', $host, $path]);
|
|
|
|
}
|
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
/**
|
|
|
|
* Generate full url path from the route path based on config
|
|
|
|
*
|
2015-06-16 11:11:35 -04:00
|
|
|
* @param string $path - (optional) The route path
|
|
|
|
* @param string $type - (optional) The controller (anime or manga), defaults to anime
|
2015-06-26 13:24:55 -04:00
|
|
|
# @param object $config - (optional) Config
|
2015-06-11 16:44:52 -04:00
|
|
|
* @return string
|
|
|
|
*/
|
2015-06-26 13:24:55 -04:00
|
|
|
function full_url($path="", $type="anime", $config=NULL)
|
2015-06-11 16:44:52 -04:00
|
|
|
{
|
2015-06-26 13:24:55 -04:00
|
|
|
if (is_null($config)) global $config;
|
2015-06-11 16:44:52 -04:00
|
|
|
|
2015-06-24 16:01:35 -04:00
|
|
|
$config_path = trim($config->{"{$type}_path"}, "/");
|
2015-06-11 16:44:52 -04:00
|
|
|
$config_host = $config->{"{$type}_host"};
|
2015-06-16 11:11:35 -04:00
|
|
|
$config_default_route = $config->{"default_{$type}_path"};
|
2015-06-11 16:44:52 -04:00
|
|
|
|
|
|
|
// Remove beginning/trailing slashes
|
|
|
|
$config_path = trim($config_path, '/');
|
|
|
|
$path = trim($path, '/');
|
|
|
|
|
2015-06-16 11:11:35 -04:00
|
|
|
// Remove any optional parameters from the route
|
|
|
|
$path = preg_replace('`{/.*?}`i', '', $path);
|
|
|
|
|
2015-06-24 16:01:35 -04:00
|
|
|
// Set the appropriate HTTP host
|
|
|
|
$host = ($config_host !== '') ? $config_host : $_SERVER['HTTP_HOST'];
|
|
|
|
|
2015-06-16 11:11:35 -04:00
|
|
|
// Set the default view
|
|
|
|
if ($path === '')
|
|
|
|
{
|
|
|
|
$path .= trim($config_default_route, '/');
|
|
|
|
if ($config->default_to_list_view) $path .= '/list';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set an leading folder
|
2015-06-11 16:44:52 -04:00
|
|
|
if ($config_path !== '')
|
|
|
|
{
|
|
|
|
$path = "{$config_path}/{$path}";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "//{$host}/{$path}";
|
|
|
|
}
|
|
|
|
|
2015-06-16 11:11:35 -04:00
|
|
|
/**
|
|
|
|
* Get the last segment of the current url
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function last_segment()
|
|
|
|
{
|
|
|
|
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
|
|
$segments = explode('/', $path);
|
|
|
|
return end($segments);
|
|
|
|
}
|
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
// End of functions.php
|