コード例 #1
0
ファイル: Pconfig.php プロジェクト: BlaBlaNet/hubzilla
 function pconfig_form($cat, $k)
 {
     $o = '<form action="pconfig" method="post" >';
     $o .= '<input type="hidden" name="form_security_token" value="' . get_form_security_token('pconfig') . '" />';
     $v = get_pconfig(local_channel(), $cat, $k);
     if (strpos($k, 'password') !== false) {
         $v = z_unobscure($v);
     }
     $o .= '<input type="hidden" name="cat" value="' . $cat . '" />';
     $o .= '<input type="hidden" name="k" value="' . $k . '" />';
     if (strpos($v, "\n")) {
         $o .= '<textarea name="v" >' . escape_tags($v) . '</textarea>';
     } else {
         $o .= '<input type="text" name="v" value="' . escape_tags($v) . '" />';
     }
     $o .= EOL . EOL;
     $o .= '<input type="submit" name="submit" value="' . t('Submit') . '" />';
     $o .= '</form>';
     return $o;
 }
コード例 #2
0
ファイル: dwpost.php プロジェクト: phellmes/hubzilla-addons
function dwpost_send(&$a, &$b)
{
    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'], 'dwpost')) {
        return;
    }
    if ($b['parent'] != $b['id']) {
        return;
    }
    // dreamwidth post in the LJ user's timezone.
    // Hopefully the person's Friendica account
    // will be set to the same thing.
    $tz = 'UTC';
    $x = q("select channel_timezone from channel where channel_id = %d limit 1", intval($b['uid']));
    if ($x && strlen($x[0]['channel_timezone'])) {
        $tz = $x[0]['channel_timezone'];
    }
    $dw_username = get_pconfig($b['uid'], 'dwpost', 'dw_username');
    $dw_password = z_unobscure(get_pconfig($b['uid'], 'dwpost', 'dw_password'));
    $dw_blog = 'http://www.dreamwidth.org/interface/xmlrpc';
    if ($dw_username && $dw_password && $dw_blog) {
        require_once 'include/bbcode.php';
        require_once 'include/datetime.php';
        $title = $b['title'];
        $post = bbcode($b['body']);
        $post = xmlify($post);
        $tags = dwpost_get_tags($b['tag']);
        $date = datetime_convert('UTC', $tz, $b['created'], 'Y-m-d H:i:s');
        $year = intval(substr($date, 0, 4));
        $mon = intval(substr($date, 5, 2));
        $day = intval(substr($date, 8, 2));
        $hour = intval(substr($date, 11, 2));
        $min = intval(substr($date, 14, 2));
        $xml = <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<methodCall><methodName>LJ.XMLRPC.postevent</methodName>
<params><param>
<value><struct>
<member><name>year</name><value><int>{$year}</int></value></member>
<member><name>mon</name><value><int>{$mon}</int></value></member>
<member><name>day</name><value><int>{$day}</int></value></member>
<member><name>hour</name><value><int>{$hour}</int></value></member>
<member><name>min</name><value><int>{$min}</int></value></member>
<member><name>event</name><value><string>{$post}</string></value></member>
<member><name>username</name><value><string>{$dw_username}</string></value></member>
<member><name>password</name><value><string>{$dw_password}</string></value></member>
<member><name>subject</name><value><string>{$title}</string></value></member>
<member><name>lineendings</name><value><string>unix</string></value></member>
<member><name>ver</name><value><int>1</int></value></member>
<member><name>props</name>
<value><struct>
<member><name>useragent</name><value><string>Friendica</string></value></member>
<member><name>taglist</name><value><string>{$tags}</string></value></member>
</struct></value></member>
</struct></value>
</param></params>
</methodCall>

EOT;
        logger('dwpost: data: ' . $xml, LOGGER_DATA);
        if ($dw_blog !== 'test') {
            $x = z_post_url($dw_blog, $xml, array('headers' => array("Content-Type: text/xml")));
        }
        logger('posted to dreamwidth: ' . print_r($x, true), LOGGER_DEBUG);
    }
}
コード例 #3
0
ファイル: wppost.php プロジェクト: phellmes/hubzilla-addons
function wppost_drop_item(&$a, &$b)
{
    $wp_enabled = get_pconfig($b['item']['uid'], 'wppost', 'post');
    if (!$wp_enabled) {
        return;
    }
    $r = q("select * from iconfig left join item on item.id = iconfig.iid where cat = 'system' and k = 'wordpress' and iid = %d and uid = %d limit 1", intval($b['item']['id']), intval($b['item']['uid']));
    if (!$r) {
        return;
    }
    $post_id = basename($r[0]['v']);
    $wp_username = get_pconfig($b['item']['uid'], 'wppost', 'wp_username');
    $wp_password = z_unobscure(get_pconfig($b['item']['uid'], 'wppost', 'wp_password'));
    $wp_blog = get_pconfig($b['item']['uid'], 'wppost', 'wp_blog');
    $wp_blogid = get_pconfig($b['uid'], 'wppost', 'wp_blogid');
    if (!$wp_blogid) {
        $wp_blogid = 1;
    }
    if ($post_id && $wp_username && $wp_password && $wp_blog) {
        $client = new IXR_Client($wp_blog);
        if ($b['item']['id'] == $b['item']['parent']) {
            $res = $client->query('wp.deletePost', $wp_blogid, $wp_username, $wp_password, $post_id);
        } else {
            $res = $client->query('wp.deleteComment', $wp_blogid, $wp_username, $wp_password, $post_id);
        }
        if (!$res) {
            logger('wppost: delete failed.');
            return;
        }
        $result = intval($client->getResponse());
        logger('wppost: delete post returns: ' . $result, LOGGER_DEBUG);
    }
}
コード例 #4
0
function rtof_post_hook(&$a, &$b)
{
    /**
     * Post to Friendica
     */
    // 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'], 'rtof')) {
        return;
    }
    logger('Red-to-Friendica post invoked');
    load_pconfig($b['uid'], 'rtof');
    $api = get_pconfig($b['uid'], 'rtof', 'baseapi');
    if (substr($api, -1, 1) != '/') {
        $api .= '/';
    }
    $username = get_pconfig($b['uid'], 'rtof', 'username');
    $password = z_unobscure(get_pconfig($b['uid'], 'rtof', 'password'));
    $msg = $b['body'];
    $postdata = array('status' => $b['body'], 'title' => $b['title'], 'message_id' => $b['mid'], 'source' => 'Red Matrix');
    if (strlen($b['body'])) {
        $ret = z_post_url($api . 'statuses/update', $postdata, 0, array('http_auth' => $username . ':' . $password, 'novalidate' => 1));
        if ($ret['success']) {
            logger('rtof: returns: ' . print_r($ret['body'], true));
        } else {
            logger('rtof: z_post_url failed: ' . print_r($ret['debug'], true));
        }
    }
}
コード例 #5
0
function diaspost_send(&$a, &$b)
{
    $hostname = 'hubzilla ' . '(' . $a->get_hostname() . ')';
    logger('diaspost_send: invoked', LOGGER_DEBUG);
    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'], 'diaspost')) {
        return;
    }
    logger('diaspost_send: prepare posting', LOGGER_DEBUG);
    $diaspost_username = get_pconfig($b['uid'], 'diaspost', 'diaspost_username');
    $diaspost_password = z_unobscure(get_pconfig($b['uid'], 'diaspost', 'diaspost_password'));
    $diaspost_url = get_pconfig($b['uid'], 'diaspost', 'diaspost_url');
    if ($diaspost_url && $diaspost_username && $diaspost_password) {
        logger('diaspost_send: all values seem to be okay', LOGGER_DEBUG);
        require_once 'include/bb2diaspora.php';
        $tag_arr = array();
        $tags = '';
        $x = preg_match_all('/\\#\\[(.*?)\\](.*?)\\[/', $b['tag'], $matches, PREG_SET_ORDER);
        if ($x) {
            foreach ($matches as $mtch) {
                $tag_arr[] = $mtch[2];
            }
        }
        if (count($tag_arr)) {
            $tags = implode(',', $tag_arr);
        }
        $title = $b['title'];
        $body = $b['body'];
        // Insert a newline before and after a quote
        $body = str_ireplace("[quote", "\n\n[quote", $body);
        $body = str_ireplace("[/quote]", "[/quote]\n\n", $body);
        // strip bookmark indicators
        $body = preg_replace('/\\#\\^\\[([zu])rl/i', '[$1rl', $body);
        $body = preg_replace('/\\#\\^http/i', 'http', $body);
        if (intval(get_pconfig($item['uid'], 'system', 'prevent_tag_hijacking'))) {
            $new_tag = html_entity_decode('&#x22d5;', ENT_COMPAT, 'UTF-8');
            $new_mention = html_entity_decode('&#xff20;', ENT_COMPAT, 'UTF-8');
            // #-tags
            $body = preg_replace('/\\#\\[url/i', $new_tag . '[url', $body);
            $body = preg_replace('/\\#\\[zrl/i', $new_tag . '[zrl', $body);
            // @-mentions
            $body = preg_replace('/\\@\\!?\\[url/i', $new_mention . '[url', $body);
            $body = preg_replace('/\\@\\!?\\[zrl/i', $new_mention . '[zrl', $body);
        }
        // remove multiple newlines
        do {
            $oldbody = $body;
            $body = str_replace("\n\n\n", "\n\n", $body);
        } while ($oldbody != $body);
        // convert to markdown
        $body = bb2diaspora($body, false, true);
        // Adding the title
        if (strlen($title)) {
            $body = "## " . html_entity_decode($title) . "\n\n" . $body;
        }
        require_once "addon/diaspost/diasphp.php";
        try {
            logger('diaspost_send: prepare', LOGGER_DEBUG);
            $conn = new Diasphp($diaspost_url);
            logger('diaspost_send: try to log in ' . $diaspost_username, LOGGER_DEBUG);
            $conn->login($diaspost_username, $diaspost_password);
            logger('diaspost_send: try to send ' . $body, LOGGER_DEBUG);
            //throw new Exception('Test');
            $conn->post($body, $hostname);
            logger('diaspost_send: success');
        } catch (Exception $e) {
            logger("diaspost_send: Error submitting the post: " . $e->getMessage());
            //			logger('diaspost_send: requeueing '.$b['uid'], LOGGER_DEBUG);
            //			$r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $b['uid']);
            //			if (count($r))
            //				$a->contact = $r[0]["id"];
            //			$s = serialize(array('url' => $url, 'item' => $b['id'], 'post' => $body));
            //			require_once('include/queue_fn.php');
            //			add_to_queue($a->contact,NETWORK_DIASPORA2,$s);
            //			notice(t('Diaspost post failed. Queued for retry.').EOL);
        }
    }
}