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;
    }
    
    ?>
  • 相关阅读:
    ImageLightbox.js – 响应式的图片 Lightbox 插件
    精美素材:10套最新出炉的免费扁平图标下载
    盘点2013年那些最优秀的网页设计作品【系列三】
    12个带给你惊喜用户体验的手机界面设计
    一款效果精致的 jQuery 多层滑出菜单插件
    创意无限:20幅惊人的霓虹灯摄影照片欣赏
    『设计前沿』14款精致的国外 iOS7 图标设计示例
    2013年值得我们学习的网页设计作品【系列二】
    Summernote – 基于 Bootstrap 的文本编辑器
    『摄影欣赏』2013年微软必应搜索十大首页美图
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/4585205.html
Copyright © 2011-2022 走看看