reasonableframework/system/base.php

97 lines
1.8 KiB
PHP
Raw Normal View History

2017-12-31 16:15:38 +00:00
<?php
2017-12-31 18:31:02 +00:00
// view render
if(!function_exists('renderView')) {
function renderView($name, $data=array()) {
if(count($data) > 0) {
extract($data);
}
2018-02-13 07:11:13 +00:00
// set user profile
if(function_exists("get_user_profile")) {
$user_profile = get_user_profile();
}
// load view file
2017-12-31 18:31:02 +00:00
$viewfile = './view/' . $name . '.php';
if(file_exists($viewfile)) {
include($viewfile);
}
}
}
// load helper
if(!function_exists('loadHelper')) {
function loadHelper($name) {
2018-02-13 07:11:13 +00:00
// set user profile
if(function_exists("get_user_profile")) {
$user_profile = get_user_profile();
}
// load helper file
2017-12-31 18:31:02 +00:00
$helperfile = './helper/' . $name . '.php';
if(file_exists($helperfile)) {
include($helperfile);
}
}
}
if(!function_exists('array_key_empty')) {
2017-12-31 16:15:38 +00:00
function array_key_empty($key, $array) {
$empty = true;
if(is_array($array)) {
if(array_key_exists($key, $array)) {
if(!empty($array[$key])) {
$empty = false;
}
}
}
return $empty;
}
}
2017-12-31 17:00:50 +00:00
if(!function_exists("cut_str")) {
function cut_str($str, $start, $len=0) {
$cutted_str = "";
if(function_exists("iconv_substr")) {
$cutted_str = iconv_substr($str, $start, $len, "utf-8");
} elseif(function_exists("mb_substr")) {
$cutted_str = mb_substr($str, $start, $len);
} else {
$cutted_str = substr($start, $len);
}
return $cutted_str;
}
}
2017-12-31 17:55:03 +00:00
2018-01-17 13:49:04 +00:00
if(!function_exists("read_file_by_line")) {
2017-12-31 17:55:03 +00:00
function read_file_by_line($filename) {
$lines = array();
$handle = fopen($filename, "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$lines[] .= $line;
}
fclose($handle);
}
return $lines;
}
}
2018-01-17 13:49:04 +00:00
if(!function_exists("nl2p")) {
function nl2p($string) {
$paragraphs = '';
foreach (explode("\n", $string) as $line) {
if (trim($line)) {
$paragraphs .= '<p>' . $line . '</p>';
}
}
return $paragraphs;
}
}