[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 #------------------------------------------------------------------------- 3 # Module: ThemeManager - a module for importing and exporting template 4 # and stylesheet packages. 5 # Version: 1.0.6, Robert Campbell <rob@techcom.dyndns.org> 6 # 7 #------------------------------------------------------------------------- 8 # CMS - CMS Made Simple is (c) 2005 by Ted Kulp (wishy@cmsmadesimple.org) 9 # This project's homepage is: http://www.cmsmadesimple.org 10 # 11 #------------------------------------------------------------------------- 12 # 13 # This program is free software; you can redistribute it and/or modify 14 # it under the terms of the GNU General Public License as published by 15 # the Free Software Foundation; either version 2 of the License, or 16 # (at your option) any later version. 17 # 18 # This program is distributed in the hope that it will be useful, 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 # GNU General Public License for more details. 22 # You should have received a copy of the GNU General Public License 23 # along with this program; if not, write to the Free Software 24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 # Or read it online: http://www.gnu.org/licenses/licenses.html#GPL 26 # 27 #------------------------------------------------------------------------- 28 29 // 30 // Permissions test 31 // 32 if( !$this->CheckPermission('Manage Themes') ) 33 { 34 $this->DisplayErrorPage($id, $params, $return_id, 35 $this->Lang('accessdenied')); 36 return; 37 } 38 39 40 /*--------------------------------------------------------- 41 _extractMenuManagerTemplates 42 ---------------------------------------------------------*/ 43 function _extractMenuManagerTemplates( $template ) 44 { 45 // get all the menumanager tags 46 $regex='/\{.*menumanager.*\}/i'; 47 preg_match_all( $regex, $template->content, $t_matches ); 48 49 // $matches[1] is all important 50 // now parse the cms_module tag, and look for a template parameter 51 $result = array(); 52 if( is_array( $t_matches ) && count($t_matches) >= 1 ) 53 { 54 foreach( $t_matches[0] as $t_match ) 55 { 56 if( preg_match( "/template\s*=[\\\"']{0,1}([a-zA-Z0-9._\ \:\-\/]+)[\\\"']{0,1}/i", $t_match, $t_matches2 ) ) 57 { 58 $result[] = $t_matches2[1]; 59 } 60 else 61 { 62 # no template named, so assume bulletmenu.tpl 63 $result[] = 'default'; 64 } 65 } 66 } 67 return $result; 68 } 69 70 71 /*--------------------------------------------------------- 72 _extractStylesheetImages 73 ---------------------------------------------------------*/ 74 function _extractStylesheetImages($stylesheet) 75 { 76 $regex='/url\s*\(\"*(.*)\"*\)/i'; 77 preg_match_all( $regex, $stylesheet->value, $matches ); 78 // $matches[1] is all immportant 79 // now strip out any that have ^http in them 80 $result = array(); 81 foreach( $matches[1] as $match ) 82 { 83 if( !preg_match( '/^http\:/', $match ) ) 84 { 85 $result[] = $match; 86 } 87 } 88 89 return $result; 90 } 91 92 93 /*--------------------------------------------------------- 94 _extractTemplateImages 95 ---------------------------------------------------------*/ 96 function _extractTemplateImages($template) 97 { 98 $result = array(); 99 $urls = get_urls($template->content); 100 // we're only concerned about the src urls 101 foreach( $urls['src'] as $src ) 102 { 103 // if it's an external link we ignore it 104 // if it's an internal link, we add it 105 if( !preg_match('/^http\:/',$src) ) 106 { 107 $result[] = $src; 108 } 109 } 110 111 return $result; 112 } 113 114 115 /*--------------------------------------------------------- 116 _trim_themename 117 ---------------------------------------------------------*/ 118 function _trim_themename( $name ) 119 { 120 $t_name_arr = explode(':',$name); 121 if( count( $t_name_arr ) == 1 ) 122 { 123 $name = trim($t_name_arr[0]); 124 } 125 else 126 { 127 $name = trim($t_name_arr[1]); 128 } 129 return $name; 130 } 131 132 // 133 // begin 134 // 135 global $gCms; 136 $styleops =& $gCms->GetStylesheetOperations(); 137 138 $themename = trim($params['input_themename'] ); 139 if( $themename == '' ) 140 { 141 $themename = 'theme'; 142 } 143 $themename = str_replace(' ','_',$themename); 144 145 $template_ids = array(); 146 $templates = array(); 147 $stylesheet_ids = array(); 148 $associations = array(); 149 $mmtemplatenames = array(); 150 $urls = array(); 151 foreach( $params as $key => $value ) 152 { 153 if( !preg_match( '/^export/i', $key ) ) 154 { 155 continue; 156 } 157 158 $id = substr( $key, strlen('export') ); 159 $template_ids[] = $id; 160 161 // we are exporting a template 162 // get the template 163 global $gCms; 164 $templateops =& $gCms->GetTemplateOperations(); 165 $templates[$id] = $templateops->LoadTemplateByID( $id ); 166 if( !$templates[$id] ) 167 { 168 $this->DisplayErrorPage( $id, $params, $returnid, 169 $this->Lang('error_templatenotfound')); 170 return; 171 } 172 173 // get the images, etc attached to the template 174 $t_urls = _extractTemplateImages($templates[$id]); 175 $urls = array_merge( $urls, $t_urls ); 176 177 // get the stylesheets attached to that template 178 $stylesheets = $styleops->GetTemplateAssociatedStylesheets( $id ); 179 $assoc = array(); 180 $assoc['tname'] = $templates[$id]->name; 181 $tmp = array(); 182 foreach( $stylesheets as $cssid ) 183 { 184 $stylesheet_ids[] = $cssid; 185 $css = $styleops->LoadStylesheetByID( $cssid ); 186 $tmp[] = $css->name; 187 $cssurls = _extractStylesheetImages($css); 188 $urls = array_merge( $urls, $cssurls ); 189 } 190 $assoc['css'] = $tmp; 191 $associations[] = $assoc; 192 193 // get any menumanager templates attached to this template 194 $t_mmtemplates = _extractMenuManagerTemplates($templates[$id]); 195 $mmtemplatenames = array_merge( $mmtemplatenames, $t_mmtemplates ); 196 } 197 198 // make sure we're not outputting the same thing twice 199 $template_ids = array_unique( $template_ids ); 200 $stylesheet_ids = array_unique( $stylesheet_ids ); 201 $mmtemplatenames = array_unique( $mmtemplatenames ); 202 $urls = array_unique( $urls ); 203 204 // checks to see if there is actually anything to output 205 if( count( $template_ids ) == 0 || count( $stylesheet_ids ) == 0 ) 206 { 207 // nothing to output 208 $this->DisplayErrorPage( $id, $params, $returnid, 209 $this->Lang('error_nooutput')); 210 return; 211 } 212 213 $instance = $this->GetModuleInstance('MenuManager'); 214 if( !$instance ) 215 { 216 // nothing to output 217 $this->DisplayErrorPage( $id, $params, $returnid, 218 $this->Lang('error_nomenumanager')); 219 return; 220 } 221 222 // preprocess the templates 223 // make sure that we replace all {cms_module module=menumanager blah,blah,blah} 224 // where there's no template name specified with one that has a template name 225 foreach( $templates as $key => $onetemplate ) 226 { 227 $newcontent = $onetemplate->content; 228 229 // step 1 230 $pattern = "/\{cms_module\s+module\s*=\s*[\\\"']{0,1}menumanager[\\\"']{0,1}\s+template\s*=\s*[\\\"']{0,1}([.a-zA-Z0-9\ \:._\-\/]+)[\\\"']{0,1}(.*?)\}/i"; 231 $replacement = "{placeholder module='menumanager' template='$1' $2}"; 232 $newcontent = preg_replace( $pattern, $replacement, $newcontent ); 233 234 // step 2 235 $pattern = "/\{cms_module\s+module\s*=\s*[\\\"']{0,1}menumanager[\\\"']{0,1}\s+(.*?)\}/i"; 236 $replacement = "{cms_module module='menumanager' template='bulletmenu' $1}"; 237 $newcontent = preg_replace( $pattern, $replacement, $newcontent ); 238 239 // step 3 240 $pattern = "/\{placeholder\s+module\s*=\s*[\\\"']{0,1}menumanager[\\\"']{0,1}\s+(.*?)\}/i"; 241 $replacement = "{cms_module module='menumanager' $1}"; 242 $newcontent = preg_replace( $pattern, $replacement, $newcontent ); 243 244 $onetemplate->content = $newcontent; 245 $templates[$key] = $onetemplate; 246 } 247 248 // output the xml header 249 $output = '<?xml version="1.0" encoding="ISO-8859-1"?>'; 250 $output .= $this->dtd; 251 $output .= "<theme>\n"; 252 $output .= " <name>".$themename."</name>\n"; 253 $output .= " <dtdversion>".DTD_VERSION."</dtdversion>\n"; 254 255 // output the templates 256 foreach( $templates as $id => $template ) 257 { 258 // parse through the html and extract the image tags 259 // and images, etc. 260 261 $_name = _trim_themename( $template->name ); 262 $output .= " <template>\n"; 263 $output .= " <tname>".$_name."</tname>\n"; 264 $output .= " <tencoding>".$template->encoding."</tencoding>\n"; 265 $output .= " <tdata><![CDATA[".base64_encode($template->content)."]]></tdata>\n"; 266 $output .= " </template>\n"; 267 if( $template->stylesheet != '' ) 268 { 269 $output .= " <stylesheet>\n"; 270 $output .= " <cssname>".$template->name." -Attached-</cssname>\n"; 271 $output .= " <cssmediatype></cssmediatype>\n"; 272 $output .= " <cssdata><![CDATA[".base64_encode($template->stylesheet)."]]></cssdata>\n"; 273 $output .= " </stylesheet>\n"; 274 } 275 } 276 277 // the menumanager templates 278 foreach( $mmtemplatenames as $mmtpl_name ) 279 { 280 $mmtemplate = false; 281 if( $mmtpl_name == 'default' ) 282 { 283 // if no name was specified for a template, use bulletmenu.tpl 284 $mmtemplate = $instance->GetMenuTemplate( 'bulletmenu.tpl' ); 285 $mmtpl_name = 'bulletmenu'; 286 } 287 else 288 { 289 $mmtemplate = $instance->GetMenuTemplate( $mmtpl_name ); 290 } 291 if( !$mmtemplate ) 292 { 293 continue; 294 } 295 296 // trim any previous theme name off of this name 297 $_name = _trim_themename( $mmtpl_name ); 298 299 $output .= " <mmtemplate>\n"; 300 $output .= " <mmtemplate_name>".$mmtpl_name."</mmtemplate_name>\n"; 301 $output .= " <mmtemplate_data>".base64_encode($mmtemplate)."</mmtemplate_data>\n"; 302 $output .= " </mmtemplate>\n"; 303 } 304 305 // the stylesheets 306 foreach( $stylesheet_ids as $id ) 307 { 308 $stylesheet = $styleops->LoadStylesheetByID( $id ); 309 $_name = _trim_themename( $stylesheet->name ); 310 $output .= " <stylesheet>\n"; 311 $output .= " <cssname>".$_name."</cssname>\n"; 312 $output .= " <cssmediatype>".$stylesheet->media_type."</cssmediatype>\n"; 313 $output .= " <cssdata><![CDATA[".base64_encode($stylesheet->value)."]]></cssdata>\n"; 314 $output .= " </stylesheet>\n"; 315 } 316 317 foreach( $associations as $assoc1 ) 318 { 319 foreach( $assoc1['css'] as $t_assoc2 ) 320 { 321 $tname = _trim_themename( $assoc1['tname'] ); 322 $assoc2 = _trim_themename( $t_assoc2 ); 323 324 $output .= " <assoc>\n"; 325 $output .= " <assoc_tname>".$tname."</assoc_tname>\n"; 326 $output .= " <assoc_cssname>".$assoc2."</assoc_cssname>\n"; 327 $output .= " </assoc>\n"; 328 } 329 } 330 331 // the files 332 foreach( $urls as $oneurl ) 333 { 334 $contents = file_get_contents( $gCms->config['root_path'].DIRECTORY_SEPARATOR.$oneurl ); 335 if( !$contents ) 336 { 337 continue; 338 } 339 $encoded = base64_encode( $contents ); 340 $output .= " <reference>\n"; 341 $output .= " <refname>".basename($oneurl)."</refname>\n"; 342 $output .= " <refencoded>1</refencoded>\n"; 343 $output .= " <reflocation>$oneurl</reflocation>\n"; 344 $output .= " <refdata><![CDATA[".$encoded."]]></refdata>\n"; 345 $output .= " </reference>\n"; 346 } 347 348 // and the theme tail 349 $output .= "</theme>\n"; 350 351 // and spit it out 352 header('Content-Description: File Transfer'); 353 header('Content-Type: application/force-download'); 354 header('Content-Disposition: attachment; filename='.$themename.'.xml'); 355 // header('Content-Type: text/xml'); 356 // header('Content-Length: '.strlen($output)); 357 358 // todo, but good enough for now. 359 while(@ob_end_clean()); 360 echo $output; 361 exit(); 362 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |