您的位置:首页 > 产品设计 > UI/UE

Texas Instruments matrix-gui-2.0 hacking -- helper_functions.php

2015-06-18 10:36 330 查看
<?php

# PHP_SELF: 但前正在执行脚本的文件名,与document root相关
# QUERY_STRING: 查询(query)的字符串
$cachefile = "cache".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
#            ^
function start_caching()                            #            |
{                                                   #            |
//Use the global $cachefile variable            #            |
global $cachefile;                              #  -->---->--+

//There is a random string to the end of the $_GET Query String to
//prevent IE from caching the Ajax request. The below line removes the random portion
//of the query so we can cache the page properly in php
if(stripos($cachefile, "&rand=")==true)
$cachefile = substr($cachefile,0,stripos($cachefile, "&rand="));

if (file_exists($cachefile))
{
// the page has been cached from an earlier request
// output the contents of the cache file
include($cachefile);
// exit the script, so that the rest isnt executed
exit;
}
else
ob_start();
}

function get_application($dot_desktop_array,$submenu,$app_name)
{
for($i = 0;$i<count($dot_desktop_array[$submenu]["apps"]);$i++)
{
if($dot_desktop_array[$submenu]["apps"][$i]["Name"]==$app_name)
return     $dot_desktop_array[$submenu]["apps"][$i];
}
return NULL;
}

function end_caching()
{
//Use the global $cachefile variable
global $cachefile;

//Disable Caching on Description Page
// open the cache file "cache/home.html" for writing
$fp = fopen($cachefile, 'w');
// save the contents of output buffer to the file
fwrite($fp, ob_get_contents());
// close the file
fclose($fp);
// Send the output to the browser
ob_end_flush();
}

function get_submenu($dot_desktop_array,$submenu_name)
{
# foreach 循环
# $k: 表示数组的下标
# $v: 表示k下标对应的数组值
foreach ($dot_desktop_array as $k => $v)
{
for($j = 0;$j<count($v["apps"]);$j++)
{
$current_entry = $v["apps"][$j];

# 如果当前的记录类型是目录,并且当前分类和给定名字一样,那么返回该对象
if($current_entry["Type"]=="directory" && $current_entry["Category"] == $submenu_name)
return $current_entry;
}
}
return NULL;
}

function read_desktop_file()
{
# 检查json.txt是否存在,并且json.txt文件长度不为0
if(file_exists("json.txt") == true && filesize("json.txt") != 0)
{
# 打开并读取文件
$handle = fopen("json.txt", "rb");
$contents = fread($handle,filesize("json.txt"));
fclose($handle);

# 接受一个JSON格式的字符串并且把它转换为PHP变量,
# 返回解析后的json对象
return json_decode($contents,true);
}
else
return null;
}

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: