3 * Name: Blogger Post Connector
4 * Description: Post to Blogger (or anything else which uses blogger XMLRPC API)
9 use Friendica\Content\Text\BBCode;
10 use Friendica\Core\Addon;
11 use Friendica\Core\L10n;
12 use Friendica\Core\PConfig;
13 use Friendica\Util\Network;
15 function blogger_install()
17 Addon::registerHook('post_local', 'addon/blogger/blogger.php', 'blogger_post_local');
18 Addon::registerHook('notifier_normal', 'addon/blogger/blogger.php', 'blogger_send');
19 Addon::registerHook('jot_networks', 'addon/blogger/blogger.php', 'blogger_jot_nets');
20 Addon::registerHook('connector_settings', 'addon/blogger/blogger.php', 'blogger_settings');
21 Addon::registerHook('connector_settings_post', 'addon/blogger/blogger.php', 'blogger_settings_post');
24 function blogger_uninstall()
26 Addon::unregisterHook('post_local', 'addon/blogger/blogger.php', 'blogger_post_local');
27 Addon::unregisterHook('notifier_normal', 'addon/blogger/blogger.php', 'blogger_send');
28 Addon::unregisterHook('jot_networks', 'addon/blogger/blogger.php', 'blogger_jot_nets');
29 Addon::unregisterHook('connector_settings', 'addon/blogger/blogger.php', 'blogger_settings');
30 Addon::unregisterHook('connector_settings_post', 'addon/blogger/blogger.php', 'blogger_settings_post');
33 Addon::unregisterHook('post_local_end', 'addon/blogger/blogger.php', 'blogger_send');
34 Addon::unregisterHook('addon_settings', 'addon/blogger/blogger.php', 'blogger_settings');
35 Addon::unregisterHook('addon_settings_post', 'addon/blogger/blogger.php', 'blogger_settings_post');
39 function blogger_jot_nets(&$a, &$b)
45 $bl_post = PConfig::get(local_user(), 'blogger', 'post');
46 if (intval($bl_post) == 1) {
47 $bl_defpost = PConfig::get(local_user(), 'blogger', 'post_by_default');
48 $selected = ((intval($bl_defpost) == 1) ? ' checked="checked" ' : '');
49 $b .= '<div class="profile-jot-net"><input type="checkbox" name="blogger_enable" ' . $selected . ' value="1" /> '
50 . L10n::t('Post to blogger') . '</div>';
55 function blogger_settings(&$a, &$s)
61 /* Add our stylesheet to the page so we can make our settings look nice */
63 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/blogger/blogger.css' . '" media="all" />' . "\r\n";
65 /* Get the current state of our config variables */
67 $enabled = PConfig::get(local_user(), 'blogger', 'post');
68 $checked = (($enabled) ? ' checked="checked" ' : '');
69 $css = (($enabled) ? '' : '-disabled');
71 $def_enabled = PConfig::get(local_user(), 'blogger', 'post_by_default');
73 $def_checked = (($def_enabled) ? ' checked="checked" ' : '');
75 $bl_username = PConfig::get(local_user(), 'blogger', 'bl_username');
76 $bl_password = PConfig::get(local_user(), 'blogger', 'bl_password');
77 $bl_blog = PConfig::get(local_user(), 'blogger', 'bl_blog');
79 /* Add some HTML to the existing form */
80 $s .= '<span id="settings_blogger_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blogger_expanded\'); openClose(\'settings_blogger_inflated\');">';
81 $s .= '<img class="connector'.$css.'" src="images/blogger.png" /><h3 class="connector">'. L10n::t('Blogger Export').'</h3>';
83 $s .= '<div id="settings_blogger_expanded" class="settings-block" style="display: none;">';
84 $s .= '<span class="fakelink" onclick="openClose(\'settings_blogger_expanded\'); openClose(\'settings_blogger_inflated\');">';
85 $s .= '<img class="connector'.$css.'" src="images/blogger.png" /><h3 class="connector">'. L10n::t('Blogger Export').'</h3>';
88 $s .= '<div id="blogger-enable-wrapper">';
89 $s .= '<label id="blogger-enable-label" for="blogger-checkbox">' . L10n::t('Enable Blogger Post Addon') . '</label>';
90 $s .= '<input id="blogger-checkbox" type="checkbox" name="blogger" value="1" ' . $checked . '/>';
91 $s .= '</div><div class="clear"></div>';
93 $s .= '<div id="blogger-username-wrapper">';
94 $s .= '<label id="blogger-username-label" for="blogger-username">' . L10n::t('Blogger username') . '</label>';
95 $s .= '<input id="blogger-username" type="text" name="bl_username" value="' . $bl_username . '" />';
96 $s .= '</div><div class="clear"></div>';
98 $s .= '<div id="blogger-password-wrapper">';
99 $s .= '<label id="blogger-password-label" for="blogger-password">' . L10n::t('Blogger password') . '</label>';
100 $s .= '<input id="blogger-password" type="password" name="bl_password" value="' . $bl_password . '" />';
101 $s .= '</div><div class="clear"></div>';
103 $s .= '<div id="blogger-blog-wrapper">';
104 $s .= '<label id="blogger-blog-label" for="blogger-blog">' . L10n::t('Blogger API URL') . '</label>';
105 $s .= '<input id="blogger-blog" type="text" name="bl_blog" value="' . $bl_blog . '" />';
106 $s .= '</div><div class="clear"></div>';
108 $s .= '<div id="blogger-bydefault-wrapper">';
109 $s .= '<label id="blogger-bydefault-label" for="blogger-bydefault">' . L10n::t('Post to Blogger by default') . '</label>';
110 $s .= '<input id="blogger-bydefault" type="checkbox" name="bl_bydefault" value="1" ' . $def_checked . '/>';
111 $s .= '</div><div class="clear"></div>';
113 /* provide a submit button */
114 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="blogger-submit" name="blogger-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
118 function blogger_settings_post(&$a, &$b)
120 if (x($_POST, 'blogger-submit')) {
121 PConfig::set(local_user(), 'blogger', 'post', intval($_POST['blogger']));
122 PConfig::set(local_user(), 'blogger', 'post_by_default', intval($_POST['bl_bydefault']));
123 PConfig::set(local_user(), 'blogger', 'bl_username', trim($_POST['bl_username']));
124 PConfig::set(local_user(), 'blogger', 'bl_password', trim($_POST['bl_password']));
125 PConfig::set(local_user(), 'blogger', 'bl_blog', trim($_POST['bl_blog']));
129 function blogger_post_local(&$a, &$b)
131 // This can probably be changed to allow editing by pointing to a different API endpoint
137 if (!local_user() || (local_user() != $b['uid'])) {
141 if ($b['private'] || $b['parent']) {
145 $bl_post = intval(PConfig::get(local_user(), 'blogger', 'post'));
147 $bl_enable = (($bl_post && x($_REQUEST, 'blogger_enable')) ? intval($_REQUEST['blogger_enable']) : 0);
149 if ($b['api_source'] && intval(PConfig::get(local_user(), 'blogger', 'post_by_default'))) {
157 if (strlen($b['postopts'])) {
158 $b['postopts'] .= ',';
161 $b['postopts'] .= 'blogger';
167 function blogger_send(&$a, &$b)
169 if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
173 if (! strstr($b['postopts'], 'blogger')) {
177 if ($b['parent'] != $b['id']) {
181 $bl_username = xmlify(PConfig::get($b['uid'], 'blogger', 'bl_username'));
182 $bl_password = xmlify(PConfig::get($b['uid'], 'blogger', 'bl_password'));
183 $bl_blog = PConfig::get($b['uid'], 'blogger', 'bl_blog');
185 if ($bl_username && $bl_password && $bl_blog) {
186 $title = '<title>' . (($b['title']) ? $b['title'] : L10n::t('Post from Friendica')) . '</title>';
187 $post = $title . BBCode::convert($b['body']);
188 $post = xmlify($post);
191 <?xml version=\"1.0\" encoding=\"utf-8\"?>
193 <methodName>blogger.newPost</methodName>
195 <param><value><string/></value></param>
196 <param><value><string/></value></param>
197 <param><value><string>$bl_username</string></value></param>
198 <param><value><string>$bl_password</string></value></param>
199 <param><value><string>$post</string></value></param>
200 <param><value><int>1</int></value></param>
206 logger('blogger: data: ' . $xml, LOGGER_DATA);
208 if ($bl_blog !== 'test') {
209 $x = Network::post($bl_blog, $xml);
212 logger('posted to blogger: ' . (($x) ? $x : ''), LOGGER_DEBUG);