Changeset 8012
- Timestamp:
- Dec 6, 2010, 9:52:44 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/themes/default/template/element_set_global.tpl
r7995 r8012 4 4 {footer_script}{literal} 5 5 pwg_initialization_datepicker("#date_creation_day", "#date_creation_month", "#date_creation_year", "#date_creation_linked_date", "#date_creation_action_set"); 6 </script>7 6 {/literal}{/footer_script} 8 7 -
trunk/include/config_default.inc.php
r7501 r8012 480 480 // production environment. 481 481 $conf['template_force_compile'] = false; 482 483 // activate merging of javascript / css files 484 $conf['template_combine_files'] = true; 482 485 483 486 // this permit to show the php errors reporting (see INI 'error_reporting' -
trunk/include/template.class.php
r8008 r8012 397 397 $scripts = $this->scriptLoader->get_head_scripts(); 398 398 $content = array(); 399 foreach ($scripts as $ id => $script)399 foreach ($scripts as $script) 400 400 { 401 401 $content[]= … … 412 412 { 413 413 ksort($this->css_by_priority); 414 $combiner = new FileCombiner('css'); 415 foreach ($this->css_by_priority as $files) 416 { 417 foreach ($files as $file_ver) 418 { 419 $combiner->add( $file_ver[0], $file_ver[1] ); 420 } 421 } 422 if ( $combiner->combine( $out_file, $out_version) ) 423 { 424 $href = get_root_url() . $out_file; 425 if ($out_version !== false) 426 $href .= '?v' . ($out_version ? $out_version : PHPWG_VERSION); 414 415 global $conf; 416 $css = array(); 417 if ($conf['template_combine_files']) 418 { 419 $combiner = new FileCombiner('css'); 420 foreach ($this->css_by_priority as $files) 421 { 422 foreach ($files as $file_ver) 423 $combiner->add( $file_ver[0], $file_ver[1] ); 424 } 425 if ( $combiner->combine( $out_file, $out_version) ) 426 $css[] = array($out_file, $out_version); 427 } 428 else 429 { 430 foreach ($this->css_by_priority as $files) 431 $css = array_merge($css, $files); 432 } 433 434 $content = array(); 435 foreach( $css as $file_ver ) 436 { 437 $href = get_root_url() . $file_ver[0]; 438 if ($file_ver[1] !== false) 439 $href .= '?v' . ($file_ver[1] ? $file_ver[1] : PHPWG_VERSION); 427 440 // trigger the event for eventual use of a cdn 428 $href = trigger_event('combined_css', $href, $out_file, $out_version); 429 $this->output = str_replace(self::COMBINED_CSS_TAG, 430 '<link rel="stylesheet" type="text/css" href="'.$href.'">', 441 $href = trigger_event('combined_css', $href, $file_ver[0], $file_ver[1]); 442 $content[] = '<link rel="stylesheet" type="text/css" href="'.$href.'">'; 443 } 444 $this->output = str_replace(self::COMBINED_CSS_TAG, 445 implode( "\n", $content ), 431 446 $this->output ); 432 }433 447 } 434 448 … … 569 583 else 570 584 { 571 if (!$this->scriptLoader->did_head())572 fatal_error('get_combined_scripts didn\'t call header');573 585 $scripts = $this->scriptLoader->get_footer_scripts(); 574 foreach ($scripts[0] as $ id => $script)586 foreach ($scripts[0] as $script) 575 587 { 576 588 $content[]= 577 589 '<script type="text/javascript" src="' 578 . Template::make_script_src($script)590 . self::make_script_src($script) 579 591 .'"></script>'; 580 592 } … … 596 608 $content[]= 597 609 's=document.createElement(\'script\'); s.type = \'text/javascript\'; s.async = true; s.src = \'' 598 . Template::make_script_src($script)610 . self::make_script_src($script) 599 611 .'\';'; 600 612 $content[]= 'after = after.parentNode.insertBefore(s, after);'; … … 611 623 { 612 624 $ret = ''; 613 if ( url_is_remote($script->path) )625 if ( $script->is_remote() ) 614 626 $ret = $script->path; 615 627 else … … 621 633 } 622 634 } 635 // trigger the event for eventual use of a cdn 636 $ret = trigger_event('combined_script', $ret, $script); 623 637 return $ret; 624 638 } … … 639 653 $version = isset($params['version']) ? $params['version'] : 0; 640 654 $this->css_by_priority[$order][] = array( $params['path'], $version); 641 //var_export( $this->css_by_priority ); echo "<br>";642 655 } 643 656 … … 830 843 public $extra = array(); 831 844 832 function Script($ id, $load_mode, $precedents, $path, $version)845 function Script($load_mode, $id, $path, $version, $precedents) 833 846 { 834 847 $this->id = $id; 835 848 $this->load_mode = $load_mode; 849 $this->id = $id; 850 $this->set_path($path); 851 $this->version = $version; 836 852 $this->precedents = $precedents; 837 $this->path = $path;838 $this->version = $version;839 853 } 840 854 … … 844 858 $this->path = $path; 845 859 } 846 860 847 861 function is_remote() 848 862 { … … 902 916 if (! isset( $this->registered_scripts[$id] ) ) 903 917 { 904 $script = new Script($ id, $load_mode, $require, $path, $version);918 $script = new Script($load_mode, $id, $path, $version, $require); 905 919 self::fill_well_known($id, $script); 906 920 $this->registered_scripts[$id] = $script; … … 946 960 } 947 961 $this->did_head = true; 948 return $this->head_done_scripts;962 return self::do_combine($this->head_done_scripts, 0); 949 963 } 950 964 951 965 function get_footer_scripts() 952 966 { 953 if (!$this->did_head)967 /*if (!$this->did_head) 954 968 { 955 969 trigger_error("Attempt to write footer scripts without header scripts", E_USER_ERROR ); 956 } 957 970 }*/ 958 971 $todo = array(); 959 972 foreach( $this->registered_scripts as $id => $script) … … 971 984 uasort($todo, array('ScriptLoader', 'cmp_by_mode_and_order')); 972 985 973 974 986 $result = array( array(), array() ); 975 987 foreach( $todo as $id => $script) … … 977 989 $result[$script->load_mode-1][$id] = $script; 978 990 } 979 return $result; 980 } 981 991 return array( self::do_combine($result[0],1), self::do_combine($result[1],2) ); 992 } 993 994 private static function do_combine($scripts, $load_mode) 995 { 996 global $conf; 997 if (count($scripts)<2 or !$conf['template_combine_files']) 998 return $scripts; 999 $combiner = new FileCombiner('js'); 1000 foreach ($scripts as $script) 1001 { 1002 if ($script->is_remote()) fatal_error("NOT IMPLEMENTED");// TODO - we cannot combine remote scripts 1003 $combiner->add( $script->path, $script->version ); 1004 } 1005 if ( $combiner->combine( $out_file, $out_version) ) 1006 { 1007 return array( 'combi' => new Script($load_mode, 'combi', $out_file, $out_version, array() ) ); 1008 } 1009 return null; 1010 } 1011 1012 // checks that if B depends on A, then B->load_mode >= A->load_mode in order to respect execution order 982 1013 private static function check_load_dep($scripts) 983 1014 { 1015 global $conf; 984 1016 do 985 1017 { … … 999 1031 $changed = true; 1000 1032 } 1001 if ($load==2 && $scripts[$precedent]->load_mode==2 && $script->is_remote() )1033 if ($load==2 && $scripts[$precedent]->load_mode==2 && ($script->is_remote() or !$conf['template_combine_files']) ) 1002 1034 {// we are async -> a predecessor cannot be async unlesss it can be merged; otherwise script execution order is not guaranteed 1003 1035 $scripts[$precedent]->load_mode = 1; … … 1009 1041 while ($changed); 1010 1042 } 1011 1012 1043 1044 1013 1045 private static function fill_well_known($id, $script) 1014 1046 { … … 1049 1081 $ret = $s1->load_mode - $s2->load_mode; 1050 1082 if ($ret) return $ret; 1051 1083 1052 1084 $ret = $s1->extra['order'] - $s2->extra['order']; 1053 1085 if ($ret) return $ret; 1054 1086 1055 1087 if ($s1->extra['order']==0 and ($s1->is_remote() xor $s2->is_remote()) ) 1056 1088 { … … 1074 1106 $this->type = $type; 1075 1107 } 1076 1108 1077 1109 static function clear_combined_files() 1078 1110 { … … 1100 1132 function combine(&$out_file, &$out_version) 1101 1133 { 1102 //var_export($this);1103 1134 if (count($this->files) == 0) 1104 1135 { … … 1140 1171 $output .= "/* BEGIN $input_file */\n"; 1141 1172 if ($this->type == "css") 1142 { 1143 $output .= $this->process_css($input_file); 1144 } 1173 $output .= self::process_css($input_file); 1145 1174 else 1146 $output .= file_get_contents(PHPWG_ROOT_PATH .$input_file);1175 $output .= self::process_js($input_file); 1147 1176 $output .= "\n"; 1148 1177 } … … 1155 1184 } 1156 1185 1157 private function process_css($file) 1186 private static function process_js($file) 1187 { 1188 $js = file_get_contents(PHPWG_ROOT_PATH . $file); 1189 if (strpos($file, '.min')===false and strpos($file, '.packed')===false ) 1190 { 1191 //TODO minify javascript with some php lib from www... 1192 } 1193 return $js; 1194 } 1195 1196 private static function process_css($file) 1158 1197 { 1159 1198 static $PATTERN = "#url\(\s*['|\"]{0,1}(.*?)['|\"]{0,1}\s*\)#"; … … 1181 1220 { 1182 1221 $search[] = $match[0]; 1183 $replace[] = $this->process_css(dirname($file) . "/$match[1]");1222 $replace[] = self::process_css(dirname($file) . "/$match[1]"); 1184 1223 } 1185 1224 $css = str_replace($search, $replace, $css); -
trunk/plugins/admin_multi_view/controller.php
r6358 r8012 12 12 pwg_unset_session_var( 'multiview_debug_l10n' ); 13 13 pwg_unset_session_var( 'multiview_debug_template' ); 14 pwg_unset_session_var( 'multiview_template_combine_files' ); 14 15 pwg_unset_session_var( 'multiview_no_history' ); 15 16 ?> … … 85 86 $refresh_main = true; 86 87 } 88 89 if ( isset($_GET['template_combine_files']) ) 90 { 91 if ( $_GET['template_combine_files']==0 ) 92 pwg_set_session_var( 'multiview_template_combine_files', 0 ); 93 else 94 pwg_unset_session_var( 'multiview_template_combine_files' ); 95 $refresh_main = true; 96 } 97 87 98 88 99 if ( isset($_GET['no_history']) ) … … 195 206 196 207 // +-----------------------------------------------------------------------+ 208 // | template combine files | 209 $template_combine_files_html=''; 210 if ($conf['template_combine_files']) 211 { 212 if ( pwg_get_session_var( 'multiview_template_combine_files', 1 ) ) 213 $template_combine_files_html.='<a href="'.$my_url.'?template_combine_files=0">Don\'t combine js&css</a>'; 214 else 215 $template_combine_files_html.='<a href="'.$my_url.'?template_combine_files=1">Combine js&css</a>'; 216 } 217 218 // +-----------------------------------------------------------------------+ 197 219 // | no history | 198 220 $no_history_html=''; … … 225 247 <tr><td>Lang</td><td><?php echo $lang_html; ?></td></tr> 226 248 </table> 227 <?php echo implode( "<br/>\n", array($show_queries_html, $debug_l10n_html, $debug_template_html, $ no_history_html) ); ?>249 <?php echo implode( "<br/>\n", array($show_queries_html, $debug_l10n_html, $debug_template_html, $template_combine_files_html, $no_history_html) ); ?> 228 250 229 251 <script type="text/javascript"> -
trunk/plugins/admin_multi_view/is_admin.inc.php
r5128 r8012 26 26 if (pwg_get_session_var( 'multiview_debug_template', 0 )) 27 27 $conf['debug_template'] = true; 28 if (pwg_get_session_var( 'multiview_no_history', 0 )) 28 if (!pwg_get_session_var( 'multiview_template_combine_files', 1 )) 29 $conf['template_combine_files'] = false; 30 if (pwg_get_session_var( 'multiview_no_history', 0 )) 29 31 { 30 32 add_event_handler( 'pwg_log_allowed', create_function( '', 'return false;' ) );
Note: See TracChangeset
for help on using the changeset viewer.