This repository has been archived by the owner on Aug 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment_publishdate.module
188 lines (150 loc) · 4.33 KB
/
comment_publishdate.module
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
<?php
// $Id$
/**
* @file
* Comment publishdate module
*
* Omogoca spremljanje, kdaj je bil komentar prvic objavljen 'published'.
*/
/**
* Implementation of hook_form_FORM_ID_alter();
*/
function comment_publishdate_form_comment_form_alter($form, &$form_state) {
global $user;
// Datum odgovora (ko je bil komentar prvic objavljen)
if (arg(0) == 'comment' && arg(1) == 'edit' && is_numeric(arg(2))){
$cid = arg(2);
$comment_published = (comment_publishdate_get($cid))? date('d-m-Y h:i', comment_publishdate_get($cid)): t('undefined');
// Spremembe forme
$form['admin']['author']['#weight'] = -2;
$form['admin']['date']['#size'] = 30;
$form['admin']['objavljeno'] = array(
'#type' => 'textfield',
'#title' => t('Comment published'),
'#default_value' => $comment_published,
'#size' => 30,
'#weight' => 0,
'#disabled' => TRUE,
);
$form['admin']['status']['#weight'] = 1;
// Link za ogled posameznega komentarja
$form['singlecomment'] = array(
'#type' => 'markup',
'#weight' => 2,
'#value' => l('Comment details', 'comment/publishdate/' . $cid, array('attributes' => array('id' => 'comment-details'))),
);
}
}
/**
* Implementation of hook_comment()
*/
function comment_publishdate_comment(&$a1, $op){
switch($op){
// Ko je komentar objavljen v bazo zapišemo timestamp objave.
case 'publish':
if (arg(0) == 'comment' && arg(1) == 'edit' && is_numeric(arg(2))){
$cid = arg(2);
comment_publishdate_set($cid);
}
break;
}
}
/**
* Preverimo ce je publish timestamp za dolocen komentar že v bazi.
*
* @param $cid
* Comment ID.
* @return
* Cas prve objave v unix timestamp obliki ce zapis obstaja, sicer FASLE.
*/
function comment_publishdate_get($cid){
if ($cid && is_numeric($cid)) {
$sql = 'SELECT publishdate FROM {comment_publishdate} WHERE cid = %d';
$result = db_query($sql, $cid);
$timestamp = db_fetch_array($result);
if ($timestamp){
return $timestamp['publishdate'];
}
else {
return FALSE;
}
}
}
/**
* V bazo zapiše timestamp objave.
*
* @param (int)$cid
* Comment ID.
*/
function comment_publishdate_set($cid) {
if ($cid && is_numeric($cid)) {
if(comment_publishdate_get($cid) == FALSE) {
$sql = 'INSERT INTO {comment_publishdate} (cid, publishdate) VALUES (%d, %d)';
(int)$timestamp = time();
db_query($sql, $cid, $timestamp);
}
}
}
/**
* Implementation of hook_menu().
*/
function comment_publishdate_menu(){
$items['comment/publishdate/%'] = array(
'title' => 'Show comment',
'title callback' => 'show_comment_title_callback',
'title arguments' => array(2),
'page callback' => 'show_single_comment',
'page arguments' => array(2),
'access arguments' => array('administer comments'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Title callback za pogled posameznega komentarja.
*
* @param $cid
* Comment id.
*/
//TODO: grdo. Mogoče bi mogla imeti tablea še en stolpec z nid-i.
function show_comment_title_callback($cid) {
$comment = _comment_load($cid);
$node = node_load($comment->nid);
drupal_set_title($node->title);
}
/**
* Implemetation of hook_link().
*/
function comment_publishdate_link($type, $object, $teaser = FALSE){
if ($type == 'comment'){
$links['preglej_komentar'] = array(
'title' => t('Comment details'),
'href' => 'comment/publishdate/' . $object->cid,
);
return $links;
}
}
/**
* Show single comment.
*
* Prikaže posamezen komentar.
*
* @param $cid
* Comment id tega komentarja.
*/
// TODO: To bi lahko naredili s theme funkcijo.
function show_single_comment($cid) {
$comment = _comment_load($cid);
$comment_user = user_load($comment->uid);
$comment_user_details = $comment_user->profile_name . ' ' . $comment_user->profile_surname . ' (' . $comment_user->name . ') - ' . $comment_user->profile_company;
$comment_published = (comment_publishdate_get($cid))? comment_publishdate_get($cid): NULL;
$header = NULL;
$rows = array(
array(t('Subject'), $comment->subject),
array(t('Post date'), date('d/m/Y h:i', $comment->timestamp)),
array(t('User'), $comment_user_details),
array(t('Comment'), $comment->comment),
array(t('Published on'), ($comment_published)? date('d/m/Y h:i', $comment_published): t('Not published yet') ),
);
return theme('table', $header , $rows , $attributes = array('id' => 'single-comment'));
}