mollom.flag.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. <?php
  2. /**
  3. * @file
  4. * Flag as inappropriate page callbacks for Mollom module.
  5. */
  6. /**
  7. * Helper function to retrieve public reasons to flag content as inappropriate.
  8. * PHP does not allow defining these as a constant but at least
  9. * they can be defined once for code maintenance purposes.
  10. */
  11. function _mollom_flag_reasons() {
  12. return array(
  13. 'spam' => t('Spam, unsolicited advertising'),
  14. 'profanity' => t('Obscene, abusive, profane language'),
  15. 'unwanted' => t('Off-topic'),
  16. );
  17. }
  18. /**
  19. * Helper function to retrieve the flag counts for a particular entity.
  20. *
  21. * @param $entity
  22. * The type of entity to retrieve counts for.
  23. * @param id
  24. * The id of the entity to retrieve counts for.
  25. *
  26. */
  27. function _mollom_flag_entity_count($entity, $id) {
  28. // Get the data for this entity.
  29. $data = mollom_data_load($entity, $id);
  30. // default values
  31. $totals = array(
  32. 'spam' => 0,
  33. 'profanity' => 0,
  34. 'unwanted' => 0,
  35. 'quality' => 0,
  36. 'total' => 0,
  37. );
  38. // Update the totals for all reasons.
  39. if (!empty($data)) {
  40. $totals['spam'] = $data->flags_spam;
  41. $totals['profanity'] = $data->flags_profanity;
  42. $totals['unwanted'] = $data->flags_unwanted;
  43. $totals['quality'] = $data->flags_quality;
  44. $totals['total'] = $data->flags_spam + $data->flags_profanity + $data->flags_unwanted + $data->flags_quality;
  45. arsort($totals);
  46. }
  47. return $totals;
  48. }
  49. /**
  50. * Adds Mollom's flag as inappropriate links to entities.
  51. * Called from hook_entity_view().
  52. */
  53. function mollom_flag_entity_view($entity, $type, $view_mode, $langcode) {
  54. if (!_mollom_flag_access($type, $entity)) {
  55. return;
  56. }
  57. // Define the internal source for feedback.
  58. $source = 'mollom_flag_entity_view_' . $type . '_' . $view_mode;
  59. list($id, $vid, $bundle) = entity_extract_ids($type, $entity);
  60. $dialog = mollom_flag_dialog_check();
  61. if (isset($dialog['link prepare callback'])) {
  62. $function = $dialog['link prepare callback'];
  63. $link_attributes = $function();
  64. }
  65. else {
  66. // Add Mollom reporting link to the existing comment link structure.
  67. $entity->content['#pre_render'][] = 'mollom_flag_entity_view_prerender';
  68. $link_attributes = array('class' => array('use-ajax', 'mollom-flag'));
  69. $attached = array(
  70. 'library' => array(
  71. array('mollom', 'flag'),
  72. ),
  73. );
  74. }
  75. $link_attributes += array(
  76. 'id' => "mollom_$type$id",
  77. );
  78. $links = array(
  79. 'mollom-flag' => array(
  80. 'title' => t('report'),
  81. 'href' => "mollom/flag/nojs/$type/$id/$source",
  82. 'html' => TRUE,
  83. 'attributes' => $link_attributes,
  84. ),
  85. );
  86. $entity->content['links']['mollom'] = array(
  87. '#theme' => 'links__comment__mollom',
  88. '#links' => $links,
  89. '#attributes' => array('class' => array('links', 'inline')),
  90. );
  91. if (isset($attached)) {
  92. $entity->content['links']['#attached'] = $attached;
  93. }
  94. }
  95. /**
  96. * Pre-render callback for entities that can be flagged as inappropriate.
  97. */
  98. function mollom_flag_entity_view_prerender($element) {
  99. if (!isset($element['#prefix'])) {
  100. $element['#prefix'] = '';
  101. }
  102. if (!isset($element['#suffix'])) {
  103. $element['#suffix'] = '';
  104. }
  105. // Add a wrapping element that can be targeted by the Ajax framework.
  106. $element['#prefix'] .= '<div class="mollom-flag-content mollom-flag-content-' . $element['#entity_type'] . '">';
  107. $element['#suffix'] .= '</div>';
  108. return $element;
  109. }
  110. /**
  111. * Callback handler for public users to report content as inappropriate.
  112. * This is step one of the two-step process. The user can now indicate the
  113. * reason for the report as one of spam, quality, profanity, or unwelcome.
  114. *
  115. * @param $type
  116. * The request type submitted, one of "ajax" or "nojs".
  117. * @param $entity
  118. * The type of entity that is being reported.
  119. * @param $id
  120. * The entity identifier that is being reported.
  121. * @param $source
  122. * The optional internal source to be submitted along with feedback.
  123. */
  124. function _mollom_flag($type, $entity, $id, $source = NULL) {
  125. $detail = FALSE;
  126. if ($type === 'nojs' || $_SERVER['REQUEST_METHOD'] !== 'POST') {
  127. $detail = TRUE;
  128. }
  129. $form = drupal_get_form('mollom_flag_reason_form', $entity, $id, $detail, $source);
  130. // If not submitted via Ajax post, then return a plain Drupal form page.
  131. if ($detail) {
  132. return $form;
  133. }
  134. $dialog = mollom_flag_dialog_check();
  135. if (isset($dialog['display form callback'])) {
  136. $function = $dialog['display form callback'];
  137. return $function($form, t('Report'));
  138. }
  139. // Deliver via custom Mollom dialog.
  140. $commands = array();
  141. $formHtml = '<div class="mollom-flag-container" role="dialog" aria-label="' . t('Report') . '">' . render($form) . '</div>';
  142. $commands[] = ajax_command_prepend(".mollom-flag-content-$entity:has(#mollom_$entity$id)",$formHtml);
  143. $page = array('#type' => 'ajax', '#commands' => $commands);
  144. ajax_deliver($page);
  145. }
  146. /**
  147. * Form builder for flag as inappropriate reporting.
  148. * This is used in both JavaScript enabled and disabled environments.
  149. *
  150. * @param $entity
  151. * The type of entity that is being reported.
  152. * @param $id
  153. * The entity id that is being reported.
  154. * @param $detail
  155. * True if the form should return details of the entity to report.
  156. * False to leave entity details out of the form display.
  157. * @param $source
  158. * The internal source to be submitted along with feedback.
  159. */
  160. function mollom_flag_reason_form($form, &$form_state, $entity, $id, $detail, $source = NULL) {
  161. $form['#prefix'] = "<div id=\"mollom-flag-$entity-$id\" class=\"mollom-flag-reasons\">";
  162. $form['#suffix'] = '</div>';
  163. // If the user is able to moderate content, then inform them that this will not
  164. // delete the content as they might expect from standard moderation.
  165. if (mollom_report_access($entity, $id)) {
  166. $form['moderation_notice'] = array(
  167. '#markup' => '<p>' . t('Admin mode enabled: feedback will be sent to Mollom.') . '<br />' . t('You will still need to remove content through standard means.') . '</p>',
  168. );
  169. $form['feedback_type'] = array(
  170. '#type' => 'value',
  171. '#value' => 'moderate',
  172. );
  173. }
  174. else {
  175. $form['feedback_type'] = array(
  176. '#type' => 'value',
  177. '#value' => 'flag',
  178. );
  179. }
  180. // Add content summary if details should be shown.
  181. $form['detail'] = array(
  182. '#type' => 'hidden',
  183. '#value' => $detail,
  184. );
  185. if ($detail !== FALSE) {
  186. $entity_objects = entity_load($entity,array($id));
  187. $entity_subject = isset($entity_objects[$id]->subject) ? $entity_objects[$id]->subject : $entity_objects[$id]->title;
  188. $form['detailset'] = array(
  189. '#type' => 'fieldset',
  190. '#title' => t('Reporting'),
  191. '#tree' => TRUE,
  192. );
  193. $form['detailset']['detail'] = array(
  194. '#markup' => '<div class="mollom-report-content">' . filter_xss($entity_subject) . '</div>',
  195. );
  196. }
  197. $form['reason'] = array(
  198. '#type' => 'radios',
  199. '#title' => t('Why are you reporting this content?'),
  200. '#options' => _mollom_flag_reasons(),
  201. '#default_value' => 'spam',
  202. '#required' => TRUE,
  203. );
  204. $form['entity'] = array(
  205. '#type' => 'value',
  206. '#value' => $entity,
  207. );
  208. $form['id'] = array(
  209. '#type' => 'value',
  210. '#value' => $id,
  211. );
  212. $form['source'] = array(
  213. '#type' => 'value',
  214. '#value' => $source,
  215. );
  216. $form['actions'] = array(
  217. '#type' => 'actions',
  218. );
  219. $form['actions']['submit'] = array(
  220. '#type' => 'submit',
  221. '#value' => t('Submit report'),
  222. '#ajax' => array(
  223. 'callback' => 'mollom_flag_reason_form_submit_ajax',
  224. 'wrapper' => "mollom-flag-$entity-$id",
  225. ),
  226. );
  227. // Override the cancel link to handle close actions.
  228. $form['actions']['cancel'] = array(
  229. '#type' => 'submit',
  230. '#value' => t('Cancel'),
  231. '#submit' => array('mollom_flag_reason_form_cancel'),
  232. '#ajax' => array(
  233. 'callback' => 'mollom_flag_reason_form_cancel_ajax',
  234. 'wrapper' => "mollom-flag-$entity-$id",
  235. ),
  236. );
  237. return $form;
  238. }
  239. /**
  240. * Form submit handler for mollom_flag_reason_form().
  241. */
  242. function mollom_flag_reason_form_submit($form, &$form_state) {
  243. $entity = $form_state['values']['entity'];
  244. $id = $form_state['values']['id'];
  245. $feedback_type = $form_state['values']['feedback_type'];
  246. $reason = $form_state['values']['reason'];
  247. $source = $form_state['values']['source'];
  248. $count_field = 'flags_' . $reason;
  249. $data = mollom_data_load($entity, $id);
  250. // We can only send data to Mollom that has been processed.
  251. if (!empty($data)) {
  252. _mollom_send_feedback($data, $reason, $feedback_type, $source);
  253. $data->$count_field += 1;
  254. mollom_data_save($data);
  255. }
  256. else {
  257. // Save the minimum entity data to be able to track reporting counts.
  258. $data = new stdClass();
  259. $data->entity = $entity;
  260. $data->id = $id;
  261. $data->$count_field = 1;
  262. mollom_data_save($data);
  263. }
  264. // If the form was shown on its own page with detail then display a standard
  265. // Drupal message style. Forms shown in a dialog handle confirmation
  266. // separately.
  267. if ($form_state['values']['detail']) {
  268. drupal_set_message(t('Thank you for your feedback.'));
  269. }
  270. }
  271. /**
  272. * Form cancellation handler for mollom_flag_reason_form().
  273. */
  274. function mollom_flag_reason_form_cancel($form, &$form_state) {
  275. $url = isset($form_state['values']['destination']) ? $form_state['values']['destination'] : '';
  276. $form_state['redirect'] = $url;
  277. }
  278. /**
  279. * Form ajax callback handler for mollom_flag_reason_form().
  280. */
  281. function mollom_flag_reason_form_submit_ajax($form, &$form_state) {
  282. $dialog = mollom_flag_dialog_check();
  283. if (isset($dialog['submit form callback'])) {
  284. $function = $dialog['submit form callback'];
  285. return $function($form, $form_state);
  286. }
  287. // Custom Mollom dialog submission handler.
  288. $entity = $form_state['values']['entity'];
  289. $id = $form_state['values']['id'];
  290. // JavaScript behaviors handle closing this window so no need to provide
  291. // a close link/button.
  292. $commands = array();
  293. $confirmHtml = '<span class="mollom-flag-confirm">' . t('Thank you for your feedback.') . '</span>';
  294. $commands[] = ajax_command_replace("#mollom-flag-$entity-$id form",$confirmHtml);
  295. return array('#type' => 'ajax', '#commands' => $commands);
  296. }
  297. /**
  298. * Form cancellation ajax callback handler for mollom_flag_reason_form().
  299. */
  300. function mollom_flag_reason_form_cancel_ajax($form, &$form_state) {
  301. $dialog = mollom_flag_dialog_check();
  302. if (isset($dialog['close callback'])) {
  303. $function = $dialog['close callback'];
  304. return $function();
  305. }
  306. // Custom Mollom dialog cancellation handler.
  307. $entity = $form_state['values']['entity'];
  308. $id = $form_state['values']['id'];
  309. $commands = array();
  310. $commands[] = ajax_command_remove(".mollom-flag-container:has(#mollom-flag-$entity-$id)");
  311. return array('#type' => 'ajax', '#commands' => $commands);
  312. }
  313. /**
  314. * Helper function to add row to node and comment admin tables for
  315. * flag as inappropriate counts.
  316. *
  317. * @param $type
  318. * The entity type that is being shown.
  319. * @param $headers
  320. * A reference to the headers associative array.
  321. * @param $rows
  322. * A reference to the row associate array
  323. *
  324. * @see mollom_form_node_admin_content_alter
  325. * @see mollom_form_comment_admin_overview_alter
  326. */
  327. function _mollom_table_add_flag_counts($type, &$headers, &$rows) {
  328. if (!mollom_flag_entity_type_access($type)) {
  329. return;
  330. }
  331. // Add the header for the flag as inappropriate column.
  332. $headers['flagged'] = array(
  333. 'data' => t('Flagged'),
  334. 'field' => 'flagged',
  335. );
  336. // Add the flag data to each row
  337. $flags = mollom_entity_type_load($type);
  338. foreach($rows as $id => $data) {
  339. $count = 0;
  340. if (isset($flags[$id])) {
  341. $count = $flags[$id]->flags_spam + $flags[$id]->flags_profanity + $flags[$id]->flags_quality + $flags[$id]->flags_unwanted;
  342. }
  343. if ($count > 0) {
  344. $rows[$id]['flagged'] = array(
  345. 'data' => array(
  346. '#type' => 'link',
  347. '#title' => $count,
  348. '#href' => "$type/$id/edit",
  349. '#options' => array(
  350. 'query' => array('mollom_flag_details' => 1),
  351. 'fragment' => 'mollom-flag-details',
  352. ),
  353. ),
  354. 'sort' => $count,
  355. );
  356. } else {
  357. $rows[$id]['flagged'] = $count;
  358. }
  359. }
  360. // Handle custom sorting requirements if sorting by the new column.
  361. $q = drupal_get_query_parameters();
  362. if (isset($q['order']) && $q['order'] == 'Flagged') {
  363. if (isset($q['sort']) && $q['sort'] === 'desc') {
  364. uasort($rows, '_mollom_compare_flag_count_desc');
  365. }
  366. else {
  367. uasort($rows, '_mollom_compare_flag_count');
  368. }
  369. }
  370. }
  371. /**
  372. * Helper comparison function to sort data by flag count ascending.
  373. * @see _mollom_table_add_flag_counts
  374. */
  375. function _mollom_compare_flag_count($a, $b) {
  376. return $a['flagged']['sort'] - $b['flagged']['sort'];
  377. }
  378. /**
  379. * Helper comparison function to sort data by flag count descending.
  380. * @see _mollom_table_add_flag_counts
  381. */
  382. function _mollom_compare_flag_count_desc($a, $b) {
  383. return $b['flagged']['sort'] - $a['flagged']['sort'];
  384. }
  385. /**
  386. * Adds flag data to comment edit form for administrators.
  387. * Called from hook_form_FORMID_alter().
  388. */
  389. function mollom_flag_comment_form_alter(&$form, &$form_state, $form_id) {
  390. // Make sure we are editing a comment.
  391. $comment = $form_state['comment'];
  392. if (empty($comment) || empty($form_state['comment']->cid)) {
  393. return;
  394. }
  395. // Make sure the user is an admin.
  396. if (!user_access('administer comments')) {
  397. return;
  398. }
  399. // Make sure this form is protected by Mollom.
  400. $forms = mollom_form_cache();
  401. if (!isset($forms['protected'][$form_id])) {
  402. return;
  403. }
  404. // Find out if flag as inappropriate is enabled for this entity.
  405. $forms = mollom_form_list();
  406. $info = $forms[$form_id];
  407. if (!empty($info) && isset($info['entity report access callback'])) {
  408. $function = $info['entity report access callback'];
  409. if (!$function($comment)) {
  410. return;
  411. }
  412. }
  413. else {
  414. return;
  415. }
  416. // Get the flag counts for this comment.
  417. $totals = _mollom_flag_entity_count('comment', $comment->cid);
  418. $output = array();
  419. $markup = $totals['total'] . ' ' . t('total');
  420. if ($totals['total'] > 0) {
  421. $reasons = _mollom_flag_reasons();
  422. foreach($totals as $reason=>$total) {
  423. if ($total > 0 && $reason !== 'total') {
  424. $output[] = $total . ': ' . $reasons[$reason];
  425. }
  426. }
  427. $markup = theme('item_list', array(
  428. 'items' => $output,
  429. 'attributes' => array('class' => 'form-item'),
  430. )
  431. );
  432. }
  433. $form['author']['mollom_flags'] = array(
  434. '#type' => 'item',
  435. '#title' => t('User flags'),
  436. '#markup' => $markup,
  437. );
  438. // Expand the admin fieldset if requested.
  439. $params = drupal_get_query_parameters();
  440. if (!empty($params['mollom_flag_details'])) {
  441. $form['author']['#collapsed'] = FALSE;
  442. }
  443. }
  444. /**
  445. * Add flag details to a node edit form.
  446. *
  447. * @see mollom_form_node_form_alter
  448. */
  449. function mollom_flag_node_form_alter(&$form, &$form_state, $form_id) {
  450. $node = $form_state['node'];
  451. // Make sure this is a node edit form.
  452. if (!isset($node->nid) || isset($node->is_new)) {
  453. return;
  454. }
  455. $params = drupal_get_query_parameters();
  456. // Node options for administrators
  457. $form['mollom_flags'] = array(
  458. '#type' => 'fieldset',
  459. '#access' => user_access('administer mollom') && mollom_flag_entity_type_access('node'),
  460. '#title' => t('User flags'),
  461. '#collapsible' => TRUE,
  462. '#collapsed' => empty($params['mollom_flag_details']) ? TRUE : FALSE,
  463. '#group' => 'additional_settings',
  464. '#weight' => 100,
  465. );
  466. $totals = _mollom_flag_entity_count('node', $node->nid);
  467. if ($totals['total'] == 0) {
  468. $form['mollom_flags']['details'] = array(
  469. '#markup' => t('This content has not been flagged by users as inappropriate.'),
  470. );
  471. }
  472. else {
  473. $reasons = _mollom_flag_reasons();
  474. $output = array();
  475. foreach($totals as $reason=>$flag_count) {
  476. if ($flag_count > 0 && $reason !== 'total') {
  477. $output[] = $flag_count . ': ' . $reasons[$reason];
  478. }
  479. }
  480. $form['mollom_flags']['details'] = array(
  481. '#title' => format_plural($totals['total'], 'Flagged by users 1 time.', 'Flagged by users @count times.'),
  482. '#items' => $output,
  483. '#theme' => 'item_list',
  484. '#type' => 'ul',
  485. '#attributes' => array('id' => 'mollom-flag-details'),
  486. );
  487. }
  488. }
  489. /**
  490. * Callback to show the flag details for a particular entity.
  491. *
  492. * @param $type
  493. * The page callback type, one of "nojs" or "ajax"
  494. * @param $entity
  495. * The type of entity to show details for.
  496. * @param $id
  497. * The id for the entity to show details for.
  498. */
  499. function mollom_flag_details($type, $entity, $id) {
  500. $detail = FALSE;
  501. if ($type === 'nojs' || $_SERVER['REQUEST_METHOD'] !== 'POST') {
  502. $links = array();
  503. $links[] = l(t('Home'), NULL);
  504. $links[] = l(t('Administration'), 'admin');
  505. $links[] = l(t('Content'), 'admin/content');
  506. $links[] = l(ucfirst($entity), "admin/content/$entity");
  507. drupal_set_breadcrumb($links);
  508. $detail = TRUE;
  509. }
  510. // Get the flag counts for this entity.
  511. $totals = _mollom_flag_entity_count($entity, $id);
  512. $list_data = array();
  513. foreach($totals as $reason => $flag_count) {
  514. if ($flag_count > 0 && $reason !== 'total') {
  515. $display = $reasons[$reason];
  516. $list_data[] = "$flag_count: $display";
  517. }
  518. }
  519. if ($detail) {
  520. $entity_objects = entity_load($entity,array($id));
  521. $entity_subject = isset($entity_objects[$id]->subject) ? $entity_objects[$id]->subject : $entity_objects[$id]->title;
  522. $output = '<fieldset>';
  523. $output .= '<legend>' . t('Flagged: ') . $entity . '</legend>';
  524. $output .= '<div class="fieldset-wrapper">' . filter_xss($entity_subject) . '</div>';
  525. $output .= '</fieldset>';
  526. $output .= theme('item_list', array(
  527. 'type' => 'ul',
  528. 'items' => $list_data,
  529. ));
  530. $output .= '</div>';
  531. return $output;
  532. }
  533. else {
  534. $output = t('Flag details:') . '\n';
  535. foreach($list_data as $item) {
  536. $output .= " - $item\n";
  537. }
  538. $commands = array();
  539. $commands[] = ajax_command_alert($output);
  540. $page = array('#type' => 'ajax', '#commands' => $commands);
  541. ajax_deliver($page);
  542. }
  543. }
  544. /**
  545. * Defines the integrated dialog modules.
  546. *
  547. * A dialog implementation may provide one or more of the callbacks in order to
  548. * affect the dialog output. The hooks needed will vary by dialog
  549. * implementation. If a callback is not found for a particular step in the
  550. * process, the default Mollom functionality will be used.
  551. *
  552. * The following information can be set:
  553. * - title: (required) the title of the dialog solution that is displayed
  554. * to site administrator within the advanced configuration settings area.
  555. * - link prepare callback: callback function to prepare links to use the dialog
  556. * solution from hook_entity_view. This callback returns an array of
  557. * classes for any links that should be opened in the dialog solution.
  558. * - display form callback: callback function to open a form in a new dialog.
  559. * This callback receives the form to display and the title for the dialog.
  560. * - close callback: callback to close the dialog window
  561. *
  562. * The site administrator can select to use one of the following in the
  563. * Mollom advanced settings if the module is installed and enabled for their
  564. * site.
  565. *
  566. * @todo: Move this into a hook implementation to allow others to extend.
  567. */
  568. function mollom_flag_dialog_info() {
  569. $modules = array(
  570. 'ctools' => array(
  571. 'title' => 'CTools (used by CTools Automodal and Modal Forms)',
  572. 'link prepare callback' => 'mollom_ctools_link_prepare',
  573. 'display form callback' => 'mollom_ctools_display_form',
  574. 'close callback' => 'mollom_ctools_close',
  575. )
  576. );
  577. return $modules;
  578. }
  579. /**
  580. * Checks to see what dialog option to use based on the user's configuration.
  581. *
  582. * @return mixed
  583. * Returns an array of dialog information for the selected dialog or FALSE
  584. * if the Mollom custom dialog should be used.
  585. *
  586. * @see mollom_flag_dialog_info()
  587. */
  588. function mollom_flag_dialog_check() {
  589. // Return dialog information for dialog selected in settings if it is
  590. // still enabled.
  591. $modules = mollom_flag_dialog_info();
  592. $configured_dialog = variable_get('mollom_fai_dialog', '');
  593. if (isset($modules[$configured_dialog]) && module_exists($configured_dialog)) {
  594. return $modules[$configured_dialog];
  595. }
  596. return FALSE;
  597. }
  598. /**
  599. * Callback handler for setting up links to use ctools.
  600. */
  601. function mollom_ctools_link_prepare() {
  602. module_load_include('module', 'ctools', 'ctools');
  603. ctools_include('modal');
  604. ctools_modal_add_js();
  605. return array(
  606. 'class' => 'ctools-use-modal'
  607. );
  608. }
  609. /**
  610. * Callback handler for public users to report content as inappropriate using
  611. * ctools modal dialog.
  612. *
  613. * @param $form
  614. * The form to display within the dialog.
  615. * @param $title
  616. * The title of the dialog window.
  617. */
  618. function mollom_ctools_display_form($form, $title) {
  619. // Utilize existing ctools constructs.
  620. module_load_include('module', 'ctools', 'ctools');
  621. ctools_include('modal');
  622. $output = drupal_render($form);
  623. $form_state = array(
  624. 'title' => $title,
  625. 'ajax' => TRUE,
  626. );
  627. $commands = ctools_modal_form_render($form_state, $output);
  628. $page = array('#type' => 'ajax', '#commands' => $commands);
  629. ajax_deliver($page);
  630. }
  631. /**
  632. * Ctools enabled form cancellation ajax callback handler for
  633. * mollom_flag_reason_form().
  634. */
  635. function mollom_ctools_close() {
  636. module_load_include('module', 'ctools', 'ctools');
  637. ctools_include('modal');
  638. $commands[] = ctools_modal_command_dismiss();
  639. return array('#type' => 'ajax', '#commands' => $commands);
  640. }