[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare SiteMgr - Web Content Management * 4 * http://www.egroupware.org * 5 * -------------------------------------------- * 6 * This program is free software; you can redistribute it and/or modify it * 7 * under the terms of the GNU General Public License as published by the * 8 * Free Software Foundation; either version 2 of the License, or (at your * 9 * option) any later version. * 10 \**************************************************************************/ 11 12 /* $Id: class.sitebo.inc.php 20295 2006-02-15 12:31:25Z $ */ 13 14 class sitebo 15 { 16 var $pages_bo; 17 var $catbo; 18 var $acl; 19 20 function sitebo() 21 { 22 $this->catbo = &$GLOBALS['Common_BO']->cats; 23 $this->pages_bo = &$GLOBALS['Common_BO']->pages; 24 $this->acl = &$GLOBALS['Common_BO']->acl; 25 //$anonymous_user is globally set in config.inc.php 26 $this->isuser = ($GLOBALS['egw_info']['user']['account_lid'] != $GLOBALS['sitemgr_info']['anonymous_user']); 27 } 28 29 function is_admin() 30 { 31 return $this->acl->is_admin(); 32 } 33 34 function getcatwrapper($cat_id) 35 { 36 $availablelangsforcat = $this->catbo->getlangarrayforcategory($cat_id); 37 if (in_array($GLOBALS['sitemgr_info']['userlang'],$availablelangsforcat)) 38 { 39 return $this->catbo->getCategory($cat_id,$GLOBALS['sitemgr_info']['userlang']); 40 } 41 else 42 { 43 foreach ($GLOBALS['sitemgr_info']['sitelanguages'] as $lang) 44 { 45 if (in_array($lang,$availablelangsforcat)) 46 { 47 return $this->catbo->getCategory($cat_id,$lang); 48 } 49 } 50 } 51 //fall back to a category in "default" lang 52 return $this->catbo->getCategory($cat_id); 53 } 54 55 function getpagewrapper($page_id) 56 { 57 $availablelangsforpage = $this->pages_bo->getlangarrayforpage($page_id); 58 if (in_array($GLOBALS['sitemgr_info']['userlang'],$availablelangsforpage)) 59 { 60 return $this->pages_bo->GetPage($page_id,$GLOBALS['sitemgr_info']['userlang']); 61 } 62 else 63 { 64 foreach ($GLOBALS['sitemgr_info']['sitelanguages'] as $lang) 65 { 66 if (in_array($lang,$availablelangsforpage)) 67 { 68 return $this->pages_bo->GetPage($page_id,$lang); 69 } 70 } 71 } 72 //fall back to a page in "default" lang 73 return $this->pages_bo->GetPage($page_id); 74 } 75 76 function loadPage($page_id) 77 { 78 global $page; 79 $page = $this->getpagewrapper($page_id); 80 } 81 82 function loadIndex() 83 { 84 global $page; 85 $page->title = lang('Site Index'); 86 $page->subtitle = ''; 87 $page->index = True; 88 $page->block =& CreateObject('sitemgr.Block_SO',True); 89 $page->block->module_name = 'navigation'; 90 $page->block->arguments = array('nav_type' => 2); // former index 91 $page->block->module_id = $GLOBALS['Common_BO']->modules->getmoduleid('navigation'); 92 $page->block->view = SITEMGR_VIEWABLE_EVERBODY; 93 $page->block->status = SITEMGR_STATE_PUBLISH; 94 $page->cat_id = CURRENT_SITE_ID; 95 return true; 96 } 97 98 function getIndex($showhidden=true,$rootonly=false,$subtitles=False) 99 { 100 $cats = $this->getCatLinks(0,!$rootonly,$subtitles); 101 $index = array(); 102 103 if (count($cats)>0) 104 { 105 $content = "\n".'<ul>'; 106 foreach($cats as $cat_id => $cat) 107 { 108 $pages = $this->getPageLinks($cat_id,$showhidden,$subtitles); 109 if (count($pages)>0) 110 { 111 foreach($pages as $page_id => $link) 112 { 113 $index[] = array( 114 'cat_id'=>$cat_id, 115 'catname'=>$cat['name'], 116 'catdepth'=>$cat['depth'], 117 'catlink'=>$cat['link'], 118 'catdescrip'=>$cat['description'], 119 'page_id' => $page_id, 120 'pagename'=>$link['name'], 121 'pagelink'=>$link['link'], 122 'pagetitle'=>$link['title'], 123 'pagesubtitle'=>$link['subtitle'] 124 ); 125 } 126 } 127 else 128 { 129 $index[] = array( 130 'cat_id'=>$cat_id, 131 'catname'=>$cat['name'], 132 'catdepth'=>$cat['depth'], 133 'catdescrip'=>$cat['description'], 134 'catlink'=>$cat['link'], 135 'pagelink'=>lang('No pages available') 136 ); 137 } 138 } 139 } 140 return $index; 141 } 142 143 function loadTOC($category_id=false) 144 { 145 global $page; 146 147 $page->title = lang('Table of Contents'); 148 $page->subtitle = ''; 149 $page->toc = True; 150 $page->cat_id = $category_id ? $category_id : CURRENT_SITE_ID; 151 $page->block =& CreateObject('sitemgr.Block_SO',True); 152 $page->block->module_name = 'navigation'; 153 $page->block->arguments = array('category_id' => $category_id,'nav_type' => 6); // former toc 154 $page->block->module_id = $GLOBALS['Common_BO']->modules->getmoduleid('navigation'); 155 $page->block->view = SITEMGR_VIEWABLE_EVERBODY; 156 $page->block->state = SITEMGR_STATE_PUBLISH; 157 return true; 158 } 159 160 function getPageLinks($category_id, $showhidden=true,$subtitle=False) 161 { 162 $pages=$this->pages_bo->getPageIDList($category_id); 163 foreach($pages as $page_id) 164 { 165 $page=$this->getpagewrapper($page_id); 166 if ($showhidden || !$page->hidden) 167 { 168 $pglinks[$page_id] = array( 169 'name'=>$page->name, 170 'link'=>'<a href="'.sitemgr_link('page_name='.$page->name). 171 ($subtitle ? '" title="'.$page->subtitle : '').'">'.$page->title.'</a>', 172 'title'=>$page->title, 173 'subtitle'=>$page->subtitle 174 ); 175 } 176 } 177 return $pglinks; 178 } 179 180 function getCatLinks($cat_id=0,$recurse=true,$description=False) 181 { 182 $catlinks = array(); 183 $cat_list = $this->catbo->getpermittedcatsRead($cat_id,$recurse); 184 foreach($cat_list as $cat_id) 185 { 186 $category = $this->getcatwrapper($cat_id); 187 $catlinks[$cat_id] = array( 188 'name'=>$category->name, 189 'link'=>'<a href="'.sitemgr_link('category_id='.$cat_id). 190 ($description ? '" title="'.$category->description : '').'">'.$category->name.'</a>', 191 'description'=>$category->description, 192 'depth'=>$category->depth 193 ); 194 } 195 return $catlinks; 196 } 197 198 function check_load_translations($lang) 199 { 200 $GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $GLOBALS['sitemgr_info']['userlang'] = $lang; 201 202 //since there are lang calls in the API, and the first lang call builds $GLOBAL['lang'], we have to re-initialise 203 if ($GLOBALS['egw']->translation->userlang != $lang) 204 { 205 $GLOBALS['egw']->translation->init(); // unset $GLOBALS[lang] and re-reads 206 } 207 $GLOBALS['egw']->translation->add_app('sitemgr'); // as we run as sitemgr-site 208 } 209 210 //like $GLOBALS['egw']->common->getPreferredLanguage, 211 //but compares languages accepted by the user 212 //to the languages the website is configured for 213 //instead of the languages installed in egroupware 214 function setsitemgrPreferredLanguage() 215 { 216 $supportedLanguages = $GLOBALS['sitemgr_info']['sitelanguages'] ? $GLOBALS['sitemgr_info']['sitelanguages'] : array('en'); 217 $postlang = $_GET['lang']; 218 if ($postlang && in_array($postlang,$supportedLanguages)) 219 { 220 $GLOBALS['egw']->session->appsession('language','sitemgr-site',$postlang); 221 $this->check_load_translations($postlang); 222 return; 223 } 224 225 $sessionlang = $GLOBALS['egw']->session->appsession('language','sitemgr-site'); 226 if ($sessionlang) 227 { 228 $this->check_load_translations($sessionlang); 229 return; 230 } 231 232 if ($this->isuser) 233 { 234 $userlang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; 235 if (in_array($userlang,$supportedLanguages)) 236 { 237 //we do not touch $GLOBALS['egw_info']['user']['preferences']['common']['lang'] if 238 //the user is registered and his lang preference is supported by the website, 239 //but save it to the appsession for quicker retrieval 240 $GLOBALS['egw']->session->appsession('language','sitemgr-site',$userlang); 241 $this->check_load_translations($userlang); 242 return; 243 } 244 } 245 246 // create a array of languages the user is accepting 247 $userLanguages = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); 248 249 // find usersupported language 250 while (list($key,$value) = each($userLanguages)) 251 { 252 // remove everything behind '-' example: de-de 253 $value = trim($value); 254 $pieces = explode('-', $value); 255 $value = $pieces[0]; 256 //print "current lang $value<br>"; 257 if (in_array($value,$supportedLanguages)) 258 { 259 $browserlang = $value; 260 break; 261 } 262 } 263 264 // no usersupported language found -> return the first entry of sitelanguages 265 if (empty($browserlang)) 266 { 267 $browserlang = $supportedLanguages[0]; 268 } 269 270 $GLOBALS['egw']->session->appsession('language','sitemgr-site',$browserlang); 271 $this->check_load_translations($browserlang); 272 } 273 274 function getmode() 275 { 276 static $allowed_modes = array('Production'=>True,'Draft'=>True,'Edit'=>True); 277 if ($this->isuser) 278 { 279 $postmode = $_GET['mode']; 280 if (isset($allowed_modes[$postmode])) 281 { 282 $GLOBALS['egw']->session->appsession('mode','sitemgr-site',$postmode); 283 return $postmode; 284 } 285 $sessionmode = $GLOBALS['egw']->session->appsession('mode','sitemgr-site'); 286 if(isset($allowed_modes[$sessionmode])) 287 { 288 return $sessionmode; 289 } 290 } 291 return 'Production'; 292 } 293 294 295 function get_icons($icon_data,$link_data=array()) 296 { 297 $content = ''; 298 299 foreach($icon_data as $name => $data) 300 { 301 $label = array_shift($data); 302 if ($data['adminonly']) 303 { 304 if (!$this->acl->is_admin()) 305 { 306 continue; // only admin is allowed to eg. add/delete cats 307 } 308 unset($data['adminonly']); 309 } 310 $onclick = $open = "if (this != '') { window.open(this,this.target,'width=800,height=600,scrollbars=yes,resizable=yes'); return false; } else { return true; }"; 311 if ($data['confirm']) 312 { 313 $onclick = "if (confirm('".addslashes($data['confirm'])."')) { $open } else { return false; }"; 314 unset($data['confirm']); 315 } 316 $content .= $GLOBALS['egw']->html->a_href( 317 $GLOBALS['egw']->html->image('sitemgr',$name,$label,'border="0"'), 318 array_merge($link_data,$data),False,'target="editwindow" onclick="'.$onclick.'"'); 319 } 320 return $content; 321 } 322 323 // get the icons with links to be added to a cat in edit-mode 324 function getEditIconsCat($cat_id) 325 { 326 if ($GLOBALS['sitemgr_info']['mode'] == 'Edit' && $GLOBALS['Common_BO']->acl->can_write_category($cat_id)) 327 { 328 $cat = $GLOBALS['Common_BO']->cats->getCategory($cat_id,$GLOBALS['Common_BO']->sites->current_site['sitelanguages'][0]); 329 330 return $this->get_icons(array( 331 'new_page' => array(lang('Add page to category'),'menuaction'=>'sitemgr.Pages_UI.edit'), 332 'new' => array(lang('Add a category'),'adminonly'=>True,'cat_id'=>0,'addsub'=>$cat_id,'menuaction'=>'sitemgr.Categories_UI.edit'), 333 'edit' => array(lang('Edit category'),'adminonly'=>True,'menuaction'=>'sitemgr.Categories_UI.edit'), 334 'delete' => array(lang('Delete category'),'adminonly'=>True,'confirm'=>lang('Are you sure you want to delete the category %1 and all of its associated pages? You cannot retrieve the deleted pages if you continue.',$cat->name),'menuaction'=>'sitemgr.Categories_UI.delete','standalone'=>1), 335 ),array( 336 'page_id' => 0, 337 'cat_id' => $cat_id 338 )); 339 } 340 return ''; 341 } 342 343 // get the icons with links to be added to a page in edit-mode 344 function getEditIconsPage($page_id,$cat_id) 345 { 346 if ($GLOBALS['sitemgr_info']['mode'] == 'Edit' && $GLOBALS['Common_BO']->acl->can_write_category($cat_id)) 347 { 348 return $this->get_icons(array( 349 'edit' => array(lang('Edit page'),'menuaction'=>'sitemgr.Pages_UI.edit'), 350 'delete' => array(lang('Delete page'),'confirm'=>lang('Do you realy want to delete this page?'),'menuaction'=>'sitemgr.Pages_UI.delete'), 351 ),array( 352 'page_id' => $page_id, 353 'cat_id' => $cat_id 354 )); 355 } 356 return ''; 357 } 358 359 function getEditIconsTop() 360 { 361 if ($GLOBALS['sitemgr_info']['mode'] == 'Edit' && $GLOBALS['Common_BO']->acl->can_write_category(CURRENT_SITE_ID)) 362 { 363 return $this->get_icons(array( 364 'new' => array(lang('Add a category'),'adminonly'=>True,'menuaction'=>'sitemgr.Categories_UI.edit') 365 )); 366 } 367 return ''; 368 } 369 } 370 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |