00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00133 class Page extends Object
00134 {
00135 var $pageid;
00136 var $templateid;
00137 var $template;
00138
00139 var $simple = false;
00140 var $public = false;
00141
00142 var $el = array();
00143
00144 var $icons = false;
00145 var $src = '';
00146 var $edit = false;
00147
00148 var $content_negotiation = false;
00149 var $cut_index = false;
00150 var $default_language = false;
00151 var $withLanguage = false;
00152 var $link = false;
00153 var $fullFilename = '';
00154
00155 var $log_filenames = array();
00156 var $modelid = 0;
00157
00158 var $publish = null;
00159 var $up_path = '';
00160
00161
00162 function Page( $objectid='' )
00163 {
00164 $this->Object( $objectid );
00165 $this->isPage = true;
00166 }
00167
00168
00175 function getObjectIdFromPageId( $pageid )
00176 {
00177 $db = db_connection();
00178
00179 $sql = new Sql( 'SELECT objectid FROM {t_page} '.
00180 ' WHERE id={pageid}' );
00181 $sql->setInt('pageid',$pageid);
00182
00183 return $db->getOne( $sql->query );
00184 }
00185
00186
00193 function getPageIdFromObjectId( $objectid )
00194 {
00195 $db = db_connection();
00196
00197 $sql = new Sql( 'SELECT id FROM {t_page} '.
00198 ' WHERE objectid={objectid}' );
00199 $sql->setInt('objectid',$objectid);
00200
00201 return $db->getOne( $sql->query );
00202 }
00203
00204
00210 function getProperties()
00211 {
00212 return array_merge( parent::getProperties(),
00213 array('full_filename'=>$this->fullFilename,
00214 'pageid' =>$this->pageid,
00215 'templateid' =>$this->templateid,
00216 'mime_type' =>$this->mimeType() ) );
00217 }
00218
00219
00224 function parentfolder()
00225 {
00226 $folder = new Folder();
00227 $folder->folderid = $this->folderid;
00228
00229 return $folder->parentfolder( false,false );
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00264 function path_to_object( $objectid )
00265 {
00266 global $conf_php,
00267 $SESS;
00268 $inhalt = '';
00269
00270 if ( ! Object::available( $objectid) )
00271 return '';
00272
00273 $param = array('oid'=>'__OID__'.$objectid.'__');
00274
00275 $object = new Object( $objectid );
00276 $object->objectLoad();
00277
00278 $cut_index = ( is_object($this->publish) && $this->publish->cut_index );
00279 $content_negotiation = ( is_object($this->publish) && $this->publish->content_negotiation );
00280
00281 if ( $this->public )
00282 {
00283 switch( $object->getType() )
00284 {
00285 case 'file':
00286
00287 $inhalt = $this->up_path();
00288
00289 $f = new File( $objectid );
00290 $f->load();
00291 $inhalt .= $f->full_filename();
00292 break;
00293
00294 case 'page':
00295
00296 $inhalt = $this->up_path();
00297
00298 $p = new Page( $objectid );
00299 $p->languageid = $this->languageid;
00300 $p->cut_index = $cut_index;
00301 $p->content_negotiation = $content_negotiation;
00302 $p->withLanguage = $this->withLanguage;
00303 $p->load();
00304 $inhalt .= $p->full_filename();
00305 break;
00306
00307 case 'link':
00308 $link = new Link( $objectid );
00309 $link->load();
00310
00311 if ( $link->isLinkToObject )
00312 {
00313 $linkedObject = new Object( $link->linkedObjectId );
00314 $linkedObject->load();
00315
00316 switch( $linkedObject->getType() )
00317 {
00318 case 'file':
00319 $f = new File( $link->linkedObjectId );
00320 $f->load();
00321 $inhalt = $this->up_path();
00322 $inhalt .= $f->full_filename();
00323 break;
00324
00325 case 'page':
00326 $p = new Page( $link->linkedObjectId );
00327 $p->languageid = $this->languageid;
00328 $p->cut_index = $cut_index;
00329 $p->content_negotiation = $content_negotiation;
00330 $p->load();
00331 $inhalt = $this->up_path();
00332 $inhalt .= $p->full_filename();
00333 break;
00334 }
00335 }
00336 else
00337 {
00338 $inhalt = $link->url;
00339 }
00340 break;
00341 }
00342 }
00343 else
00344 {
00345
00346 switch( $object->getType() )
00347 {
00348 case 'file':
00349 $inhalt = Html::url('file','show',$objectid,$param);
00350 break;
00351
00352 case 'page':
00353 $inhalt = Html::url('page','show',$objectid,$param);
00354 break;
00355
00356 case 'link':
00357 $link = new Link( $objectid );
00358 $link->load();
00359
00360 if ( $link->isLinkToObject )
00361 {
00362 $linkedObject = new Object( $link->linkedObjectId );
00363 $linkedObject->load();
00364
00365 switch( $linkedObject->getType() )
00366 {
00367 case 'file':
00368 $inhalt = Html::url('file','show',$link->linkedObjectId,$param);
00369 break;
00370
00371 case 'page':
00372 $inhalt = Html::url('page','show',$link->linkedObjectId,$param);
00373 break;
00374 }
00375 }
00376 else
00377 {
00378 $inhalt = $link->url;
00379 }
00380 break;
00381 }
00382 }
00383
00384 return $inhalt;
00385 }
00386
00387
00388
00396 function up_path()
00397 {
00398 global $conf;
00399
00400 if ( $conf['filename']['url'] == 'absolute' )
00401 {
00402 $this->up_path = '/';
00403 return $this->up_path;
00404 }
00405
00406 if ( $this->up_path != '' )
00407 return $this->up_path;
00408
00409 $folder = new Folder( $this->parentid );
00410 $folder->load();
00411 $folder->parentObjectIds(false,true);
00412 $f = count( $folder->parentfolders );
00413
00414 if ( $f == 0 )
00415 {
00416 $this->up_path = './';
00417 }
00418 else
00419 {
00420 $this->up_path = str_repeat( '../',$f );
00421 }
00422
00423 return $this->up_path;
00424 }
00425
00426
00430 function add()
00431 {
00432 $db = db_connection();
00433
00434 $this->objectAdd();
00435
00436 $sql = new Sql('SELECT MAX(id) FROM {t_page}');
00437 $this->pageid = intval($db->getOne($sql->query))+1;
00438
00439 $sql = new Sql('INSERT INTO {t_page}'.
00440 ' (id,objectid,templateid)'.
00441 ' VALUES( {pageid},{objectid},{templateid} )' );
00442 $sql->setInt ('pageid' ,$this->pageid );
00443 $sql->setInt ('objectid' ,$this->objectid );
00444 $sql->setInt ('templateid',$this->templateid );
00445
00446 $db->query( $sql->query );
00447 }
00448
00449
00453 function load()
00454 {
00455 $db = db_connection();
00456
00457 $sql = new Sql( 'SELECT * FROM {t_page} '.
00458 ' WHERE objectid={objectid}' );
00459 $sql->setInt('objectid',$this->objectid);
00460 $row = $db->getRow( $sql->query );
00461
00462 $this->pageid = $row['id' ];
00463 $this->templateid = $row['templateid'];
00464
00465 $this->objectLoad();
00466 }
00467
00468
00469 function delete()
00470 {
00471 global $db;
00472
00473 $sql = new Sql( 'DELETE FROM {t_value} '.
00474 ' WHERE pageid={pageid}' );
00475 $sql->setInt('pageid',$this->pageid);
00476 $db->query( $sql->query );
00477
00478 $sql = new Sql( 'DELETE FROM {t_page} '.
00479 ' WHERE objectid={objectid}' );
00480 $sql->setInt('objectid',$this->objectid);
00481 $db->query( $sql->query );
00482
00483 $this->objectDelete();
00484 }
00485
00486
00491 function copyValuesFromPage( $otherpageid )
00492 {
00493 $this->load();
00494
00495 foreach( $this->getElementIds() as $elementid )
00496 {
00497 foreach( Language::getAll() as $lid=>$lname )
00498 {
00499 $val = new Value();
00500 $val->publish = false;
00501 $val->element = new Element( $elementid );
00502
00503 $val->objectid = $otherpageid;
00504 $val->pageid = Page::getPageIdFromObjectId( $otherpageid );
00505 $val->languageid = $lid;
00506 $val->load();
00507
00508
00509 if ( $val->valueid != 0 )
00510 {
00511 $val->objectid = $this->objectid;
00512 $val->pageid = Page::getPageIdFromObjectId( $this->objectid );
00513 $val->save();
00514 }
00515 }
00516 }
00517 }
00518
00519
00520
00521
00522 function save()
00523 {
00524 $db = db_connection();
00525
00526 $sql = new Sql('UPDATE {t_page}'.
00527 ' SET templateid ={templateid}'.
00528 ' WHERE objectid={objectid}' );
00529 $sql->setInt('templateid' ,$this->templateid);
00530 $sql->setInt('objectid' ,$this->objectid );
00531 $db->query( $sql->query );
00532
00533 $this->objectSave();
00534 }
00535
00536
00537
00538 function replaceTemplate( $newTemplateId,$replaceElementMap )
00539 {
00540 $oldTemplateId = $this->templateid;
00541
00542 $db = db_connection();
00543
00544
00545 $this->templateid = $newTemplateId;
00546
00547 $sql = new Sql('UPDATE {t_page}'.
00548 ' SET templateid ={templateid}'.
00549 ' WHERE objectid={objectid}' );
00550 $sql->setInt('templateid' ,$this->templateid);
00551 $sql->setInt('objectid' ,$this->objectid );
00552 $db->query( $sql->query );
00553
00554
00555
00556 $template = new Template( $oldTemplateId );
00557 foreach( $template->getElementIds() as $oldElementId )
00558 {
00559 if ( !isset($replaceElementMap[$oldElementId]) ||
00560 intval($replaceElementMap[$oldElementId]) < 1 )
00561 {
00562 Logger::debug( 'deleting value of elementid '.$oldElementId );
00563 $sql = new Sql('DELETE FROM {t_value}'.
00564 ' WHERE pageid={pageid}'.
00565 ' AND elementid={elementid}' );
00566 $sql->setInt('pageid' ,$this->pageid);
00567 $sql->setInt('elementid',$oldElementId );
00568
00569 $db->query( $sql->query );
00570 }
00571 else
00572 {
00573 $newElementId = intval($replaceElementMap[$oldElementId]);
00574
00575 Logger::debug( 'updating elementid '.$oldElementId.' -> '.$newElementId );
00576 $sql = new Sql('UPDATE {t_value}'.
00577 ' SET elementid ={newelementid}'.
00578 ' WHERE pageid ={pageid}'.
00579 ' AND elementid={oldelementid}' );
00580 $sql->setInt('pageid' ,$this->pageid);
00581 $sql->setInt('oldelementid',$oldElementId );
00582 $sql->setInt('newelementid',$newElementId );
00583 $db->query( $sql->query );
00584 }
00585 }
00586 }
00587
00588
00589
00595 function full_filename()
00596 {
00597 $filename = $this->path();
00598
00599 if ( !empty($filename) )
00600 $filename .= '/';
00601
00602 if ( !$this->cut_index || $this->filename != 'index' )
00603 {
00604 $filename .= $this->filename();
00605
00606 if ( !$this->content_negotiation )
00607 {
00608 if ( !$this->default_language && $this->withLanguage )
00609 {
00610 $l = new Language( $this->languageid );
00611 $l->load();
00612 $filename .= '.'.$l->isoCode;
00613 }
00614
00615 $t = new Template( $this->templateid );
00616 $t->modelid = $this->modelid;
00617 $t->load();
00618 $filename .= '.'.$t->extension;
00619
00620 if ( $this->default_language && $this->withLanguage )
00621 {
00622 $filename .= '.'.$t->extension;
00623 }
00624 }
00625 }
00626
00627 $this->fullFilename = $filename;
00628 return $filename;
00629 }
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00665 function getElementIds()
00666 {
00667 $t = new Template( $this->templateid );
00668
00669 return $t->getElementIds();
00670 }
00671
00672
00673
00680 function getElements()
00681 {
00682 if ( !isset($this->template) )
00683 $this->template = new Template( $this->templateid );
00684
00685 return $this->template->getElements();
00686 }
00687
00688
00689
00696 function getWritableElements()
00697 {
00698 if ( !isset($this->template) )
00699 $this->template = new Template( $this->templateid );
00700
00701 return $this->template->getWritableElements();
00702 }
00703
00704
00705
00712 function generate_elements()
00713 {
00714 $this->values = array();
00715
00716 if ( $this->simple )
00717 $elements = $this->getWritableElements();
00718 else
00719 $elements = $this->getElements();
00720
00721 foreach( $elements as $elementid=>$element )
00722 {
00723
00724 $val = new Value();
00725 $val->publish = $this->public;
00726 $val->element = $element;
00727
00728 $val->objectid = $this->objectid;
00729 $val->pageid = $this->pageid;
00730 $val->languageid = $this->languageid;
00731 $val->simple = $this->simple;
00732 $val->modelid = $this->modelid;
00733 $val->page = $this;
00734 $val->generate();
00735 $val->page = null;
00736 $this->values[$elementid] = $val;
00737 }
00738 }
00739
00740
00745 function generate()
00746 {
00747 global $conf;
00748
00749 if ( $conf['cache']['enable_cache'] && is_file($this->tmpfile() ))
00750 {
00751 $this->value = implode('',file($this->tmpfile()));
00752 return $this->value;
00753 }
00754
00755 $this->template = new Template( $this->templateid );
00756 $this->template->modelid = $this->modelid;
00757 $this->template->load();
00758 $this->ext = $this->template->extension;
00759
00760 $this->generate_elements();
00761
00762 $src = $this->template->src;
00763
00764
00765
00766 foreach( $this->values as $id=>$value )
00767 {
00768 $inh = $value->value;
00769 $src = str_replace( '{{'.$id.'}}',$inh,$src );
00770
00771
00772 if ( $inh == '' )
00773 {
00774
00775 $src = str_replace( '{{IFEMPTY:'.$id.':BEGIN}}','',$src );
00776 $src = str_replace( '{{IFEMPTY:'.$id.':END}}' ,'',$src );
00777
00778 $src = Text::entferneVonBis( $src,'{{IFNOTEMPTY:'.$id.':BEGIN}}','{{IFNOTEMPTY:'.$id.':END}}' );
00779 }
00780 else
00781 {
00782
00783 $src = str_replace( '{{IFNOTEMPTY:'.$id.':BEGIN}}','',$src );
00784 $src = str_replace( '{{IFNOTEMPTY:'.$id.':END}}' ,'',$src );
00785
00786 $src = Text::entferneVonBis( $src,'{{IFEMPTY:'.$id.':BEGIN}}','{{IFEMPTY:'.$id.':END}}' );
00787 }
00788
00789 if ( $this->icons )
00790 $src = str_replace( '{{->'.$id.'}}','<a href="'.Html::url('pageelement','edit',$this->objectid,array('elementid'=>$id)).'" title="'.$value->element->desc.'" target="cms_main_main"><img src="'.OR_THEMES_DIR.$conf['interface']['theme'].'/images/icon_el_'.$value->element->type.IMG_ICON_EXT.'" border="0"></a>',$src );
00791 else
00792 $src = str_replace( '{{->'.$id.'}}','',$src );
00793 }
00794
00795 #Html::debug(strlen($src),'laenge am ende');
00796
00797 $this->value = &$src;
00798
00799
00800 $f = fopen( $this->tmpfile(),'w' );
00801 fwrite( $f,$this->value );
00802 fclose( $f );
00803
00804 return $this->value;
00805 }
00806
00807
00811 function write()
00812 {
00813 if ( !is_file($this->tmpfile()))
00814 $this->generate();
00815 }
00816
00817
00821 function publish()
00822 {
00823 global $SESS;
00824 $db = db_connection();
00825
00826 if ( ! is_object($this->publish) )
00827 $this->publish = new Publish();
00828
00829 $this->public = true;
00830
00831
00832 $allLanguages = Language::getAll();
00833
00834 foreach( $allLanguages as $languageid=>$x )
00835 {
00836 $this->languageid = $languageid;
00837 $this->withLanguage = count($allLanguages) > 1;
00838
00839
00840 foreach( Model::getAll() as $projectmodelid=>$x )
00841 {
00842 $this->modelid = $projectmodelid;
00843
00844 $this->load();
00845 $this->generate();
00846 $this->write();
00847
00848
00849 $t = new Template( $this->templateid );
00850 $t->modelid = $this->modelid;
00851 $t->load();
00852
00853 if ( !empty($t->extension) )
00854 {
00855 $this->publish->copy( $this->tmpfile(),$this->full_filename() );
00856 unlink( $this->tmpfile() );
00857 $this->publish->publishedObjects[] = $this->getProperties();
00858 }
00859 }
00860 }
00861
00862 }
00863
00864
00870 function mimeType()
00871 {
00872 if ( ! is_object($this->template) )
00873 {
00874 $this->template = new Template( $this->templateid );
00875 $this->template->modelid = $this->modelid;
00876 $this->template->load();
00877 }
00878
00879 $this->mime_type = $this->template->mimeType();
00880
00881 return( $this->mime_type );
00882 }
00883
00884
00885
00889 function tmpfile()
00890 {
00891 $db = db_connection();
00892 $filename = $this->getTempFileName( array('db'=>$db->id,
00893 'o' =>$this->objectid,
00894 'l' =>$this->languageid,
00895 'm' =>$this->modelid,
00896 'p' =>intval($this->public),
00897 's' =>intval($this->simple) ) );
00898 return $filename;
00899 }
00900
00901
00902
00903 function setTimestamp()
00904 {
00905 $tmpFilename = $this->tmpfile();
00906
00907 if ( is_file($tmpFilename) )
00908 unlink( $tmpFilename);
00909
00910 parent::setTimestamp();
00911 }
00912
00913 }
00914
00915
00916 ?>