-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDumpLexicon.php
78 lines (70 loc) · 2.31 KB
/
DumpLexicon.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
<?php
/**
* @package = DumpLexicon
*
* dump MODX Revolution 2.x lexicon content from database do files
*
* This script dumps any MODX Revolution 2.x lexicon content from
* database to include files.
*
* This script runs outside of MODx, but uses its config and xPDO
* objects.
*
* TODO:
*
*/
define('NAMESPACE_', 'hotpointclub');
// define('ORDERBY', 'name'); // optional - order by name
define('PATH', './core/components/' . NAMESPACE_ . '/lexicon/');
define(MODX_CORE_PATH, dirname(__FILE__) . '/../core/');
include_once MODX_CORE_PATH . '/model/modx/modx.class.php';
$modx= new modX();
$modx->initialize('mgr');
// collect lexicon items
$lexicon = array();
$query = $modx->newQuery('modLexiconEntry');
$query->where(array('namespace' => NAMESPACE_));
if (defined('ORDERBY')) {
// if is defined sorting
if (ORDERBY) {
// if sort fieldname isn't empty
$query->sortby(ORDERBY, 'asc');
}
}
$entries = $modx->getCollection('modLexiconEntry', $query);
foreach ($entries as $entry) {
$data = $entry->toArray();
$lexicon[$data['language']][$data['topic']][$data['name']] = $data['value'];
}
// create directories and files
foreach ($lexicon as $language => $data) {
$dir = PATH . $language . '/';
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
foreach ($data as $topic => $data2) {
$handle = fopen($dir . '/' . $topic . '.inc.php', 'w');
fwrite($handle, '<?php' . "\n");
fwrite($handle, '/**' . "\n");
fwrite($handle, ' * ' . $topic . ' ' . $language . ' lexicon topic' . "\n");
fwrite($handle, ' *' . "\n");
fwrite($handle, ' * @language ' . $language . '' . "\n");
fwrite($handle, ' * @package ' . NAMESPACE_ . "\n");
fwrite($handle, ' * @subpackage lexicon' . "\n");
fwrite($handle, ' *' . "\n");
fwrite($handle, ' * @updated ' . date('Y-m-d') . "\n");
fwrite($handle, ' */' . "\n");
fwrite($handle, "\n");
foreach ($data2 as $name => $value) {
fwrite($handle, "\$_lang['" . $name . "'] = '" . addslashes($value) . "';\n");
}
fwrite($handle, '?>' . "\n");
fclose($handle);
}
}
if (count($lexicon)) {
echo 'MODX lexicon ' . NAMESPACE_ . ' exported to directory ' . PATH;
} else {
echo 'MODX lexicon ' . NAMESPACE_ . ' is empty!';
}
?>