' . ' ' . t('Post to Red') . ''; } } function redred_settings_post ($a,$post) { if(! local_channel()) return; // don't check redred settings if redred submit button is not clicked if (! x($_POST,'redred-submit')) return; $channel = $a->get_channel(); // Don't let somebody post to their self channel. Since we aren't passing message-id this would be very very bad. if(! trim($_POST['redred_channel'])) { notice( t('Channel is required.') . EOL); return; } if($channel['channel_address'] === trim($_POST['redred_channel'])) { notice( t('Invalid channel.') . EOL); return; } set_pconfig(local_channel(), 'redred', 'baseapi', trim($_POST['redred_baseapi'])); set_pconfig(local_channel(), 'redred', 'username', trim($_POST['redred_username'])); set_pconfig(local_channel(), 'redred', 'password', z_obscure(trim($_POST['redred_password']))); set_pconfig(local_channel(), 'redred', 'channel', trim($_POST['redred_channel'])); set_pconfig(local_channel(), 'redred', 'post', intval($_POST['redred_enable'])); set_pconfig(local_channel(), 'redred', 'post_by_default', intval($_POST['redred_default'])); info( t('redred Settings saved.') . EOL); } function redred_settings(&$a,&$s) { if(! local_channel()) return; //head_add_css('/addon/redred/redred.css'); $api = get_pconfig(local_channel(), 'redred', 'baseapi'); $username = get_pconfig(local_channel(), 'redred', 'username' ); $password = z_unobscure(get_pconfig(local_channel(), 'redred', 'password' )); $channel = get_pconfig(local_channel(), 'redred', 'channel' ); $enabled = get_pconfig(local_channel(), 'redred', 'post'); $checked = (($enabled) ? 1 : false); $defenabled = get_pconfig(local_channel(),'redred','post_by_default'); $defchecked = (($defenabled) ? 1 : false); $sc .= replace_macros(get_markup_template('field_checkbox.tpl'), array( '$field' => array('redred_enable', t('Allow posting to Red Channel'), $checked, '', array(t('No'),t('Yes'))), )); $sc .= replace_macros(get_markup_template('field_checkbox.tpl'), array( '$field' => array('redred_default', t('Send public postings to Red by default'), $defchecked, '', array(t('No'),t('Yes'))), )); $sc .= replace_macros(get_markup_template('field_input.tpl'), array( '$field' => array('redred_baseapi', t('Red API Path'), $api, t('https://{sitename}/api')) )); $sc .= replace_macros(get_markup_template('field_input.tpl'), array( '$field' => array('redred_username', t('Red login name'), $username, t('Email')) )); $sc .= replace_macros(get_markup_template('field_input.tpl'), array( '$field' => array('redred_channel', t('Red channel name'), $channel, t('Nickname')) )); $sc .= replace_macros(get_markup_template('field_password.tpl'), array( '$field' => array('redred_password', t('Red password'), $password, '') )); $s .= replace_macros(get_markup_template('generic_addon_settings.tpl'), array( '$addon' => array('redred', '' . t('Red to Red Post Settings'), '', t('Submit')), '$content' => $sc )); } function redred_post_local(&$a,&$b) { if($b['created'] != $b['edited']) return; if(! perm_is_allowed($b['uid'],'','view_stream')) return; if((local_channel()) && (local_channel() == $b['uid']) && (! $b['item_private'])) { $redred_post = get_pconfig(local_channel(),'redred','post'); $redred_enable = (($redred_post && x($_REQUEST,'redred_enable')) ? intval($_REQUEST['redred_enable']) : 0); // if API is used, default to the chosen settings if($_REQUEST['api_source'] && intval(get_pconfig(local_channel(),'redred','post_by_default'))) $redred_enable = 1; if(! $redred_enable) return; if(strlen($b['postopts'])) $b['postopts'] .= ','; $b['postopts'] .= 'redred'; } } function redred_post_hook(&$a,&$b) { /** * Post to Red */ // for now, just top level posts. if($b['mid'] != $b['parent_mid']) return; if((! is_item_normal($b)) || $b['item_private'] || ($b['created'] !== $b['edited'])) return; if(! perm_is_allowed($b['uid'],'','view_stream')) return; if(! strstr($b['postopts'],'redred')) return; logger('Red-to-Red post invoked'); load_pconfig($b['uid'], 'redred'); $api = get_pconfig($b['uid'], 'redred', 'baseapi'); if(substr($api,-1,1) != '/') $api .= '/'; $username = get_pconfig($b['uid'], 'redred', 'username'); $password = z_unobscure(get_pconfig($b['uid'], 'redred', 'password')); $channel = get_pconfig($b['uid'], 'redred', 'channel'); $msg = $b['body']; $postdata = array('status' => $b['body'], 'title' => $b['title'], 'channel' => $channel); if(strlen($b['body'])) { $ret = z_post_url($api . 'statuses/update', $postdata, 0, array('http_auth' => $username . ':' . $password)); if($ret['success']) logger('redred: returns: ' . print_r($ret['body'],true)); else logger('redred: z_post_url failed: ' . print_r($ret['debug'],true)); } }