4 * Name: Blogger Post Connector
5 * Description: Post to Blogger (or anything else which uses blogger XMLRPC API)
10 function blogger_install() {
11 register_hook('post_local', 'addon/blogger/blogger.php', 'blogger_post_local');
12 register_hook('notifier_normal', 'addon/blogger/blogger.php', 'blogger_send');
13 register_hook('jot_networks', 'addon/blogger/blogger.php', 'blogger_jot_nets');
14 register_hook('connector_settings', 'addon/blogger/blogger.php', 'blogger_settings');
15 register_hook('connector_settings_post', 'addon/blogger/blogger.php', 'blogger_settings_post');
18 function blogger_uninstall() {
19 unregister_hook('post_local', 'addon/blogger/blogger.php', 'blogger_post_local');
20 unregister_hook('notifier_normal', 'addon/blogger/blogger.php', 'blogger_send');
21 unregister_hook('jot_networks', 'addon/blogger/blogger.php', 'blogger_jot_nets');
22 unregister_hook('connector_settings', 'addon/blogger/blogger.php', 'blogger_settings');
23 unregister_hook('connector_settings_post', 'addon/blogger/blogger.php', 'blogger_settings_post');
26 unregister_hook('post_local_end', 'addon/blogger/blogger.php', 'blogger_send');
27 unregister_hook('plugin_settings', 'addon/blogger/blogger.php', 'blogger_settings');
28 unregister_hook('plugin_settings_post', 'addon/blogger/blogger.php', 'blogger_settings_post');
33 function blogger_jot_nets(&$a,&$b) {
37 $bl_post = get_pconfig(local_user(),'blogger','post');
38 if(intval($bl_post) == 1) {
39 $bl_defpost = get_pconfig(local_user(),'blogger','post_by_default');
40 $selected = ((intval($bl_defpost) == 1) ? ' checked="checked" ' : '');
41 $b .= '<div class="profile-jot-net"><input type="checkbox" name="blogger_enable" ' . $selected . ' value="1" /> '
42 . t('Post to blogger') . '</div>';
47 function blogger_settings(&$a,&$s) {
52 /* Add our stylesheet to the page so we can make our settings look nice */
54 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/blogger/blogger.css' . '" media="all" />' . "\r\n";
56 /* Get the current state of our config variables */
58 $enabled = get_pconfig(local_user(),'blogger','post');
60 $checked = (($enabled) ? ' checked="checked" ' : '');
62 $def_enabled = get_pconfig(local_user(),'blogger','post_by_default');
64 $def_checked = (($def_enabled) ? ' checked="checked" ' : '');
66 $bl_username = get_pconfig(local_user(), 'blogger', 'bl_username');
67 $bl_password = get_pconfig(local_user(), 'blogger', 'bl_password');
68 $bl_blog = get_pconfig(local_user(), 'blogger', 'bl_blog');
71 /* Add some HTML to the existing form */
73 $s .= '<div class="settings-block">';
74 $s .= '<h3>' . t('Blogger Post Settings') . '</h3>';
75 $s .= '<div id="blogger-enable-wrapper">';
76 $s .= '<label id="blogger-enable-label" for="blogger-checkbox">' . t('Enable Blogger Post Plugin') . '</label>';
77 $s .= '<input id="blogger-checkbox" type="checkbox" name="blogger" value="1" ' . $checked . '/>';
78 $s .= '</div><div class="clear"></div>';
80 $s .= '<div id="blogger-username-wrapper">';
81 $s .= '<label id="blogger-username-label" for="blogger-username">' . t('Blogger username') . '</label>';
82 $s .= '<input id="blogger-username" type="text" name="bl_username" value="' . $bl_username . '" />';
83 $s .= '</div><div class="clear"></div>';
85 $s .= '<div id="blogger-password-wrapper">';
86 $s .= '<label id="blogger-password-label" for="blogger-password">' . t('Blogger password') . '</label>';
87 $s .= '<input id="blogger-password" type="password" name="bl_password" value="' . $bl_password . '" />';
88 $s .= '</div><div class="clear"></div>';
90 $s .= '<div id="blogger-blog-wrapper">';
91 $s .= '<label id="blogger-blog-label" for="blogger-blog">' . t('Blogger API URL') . '</label>';
92 $s .= '<input id="blogger-blog" type="text" name="bl_blog" value="' . $bl_blog . '" />';
93 $s .= '</div><div class="clear"></div>';
95 $s .= '<div id="blogger-bydefault-wrapper">';
96 $s .= '<label id="blogger-bydefault-label" for="blogger-bydefault">' . t('Post to Blogger by default') . '</label>';
97 $s .= '<input id="blogger-bydefault" type="checkbox" name="bl_bydefault" value="1" ' . $def_checked . '/>';
98 $s .= '</div><div class="clear"></div>';
100 /* provide a submit button */
102 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="blogger-submit" name="blogger-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
107 function blogger_settings_post(&$a,&$b) {
109 if(x($_POST,'blogger-submit')) {
111 set_pconfig(local_user(),'blogger','post',intval($_POST['blogger']));
112 set_pconfig(local_user(),'blogger','post_by_default',intval($_POST['bl_bydefault']));
113 set_pconfig(local_user(),'blogger','bl_username',trim($_POST['bl_username']));
114 set_pconfig(local_user(),'blogger','bl_password',trim($_POST['bl_password']));
115 set_pconfig(local_user(),'blogger','bl_blog',trim($_POST['bl_blog']));
121 function blogger_post_local(&$a,&$b) {
123 // This can probably be changed to allow editing by pointing to a different API endpoint
128 if((! local_user()) || (local_user() != $b['uid']))
131 if($b['private'] || $b['parent'])
134 $bl_post = intval(get_pconfig(local_user(),'blogger','post'));
136 $bl_enable = (($bl_post && x($_REQUEST,'blogger_enable')) ? intval($_REQUEST['blogger_enable']) : 0);
138 if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'blogger','post_by_default')))
144 if(strlen($b['postopts']))
145 $b['postopts'] .= ',';
146 $b['postopts'] .= 'blogger';
152 function blogger_send(&$a,&$b) {
154 if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))
157 if(! strstr($b['postopts'],'blogger'))
160 if($b['parent'] != $b['id'])
164 $bl_username = xmlify(get_pconfig($b['uid'],'blogger','bl_username'));
165 $bl_password = xmlify(get_pconfig($b['uid'],'blogger','bl_password'));
166 $bl_blog = get_pconfig($b['uid'],'blogger','bl_blog');
168 if($bl_username && $bl_password && $bl_blog) {
170 require_once('include/bbcode.php');
172 $title = '<title>' . (($b['title']) ? $b['title'] : t('Post from Friendica')) . '</title>';
173 $post = $title . bbcode($b['body']);
174 $post = xmlify($post);
177 <?xml version=\"1.0\" encoding=\"utf-8\"?>
179 <methodName>blogger.newPost</methodName>
181 <param><value><string/></value></param>
182 <param><value><string/></value></param>
183 <param><value><string>$bl_username</string></value></param>
184 <param><value><string>$bl_password</string></value></param>
185 <param><value><string>$post</string></value></param>
186 <param><value><int>1</int></value></param>
192 logger('blogger: data: ' . $xml, LOGGER_DATA);
194 if($bl_blog !== 'test')
195 $x = post_url($bl_blog,$xml);
196 logger('posted to blogger: ' . (($x) ? $x : ''), LOGGER_DEBUG);