-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadTranslation.php
More file actions
executable file
·124 lines (98 loc) · 3.48 KB
/
uploadTranslation.php
File metadata and controls
executable file
·124 lines (98 loc) · 3.48 KB
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
<?php
/**
* @package Language Manager By Team PayPlans
*
* @copyright Copyright (C) 2009 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later;
* @Author Jitendra Khatri
* @contact payplans@readybytes.in
*
*/
const _JEXEC = 1;
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';
// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';
jimport('joomla.filesystem.folder');
class uploadTranslation extends JApplicationCli
{
//Function contains script for adding Resource Entry
public function doExecute()
{
$this->out('For Uploading Translations Type "upload" : ');
$input = $this->in();
if($input == 'upload')
{
//For Taking File Name
$this->out("File Path : ");
$folderPath = $this->in();
//
// //For Taking Resource Id.
// $this->out("Language Code : ");
// $languageCode = $this->in();
//
$folders = JFolder::folders($folderPath);
foreach($folders as $folder){
$subFolderPath = $folderPath."/".$folder;
$files = JFolder::files($subFolderPath);
foreach($files as $file){
$filePath = $subFolderPath."/".$file;
if(file_exists($filePath))
{
$fileContent = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$db = JFactory::getDbo();
$query = $db->getQuery(true);
//For Cross checking of key and reource id exists or not.
$query->select('*')
->from('`#__dictionary`');
$db->setQuery($query);
$db->query();
$record = $db->loadObjectList('key');
$query->clear();
foreach($fileContent as $arrKey => $string)
{
$string = trim($string, " ");
//If Comment then nothing to dump in DataBase
if( empty($string) || ($string[0] == ';'))
continue;
//For Separating key and value from the string
$string = explode('="', $string);
if (empty($string[0]) || empty($string[1]))
continue;
$key = $string[0];
$value = rtrim($string[1], '"\n');
if(!array_key_exists("$key", $record) || ( array_key_exists("$key", $record)
&& !($record[$key]->value == $value)
&& !($record[$key]->language_code == $folder) ) )
{
$value = $db->quote($value);
//Dumps key value and resource id into database
$query->insert('#__dictionary');
$query->set("`key`='$key', `value`=$value, `language_code`='$folder'");
$db->setQuery($query);
$db->query();
}
unset($key);
unset($value);
unset($string);
$query->clear();
}
}
}
}
}
}
}
JApplicationCli::getInstance('uploadTranslation')->execute();