Server : nginx/1.22.1
System : Linux iZwz9daxib3w3i063fw434Z 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64
User : www ( 1000)
PHP Version : 5.6.40
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Directory :  /www/wwwroot/www.jkmold.com/api/
Upload File :
Current Directory [ Writeable ] Root Directory [ Writeable ]


Current File : /www/wwwroot/www.jkmold.com/api/get_menu.php
<?php

/**

 * 获取联动菜单接口

 */

defined('IN_PHPCMS') or exit('No permission resources.'); 

if(!$_GET['callback'] || !$_GET['act'])  showmessage(L('error'));



switch($_GET['act']) {

	case 'ajax_getlist':

		ajax_getlist();

	break;

	

	case 'ajax_getpath':

		ajax_getpath($_GET['parentid'],$_GET['keyid'],$_GET['callback'],$_GET['path']);

	break;	

	case 'ajax_gettopparent':

		ajax_gettopparent($_GET['id'],$_GET['keyid'],$_GET['callback'],$_GET['path']);

	break;		

}





/**

 * 获取地区列表

 */

function ajax_getlist() {

	$cachefile = safe_getcache($_GET['cachefile']);

	$path = safe_getcache($_GET['path']);

	$title = $_GET['title'];

	$key = $_GET['key'];

	$infos = getcache($cachefile,$path);

	$where_id = intval($_GET['parentid']);

	$parent_menu_name = ($where_id==0) ? '' : trim($infos[$where_id][$key]);

	is_array($infos)?null:$infos = array();

	foreach($infos AS $k=>$v) {

		if($v['parentid'] == $where_id) {

			if ($v['parentid']) $parentid = $infos[$v['parentid']]['parentid'];

			$s[]=iconv(CHARSET,'utf-8',$v['catid'].','.trim($v[$key]).','.$v['parentid'].','.$parent_menu_name.','.$parentid);

		}

	}

	if(count($s)>0) {

		$jsonstr = json_encode($s);

		echo trim_script($_GET['callback']).'(',$jsonstr,')';

		exit;			

	} else {

		echo trim_script($_GET['callback']).'()';exit;			

	}

}



/**

 * 获取地区父级路径路径

 * @param $parentid 父级ID

 * @param $keyid 菜单keyid

 * @param $callback json生成callback变量

 * @param $result 递归返回结果数组

 * @param $infos

 */

function ajax_getpath($parentid,$keyid,$callback,$path = 'commons',$result = array(),$infos = array()) {

	$path = safe_getcache($path);

	$keyid = safe_getcache($keyid);

	$parentid = intval($parentid);

	if(!$infos) {

		$infos = getcache($keyid,$path);

	}

	if(array_key_exists($parentid,$infos)) {

		$result[]=iconv(CHARSET,'utf-8',trim($infos[$parentid]['catname']));

		return ajax_getpath($infos[$parentid]['parentid'],$keyid,$callback,$path,$result,$infos);

	} else {

		if(count($result)>0) {

			krsort($result);

			$jsonstr = json_encode($result);

			echo trim_script($callback).'(',$jsonstr,')';

			exit;

		} else {

			$result[]=iconv(CHARSET,'utf-8',$datas['title']);

			$jsonstr = json_encode($result);

			echo trim_script($callback).'(',$jsonstr,')';

			exit;

		}

	}

}

/**

 * 获取地区顶级ID

 * Enter description here ...

 * @param  $linkageid 菜单id

 * @param  $keyid 菜单keyid

 * @param  $callback json生成callback变量

 * @param  $infos 递归返回结果数组

 */

function ajax_gettopparent($id,$keyid,$callback,$path,$infos = array()) {

	$path = str_replace(array('/', '//'), '', $path);

	$keyid = str_replace(array('/', '//'), '', $keyid);

	$id = intval($id);

	if(!$infos) {

		$infos = getcache($keyid,$path);

	}

	if($infos[$id]['parentid']!=0) {

		return ajax_gettopparent($infos[$id]['parentid'],$keyid,$callback,$path,$infos);

	} else {

		echo trim_script($callback).'(',$id,')';

		exit;		

	}

}

function safe_getcache($str) {

	$str = str_replace(array("'",'#','=','`','$','%','&',';','..'), '', $str);

	$str = preg_replace('/(\/){1,}|(\\\){1,}/', '', $str);

	return $str;

}

?>