]> git.mxchange.org Git - friendica-addons.git/blobdiff - fromapp/fromapp.php
Clean up the code
[friendica-addons.git] / fromapp / fromapp.php
index 58eaa46938d78f81516e171f2cd0652921eb2ffe..de8587445d9e32b621db06ae22752711139e91dc 100644 (file)
@@ -32,7 +32,9 @@ function fromapp_settings_post($a,$post) {
        if(! local_user() || (! x($_POST,'fromapp-submit')))
                return;
 
-       set_pconfig(local_user(),'fromapp','app',$_POST['fromapp']);
+       set_pconfig(local_user(),'fromapp','app',$_POST['fromapp-input']);
+       set_pconfig(local_user(),'fromapp','force',intval($_POST['fromapp-force']));
+
        info( t('Fromapp settings updated.') . EOL);
 }
 
@@ -50,19 +52,34 @@ function fromapp_settings(&$a,&$s) {
        $fromapp = get_pconfig(local_user(),'fromapp','app');
        if($fromapp === false)
                $fromapp = '';
+
+       $force = intval(get_pconfig(local_user(),'fromapp','force'));
+
+       $force_enabled = (($force) ? ' checked="checked" ' : '');
+
        
        /* Add some HTML to the existing form */
 
-       $s .= '<div class="settings-block">';
+       $s .= '<span id="settings_fromapp_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_fromapp_expanded\'); openClose(\'settings_fromapp_inflated\');">';
+       $s .= '<h3>' . t('FromApp Settings') . '</h3>';
+       $s .= '</span>';
+       $s .= '<div id="settings_fromapp_expanded" class="settings-block" style="display: none;">';
+       $s .= '<span class="fakelink" onclick="openClose(\'settings_fromapp_expanded\'); openClose(\'settings_fromapp_inflated\');">';
        $s .= '<h3>' . t('FromApp Settings') . '</h3>';
+       $s .= '</span>';
        $s .= '<div id="fromapp-wrapper">';
-       $s .= '<label id="fromapp-label" for="fromapp">' . t('The application name you would like to show your posts originating from.') . '</label>';
-       $s .= '<input id="fromapp-input" type="text" name="fromapp" value="' . $fromapp . '" ' . '/>';
+       $s .= '<label id="fromapp-label" for="fromapp-input">' . t('The application name you would like to show your posts originating from.') . '</label>';
+       $s .= '<input id="fromapp-input" type="text" name="fromapp-input" value="' . $fromapp . '" ' . '/>';
+       $s .= '<div class="clear"></div>';
+
+       $s .= '<label id="fromapp-force-label" for="fromapp-force">' . t('Use this application name even if another application was used.') . '</label>';
+       $s .= '<input id="fromapp-force" type="checkbox" name="fromapp-force" value="1" ' . $force_enabled . '/>';
+
        $s .= '</div><div class="clear"></div>';
 
        /* provide a submit button */
 
-       $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="fromapp-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
+       $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="fromapp-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
 
 }
 
@@ -74,11 +91,16 @@ function fromapp_post_hook(&$a,&$item) {
         return;
 
     $app = get_pconfig(local_user(), 'fromapp', 'app');
+       $force = intval(get_pconfig(local_user(), 'fromapp','force'));
 
     if(($app === false) || (! strlen($app)))
         return;
 
-       $item['app'] = $app;
+       if(strlen(trim($item['app'])) && (! $force))
+               return;
+
+       $apps = explode(',',$app);
+       $item['app'] = trim($apps[mt_rand(0,count($apps)-1)]);
        return;
 
-}
\ No newline at end of file
+}