4 * \defgroup Skin Skin Module
10 * The skin module, which controls the output of content.
11 * The skin system allows for nearly all output of the system to be
12 * customized by user skins.
14 * If path_not_found or access denied it should not proccess certain aspects such as tabs and stuff
17 define('DEFAULT_SKIN', 'bluebreeze');
18 global $skin, $styles, $scripts;
20 function skin_ini($skin = NULL){
24 //Use session variables when complete
25 if(user_access('select own skin', 'skin') && core_variable_get('skin per user', 0) == 1){
26 $skin = db_query("SELECT theme FROM {PRE_}users WHERE uid = ".$user['uid']." AND theme != '' ", TRUE, TRUE);
29 //Select theme if no user specific theme was selected
30 if(!isset($skin['name'])){
31 $skin['name'] = core_variable_get('skin_default', DEFAULT_SKIN);
34 $skin['path'] = dirname(core_get_filename($skin['name'], 'theme'));
36 //Load the templates engine
37 include_once($skin['path'].'/'.$skin['name'].'.template');
39 $ini = parse_ini_file($skin['path'].'/'.$skin['name'].'.ini', 'sections');
42 $skin['data'] = db_query("SELECT * FROM {PRE_}system WHERE type = 'theme' AND name = '".$skin['name']."'", TRUE, TRUE);
45 call_user_func($skin['name'].'_boot');
46 $skin['regions']['list'] = $skin['regions'];
53 * This will set the themes default settings like photos in posts and so on
55 * This function may be merged with _ini
57 function skin_set_defaults(){
59 global $skin, $settings;
61 //Add site's name to title
62 if(!isset($skin['head_title'])){
63 $skin['head_title'] = (isset($skin['page_title']) ? $skin['page_title'] : core_variable_get('site_name', 'localhost'));
67 $skin['site_name'] = core_variable_get('site_name', 'esTigi');
70 $skin['site_path'] = $settings['base_root'].$settings['base_url'] . $settings['base_path'];
72 //Get all variables for this skin, if any
73 core_variable_get(NULL, FALSE, $skin['name']);
74 if(count($settings['variables'][$skin['name']]) > 0){
75 foreach($settings['variables'][$skin['name']] as $var => $content){
76 $skin[$var] = $content;
80 //Not all of this are skin related, but for now it should work. They will be moved to the general skin varibles
81 foreach($settings['variables']['system'] as $var => $content){
82 $skin[$var] = $content;
85 //Set the correct logo
86 if($skin['display_logo'] == 0){
87 $skin['logo'] = FALSE;
90 $skin['logo'] = $skin['path'] .'/'. $skin['logo'];
98 * An array of tabs to add
100 * The type of tab options: primary, secundary
102 * Add proper support for secundary tabs
104 function skin_tabs($tabs, $type = 'primary'){
109 foreach($tabs as $url => $tab){
110 $class = ($x == $url ? 'tabs_'.$type.'_active' : 'tabs_'.$type);
111 $skin['all_tabs'][$type] .= '<span class="'.$class.'"><a href="'.path_set_url($url).'" class="'.$class.'">'.$tab.'</a></span>';
116 if($skin['all_tabs']){
117 foreach($skin['all_tabs'] as $type => $tab){
118 $skin['tabs'] .= $tab . '<br>';
125 * Theme a tpl file provided by modules
126 * file format module-filename.tpl.php
127 * file format module-filename_VAR_.tpl.php (variable content files)
128 * it will be converted to module-filename-var_name-.tpl.php
130 * The module that is calling this
132 * The name of the template file, without the .tpl.php extention
134 * The content with which you want to dress your template
136 * A variable portion of the name to replace _VAR_ with under certain situations.
140 function skin_dressme_tpl($module, $file, $content, $var = NULL){
145 $module_dir = dirname(core_get_filename($module));
146 $fullfilename = NULL;
148 //Load the appropriate file
150 $filevar = str_replace('_VAR_', $var, $file);
152 //Overriden file with variable name
153 if(file_exists($skin['path'] . '/' . $filevar)){
154 $fullfilename = $skin['path'] . '/' . $filevar;
156 //If not, we'll look for the generic file
157 elseif(file_exists($skin['path'] . '/' . $file)){
158 $fullfilename = $skin['path'] . '/' . $file;
160 //If not we'll see if there is a file with this overriden name in the modules directory
161 elseif(file_exists($module_dir . '/' . $filevar)){
162 $fullfilename = $module_dir . '/' . $filevar;
166 if(!isset($fullfilename)){
167 //If this does not exist your module has problems
168 $fullfilename = $module_dir . '/' . $file;
172 return skin_get_content($fullfilename, $module, $content, $type);
176 * Theme a tpl function provided by modules
177 * function name format module_function()
178 * function format module_function_VAR_() (variable content files)
179 * it will be converted to module_function-var_name()
181 function skin_dressme_func($module, $function, $content, $file, $var = NULL){
185 core_load($module, $file);
187 //Load the appropriate function
189 $funcvar = str_replace('_VAR_', $var, $function);
190 //$funcvar_skinned = str_replace('_VAR_', $var, $function);
191 //Overriden file with variable name
192 if(function_exists($funcvar.'_'.$skin['name'])){
193 return call_user_func($funcvar.'_'.$skin['name'], $content);
195 //If not, we'll look for the generic function
196 elseif(function_exists($function.'_'.$skin['name'])){
197 return call_user_func($function.'_'.$skin['name'], $content);
199 //If not we'll see if there is a file with this overriden name in the modules directory
200 elseif(function_exists($funcvar)){
201 return call_user_func($funcvar, $content);
205 return call_user_func($function, $content);
209 function skin_links(){
211 global $links, $skin;
213 //$links[$nid]['type']
216 if(!isset($the_links)){
217 if(is_array($links) && count($links) > 0){
218 foreach($links as $node_id => $link_data){
219 foreach($link_data as $link_type => $link_details){
220 $the_links[$node_id][$link_type] = '<div class="links_'.$link_type.'">';
221 foreach($link_details as $link){
222 $the_links[$node_id][$link_type] .= '<a href="'.path_set_url($link['href']).'" class="'.$link['class'].'"'.$link['attributes'].' >'.$link['text'].'</a> ';
224 $the_links[$node_id][$link_type] .= '</div>';
230 $skin['links'] = $the_links;
237 * Return a themed image.
240 * Either the path of the image file (relative to base path)
242 * The alternative text for text-based browsers.
244 * The title text is displayed when the image is hovered in some popular browsers.
246 * List of attributes to be placed in the img tag.
248 * A string containing the image tag.
250 * Give the posibility to indicate max(width|height) and adjust acordingly
252 * Skin full url path images
255 function skin_image($path, $alt = '', $title = '', $attributes = NULL) {
259 $url = $settings['base_root'] . $settings['base_url'] . $settings['base_path'] . $path;
261 return '<img src="'. $url .'" alt="'. $alt .'" title="'. $title .'" '. (isset($attributes) ? $attributes : '') .' />';
265 * Handles css loading
266 * This function handles the css used by modules and skins
268 * Overide module css with theme's custom css - Use skin.template for this
270 function skin_add_css($ref, $name, $type = 'theme'){
272 global $base_path, $skin;
277 $path = dirname(core_get_filename($ref, $type));
279 //this should be validated with the skin settings
280 return $styles .= '<link type="text/css" rel="stylesheet" media="all" href="'.$path.'/'.$name.'" />';
284 function skin_add_script(){
286 $scripts .= '<script type="text/javascript" src="misc/js/jquery.js"></script>';
287 return $scripts = '<script type="text/javascript" src="misc/js/jquery.validationEngine.js"></script>';
292 * Gets a template file with its variable parts replaced
293 * As seen on http://cr.php.net/manual/en/function.include.php
295 * The name of the file to use
297 * The name of the module using the skins
299 * An array with the content to be used in the skin. In the skin all variables will be accessible using a variable $foo[]
302 function skin_get_content($filename, $module = NULL, $content) {
304 global $skin, $base_path, $styles, $scripts;
306 //This will make the contents of the variables available to the tpl
311 if (is_file($filename)) {
314 $contents = ob_get_contents();
321 //No idea what this is doing
322 function skin_get_settings(){
329 * Give the final touches and load the skin
331 function skin_fini($content){
333 global $skin, $base_path;
335 skin_add_css(core_variable_get('default_skin', DEFAULT_SKIN), 'style.css');
336 $skin['styles'] = skin_add_css(core_variable_get('default_skin', DEFAULT_SKIN), 'layout.css');
337 //$scripts = skin_add_script();
339 //$content = $content;
344 //Create warnings and such
345 $warnings = system_warnings(NULL);
346 if(count($warnings) > 0){
347 foreach($warnings as $type => $warning){
348 $skin['messages'] .= skin_dressme_func('system', 'system_warning_skin_VAR_', array($warning, $type), 'skinned', '-'.$type);
355 $filename = $skin['path'] . '/page.tpl.php';
356 //Create the variables as needed
358 //Load the index of the theme and print it
359 //It may be faster or less memory consuming to just print the page, we don't need the buffer any more really
360 //return skin_get_content($filename, '', $content);
361 include_once($filename);