| [21] | 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | |
|---|
| 4 | ___Canvas XML Functions_________________________________________ |
|---|
| 5 | |
|---|
| 6 | Imports function name and variable definitions from an XML file. |
|---|
| 7 | Contains the XML and directory scanning functions. |
|---|
| 8 | |
|---|
| 9 | ________________________________________________________________ |
|---|
| 10 | |
|---|
| 11 | */ |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | function canvas_get_plugin($filename, $modTitle) { |
|---|
| 15 | global $plugin, $current_function, $current_variable, $current_tag, $current_option; |
|---|
| 16 | if (!($xmlparser = xml_parser_create())) echo("ERROR: Cannot create parser for ".$filename); |
|---|
| 17 | xml_set_element_handler($xmlparser, "startElement", "endElement"); |
|---|
| 18 | |
|---|
| 19 | $current_function = trim($modTitle); |
|---|
| 20 | $plugin = new importedFunction(); |
|---|
| 21 | $plugin->functionName = $current_function; |
|---|
| 22 | |
|---|
| 23 | xml_set_character_data_handler($xmlparser, "canvas_import_XML_content"); |
|---|
| 24 | |
|---|
| 25 | if (!($fp = fopen($filename, "r"))) echo("ERROR: Can't open ".$filename); |
|---|
| 26 | while ($data = fread($fp, 4096)) { |
|---|
| 27 | $data=eregi_replace(">"."[[:space:]]+"."<","><",$data); |
|---|
| 28 | $data=eregi_replace(">"."[[:space:]]+",">",$data); |
|---|
| 29 | $data=eregi_replace("[[:space:]]+"."<","<",$data); |
|---|
| 30 | |
|---|
| 31 | if (!xml_parse($xmlparser, $data, feof($fp))) { |
|---|
| 32 | echo(sprintf("XML error: %s at line %d of".$filename, |
|---|
| 33 | xml_error_string(xml_get_error_code($xml_parser)), |
|---|
| 34 | xml_get_current_line_number($xml_parser))); |
|---|
| 35 | } |
|---|
| 36 | } |
|---|
| 37 | xml_parser_free($xmlparser); |
|---|
| 38 | |
|---|
| 39 | return $plugin; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | function canvas_import_XML_content($parser, $data) { |
|---|
| 43 | global $plugin, $current_function, $current_variable, $current_option, $current_tag; |
|---|
| 44 | |
|---|
| 45 | $functionNameKey = "^CANVAS^FUNCTION^NAME"; |
|---|
| 46 | $functionUBIKey = "^CANVAS^FUNCTION^UBI"; |
|---|
| 47 | $functionPathKey = "^CANVAS^FUNCTION^PATH"; |
|---|
| 48 | $functionAuthorKey = "^CANVAS^FUNCTION^AUTHOR"; |
|---|
| 49 | $functionUriKey = "^CANVAS^FUNCTION^URI"; |
|---|
| 50 | $functionDescKey = "^CANVAS^FUNCTION^DESCRIPTION"; |
|---|
| 51 | $functionGroupKey = "^CANVAS^FUNCTION^GROUP"; |
|---|
| 52 | $functionNumvarsKey = "^CANVAS^FUNCTION^NUMVARS"; |
|---|
| 53 | $variablesKey = "^CANVAS^FUNCTION^VARIABLES"; |
|---|
| 54 | $variableKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE"; |
|---|
| 55 | $variableNameKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^NAME"; |
|---|
| 56 | $variableDescriptionKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^DESCRIPTION"; |
|---|
| 57 | $variableTypeKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^TYPE"; |
|---|
| 58 | $variableDirectoryKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^DIRECTORY"; |
|---|
| 59 | $variableDefaultKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^DEFAULT"; |
|---|
| 60 | $variableNumoptsKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^NUMOPTIONS"; |
|---|
| 61 | $optionsKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^OPTIONS"; |
|---|
| 62 | $optionKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^OPTIONS^OPTION"; |
|---|
| 63 | $optionTextKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^OPTIONS^OPTION^DISPLAYTEXT"; |
|---|
| 64 | $optionValueKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^OPTIONS^OPTION^VALUE"; |
|---|
| 65 | $optionParamsKey = "^CANVAS^FUNCTION^VARIABLES^VARIABLE^OPTIONS^OPTION^PARAMS"; |
|---|
| 66 | |
|---|
| 67 | if($current_tag == $functionNameKey) { |
|---|
| 68 | $current_function = trim($data); |
|---|
| 69 | $plugin = new importedFunction(); |
|---|
| 70 | $plugin->functionName = $current_function; |
|---|
| 71 | } elseif($current_tag == $functionUBIKey) { |
|---|
| 72 | $plugin->functionUBI = trim($data); |
|---|
| 73 | } elseif($current_tag == $functionPathKey) { |
|---|
| 74 | $plugin->functionPath = trim($data); |
|---|
| 75 | } elseif($current_tag == $functionAuthorKey) { |
|---|
| 76 | $plugin->functionAuthor = trim($data); |
|---|
| 77 | } elseif($current_tag == $functionUriKey) { |
|---|
| 78 | $plugin->functionUri = trim($data); |
|---|
| 79 | } elseif($current_tag == $functionDescKey) { |
|---|
| 80 | $plugin->functionDesc = trim($data); |
|---|
| 81 | } elseif($current_tag == $functionGroupKey) { |
|---|
| 82 | if(trim($data) == '') $data = 'Other'; |
|---|
| 83 | $plugin->functionGroup = $data; |
|---|
| 84 | } elseif($current_tag == $variableNameKey) { |
|---|
| 85 | $current_variable = trim($data); |
|---|
| 86 | $plugin->variables[$current_variable]['name'] = $current_variable; |
|---|
| 87 | } elseif($current_tag == $variableDescriptionKey) { |
|---|
| 88 | $plugin->variables[$current_variable]['description'] = trim($data); |
|---|
| 89 | } elseif($current_tag == $variableTypeKey) { |
|---|
| 90 | $plugin->variables[$current_variable]['type'] = trim($data); |
|---|
| 91 | } elseif($current_tag == $variableDirectoryKey) { |
|---|
| 92 | $plugin->variables[$current_variable]['option']['gallery']['name'] = 'Image Directory URI'; |
|---|
| 93 | $plugin->variables[$current_variable]['option']['gallery']['value'] = trim($data); |
|---|
| 94 | } elseif($current_tag == $variableDefaultKey) { |
|---|
| 95 | $plugin->variables[$current_variable]['default'] = trim($data); |
|---|
| 96 | } elseif($current_tag == $optionTextKey) { |
|---|
| 97 | $current_option = trim($data); |
|---|
| 98 | $plugin->variables[$current_variable]['option'][$current_option]['name'] = $current_option; |
|---|
| 99 | } elseif($current_tag == $optionValueKey) { |
|---|
| 100 | $plugin->variables[$current_variable]['option'][$current_option]['value'] = trim($data); |
|---|
| 101 | } elseif($current_tag == $optionParamsKey) { |
|---|
| 102 | $plugin->variables[$current_variable]['option'][$current_option]['params'] = trim($data); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | function canvas_import_layout_XML($parser, $data) { |
|---|
| 109 | global $imported_theme, $imported_blocks, $imported_variables, $id, $variable, $current_tag; |
|---|
| 110 | |
|---|
| 111 | $themeTitle = "^CANVAS^EXPORT^META^TITLE"; |
|---|
| 112 | $themeAuthor = "^CANVAS^EXPORT^META^AUTHOR"; |
|---|
| 113 | $themeURI = "^CANVAS^EXPORT^META^URI"; |
|---|
| 114 | $theme = "^CANVAS^EXPORT^META^THEME"; |
|---|
| 115 | $blockName = "^CANVAS^EXPORT^LAYOUT^BLOCK^NAME"; |
|---|
| 116 | $blockType = "^CANVAS^EXPORT^LAYOUT^BLOCK^TYPE"; |
|---|
| 117 | $blockZone = "^CANVAS^EXPORT^LAYOUT^BLOCK^ZONE"; |
|---|
| 118 | $blockPosition = "^CANVAS^EXPORT^LAYOUT^BLOCK^POSITION"; |
|---|
| 119 | $blockAuthor = "^CANVAS^EXPORT^LAYOUT^BLOCK^AUTHOR"; |
|---|
| 120 | $blockDesc = "^CANVAS^EXPORT^LAYOUT^BLOCK^DESCRIPTION"; |
|---|
| 121 | $blockGroup = "^CANVAS^EXPORT^LAYOUT^BLOCK^GROUP"; |
|---|
| 122 | $blockURI = "^CANVAS^EXPORT^LAYOUT^BLOCK^URI"; |
|---|
| 123 | $blockPath = "^CANVAS^EXPORT^LAYOUT^BLOCK^PATH"; |
|---|
| 124 | $blockUBI = "^CANVAS^EXPORT^LAYOUT^BLOCK^UBI"; |
|---|
| 125 | $blockID = "^CANVAS^EXPORT^LAYOUT^BLOCK^ID"; |
|---|
| 126 | $variableName = "^CANVAS^EXPORT^LAYOUT^BLOCK^VARIABLES^VARIABLE^NAME"; |
|---|
| 127 | $variableValue = "^CANVAS^EXPORT^LAYOUT^BLOCK^VARIABLES^VARIABLE^VALUE"; |
|---|
| 128 | |
|---|
| 129 | if($current_tag == $theme) { |
|---|
| 130 | $imported_theme['theme'] = trim($data); |
|---|
| 131 | } elseif($current_tag == $themeTitle) { |
|---|
| 132 | $imported_theme['title'] = trim($data); |
|---|
| 133 | } elseif($current_tag == $themeAuthor) { |
|---|
| 134 | $imported_theme['author'] = trim($data); |
|---|
| 135 | } elseif($current_tag == $themeURI) { |
|---|
| 136 | $imported_theme['uri'] = trim($data); |
|---|
| 137 | } elseif($current_tag == $blockID) { |
|---|
| 138 | $id = trim($data); |
|---|
| 139 | } elseif($current_tag == $blockUBI) { |
|---|
| 140 | $imported_blocks[$id]['ubi'] = trim($data); |
|---|
| 141 | } elseif($current_tag == $blockName) { |
|---|
| 142 | $imported_blocks[$id]['name'] = trim($data); |
|---|
| 143 | } elseif($current_tag == $blockType) { |
|---|
| 144 | $imported_blocks[$id]['type'] = trim($data); |
|---|
| 145 | } elseif($current_tag == $blockZone) { |
|---|
| 146 | $imported_blocks[$id]['zone'] = trim($data); |
|---|
| 147 | } elseif($current_tag == $blockPosition) { |
|---|
| 148 | $imported_blocks[$id]['position'] = trim($data); |
|---|
| 149 | } elseif($current_tag == $blockAuthor) { |
|---|
| 150 | $imported_blocks[$id]['author'] = trim($data); |
|---|
| 151 | } elseif($current_tag == $blockDesc) { |
|---|
| 152 | $imported_blocks[$id]['description'] = trim($data); |
|---|
| 153 | } elseif($current_tag == $blockGroup) { |
|---|
| 154 | $imported_blocks[$id]['group'] = trim($data); |
|---|
| 155 | } elseif($current_tag == $blockURI) { |
|---|
| 156 | $imported_blocks[$id]['uri'] = trim($data); |
|---|
| 157 | } elseif($current_tag == $blockPath) { |
|---|
| 158 | $imported_blocks[$id]['path'] = trim($data); |
|---|
| 159 | } elseif($current_tag == $variableName) { |
|---|
| 160 | $variable = trim($data); |
|---|
| 161 | $imported_variables[$id][$variable]['name'] = trim($data); |
|---|
| 162 | } elseif($current_tag == $variableValue) { |
|---|
| 163 | $imported_variables[$id][$variable]['value'] = trim($data); |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | function endElement($parser, $name) { |
|---|
| 168 | global $current_tag; |
|---|
| 169 | $caret_pos = strrpos($current_tag,'^'); |
|---|
| 170 | $current_tag = substr($current_tag,0,$caret_pos); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | function startElement($parser, $name, $attrs) { |
|---|
| 174 | global $current_tag; |
|---|
| 175 | $current_tag .= "^$name"; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | // Scans the directory (included for PHP 4 users) |
|---|
| 179 | if(!function_exists(scandirectory)) { |
|---|
| 180 | function scandirectory($dir = './', $sort = 0) { |
|---|
| 181 | $dir_open = @opendir($dir); |
|---|
| 182 | if (!$dir_open) return false; |
|---|
| 183 | while(($dir_content = readdir($dir_open)) !== false) { |
|---|
| 184 | $files[] = $dir_content; |
|---|
| 185 | } |
|---|
| 186 | if ($sort == 1) rsort($files, SORT_STRING); |
|---|
| 187 | else sort($files, SORT_STRING); |
|---|
| 188 | return $files; |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | ?> |
|---|