-
Notifications
You must be signed in to change notification settings - Fork 1
/
BuildPageTreeLanguageVariant.php
executable file
·212 lines (172 loc) · 6.6 KB
/
BuildPageTreeLanguageVariant.php
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
<?php
/**
* ZOOLU - Content Management System
* Copyright (c) 2008-2009 HID GmbH (http://www.hid.ag)
*
* LICENSE
*
* This file is part of ZOOLU.
*
* ZOOLU is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZOOLU is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ZOOLU. If not, see http://www.gnu.org/licenses/gpl-3.0.html.
*
* For further information visit our website www.getzoolu.org
* or contact us at zoolu@getzoolu.org
*
* @category ZOOLU
* @package cli
* @copyright Copyright (c) 2008-2009 HID GmbH (http://www.hid.ag)
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License, Version 3
* @version $Id: version.php
*/
define('APPLICATION_ENV', 'development');
/**
* include general (autoloader, config)
*/
require_once(dirname(__FILE__) . '/../sys_config/general.inc.php');
try {
$objConsoleOpts = new Zend_Console_Getopt(
array(
'folderId|f=i' => 'Folder Id',
'rootLevelId|r=i' => 'RootLevel Id',
'fromLanguageId|fl=i' => 'From Language Id',
'toLanguageId|tl=i' => 'To Language Id',
'deleteUrls|du=i' => 'Delete Urls'
)
);
echo "build tree language variant\n---------------------------\n";
if (isset($objConsoleOpts->fromLanguageId) && isset($objConsoleOpts->toLanguageId)) {
echo "load first level of the tree ...\n";
require_once GLOBAL_ROOT_PATH . $core->sysConfig->path->zoolu_modules . 'core/models/Folders.php';
$objModelFolders = new Model_Folders();
$objModelFolders->setLanguageId($objConsoleOpts->fromLanguageId);
if (isset($objConsoleOpts->folderId) && $objConsoleOpts->folderId > 0) {
$objPages = $objModelFolders->loadChildNavigation($objConsoleOpts->folderId);
} else if (isset($objConsoleOpts->rootLevelId) && $objConsoleOpts->rootLevelId > 0) {
$objPages = $objModelFolders->loadRootNavigation($objConsoleOpts->rootLevelId);
}
// simulate user auth
$obj = new stdClass();
$obj->id = 2; //user id
Zend_Auth::getInstance()->getStorage()->write($obj);
if (isset($objPages) && count($objPages)) {
buildTreeLanguageVariantNow($objPages);
}
// delete urls
if (isset($objConsoleOpts->deleteUrls) && $objConsoleOpts->deleteUrls == 1) {
deleteUrls();
}
}
echo "---------------------------\n";
} catch (Exception $exc) {
echo($exc);
}
/*--------------------------------------------------------
* some functions building the tree language variante
*-------------------------------------------------------/
/**
* buildTreeLanguageVariantNow
*/
function buildTreeLanguageVariantNow($objPages, $intLevel = 0)
{
global $objModelFolders, $core;
foreach ($objPages as $objPage) {
for ($i = 0; $i < ($intLevel * 2); $i++) {
echo "-";
}
echo $objPage->id . ' :: ' . $objPage->elementType . ' :: ' . $objPage->title . '|' . $objPage->guiTitle . ' :: ' . $objPage->genericFormId . ' :: ' . $objPage->templateId . "\n";
switch ($objPage->elementType) {
case 'folder':
$objNewPage = $objModelFolders->loadChildNavigation($objPage->id);
buildFolderLanguageVariant($objPage);
buildTreeLanguageVariantNow($objNewPage, ($intLevel + 1));
break;
case 'page':
buildPageLanguageVariant($objPage);
break;
}
}
}
/**
* buildFolderLanguageVariant
*/
function buildFolderLanguageVariant($objFolder)
{
global $objConsoleOpts, $core;
// folder form
$objFolderForm = new GenericForm();
$objFolderForm->Setup()->setElementId($objFolder->id);
$objFolderForm->Setup()->setFormId($objFolder->genericFormId);
$objFolderForm->Setup()->setActionType($core->sysConfig->generic->actions->edit);
$objFolderForm->Setup()->setLanguageId($objConsoleOpts->fromLanguageId);
$objFolderForm->Setup()->setFormLanguageId($core->sysConfig->languages->default->id);
// load basic generic form
$objFolderForm->Setup()->loadGenericForm();
// load generic form structur
$objFolderForm->Setup()->loadGenericFormStructure();
// init data type object
$objFolderForm->initDataTypeObject();
// load data
$objFolderForm->loadFormData();
// set new language
$objFolderForm->Setup()->setLanguageId($objConsoleOpts->toLanguageId);
// set new language
$objFolderForm->saveFormData();
}
/**
* buildPageLanguageVariant
*/
function buildPageLanguageVariant($objPage)
{
global $objConsoleOpts, $core;
// product form
$objPageForm = new GenericForm();
$objPageForm->Setup()->setElementId($objPage->id);
$objPageForm->Setup()->setFormId($objPage->genericFormId);
$objPageForm->Setup()->setTemplateId($objPage->templateId);
$objPageForm->Setup()->setFormVersion($objPage->version);
$objPageForm->Setup()->setActionType($core->sysConfig->generic->actions->edit);
$objPageForm->Setup()->setLanguageId($objConsoleOpts->fromLanguageId);
$objPageForm->Setup()->setFormLanguageId($core->sysConfig->languages->default->id);
$objPageForm->Setup()->setModelSubPath('cms/models/');
// load basic generic form
$objPageForm->Setup()->loadGenericForm();
// load generic form structur
$objPageForm->Setup()->loadGenericFormStructure();
// init data type object
$objPageForm->initDataTypeObject();
// load data
$objPageForm->loadFormData();
// set new language
$objPageForm->Setup()->setLanguageId($objConsoleOpts->toLanguageId);
//rest url
if ($objPageForm->Setup()->getField('url')) {
$objPageForm->Setup()->getField('url')->setValue('');
}
// set new language
$objPageForm->saveFormData();
}
/**
* deleteUrls
*/
function deleteUrls()
{
global $objConsoleOpts, $core;
if (isset($objConsoleOpts->toLanguageId)) {
$sql = "DELETE FROM `urls` WHERE `urls`.`idLanguages` = " . $objConsoleOpts->toLanguageId . " AND `urls`.`url` != '';";
$stmt = $core->dbh->prepare($sql);
$stmt->execute();
echo "---------------------------\nUrls deleted!\n";
}
}
?>