[various] Convert connector_settings hook functions to the new data array format

- Add separate template files to several addons
- Remove superfluous addon settings CSS files
This commit is contained in:
Hypolite Petovan 2021-11-21 17:10:13 -05:00
parent 779b38ec09
commit 9acfdb4090
36 changed files with 612 additions and 1012 deletions

View file

@ -0,0 +1,5 @@
{{include file="field_checkbox.tpl" field=$enabled}}
{{include file="field_input.tpl" field=$username}}
{{include file="field_password.tpl" field=$password}}
{{include file="field_input.tpl" field=$blog}}
{{include file="field_checkbox.tpl" field=$bydefault}}

View file

@ -1,20 +0,0 @@
#wppost-enable-label, #wppost-username-label, #wppost-password-label,
#wppost-blog-label, #wppost-bydefault-label,
#wppost-backlink-label, #wppost-shortcheck-label {
float: left;
width: 200px;
margin-top: 10px;
}
#wppost-checkbox, #wppost-username, #wppost-password,
#wppost-blog, #wppost-bydefault,
#wppost-shortcheck, #wppost-backlink {
float: left;
margin-top: 10px;
}
#wppost-submit {
margin-top: 15px;
}

View file

@ -6,10 +6,12 @@
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
*/
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Post;
@ -25,7 +27,7 @@ function wppost_install()
Hook::register('connector_settings_post', 'addon/wppost/wppost.php', 'wppost_settings_post');
}
function wppost_jot_nets(\Friendica\App &$a, array &$jotnets_fields)
function wppost_jot_nets(App &$a, array &$jotnets_fields)
{
if (!local_user()) {
return;
@ -44,92 +46,39 @@ function wppost_jot_nets(\Friendica\App &$a, array &$jotnets_fields)
}
function wppost_settings(&$a, &$s) {
if(! local_user())
function wppost_settings(App &$a, array &$data)
{
if (!local_user()) {
return;
}
/* Add our stylesheet to the page so we can make our settings look nice */
$enabled = DI::pConfig()->get(local_user(), 'wppost', 'post', false);
$wp_username = DI::pConfig()->get(local_user(), 'wppost', 'wp_username');
$wp_blog = DI::pConfig()->get(local_user(), 'wppost', 'wp_blog');
$def_enabled = DI::pConfig()->get(local_user(), 'wppost', 'post_by_default', false);
$back_enabled = DI::pConfig()->get(local_user(), 'wppost', 'backlink', false);
$wp_backlink_text = DI::pConfig()->get(local_user(), 'wppost', 'wp_backlink_text');
$shortcheck_enabled = DI::pConfig()->get(local_user(), 'wppost', 'shortcheck', false);
DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/wppost/wppost.css' . '" media="all" />' . "\r\n";
/* Get the current state of our config variables */
$enabled = DI::pConfig()->get(local_user(),'wppost','post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$css = (($enabled) ? '' : '-disabled');
$def_enabled = DI::pConfig()->get(local_user(),'wppost','post_by_default');
$back_enabled = DI::pConfig()->get(local_user(),'wppost','backlink');
$shortcheck_enabled = DI::pConfig()->get(local_user(),'wppost','shortcheck');
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
$back_checked = (($back_enabled) ? ' checked="checked" ' : '');
$shortcheck_checked = (($shortcheck_enabled) ? ' checked="checked" ' : '');
$wp_username = DI::pConfig()->get(local_user(), 'wppost', 'wp_username');
$wp_password = DI::pConfig()->get(local_user(), 'wppost', 'wp_password');
$wp_blog = DI::pConfig()->get(local_user(), 'wppost', 'wp_blog');
$wp_backlink_text = DI::pConfig()->get(local_user(), 'wppost', 'wp_backlink_text');
/* Add some HTML to the existing form */
$s .= '<span id="settings_wppost_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_wppost_expanded\'); openClose(\'settings_wppost_inflated\');">';
$s .= '<img class="connector'.$css.'" src="images/wordpress.png" /><h3 class="connector">'. DI::l10n()->t('Wordpress Export').'</h3>';
$s .= '</span>';
$s .= '<div id="settings_wppost_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_wppost_expanded\'); openClose(\'settings_wppost_inflated\');">';
$s .= '<img class="connector'.$css.'" src="images/wordpress.png" /><h3 class="connector">'. DI::l10n()->t('Wordpress Export').'</h3>';
$s .= '</span>';
$s .= '<div id="wppost-enable-wrapper">';
$s .= '<label id="wppost-enable-label" for="wppost-enable">' . DI::l10n()->t('Enable WordPress Post Addon') . '</label>';
$s .= '<input type="hidden" name="wppost" value="0"/>';
$s .= '<input id="wppost-enable" type="checkbox" name="wppost" value="1" ' . $checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="wppost-username-wrapper">';
$s .= '<label id="wppost-username-label" for="wppost-username">' . DI::l10n()->t('WordPress username') . '</label>';
$s .= '<input id="wppost-username" type="text" name="wp_username" value="' . $wp_username . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="wppost-password-wrapper">';
$s .= '<label id="wppost-password-label" for="wppost-password">' . DI::l10n()->t('WordPress password') . '</label>';
$s .= '<input id="wppost-password" type="password" name="wp_password" value="' . $wp_password . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="wppost-blog-wrapper">';
$s .= '<label id="wppost-blog-label" for="wppost-blog">' . DI::l10n()->t('WordPress API URL') . '</label>';
$s .= '<input id="wppost-blog" type="text" name="wp_blog" value="' . $wp_blog . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="wppost-bydefault-wrapper">';
$s .= '<label id="wppost-bydefault-label" for="wppost-bydefault">' . DI::l10n()->t('Post to WordPress by default') . '</label>';
$s .= '<input type="hidden" name="wp_bydefault" value="0"/>';
$s .= '<input id="wppost-bydefault" type="checkbox" name="wp_bydefault" value="1" ' . $def_checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="wppost-backlink-wrapper">';
$s .= '<label id="wppost-backlink-label" for="wppost-backlink">' . DI::l10n()->t('Provide a backlink to the Friendica post') . '</label>';
$s .= '<input type="hidden" name="wp_backlink" value="0"/>';
$s .= '<input id="wppost-backlink" type="checkbox" name="wp_backlink" value="1" ' . $back_checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="wppost-backlinktext-wrapper">';
$s .= '<label id="wppost-backlinktext-label" for="wp_backlink_text">' . DI::l10n()->t('Text for the backlink, e.g. Read the original post and comment stream on Friendica.') . '</label>';
$s .= '<input id="wppost-backlinktext" type="text" name="wp_backlink_text" value="'. $wp_backlink_text.'" ' . $wp_backlink_text . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="wppost-shortcheck-wrapper">';
$s .= '<label id="wppost-shortcheck-label" for="wppost-shortcheck">' . DI::l10n()->t("Don't post messages that are too short") . '</label>';
$s .= '<input type="hidden" name="wp_shortcheck" value="0"/>';
$s .= '<input id="wppost-shortcheck" type="checkbox" name="wp_shortcheck" value="1" '.$shortcheck_checked.'/>';
$s .= '</div><div class="clear"></div>';
/* provide a submit button */
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="wppost-submit" name="wppost-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div></div>';
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/wppost/');
$html = Renderer::replaceMacros($t, [
'$enabled' => ['wppost', DI::l10n()->t('Enable Wordpress Post Addon'), $enabled],
'$username' => ['wp_username', DI::l10n()->t('Wordpress username'), $wp_username],
'$password' => ['wp_password', DI::l10n()->t('Wordpress password')],
'$blog' => ['wp_blog', DI::l10n()->t('WordPress API URL'), $wp_blog],
'$bydefault' => ['wp_bydefault', DI::l10n()->t('Post to Wordpress by default'), $def_enabled],
'$backlink' => ['wp_backlink', DI::l10n()->t('Provide a backlink to the Friendica post'), $back_enabled],
'$backlink_text' => ['wp_backlink_text', DI::l10n()->t('Text for the backlink, e.g. Read the original post and comment stream on Friendica.'), $wp_backlink_text],
'$shortcheck' => ['wp_shortcheck', DI::l10n()->t('Don\'t post messages that are too short'), $shortcheck_enabled],
]);
$data = [
'connector' => 'wppost',
'title' => DI::l10n()->t('Wordpress Export'),
'image' => 'images/wordpress.png',
'enabled' => $enabled,
'html' => $html,
];
}