EGOCMS  18.0
EGOTEC Content-Managament-System
Site.php
gehe zur Dokumentation dieser Datei
1 <?php
5 require_once('base/functions.php');
6 
10 class Site_Exception extends Exception
11 {
12  const SITE_DOESNT_EXIST = 1;
13  const LANG_DOESNT_EXIST = 2;
14  const LANG_NOT_DELETABLE = 3;
15  const MISSING_TEMPLATE = 4;
16 }
17 
29 class Site
30 {
31  private $_isDefault;
33  private $_onlyActive;
34  private $_time;
35  private $_types;
36  private $_typesFlat;
37  private $_param = array();
38  private $_metaUrlIsCached = false;
39  private $_metaUrl = array();
40  private $_cache;
41  private $_languages;
42  private $_classes = array();
43  private $_root;
45  public $name;
46  public $site;
47  public $admin;
48  public $language;
49  public $pageTable;
50  public $skin = '';
51  public $theme = '';
52  public $rootId = 1;
53  public $importFlag = false;
55  public $conf = array();
57  private $virtualHosts = array();
59  private static $confs = array();
68  public function __call($function, $params) {
69  if (strpos($function, '__') !== 0) {
70  $magic_file = $GLOBALS['egotec_conf']['lib_dir'].'base/'.get_class($this).'.'.$function.'.php';
71  if (file_exists($magic_file)) {
72  require_once($magic_file);
73  return call_user_func($function, $this, $params);
74  } else {
75  throw new Exception("Method 'Site.$function' not found");
76  }
77  }
78  }
79 
85  private function _loadConfig() {
86  if ($this->pageTable && isset(self::$confs[$this->pageTable])) {
87  $this->conf = self::$confs[$this->pageTable];
88  } else {
89  $confs = array(
90  $this->globalAllowed() ? $GLOBALS['egotec_conf']['site_dir'] . '_global/admin/conf.json' : '',
91  $GLOBALS['egotec_conf']['site_dir'] . $this->name . '/admin/conf.json'
92  );
93  $this->conf = array();
94  foreach ($confs as $conf) {
95  if ($conf && Ego_System::file_exists($conf)) {
96  $this->conf = Ego_System::getJSON($conf, $this->conf, true, ['plugins', 'toolbar', 'menubar']);
97  }
98  }
99 
100  if (empty($this->conf['site'])) {
101  // Abwärtskompatibilität: site Konfiguration aus conf.ini laden
102  if (Ego_System::file_exists($GLOBALS['egotec_conf']['site_dir'] . $this->name . '/conf.ini')) {
103  $this->conf['site'] = parse_ini_file($GLOBALS['egotec_conf']['site_dir'] . $this->name . '/conf.ini', true);
104  } else {
105  throw new Site_Exception("Site '$this->name' doesn't exist.", Site_Exception::SITE_DOESNT_EXIST);
106  }
107  }
108 
109  if (empty($this->conf['admin'])) {
110  // Abwärtskompatibilität: admin Konfiguration aus conf.ini laden
111  if (Ego_System::file_exists($GLOBALS['egotec_conf']['site_dir'] . $this->name . '/admin/conf.ini')) {
112  $this->conf['admin'] = parse_ini_file($GLOBALS['egotec_conf']['site_dir'] . $this->name . '/admin/conf.ini', true);
113  } else {
114  throw new Site_Exception("Site '$this->name' doesn't exist.", Site_Exception::SITE_DOESNT_EXIST);
115  }
116  }
117 
118  // Einstellungen der Designvorlage übernehmen
119  if (!empty($this->conf['site']['theme'])) {
120  $theme_paths = array(
121  $GLOBALS['egotec_conf']['pub_dir'] . 'theme/' . $this->conf['site']['theme'] . '/site/admin/conf.json',
122  $this->globalAllowed() ? $GLOBALS['egotec_conf']['site_dir'] . '_global/admin/' . $this->conf['site']['theme'] . '.json' : ''
123  );
124  foreach ($theme_paths as $theme_path) {
125  if ($theme_path && Ego_System::file_exists($theme_path)) {
126  $theme_conf = Ego_System::getJSON($theme_path);
127  foreach (array('panel', 'navigation', 'layouts', 'page') as $key) {
128  if (!empty($theme_conf[$key])) {
129  if (empty($this->conf[$key])) {
130  $this->conf[$key] = array();
131  }
132  $this->conf[$key] = array_replace_recursive($theme_conf[$key], $this->conf[$key]);
133  }
134  }
135  }
136  }
137  }
138 
139  // Verwendete Sprache erkennen
140  if (!$this->language) {
141  $this->language = $this->conf['site']['default_language'];
142  $this->pageTable = $this->name.'_'.$this->language;
143  }
144 
145  // Die Meta Daten werden nach Sprache gesetzt (abwärtskompatibel)
146  $this->conf['site']['robots'] = $this->conf['site']['robots_' . $this->language] ?
147  $this->conf['site']['robots_' . $this->language] : ($this->conf['site']['robots_' . $this->conf['site']['default_language']] ?
148  $this->conf['site']['robots_' . $this->conf['site']['default_language']] :
149  $this->conf['site']['robots']);
150  $this->conf['site']['keywords'] = $this->conf['site']['keywords_' . $this->language] ?
151  $this->conf['site']['keywords_' . $this->language] : ($this->conf['site']['keywords_' . $this->conf['site']['default_language']] ?
152  $this->conf['site']['keywords_' . $this->conf['site']['default_language']] :
153  $this->conf['site']['keywords']);
154  $this->conf['site']['description'] = $this->conf['site']['description_' . $this->language] ?
155  $this->conf['site']['description_' . $this->language] : ($this->conf['site']['description_' . $this->conf['site']['default_language']] ?
156  $this->conf['site']['description_' . $this->conf['site']['default_language']] :
157  $this->conf['site']['description']);
158 
159  // Bei Multimedia-Seiten immer die Multimediatypen aktivieren
160  if ($this->conf['site']['type'] == 'media') {
161  $this->conf['admin']['enabled_types']['multimedia'] = 1;
162  $this->conf['admin']['enabled_types']['multimedia/image'] = 1;
163  $this->conf['admin']['enabled_types']['multimedia/file'] = 1;
164  $this->conf['admin']['enabled_types']['multimedia/category'] = 1;
165  }
166 
167  // Bezeichnung bestimmen
168  if (!empty($this->conf['site']['title_' . $this->language])) {
169  $this->conf['site']['title'] = $this->conf['site']['title_' . $this->language];
170  } elseif (!empty($this->conf['site']['title_' . $this->conf['site']['default_language']])) {
171  $this->conf['site']['title'] = $this->conf['site']['title_' . $this->conf['site']['default_language']];
172  } elseif (empty($this->conf['site']['title'])) {
173  // Abwärtskompatibilität: Fallback auf Name wenn keine Bezeichnung existiert
174  $this->conf['site']['title'] = $this->name;
175  }
176 
180  self::$confs[$this->pageTable] = &$this->conf;
181  }
182 
183  // Abwärtskompatibilität: site und admin als Referenz setzen
184  $this->site = &$this->conf['site'];
185  $this->admin = &$this->conf['admin'];
186  }
187 
194  static function createSite($new_site)
195  {
196  Ego_System::mkdir($GLOBALS['egotec_conf']['site_dir'].$new_site['name']);
197  if ($new_site['type']=='media')
198  {
199  Ego_System::mkdir($GLOBALS['egotec_conf']['var_dir'].'media/'.$new_site['name']);
200  }
201  if (!empty($new_site['default_skin'])) {
202  $skin_dir = $GLOBALS['egotec_conf']['skin_dir'].$new_site['default_skin'];
203  if (!Ego_System::file_exists($skin_dir)) {
204  Ego_System::mkdir($skin_dir);
205  }
206  }
207 
209  copy($GLOBALS['egotec_conf']['lib_dir'].'template/site/conf.ini', $GLOBALS['egotec_conf']['site_dir'].$new_site['name'].'/conf.ini');
210  Ego_System::mkdir($GLOBALS['egotec_conf']['site_dir'].$new_site['name'].'/admin');
211  copy($GLOBALS['egotec_conf']['lib_dir'].'template/site/admin/conf.ini', $GLOBALS['egotec_conf']['site_dir'].$new_site['name'].'/admin/conf.ini');
212 
213  $newSite = new Site($new_site['name']);
214 
215  if ($new_site['lang'])
216  {
217  $new_site['default_language'] = $new_site['lang'];
218  $new_site['languages'] = $new_site['lang'];
219  }
220 
221  // Die Mandantenbezeichnung wird der Standardsprache zugeordnet
222  if ($new_site['title'] && $new_site['default_language']) {
223  $new_site['title_' . $new_site['default_language']] = $new_site['title'];
224  unset($new_site['title']);
225  }
226 
227  $rights = $new_site['rights'];
228  unset($new_site['name'], $new_site['lang'], $new_site['rights']);
229  $newSite->save($new_site);
230  $newSite->createTables();
231  require_once('base/Ego_Search_Factory.php'); // Den Suchindex initialisieren.
232  $search = Ego_Search_Factory::start($newSite->pageTable);
233  $search->reset();
234  $date = date('Y-m-d H:i:s');
235  $field = array(
236  'id' => 1,
237  'name' => 'Homepage',
238  'title' => 'Homepage',
239  'url' => '',
240  'short' => '',
241  'content' => 'This is the Homepage of a new site.',
242  'extra' => serialize(array()),
243  'a_date' => $date,
244  'c_date' => $date,
245  'a_user' => $GLOBALS['auth']->getId(),
246  'c_user' => $GLOBALS['auth']->getId(),
247  'type' => $new_site['type']=='media'?'multimedia/category':'page',
248  'children_order' => 'type',
249  'order_field' => 0,
250  'nav_hide' => 0,
251  'inactive' => 0,
252  'cache' => 7,
253  'release_from' => '0000-00-00 00:00:00',
254  'release_until' => '0000-00-00 00:00:00',
255  'workflow' => '',
256  'workflow_state' => 0,
257  'deleted' => 0
258  );
259  $db = new_db_connection();
260  $no_null_rights = trim(Auth::NO_NULL_RIGHTS, ',');
261  $no_null_rights = explode(',', $no_null_rights);
262  $insert_rights = array(
263  'set' => array(
264  'page_id' => 1,
265  'group_id' => '*',
266  'role_id' => '*'
267  )
268  );
269  foreach ($newSite->getLanguages() as $lang)
270  {
271  $db->insert(array('table' => $newSite->name.'_'.$lang, 'set' => $field));
272  $insert_rights['table'] = $newSite->name.'_'.$lang.'_rights';
273  foreach ($no_null_rights as $no_null_right)
274  {
275  if ($no_null_right != 'live') {
276  $insert_rights['set']['perm'] = $no_null_right;
277  $db->insert($insert_rights);
278  }
279  }
280  }
281 
282  /* Typenverwaltung setzen - #36701 */
283  if($newSite->site['type'] == "media")
284  {
285  $newSite->save_admin(array(
286  'enabled_types' => array(
287  'multimedia' => 1,
288  'multimedia/image' => 1,
289  'multimedia/file' => 1,
290  'multimedia/category' => 1
291  )
292  ));
293  } elseif ($newSite->site['type'] == "external") {
294  $newSite->save_admin(array(
295  'enabled_types' => array(
296  'redirect' => 1
297  )
298  ));
299  } else {
300  $newSite->save_admin(array(
301  'enabled_types' => array(
302  'page' => 1
303  )
304  ));
305  }
306 
307  /* Bei neuen Mandanten gleich Rechte setzen - #66260 und #100979 */
308  $default_group = is_array($rights) && $rights['group'] ? $rights['group'] : $GLOBALS['egotec_conf']['superuser']['group'];
309  $default_role = is_array($rights) && $rights['role'] ? $rights['role'] : $GLOBALS['egotec_conf']['superuser']['role'];
310 
311  $right = $newSite->site['right'];
312  $right['admin_group_0'] = $default_group;
313  $right['admin_role_0'] = $default_role;
314 
315  $right['translate_group_0'] = $default_group;
316  $right['translate_role_0'] = $default_role;
317 
318  $right['view_group_0'] = $default_group;
319  $right['view_role_0'] = $default_role;
320 
321  $right['linkto_group_0'] = $default_group;
322  $right['linkto_role_0'] = $default_role;
323 
324  $right['addclone_group_0'] = $default_group;
325  $right['addclone_role_0'] = $default_role;
326 
327  $right['newclone_group_0'] = $default_group;
328  $right['newclone_role_0'] = $default_role;
329 
330  $right['trashcan_group_0'] = $default_group;
331  $right['trashcan_role_0'] = $default_role;
332 
333  $right['stats_group_0'] = $default_group;
334  $right['stats_role_0'] = $default_role;
335 
336  $right['liveserver_group_0'] = $default_group;
337  $right['liveserver_role_0'] = $default_role;
338 
339  $right['site_group_0'] = $default_group;
340  $right['site_role_0'] = $default_role;
341 
342  $right['skin_group_0'] = $default_group;
343  $right['skin_role_0'] = $default_role;
344 
345  $right['change_type_group_0'] = $default_group;
346  $right['change_type_role_0'] = $default_role;
347 
348  $right['linkchecker_group_0'] = $default_group;
349  $right['linkchecker_role_0'] = $default_role;
350 
351  $right['nousechecker_group_0'] = $default_group;
352  $right['nousechecker_role_0'] = $default_role;
353 
354  $right['barriercheck_group_0'] = $default_group;
355  $right['barriercheck_role_0'] = $default_role;
356 
357  $newSite->save_admin(array(
358  'right' => $right
359  ));
360 
361  // Konfiguration aus der internen Cache entfernen, da diese bereits geändert wurde, und neu laden
362  self::$confs[$newSite->pageTable];
363  $newSite = new Site($newSite->name);
364 
365  // Frontend Administration aktivieren, wenn es ein Layout gibt
366  if ($newSite->getSkinFile('layout.tpl') || $newSite->getSkinFile('layout.html')) {
367  $newSite->save_admin(array(
368  'frontend_admin' => 1
369  ));
370  }
371 
372  return $newSite;
373  }
374 
413  function __construct($site_name='', $language='', $skin='', $only_active=true, $time='')
414  {
415  $this->_onlyActive = $only_active;
416  if ($_REQUEST['preview'] && $GLOBALS['auth'] && !$GLOBALS['auth']->isNobody()) {
417  $this->_onlyActive = false;
418  }
419 
420  $site_name = str_replace('/', '', $site_name); // #197684
421  if (!file_exists($GLOBALS['egotec_conf']['site_dir'].$site_name))
422  {
423  throw new Site_Exception("Site '$site_name' doesn't exist.", Site_Exception::SITE_DOESNT_EXIST);
424  }
425  if ($site_name=='')
426  { // Wenn keine Site übergeben wurde,
427  $this->_isDefault = true;
429  $site_name = $GLOBALS['egotec_conf']['default_site'];
430  }
431  $this->name = $site_name;
432  $this->_loadConfig();
433  if ($skin && in_array($skin, $this->getSkins()))
434  {
435  $this->skin = $skin;
436  } else {
437  $this->skin = $this->site['default_skin'];
438  }
439  $this->theme = (string) $this->site['theme'];
440  $this->setLanguage($language);
441  if ($GLOBALS['virtual_host_site'] && $GLOBALS['virtual_host_lang'] && $GLOBALS['virtual_host_site']==$this->name)
442  { // Falls ein virtueller Host eingetragen ist,
443  $this->site['default_language'] = $GLOBALS['virtual_host_lang'];
444  }
445  $this->setTime($time);
446 
447  /* Wenn diese Site keine Multimedia Site ist
448  * oder keine Multimedia Site zugewiesen hat,
449  * dann muss der Mediapool aktiviert sein. */
450  if (
451  !$this->hasMediaSite()
452  && !$this->admin['mediapool']['active']
453  ) {
454  $this->save_admin(array(
455  'mediapool' => array(
456  'active' => 1
457  )
458  ));
459  }
460  }
461 
468  public function setOnlyActive($b) {
469  $this->_onlyActive = $b;
470  }
471 
482  function setTime($time='')
483  {
484  if ($time)
485  {
486  $this->_time = $time;
487  } else {
488  $expire_time = $this->_cache->getExpire();
489  $this->_time = date('Y-m-d H:i:s', (int)($expire_time ? $expire_time : time()));
490  }
491  }
492 
499  function setLanguage($language='')
500  {
501  // Alle zwischengespeicherten virtuellen Hosts leeren
502  $this->virtualHosts = array();
503 
504  if ($language=='')
505  {
506  $language = $this->site['default_language'];
507  }
508  if (in_array($language, $this->getLanguages()))
509  { // Die Sprache nur setzen, wenn Sie in der Site vorhanden ist.
510  $new_page_table = $this->name.'_'.$language;
511  if ($this->_param['auth_or'])
512  { // Tabellenverweise anpassen.
513  $this->_param['auth_or'] = str_replace($this->pageTable, $new_page_table, $this->_param['auth_or']);
514  }
515  if ($this->_param['deleted_or'])
516  { // Tabellenverweise anpassen.
517  $this->_param['deleted_or'] = str_replace($this->pageTable, $new_page_table, $this->_param['deleted_or']);
518  }
519  $this->language = $language;
520  $this->pageTable = $new_page_table; // Der Name der Seitentabelle setzt sich aus dem Namen der Site und dem Sprachkürzel zusammen.
521  } else {
522  $this->language = $this->site['default_language'];
523  $this->pageTable = $this->name.'_'.$this->site['default_language']; // Der Name der Seitentabelle setzt sich aus dem Namen der Site und dem Sprachkürzel zusammen.
524  throw new Site_Exception('Die Sprache existiert nicht', Site_Exception::LANG_DOESNT_EXIST );
525  }
526 
527  // Cache erzeugen.
528  $path = $this->name.'/'.$this->language.'/';
529  if ($this->_cache)
530  {
531  $this->_cache->setPath($this->name.'/'.$this->language.'/');
532  } else {
533 
534  if (empty($GLOBALS["egotec_conf"]["cachemedia_dir"])) {
535  $GLOBALS["egotec_conf"]["cachemedia_dir"] = $GLOBALS["egotec_conf"]["var_dir"]."cachemedia/";
536  }
537 
538  switch ($GLOBALS['egotec_conf']['site_cache_type'])
539  {
540  case 'apc':
541  require_once('base/Ego_Cache_apc.php');
542  $this->_cache = new Ego_Cache_apc($path);
543  break;
544  case 'apcu':
545  require_once('base/Ego_Cache_apcu.php');
546  $this->_cache = new Ego_Cache_apcu($path);
547  break;
548  case 'shm':
549  require_once('base/Ego_Cache_shm.php');
550  $this->_cache = new Ego_Cache_shm($path);
551  break;
552  default:
553  require_once('base/Ego_Cache_file.php');
554  $this->_cache = new Ego_Cache_file($path);
555  }
556  }
557  if ($this->_cache->isExpired()) {
558  $this->clearCache();
559  }
560  $this->_loadConfig();
561  }
562 
568  function setRights($rights = array())
569  {
570  $this->_rights = array_unique($rights);
571  $this->setParam(array('rights' => $this->_rights));
572  }
573 
579  function addParam($param)
580  {
581  if ($this->_param)
582  {
583  $this->_param = array_merge($this->_param, $param);
584  } else {
585  $this->_param = $param;
586  }
587  }
588 
594  function setParam($param)
595  {
596  $this->_param = $param;
597  }
598 
602  function getHash()
603  {
604  return md5(serialize($this->_param));
605  }
606 
612  function getLanguages()
613  {
614  if (!$this->_languages) {
615  $this->_languages = explode(',', $this->site['languages']);
616  }
617  return $this->_languages;
618  }
619 
626  public function getSkins($theme = false) {
627  $skins = explode(',', $this->site['skins']);
628 
629  // Das Standard Skin muss immer enthalten sein
630  if (!in_array($this->site['default_skin'], $skins)) {
631  $skins[] = $this->site['default_skin'];
632  }
633 
634  // Designvorlage ebenfalls anführen
635  if ($theme && !empty($this->theme)) {
636  $skins[] = $this->theme;
637  }
638 
639  return array_filter($skins);
640  }
641 
649  function getPageId($name, $param = array())
650  {
651  $name = addslashes($name);
652 
653  $id_file = $GLOBALS['egotec_conf']['cache_dir'].$this->name.'/_id/'.$name;
654  if (file_exists($id_file))
655  { // Die ID aus dem Cache holen => keine DB Abfrage notwendig.
656  $page_id = file_get_contents($id_file);
657  } elseif ($name)
658  {
659  $db = new_db_connection(array( // Zunächst die ID über die Url bestimmen.
660  'fields' => 'id',
661  'table' => $this->pageTable,
662  'where' => 'url like :name',
663  'bind' => array('name' => $name)
664  ));
665  if ($db->nextRecord())
666  {
667  $page_id = $db->Record['id'];
668  } else
669  { // Falls über die Url keine ID gefunden wurde, dann wird die ID über den Namen bestimmt-
670  $db->select(array(
671  'fields' => 'id',
672  'table' => $this->pageTable,
673  'where' => 'name like :name',
674  'bind' => array('name' => $name),
675  'order' => 'id asc', // Damit eine Seite, die später mit dem gleichen Namen eingefügt wurde, nicht gefunden wird.
676  'limit' => '1'
677  ));
678  if ($db->nextRecord())
679  {
680  $page_id = $db->Record['id'];
681  }
682  }
683  if (!$page_id)
684  {
685  if (isset($param['internal']))
686  {
687  // Bei internen Abfragen keinen Header senden
688  $page_id = 0;
689  } else
690  {
691  // Falls keine passende Seite gefunden wurde, wird die Suchseite aufgerufen.
692  Ego_System::header(404);
693  $db->select(array(
694  'fields' => 'id',
695  'table' => $this->pageTable,
696  'where' => "type='search' or type='search_plus'",
697  'order' => 'type,id asc',
698  'limit' => '1'
699  ));
700  if ($db->nextRecord())
701  {
702  $page_id = $db->Record['id'];
703  $_REQUEST['search_string'] = $name;
704  $_REQUEST['to_search'] = 'name,title,short,content,data';
705  $_REQUEST['search'] = 1;
706  }
707  }
708  }
709  } else {
710  $page_id = $this->rootId;
711  }
712  return $page_id;
713  }
714 
720  public function getOnlyActive() {
721  return $this->_onlyActive;
722  }
723 
729  public function getTime() {
730  return $this->_time;
731  }
732 
766  function getPages($query=array(), $param = array())
767  {
768  if (is_array($param))
769  {
770  $param = array_merge($this->_param, $param);
771  } else {
772  $param = $this->_param;
773  }
774  if (!$param['lang'])
775  { // Wird keine Sprache übergeben, was meist der Fall ist, dann wird die Sprache des $site Objekts verwendet.
776  $param['lang'] = $this->language;
777  $site = $this;
778  } else {
779  $site = clone $this;
780  try {
781  $site->setLanguage($param['lang']);
782  } catch (Site_Exception $e) {
783  if ($e->getCode() == Site_Exception::LANG_DOESNT_EXIST) {
784  return new Page_Iterator($this);
785  }
786  }
787  }
788  $page_table = $site->name.'_'.$param['lang'];
789 
790  if (is_string($query)||is_bool($query))
791  { // Beim Aufruf über Smarty liegt query als string in der Form array("where" => "...") vor
792  egotec_error_log('$query wurde als String übergeben Query: '.$query);
793  eval ("\$query = $query;");
794  }
795  if (trim($query['where']))
796  { // Um weitere Bedingungen anfügen zu können, müssen die übergebenen Bedingungen geklammert werden.
797  $query['where'] = '('.$query['where'].')';
798  } else
799  {
800  $query['where'] = '1=1';
801  }
802  if (($site->getOnlyActive() && !$param['inactive']) || $param['only_active'])
803  { // Die ursprüngliche Zeile $query.=... gab beim Aufruf über Smarty eine Fehlermeldung
804  $query['where'] = $query['where']."
805  and inactive=0
806  ";
807  $query['where'] = $query['where']."
808  and (release_until='0000-00-00 00:00:00' or release_until >= '".$site->getTime()."')
809  and (release_from='0000-00-00 00:00:00' or release_from < '".$site->getTime()."')
810  ";
811  } elseif (($_REQUEST['preview'] || $GLOBALS['frontend_admin']) && empty($param['expired'])) {
812  // In der Vorschau/Frontend Administration werden inaktive Seiten durch das Freigabe bis Datum nicht angezeigt
813  $query['where'] = $query['where']."
814  and (release_until='0000-00-00 00:00:00' or release_until >= '".$site->getTime()."')
815  ";
816  }
817 
818  // Bitand ermitteln
819  $bitand_query = $this->getBitandQuery($param);
820  $query['bitand'] = $bitand_query;
821 
822  if ((integer)$param['deleted']>=0)
823  { // Gelöschte Seiten ausblenden.
824  $query['where'] = $query['where'].' AND (deleted='.
825  (integer)$param['deleted'].($param['deleted_or']?' OR '.$param['deleted_or']:'').')';
826  }
827  $query['table'] = ($query['table']?$query['table'].',':'').$page_table;
828  if (!isset($param['rights']))
829  {
830  $param['rights'] = array('view');
831  }
832  if (!isset($query['fields']))
833  {
834  $query['fields'] = $page_table.'.*';
835  }
836  if ($param['where'])
837  {
838  $query['where'] = ($query['where']?$query['where'].' AND ':'').'('.$param['where'].')';
839  }
840  if ($param['auth_or']!='1=1')
841  {
842  $query = $GLOBALS['auth']->getPageTableQuery($page_table, $param['rights'], $query, $param);
843  }
844  if ($param['fulltext'] || $param['extra'] || $param['filter'])
845  {
846  require_once('base/Ego_Search_Factory.php');
847  $search = Ego_Search_Factory::start($site->pageTable, array_merge(['only_active' => $site->getOnlyActive()], $param));
848 
849  if ($param['extra']) {
850  // Extra Suche durchführen
851  if (isset($param['extra_bind'])) {
852  // Fallback für extra_back, da extra-back nicht als Smarty Parameter übergeben werden kann
853  $param['extra-bind'] = $param['extra_bind'];
854  }
855  $search->setExtraQuery($param['extra'], (array) $param['extra-bind']);
856  }
857 
858  if ($query['where'] && preg_match('/\W'.$this->pageTable.'\.id in \(([0-9, ]+)\)/i', $query['where'], $matches)) {
859  $query['id_list'] = array_map('trim', explode(',', $matches[1]));
860  }
861 
862  if ($GLOBALS['egotec_conf']['search_engine'] == 'sql') {
863  $query = $search->search((string) $param['fulltext'], $site->pageTable.'.id', $query, true);
864  } elseif ($GLOBALS['egotec_conf']['search_engine'] == 'lucene' || $GLOBALS['egotec_conf']['search_engine'] == 'elastic') {
865  $query = $search->search((string) $param['fulltext'], $site->pageTable.'.id', $query, $param['filter'], (bool) $param['fuzzy']);
866  } else {
867  $query = $search->search((string) $param['fulltext'], $site->pageTable.'.id', $query);
868  }
869  $query['distinct'] = true;
870  }
871  if ($param['without_types'])
872  {
873  $query['where'].= ' AND type NOT IN (\''.str_replace(",","','",$param['without_types']).'\')';
874  }
875  if ($param['search_keywords'])
876  {
877  if ($site->admin['keywords']['site'])
878  {
879  $keywords_tbl = $site->admin['keywords']['site'].'_'.$site->language;
880  } else
881  {
882  $keywords_tbl = $site->pageTable;
883  }
884  require_once('base/Ego_Search_Sql.php');
885  $search = new Ego_Search_Sql($keywords_tbl, '_keywords');
886  $query = $search->search(
887  $param['search_keywords'],
888  $site->pageTable.'.id',
889  $query,
890  true,
891  'page_id',
892  'word',
893  '',
894  $site->name.'_keywords_rel.page_id',
895  ','.$site->name.'_keywords_rel',
896  $site->name.'_keywords_rel.keyword_id='.$keywords_tbl.'_keywords.id',
897  'SELECT SUM(page_id/page_id) FROM '.$keywords_tbl.'_keywords,'.$site->name.'_keywords_rel WHERE '.
898  $site->name.'_keywords_rel.keyword_id='.$keywords_tbl.'_keywords.id',
899  true
900  );
901  $query['distinct'] = true;
902  }
903  if ($query['andor'])
904  {
905  $and = array();
906  foreach ($query['andor'] as $ors)
907  {
908  $and[] = '('.join(') OR (', $ors).')';
909  }
910  $query['where'].= "\n AND (".join(") AND (", $and).')';
911  unset($query['andor']);
912  }
913  if ($query['and'])
914  {
915  $query['where'].= "\n AND ".join(' AND ', $query['and']);
916  unset($query['and']);
917  }
918  if ($query['or'])
919  {
920  $query['where'].= "\n AND ( (".join(")\n OR (", $query['or']).') )';
921  unset($query['or']);
922  }
923  if ($query['score'])
924  {
925  $query['fields2'] = '(LN(('.join(') + (', $query['score']).'))+1) AS score';
926  unset($query['score']);
927  }
928  if ($param['has_children'])
929  {
930  $has_children_where = $param['has_children_where'] ? ' AND ('.$param['has_children_where'].') ' : '';
931  if ((integer)$param['deleted']>=0)
932  { // Gelöschte Seiten ausblenden.
933  $has_children_where.= ' AND (has_table.deleted='.
934  (integer)$param['deleted'].($param['deleted_or']?' OR '.$param['deleted_or']:'').')';
935  }
936  if (($site->getOnlyActive() && !$param['inactive']) || $param['only_active'])
937  { // Die ursprüngliche Zeile $query.=... gab beim Aufruf über Smarty eine Fehlermeldung
938  $has_children_where.= ' AND has_table.inactive=0'.
939  ' AND (has_table.release_until=\'0000-00-00 00:00:00\' or has_table.release_until>=\''.$site->getTime().'\')'.
940  ' AND (has_table.release_from=\'0000-00-00 00:00:00\' or has_table.release_from<\''.$site->getTime().'\')';
941  } elseif (($_REQUEST['preview'] || $GLOBALS['frontend_admin']) && empty($param['expired'])) {
942  // In der Vorschau/Frontend Administration werden inaktive Seiten durch das Freigabe bis Datum nicht angezeigt
943  $has_children_where.= ' AND (has_table.release_until=\'0000-00-00 00:00:00\' or has_table.release_until>=\''.$site->getTime().'\')';
944  }
945 
946  /* Bitand für has_children ermitteln
947  * (die pageTable muss mit "has_table" ersetzt werden, damit die bitand Anweisungen auch auf den Sub-Select angewendet werden)
948  */
949  $query['field_as_bitand']['has_children'] = array_map(function($value) {
950  $value[0] = str_replace($this->pageTable . '.', 'has_table.', $value[0]);
951  return $value;
952  }, $bitand_query);
953 
954  $children_query = [
955  'page_table' => 'has_table',
956  'where' => ''.$page_table.'.id='.$page_table.'_children.page_id'.
957  ' AND '.$page_table.'_children.child=has_table.id'.
958  $has_children_where
959  ];
960  $query['distinct'] = true;
961 
962  if ($param['auth_or']!='1=1')
963  {
964  $children_query = $GLOBALS['auth']->getPageTableQuery($page_table, $param['rights'], $children_query, $param);
965  }
966  $query['field_as']['has_children'] = 'SELECT count(DISTINCT child)'.
967  ' FROM '.$page_table.'_children,'.$page_table.' has_table'.
968  ($children_query['join']?' LEFT JOIN '.(is_array($children_query['join'])?
969  implode(' LEFT JOIN ', $children_query['join']):$children_query['join']):'').
970  ' WHERE '.$children_query['where'];
971  }
972  if ($param['multi_parents'])
973  {
974  $multi_where = '';
975  if ((integer)$param['deleted']>=0)
976  { // Gelöschte Seiten ausblenden.
977  $multi_where.= ' AND (multi_table.deleted='.
978  (integer)$param['deleted'].($param['deleted_or']?' OR '.$param['deleted_or']:'').')';
979  }
980  if (($site->getOnlyActive() && !$param['inactive']) || $param['only_active'])
981  { // Die ursprüngliche Zeile $query.=... gab beim Aufruf über Smarty eine Fehlermeldung
982  $multi_where.= ' AND multi_table.inactive=0'.
983  ' AND (multi_table.release_until=\'0000-00-00 00:00:00\' or multi_table.release_until>=\''.$site->getTime().'\')'.
984  ' AND (multi_table.release_from=\'0000-00-00 00:00:00\' or multi_table.release_from<\''.$site->getTime().'\')';
985  } elseif (($_REQUEST['preview'] || $GLOBALS['frontend_admin']) && empty($param['expired'])) {
986  // In der Vorschau/Frontend Administration werden inaktive Seiten durch das Freigabe bis Datum nicht angezeigt
987  $multi_where.= ' AND (multi_table.release_until=\'0000-00-00 00:00:00\' or multi_table.release_until>=\''.$site->getTime().'\')';
988  }
989 
990  // Bitand für multi_parents ermitteln
991  $query['field_as_bitand']['multi_parents'] = $bitand_query;
992 
993  $query['field_as']['multi_parents'] = 'SELECT count(page_id)-1'.
994  ' FROM '.$page_table.'_children,'.$page_table.' multi_table'.
995  ' WHERE '.$page_table.'.id=child'.
996  ' AND '.$page_table.'_children.page_id=multi_table.id'.
997  $multi_where;
998  $query['distinct'] = true;
999  }
1000  require_once('base/Page_Iterator.php');
1001  if ($GLOBALS['egotec_conf']['pages_cache'] && !$param['no_cache'])
1002  {
1003  return new Page_Iterator($site, new_db_connection($query, $site->getCache()));
1004  } else {
1005  return new Page_Iterator($site, new_db_connection($query));
1006  }
1007  }
1008 
1016  private function getBitandQuery($param) {
1017  $query = array();
1018 
1019  if ($param['no_nav_hide'])
1020  { // Nur Seiten, die in der Navigation angezeigt werden (nav_hide&1=0)
1021  $query[] = array('nav_hide', 1, 0);
1022  $param['sitemap'] = true; // Außerdem nur Seiten, die in der Sitemap angezeigt werden
1023  }
1024  if ($param['no_intranet'])
1025  { // Nur Seiten, die auf den Liveserver übertragen werden (nav_hide&2=0)
1026  $query[] = array('nav_hide', 2, 0);
1027  }
1028  if ($param['intranet'])
1029  { // Nur Seiten, die nur im Intranet angezeigt werden (nav_hide&2=2)
1030  $query[] = array('nav_hide', 2, 2);
1031  }
1032  if ($param['search'])
1033  { // Nur Seiten, die nicht von der Suche ausgeschlossen werden (nav_hide&4=0)
1034  $query[] = array('nav_hide', 4, 0);
1035  }
1036  if ($param['sitemap'] && (!$GLOBALS['egotec_conf']['show_hidden_sitemap'] || !$GLOBALS['admin_area']))
1037  { // Nur Seiten, die in der Sitemap angezeigt werden (nav_hide&8=0)
1038  $query[] = array('nav_hide', 8, 0);
1039  }
1040  if ($param['nouse'])
1041  { // Nur Seiten, die im Verwendungsnachweis berücksichtigt werden sollen (nav_hide&16=0)
1042  $query[] = array('nav_hide', 16, 0);
1043  }
1044  if (isset($param['flag0']))
1045  { // Weitere Flag für offene Anwendungsfälle (nav_hide&32=0)
1046  $query[] = array('nav_hide', 32, $param['flag0']?32:0);
1047  }
1048  if (isset($param['flag1']))
1049  { // Weitere Flag für offene Anwendungsfälle (nav_hide&64=0)
1050  $query[] = array('nav_hide', 64, $param['flag1']?64:0);
1051  }
1052  if (isset($param['flag2']))
1053  { // Weitere Flag für offene Anwendungsfälle (nav_hide&128=0)
1054  $query[] = array('nav_hide', 128, $param['flag2']?128:0);
1055  }
1056  if (isset($param['flag3']))
1057  { // Weitere Flag für offene Anwendungsfälle (nav_hide&256=0)
1058  $query[] = array('nav_hide', 256, $param['flag3']?256:0);
1059  }
1060  if (isset($param['flag4']))
1061  { // Weitere Flag für offene Anwendungsfälle (nav_hide&512=0)
1062  $query[] = array('nav_hide', 512, $param['flag4']?512:0);
1063  }
1064  if (isset($param['flag5']))
1065  { // Weitere Flag für offene Anwendungsfälle (nav_hide&1024=0)
1066  $query[] = array('nav_hide', 1024, $param['flag5']?1024:0);
1067  }
1068  if (isset($param['flag6']))
1069  { // Weitere Flag für offene Anwendungsfälle (nav_hide&2048=0)
1070  $query[] = array('nav_hide', 2048, $param['flag6']?2048:0);
1071  }
1072  if (isset($param['flag7']))
1073  { // Weitere Flag für offene Anwendungsfälle (nav_hide&4096=0)
1074  $query[] = array('nav_hide', 4096, $param['flag7']?4096:0);
1075  }
1076 
1077  return $query;
1078  }
1079 
1086  function getLostPages($deleted = -1)
1087  {
1088  /* Verlorene Seiten sind:
1089  * 1. Seiten ohne Elternseite
1090  * 2. Seiten die als Elternseite nur Schlagwörter haben (aber selbst kein Schlagwort sind) */
1091  return $this->getPages(
1092  array(
1093  'join' => array($this->pageTable.'_children ON child = id'),
1094  'where' => "id != {$this->rootId} AND (child IS NULL OR (type != '_keywords/entry' AND id IN (SELECT child FROM {$this->pageTable}_children INNER JOIN {$this->pageTable} ON page_id = id WHERE type = '_keywords/entry') AND id NOT IN (SELECT child FROM {$this->pageTable}_children INNER JOIN {$this->pageTable} ON page_id = id WHERE type != '_keywords/entry')))"
1095  ),
1096  array(
1097  'deleted' => $deleted,
1098  'auth_or' => '1=1'
1099  )
1100  );
1101  }
1102 
1113  function getPage($id, $param=array())
1114  {
1115  if ($id=='')
1116  {
1117  return null;
1118  }
1119  if (!is_numeric($id))
1120  {
1121  $id = $this->getPageId($id, $param);
1122  }
1123  $cache_key = md5(serialize([$this->language, $param]));
1124  if ($id == $this->rootId && $page=$this->_root[$cache_key]) {
1125  return $page;
1126  }
1127  if (is_numeric($id) && is_numeric($_REQUEST['id']) && $id == $_REQUEST['id']) {
1128  // Falls möglich, die aktuelle abgelaufene Seite anzeigen
1129  $param['expired'] = true;
1130  }
1131  $pages = $this->getPages(
1132  array(
1133  'fields' => $param['fields'],
1134  'where' => 'id=:id',
1135  'bind' => array('id' => (int)$id)
1136  ),
1137  $param
1138  );
1139 
1140  $page = $pages->nextPage();
1141  if ($id == $this->rootId) { // Die root Seite cachen, da auf diese oft zugefriffen wird.
1142  $this->_root[$cache_key] = $page;
1143  }
1144  return $page;
1145  }
1146 
1158  function getRoot($param = array())
1159  {
1160  return $this->getPage($this->rootId, $param);
1161  }
1162 
1171  function getErrorPage()
1172  {
1173  $GLOBALS['_SERVER']['REDIRECT_STATUS'] = '404';
1174  if (!($page = $this->getPage($this->site['error_id'] ? $this->site['error_id'] : $this->rootId))) {
1175  // Falls die eingestellte Fehlerseite nicht erreichbar ist, wird die Startseite verwendet
1176  $page = $this->getRoot();
1177  }
1178  return $page;
1179  }
1180 
1187  function getUrl($param, $page = null)
1188  {
1189  if (!$this->_onlyActive && !isset($param['nonactive']))
1190  { // Auch inaktive Seiten anzeigen.
1191  $param['nonactive'] = true;
1192  }
1193  if (isset($param['nonactive']) && !$param['nonactive'])
1194  {
1195  unset($param['nonactive']);
1196  }
1197  if (!isset($param['lang']))
1198  {
1199  $param['lang'] = $this->language;
1200  }
1201  if (!isset($param['skin']) && $this->skin!=$this->site['default_skin'])
1202  {
1203  $param['skin'] = $this->skin;
1204  }
1205  if (!isset($param['site']))
1206  {
1207  $param['site'] = $this->name;
1208  }
1209 
1210  // Alphabetische Reihenfolge der URL Parameter
1211  ksort($param);
1212 
1213  if ($param['get_frontend_url']) {
1214  // Im Adminbereich eine sprechende URL ermitteln
1215  unset($param['get_frontend_url']);
1216  if ($GLOBALS['is_admin']) {
1217  require_once('soap/Ego_SOAP.php');
1218  $soap = new Ego_SOAP();
1219  return $soap->soapCall('pageGetUrl', array(
1220  'site' => $this->name,
1221  'lang' => $this->language,
1222  'id' => $param['id'],
1223  'param' => soap_var($param)
1224  ));
1225  }
1226  }
1227  return get_url('index.php', $param, $page);
1228  }
1229 
1237  function getPageUrl($page_id, $params = array(), $page = null)
1238  {
1239  return $page_id?$this->getUrl(array_merge(array('id' => $page_id), $params), $page):$this->getErrorPage();
1240  }
1241 
1252  function getMediaSite($lang = '')
1253  {
1254  if ($this->site['type'] != 'media' && empty($this->site['media'])) {
1255  return null;
1256  }
1264  if ($lang == '')
1265  {
1266  $lang = $this->language;
1267  }
1268 
1269  if ($this->site['type'] == 'media')
1270  {
1271  $media_site = $this;
1272  } else
1273  {
1274  $media_site = new Site($this->site['media'], '', '', $this->_onlyActive);
1275  $media_site->setParam($this->_param);
1276  }
1277 
1278  // Prüfen ob die aktuelle Sprache auch im Multimedia Mandanten existiert
1279  if (
1280  in_array($lang, $media_site->getLanguages())
1281  && $lang != $media_site->language
1282  )
1283  {
1284  $media_site->setLanguage($lang);
1285  }
1286 
1287  return $media_site;
1288  }
1289 
1295  public function hasMediaSite() {
1296  return ($this->site['type'] == 'media' || !empty($this->site['media']));
1297  }
1298 
1306  function getMediaUrl($id, $param = array(), $url_param = array())
1307  {
1308  if ($param['no_suffix'])
1309  {
1310  $url_param['no_suffix'] = $param['no_suffix'];
1311  unset($param['no_suffix']);
1312  }
1313  return $this->getMediaSite()->getPage($id, $param)->getUrl($url_param);
1314  }
1315 
1322  function clearCache($id=0, $all_languages = false)
1323  {
1324  if ($all_languages) {
1325  // Cache für alle Sprachen ungültig setzen
1326  $site = clone $this;
1327  foreach ($site->getLanguages() as $lang) {
1328  $site->setLanguage($lang);
1329  $site->clearCache($id);
1330  }
1331  return;
1332  }
1333 
1334  $language = $this->language;
1335  $pageTable = $this->name.'_'.$language;
1336  if (!file_exists($GLOBALS['egotec_conf']['log_dir'].$this->name.'_'.$language))
1337  {
1338  Ego_System::mkdir($GLOBALS['egotec_conf']['log_dir'].$this->name.'_'.$language, 0777, true);
1339  }
1340 
1341  if ($id)
1342  { // Bei Bildern wird nicht der komplette Cache, sondern nur das aktuelle Bild gelöscht
1343  $cache_path = $GLOBALS['egotec_conf']['cachemedia_dir'].$this->name.'/'.$language.'/';
1344  Ego_System::deldir($cache_path.$id, true);
1345  }
1346 
1352  // Cache, Lebensdauer einstellen nun immer 24h
1353  $new_cache_lifetime = 86400;
1354 
1355  $cache_expire = date('Y-m-d H:i:s', time()+$new_cache_lifetime);
1356  $time = date('Y-m-d H:i:s');
1357  $db = new_db_connection(array( // Datum der nächsten Änderung durch Ablauf von Freigabefenstern bestimmen.
1358  'fields' => '*',
1359  'table' => $pageTable,
1360  'where' => 'release_from>:time',
1361  'bind' => array('time' => $time),
1362  'order' => 'release_from asc',
1363  'limit' => '1'
1364  ));
1365  if ($db->nextRecord())
1366  {
1367  if ($db->Record['release_from']<$cache_expire)
1368  {
1369  $cache_expire = $db->Record['release_from'];
1370  }
1371  }
1372  $db->select(array(
1373  'fields' => '*',
1374  'table' => $pageTable,
1375  'where' => 'release_until>:time',
1376  'bind' => array('time' => $time),
1377  'order' => 'release_until asc',
1378  'limit' => '1'
1379  ));
1380  if ($db->nextRecord())
1381  {
1382  if ($db->Record['release_until']<$cache_expire)
1383  {
1384  $cache_expire = $db->Record['release_until'];
1385  }
1386  }
1387  $d = preg_split('/[-, ,:]/', $cache_expire);
1388  $this->_cache->reset();
1389 
1390  $this->_cache->setExpire(mktime($d[3], $d[4], $d[5], $d[1], $d[2], $d[0]));
1391  $this->setTime(); // Der Zeitstempel für die Freigabeabfrage muss neu gesetzt werden.
1392 
1393  // types.cache und classes.cache löschen
1394  Ego_System::clearTypeCache($this->name);
1395 
1396  // Allgemeine Cache löschen (nicht für APC, da hier die allgemeine Cache die selbe ist wie die Site Cache)
1397  if ($GLOBALS['egotec_conf']['site_cache_type'] != 'apc') {
1398  $cache = Ego_System::getCache();
1399  $cache->reset();
1400  }
1401  Ego_System::clearNginxCache();
1402  }
1403 
1409  function save($site)
1410  {
1411  require_once('base/Ego_System.php');
1412  $this->site = array_merge($this->site, $site);
1413 
1414  // Diese Keys gibt es nicht mehr und sind mittlerweile unterteilt in Sprachen
1415  unset($this->site['title']);
1416  unset($this->site['robots']);
1417  unset($this->site['keywords']);
1418  unset($this->site['description']);
1419  unset($this->_languages);
1420 
1421  Ego_System::write_ini_file($GLOBALS['egotec_conf']['site_dir'].$this->name.'/conf.ini', $this->site);
1422  }
1423 
1429  function save_admin($admin=array())
1430  {
1431  require_once('base/Ego_System.php');
1432  $original_admin = $this->admin;
1433  $this->admin = array_merge($this->admin, $admin);
1434 
1438  $enabled_types = array();
1439  if(is_array($this->admin['enabled_types']))
1440  {
1441  foreach ($this->admin['enabled_types'] as $key => $value)
1442  {
1443  if ($value == '1')
1444  {
1445  $enabled_types[$key] = $value;
1446  }
1447  }
1448  }
1449  $this->admin['enabled_types'] = $enabled_types;
1450 
1451  // Schlagwortregister anlegen
1452  if ($this->admin['keyword_register_own_site']) {
1453  if (!isset($this->admin['keywords']['site'])) {
1454  $this->admin['keywords']['site'] = $this->name;
1455  }
1456  $reset = $this->admin['keywords']['site'] != $original_admin['keywords']['site'];
1457  if ($this->name !== $this->admin['keywords']['site']) {
1458  $origin_site = new Site($this->admin['keywords']['site']);
1459  $this->keywordRegister($origin_site, $reset);
1460  } else {
1461  $this->keywordRegister(null, $reset);
1462  }
1463  }
1464 
1465  Ego_System::write_ini_file($GLOBALS['egotec_conf']['site_dir'].$this->name.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'conf.ini', $this->admin);
1466  Ego_System::clearTypeCache($this->name);
1467  }
1468 
1476  private function keywordRegister($origin_site = null, $reset = false) {
1477  $root_page = $this->getRoot();
1478  // Überprüfen ob es bereits ein Schlagwortregister existiert.
1479  $keyword_register_page = $this->getPages(array(
1480  'where' => "type='_keywords/list'"
1481  ),array(
1482  'auth_or' => '1=1'
1483  ))->nextPage();
1484  if ($keyword_register_page) {
1485  if ($reset) {
1486  // Wenn das Schlagwortregister gewechselt wird, muss es neu angelegt werden
1487  $keyword_register_page->delete(false, false, true, array(
1488  'where' => "type = '_keywords/entry'"
1489  ));
1490  $this->clearTrashcan(array(
1491  'where' => "type = '_keywords/list' OR type = '_keywords/entry'"
1492  ));
1493  } else {
1494  // Wenn ein Schlagwortregister existiert, dann nicht machen.
1495  return;
1496  }
1497  }
1498 
1499  if ($origin_site) {
1500  // Schlagwortregisterstartseite klonen.
1501  $origin_page = $origin_site->getPages(array(
1502  'where' => "type='_keywords/list'"
1503  ),array(
1504  'auth_or' => '1=1'
1505  ))->nextPage();
1506  if (!$origin_page) { // Wenn beim Originalmandant kein Schlagwortregister existiert,
1507  $keyword_register_field = array(
1508  'name' => "Schlagwortregister",
1509  'title' => "Schlagwortregister",
1510  'type' => "_keywords/list",
1511  'inactive' => 0,
1512  'nav_hide' => 1+4+8 // Aus Navigation, Sitemap und Suche ausschließen.
1513  );
1514  $origin_page = $origin_site->getRoot()->newChild($keyword_register_field); // dann dieses erstellen.
1515  } elseif ($origin_page->isClone()) { // Wenn der ausgewählte Mandant ebenfalls Klone nutzt,
1516  $origin_page = $origin_page->getCloneOriginal(); // so wird das Original geklont.
1517  }
1518  $clone_page = $root_page->createClone($origin_page);
1519  $keyword_recursive = function($origin_page, $clone_page) use (&$keyword_recursive) {
1520  $orgin_children = $origin_page->getChildren(array(
1521  'where' => "type='_keywords/entry'"
1522  ),array(
1523  'auth_or' => '1=1'
1524  ));
1525  foreach ($orgin_children as $orgin_child) {
1526  $clone_child = $clone_page->createClone($orgin_child);
1527  $keyword_recursive($orgin_child, $clone_child);
1528  }
1529  };
1530  $keyword_recursive($origin_page, $clone_page);
1531  } else {
1532  $keyword_register_field = array(
1533  'name' => "Schlagwortregister",
1534  'title' => "Schlagwortregister",
1535  'type' => "_keywords/list",
1536  'inactive' => 0,
1537  'nav_hide' => 1+4+8 // Aus Navigation, Sitemap und Suche ausschließen.
1538  );
1539  $root_page->newChild($keyword_register_field);
1540  }
1541  }
1542 
1555  private function _getTypesOfDirectory($root_dir, $site_name, $type='', $fullname='', $depth=-1, $site_type='')
1556  {
1557  if (file_exists($root_dir.($type?$type.'/':'').'/type.ini'))
1558  {
1559  $entry = parse_ini_file($root_dir.($type?$type.'/':'').'/type.ini', true);
1560  $fullname = ($fullname?$fullname.'/':'').$entry['title'];
1561  $global = false;
1562  if (
1563  $root_dir == $GLOBALS['egotec_conf']['lib_dir'].'type/site/'
1564  || $root_dir == $GLOBALS['egotec_conf']['site_dir'].'_global/'
1565  ) {
1566  $global = true;
1567  }
1568 
1569  $system = false;
1570  switch ($type) {
1571  case '_keywords':
1572  case '_keywords/abbreviations':
1573  if ($this->admin['keyword_register_own_site']) {
1574  $system = true;
1575  }
1576  }
1577 
1578  $types = array(
1579  'depth' => $depth,
1580  'type' => $type,
1581  'name' => $entry['title'],
1582  'fullname' => $fullname,
1583  'active' => !$entry['inactive'],
1584  'hidden' => (bool) $entry['hidden'],
1585  'global' => $global,
1586  'system' => $system,
1587  'blacklist' => $entry['blacklist'],
1588  'whitelist' => $entry['whitelist']
1589  );
1590 
1591  // Blacklist - Wenn der Seitentyp vom Mandanten ausgeschlossen ist.
1592  $excluded_sites = explode(',', $types['blacklist']);
1593 
1594  if ($types['whitelist']) {
1595  // Whitelist - Wenn der Seitentyp nur auf bestimmten Mandanten verfügbar ist.
1596  $included_sites = explode(',', $types['whitelist']);
1597  }
1598  // Wenn sich der Seitentyp auf der Blacklist befindet, nicht anzeigen.
1599  if (is_array($excluded_sites) && in_array($site_name, $excluded_sites)) {
1600  return [];
1601  }
1602 
1603  // Wenn eine Whitelist vorhanden ist und der Seitentyp nicht auf dieser ist, nicht anzeigen.
1604  if (is_array($included_sites) && !empty($included_sites) && !in_array($site_name, $included_sites) ) {
1605  return [];
1606  }
1607 
1608  foreach (array("icon","jquery") as $k)
1609  {
1610  if ($entry[$k])
1611  {
1612  $types[$k] = $entry[$k];
1613  }
1614  }
1615 
1616  }
1617  if (is_dir($root_dir.($type?$type.'/':'')))
1618  {
1619  $dir = dir($root_dir.($type?$type.'/':''));
1620  while ($file = $dir->read())
1621  {
1622  if ($file[0]!='.' && is_dir($dir->path.$file) && ($file!='multimedia' || $site_type=='media'))
1623  {
1624  $type_array = $this->_getTypesOfDirectory($root_dir, $site_name, ($type?$type.'/':'').$file, $fullname, $depth+1, $site_type);
1625  if ($type_array)
1626  {
1627  $types['children'][$type_array['type']] = $type_array;
1628  }
1629  }
1630  }
1631  }
1632  if ($types['children'])
1633  {
1634  uasort($types['children'], '_types_compare');
1635  }
1636 
1637  return $types;
1638  }
1639 
1646  private static function _getFlatTypes($tree)
1647  {
1648  $types_array = array();
1649  if(is_array($tree))
1650  {
1651  foreach ($tree as $item)
1652  {
1653  $types_array[] = $item;
1654  if ($item['children'])
1655  {
1656  $types_array = array_merge($types_array, Site::_getFlatTypes($item['children']));
1657  }
1658  }
1659  }
1660  return $types_array;
1661  }
1662 
1677  function getTypes($flat=true,$params=array())
1678  {
1679  $cache_file = $GLOBALS['egotec_conf']['cache_dir'].$this->name.'/types'.($flat ? 'Flat' : '').md5(serialize(array($params)));
1680  if (
1681  Ego_System::file_exists($cache_file)
1682  && ($types = @unserialize(Ego_System::file_get_contents($cache_file)))
1683  ) {
1684  return $types;
1685  }
1686 
1687  if ($params['only_system'])
1688  {//Systemseitentypen die NICHT durch Mandantenspezifische Seitentypen überschrieben werden
1689  $types = $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['site_dir'].$this->name.'/', $this->name);
1690  $types1 = $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['pub_dir'].'type/site/', $this->name);
1691  $types2 = $this->theme ? $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['pub_dir']."theme/{$this->theme}/site/", $this->name) : null;
1692  $types3 = $this->globalAllowed() ? $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['site_dir'].'_global/', $this->name) : null;
1693  $types4 = $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['lib_dir'].'type/site/', $this->name, '', '', -1, $this->site['type']);
1694 
1695  if (is_array($types)) {
1696  $result_types['children'] = array_diff_key($types4['children'],$types['children']);
1697  } else {
1698  $result_types = $types4;
1699  }
1700  if (is_array($types3)) {
1701  $result_types['children'] = array_diff_key($result_types['children'],$types3['children']);
1702  }
1703  if (is_array($types2)) {
1704  $result_types['children'] = array_diff_key($result_types['children'], $types2['children']);
1705  }
1706  if (is_array($types1)) {
1707  $result_types['children'] = array_merge($result_types['children'],$types1['children']);
1708  }
1709  $this->_types = $result_types['children']?$result_types['children']:array();
1710  if ($params['include_theme']) {
1711  $theme_types = $types2['children']?$types2['children']:array();
1712  $this->_types = array_merge($this->_types, $theme_types);
1713  }
1714  if ($params['include_global']) {
1715  $global_types = $types3['children']?$types3['children']:array();
1716  $this->_types = array_merge($this->_types, $global_types);
1717  }
1718  } elseif ($params['only_global'])
1719  {
1720  if ($this->globalAllowed()) {
1721  $types = $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['site_dir'].'_global/', $this->name);
1722  $this->_types = $types['children']?$types['children']:array();
1723  } else {
1724  $this->_types = array();
1725  }
1726  } elseif ($params['only_site'])
1727  {
1728  $types = $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['site_dir'].$this->name.'/', $this->name);
1729  $this->_types = $types['children']?$types['children']:array();
1730  } elseif ($params['only_theme'])
1731  {
1732  $types = $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['pub_dir'].'theme/'.$this->theme.'/site/', $this->name);
1733  $this->_types = $types['children']?$types['children']:array();
1734  } else
1735  {
1736  if (!$this->_types)
1737  {
1738  $types_filename=$GLOBALS['egotec_conf']['cache_dir'].$this->name.'/types.cache';
1739  if (Ego_System::file_exists($types_filename))
1740  {
1741  $this->_types = @unserialize(Ego_System::file_get_contents($types_filename));
1742  } else
1743  {
1744  $types = $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['site_dir'].$this->name.'/', $this->name);
1745  $types1 = $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['pub_dir'].'type/site/', $this->name);
1746  $types2 = $this->theme ? $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['pub_dir']."theme/{$this->theme}/site/", $this->name) : null;
1747  $types3 = $this->globalAllowed() ? $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['site_dir'].'_global/', $this->name) : null;
1748  $types4 = $this->_getTypesOfDirectory($GLOBALS['egotec_conf']['lib_dir'].'type/site/', $this->name, '', '', -1, $this->site['type']);
1749 
1750  $this->_types = array_merge(
1751  $types4['children']?$types4['children']:array(),
1752  $types3['children']?$types3['children']:array(),
1753  $types2['children']?$types2['children']:array(),
1754  $types1['children']?$types1['children']:array(),
1755  $types['children']?$types['children']:array()
1756  );
1757  Ego_System::file_put_contents($types_filename, serialize($this->_types));
1758  }
1759  }
1760  }
1761 
1762  if ($flat)
1763  {
1764  $md5 = md5(serialize($params));
1765  if (!$this->_typesFlat[$md5])
1766  {
1767  $this->_typesFlat[$md5] = Site::_getFlatTypes($this->_types);
1768  }
1769  uasort($this->_typesFlat[$md5], '_types_compare');
1770  Ego_System::file_put_contents($cache_file, serialize($this->_typesFlat[$md5]));
1771  return $this->_typesFlat[$md5];
1772  } else
1773  {
1774  uasort($this->_types, '_types_compare');
1775  Ego_System::file_put_contents($cache_file, serialize($this->_types));
1776  return $this->_types;
1777  }
1778  }
1779 
1786  function getTypeInfo($name) {
1787  if (!empty($this->_types)) {
1788  $parts = explode('/', $name);
1789  $type = $this->_types[$parts[0]];
1790  $child = '';
1791  foreach ($parts as $index => $part) {
1792  if ($type['type'] == $name) {
1793  return $type;
1794  } else {
1795  if (empty($child)) {
1796  $child = $part;
1797  } else {
1798  $child .= '/'.$part;
1799  }
1800  if (!empty($type['children']) && !empty($type['children'][$child])) {
1801  $type = $type['children'][$child];
1802  if ($type['type'] == $name) {
1803  return $type;
1804  }
1805  }
1806  }
1807  }
1808  } else {
1809  $types = $this->getTypes();
1810  foreach ($types as $type) {
1811  if ($type['type'] == $name) {
1812  return $type;
1813  }
1814  }
1815  }
1816  return array();
1817  }
1818 
1826  function getTypeFiles($type)
1827  {
1828  $files = array();
1829  $dirs_to_read = array(
1830  'site &raquo; ' => array(
1831  $GLOBALS['egotec_conf']['lib_dir'].'type/site/'.$type,
1832  $this->globalAllowed() ? $GLOBALS['egotec_conf']['site_dir'].'_global/'.$type : '',
1833  $GLOBALS['egotec_conf']['site_dir'].$this->name.'/'.$type,
1834  ),
1835  'site/admin &raquo; ' => array(
1836  $GLOBALS['egotec_conf']['lib_dir'].'type/site/'.$type.'/admin',
1837  $this->globalAllowed() ? $GLOBALS['egotec_conf']['site_dir'].'_global/'.$type.'/admin' : '',
1838  $GLOBALS['egotec_conf']['site_dir'].$this->name.'/'.$type.'/admin',
1839  ),
1840  'skin &raquo; ' => array(
1841  $GLOBALS['egotec_conf']['bin_dir'].'type/skin/'.$type,
1842  $GLOBALS['egotec_conf']['lib_dir'].'type/skin/'.$type,
1843  $this->globalAllowed() ? $GLOBALS['egotec_conf']['skin_dir'].'_global/'.$type : '',
1844  $GLOBALS['egotec_conf']['skin_dir'].$this->skin.'/'.$type
1845  )
1846  );
1847  if (!empty($this->theme)) {
1848  $dirs_to_read[$this->theme.' &raquo; '] = array(
1849  $GLOBALS['egotec_conf']['pub_dir'].'theme/'.$this->theme.'/site/'.$type,
1850  $GLOBALS['egotec_conf']['pub_dir'].'theme/'.$this->theme.'/skin/'.$type,
1851  );
1852  $dirs_to_read[$this->theme.'/admin &raquo; '] = array(
1853  $GLOBALS['egotec_conf']['pub_dir'].'theme/'.$this->theme.'/site/'.$type.'/admin'
1854  );
1855  }
1856 
1857  foreach ($dirs_to_read as $key => $dirs)
1858  {
1859  foreach ($dirs as $d)
1860  {
1861  if (!$d) {
1862  continue;
1863  }
1864  $dir = @dir($d);
1865  while ($dir && false !== ($f = $dir->read()))
1866  {
1867  if ($f[0]=='.' || is_dir($dir->path.'/'.$f)) continue;
1868 
1869  $files[$key.'/'.$f] = $dir->path.'/'.$f;
1870  }
1871  }
1872  }
1873 
1874  return $files;
1875  }
1876 
1887  function getBlocks()
1888  {
1889  $blocks = array();
1890 
1891  // Verzeichnis in dem die Blöcke liegen
1892  $dir = $GLOBALS['egotec_conf']['skin_dir'].$this->skin.'/blocks/';
1893 
1894  if (is_dir($dir))
1895  {
1896  $d = dir($dir);
1897 
1898  while(false !== ($entry = $d->read()))
1899  {
1900  if (preg_match('/^(.*?)\.html$/i', $entry, $matches))
1901  {
1902  $name = $matches[1];
1903 
1904  // HTML
1905  $blocks[$name] = array(
1906  'html' => file_get_contents($dir.$entry)
1907  );
1908 
1909  // Beschreibung
1910  $desc = $dir.$name.'_desc.php';
1911  if (file_exists($desc))
1912  {
1913  $blocks[$name]['desc'] = file_get_contents($desc);
1914  }
1915 
1916  // Vorschau
1917  $img = $dir.$name.'.gif';
1918  if (file_exists($img))
1919  {
1920  $blocks[$name]['img'] = $img;
1921  }
1922  }
1923  }
1924 
1925  $d->close();
1926  }
1927 
1928  // Array sortieren
1929  ksort($blocks);
1930 
1931  return $blocks;
1932  }
1933 
1943  function getSitemapRootIdArray($param = array(), $recalc = false, $user = true, $query = array())
1944  {
1945  $key = md5($this->pageTable.json_encode($this->_param));
1946 
1947  // Aus dem User Objekt holen
1948  if (
1949  !$recalc
1950  && $user
1951  && is_array($GLOBALS['auth']->user->extra['rootIdArray'])
1952  && is_array($GLOBALS['auth']->user->extra['rootIdArray'][$key])
1953  ) {
1954  return $GLOBALS['auth']->user->extra['rootIdArray'][$key];
1955  }
1956 
1957  $where = $query['where'];
1958  unset($query['where']);
1959  $query = array_merge(array(
1960  'fields' => $this->pageTable.'.id, '. $this->pageTable.'_children.page_id',
1961  'inner' => array($this->pageTable.'_children ON '.$this->pageTable.'_children.child='.$this->pageTable.'.id'),
1962  'distinct' => true
1963  ), $query);
1964  if ($where) {
1965  $query['where'] = $where;
1966  }
1967  $all_parents = $this->getPages($query, $param);
1968 
1969  $id_string = '';
1970  $parent_string = '';
1971  foreach ($all_parents as $page)
1972  {
1973  $parent_string = $parent_string.','.$page->field['page_id'];
1974  $id_string = $id_string.','.$page->field['id'];
1975  }
1976  $parent_string = trim($parent_string,',');
1977  $id_string = trim($id_string,',');
1978 
1979  $parents = array();
1980  $all_ids = array();
1981  $parents = empty($parent_string) ? array() : explode(',', $parent_string);
1982  $all_ids = empty($id_string) ? array() : explode(',', $id_string);
1983  $parents = array_unique($parents);
1984  $all_ids = array_unique($all_ids);
1985 
1986  if ($param['deleted'] == 1)
1987  { // Die Eltern aller gelöschten Seiten zurückgeben.
1988  $ids = $parents;
1989  } elseif (empty($parents))
1990  { // es gibt keine Eltern
1991  $ids = array();
1992  } else {
1993  $with_permission = $all_ids; // Alle Eltern bestimmen, auf die der Benutzer eine Berechtigung besitzt.
1994  $ids = array(); // Alle Vorfahren zu den Eltern bestimmen, für die der Benutzer keine Berechtigung besitzt.
1995  $page = $this->getRoot(array('auth_or' => '1=1', 'deleted_or' => '1=1'));
1996 
1997  foreach ($parents as $id)
1998  {
1999  if (!in_array($id, $with_permission))
2000  {
2001  $ids = array_merge($ids,$page->_getAncestorsIds(
2002  $this->getPage($id, array('auth_or' => '1=1')),
2003  array('limit' => 1, 'order' => 'id'),
2004  array('auth_or' => '1=1', 'deleted' => -1)
2005  ));
2006  $ids[] = $id;
2007  }
2008  }
2009  }
2010  $ids = array_unique($ids);
2011 
2012  // Im User Objekt speichern
2013  if (!isset($param['deleted']) && $user) {
2014  if (!is_array($GLOBALS['auth']->user->extra['rootIdArray'])) {
2015  $GLOBALS['auth']->user->extra['rootIdArray'] = array();
2016  }
2017  $GLOBALS['auth']->user->extra['rootIdArray'][$key] = $ids;
2018  $GLOBALS['auth']->user->update();
2019  }
2020 
2021  return $ids;
2022  }
2023 
2033  function hasRight($right, $flag=false, $user_id = false, $rights = array())
2034  {
2035  $rights = !empty($rights) ? $rights : $this->admin['right'];
2036  if ($right == "desktop")
2037  {
2038  $flag = true;
2039  }
2040  $i = 0;
2041  do
2042  {
2043  $group = $rights[$right.'_group_'.$i];
2044  if ($group=='')
2045  {
2046  break;
2047  }
2048  $role = $rights[$right.'_role_'.$i];
2049  if ($GLOBALS['auth']->hasPermission($group, $role, $flag, $user_id))
2050  {
2051  return true;
2052  }
2053  $i++;
2054  } while ($group!='');
2055  return $i==0;
2056  }
2057 
2064  function hasPermission($right)
2065  {
2066  $rights = $this->admin['right'];
2067 
2068  if (is_array($rights))
2069  {
2070  foreach ($rights as $r => $value)
2071  {
2072  if (preg_match('/^'.$right.'_group_(\d+)/i', $r, $g))
2073  {
2074  $group = $g[1];
2075 
2076  if (isset($rights[$right.'_role_'.$group]) && !$this->isPermission($value, $rights[$right.'_role_'.$group]))
2077  {
2078  return false;
2079  }
2080  }
2081  }
2082  }
2083 
2084  return true;
2085  }
2086 
2090  function isPermission($group, $role)
2091  {
2092  if (empty($group) && empty($role))
2093  {
2094  return true;
2095  }
2096 
2097  $db = new_db_connection(
2098  array(
2099  'fields' => 'group_id',
2100  'table' => 'egotec_group',
2101  'where' => 'group_id =:group',
2102  'bind' => array(
2103  'group' => $group
2104  )
2105  )
2106  );
2107  if($db->nextRecord())
2108  {
2109  $db = new_db_connection(
2110  array(
2111  'fields' => 'role_id',
2112  'table' => 'egotec_role',
2113  'where' => 'role_id =:role',
2114  'bind' => array(
2115  'role' => $role
2116  )
2117  )
2118  );
2119 
2120  return $db->nextRecord();
2121  }else
2122  {
2123  return false;
2124  }
2125  }
2126 
2134  function checkRight($right, $flag=false)
2135  {
2136  if ($this->hasRight($right, $flag))
2137  {
2138  return true;
2139  } else {
2140  throw new Auth_Exception(Auth_Exception::PERMISSION_DENIED_TEXT, Auth_Exception::PERMISSION_DENIED);
2141  }
2142  }
2143 
2150  public function getRights($right) {
2151  $rights = array();
2152  $i = 0;
2153  do {
2154  $group = $this->admin['right'][$right.'_group_'.$i];
2155  if ($group == '') {
2156  break;
2157  }
2158  $role = $this->admin['right'][$right.'_role_'.$i];
2159  $rights[] = array('group' => $group, 'role' => $role);
2160  $i++;
2161  } while ($group != '');
2162  return $rights;
2163  }
2164 
2171  public function setRight($right, $rights) {
2172  // Zunächst alle bisherigen Einträge löschen.
2173  $i = 0;
2174  do {
2175  $group = $this->admin['right'][$right.'_group_'.$i];
2176  if ($group == '') {
2177  break;
2178  }
2179  unset($this->admin['right'][$right.'_group_'.$i]);
2180  unset($this->admin['right'][$right.'_role_'.$i]);
2181  $i++;
2182  } while ($group != '');
2183 
2184  // Jetzt die Rechte setzen.
2185  $i = 0;
2186  foreach ($rights as $one_right) {
2187  $this->admin['right'][$right.'_group_'.$i] = $one_right['group'];
2188  $this->admin['right'][$right.'_role_'.$i] = $one_right['role'];
2189  }
2190  }
2191 
2196  function destroyIDs($ids)
2197  {
2198  $languages = $this->getLanguages();
2199  $name = $this->name;
2200  foreach($languages as $language)
2201  {
2202  foreach($ids as $id)
2203  {
2204  $_dbErase = new_db_connection();
2205  $_dbErase->delete(array('from' => $name.'_'.$language, 'where' => 'id = \''.$id.'\''));
2206  $_dbErase->delete(array('from' => $name.'_'.$language.'_fulltext', 'where' => 'id = \''.$id.'\''));
2207  $_dbErase->delete(array('from' => $name.'_'.$language.'_rights', 'where' => 'page_id = \''.$id.'\''));
2208  $_dbErase->delete(array('from' => $name.'_'.$language.'_users', 'where' => 'page_id = \''.$id.'\''));
2209  $_dbErase->delete(array('from' => $name.'_'.$language.'_v', 'where' => 'id = \''.$id.'\''));
2210  }
2211  }
2212  }
2213 
2221  function hasRightsOnId($id, $rights, $user_id = false)
2222  {
2223  $query = array(
2224  'fields'=> 'id',
2225  'from' => $this->pageTable,
2226  'where' => 'id='.$id
2227  );
2228  $db = new_db_connection(
2229  $GLOBALS['auth']->getPageTableQuery(
2230  $this->pageTable,
2231  $rights,
2232  $query,
2233  array(
2234  'user_id' => $user_id
2235  )
2236  )
2237  );
2238  if ($user_id)
2239  {
2240  return (boolean)$db->nextRecord();
2241  } else {
2242  return $db->nextRecord() || $GLOBALS['auth']->hasSuperuserPermission();
2243  }
2244  }
2245 
2255  public function isMetaUrl($path)
2256  {
2257  if (!$this->_metaUrlIsCached)
2258  {
2259  $this->_metaUrl = array();
2260  // Oracle liefert bei url != '' kein Ergebnis
2261  $where = Ego_System::getDbDriver() == 'oci' ? "url != '?'" : "url != ''";
2262  foreach ($this->getLanguages() as $lang)
2263  {
2264  $urls = $this->getPages(
2265  array(
2266  'fields' => 'url,type',
2267  'where' => $where
2268  ),
2269  array(
2270  'lang' => $lang,
2271  'inactive' => true,
2272  'auth_or' => '1=1'
2273  )
2274  );
2275  while ($url = $urls->nextPage())
2276  {
2277  $this->_metaUrl[] = $url->field['url'];
2278  }
2279  }
2280  $this->_metaUrlIsCached = true;
2281  }
2282  return in_array($path, $this->_metaUrl);
2283  }
2284 
2290  public function isPublicSave() {
2291  return $this->site['type'] == 'content' && $GLOBALS['egotec_conf']['save_method'] == 'public';
2292  }
2293 
2299  public function __toString()
2300  {
2301  return 'Site('.$this->name.'.'.$this->language.')';
2302  }
2303 
2309  public function __clone()
2310  {
2311  if ($this->_cache) {
2312  /* Wenn das Site Objekt geklont wird, muss das Cache Objekt ebenfalls geklont werden,
2313  * da es ansonsten eine Referenz zum originalen Objekt ist. */
2314  $this->_cache = clone $this->_cache;
2315  }
2316  }
2317 
2326  public function enoughDiskSpace()
2327  {
2328  $need_space = 2*1024*1024*1024; // 2 GB
2329  $dir_name = $GLOBALS['egotec_conf']['backup_dir'].'site/'.$this->name;
2330  if (Ego_System::file_exists($dir_name))
2331  {
2332  $times = array();
2333  $newest = 0;
2334  $dir = dir($GLOBALS['egotec_conf']['backup_dir'].'site/'.$this->name);
2335  while (false !== ($f = $dir->read()))
2336  {
2337  if (strrpos($f, '.tar.gz')===strlen($f)-7)
2338  {
2339  $time = filemtime($dir_name.'/'.$f);
2340  $times[$time] = filesize($dir_name.'/'.$f);
2341  $newest = $time > $newest ? $time : $newest;
2342  }
2343  }
2344  $dir->close();
2345  ksort($times);
2346  if (sizeof($times)>0)
2347  {
2348  $need_space = intval($times[$newest]) *3;
2349  }
2350  } else
2351  {
2352  if (!Ego_System::file_exists($GLOBALS['egotec_conf']['backup_dir']))
2353  {
2354  Ego_System::mkdir($GLOBALS['egotec_conf']['backup_dir']);
2355  }
2356  $dir_name = $GLOBALS['egotec_conf']['backup_dir'];
2357 
2358  // Backup Verzeichnis existiert nicht, dann anlegen
2359  if (!Ego_System::file_exists($dir_name))
2360  {
2361  Ego_System::mkdir($dir_name);
2362  }
2363  }
2364  if ($need_space < disk_free_space($dir_name))
2365  {
2366  return true;
2367  } else
2368  {
2369  return false;
2370  }
2371  }
2372 
2378  public function getCache()
2379  {
2380  return $this->_cache;
2381  }
2382 
2388  public function getCacheExpire()
2389  {
2390  $expire = (int) $this->admin['cache_expire_time'];
2391  if ($expire == 0) {
2392  $expire = 3600; // Standard: 1 Stunde
2393  }
2394  return $expire;
2395  }
2396 
2402  public function getCacheEntry($key)
2403  {
2404  if ($_REQUEST['preview']) {
2405  $key .= 'P';
2406  }
2407  return $this->_cache->get($key);
2408  }
2409 
2417  public function setCacheEntry($key, $value)
2418  {
2419  if ($_REQUEST['preview']) {
2420  $key .= 'P';
2421  }
2422  $this->_cache->set($key, $value);
2423  }
2424 
2428  public function getCacheLastChanged()
2429  {
2430  return $this->_cache->getLastChanged();
2431  }
2432 
2440  public function getDesklets($rights = false, $trashcan = false) {
2441  $site = $this;
2442  $auth = clone $GLOBALS['auth'];
2443  $smarty = clone $GLOBALS['smarty'];
2444  $active_cells = explode(',', $GLOBALS['auth']->user->extra[$this->name.'_desktop_cells']);
2445 
2446  // Standard Inhalt für leere Desklets
2447  $desklet_default_content = '<p class="refresh"><a href="javascript:void(0)" onclick="egoDesktop.refresh()">'
2448  .$GLOBALS['auth']->translate('Laden Sie den Desktop neu, um den Inhalt dieses Desklets anzuzeigen.')
2449  .'</a></p>';
2450  $smarty->assign('desklet_default_content', $desklet_default_content);
2451 
2452  $desktop_dir = dir($GLOBALS['egotec_conf']['lib_dir'].'desktop/'.($trashcan ? 'trashcan/' : ''));
2453  while ($desktop_file = $desktop_dir->read()) {
2454  if (
2455  is_file($desktop_dir->path.$desktop_file)
2456  && substr($desktop_file, strlen($desktop_file)-4) == '.php'
2457  && file_exists($desktop_dir->path.$desktop_file)
2458  ) {
2459  require($desktop_dir->path.$desktop_file);
2460  }
2461  }
2462  $desktop_dir->close();
2463  if (!$trashcan) {
2464  if ($this->globalAllowed() && file_exists($GLOBALS['egotec_conf']['site_dir'].'_global/admin/desktop/')) {
2465  $desktop_dir = dir($GLOBALS['egotec_conf']['site_dir'].'_global/admin/desktop/');
2466  while ($desktop_file = $desktop_dir->read()) {
2467  if (
2468  is_file($desktop_dir->path.$desktop_file)
2469  && substr($desktop_file, strlen($desktop_file)-4) == '.php'
2470  && file_exists($desktop_dir->path.$desktop_file)
2471  ) {
2472  require($desktop_dir->path.$desktop_file);
2473  }
2474  }
2475  $desktop_dir->close();
2476  }
2477  if (file_exists($GLOBALS['egotec_conf']['site_dir'].$this->name.'/admin/desktop/')) {
2478  $desktop_dir = dir($GLOBALS['egotec_conf']['site_dir'].$this->name.'/admin/desktop/');
2479  while ($desktop_file = $desktop_dir->read()) {
2480  if (
2481  is_file($desktop_dir->path.$desktop_file)
2482  && substr($desktop_file, strlen($desktop_file)-4) == '.php'
2483  && file_exists($desktop_dir->path.$desktop_file)
2484  ) {
2485  require($desktop_dir->path.$desktop_file);
2486  }
2487  }
2488  $desktop_dir->close();
2489  }
2490  foreach ($this->getTypes() as $type) {
2491  $desktop_file = $GLOBALS['egotec_conf']['site_dir'].$this->name.'/'.$type['type'].'/admin/desktop.php';
2492  if ($this->globalAllowed() && !file_exists($desktop_file)) { // Fallback in das _global Verzeichnis.
2493  $desktop_file = $GLOBALS['egotec_conf']['site_dir'].'_global/'.$type['type'].'/admin/desktop.php';
2494  }
2495  if (!file_exists($desktop_file)) { // Fallback in das lib/type Verzeichnis.
2496  $desktop_file = $GLOBALS['egotec_conf']['lib_dir'].'type/site/'.$type['type'].'/admin/desktop.php';
2497  }
2498  if (file_exists($desktop_file)) {
2499  require($desktop_file);
2500  }
2501  }
2502 
2503  foreach ($GLOBALS['cells'] as $index => &$cell_item) {
2504  if (is_array($cell_item)) {
2505  foreach ($cell_item as &$cell) {
2506  if ($rights && isset($site->admin['desklets'][$cell['id']])) {
2507  $rights = explode(';', $site->admin['desklets'][$cell['id']]);
2508  if (sizeof($rights) > 0) {
2509  $perm = false;
2510  foreach ($rights as $right) {
2511  $group_role = explode(',', $right);
2512  if (
2513  empty($group_role[0])
2514  || empty($group_role[1])
2515  ||$GLOBALS['auth']->hasPermission($group_role[0], $group_role[1])
2516  ) {
2517  $perm = true;
2518  }
2519  }
2520  if (!$perm) {
2521  unset($GLOBALS['cells'][$index]);
2522  break;
2523  }
2524  }
2525  }
2526  $cell['visible'] = ($cell['permanent'] || in_array($this->name.'_'.$cell['id'], $active_cells));
2527  $cell['permanent'] = !empty($cell['permanent']);
2528 
2529  // Leere Desklets mit einem Standard Inhalt befüllen
2530  if (trim($cell['body']) == '') {
2531  $cell['body'] = $desklet_default_content;
2532  }
2533  }
2534  }
2535  }
2536  }
2537  return $GLOBALS['cells'] = array_values($GLOBALS['cells']);
2538  }
2539 
2546  public function getUploaderPage($page = null) {
2547  if ($file = $this->getSiteFile('admin/uploader.php')) {
2548  require_once($file);
2549  if (function_exists('getUploaderPage')) {
2550  if (!$page && $GLOBALS['page']) {
2551  $page = $GLOBALS['page'];
2552  }
2553  return getUploaderPage($this, $page);
2554  }
2555  } elseif ($this->hasMediaSite()) {
2556  $media_site = $this->getMediaSite();
2557  $media_site->addParam(array(
2558  'auth_or' => '1=1'
2559  ));
2560  $_users_page = $media_site->getPages(
2561  array('where' => 'name=\'_users\''),
2562  array(
2563  'auth_or' => '1=1',
2564  'inactive' => true,
2565  'only_active' => false
2566  )
2567  )->nextPage();
2568  if (!$_users_page)
2569  {
2570  $media_root_page = $media_site->getRoot(array('auth_or' => '1=1'));
2571  if (!$media_root_page) {
2572  return null;
2573  } else {
2574  $_users_page = $media_root_page->newChild(array(
2575  'name' => '_users',
2576  'title' => '_users',
2577  'type' => 'multimedia/category',
2578  'inactive' => 0
2579  ));
2580  }
2581  }
2582  $user_page = $_users_page->getChildren(
2583  array(
2584  'where' => 'name=:name',
2585  'bind' => array(
2586  'name' => $GLOBALS['auth']->user->field['username']
2587  )
2588  ),
2589  array(
2590  'auth_or' => '1=1',
2591  'inactive' => true,
2592  'only_active' => false
2593  )
2594  )->nextPage();
2595  if (!$user_page && !empty($GLOBALS['auth']->user->field['username']))
2596  {
2597  $user_page = $_users_page->newChild(array(
2598  'name' => $GLOBALS['auth']->user->field['username'],
2599  'title' => $GLOBALS['auth']->user->field['username'],
2600  'type' => 'multimedia/category',
2601  'inactive' => 0
2602  ));
2603  $user_page->setUsersArray(array(
2604  'edit' => array(array('user_id' => $GLOBALS['auth']->getId())),
2605  'child' => array(array('user_id' => $GLOBALS['auth']->getId())),
2606  'remove' => array(array('user_id' => $GLOBALS['auth']->getId()))
2607  ));
2608 
2609  // Sicherstellen, dass es mindestens eine Gruppen/Rollen Kombination gibt
2610  $rights = $user_page->getRightsArray();
2611  foreach (array('edit', 'child', 'remove') as $perm) {
2612  if (
2613  empty($rights[$perm])
2614  || in_array('*', array($rights[$perm][0]['group_id'], $rights[$perm][0]['role_id']))
2615  ) {
2616  $rights[$perm] = array(
2617  array(
2618  'group_id' => $GLOBALS['egotec_conf']['superuser']['group'],
2619  'role_id' => $GLOBALS['egotec_conf']['superuser']['role']
2620  )
2621  );
2622  }
2623  }
2624  $user_page->setRightsArray($rights);
2625  }
2626  return $user_page;
2627  }
2628  return null;
2629  }
2630 
2636  public function hasDeleted() {
2637  $deleted = $this->getPages(array(), array(
2638  'auth_or' => '1=1',
2639  'deleted' => 1
2640  ));
2641  return (bool) $deleted->nextPage();
2642  }
2643 
2650  public function clearTrashcan($query = array()) {
2651  $cluster_list = Ego_System::getCluster($this);
2652  if (empty($query['where'])) {
2653  $query['where'] = '1=1';
2654  }
2655  if (count($cluster_list) > 0) {
2656  $time = array();
2657  foreach ($cluster_list as $cluster) {
2658  $log_filename = $GLOBALS['egotec_conf']['log_dir'].$this->name.'/live.'.$this->name.'_'.$this->language.'.'.$cluster['id'].'.up.date';
2659  if (file_exists($log_filename)) {
2660  $time[] = file_get_contents($log_filename);
2661  }
2662  }
2663  sort($time);
2664  if (count($time) > 0) {
2665  $query['where'].= " AND ".$this->pageTable.".c_date<'{$time[0]}'";
2666  }
2667  } else {
2668  $log_filename = $GLOBALS['egotec_conf']['log_dir'].$this->name.'/live.'.$this->name.'_'.$this->language.'.date';
2669  if (!file_exists($log_filename)) {
2670  $log_filename = $GLOBALS['egotec_conf']['log_dir'].$this->name.'/live.date';
2671  }
2672  if (file_exists($log_filename)) {
2673  $live_date = file_get_contents($log_filename);
2674  $query['where'].= " AND ".$this->pageTable.".c_date<'$live_date'";
2675  }
2676  }
2677 
2678  $del_array = array();
2679  $del_pages = $this->getPages($query, array(
2680  'deleted' => 1,
2681  'inactive' => true,
2682  'only_active' => false,
2683  'no_cache' => 1,
2684  'rights' => array('delete')
2685  ));
2686  while ($page = $del_pages->nextPage()) {
2687  $del_array[] = $page;
2688  }
2689  foreach ($del_array as $page) {
2690  $page->destroy();
2691  }
2692 
2693  $rest = $this->getPages($query, array(
2694  'deleted' => 1,
2695  'inactive' => true,
2696  'only_active' => false,
2697  'no_cache' => 1
2698  ));
2699  $msg = $GLOBALS['auth']->translate("Der Papierkorb wurde geleert.");
2700  $z = $rest->numRecords();
2701  if ($z > 0) {
2702  $msg.= "<br />".$GLOBALS['auth']->translate("%z Seiten können wegen mangelnder Berechtigung nicht gelöscht werden oder werden beim nächsten Liveabgleich gelöscht.");
2703  $msg = str_replace('%z', $z, $msg);
2704  }
2705  $msg = str_replace('%z', $z, $msg);
2706  return $msg;
2707  }
2708 
2715  public function getPageClass($type = 'page') {
2716  $cache_key = 'pageClasses';
2717  if (empty($this->_classes)) {
2718  $this->_classes = $this->getCacheEntry($cache_key);
2719  }
2720  if ($this->_classes === null || !isset($this->_classes[$type])) {
2721  if (!is_array($this->_classes)) {
2722  $this->_classes = array();
2723  }
2724  $this->_classes[$type] = $this->_getPageClass($type);
2725  $this->setCacheEntry($cache_key, $this->_classes);
2726  }
2727 
2728  if (!class_exists($this->_classes[$type]['class'], false) && !empty($this->_classes[$type]['file'])) {
2729  $file = $GLOBALS['egotec_conf']['egotec_dir'].ltrim($this->_classes[$type]['file'], DIRECTORY_SEPARATOR);
2730  require_once($file);
2731  }
2732  return $this->_classes[$type]['class'];
2733  }
2734 
2742  private function _getPageClass($type) {
2743  $prefix = 'Page' . ($this->conf['page']['prefix'] ?? '');
2744 
2745  // Page Erweiterung für den Seitentyp suchen
2746  $class = $prefix;
2747  foreach (explode('/', $type) as $part) {
2748  $class .= ucfirst($part);
2749  }
2750 
2751  // Seitentyp Page Erweiterung suchen
2752  if ($file = $this->getSiteFile($type.'/page.php', array('module'), true, true)) {
2753  return array('file' => $file, 'class' => $class);
2754  }
2755 
2756  // Mandanten Page Erweiterung suchen
2757  $class = 'Page' . ucfirst($this->name);
2758  if ($file = $this->getSiteFile('page.php', array('module', 'global', 'parent_theme'), true, true)) {
2759  return array('file' => $file, 'class' => $class);
2760  }
2761 
2762  // Designvorlage Page Erweiterung suchen (nur in pub/theme/)
2763  if ($this->theme) {
2764  $class = 'Page' . ucfirst($this->theme);
2765  if ($file = $this->getSiteFile('page.php', array('custom', 'global', 'system', 'module', 'parent_custom'), true, true)) {
2766  return array('file' => $file, 'class' => $class);
2767  }
2768  }
2769 
2770  // Globale Page Erweiterung suchen
2771  $class = 'PageGlobal';
2772  if ($file = $this->getSiteFile('page.php', array('custom', 'system', 'module'), true, true)) {
2773  return array('file' => $file, 'class' => $class);
2774  }
2775 
2776  // Es gibt keine Page Erweiterung
2777  return array('file' => '', 'class' => 'Page');
2778  }
2779 
2787  public function updateLinks($language = '', $output = false) {
2788  set_time_limit(0);
2789  $this->removeLinks($language);
2790  if (empty($language)) {
2791  $languages = $this->getLanguages();
2792  } else {
2793  $languages = array($language);
2794  }
2795  $params = array(
2796  'inactive' => true,
2797  'only_active' => false,
2798  'no_cache' => true,
2799  'auth_or' => '1=1'
2800  );
2801  foreach ($this->getPages(array(), $params) as $page) {
2802  foreach ($languages as $lang) {
2803  if ($lang_page = $page->getLanguagePage($lang, $params)) {
2804  if ($output) {
2805  Ego_System::flush('.');
2806  }
2807  $lang_page->updateLinks(false);
2808  }
2809  }
2810  }
2811  }
2812 
2823  public function updateMediaIndex($resume, $c_date, $skipFirst, $dryRun, $timeout) {
2824  if($this->site['type'] != 'media') {
2825  echo "Is not a media site\n";
2826  return;
2827  }
2828 
2829  if ($GLOBALS['egotec_conf']['openoffice']['active'] != 1) {
2830  echo "index is not active\n";
2831  return;
2832  }
2833 
2834  require_once('openoffice/openoffice.php');
2835 
2836  // kl. Migration auf Sprach Verzeichnisse
2837  $old_file = $GLOBALS['egotec_conf']['log_dir'].$this->name;
2838  $new_file = $GLOBALS['egotec_conf']['log_dir'].$this->name."_".$this->language;
2839 
2840  if(Ego_System::file_exists($old_file."/index.tmp")) {
2841  if(!Ego_System::file_exists($new_file."/index.date")) {
2842  Ego_System::file_put_contents($new_file."/index.date", Ego_System::file_get_contents($old_file."/index.date"));
2843  }
2844  @unlink($old_file);
2845  }
2846 
2847  $position = 0;
2848  if($resume && Ego_System::file_exists($new_file."/index.date")) {
2849  $position = Ego_System::file_get_contents($new_file."/index.date");
2850  }
2851 
2852  $files = array();
2853  $addFile = function($path, $entry) use (&$files) {
2854  if($entry[0] === '.') { // '.' Einträge überspringen
2855  return;
2856  }
2857 
2858  if(preg_match('/_/', $entry)) { // ein Archiveintrag, wird übersprungen
2859  return;
2860  }
2861  $files[$entry] = filemtime($path.'/'.$entry).' '.$entry;
2862  };
2863 
2864  $path = $GLOBALS['egotec_conf']['var_dir'] . 'media/' . $this->name;
2865 
2866  if (!Ego_System::file_exists($path)) {
2867  // Abbrechen, wenn es das Multimedia Verzeichnis nicht gibt
2868  return;
2869  }
2870 
2871  // alle direkt unter /media/multimedia/*
2872  $d = dir($path);
2873  while (false !== ($entry = $d->read())) {
2874  if (!is_dir($d->path.'/'.$entry)) {
2875  $addFile($d->path, $entry);
2876  }
2877  }
2878  $d->close();
2879 
2880  // alle direkt unter /media/multimedia/language/*
2881  if (Ego_System::file_exists($d->path.'/'.$this->language)) {
2882  $d = dir($d->path.'/'.$this->language);
2883  while (false !== ($_entry = $d->read())) {
2884  $files[$this->language.'/'.$_entry] = filemtime($d->path.'/'.$_entry).' '.$this->language.'/'.$_entry;
2885  }
2886  $d->close();
2887  }
2888 
2889  asort($files);
2890  $startTime = time();
2891  clearstatcache();
2892 
2893  foreach($files as $entry => $fileTime) {
2894  if($resume && $fileTime <= $position) {
2895  continue;
2896  }
2897 
2898  $timeRound = strtok($fileTime, ' '); // Den Unixzeitstempel extrahieren.
2899 
2900  if ($skipFirst) {
2901  $skipFirst = false;
2902  echo "[Fs ] $entry ".date("Y-m-d H:i:s", $timeRound)."\n";
2903  continue;
2904  }
2905 
2906  $id = preg_replace('/^[^\d]+/', '', $entry);
2907  if (!is_numeric($id)) {
2908  continue;
2909  }
2910 
2911  $page = $this->getPage($id, array('inactive' => 1, 'auth_or' => '1=1'));
2912  if(!$page) {
2913  echo "[F] $id not found in DB\n";
2914  continue;
2915  }
2916 
2917  echo "[DS ] ".$entry." ".date("Y-m-d H:i:s", $timeRound)."\n";
2918 
2919  $extra = $page->extra;
2920  $mime_type = $extra['mime_type'];
2921  $file_ext = $extra['image_type']; // wird von der convert_content benötigt
2922 
2923  if (!empty($mime_type)) {
2924  if (!empty($file_ext)) {
2925  $mime_type = Ego_System::getMimeTypes($file_ext);
2926  } else {
2927  continue;
2928  }
2929  }
2930 
2931  # nur Dateien vom Type ^application oder text... versuchen zu importieren
2932  if (!preg_match('/^application|text/', $mime_type)) {
2933  continue;
2934  }
2935 
2936  if (empty($file_ext)) {
2937  if (!$GLOBALS['mime2ext']) {
2938  $GLOBALS['mime2ext'] = array_flip(Ego_System::getMimeTypes());
2939  }
2940 
2941  $file_ext = $GLOBALS['mime2ext'][$mime_type];
2942  }
2943 
2944  $content = convert_content($path . '/' . $entry, $file_ext, $mime_type);
2945  if(!empty($content)) {
2946  echo "[FC";
2947  if(!$dryRun) {
2948  try {
2949  $page->update(array(
2950  'field' => array(
2951  'content' => Ego_System::filterNonUtf8($content, '', true)
2952  ), TRUE, !$c_date
2953  ));
2954  } catch(Exception $e) {
2955  echo "f] " . $e->getMessage() . "\n";
2956  Ego_System::file_put_contents($new_file."/index_error.log", date("Y-m-d H:i:s")." Datei: $entry (".$page->field["name"]."), Datenbankupdate fehlgeschlagen\n", FILE_APPEND);
2957  }
2958  echo "u] $entry\n";
2959  Ego_System::file_put_contents($new_file."/index.log", date("Y-m-d H:i:s")." $entry (".$page->field["name"].".".$extra['image_type'].") [".strlen($content)."]\n", FILE_APPEND);
2960  } else {
2961  echo " ] $entry\n";
2962  }
2963  } else {
2964  echo "[FCf] $entry (mime_type: $mime_type)\n";
2965  Ego_System::file_put_contents($new_file."/index_error.log", date("Y-m-d H:i:s")." Datei: $entry (".$page->field["name"].".".$extra['image_type']."), konnte nicht konvertiert werden\n", FILE_APPEND);
2966  }
2967 
2968  // position merken
2969  if(!$dryRun) {
2970  Ego_System::file_put_contents($new_file."/index.date", $fileTime);
2971  }
2972  if ($timeout && time() - $startTime > $timeout) {
2973  break;
2974  }
2975  }
2976 
2977  $this->clearCache();
2978  echo $this->name."_".$this->language." Cache cleared.\n";
2979  }
2980 
2987  public function removeLinks($language = '') {
2988  $db = new_db_connection();
2989  $db->begin();
2990  if ($language) {
2991  $db->delete(array(
2992  'table' => 'egotec_links',
2993  'where' => 'src_site = :site AND src_lang = :lang',
2994  'bind' => array(
2995  'site' => $this->name,
2996  'lang' => $language
2997  )
2998  ));
2999  } else {
3000  $db->delete(array(
3001  'table' => 'egotec_links',
3002  'where' => 'src_site = :site',
3003  'bind' => array(
3004  'site' => $this->name
3005  )
3006  ));
3007  }
3008  $db->commit();
3009  }
3010 
3017  public function removeUrls($language = '') {
3018  $db = new_db_connection();
3019  $db->begin();
3020  if ($language) {
3021  $db->delete(array(
3022  'table' => 'egotec_url',
3023  'where' => 'site = :site AND lang = :lang',
3024  'bind' => array(
3025  'site' => $this->name,
3026  'lang' => $language
3027  )
3028  ));
3029  } else {
3030  $db->delete(array(
3031  'table' => 'egotec_url',
3032  'where' => 'site = :site',
3033  'bind' => array(
3034  'site' => $this->name
3035  )
3036  ));
3037  }
3038  $db->commit();
3039  }
3040 
3048  public function updateUrls($reset = false, $verbose = false) {
3049  if ($reset) {
3050  // Alle zugehörigen URLs löschen
3051  $this->removeUrls($this->language);
3052  }
3053  if ($root = $this->getRoot(array(
3054  'auth_or' => '1=1',
3055  'inactive' => true,
3056  'only_active' => false
3057  ))) {
3058  $root->updateUrls($verbose, true);
3059  $this->clearCache();
3060  }
3061  }
3062 
3068  public function getUnusedPages() {
3069  if ($this->site['type'] == 'media') {
3070  return $this->getPages(array(
3071  'join' => array('egotec_links ON ('
3072  .' egotec_links.dest_site = :site'
3073  .' AND egotec_links.dest_lang = :lang'
3074  .' AND id = egotec_links.dest_id)'),
3075  'where' => "egotec_links.src_id IS NULL"
3076  ." AND deleted = 0"
3077  ." AND type IN ('multimedia/file', 'multimedia/image')",
3078  'bind' => array(
3079  'site' => $this->name,
3080  'lang' => $this->language
3081  )
3082  ), array(
3083  'auth_or' => '1=1',
3084  'inactive' => 1,
3085  'only_active' => false,
3086  'nouse' => true
3087  ));
3088  } elseif ($media = $this->getMediaSite()) {
3089  return $media->getUnusedPages();
3090  }
3091  return new Page_Iterator();
3092  }
3093 
3112  public function getCopyrights() {
3113  $copyrights = [];
3114 
3115  // Multimedia Mandanten prüfen
3116  if ($media = $this->getMediaSite()) {
3117  $pages = $media->getPages([
3118  'fields' => $media->pageTable.'.*, egotec_links.src_id',
3119  'inner' => [
3120  'egotec_links ON ' . $media->pageTable . '.id = egotec_links.dest_id'
3121  ],
3122  'where' => 'src_site = :src_site AND src_lang = :src_lang AND dest_site = :dest_site',
3123  'bind' => [
3124  'src_site' => $this->name,
3125  'src_lang' => $this->language,
3126  'dest_site' => $media->name
3127  ]
3128  ]);
3129  foreach ($pages as $page) {
3130  if ($page->extra['copyright'] !== null) {
3131  $key = md5(mb_strtolower($page->extra['copyright']));
3132 
3133  if (!isset($copyrights[$key])) {
3134  $copyrights[$key] = [
3135  'title' => $page->extra['copyright'],
3136  'pages' => []
3137  ];
3138  }
3139 
3140  $identity = $page->getIdentity();
3141  if (!isset($copyrights[$key]['pages'][$identity])) {
3142  $copyrights[$key]['pages'][$identity] = [
3143  'page' => $page,
3144  'pool' => null,
3145  'linked' => []
3146  ];
3147  }
3148 
3149  if ($link = $this->getPage($page->field['src_id'])) {
3150  $copyrights[$key]['pages'][$identity]['linked'][] = $link;
3151  }
3152  }
3153  }
3154  }
3155 
3156  // Mediapool Dateien prüfen
3157  if ($this->admin['mediapool']['active']) {
3158  $pages = $this->getPages();
3159  foreach ($pages as $page) {
3160  foreach ($page->getMediapool()->list() as $item) {
3161  if ($item['copyright']) {
3162  $key = md5(mb_strtolower($item['copyright']));
3163 
3164  if (!isset($copyrights[$key])) {
3165  $copyrights[$key] = [
3166  'title' => $item['copyright'],
3167  'pages' => []
3168  ];
3169  }
3170 
3171  $identity = $item['name'];
3172  if (!isset($copyrights[$key]['pages'][$identity])) {
3173  $copyrights[$key]['pages'][$identity] = [
3174  'page' => $page,
3175  'pool' => $item,
3176  'linked' => []
3177  ];
3178  }
3179 
3180  $copyrights[$key]['pages'][$identity]['linked'][] = $page;
3181  }
3182  }
3183  }
3184  }
3185 
3186  usort($copyrights, function($a, $b) {
3187  return strcmp($a['title'], $b['title']);
3188  });
3189  return array_values($copyrights);
3190  }
3191 
3204  public function getTemplate($mobile = false, $name = 'index', $dir = '', $variant = '', $suffix = '', $fallback = true) {
3205  if (empty($suffix)) {
3206  $suffix = $_SERVER['REQUEST_SUFFIX'];
3207  }
3208  $key = 'template'.md5(serialize(array($this->skin, $mobile, $name, $dir, $variant, $suffix, $fallback)));
3209  $template = $this->getCacheEntry($key);
3210  if ($template === null) {
3211  $template = '';
3212 
3213  if (!empty($variant)) {
3214  $variant = ".{$variant}";
3215  }
3216  if ($suffix == '.htm') {
3217  // Bei .htm immer das .pdf Template verwenden
3218  $suffix = '.pdf';
3219  }
3220  $suffix = !in_array($suffix, array('.html', '.php')) ? $suffix : '';
3221  if ($suffix && $variant == $suffix) {
3222  $variant = '';
3223  }
3224  $base_dir = $dir ? explode('/', $dir)[0] : '';
3225  foreach (array('.tpl', '.html') as $file_suffix) {
3226  if (!empty($template)) {
3227  break;
3228  }
3229  $file = $mobile ? $name . $variant . '.mobile' . $suffix . $file_suffix : $name . $variant . $suffix . $file_suffix;
3230  if (
3231  $base_dir
3232  && $name == 'index'
3233  && !$this->skin
3234  && !$this->theme
3235  && ($template_file = $this->getSkinFile($base_dir . '/' . $name . $variant . $file_suffix))
3236  ) {
3237  $template = $template_file;
3238  } elseif (
3239  ($dir && ($template_file = $this->getSkinFile($dir . '/' . $file)))
3240  || ($template_file = $this->getSkinFile($file))
3241  ) {
3242  $template = $template_file;
3243  } elseif ($suffix != '') {
3244  $file = $mobile ? $name . $variant . '.mobile' . $suffix . $file_suffix : $name . $variant . $suffix . $file_suffix;
3245  if (
3246  ($dir && ($template_file = $this->getSkinFile($dir . '/' . $file)))
3247  || ($template_file = $this->getSkinFile($file))
3248  ) {
3249  $template = $template_file;
3250  }
3251  }
3252  }
3253  // Es gibt kein Template
3254  if (empty($template)) {
3255  if ($mobile) {
3256  // Wenn es kein Mobile Template gibt, dann versuchen ein Standard Template zu ermitteln
3257  $template = $this->getTemplate(false, $name, $dir, $variant, $suffix, $fallback);
3258  } elseif ($variant != '' && $suffix != '') {
3259  // Wenn es keine Template Variante mit dem Suffix gibt, dann versuchen ohne Variante zu ermitteln
3260  $template = $this->getTemplate(false, $name, $dir, '', $suffix, $fallback);
3261  } elseif ($fallback) {
3262  // Das Standard Template verwenden
3263  if ($suffix != '') {
3264  // Wenn es kein <name>.variant.suffix Template gibt, dann <name>.variant.html verwenden
3265  return $this->getTemplate($mobile, $name, $dir, $variant, '.html');
3266  } elseif ($variant != '') {
3267  // Wenn es kein <name>.variant.html Template gibt, dann <name>.html verwenden
3268  return $this->getTemplate($mobile, $name, $dir, '', '.html');
3269  } elseif ($name == 'body') {
3270  $template_file = $GLOBALS['egotec_conf']['lib_dir'] . 'type/skin/page/body.html';
3271  if (Ego_System::file_exists($template_file)) {
3272  $template = $template_file;
3273  }
3274  }
3275  }
3276  }
3277  if (empty($template) && $fallback) {
3278  throw new Site_Exception('Template does not exist.', Site_Exception::MISSING_TEMPLATE);
3279  }
3280  $this->setCacheEntry($key, $template);
3281  }
3282  return $template;
3283  }
3284 
3295  public function getSkinFile($path, $skip = array('module'), $url = false, $relative = false) {
3296  if (!$this->globalAllowed() && !in_array('global', $skip)) {
3297  // Für diesen Mandanten keine globalen Templates verwenden
3298  $skip[] = 'global';
3299  }
3300  return Ego_System::getFallbackFile('skin', $this->skin, $path, $skip, $url, $relative, $this->theme);
3301  }
3302 
3313  public function getSiteFile($path, $skip = array('module'), $url = false, $relative = false) {
3314  if (
3315  !$this->globalAllowed() && !in_array('global', $skip)
3316  ) {
3317  // Für diesen Mandanten keine globalen Skripte verwenden
3318  $skip[] = 'global';
3319  }
3320  return Ego_System::getFallbackFile('site', $this->name, $path, $skip, $url, $relative, $this->theme);
3321  }
3322 
3331  public function getFile($path, $type = 'skin') {
3332  switch ($type) {
3333  case 'skin':
3334  return $this->getSkinFile($path, array('module'), true);
3335  case 'site':
3336  return $this->getSiteFile($path, array('module'), true);
3337  }
3338  return '';
3339  }
3340 
3348  public function getVariantFiles($path, $skip = array()) {
3349  $key = 'variant'.md5(serialize(array($path, $skip)));
3350  $variants = $this->getCacheEntry($key);
3351  if ($variants === null) {
3352  $variants = Ego_System::getVariantFiles('skin', $this->skin, $path, $skip, $this->theme);
3353  $this->setCacheEntry($key, $variants);
3354  }
3355  return $variants;
3356  }
3357 
3366  public function getLayoutFiles($path = '', $skip = array(), $conf = array()) {
3367  $key = 'layout'.md5(serialize(array($path, $skip)));
3368  $layouts = $this->getCacheEntry($key);
3369  if ($layouts === null) {
3370  $layouts = array_merge(
3371  Ego_System::getFiles('skin', $this->skin, 'layouts/*.tpl', $skip, $this->theme),
3372  $path != '' ? Ego_System::getFiles('skin', $this->skin, $path.'/layouts/*.tpl', $skip, $this->theme, false, false) : array()
3373  );
3374  $layouts = array('default' => $layouts['_empty']) + $layouts;
3375  if (empty($conf)) {
3376  $conf = $this->conf['layouts'];
3377  }
3378  if (!empty($conf)) {
3379  foreach ($layouts as $layout => $title) {
3380  if (!empty($conf[$layout]['title'])) {
3381  $layouts[$layout] = $GLOBALS['auth']->translate($conf[$layout]['title']);
3382  }
3383  }
3384  }
3385  unset($layouts['_empty']);
3386  $this->setCacheEntry($key, $layouts);
3387  }
3388  return $layouts;
3389  }
3390 
3398  public function getBlockFiles($path = '', $skip = array()) {
3399  $key = 'block'.md5(serialize(array($path, $skip)));
3400  $blocks = $this->getCacheEntry($key);
3401  if ($blocks === null) {
3402  $blocks = array_merge(
3403  Ego_System::getFiles('skin', $this->skin, 'blocks/*.tpl', $skip, $this->theme, false, false),
3404  $path != '' ? Ego_System::getFiles('skin', $this->skin, $path.'/blocks/*.tpl', $skip, $this->theme, false, false) : array()
3405  );
3406  $this->setCacheEntry($key, $blocks);
3407  }
3408  return $blocks;
3409  }
3410 
3416  public function getEditorTemplates() {
3417  $templates = array();
3418  $template_dirs = array(
3419  array($GLOBALS['egotec_conf']['skin_dir'].$this->skin.'/blocks/', $GLOBALS['egotec_conf']['url_dir'].'skin/'.$this->skin.'/blocks/'),
3420  $this->globalAllowed() ? array($GLOBALS['egotec_conf']['skin_dir'].'_global/blocks/', $GLOBALS['egotec_conf']['url_dir'].'skin/_global/blocks/') : array()
3421  );
3422  if ($this->theme) {
3423  $template_dirs[] = array($GLOBALS['egotec_conf']['pub_dir']."theme/{$this->theme}/skin/blocks/", $GLOBALS['egotec_conf']['url_dir']."pub/theme/{$this->theme}/skin/blocks/");
3424  }
3425  foreach ($template_dirs as $template_dir) {
3426  if (!empty($template_dir) && Ego_System::file_exists($template_dir[0])) {
3427  // Alle Templates dieses Verzeichnisses ermitteln
3428  $dir = dir($template_dir[0]);
3429  while (($file = $dir->read()) !== false) {
3430  if (
3431  !in_array($file, array('.', '..'))
3432  && preg_match('/^(.*?)\.html$/i', $file, $match)
3433  ) {
3434  // Bezeichnung
3435  $name = $match[1];
3436 
3437  // Pfad
3438  $url = $template_dir[1].$file;
3439 
3440  // Beschreibung
3441  $description = '';
3442  if (Ego_System::file_exists($template_dir[0].$name.'_desc.php')) {
3443  // Es existiert eine Beschreibung für dieses Template
3444  $description = Ego_System::file_get_contents($template_dir[0].$name.'_desc.php');
3445  $description = preg_replace('/(\r\n|\r|\n|\t)/msi', '', strip_tags($description));
3446  $description = str_replace("'", "\'", $description);
3447  }
3448 
3449  $templates[] = array(
3450  'title' => $name,
3451  'url' => $url,
3452  'description' => $description
3453  );
3454  }
3455  }
3456  $dir->close();
3457  }
3458  }
3459  ksort($templates);
3460  return $templates;
3461  }
3462 
3468  public function hasLiveserver() {
3469  return (
3470  !$GLOBALS['egotec_conf']['liveserver']
3471  && $this->admin['live']['login']
3472  && $this->admin['live']['password']
3473  && ($this->admin['live']['location'] || Ego_System::getCluster($this))
3474  );
3475  }
3476 
3483  public function getSearchCount($weight = 0) {
3484  if (!is_numeric($weight)) {
3485  $weight = 0;
3486  }
3487 
3488  $counts = array();
3489  $default_counts = array(
3490  'keywords' => 100,
3491  'url' => 50,
3492  'name' => 25,
3493  'title' => 12,
3494  'short' => 6,
3495  'content' => 3,
3496  'extra' => 1
3497  );
3498  foreach ($default_counts as $key => $default_value) {
3499  $value = (!empty($this->admin['count'][$key]) ? (int)$this->admin['count'][$key] : $default_value) + $weight;
3500  $counts[$key] = $value > 0 ? $value : 1;
3501  }
3502  return $counts;
3503  }
3504 
3511  public function getVHosts() {
3512  $virtualhost = array();
3513  if (Ego_System::file_exists($GLOBALS['egotec_conf']['var_dir'].'conf/virtual_hosts.ini')) {
3514  $virtualhosts_ini = parse_ini_file($GLOBALS['egotec_conf']['var_dir'].'conf/virtual_hosts.ini', true);
3515  foreach ($virtualhosts_ini as $vhost => $vdata) {
3516  if ($vdata['site'] == $this->name && $vdata['lang'] == $this->language && !array_key_exists($vhost, $virtualhost)) {
3517  $virtualhost[md5($vhost)] = array(
3518  'site' => $vdata['site'],
3519  'lang' => $vdata['lang'],
3520  'domain' => $vhost
3521  );
3522  }
3523  }
3524  }
3525  if (empty($virtualhost)) {
3526  $virtualhost[md5($_SERVER['HTTP_HOST'].'/')] = array(
3527  'site' => $this->site,
3528  'lang' => $this->language,
3529  'domain' => $_SERVER['HTTP_HOST'].'/'
3530  );
3531  }
3532  return $virtualhost;
3533  }
3534 
3542  public function updatePiwikHosts() {
3543  require_once 'stats/Ego_Piwik.php';
3544  $piwik = new Ego_Piwik();
3545  $piwiksites = $this->getPages(array(
3546  'where' => "extra LIKE '%s:5:\"piwik\"%'"
3547  ));
3548  $hosts = $this->getVHosts();
3549  // Wenn Seiten hinterlegt sind, werden die URLs geupdatet
3550  if ($piwiksites->numRecords()) {
3551  foreach ($piwiksites as $psite) {
3552  if ($psite->extra['piwik']) {
3553  if ($psite->extra['piwik']['auth_token'] == 'undefined' && $psite->extra['piwik']['red_id'] == 'undefined') {
3554  $piwikdata = $psite->addPiwikSite();
3555  $extra = $psite->extra;
3556  $extra['piwik'] = $piwikdata;
3557  $psite->updateExtra($extra);
3558  } else {
3559  if (!$psite->extra['piwik']['live_id'] && $this->hasLiveserver()) {
3560  $piwikdata = $piwik->createWebsite($psite, true);
3561  $extra = $psite->extra;
3562  $extra['piwik'] = $piwikdata;
3563  $psite->updateExtra($extra);
3564  }
3565  $piwik->updateSiteURLs($psite->extra['piwik']['red_id'], $hosts, $psite->extra['piwik']['live_id'], $this);
3566  }
3567  }
3568  }
3569  } else { // Sind keine hinterlegt wird unterhalb der RootPage eine Statistikseite erstellt (auch für neue Mandanten)
3570  $new_psite = $this->getRoot();
3571  if ($new_psite && !$new_psite->extra['do_not_track']) {
3572  $piwikdata = $new_psite->addPiwikSite();
3573  $extra = $new_psite->extra;
3574  $extra['piwik'] = $piwikdata;
3575  $new_psite->updateExtra($extra);
3576  }
3577  }
3578  }
3579 
3587  public function getAdminText($suffix = '', $fallback = true) {
3588  if ($fallback && !$suffix && $GLOBALS['egotec_conf']['liveserver']) {
3589  $admin_text = $this->getAdminText('_live', false);
3590  return $admin_text ? $admin_text : $this->getAdminText('', false);
3591  }
3592  if (!empty($this->admin['administration']['admin_text'.$suffix])) {
3593  return array(
3594  'text' => $GLOBALS['auth']->translate($this->admin['administration']['admin_text'.$suffix]),
3595  'url' => (string) $this->admin['administration']['admin_url'.$suffix]
3596  );
3597  } elseif (!empty($GLOBALS['egotec_conf']['admin_text'.$suffix])) {
3598  return array(
3599  'text' => $GLOBALS['auth']->translate($GLOBALS['egotec_conf']['admin_text'.$suffix]),
3600  'url' => (string) $GLOBALS['egotec_conf']['admin_url'.$suffix]
3601  );
3602  }
3603  return null;
3604  }
3605 
3612  public function isFrontendAdmin($check_rights = true) {
3613  return $this->site['type'] == 'content'
3614  && $this->admin['frontend_admin']
3615  && (
3616  !$check_rights
3617  || (
3618  $GLOBALS['auth']
3619  && !$GLOBALS['auth']->isNobody()
3620  )
3621  );
3622  }
3623 
3629  public function cleanup() {
3630  $db = new_db_connection();
3631  if ( in_array(get_class($db), ["Ego_Sql_mssql", "Ego_Sql_oci"]) ) {
3632  return; // TODO make mssql and oracle compatible
3633  };
3634  $db->begin();
3635 
3636  foreach ($this->getLanguages() as $lang) {
3637  $pageTable = $this->name.'_'.$lang;
3638  foreach (array(
3639  array('_v', 'id', $pageTable, 'id'), // Alle Einträge aus _v entfernen, bei denen id nicht in $pageTable existiert
3640  array('_children', 'page_id', $pageTable, 'id'), // Alle Einträge aus _children entfernen, bei denen page_id nicht in $pageTable existiert
3641  array('_rights', 'page_id', $pageTable, 'id'), // Alle Einträge aus _rights entfernen, bei denen page_id nicht in $pageTable existiert
3642  array('_users', 'page_id', $pageTable, 'id'), // Alle Einträge aus _users entfernen, bei denen page_id nicht in $pageTable existiert
3643  array('_rights', 'group_id', 'egotec_group', 'group_id'), // Alle Einträge aus _rights entfernen, bei denen group_id nicht in egotec_group existiert
3644  array('_rights', 'role_id', 'egotec_role', 'role_id'), // Alle Einträge aus _rights entfernen, bei denen role_id nicht in egotec_role existiert
3645  array('_users', 'user_id', 'egotec_user', 'user_id') // Alle Einträge aus _users entfernen, bei denen user_id nicht in egotec_user existiert
3646  ) as $v) {
3647  $db->delete(array(
3648  'table' => "{$pageTable}{$v[0]} AS t",
3649  'fields' => "t.*",
3650  'join' => array("{$v[2]} ON t.{$v[1]} = {$v[2]}.{$v[3]}"),
3651  'where' => "t.{$v[1]} != '*' AND {$v[2]}.{$v[3]} IS NULL"
3652  ));
3653  }
3654  }
3655 
3656  $db->commit();
3657  }
3658 
3665  public function getNextReplicationDate($page = null) {
3666  if (
3667  empty($GLOBALS['egotec_conf']['liveserver']) // Nicht auf dem Liveserver
3668  && (!$page
3669  || (($page->field['nav_hide']&2) == 0 // Diese Seite darf übertragen werden
3670  && $page->isPublic())) // Diese Seite ist keine Zwischenspeicherung
3671  ) {
3672  // Das Datum des letzten Live-/Clusterupdates ermitteln
3673  $live_date = '';
3674  if (($clusters = Ego_System::getCluster()) && sizeof($clusters)) {
3675  // Clusterupdate
3676  foreach ($clusters as $cluster) {
3677  $cluster_date_file = $GLOBALS['egotec_conf']['log_dir'].$this->name.'/live.'.$this->name.'_'.$this->language.'.'.$cluster['id'].'.date';
3678  if (Ego_System::file_exists($cluster_date_file)) {
3679  $cluster_date = Ego_System::file_get_contents($cluster_date_file);
3680  if (!$live_date || $cluster_date > $live_date) {
3681  $live_date = $cluster_date;
3682  }
3683  }
3684  }
3685  } else {
3686  // Liveupdate
3687  $live_date_file = $GLOBALS['egotec_conf']['log_dir'] . $this->name . '/live.' . $this->name . '_' . $this->language . '.date';
3688  if (!Ego_System::file_exists($live_date_file)) {
3689  $live_date_file = $GLOBALS['egotec_conf']['log_dir'] . $this->name . '/live.date';
3690  }
3691  if (Ego_System::file_exists($live_date_file)) {
3692  $live_date = Ego_System::file_get_contents($live_date_file);
3693  }
3694  }
3695 
3696  // Das Datum des letzten Live-/Clusterupdates ist bekannt (und diese Seite wurde seitdem bearbeitet)
3697  if (!empty($live_date) && (!$page || $page->field['c_date'] > $live_date)) {
3698  // Prüfen, in welchen (aktiven) Diensten ein Live-/Clusterupdate aktiviert und das Intervall bekannt ist
3699  $next_date = '';
3700  foreach ($this->conf['admin'] as $key => $values) {
3701  if (
3702  strpos($key, 'cron_') === 0
3703  && !empty($GLOBALS['egotec_conf'][$key]['aktiv'])
3704  && !empty($GLOBALS['egotec_conf'][$key]['interval'])
3705  && (!empty($values['live_incr'])
3706  || !empty($values['cluster_incr']))
3707  ) {
3708  $dates = array(
3709  date('Y-m-d'),
3710  date('Y-m-d', strtotime('+1 day')) // Wenn heute kein Update mehr stattfindet, dann für morgen prüfen
3711  );
3712  if (
3713  strpos($GLOBALS['egotec_conf'][$key]['interval'], '*') === 0
3714  && strlen($GLOBALS['egotec_conf'][$key]['interval']) >= 2
3715  ) {
3716  // Alle n Uhrzeiten
3717  $n_date = substr($GLOBALS['egotec_conf'][$key]['interval'], 1);
3718  list($h, $is) = explode(':', $n_date, 2);
3719  $intervals = array();
3720  foreach (range(0, 24, $h) as $h_range) {
3721  $intervals[] = $h_range.($is ? ":{$is}" : '');
3722  }
3723  } else {
3724  $intervals = explode(',', $GLOBALS['egotec_conf'][$key]['interval']);
3725  }
3726  foreach ($intervals as $date) {
3727  list($h, $i, $s) = explode(':', $date, 3);
3728  $time = sprintf('%02d:%02d:%02d', (string) $h, (string) $i, (string) $s);
3729  foreach ($dates as $date) {
3730  $date = "$date $time";
3731  if (
3732  $date > (!$page ? $live_date : date('Y-m-d H:i:s', strtotime($page->field['c_date'])))
3733  && $date > date('Y-m-d H:i:s') // Datum muss in der Zukunft liegen
3734  && (empty($next_date) || $date < $next_date)
3735  ) {
3736  $next_date = $date;
3737  break;
3738  }
3739  }
3740  }
3741  }
3742  }
3743  return $next_date;
3744  }
3745  }
3746  return '';
3747  }
3748 
3754  public function getRewriteConf() {
3755  $conf = $GLOBALS['egotec_conf']['rewrite'];
3756  if ($this->conf['admin']['rewrite']['overwrite']) {
3757  $conf = $this->conf['admin']['rewrite'];
3758  unset($conf['overwrite']);
3759  }
3760  return $conf;
3761  }
3762 
3768  public function getSocialNetworks() {
3769  $networks = array();
3770 
3771  // Facebook
3772  if (!empty($this->admin['social']['facebook_page_id']) && !empty($this->admin['social']['facebook_access_token'])) {
3773  $networks[] = 'facebook';
3774  }
3775 
3776  // Twitter
3777  if (!empty($this->admin['social']['twitter_access_token'])) {
3778  $networks[] = 'twitter';
3779  }
3780 
3781  return $networks;
3782  }
3783 
3789  public function getVirtualHosts() {
3790  if (empty($this->virtualHosts)) {
3791  foreach (Ego_System::getVirtualHosts() as $virtual_host => $identity) {
3792  if (
3793  $identity['site'] == $this->name
3794  && $identity['lang'] == $this->language
3795  ) {
3796  $this->virtualHosts[] = (string) $virtual_host;
3797  }
3798  }
3799 
3800  if (empty($this->virtualHosts)) {
3801  // Gibt es keinen virtuellen Host, wird die Domain automatisch generiert
3802  $host = $_SERVER['HTTP_HOST'];
3803  if (!empty($GLOBALS['egotec_conf']['rewrite']['host'])) {
3804  $host = $GLOBALS['egotec_conf']['rewrite']['host'];
3805  }
3806  $default_host = rtrim($host, '/');
3807  if ($GLOBALS['egotec_conf']['default_site'] != $this->name) {
3808  $default_host .= '/' . $this->name;
3809  }
3810  if (sizeof($this->getLanguages()) > 1) {
3811  if ($this->language == $this->site['default_language']) {
3812  // Die Standardsprache kann auch ohne Sprachangabe aufgerufen werden
3813  $this->virtualHosts[] = $default_host;
3814  }
3815  $default_host .= (strpos($default_host, '/') === false ? '/' : '-') . $this->language;
3816  }
3817  $this->virtualHosts[] = $default_host;
3818  }
3819  }
3820  return $this->virtualHosts;
3821  }
3822 
3828  public function globalAllowed() {
3829  return !$GLOBALS['egotec_conf']['non_global_sites']
3830  || !in_array($this->name, explode(',', $GLOBALS['egotec_conf']['non_global_sites']));
3831  }
3832 }
3833 
3837 function _types_compare($a, $b)
3838 {
3839  // Für die Sortierung nicht zu beachtende Zeichen, da diese das Ergebnis verfälschen würden
3840  $f = create_function('$c', 'return preg_replace("/[- ]/", "_", $c);');
3841 
3842  return strcasecmp($f($a['fullname']), $f($b['fullname']));
3843 }
__construct($site_name='', $language='', $skin='', $only_active=true, $time='')
Definition: Site.php:413
updatePiwikHosts()
Definition: Site.php:3542
const LANG_DOESNT_EXIST
Definition: Site.php:13
getAdminText($suffix='', $fallback=true)
Definition: Site.php:3587
getCache()
Definition: Site.php:2378
setOnlyActive($b)
Definition: Site.php:468
const SITE_DOESNT_EXIST
Definition: Site.php:12
static getVariantFiles($type, $name, $path, $skip=array(), $parent='')
getSiteFile($path, $skip=array('module'), $url=false, $relative=false)
Definition: Site.php:3313
static file_put_contents($filename, $data, $flags=0, $context=null)
static start($table='', $param=[])
getVHosts()
Definition: Site.php:3511
setParam($param)
Definition: Site.php:594
addParam($param)
Definition: Site.php:579
const LANG_NOT_DELETABLE
Definition: Site.php:14
getPageClass($type='page')
Definition: Site.php:2715
updateMediaIndex($resume, $c_date, $skipFirst, $dryRun, $timeout)
Definition: Site.php:2823
$name
Definition: Site.php:45
getLayoutFiles($path='', $skip=array(), $conf=array())
Definition: Site.php:3366
getCacheExpire()
Definition: Site.php:2388
static createSite($new_site)
Definition: Site.php:194
isPublicSave()
Definition: Site.php:2290
getSkinFile($path, $skip=array('module'), $url=false, $relative=false)
Definition: Site.php:3295
getCacheEntry($key)
Definition: Site.php:2402
getNextReplicationDate($page=null)
Definition: Site.php:3665
isFrontendAdmin($check_rights=true)
Definition: Site.php:3612
getUploaderPage($page=null)
Definition: Site.php:2546
getFile($path, $type='skin')
Definition: Site.php:3331
const NO_NULL_RIGHTS
Definition: Auth.php:94
getCopyrights()
Definition: Site.php:3112
$language
Definition: Site.php:48
static getJSON($path, $values=array(), $combine=false, $ignore=[])
getOnlyActive()
Definition: Site.php:720
globalAllowed()
Definition: Site.php:3828
getRewriteConf()
Definition: Site.php:3754
getCacheLastChanged()
Definition: Site.php:2428
updateLinks($language='', $output=false)
Definition: Site.php:2787
static flush($string='')
Definition: Ego_System.php:724
static file_exists($file)
getDesklets($rights=false, $trashcan=false)
Definition: Site.php:2440
getPages($query=array(), $param=array())
Definition: Site.php:766
getUnusedPages()
Definition: Site.php:3068
__call($function, $params)
Definition: Site.php:68
__toString()
Definition: Site.php:2299
getTemplate($mobile=false, $name='index', $dir='', $variant='', $suffix='', $fallback=true)
Definition: Site.php:3204
removeLinks($language='')
Definition: Site.php:2987
static getMimeTypes($ext='')
static mkdir($dir, $mode=0755, $recursive=true)
Definition: Ego_System.php:497
static getCluster($site=null)
isMetaUrl($path)
Definition: Site.php:2255
__clone()
Definition: Site.php:2309
getPageId($name, $param=array())
Definition: Site.php:649
hasLiveserver()
Definition: Site.php:3468
getHash()
Definition: Site.php:602
getSkins($theme=false)
Definition: Site.php:626
getBlockFiles($path='', $skip=array())
Definition: Site.php:3398
clearTrashcan($query=array())
Definition: Site.php:2650
$site
Definition: Site.php:46
const MISSING_TEMPLATE
Definition: Site.php:15
_types_compare($a, $b)
Definition: Site.php:3837
static file_get_contents($filename, $utf8=true, $context=null)
setRights($rights=array())
Definition: Site.php:568
removeUrls($language='')
Definition: Site.php:3017
$admin
Definition: Site.php:47
cleanup()
Definition: Site.php:3629
static getFallbackFile($type, $name, $path, $skip=array('module'), $url=false, $relative=false, $parent='')
enoughDiskSpace()
Definition: Site.php:2326
static getDbDriver()
getSearchCount($weight=0)
Definition: Site.php:3483
hasDeleted()
Definition: Site.php:2636
getVariantFiles($path, $skip=array())
Definition: Site.php:3348
setTime($time='')
Definition: Site.php:482
getTime()
Definition: Site.php:729
updateUrls($reset=false, $verbose=false)
Definition: Site.php:3048
setLanguage($language='')
Definition: Site.php:499
static filterNonUtf8($s, $substitute="", $strict=false)
Definition: Ego_System.php:320
static header($header, $replace=true)
Definition: Ego_System.php:833
getLanguages()
Definition: Site.php:612
getSocialNetworks()
Definition: Site.php:3768
static getVirtualHosts()
getVirtualHosts()
Definition: Site.php:3789
getEditorTemplates()
Definition: Site.php:3416
hasRightsOnId($id, $rights, $user_id=false)
Definition: Site.php:2221
setCacheEntry($key, $value)
Definition: Site.php:2417
$pageTable
Definition: Site.php:49
static getFiles($type, $name, $path, $skip=array(), $parent='', $return_path=false, $get_variants=true)
Definition: Site.php:29