关于php常用自定义函数_运行钩子以下文字资料是由3搜网小编为大家搜集整理后发布的内容,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“php常用自定义函数_运行钩子”文章吧。
/**
* 运行钩子(插件使用)
*/
function runhook($method) {
$time_start = getmicrotime();
$data = '';
$getpclass = FALSE;
$hook_appid = getcache('hook','plugins');
if(!empty($hook_appid)) {
foreach($hook_appid as $appid => $p) {
$pluginfilepath = CODE_PATH.'plugin'.DIRECTORY_SEPARATOR.$p.DIRECTORY_SEPARATOR.'hook.class.php';
$getpclass = TRUE;
include_once $pluginfilepath;
}
$hook_appid = array_flip($hook_appid);
if($getpclass) {
$pclass = new ReflectionClass('hook');
foreach($pclass->getMethods() as $r) {
$legalmethods[] = $r->getName();
}
}
if(in_array($method,$legalmethods)) {
foreach (get_declared_classes() as $class){
$refclass = new ReflectionClass($class);
if($refclass->isSubclassOf('hook')){
if ($_method = $refclass->getMethod($method)) {
$classname = $refclass->getName();
if ($_method->isPublic() && $_method->isFinal()) {
plugin_stat($hook_appid[$classname]);
$data .= $_method->invoke(null);
}
}
}
}
}
return $data;
}
}
function getmicrotime() {
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
/**
* 插件前台模板加载
* Enter description here ...
* @param unknown_type $module
* @param unknown_type $template
* @param unknown_type $style
*/
function p_template($plugin = 'content', $template = 'index',$style='default') {
if(!$style) $style = 'default';
$template_cache = app_base::load_sys_class('template_cache');
$compiledtplfile = ROOT_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.$template.'.php';
if(!file_exists($compiledtplfile) || (file_exists(CODE_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html') && filemtime(CODE_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html') > filemtime($compiledtplfile))) {
$template_cache->template_compile('plugin/'.$plugin, $template, 'default');
} elseif (!file_exists(CODE_PATH.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.html')) {
showmessage('Template does not exist.'.DIRECTORY_SEPARATOR.'plugin'.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.$template.'.html');
}
return $compiledtplfile;
}
/**
* 读取缓存动态页面
*/
function cache_page_start() {
$relate_url = isset($_SERVER['REQUEST_URI']) ? safe_replace($_SERVER['REQUEST_URI']) : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.safe_replace($_SERVER['QUERY_STRING']) : $path_info);
define('CACHE_PAGE_ID', md5($relate_url));
$contents = getcache(CACHE_PAGE_ID, 'page_tmp/'.substr(CACHE_PAGE_ID, 0, 2));
if($contents && intval(substr($contents, 15, 10)) > SYS_TIME) {
echo substr($contents, 29);
exit;
}
if (!defined('HTML')) define('HTML',true);
return true;
}
/**
* 写入缓存动态页面
*/
function cache_page($ttl = 360, $isjs = 0) {
if($ttl == 0 || !defined('CACHE_PAGE_ID')) return false;
$contents = ob_get_contents();
if($isjs) $contents = format_js($contents);
$contents = "<!--expiretime:".(SYS_TIME + $ttl)."-->\n".$contents;
setcache(CACHE_PAGE_ID, $contents, 'page_tmp/'.substr(CACHE_PAGE_ID, 0, 2));
}
/**
*
* 获取远程内容
* @param $url 接口url地址
* @param $timeout 超时时间
*/
function pc_file_get_contents($url, $timeout=30) {
$stream = stream_context_create(array('http' => array('timeout' => $timeout)));
return @file_get_contents($url, 0, $stream);
}
/**
* Function get_vid
* 获取视频信息
* @param int $contentid 内容ID 必须
* @param int $catid 栏目id 取内容里面视频信息时必须
* @param int $isspecial 是否取专题的视频信息
*/
function get_vid($contentid = 0, $catid = 0, $isspecial = 0) {
static $categorys;
if (!$contentid) return false;
if (!$isspecial) {
if (!$catid) return false;
$contentid = intval($contentid);
$catid = intval($catid);
$siteid = get_siteid();
if (!$categorys) {
$categorys = getcache('category_content_'.$siteid, 'commons');
}
$modelid = $categorys[$catid]['modelid'];
$video_content = app_base::load_model('video_content_model');
$r = $video_content->get_one(array('contentid'=>$contentid, 'modelid'=>$modelid), 'videoid', 'listorder ASC');
$video_store =app_base::load_model('video_store_model');
return $video_store->get_one(array('videoid'=>$r['videoid']));
} else {
$special_content = app_base::load_model('special_content_model');
$contentid = intval($contentid);
$video_store =app_base::load_model('video_store_model');
$r = $special_content->get_one(array('id'=>$contentid), 'videoid');
return $video_store->get_one(array('videoid'=>$r['videoid']));
}
}
/**
* Function dataformat
* 时间转换
* @param $n INT时间
*/
function dataformat($n) {
$hours = floor($n/3600);
$minite = floor($n%3600/60);
$secend = floor($n%3600%60);
$minite = $minite < 10 ? "0".$minite : $minite;
$secend = $secend < 10 ? "0".$secend : $secend;
if($n >= 3600){
return $hours.":".$minite.":".$secend;
}else{
return $minite.":".$secend;
}
}
function httpResponse($status, $msg=''){
$m = app_base::load_model('category_model');
$CATEGORYS = $m->select(array('parentid'=>0),'*','','listorder');
include CODE_PATH . 'libs'.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'http'.DIRECTORY_SEPARATOR.$status.'.php';
}
function array_change_key_case_recursive($arr)
{
if(! $arr || !is_array($arr))return array();
return array_map(function($item){
if(is_array($item))
$item = array_change_key_case_recursive($item);
return $item;
},array_change_key_case($arr));
}
function visitauth(){
$vtime = time();
$vsign = md5("cuichuande@ideadata.com.cn#$%" . $vtime);
return "tm={$vtime}&sn={$vsign}";
} 以上就是关于“php常用自定义函数_运行钩子”这篇文章的内容,希望分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注3搜网技术频道。


