Working on new access system...
[estigi.git] / core / block / block.module
blob5d513e71fd1d6e7b2b160f6dc1390b8383bd920c
1 <?php
3 /**
4  * \defgroup Block Block Module
5  */
6 /*@{*/
8 /**
9  * Determines if a block wil be visible or not
10  * @param &$block
11  *  A pointer to the $block array
12  * @todo
13  *  Fix/Create def_view and everything else, there is a lot to be done here
14  */
15 function block_visibility(&$block) {
17         global $user, $x, $xx;
19         //By default it will not be displayed
20         $by_view = $by_role = $by_page = FALSE;
22         //This is not complete
23         //Default visibility    
24         if($block['def_view'] == 'av'){
25                 $by_view = TRUE;
26         }
27         elseif($block['def_view'] == ''){
28                 $by_view = TRUE;
29         }
30         else{
31                 $by_view = TRUE;
32         }
34         //Determine if this role will see it
35         if($block['roles'] != ''){
36                 $block['roles'] = explode(',', $block['roles']);
37                 foreach($user['roles'] as $userrole => $role){
38                         if(in_array($userrole, $block['roles'])){
39                                 $by_role = TRUE;
40                         }
41                 }
42         }
43         else{
44                 $by_role = TRUE;
45         }
47         //Determine if this page will see it
48         if($block['pages'] != ''){
49                 if($block['pages_type'] < 2){
50                                 $page_match = path_match_path($x, $block['pages']);
51                         //In all pages except the following ones
52                         if($block['pages_type'] == 0 && $page_match == 0){
53                                 $by_page = TRUE;
54                         }
55                         //Only in the following pages
56                         elseif($block['pages_type'] == 1 && $page_match){
57                                 $by_page = TRUE;
58                         }
59                 }
60                 //PHP type
61                 else{
62                         $by_page = eval($block['pages']);
63                 }
64         }
65         //If nothing came will make it true by default
66         else{
67                 $by_page = TRUE;
68         }
70         if($by_role && $by_page){
71                 return TRUE;
72         }
76 /**
77  * Implementation of hook_ini
78  * Setup all blocks for the current page
79  */
80 function block_ini(){
82         global $db, $skin, $block_display, $block_settings, $redirect;
84         if($redirect){
85                 return FALSE;
86         }
88         //Select all blocks
89         $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);
91         if(!$blocks){
92                 return;
93         }
95         foreach($blocks as $block){
97                 //Lets see if it will be displayed
98                 if(block_visibility($block)){
100                         //format body
102                         //Custom settings
103                         if($block['settings'] != ''){
104                                 $block_settings['settings'] = unserialize($block['settings']);
105                                 foreach($block_settings['settings'] as $conf => $details){
106                                         $block_settings[$conf] = $details;
107                                 }
108                                 unset($block_settings['settings']);
109                         }
111                         $block['body'] = text_process($block['body'], $block['format']);
113                         //Set title
114                         $block['title'] = ($block['title_ov'] != '' ? ($block['title_ov'] == '<none>' ? '' : $block['title_ov']) : $block['title']);
116                         //skin block
117                         $contents = array('module' => $block['module'],'blockid' => $block['bid'], 'title' => ($block['title_ov'] != '' ? ($block['title_ov'] == '<none>' ? '' : $block['title_ov']) : $block['title']), 'body' => $block['body']);
118                         $skin['regions'][$block['region']] .= skin_dressme_tpl('block', 'block_VAR_', $contents, $block['bid']);
120                 }
122         }
127 /*@}*/