X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=dwpost%2Fdwpost.php;h=56e04f783c2be41e7925a903e093d0cddf58f1b6;hb=2d4ecd5ccf25c844502e2cadbf60f3cad5b33ba7;hp=9bcee9c2986cad9bf34c79d25b58f7d8746f294a;hpb=c67ad31c8bf3749ac21bc62116ecb21c52daa544;p=friendica-addons.git diff --git a/dwpost/dwpost.php b/dwpost/dwpost.php index 9bcee9c2..56e04f78 100644 --- a/dwpost/dwpost.php +++ b/dwpost/dwpost.php @@ -14,8 +14,9 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Model\Post; +use Friendica\Model\Tag; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Network; use Friendica\Util\XML; function dwpost_install() @@ -27,15 +28,6 @@ function dwpost_install() Hook::register('connector_settings_post', 'addon/dwpost/dwpost.php', 'dwpost_settings_post'); } -function dwpost_uninstall() -{ - Hook::unregister('post_local', 'addon/dwpost/dwpost.php', 'dwpost_post_local'); - Hook::unregister('notifier_normal', 'addon/dwpost/dwpost.php', 'dwpost_send'); - Hook::unregister('jot_networks', 'addon/dwpost/dwpost.php', 'dwpost_jot_nets'); - Hook::unregister('connector_settings', 'addon/dwpost/dwpost.php', 'dwpost_settings'); - Hook::unregister('connector_settings_post', 'addon/dwpost/dwpost.php', 'dwpost_settings_post'); -} - function dwpost_jot_nets(App $a, array &$jotnets_fields) { if (!local_user()) { @@ -168,6 +160,8 @@ function dwpost_send(App $a, array &$b) return; } + $b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], $b['body']); + /* * dreamwidth post in the LJ user's timezone. * Hopefully the person's Friendica account @@ -189,9 +183,9 @@ function dwpost_send(App $a, array &$b) if ($dw_username && $dw_password && $dw_blog) { $title = $b['title']; - $post = BBCode::convert($b['body']); + $post = BBCode::convertForUriId($b['uri-id'], $b['body'], BBCode::CONNECTORS); $post = XML::escape($post); - $tags = dwpost_get_tags($b['tag']); + $tags = Tag::getCSVByURIId($b['uri-id'], [Tag::HASHTAG]); $date = DateTimeFormat::convert($b['created'], $tz); $year = intval(substr($date,0,4)); @@ -230,18 +224,9 @@ EOT; Logger::log('dwpost: data: ' . $xml, Logger::DATA); if ($dw_blog !== 'test') { - $x = Network::post($dw_blog, $xml, ["Content-Type: text/xml"])->getBody(); + $x = DI::httpRequest()->post($dw_blog, $xml, ["Content-Type: text/xml"])->getBody(); } Logger::log('posted to dreamwidth: ' . ($x) ? $x : '', Logger::DEBUG); } } - -function dwpost_get_tags($post) -{ - preg_match_all("/\]([^\[#]+)\[/", $post, $matches); - - $tags = implode(', ', $matches[1]); - - return $tags; -}