Minor tweaks and house cleaning
[estigi.git] / core / block / block.module
blob2f17c6ddaf1e7ad6bc14e7893703a9bb3761018a
1 <?php
3 /**
4  * Determines if a block wil be visible or not
5  * @param &$block
6  *  A pointer to the $block array
7  * @todo
8  *  Fix/Create def_view and everything else, there is a lot to be done here
9  */
10 function block_visibility(&$block) {
12         global $user, $x, $xx;
14         //By default it will not be displayed
15         $by_view = $by_role = $by_page = FALSE;
17         //This is not complete
18         //Default visibility    
19         if($block['def_view'] == 'av'){
20                 $by_view = TRUE;
21         }
22         elseif($block['def_view'] == ''){
23                 $by_view = TRUE;
24         }
25         else{
26                 $by_view = TRUE;
27         }
29         //Determine if this role will see it
30         if($block['roles'] != ''){
31                 $block['roles'] = explode(',', $block['roles']);
32                 foreach($user['roles'] as $userrole => $role){
33                         if(in_array($userrole, $block['roles'])){
34                                 $by_role = TRUE;
35                         }
36                 }
37         }
38         else{
39                 $by_role = TRUE;
40         }
42         //Determine if this page will see it
43         if($block['pages'] != ''){
44                 if($block['pages_type'] < 2){
45                                 $page_match = path_match_path($x, $block['pages']);
46                         //In all pages except the following ones
47                         if($block['pages_type'] == 0 && $page_match == 0){
48                                 $by_page = TRUE;
49                         }
50                         //Only in the following pages
51                         elseif($block['pages_type'] == 1 && $page_match){
52                                 $by_page = TRUE;
53                         }
54                 }
55                 //PHP type
56                 else{
57                         $by_page = eval($block['pages']);
58                 }
59         }
60         //If nothing came will make it true by default
61         else{
62                 $by_page = TRUE;
63         }
65         if($by_role && $by_page){
66                 return TRUE;
67         }
71 /**
72  * Implementation of hook_ini
73  * Setup all blocks for the current page
74  */
75 function block_ini(){
77         global $db, $skin, $block_display, $block_settings, $redirect;
79         if($redirect){
80                 return FALSE;
81         }
83         //Select all blocks
84         $blocks = db_query("SELECT b.*, br.* FROM {PRE_}blocks b INNER JOIN {PRE_}blocks_regions br on b.bid = br.bid WHERE skin = '".$skin['name']."' AND status = 1 ORDER BY pos ASC", TRUE);
86         if(!$blocks){
87                 return;
88         }
90         foreach($blocks as $block){
92                 //Lets see if it will be displayed
93                 if(block_visibility($block)){
95                         //format body
97                         //Custom settings
98                         if($block['settings'] != ''){
99                                 $block_settings['settings'] = unserialize($block['settings']);
100                                 foreach($block_settings['settings'] as $conf => $details){
101                                         $block_settings[$conf] = $details;
102                                 }
103                                 unset($block_settings['settings']);
104                         }
106                         $block['body'] = text_process($block['body'], $block['format']);
108                         //Set title
109                         $block['title'] = ($block['title_ov'] != '' ? ($block['title_ov'] == '<none>' ? '' : $block['title_ov']) : $block['title']);
111                         //skin block
112                         $contents = array('module' => $block['module'],'blockid' => $block['bid'], 'title' => ($block['title_ov'] != '' ? ($block['title_ov'] == '<none>' ? '' : $block['title_ov']) : $block['title']), 'body' => $block['body']);
113                         $skin['regions'][$block['region']] .= skin_dressme_tpl('block', 'block_VAR_', $contents, $block['bid']);
115                 }
117         }