X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=dwpost%2Fdwpost.php;h=9a973b672f2859d633bfca96d42ceb706fc973d8;hb=19b2c8d83315ba7bc024ec2b29ea87762bc1ffa6;hp=5c13734bbd1dc2a4d0b555485c1a2802a226103a;hpb=335fcf670f35f577eacf1050b223641b60bbb35c;p=friendica-addons.git diff --git a/dwpost/dwpost.php b/dwpost/dwpost.php index 5c13734b..9a973b67 100644 --- a/dwpost/dwpost.php +++ b/dwpost/dwpost.php @@ -11,13 +11,11 @@ use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; -use Friendica\Core\L10n; use Friendica\Core\Logger; -use Friendica\Core\PConfig; use Friendica\Database\DBA; use Friendica\DI; +use Friendica\Model\Tag; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Network; use Friendica\Util\XML; function dwpost_install() @@ -44,13 +42,13 @@ function dwpost_jot_nets(App $a, array &$jotnets_fields) return; } - if (PConfig::get(local_user(), 'dwpost', 'post')) { + if (DI::pConfig()->get(local_user(), 'dwpost', 'post')) { $jotnets_fields[] = [ 'type' => 'checkbox', 'field' => [ 'dwpost_enable', - L10n::t('Post to Dreamwidth'), - PConfig::get(local_user(), 'dwpost', 'post_by_default') + DI::l10n()->t('Post to Dreamwidth'), + DI::pConfig()->get(local_user(), 'dwpost', 'post_by_default') ] ]; } @@ -64,61 +62,61 @@ function dwpost_settings(App $a, &$s) } /* Add our stylesheet to the page so we can make our settings look nice */ - $a->page['htmlhead'] .= '' . "\r\n"; + DI::page()['htmlhead'] .= '' . "\r\n"; /* Get the current state of our config variables */ - $enabled = PConfig::get(local_user(), 'dwpost', 'post'); + $enabled = DI::pConfig()->get(local_user(), 'dwpost', 'post'); $checked = (($enabled) ? ' checked="checked" ' : ''); - $def_enabled = PConfig::get(local_user(), 'dwpost', 'post_by_default'); + $def_enabled = DI::pConfig()->get(local_user(), 'dwpost', 'post_by_default'); $def_checked = (($def_enabled) ? ' checked="checked" ' : ''); - $dw_username = PConfig::get(local_user(), 'dwpost', 'dw_username'); - $dw_password = PConfig::get(local_user(), 'dwpost', 'dw_password'); + $dw_username = DI::pConfig()->get(local_user(), 'dwpost', 'dw_username'); + $dw_password = DI::pConfig()->get(local_user(), 'dwpost', 'dw_password'); /* Add some HTML to the existing form */ $s .= ''; - $s .= '

'. L10n::t("Dreamwidth Export").'

'; + $s .= '

'. DI::l10n()->t("Dreamwidth Export").'

'; $s .= '
'; $s .= ''; + $s .= '
'; } function dwpost_settings_post(App $a, array &$b) { if (!empty($_POST['dwpost-submit'])) { - PConfig::set(local_user(), 'dwpost', 'post', intval($_POST['dwpost'])); - PConfig::set(local_user(), 'dwpost', 'post_by_default', intval($_POST['dw_bydefault'])); - PConfig::set(local_user(), 'dwpost', 'dw_username', trim($_POST['dw_username'])); - PConfig::set(local_user(), 'dwpost', 'dw_password', trim($_POST['dw_password'])); + DI::pConfig()->set(local_user(), 'dwpost', 'post', intval($_POST['dwpost'])); + DI::pConfig()->set(local_user(), 'dwpost', 'post_by_default', intval($_POST['dw_bydefault'])); + DI::pConfig()->set(local_user(), 'dwpost', 'dw_username', trim($_POST['dw_username'])); + DI::pConfig()->set(local_user(), 'dwpost', 'dw_password', trim($_POST['dw_password'])); } } @@ -137,11 +135,11 @@ function dwpost_post_local(App $a, array &$b) return; } - $dw_post = intval(PConfig::get(local_user(),'dwpost','post')); + $dw_post = intval(DI::pConfig()->get(local_user(),'dwpost','post')); $dw_enable = (($dw_post && !empty($_REQUEST['dwpost_enable'])) ? intval($_REQUEST['dwpost_enable']) : 0); - if ($b['api_source'] && intval(PConfig::get(local_user(),'dwpost','post_by_default'))) { + if ($b['api_source'] && intval(DI::pConfig()->get(local_user(),'dwpost','post_by_default'))) { $dw_enable = 1; } @@ -185,15 +183,15 @@ function dwpost_send(App $a, array &$b) $tz = $x[0]['timezone']; } - $dw_username = PConfig::get($b['uid'],'dwpost','dw_username'); - $dw_password = PConfig::get($b['uid'],'dwpost','dw_password'); + $dw_username = DI::pConfig()->get($b['uid'],'dwpost','dw_username'); + $dw_password = DI::pConfig()->get($b['uid'],'dwpost','dw_password'); $dw_blog = 'http://www.dreamwidth.org/interface/xmlrpc'; if ($dw_username && $dw_password && $dw_blog) { $title = $b['title']; $post = BBCode::convert($b['body']); $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)); @@ -232,18 +230,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; -}