forked from ding2/ding_user
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathding_user_comments.inc
More file actions
89 lines (71 loc) · 2.45 KB
/
ding_user_comments.inc
File metadata and controls
89 lines (71 loc) · 2.45 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
<?php
/**
* @file
* Implements popup for logging in to add comments
*/
/**
* Implements hook_entity_view
* hook is implented to alter the 'log in to add comment' part of comments
* define a new theme for comments if ['comment_forbidden'] is set
**/
function ding_user_entity_view($comment, $type, $view_mode, $langcode ) {
// dpm($comment);
if ( isset($comment->content['links']['comment']['#links']['comment_forbidden']) ) {
$comment->content['links']['comment']['#theme'] = 'ding_user_comment_post_forbidden';
}
}
/**
* Implements hook_theme
*/
function ding_user_theme($existing, $type, $theme, $path) {
return array('ding_user_comment_post_forbidden' =>
array('render element' => 'elements', )
);
}
/**
* get a form for displaying the 'log in' to add comments link
* @return form
*/
function ding_user_comment_forbidden_form() {
$form['submit'] =
array('#type' => 'submit',
'#value' => t('Log in'),
'#ajax' =>
array('callback' => 'ding_user_comment_forbidden_form_callback', ), );
return $form;
}
/**
* Theme comment_post_forbidden (log in to add comments)
*/
function theme_ding_user_comment_post_forbidden($variables) {
$render_array = array();
$form = drupal_get_form('ding_user_comment_forbidden_form');
$class = drupal_html_class('ding_user_comment_forbidden_form');
$render_array['#prefix'] = '<div class="' . $class . '">';
$render_array['#markup'] = drupal_render($form);
$render_array['#suffix'] = '<span>' . t('to add comments') . '</span></div>';
return drupal_render($render_array);
}
/**
* callback for ding_user_comment_forbidden_form form
*/
function ding_user_comment_forbidden_form_callback($form, $form_state) {
global $base_root;
$creds = array('name' => '', 'pass' => '');
$creds = ding_user_get_creds();
$name = isset($creds['name']) ? $creds['name'] : '';
$pass = isset($creds['pass']) ? $creds['pass'] : '';
try{ $success = ding_provider_invoke('user', 'authenticate', $name, $pass); }
catch (DingProviderAuthException $e) {
//do nothing
}
// user sucessfully logged in - reload page
// @TODO .. there must be an easier way to refresh a page -- drupal_reload???
// couldn't find any in Ajax framework commands
ctools_include('ajax');
ctools_add_js('ajax-responder');
$url = $base_root . $form['#action'];
$commands = array();
$commands[] = ctools_ajax_command_redirect($url);
return array('#type' => 'ajax', '#commands' => $commands);
}