]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
enable confirmation queue
[quix0rs-gnu-social.git] / lib / util.php
index 63fcb5ad851736e41b1c5fd154a9b4336d1cab67..1a0dd07d2628552ab6c2551f33ce95dac3c5342a 100644 (file)
@@ -94,7 +94,8 @@ function common_element_start($tag, $attrs=NULL) {
 
 function common_element_end($tag) {
        global $xw;
-       $xw->endElement();
+       # TODO: switch based on $tag
+       $xw->fullEndElement();
 }
 
 function common_element($tag, $attrs=NULL, $content=NULL) {
@@ -218,7 +219,7 @@ function common_show_footer() {
        common_element_end('div'); # content div
        common_foot_menu();
        common_element_start('div', array('id' => 'footer'));
-       common_element_start('p', 'laconica');
+       common_element_start('div', 'laconica');
        if (common_config('site', 'broughtby')) {
                $instr = _t('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). ');
        } else {
@@ -231,7 +232,7 @@ function common_show_footer() {
                         '(http://www.fsf.org/licensing/licenses/agpl-3.0.html).');
     $output = common_markup_to_html($instr);
     common_raw($output);
-       common_element_end('p');
+       common_element_end('div');
        common_element('img', array('id' => 'cc',
                                                                'src' => $config['license']['image'],
                                                                'alt' => $config['license']['title']));
@@ -392,7 +393,7 @@ function common_textarea($id, $label, $content=NULL, $instructions=NULL) {
                                                                         'cols' => 40,
                                                                         'name' => $id,
                                                                         'id' => $id),
-                                  ($content) ? $content : ' ');
+                                  ($content) ? $content : '');
        if ($instructions) {
                common_element('span', 'input_instructions', $instructions);
        }
@@ -483,6 +484,7 @@ function common_rememberme() {
        common_set_cookie(REMEMBERME,
                                          implode(':', array($rm->user_id, $rm->code)),
                                          time() + REMEMBERME_EXPIRY);
+       return true;
 }
 
 function common_remembered_user() {
@@ -627,6 +629,15 @@ function common_avatar_url($filename) {
        return common_path('avatar/'.$filename);
 }
 
+function common_avatar_display_url($avatar) {
+       $server = common_config('avatar', 'server');
+       if ($server) {
+               return 'http://'.$server.'/'.$avatar->filename;
+       } else {
+               return $avatar->url;
+       }
+}
+
 function common_default_avatar($size) {
        static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
                                                          AVATAR_STREAM_SIZE => 'stream',
@@ -798,17 +809,51 @@ function common_redirect($url, $code=307) {
 }
 
 function common_broadcast_notice($notice, $remote=false) {
-       // XXX: optionally use a queue system like http://code.google.com/p/microapps/wiki/NQDQ
+       if (common_config('queue', 'enabled')) {
+               # Do it later!
+               return common_enqueue_notice($notice);
+       } else {
+               return common_real_broadcast($notice, $remote);
+       }
+}
+
+# Stick the notice on the queue
+
+function common_enqueue_notice($notice) {
+       common_log(LOG_INFO, 'start queueing notice ID = ' . $notice->id);
+       $qi = new Queue_item();
+       $qi->notice_id = $notice->id;
+       $qi->created = DB_DataObject_Cast::dateTime();
+       $result = $qi->insert();
+       if ($result === FALSE) {
+           $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
+           common_log(LOG_ERROR, 'DB error inserting queue item: ' . $last_error->message);
+           return false;
+       }
+       common_log(LOG_INFO, 'complete queueing notice ID = ' . $notice->id);
+       return $result;
+}
+         
+function common_real_broadcast($notice, $remote=false) {
+       $success = true;
        if (!$remote) {
                # Make sure we have the OMB stuff
                require_once(INSTALLDIR.'/lib/omb.php');
-               omb_broadcast_remote_subscribers($notice);
+               $success = omb_broadcast_remote_subscribers($notice);
+               if (!$success) {
+                       common_log(LOG_ERROR, 'Error in OMB broadcast for notice ' . $notice->id);
+               }
+       }
+       if ($success) {
+               require_once(INSTALLDIR.'/lib/jabber.php');
+               $success = jabber_broadcast_notice($notice);
+               if (!$success) {
+                       common_log(LOG_ERROR, 'Error in jabber broadcast for notice ' . $notice->id);
+               }
        }
-       require_once(INSTALLDIR.'/lib/jabber.php');
-       jabber_broadcast_notice($notice);
        // XXX: broadcast notices to SMS
        // XXX: broadcast notices to other IM
-       return true;
+       return $success;
 }
 
 function common_broadcast_profile($profile) {
@@ -829,16 +874,18 @@ function common_notice_form($action=NULL, $content=NULL) {
        $user = common_current_user();
        assert(!is_null($user));
        common_element_start('form', array('id' => 'status_form',
-                                                                          'method' => 'POST',
+                                                                          'method' => 'post',
                                                                           'action' => common_local_url('newnotice')));
        common_element_start('p');
-       common_element('label', array('for' => 'status_update',
+       common_element('label', array('for' => 'status_textarea',
                                                                  'id' => 'status_label'),
                                   _t('What\'s up, ').$user->nickname.'?');
         common_element('span', array('id' => 'counter', 'class' => 'counter'), '140');
        common_element('textarea', array('id' => 'status_textarea',
+                                                                        'cols' => 60,
+                                                                        'rows' => 3,
                                                                         'name' => 'status_textarea'),
-                                  ');
+                                  ($content) ? $content : '');
        if ($action) {
                common_hidden('returnto', $action);
        }