Project

General

Profile

« Previous | Next » 

Revision 460

Added by Matthias almost 17 years ago

Added Changeset [458] and [459] to branches 2.6.x

View differences:

frontend.functions.php
290 290
	}
291 291
}
292 292

  
293
// Function to include optional module CSS stylesheets (module.css) into the <head> section
294
if (!function_exists('page_css')) {
295
	function page_css() {
296
    global $wb, $database;
297
    $css_head = "";
293
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend
294
if(!function_exists('register_frontend_modfiles')) {
295
	function register_frontend_modfiles($file_id="css") {
296
		// sanity check of parameter passed to the function
297
		$file_id = strtolower($file_id);
298
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") { 
299
			return;
300
		}
298 301

  
299
    // obtain list of modules used for actual displayed page
300
		$page_id=$wb->page_id;
301
    $query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections WHERE page_id=$page_id AND module<>'wysiwyg'");
302
    while($row = $query_modules->fetchRow()) {
303
      if(file_exists(WB_PATH .'/modules/' .$row['module'] .'/module.css')) {
304
        // build css link for current module.css
305
        $css_link = "<link href=\"" .WB_URL ."/modules/" .$row['module'];
306
        $css_link .= "/module.css\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\" />\n";
307
        // ensure that module.css is not added twice (e.g. if 2 sections include the same module)
308
        $css_head = str_replace($css_link, "", $css_head);
309
        $css_head .= $css_link;
310
      }
311
    }
312
    // write out links to all external module stylesheets (module.css)
313
    if($css_head != "") {
314
      $css_head = "<!-- Include external module CSS stylesheets -->\n" .$css_head;
315
      echo $css_head;
316
    }
317
	}
318
}
302
		global $wb, $database;
303
		// define default baselink and filename for optional module javascript and stylesheet files
304
		$head_links = "";
305
		if($file_id == "css") {
306
      	$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"'; 
307
			$base_link.= 'rel="stylesheet" type="text/css" media="screen" />';
308
			$base_file = "frontend.css";
309
		} else {
310
			$base_link = '<script type="text/javascript" src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js"></script>';
311
			$base_file = "frontend.js";
312
		}
319 313

  
320
// Function to include optional module javascript files (module.js) into the <head> section
321
if (!function_exists('page_javascript')) {
322
	function page_javascript() {
323
    global $wb, $database;
324
    $js_head = "";
314
  		// gather information for all models embedded on actual page
315
		$page_id = $wb->page_id;
316
    	$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections 
317
			WHERE page_id=$page_id AND module<>'wysiwyg'");
325 318

  
326
    // obtain list of modules used for actual displayed page
327
		$page_id=$wb->page_id;
328
    $query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections WHERE page_id=$page_id AND module<>'wysiwyg'");
329
    while($row = $query_modules->fetchRow()) {
330
      if(file_exists(WB_PATH .'/modules/' .$row['module'] .'/module.js')) {
331
        // build javascript link for current module.js
332
        $js_link = "<script type=\"text/javascript\" src=\"" .WB_URL ."/modules/" .$row['module'];
333
        $js_link .= "/module.js\"></script>\n";
334
        // ensure that module.js is not added twice (e.g. if 2 sections include the same module)
335
        $js_head = str_replace($js_link, "", $js_head);
336
        $js_head .= $js_link;
337
      }
338
    }
339
    // write out links to all external module javascript files (module.js)
340
    if($js_head != "") {
341
      $js_head = "<!-- Include external module javascript files -->\n" .$js_head;
342
      echo $js_head;
343
    }
319
    	while($row = $query_modules->fetchRow()) {
320
			// check if page module directory contains a frontend.js or frontend.css file
321
      	if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
322
				// create link with frontend.js or frontend.css source for the current module
323
				$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
324
        		// ensure that frontend.js or frontend.css is only added once per module type
325
        		if(strpos($head_links, $tmp_link) === false) {
326
					$head_links .= $tmp_link ."\n";
327
				}
328
			}
329
    	}
330
  		// write out links with all external module javascript/CSS files, remove last line feed
331
		echo $head_links;
344 332
	}
345 333
}
346 334

  

Also available in: Unified diff