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');
59 $checked = (($enabled) ? ' checked="checked" ' : '');
60 $css = (($enabled) ? '' : '-disabled');
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 .= '<span id="settings_blogger_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blogger_expanded\'); openClose(\'settings_blogger_inflated\');">';
74 $s .= '<img class="connector'.$css.'" src="images/blogger.png" /><h3 class="connector">'. t('Blogger Export').'</h3>';
76 $s .= '<div id="settings_blogger_expanded" class="settings-block" style="display: none;">';
77 $s .= '<span class="fakelink" onclick="openClose(\'settings_blogger_expanded\'); openClose(\'settings_blogger_inflated\');">';
78 $s .= '<img class="connector'.$css.'" src="images/blogger.png" /><h3 class="connector">'. t('Blogger Export').'</h3>';
81 $s .= '<div id="blogger-enable-wrapper">';
82 $s .= '<label id="blogger-enable-label" for="blogger-checkbox">' . t('Enable Blogger Post Plugin') . '</label>';
83 $s .= '<input id="blogger-checkbox" type="checkbox" name="blogger" value="1" ' . $checked . '/>';
84 $s .= '</div><div class="clear"></div>';
86 $s .= '<div id="blogger-username-wrapper">';
87 $s .= '<label id="blogger-username-label" for="blogger-username">' . t('Blogger username') . '</label>';
88 $s .= '<input id="blogger-username" type="text" name="bl_username" value="' . $bl_username . '" />';
89 $s .= '</div><div class="clear"></div>';
91 $s .= '<div id="blogger-password-wrapper">';
92 $s .= '<label id="blogger-password-label" for="blogger-password">' . t('Blogger password') . '</label>';
93 $s .= '<input id="blogger-password" type="password" name="bl_password" value="' . $bl_password . '" />';
94 $s .= '</div><div class="clear"></div>';
96 $s .= '<div id="blogger-blog-wrapper">';
97 $s .= '<label id="blogger-blog-label" for="blogger-blog">' . t('Blogger API URL') . '</label>';
98 $s .= '<input id="blogger-blog" type="text" name="bl_blog" value="' . $bl_blog . '" />';
99 $s .= '</div><div class="clear"></div>';
101 $s .= '<div id="blogger-bydefault-wrapper">';
102 $s .= '<label id="blogger-bydefault-label" for="blogger-bydefault">' . t('Post to Blogger by default') . '</label>';
103 $s .= '<input id="blogger-bydefault" type="checkbox" name="bl_bydefault" value="1" ' . $def_checked . '/>';
104 $s .= '</div><div class="clear"></div>';
106 /* provide a submit button */
108 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="blogger-submit" name="blogger-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
113 function blogger_settings_post(&$a,&$b) {
115 if(x($_POST,'blogger-submit')) {
117 set_pconfig(local_user(),'blogger','post',intval($_POST['blogger']));
118 set_pconfig(local_user(),'blogger','post_by_default',intval($_POST['bl_bydefault']));
119 set_pconfig(local_user(),'blogger','bl_username',trim($_POST['bl_username']));
120 set_pconfig(local_user(),'blogger','bl_password',trim($_POST['bl_password']));
121 set_pconfig(local_user(),'blogger','bl_blog',trim($_POST['bl_blog']));
127 function blogger_post_local(&$a,&$b) {
129 // This can probably be changed to allow editing by pointing to a different API endpoint
134 if((! local_user()) || (local_user() != $b['uid']))
137 if($b['private'] || $b['parent'])
140 $bl_post = intval(get_pconfig(local_user(),'blogger','post'));
142 $bl_enable = (($bl_post && x($_REQUEST,'blogger_enable')) ? intval($_REQUEST['blogger_enable']) : 0);
144 if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'blogger','post_by_default')))
150 if(strlen($b['postopts']))
151 $b['postopts'] .= ',';
152 $b['postopts'] .= 'blogger';
158 function blogger_send(&$a,&$b) {
160 if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))
163 if(! strstr($b['postopts'],'blogger'))
166 if($b['parent'] != $b['id'])
170 $bl_username = xmlify(get_pconfig($b['uid'],'blogger','bl_username'));
171 $bl_password = xmlify(get_pconfig($b['uid'],'blogger','bl_password'));
172 $bl_blog = get_pconfig($b['uid'],'blogger','bl_blog');
174 if($bl_username && $bl_password && $bl_blog) {
176 require_once('include/bbcode.php');
178 $title = '<title>' . (($b['title']) ? $b['title'] : t('Post from Friendica')) . '</title>';
179 $post = $title . bbcode($b['body']);
180 $post = xmlify($post);
183 <?xml version=\"1.0\" encoding=\"utf-8\"?>
185 <methodName>blogger.newPost</methodName>
187 <param><value><string/></value></param>
188 <param><value><string/></value></param>
189 <param><value><string>$bl_username</string></value></param>
190 <param><value><string>$bl_password</string></value></param>
191 <param><value><string>$post</string></value></param>
192 <param><value><int>1</int></value></param>
198 logger('blogger: data: ' . $xml, LOGGER_DATA);
200 if($bl_blog !== 'test')
201 $x = post_url($bl_blog,$xml);
202 logger('posted to blogger: ' . (($x) ? $x : ''), LOGGER_DEBUG);