-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContentPage.php.inc
executable file
·1800 lines (1604 loc) · 60.7 KB
/
ContentPage.php.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @brief Admin_ContentPage Module ContentPage library
* @details Plugin / Module Library
* @file plugin/module/Admin_ContentPage/lib/ContentPage.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.2
* @date Creation: Jun 2005
* @date Modification: Oct 2018
* @copyright 2005 - 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* ContentPage class.
*/
final class ContentPage {
/**
* var integer $mode
* @brief Page mode, same as CaMykS modes.
*/
public $mode;
/**
* var integer $id
* @brief Page id.
*/
public $id = 0;
/**
* var string $name
* @brief Page symbolic name.
*/
public $name = '';
/**
* var integer $parent_id
* @brief Parent page id.
*/
public $parent_id;
/**
* var integer $position
* @brief Sorting position in parent page children list.
*/
public $position;
/**
* var string $type
* @brief Page type, currently unused.
*/
public $type = 'page';
/**
* var boolean $active
* @brief Page status.
*/
public $active = 0;
/**
* var boolean $secured
* @brief Page has to be access with https, currently unused.
*/
public $secured = 0;
/**
* var integer $wf_version
* @brief Workflow version, currently unused.
*/
public $wf_version = 1;
/**
* var integer $wf_status
* @brief Workflow status, currently unused.
*/
public $wf_status;
/**
* var integer $wf_cdate
* @brief Workflow creation date, currently unused.
*/
public $wf_cdate;
/**
* var integer $wf_mdate
* @brief Workflow modification date, currently unused.
*/
public $wf_mdate;
/**
* var string $wf_owner
* @brief Page owner.
*/
public $wf_owner;
/**
* var string $wf_editor
* @brief Page editor group.
*/
public $wf_editor;
/**
* var string $wf_validator
* @brief Page validation group, currently unused.
*/
public $wf_validator;
/**
* var string $template
* @brief Page template.
*/
public $template = '';
/**
* var string $theme
* @brief Page theme.
*/
public $theme = '';
/**
* var boolean $homepage
* @brief Is page the home page.
*/
public $homepage;
/**
* var array $modules
* @brief Included modules.
*/
public $modules = array();
/**
* var array $metas
* @brief Page metas.
*/
public $metas = array();
/**
* var string $metas_
* @brief Textual version of metas.
*/
public $metas_ = '';
/**
* var array $children
* @brief Page children.
*/
public $children = array();
/**
* var array $params
* @brief Page parameters.
*/
public $params = array();
/**
* var array $params
* @brief Textual version of page parameters.
*/
public $params_;
/**
* var boolean $_libIsInstalled
* @brief Library installation status.
*/
public $_libIsInstalled;
/**
* var boolean $_libParent
* @brief Parent module.
*/
public $_libParent;
/**
* var string $object_type
* @brief Library object type.
*/
public $object_type = 'Module Library';
/**
* var integer $maxmodules
* @brief Maximum module to be inserted in page.
*/
public $maxmodules;
/**
* Class constructor.
* @param integer $mode
* @param integer $id
* @param array $params
* @return void
*/
public function __construct($mode=CAMYKS_MODE_SITE, $id=0, $params=array()) {
global $camyks;
/* set up page id */
if ((int)$id >= 0) {
$this->id = (int)$id;
} else {
$this->id = 0;
}
//$this->sitelink = '';
$this->mode = $mode;
$this->params_ = $params;
$this->maxmodules = $camyks->get_confValue('page_maxmodules');
$this->_libParent = &$camyks->modules['Admin_ContentPage'];
}
/* Data manipulation methods */
/**
* Return page case of CaMykS mode.
* @param mixed $page the page to get
* @return boolean success
*/
public function get($page=null) {
if ($this->mode == CAMYKS_MODE_SITE) {
return $this->site_get($page);
} else if ($this->mode == CAMYKS_MODE_ADMIN) {
if ($this->id == 0) {
return $this->initialise();
} else {
return $this->admin_get();
}
}
}
/**
* Save object.
* @return boolean success
*/
public function save() {
if ($this->check_data()) {
if ($this->id > 0)
return $this->update_toDatabase();
return $this->create_toDatabase();
}
}
/**
* Return object in site mode.
* @param mixed $page the page to get
* @return boolean success
*/
public function site_get($page) {
return $this->get_fromDatabase($page);
}
/**
* Load object as displayed front page.
* @param mixed $page
* @return boolean success
*/
public function load_asFrontPage($page) {
global $camyks;
/* check page : prevent from url injection */
if (preg_match('/[^a-zA-Z0-9_\-]/', $page))
$page=0;
/* try to load page */
if ($page == '' and $this->get_homeFromDatabase())
return true;
if ($this->get_fromDatabase($page))
return true;
/* check for 404 header sending */
if ($this->get_configValue('page_404SendHeader') == 1)
header('HTTP/1.1 404 Not Found');
/* load failed, use fallbacks */
switch ($this->get_configValue('page_404FallBack')) {
case 'home_display':
$this->get_homeFromDatabase();
return false;
case 'home_redirect':
header('Location:'.$camyks->get_siteHomepageLink());
die();
case 'page_display':
if ($page != $this->get_configValue('page_404ErrorPage')) {
$this->site_get($this->get_configValue('page_404ErrorPage'));
return false;
}
break;
case 'page_redirect':
if ($page != $this->get_configValue('page_404ErrorPage')) {
header('Location:'.$camyks->get_siteLink($this->get_configValue('page_404ErrorPage')));
die();
}
break;
case 'error404_display':
if (file_exists($this->get_configValue('page_404ErrorFile'))) {
@readfile($this->get_configValue('page_404ErrorFile'));
die();
}
break;
case 'error404_redirect':
if (file_exists($this->get_configValue('page_404ErrorFile'))) {
header('Location:'.$camyks->get_confValue('url').'/'.$this->get_configValue('page_404ErrorFile'));
die();
}
break;
}
/* error on fallback page, alternate fallback, redirect to home page */
header('Location:'.$camyks->get_siteHomepageLink());
return false;
}
/**
* Return object in admin mode.
* @return boolean success
*/
public function admin_get() {
return $this->get_allVersionsFromDatabase();
}
/**
* Check admin user right on this page.
* @return boolean result
*/
public function check_rights() {
global $camyks;
/* check workflow and status */
if ($camyks->site_conf['workflow'] == 1 and $this->wf_status != 'edition') {
return false;
}
/* check webmaster */
if ($camyks->adminUser->webmaster == 1) {
return true;
}
/* check owner value */
if ($camyks->adminUser->login == $this->wf_owner) {
return true;
}
/* check editor group value */
if ($camyks->check_sharedData('cp_groups')) {
$camyks->set_sharedData('cp_groups', array());
}
$groups = $camyks->modules['Admin_Group']->get_groups();
if (isset($groups[$this->wf_editor]))
return ($groups[$this->wf_editor]->is_userInGroup($camyks->adminUser->login));
return false;
}
/**
* Check page data.
* @return boolean result
*/
private function check_data() {
global $camyks;
/* check name */
$this->name = trim($this->name);
/* parse invalid chars */
if ($camyks->get_confValue('friendlyurls') == 'modern')
$this->name = preg_replace(array('/^([^a-zA-Z0-9]+)/', '/([^_a-zA-Z0-9\-]+)/', '/([^a-zA-Z0-9]+)$/'), array('', '-', ''), $this->name);
else
$this->name = preg_replace(array('/^([^a-zA-Z0-9]+)/', '/([^_a-zA-Z0-9]+)/', '/([^a-zA-Z0-9]+)$/'), array('', '_', ''), $this->name);
/* check empty name */
if ($this->name == '') {
if ($this->id > 0) {
$this->name = $this->type.$this->id;
} else {
$sql = 'select max(id) as m from admin_contentpage';
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__))
if ($data = $camyks->db_conn->get_queryDataLine())
$this->name = $this->type.($data['m']+1);
else
$this->name = $this->type;
else
$this->name = $this->type;
}
} else if (!preg_match ('([_a-zA-Z\-])', $this->name)) {
/* check if name contain at least one alphabetic char */
$this->name = $this->type.$this->name;
}
/* check if name exists */
$pages = array();
$sql = 'select id, name';
$sql .= ' from admin_contentpage';
$sql .= ' where name like "'.$this->name.'%"';
$sql .= ' group by id, name';
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__))
while($data = $camyks->db_conn->get_queryDataLine())
$pages[$data['name']] = $data['id'];
if ((isset ($pages[$this->name]) and $pages[$this->name] != $this->id)) {
$cnt = 1;
while (isset($pages[$this->name.$cnt]) and $pages[$this->name.$cnt] != $this->id) {
$cnt++;
}
$this->name .= $cnt;
}
/* trim localized data */
foreach ($this->locales as $l => $trad)
foreach ($trad as $item => $value)
$this->locales[$l][$item] = trim($value);
/* trim global metas */
foreach ($this->metas as $m => $meta)
foreach ($meta as $item => $value)
$this->metas[$m][$item] = trim ($value);
/* create encoded version of metas */
$this->encode_metas();
/* add user name if needed */
$this->wf_owner = isset($camyks->adminUser->login)?$camyks->adminUser->login:'admin';
return true;
}
/**
* Initialise object.
* @return boolean result
*/
private function initialise() {
global $camyks;
/* get header values */
$this->parent_id = isset($_REQUEST['parent_id'])? (int)$_REQUEST['parent_id'] : 0;
$this->type = isset($_REQUEST['type'])? $_REQUEST['type'] : 'page';
/* get parent relative values */
$this->get_parentRights();
$this->get_newPosition();
$this->name = '';
$this->active = 0;
$this->secured = 0;
$this->wf_version = 1;
$this->wf_state = ($camyks->get_confValue('workflow') == 0 ? 'inline' : 'edition');
$this->wf_owner = $camyks->adminUser->login;
$this->wf_cdate = time();
$this->wf_mdate = time();
$this->theme = '';
$this->template = '';
$this->homepage = 0;
foreach ($camyks->get_confValue('editing_languages') as $l) {
$this->locales[$l] = array('title'=>'', 'shorttitle'=>'', 'description'=>'', 'keywords'=>'');
}
return true;
}
/*********************** DATABASE DATA I/O ************************/
/**
* Load object data from database.
* @param mixed $page the page to get
* @return boolean success
*/
private function get_fromDatabase($page=null) {
if (isset ($page)) {
if (is_numeric($page))
return $this->get_objectFromDatabase(' and admin_contentpage.id='.(int)$page);
else if (is_string($page))
return $this->get_objectFromDatabase(' and admin_contentpage.name="'.addSlashes($page).'"');
}
return $this->get_objectFromDatabase(' and admin_contentpage.id='.(int)$this->id);
}
/**
* Load homepage object data from database.
* @return boolean success
*/
public function get_homeFromDatabase() {
return $this->get_objectFromDatabase(' and admin_contentpage.homepage=1');
}
/**
* Load first object available from database.
* @return boolean success
*/
private function get_firstFromDatabase() {
return $this->get_objectFromDatabase('');
}
/**
* Load object data from database generic method.
* @param string $query some query modification
* @return boolean success
*/
private function get_objectFromDatabase ($query='') {
global $camyks;
$sql = 'select *';
$sql .= ' from admin_contentpage, admin_contentpagelocale';
$sql .= ' where admin_contentpage.type="page"';
$sql .= ' and admin_contentpage.wf_status="inline"';
if (isset($_REQUEST['preview']) and $_REQUEST['preview'] == 'forced' and $camyks->modules['Admin_ContentPage']->check_right(0)) {
/* page preview */
} else {
$sql .= ' and admin_contentpage.active=1';
}
$sql .= ' '.$query;
$sql .= ' and admin_contentpage.id=admin_contentpagelocale.id';
$sql .= ' and admin_contentpage.wf_version=admin_contentpagelocale.wf_version';
$sql .= ' and admin_contentpagelocale.language="'.$camyks->current_language.'"';
$sql .= ' limit 1';
/* execute query */
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__)) {
/* gather object data */
if ($data = $camyks->db_conn->get_queryDataLine()) {
$this->get_fromArray($data);
$this->get_localeFromArray($data);
return true;
}
}
return false;
}
/**
* Load all object version from database, set the latest version to the object.
* @return boolean success
*/
private function get_allVersionsFromDatabase() {
global $camyks;
$isFirst = true;
$sql = 'select * from admin_contentpage where id='.$this->id.' order by wf_version desc';
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__)) {
/* execute sql query */
while ($data = $camyks->db_conn->get_queryDataLine()) {
if ($isFirst) {
$this->get_fromArray($data);
$this->get_localesFromDatabase();
$this->versions = array();
$isFirst = false;
} else {
$p = new ContentPage(CAMYKS_MODE_ADMIN, $this->id);
$p->get_fromArray();
$this->versions[] = $p;
}
return true;
}
}
return false;
}
/**
* Load object locales from database.
* @return success
*/
private function get_localesFromDatabase() {
global $camyks;
$this->locales = array();
$sql = 'select * from admin_contentpagelocale where id='.$this->id.' and wf_version='.$this->wf_version;
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__)) {
while ($data = $camyks->db_conn->get_queryDataLine()){
$this->locales[ $data['language'] ] = $this->get_localesFromArray($data);
}
}
foreach ($camyks->get_confValue('editing_languages') as $l) {
if (!isset($this->locales[$l]))
$this->locales[$l] = $this->get_localesFromArray(array('title'=>'', 'shorttitle'=>'', 'keywords'=>'', 'description'=>''));
}
return true;
}
/**
* Create new object to the database.
* @return boolean success
*/
private function create_toDatabase() {
global $camyks;
$sql = 'INSERT INTO `admin_contentpage` (';
$sql .= ' `parent_id`';
$sql .= ', `position`';
$sql .= ', `type`';
$sql .= ', `name`';
$sql .= ', `active`';
$sql .= ', `secured`';
$sql .= ', `wf_version`';
$sql .= ', `wf_status`';
$sql .= ', `wf_cdate`';
$sql .= ', `wf_mdate`';
$sql .= ', `wf_owner`';
$sql .= ', `wf_editor`';
$sql .= ', `wf_validator`';
$sql .= ', `template`';
$sql .= ', `theme`';
$sql .= ', `homepage`';
$sql .= ', `metas`';
for ($i=0; $i< $this->maxmodules; $i++) {
$sql .= ', `m'.$i.'_name`';
$sql .= ', `m'.$i.'_content`';
$sql .= ', `m'.$i.'_theme`';
}
$sql .= ') VALUES (';
$sql .= ''.$this->parent_id.'';
$sql .= ', '.$this->position.'';
$sql .= ', "'.$this->type.'"';
$sql .= ', "'.$this->name.'"';
$sql .= ', '.$this->active.'';
$sql .= ', '.$this->secured.'';
$sql .= ', '.$this->wf_version.'';
$sql .= ', "'.($camyks->site_conf['workflow'] == 0 ? 'inline' : 'edition').'"';
$sql .= ', '.time().'';
$sql .= ', '.time().'';
$sql .= ', "'.$this->wf_owner.'"';
$sql .= ', "'.$this->wf_editor.'"';
$sql .= ', "'.$this->wf_validator.'"';
$sql .= ', "'.$this->template.'"';
$sql .= ', "'.$this->theme.'"';
$sql .= ', '.$this->homepage.'';
$sql .= ', "'.addslashes($this->metas_).'"';
for ($i=0; $i<$this->maxmodules; $i++) {
if (isset ($this->modules[$i])) {
$sql .= ', "'.$this->modules[$i]['name'].'"';
$sql .= ', "'.$this->modules[$i]['content'].'"';
$sql .= ', "'.$this->modules[$i]['theme'].'"';
} else {
$sql .= ', ""';
$sql .= ', ""';
$sql .= ', ""';
}
}
$sql .= ')';
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__)) {
$this->id = $camyks->db_conn->get_queryGeneratedId();
return $this->update_languages ();
}
return false;
}
/**
* Update object to database.
* @return boolean success
*/
private function update_toDatabase() {
global $camyks;
$sql = 'update admin_contentpage';
$sql .= ' set ';
if ($this->allow_content_edition and $this->allow_rights_edition) {
$sql .= $this->update_contentQuery();
$sql .= ', ' .$this->update_rightsQuery();
} else if ($this->allow_content_edition) {
$sql .= $this->update_contentQuery();
} else if ($this->allow_rights_edition) {
$sql .= $this->update_rightsQuery();
} else {
return false;
}
$sql .= ', `wf_mdate`='.time();
$sql .= ' where id='.$this->id;
$sql .= ' and wf_version='.$this->wf_version;
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__)) {
if ($this->allow_content_edition)
return $this->update_languages();
return true;
} else {
return false;
}
}
/**
* Build content part for the updating query.
* @return string the sql query part
*/
private function update_contentQuery() {
$sql = ' `name`="'.$this->name.'"';
$sql .= ', `active`='.$this->active;
$sql .= ', `secured`='.$this->secured;
$sql .= ', `template`="'.$this->template.'"';
$sql .= ', `theme`="'.$this->theme.'"';
$sql .= ', `homepage`='.$this->homepage;
$sql .= ', `metas`="'.addslashes($this->metas_).'"';
for ($i=0; $i< $this->maxmodules; $i++) {
$sql .= ', `m'.$i.'_name`="'.$this->modules[$i]['name'].'"';
$sql .= ', `m'.$i.'_content`="'.$this->modules[$i]['content'].'"';
$sql .= ', `m'.$i.'_theme`="'.$this->modules[$i]['theme'].'"';
}
return $sql;
}
/**
* Build right part for the updating query.
* @return string the sql query part
*/
private function update_rightsQuery() {
global $camyks;
$sql = ' `wf_editor`="'.$this->wf_editor.'"';
if ($camyks->site_conf['workflow'] == 1) {
$sql = ' `wf_validator`="'.$this->wf_validator.'"';
}
return $sql;
}
/**
* Update object languages.
* @return boolean success
*/
private function update_languages() {
global $camyks;
/* delete locales lines */
$this->delete_localesFromDatabase();
/* insert new locale values */
$sql = 'INSERT INTO `admin_contentpagelocale` (';
$sql .= ' `id`';
$sql .= ', `wf_version`';
$sql .= ', `language`';
$sql .= ', `title`';
$sql .= ', `shorttitle`';
$sql .= ', `keywords`';
$sql .= ', `description`';
$sql .= ') values ';
foreach ($this->locales as $lang => $l) {
$sql .= '('.$this->id.', '.$this->wf_version.', "'.$lang.'"';
$sql .= ', "'.$camyks->encode_value($l['title']).'"';
$sql .= ', "'.$camyks->encode_value($l['shorttitle']).'"';
$sql .= ', "'.$camyks->encode_value($l['keywords']).'"';
$sql .= ', "'.$camyks->encode_value($l['description']).'"';
$sql .= '), ';
}
$sql = substr($sql, 0, strlen($sql)-2);
return $camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__);
}
/**
* Delete object from database.
* @return boolean success
*/
public function delete_fromDatabase() {
global $camyks;
$sql = 'delete from admin_contentpage';
$sql .= ' where id='.$this->id;
$sql .= ' and wf_version='.$this->wf_version;
return $camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__);
}
/**
* Delete object languages from database.
* @return boolean success
*/
public function delete_localesFromDatabase() {
global $camyks;
$sql = 'delete from admin_contentpagelocale';
$sql .= ' where id='.$this->id;
$sql .= ' and wf_version='.$this->wf_version;
return $camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__);
}
/**
* Install object table into database, add first page.
* @return boolean success
*/
public function install() {
global $camyks;
/* create master table */
$fields = array(
array('name'=>'parent_id', 'type'=>'int', 'desc1'=>'bigint unsigned', 'desc2'=>'', 'default'=>0),
array('name'=>'position', 'type'=>'int', 'desc1'=>'int unsigned', 'desc2'=>'', 'default'=>0),
array('name'=>'type', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>16, 'default'=>''),
array('name'=>'name', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>128, 'default'=>''),
array('name'=>'active', 'type'=>'int', 'desc1'=>'tinyint unsigned', 'desc2'=>'', 'default'=>1),
array('name'=>'secured', 'type'=>'int', 'desc1'=>'tinyint unsigned', 'desc2'=>'', 'default'=>0),
array('name'=>'wf_version', 'type'=>'int', 'desc1'=>'int unsigned', 'desc2'=>'', 'default'=>0),
array('name'=>'wf_status', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>16, 'default'=>''),
array('name'=>'wf_cdate', 'type'=>'int', 'desc1'=>'bigint unsigned', 'desc2'=>'', 'default'=>0),
array('name'=>'wf_mdate', 'type'=>'int', 'desc1'=>'bigint unsigned', 'desc2'=>'', 'default'=>0),
array('name'=>'wf_owner', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>32, 'default'=>''),
array('name'=>'wf_editor', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>32, 'default'=>''),
array('name'=>'wf_validator', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>32, 'default'=>''),
array('name'=>'template', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>255, 'default'=>''),
array('name'=>'theme', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>255, 'default'=>''),
array('name'=>'homepage', 'type'=>'int', 'desc1'=>'tinyint unsigned', 'desc2'=>'', 'default'=>0),
array('name'=>'metas', 'type'=>'text', 'desc1'=>'text', 'desc2'=>'', 'default'=>''),
);
for ($i=0; $i< $this->maxmodules; $i++) {
$fields[] = array('name'=>'m'.$i.'_name', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>255, 'default'=>'');
$fields[] = array('name'=>'m'.$i.'_content', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>255, 'default'=>'');
$fields[] = array('name'=>'m'.$i.'_theme', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>255, 'default'=>'');
}
if (!$camyks->db_conn->create_table('admin_contentpage', $fields, $camyks->get_mysqlencodingvalue(), true, array('id', 'wf_version')))
return false;
/* create locale table */
$fields = array(
array('name'=>'wf_version', 'type'=>'int', 'desc1'=>'int unsigned', 'desc2'=>'', 'default'=>0),
array('name'=>'language', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>3, 'default'=>''),
array('name'=>'title', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>255, 'default'=>''),
array('name'=>'shorttitle', 'type'=>'text', 'desc1'=>'varchar', 'desc2'=>255, 'default'=>''),
array('name'=>'keywords', 'type'=>'text', 'desc1'=>'text', 'desc2'=>'', 'default'=>''),
array('name'=>'description', 'type'=>'text', 'desc1'=>'text', 'desc2'=>'', 'default'=>''),
);
if (!$camyks->db_conn->create_table('admin_contentpagelocale', $fields, $camyks->get_mysqlencodingvalue(), true, array('id', 'wf_version', 'language')))
return false;
/* add first page */
$this->id = 0;
$this->parent_id = 0;
$this->position = 0;
$this->type = 'page';
$this->name = 'home';
$this->active = 1;
$this->secured = 0;
$this->wf_version = 1;
$this->wf_status = 'inline';
$this->wf_owner = 'admin';
$this->wf_editor = 'all';
$this->wf_validator = 'all';
$this->theme = '';
$this->template = '';
$this->homepage = 1;
$this->metas_ = '';
$this->locales = array();
foreach ($camyks->site_conf['editing_languages'] as $l) {
$this->locales[$l] = array('title'=>'', 'shorttitle'=>'', 'keywords'=>'', 'description'=>'');
}
return $this->create_toDatabase();
}
/**
* Check if object is installed in database.
* @return boolean result
*/
public function is_installed() {
global $camyks;
if (!isset($this->_libIsInstalled)) {
/* check database presence in plugin manager module */
if (isset($camyks->modules['Admin_PluginManager']))
$this->_libIsInstalled = $camyks->modules['Admin_PluginManager']->check_tableExists('admin_contentpage');
else {
/* load table list */
$tl = $camyks->db_conn->get_tableList();
/* check if main table is in installed table list */
$this->_libIsInstalled = in_array('admin_contentpage', $tl);
}
}
return $this->_libIsInstalled;
}
/**
* Load parent page rights.
* @return void
*/
private function get_parentRights() {
global $camyks;
if ($this->parent_id > 0){
$sql = 'select wf_editor, wf_validator from admin_contentpage where id='.$this->parent_id.' order by wf_version desc';
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__)) {
/* execute sql query */
if ($data = $camyks->db_conn->get_queryDataLine()) {
$this->wf_editor = $data['wf_editor'];
$this->wf_validator = $data['wf_validator'];
return;
}
}
}
if ($camyks->site_conf['workflow'] == 0) {
$this->wf_editor = 'all';
$this->wf_validator = 'all';
} else {
$this->wf_editor = 'none';
$this->wf_validator = 'none';
}
}
/**
* Return next page position into page tree.
* @return void
*/
private function get_newPosition() {
global $camyks;
$sql = 'select max(position) as cnt from admin_contentpage where type="page" and parent_id='.$this->parent_id.'';
if ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__)) {
/* execute sql query */
if ($data = $camyks->db_conn->get_queryDataLine()) {
$this->position = $data['cnt']+1;
return;
}
}
$this->position = 0;
}
/*********************** HEADER DATA I/O ************************/
/**
* Load object data from header.
* @return void
*/
public function get_fromHeader() {
global $camyks;
if ($this->allow_content_edition) {
/* get content values */
$this->parent_id = (int)$_REQUEST['parent_id'];
$this->name = $_REQUEST['name'];
$this->type = isset($_REQUEST['type'])? $_REQUEST['type'] : 'page';
$this->active = isset ($_REQUEST['active']) ? (int)$_REQUEST['active'] : 0;
$this->secured = isset ($_REQUEST['secured']) ? (int)$_REQUEST['secured'] : 0;
$this->template = $_REQUEST['template'];
$this->theme = $_REQUEST['theme'];
$this->homepage = isset ($_REQUEST['homepage']) ? (int)$_REQUEST['homepage'] : 0;
/* get metas lines */
$this->metas = array();
$meta_count = isset($_REQUEST['meta_count'])?(int)$_REQUEST['meta_count']:0;
for ($i=0; $i<$meta_count; $i++) {
if (isset($_REQUEST['meta_name'.$i]) and $_REQUEST['meta_name'.$i]!= '') {
$this->metas[] = array($_REQUEST['meta_name'.$i],
isset($_REQUEST['meta_content'.$i])?$_REQUEST['meta_content'.$i]:'',
isset($_REQUEST['meta_language'.$i])?$_REQUEST['meta_language'.$i]:'',
isset($_REQUEST['meta_method'.$i])?$_REQUEST['meta_method'.$i]:'');
}
}
/* get modules */
for ($i=0; $i< $this->maxmodules; $i++) {
$m = array();
$m['name'] = $_REQUEST['m'.$i.'_name'];
$m['content'] = $_REQUEST['m'.$i.'_content'];
$m['theme'] = isset($_REQUEST['m'.$i.'_theme'])?$_REQUEST['m'.$i.'_theme']:'';
$this->modules[$i] = $m;
}
/* get translations */
$this->locales = array();
foreach ($camyks->site_conf['editing_languages'] as $l) {
$this->locales[$l] = array();
$this->locales[$l]['title'] = $_REQUEST['title_'.$l];
$this->locales[$l]['shorttitle'] = $_REQUEST['shorttitle_'.$l];
$this->locales[$l]['description'] = $_REQUEST['description_'.$l];
$this->locales[$l]['keywords'] = $_REQUEST['keywords_'.$l];
}
}
/* get rights values */
if ($this->allow_rights_edition) {
$this->wf_editor = $_REQUEST['wf_editor'];
if ($camyks->site_conf['workflow'] == 1) {
$this->wf_validator = $_REQUEST['wf_validator'];
}
}
}
/**
* Update page location.
* @param integer $newParentId
* @return boolean success
*/
public function update_move($newParentId) {
global $camyks;
$this->parent_id = $newParentId;
$this->get_newPosition();
/* build update sql query */
$sql = 'update admin_contentpage';
$sql .= ' set position='.$this->position;
$sql .= ', parent_id='.$this->parent_id;
$sql .= ' where id='.$this->id;
return ($camyks->db_conn->execute_query($sql) or $camyks->log_sqlerror($this, $sql, __FILE__, __LINE__));
}
/**
* Update page position up.
* @return boolean success
*/
public function update_moveUp() {
return $this->update_movePosition(-1);
}
/**
* Update page position down.
* @return boolean success
*/
public function update_moveDown() {
return $this->update_movePosition(1);
}
/**