-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodifydate.php
204 lines (174 loc) · 5.86 KB
/
modifydate.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
<?php
/**
* @package Joomla.Plugin
* @subpackage Content.modifydate
*
* @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Factory;
/**
* Joomla! SEF Plugin.
*
* @since 1.5
*/
class PlgSystemModifyDate extends CMSPlugin
{
/**
* Application object.
*
* @var JApplicationCms
* @since 3.5
*/
protected $app;
/**
* Add the canonical uri to the head.
*
* @return void
*
* @since 3.5
*/
public function onAfterDispatch()
{
$doc = $this->app->getDocument();
// equivalent of $app = JFactory::getApplication();
$ismodified = (int) $this->params->get('modify_date', 0);
$dateformate = JText::_( 'DATE_FORMAT_CALENDAR_DATETIME');
if( $ismodified === 1){
$calendar = JHTML::calendar('','jform[modified_new]', 'jform_modified', $dateformate,array('size'=>'22','class'=>' required','showTime'=>true));
$calendar = preg_replace("/\s+|\n+|\r/", ' ', $calendar);
$input = $this->app->input;
$option = $input->get('option');
$view = $input->get('view');
$layout = $input->get('layout');
$id = $input->get('id');
if($option=='com_content' && $view=='article' && $layout=='edit' && isset($id)){
$db = Factory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__content');
$query->where('id = '. $id ); //put your condition here
$db->setQuery($query);
$result = $db->loadObjectList();
$resultmodified='';
if(!empty($result)){
$result = $result[0];
$resultmodified = $result->modified;
}
if($resultmodified){
$document = JFactory::getDocument();
$doc->addScriptDeclaration("
window.onload = (event) => {
document.getElementById('jform_modified').removeAttribute('readonly');
var valued = '".$resultmodified."';
console.log(valued);
document.getElementById('jform_modified').parentNode.setAttribute('id','modifydated');
document.getElementById('modifydated').parentNode.setAttribute('id','modifydatedid');
var elem = document.getElementById('jform_modified_btn');
elem.parentNode.removeChild(elem);
var elem = document.getElementById('jform_modified');
elem.parentNode.removeChild(elem);
document.getElementById('modifydatedid').innerHTML ='".$calendar."';
var elements = document.querySelectorAll('#modifydatedid .field-calendar');
for (i = 0; i < elements.length; i++) {
JoomlaCalendar.init(elements[i]);
}
document.getElementById('jform_modified').setAttribute('value',valued);
document.getElementById('jform_modified').setAttribute('data-alt-value',valued);
};
");
}else{
$document = JFactory::getDocument();
$doc->addScriptDeclaration("
window.onload = (event) => {
document.getElementById('jform_modified').removeAttribute('readonly');
var valued = document.getElementById('jform_modified').value;
console.log(valued);
document.getElementById('jform_modified').parentNode.setAttribute('id','modifydated');
document.getElementById('modifydated').parentNode.setAttribute('id','modifydatedid');
var elem = document.getElementById('jform_modified_btn');
elem.parentNode.removeChild(elem);
var elem = document.getElementById('jform_modified');
elem.parentNode.removeChild(elem);
document.getElementById('modifydatedid').innerHTML ='".$calendar."';
var elements = document.querySelectorAll('#modifydatedid .field-calendar');
for (i = 0; i < elements.length; i++) {
JoomlaCalendar.init(elements[i]);
}
document.getElementById('jform_modified').setAttribute('value',valued);
document.getElementById('jform_modified').setAttribute('data-alt-value',valued);
};
");
}
}
}else{
return;
}
//die('here');
}
/**
* Convert the site URL to fit to the HTTP request.
*
* @return void
*/
public function onAfterRender()
{
}
/**
* Convert the updated the modified the date of article.
*
* @return void
*/
function onContentAfterSave($context, $article, $isNew) {
$ismodified = (int) $this->params->get('modify_date', 0);
$input = $this->app->input;
$option = $input->get('option');
$view = $input->get('view');
$layout = $input->get('layout');
$id = $input->get('id');
if( $ismodified === 1 && isset($id)){
if(isset($_POST['jform']['modified_new'])){
$date_forchange= date('Y-m-d H:i:s',strtotime($_POST['jform']['modified_new']));
//$article->modified =$_POST['jform']['modified_new'];
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$fields = array('modified');
$fields = array(
$db->quoteName('modified') . ' = ' . $db->quote($date_forchange));
$conditions = array($db->quoteName('id') . ' = '.$id );
$query->update($db->quoteName('#__content'))->set($fields)->where($conditions);
echo $query;
$db->setQuery($query);
$result = $db->execute();
$query = $db->getQuery(true);
// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
/*$query->select($db->quoteName(array('modified', 'id')));
$query->from($db->quoteName('#__content'));
$query->where($db->quoteName('id') . ' = ' . $db->quote($id));
$query->order('ordering ASC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();
print_r($results);
die();*/
}
}
return true;
}
/**
* Check the buffer.
*
* @param string $buffer Buffer to be checked.
*
* @return void
*/
private function checkBuffer($buffer)
{
}
}