-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadResource.php
More file actions
executable file
·136 lines (112 loc) · 3.58 KB
/
uploadResource.php
File metadata and controls
executable file
·136 lines (112 loc) · 3.58 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
125
126
127
128
129
130
131
132
133
134
135
136
<?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 uploadResource extends JApplicationCli
{
//Function contains script for adding Resource Entry
public function doExecute()
{
$this->out('For List of Available Resources Type "list" and For Uploading New Resource Type "upload" : ');
$list = $this->in();
// $list = 'upload';
switch(strtolower($list))
{
case 'list':
$result = $this->_getResources();
if($result)
{
foreach($result as $resource){
$this->out("\nFile Id : $resource->file_id\n"."File Name : $resource->file_name\n"."Version : $resource->version\n");
}
$this->out('For Uploading Resource Use "upload" :');
}
break;
case 'upload':
//For Taking File Name
$this->out("File Path : ");
$filePath = $this->in();
//For Taking Resource Id.
$this->out("Resource File Id : ");
$resourceId = $this->in();
$this->_uploadResource($filePath, $resourceId);
}
}
protected function _getResources()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*')
->from('#__resource');
$db->setQuery($query);
$db->query();
return $db->loadObjectList();
}
protected function _uploadResource($filePath, $resourceId)
{
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('`#__source`');
$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], '"');
if(!array_key_exists("$key", $record))
{
$value = $db->quote($value);
//Dumps key value and resource id into database
$query->insert('`#__source`');
$query->set("`key`='$key', `value`=$value, `resource_id`='$resourceId'");
$db->setQuery((string)$query);
$db->query();
$query->clear();
}
unset($key);
unset($value);
unset($string);
}
}
}
}
JApplicationCli::getInstance('uploadResource')->execute();