1<?php 2/* 3 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the 16 * distribution. 17 * 18 * Neither the name of Texas Instruments Incorporated nor the names of 19 * its contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34*/ 35function get_contents($field_name,$filestring) 36{ 37 $pos = stripos($filestring,$field_name."="); 38 39 if($pos != false) 40 { 41 $pos += strlen($field_name."="); 42 $newlinepos = stripos($filestring,"\n",$pos); 43 44 if($newlinepos == -1) 45 $newlinepos = stripos($filestring,"\r",$pos); 46 47 $returnedstring = substr($filestring,$pos,$newlinepos-$pos); 48 return $returnedstring; 49 } 50 return -1; 51} 52 53system("find -name '*.desktop' -print > catdesktop.txt"); 54 55if(filesize("catdesktop.txt") == 0) 56{ 57 echo "No .desktop files found"; 58 return; 59} 60 61$handle = fopen("catdesktop.txt", "rb"); 62$contents = fread($handle,filesize("catdesktop.txt")); 63fclose($handle); 64unlink('catdesktop.txt'); 65 66$contents = explode("\n",$contents); 67 68for($x = 0;$x<count($contents)&&strlen($contents[$x])>0;$x++) 69{ 70 $handle = fopen($contents[$x], "rb"); 71 $dotdesktop = fread($handle,filesize($contents[$x])); 72 fclose($handle); 73 74 $top["Name"] = get_contents("Name",$dotdesktop); 75 76 if(get_contents("X-MATRIX-DisplayPriority",$dotdesktop)!=-1) 77 $top["Order"] = get_contents("X-MATRIX-DisplayPriority",$dotdesktop); 78 else 79 $top["Order"] = 999; 80 81 $icon_path = get_contents("Icon",$dotdesktop); 82 83 $webserver_root = "/usr/share/matrix-gui-2.0/"; 84 85 $top["Icon"] = substr($icon_path,strlen($webserver_root)); 86 87 $type = strtolower(get_contents("Type",$dotdesktop)); 88 89 $top["Type"] = $type; 90 91 $category = get_contents("Categories",$dotdesktop); 92 93 $category = trim(strtolower($category)); 94 95 if($type == "directory") 96 { 97 $top["Category"] = get_contents("X-MATRIX-CategoryTarget",$dotdesktop); 98 99 }elseif($type == "application") 100 { 101 $top["Exec"] = get_contents("Exec",$dotdesktop); 102 103 $top["ProgramType"] = get_contents("ProgramType",$dotdesktop); 104 105 $top["Description_Link"] = get_contents("X-MATRIX-Description",$dotdesktop); 106 107 $top["Lock"] = get_contents("X-MATRIX-LOCK",$dotdesktop); 108 109 $top["Category"] = get_contents("Categories",$dotdesktop); 110 } 111 112 if($category == -1) 113 $application["main_menu"]["apps"][] = $top; 114 else 115 $application[$category]["apps"][] = $top; 116 117 unset($top); 118} 119 120function cmp($a, $b) 121{ 122 if($a["Order"] < $b["Order"]) 123 return -1; 124 elseif($a["Order"] == $b["Order"]) 125 return 0; 126 elseif($a["Order"] > $b["Order"]) 127 return 1; 128} 129 130foreach ($application as $key => $value) { 131 usort($application[$key]["apps"], "cmp"); 132} 133 134$ourFileName = "json.txt"; 135$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); 136fwrite($ourFileHandle,json_encode($application)); 137fclose($ourFileHandle); 138?> 139 140