/[drupal]/contributions/modules/facebook_status/facebook_status.edit.inc
ViewVC logotype

Contents of /contributions/modules/facebook_status/facebook_status.edit.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Mon May 25 05:59:44 2009 UTC (6 months ago) by icecreamyou
Branch: MAIN
CVS Tags: DRUPAL-6--2-0-BETA4, HEAD
Branch point for: DRUPAL-6--2
File MIME type: text/x-php
MANY API CHANGES!

*Removed slider
_render hook now applies to the status on the update form
JS now loads on all update forms
Better formatting for time
Removed $linked parameter from theme('facebook_status_item')
Removed redundant and deprecated code comments
*Added option to use a textarea instead of a textfield
*Added JavaScript-driven character counting
Improved JavaScript handling of status update form
Changed redundant title of a setting
Status length can now be up to 1000 characters
"status/openapi" changed to "statuses/openapi"
Added "edit" pages
*#425628 Allow input filters on statuses
Added flood control and permissions for using the Open API
*Added ability to post on others' profiles.
Added a delete page (uses edit permissions)
Corrected missing arguments in return value from hook_theme()
Delete users' posts on user deletion
Lots of other minor improvements and bug fixes
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Provides edit/delete status forms.
7 */
8
9 /**
10 * The edit status form.
11 */
12 function _facebook_status_edit(&$form_state, $status) {
13 $size = variable_get('facebook_status_size_long', 40);
14 $maxlength = variable_get('facebook_status_length', 192);
15 $account = user_load(array('uid' => $status->uid));
16 //Because this text will appear exactly as-is in the textfield, we can't use a full check_plain() or filter_xss().
17 $default = str_replace('"', '', $status->status);
18
19 if (variable_get('facebook_status_concat', 1)) {
20 $prefix = '<span class="facebook_status_prefix">'. t('!fbss_prefix_name ', array('!fbss_prefix_name' => theme('username', $account))) .'&nbsp;</span>';
21 }
22 else {
23 $prefix = '';
24 }
25
26 $path = drupal_get_path('module', 'facebook_status');
27 drupal_add_js($path .'/facebook_status.js');
28 drupal_add_css($path .'/facebook_status.css');
29 drupal_add_js(array('facebook_status' => array(
30 'maxlength' => $maxlength,
31 'ttype' => variable_get('facebook_status_type', 'textfield'))
32 ), 'setting');
33 //Don't show the slider; we'd have to do a custom version of theme('facebook_status_item').
34 $slider = '';
35 $form = array('#cache' => TRUE);
36 $form['slider'] = array(
37 '#prefix' => '<span id="facebook_status_replace">',
38 '#value' => '<span id="facebook_status_slider">'. $slider .'</span>',
39 );
40 $form['status'] = array(
41 '#type' => variable_get('facebook_status_type', 'textfield'),
42 '#field_prefix' => $prefix,
43 '#size' => $size,
44 '#cols' => $size,
45 '#rows' => 2,
46 '#maxlength' => $maxlength,
47 '#default_value' => $default,
48 '#attributes' => array('class' => 'facebook_status_text'),
49 '#suffix' => '</span>',
50 '#resizable' => FALSE,
51 );
52 $form['sid'] = array(
53 '#type' => 'value',
54 '#value' => $status->sid,
55 );
56 $form['fbss-submit'] = array(
57 '#type' => 'submit',
58 '#value' => t('Save'),
59 '#attributes' => array('class' => 'facebook_status_submit'),
60 );
61 $form['chars'] = array(
62 '#value' => '<span id="facebook_status_chars">'. t('%chars characters allowed', array('%chars' => $maxlength)) .'</span>',
63 );
64 //@todo: This is bad. It should be in the CSS but that doesn't seem to be working.
65 $form['#attributes'] = array('style' => 'margin-bottom: 0;');
66 return $form;
67 }
68
69 /**
70 * Validate function for the status update form.
71 */
72 function _facebook_status_edit_validate($form, &$form_state) {
73 $maxlen = variable_get('facebook_status_length', 192);
74 if (drupal_strlen($form_state['values']['status']) > $maxlen) {
75 form_set_error('status', t('The status must be no longer than %chars characters.', array('%chars' => $maxlen)));
76 }
77 }
78
79 /**
80 * Submit function for the status update form.
81 */
82 function _facebook_status_edit_submit($form, &$form_state) {
83 $status_old = facebook_status_load($form_state['values']['sid']);
84 $account = user_load(array('uid' => $status_old->uid));
85 $new_status = trim($form_state['values']['status']);
86
87 global $user;
88 //If the user clears the status, set the time to zero so the new, blank status will not show up as new in lists.
89 $time = time();
90 if ($new_status === '') {
91 $time = 0;
92 }
93 //Pretend to have set a new status if the submitted status is exactly the same as the old one.
94 if ($new_status != $status_old->status && $account->uid) {
95 $sql = "UPDATE {facebook_status} SET status = '%s', status_time = %d WHERE sid = %d ORDER BY sid DESC";
96 db_query($sql, $new_status, $time, $status_old->sid);
97 //Invokes hook_facebook_status_save($status_owner_object, &$status, $sid).
98 module_invoke_all('facebook_status_save', $account, $new_status, $status_old->sid);
99 }
100
101 if ($_GET['destination']) {
102 $form_state['redirect'] = array($_GET['destination']);
103 }
104 else {
105 $form_state['redirect'] = array('share-status');
106 }
107 drupal_set_message(t('Status has been successfully edited.'));
108 }
109
110 /**
111 * The delete status confirmation form.
112 */
113 function _facebook_status_delete(&$form_state, $status) {
114 $form['infotext'] = array('#value' => t('Are you sure you want to permanently delete the status %status?', array('%status' => $status->status)));
115 $form['confirm'] = array(
116 '#type' => 'submit',
117 '#value' => t('Confirm'),
118 '#submit' => array('_facebook_status_delete_confirm'),
119 );
120 $form['back'] = array(
121 '#type' => 'submit',
122 '#value' => t('Cancel'),
123 '#submit' => array('_facebook_status_delete_cancel'),
124 );
125 $form['status'] = array(
126 '#type' => 'value',
127 '#value' => $status->sid,
128 );
129 return $form;
130 }
131
132 /**
133 * Deletes a status.
134 */
135 function _facebook_status_delete_confirm($form, &$form_state) {
136 facebook_status_delete_status($form_state['values']['status']);
137 drupal_set_message(t('Status deleted.'));
138 }
139
140 /**
141 * Cancels status deletion.
142 */
143 function _facebook_status_delete_cancel($form, &$form_state) {
144 if ($_GET['destination']) {
145 $form_state['redirect'] = $_GET['destination'];
146 }
147 else {
148 $form_state['redirect'] = 'user';
149 }
150 }

  ViewVC Help
Powered by ViewVC 1.1.2