zoukankan      html  css  js  c++  java
  • Texas Instruments matrix-gui-2.0 hacking -- helper_functions.php

    <?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;
    }
    
    ?>
  • 相关阅读:
    图,深度,广度优先遍历(一)
    java实现快速排序
    图,深度,广度优先遍历(二)
    图,深度,广度优先遍历(三)
    Jpa动态多表if多条件联合查询(if中包含list不为null和“=”的判断),并对查询结果进行分页
    SpringBoo启动报错:Failed to load property source from location ‘classpath:/bootstrap.yml‘
    Java对象创建和Javabean创建
    Linux解压命令
    BDD测试利器:mocha+should.js
    《老码识途》读书笔记:第一章(中)
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/4585205.html
Copyright © 2011-2022 走看看