| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: mollom.pages.inc,v 1.1.2.16 2010/08/07 02:49:44 dries Exp $ 3 4 /** 5 * @file 6 * Various non-administration page callbacks for the mollom module. 7 */ 8 9 /** 10 * AJAX callback to retrieve a CAPTCHA. 11 * 12 * @param $type 13 * The new CAPTCHA type to retrieve, e.g. 'image' or 'audio'. 14 * @param $session_id 15 * The last known Mollom session id contained in the form. 16 * 17 * @return 18 * A JSON array containing: 19 * - content: The HTML markup for the new CAPTCHA. 20 * - session_id: The Mollom session id for the new CAPTCHA. 21 * 22 * @todo Add error handling. 23 */ 24 function mollom_captcha_js($type, $session_id) { 25 // Extract Mollom session id from form element value. 26 @list($timestamp, $mollom_session_id) = explode('-', $session_id, 2); 27 if (empty($mollom_session_id)) { 28 watchdog('mollom', 'Bogus session id %session.', array('%session' => $session_id), WATCHDOG_WARNING); 29 drupal_json(); 30 exit(); 31 } 32 33 $captcha = mollom_get_captcha($type, array('session_id' => $mollom_session_id)); 34 35 // Update cached session id in the cached $form_state. 36 if (!empty($captcha['response']['session_id'])) { 37 if ($cache = cache_get($mollom_session_id, 'cache_mollom')) { 38 $form_state['mollom'] = $cache->data; 39 $form_state['mollom']['response']['session_id'] = $captcha['response']['session_id']; 40 cache_set($form_state['mollom']['response']['session_id'], $form_state['mollom'], 'cache_mollom', $timestamp + 21600); 41 // After successfully updating the cache, replace the original session id. 42 $mollom_session_id = $captcha['response']['session_id']; 43 } 44 } 45 46 // Return new content and new session_id via JSON. 47 $data = array( 48 'content' => $captcha['markup'], 49 'session_id' => $timestamp . '-' . $mollom_session_id, 50 ); 51 drupal_json($data); 52 exit(); 53 } 54 55 /** 56 * Form builder for report to Mollom form. 57 * 58 * @param $entity 59 * The entity type of the data to report, e.g. 'node' or 'comment'. 60 * @param $id 61 * The entity id the data belongs to. If 'session' is passed as $entity, then 62 * $id is assumed to be a Mollom session_id, as returned by Mollom servers, 63 * which should only be used to report session data that was not stored for an 64 * entity in the database (such as contact form submissions). 65 */ 66 function mollom_report_form(&$form_state, $entity, $id) { 67 $form['entity'] = array( 68 '#type' => 'value', 69 '#value' => $entity, 70 ); 71 $form['id'] = array( 72 '#type' => 'value', 73 '#value' => $id, 74 ); 75 $form['feedback'] = array( 76 '#type' => 'radios', 77 '#title' => t('Optionally report this to Mollom'), 78 '#options' => array( 79 'none' => t("Don't send feedback to Mollom"), 80 'spam' => t('Report as spam or unsolicited advertising'), 81 'profanity' => t('Report as obscene, violent or profane content'), 82 'low-quality' => t('Report as low-quality content or writing'), 83 'unwanted' => t('Report as unwanted, taunting or off-topic content'), 84 ), 85 '#default_value' => 'none', 86 '#description' => t("Mollom is a web service that helps you moderate your site's content: see <a href=\"http://mollom.com\">http://mollom.com</a> for more information. By sending feedback to Mollom, you teach Mollom about the content you like and dislike, allowing Mollom to do a better job helping you moderate your site's content. If you want to report multiple posts at once, you can use Mollom's bulk operations on the content and comment administration pages."), 87 ); 88 89 // @todo "Delete" does not work for reporting mails to Mollom. In D7+, this 90 // form should be used solely for mails, as other entities are reported 91 // through existing delete confirmation forms instead. Perhaps there should 92 // be a dedicated form for reporting mails, as they are not really 93 // compatible with any of the standard processes either way. 94 return confirm_form($form, 95 t('Are you sure you want to delete and report the content as inappropriate?'), 96 isset($_GET['destination']) ? $_GET['destination'] : '<front>', 97 t('This action cannot be undone.'), 98 t('Delete'), t('Cancel') 99 ); 100 } 101 102 /** 103 * Form submit handler for mollom_report_form(). 104 */ 105 function mollom_report_form_submit($form, &$form_state) { 106 if ($form_state['values']['confirm']) { 107 $entity = $form_state['values']['entity']; 108 $id = $form_state['values']['id']; 109 110 // Load the Mollom session data. 111 if ($entity == 'session') { 112 $data = new stdClass; 113 $data->session = $id; 114 } 115 else { 116 $data = mollom_data_load($entity, $id); 117 } 118 119 // Send feedback to Mollom, if we have session data. 120 if (isset($data->session) && isset($form_state['values']['feedback']) && $form_state['values']['feedback'] != 'none') { 121 // @todo Check the actual reponse. 122 _mollom_send_feedback($data->session, $form_state['values']['feedback']); 123 drupal_set_message(t('The content was successfully reported as inappropriate.')); 124 } 125 126 // Delete the content. The callback should take care of proper deletion and 127 // cache clearing on its own. 128 foreach (mollom_form_list() as $form_id => $info) { 129 if (!isset($info['entity']) || $info['entity'] != $entity) { 130 continue; 131 } 132 // If there is a 'report delete callback', invoke it. 133 if (isset($info['report delete callback']) && function_exists($info['report delete callback'])) { 134 $function = $info['report delete callback']; 135 $function($entity, $id); 136 break; 137 } 138 } 139 140 $form_state['redirect'] = '<front>'; 141 } 142 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |