Files
admin_hura_8/inc/common.php

66 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2024-01-18 23:13:02 +07:00
<?php
2024-01-28 10:53:31 +07:00
function debug_var($input) {
@ob_start();
print_r($input);
$content = ob_get_contents();
@ob_end_clean();
echo join("\r", ['<textarea cols="80" rows="20">', $content, '</textarea>']) ;
}
2024-01-18 23:13:02 +07:00
function init_autoload(){
2025-11-20 13:10:28 +07:00
$candidates = [
ROOT_DIR . '/package/vendor/autoload.php',
ROOT_DIR . '/vendor/autoload.php'
];
$autoload = null;
foreach ($candidates as $file) {
if (file_exists($file)) {
$autoload = $file;
break;
}
}
if (!$autoload) {
$paths = implode("', '", $candidates);
trigger_error("Composer autoload not found. Expected one of: '" . $paths . "'.\nRun 'composer install' in the 'package' directory (or the project root) to install dependencies.", E_USER_ERROR);
}
$classLoader = require_once $autoload;
if (is_object($classLoader) && method_exists($classLoader, 'add')) {
$classLoader->add("Hura8", ROOT_DIR . '/inc');
}
2024-01-18 23:13:02 +07:00
return $classLoader;
}
2024-01-20 09:29:38 +07:00
//get current paging id
function getPageId(){
return getRequestInt('page', 1);
}
function getPageSize($default=10){
return getRequestInt('pageSize', $default);
}
//Function to get the post value in submit
function getPost($var, $default="", $encode = false, $keep_tag=""){
return isset($_POST[$var]) ? $_POST[$var] : $default;
}
//Function to get the INTERGER request value of a variable
function getRequestInt($var, $min_value = 0){
$request = isset($_REQUEST[$var]) ? (int) $_REQUEST[$var] : (int) $min_value;
$request = ($request >= $min_value ) ? $request : $min_value; //if user tampers request parameter
return $request;
}
//Function to get the request value of a variable
function getRequest($var, $default=""){
return $_REQUEST[$var] ?? $default;
}