Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
clean up: remove the ugly define()'s and update settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
Caerostris committed Dec 16, 2014
1 parent e255e8f commit 007c3c1
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 104 deletions.
42 changes: 7 additions & 35 deletions class.van2shout.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with Van2Shout. If not, see <http://www.gnu.org/licenses/>.

if(C('Plugin.Van2Shout.FBUrl', '') != '' && C('Plugin.Van2Shout.FBSecret', '') != '')
{
define('USE_FIREBASE', true);
}
else
{
define('USE_FIREBASE', false);
}

if(C('Plugin.Van2Shout.ContentAsset', true))
{
define('VAN2SHOUT_ASSETTARGET', 'Content');
}
else
{
define('VAN2SHOUT_ASSETTARGET', 'Panel');
}

// Define the plugin:
$PluginInfo['Van2Shout'] = array(
'Name' => 'Van2Shout',
Expand Down Expand Up @@ -78,9 +60,10 @@ public function SettingsController_Van2Shout_Create($Sender) {
$RoleModel = new RoleModel();
$Roles = $RoleModel->Get();

$Schema['Plugin.Van2Shout.FBUrl'] = array('LabelCode' => 'FBUrl', 'Control' => 'Input', 'Default' => C('Plugin.Van2Shout.FBUrl', ''));
$Schema['Plugin.Van2Shout.FBSecret'] = array('LabelCode' => 'FBSecret', 'Control' => 'Input', 'Default' => C('Plugin.Van2Shout.FBSecret', ''));
$Schema['Plugin.Van2Shout.ContentAsset'] = array('LabelCode' => 'ContentAsset', 'Control' => 'Checkbox', 'Default' => C('Plugin.Van2Shout.ContentAsset', true));
$Schema['Plugin.Van2Shout.Firebase.Enable'] = array('LabelCode' => 'Firebase.Eanble', 'Control' => 'Checkbox', 'Default' => C('Plugin.Van2Shout.Firebase.Enable', false));
$Schema['Plugin.Van2Shout.Firebase.Url'] = array('LabelCode' => 'Firebase.Url', 'Control' => 'Input', 'Default' => C('Plugin.Van2Shout.Firebase.Url', ''));
$Schema['Plugin.Van2Shout.Firebase.Secret'] = array('LabelCode' => 'Firebase.Secret', 'Control' => 'Input', 'Default' => C('Plugin.Van2Shout.Firebase.Secret', ''));
$Schema['Plugin.Van2Shout.DisplayTarget.DiscussionsController'] = array('LabelCode' => 'AssetContent', 'Control' => 'Checkbox', 'Default' => C('Plugin.Van2Shout.DisplayTarget.DiscussionsController', true));
$Schema['Plugin.Van2Shout.Timestamp'] = array('LabelCode' => 'Timestamp', 'Control' => 'Checkbox', 'Default' => C('Plugin.Van2Shout.Timestamp', false));
$Schema['Plugin.Van2Shout.SendText'] = array('LabelCode' => 'SendText', 'Control' => 'Input', 'Default' => C('Plugin.Van2Shout.SendText', 'Send'));
$Schema['Plugin.Van2Shout.TimeColour'] = array('LabelCode' => 'TimeColour', 'Control' => 'Input', 'Default' => C('Plugin.Van2Shout.TimeColour', 'grey'));
Expand All @@ -98,18 +81,11 @@ public function SettingsController_Van2Shout_Create($Sender) {
$Sender->Render(dirname(__FILE__) . DS . 'views' . DS . 'settings.php');
}

public function Base_Render_Before($Sender) {
if(VAN2SHOUT_ASSETTARGET != 'Panel')
return;

$this->includev2s($Sender);
}

public function DiscussionsController_Render_Before($Sender) {
if(VAN2SHOUT_ASSETTARGET != 'Content')
if(!C('Plugin.Van2Shout.DisplayTarget.DiscussionsController', true))
return;

$this->includev2s($Sender);
$this->includev2s($Sender, 'Content');
}

public function ProfileController_AfterAddSideMenu_Handler($Sender) {
Expand Down Expand Up @@ -173,7 +149,7 @@ private function includev2s($Sender)
$Sender->AddJsFile('emojify.min.js', 'plugins/Van2Shout/js');

//Include firebase script?
if(USE_FIREBASE)
if(C('Plugin.Van2Shout.Firebase.Enable', false))
{
$Sender->Head->AddString("\n<script src='https://cdn.firebase.com/v0/firebase.js'></script>");
}
Expand All @@ -190,10 +166,6 @@ private function includev2s($Sender)
}
}

private function checkTableFormat()
{
}

public function Setup() {
$Construct = GDN::Structure();
$Construct->Table('Shoutbox');
Expand Down
7 changes: 6 additions & 1 deletion firebase/rules.firebase → firebase/rules.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<h1>Firebase Security Rules</h1>
Login in to your firebase and open the <b>Security</b> tab.<br />
Copy & Paste these rules and hit save:
<pre>
{
"rules": {
"broadcast": {
".read": "auth != null",
"$key": {
"$key": {
".write": "auth != null && (!data.exists() || auth.delete == true) && auth.post == true && newData.child('colour').val() == auth.colour && auth.id == newData.child('uname').val()"
}
},
Expand All @@ -16,3 +20,4 @@
}
}
}
</pre>
2 changes: 1 addition & 1 deletion firebase/v2s.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function fb_new_token()
if(!$Session->CheckPermission('Plugins.Van2Shout.View'))
return;

$tokenGen = new Services_FirebaseTokenGenerator(C('Plugin.Van2Shout.FBSecret', ''));
$tokenGen = new Services_FirebaseTokenGenerator(C('Plugin.Van2Shout.Firebase.Secret', ''));

$conf = array("id" => $Session->User->Name);

Expand Down
2 changes: 1 addition & 1 deletion modules/class.van2shoutdiscussionsmodule.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct($Sender = '') {
}

public function AssetTarget() {
return VAN2SHOUT_ASSETTARGET;
return 'Content';
}

public function ToString() {
Expand Down
32 changes: 5 additions & 27 deletions views/discussionscontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,16 @@
$Session = GDN::Session();
if($Session->CheckPermission('Plugins.Van2Shout.Post'))
{
if(VAN2SHOUT_ASSETTARGET == 'Content')
{
$width = "90%";
}
else
{
$width = "70%";
}
echo "<form action='javascript:SubmitMessage();'>\n<input type='text' style='width: ".$width."' name='shoutboxinput' id='shoutboxinput' onkeydown='checkLength();' />";
echo "<form action='javascript:SubmitMessage();'>\n<input type='text' style='width: 90%' name='shoutboxinput' id='shoutboxinput' onkeydown='checkLength();' />";
echo "<img src='".Gdn::Request()->Domain()."/".Gdn::Request()->Webroot()."/applications/dashboard/design/images/progress.gif' style='display:none;' id='shoutboxloading' />\n";
echo "<input type='submit' value='".T(C('Plugin.Van2Shout.SendText', 'Send'))."' id='van2shoutsubmit' name='van2shoutsubmit' class='Button' />\n</form>\n";
}
?>
</div>
<script src="<?php echo Gdn::Request()->Domain()."/".Gdn::Request()->WebRoot(); ?>/plugins/Van2Shout/js/moment.min.js" type="text/javascript"></script>
<script type="text/javascript">
<?php
if(VAN2SHOUT_ASSETTARGET == 'Content')
{
echo "$('#van2shout').prependTo('#Content');\n";
echo "$('#van2shout').insertAfter('.Info');\n";
}
?>
$('#van2shout').prependTo('#Content');
$('#van2shout').insertAfter('.Info');

var timecolour = "<?php echo C('Plugin.Van2Shout.TimeColour', 'grey'); ?>";

Expand Down Expand Up @@ -99,21 +86,12 @@ function DeleteMsg(id)
}
});

<?php include(USE_FIREBASE ? dirname(__FILE__).DS.'discussionscontroller_firebase.php' : dirname(__FILE__).DS.'discussionscontroller_local.php'); ?>
<?php include(C('Plugin.Van2Shout.Firebase.Enable', false) ? dirname(__FILE__).DS.'discussionscontroller_firebase.php' : dirname(__FILE__).DS.'discussionscontroller_local.php'); ?>
</script>

<style type="text/css">
#van2shoutscroll {
<?php
if(VAN2SHOUT_ASSETTARGET == 'Content')
{
echo "height:200px;\n";
}
else
{
echo "height:500px\n;";
}
?>
height:200px;\n";
overflow:auto;
}

Expand Down
2 changes: 1 addition & 1 deletion views/discussionscontroller_firebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
var oldestID = 0;
var maxMessages = <?php echo C('Plugin.Van2Shout.MsgCount', '50') ?>;
var loggedInUname = "<?php echo $uname; ?>";
var firebase = new Firebase('<?php echo C('Plugin.Van2Shout.FBUrl', ''); ?>');
var firebase = new Firebase('<?php echo C('Plugin.Van2Shout.Firebase.Url', ''); ?>');
firebase.auth(AUTH_TOKEN, function(err)
{
if(err)
Expand Down
66 changes: 28 additions & 38 deletions views/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,38 @@

<h1>
<p style="font-size:18px"><?php echo T('Van2Shout'); ?></p>
<p><a style="margin-left:0px;" target="_blank" href="http://kenoschwalb.com/page/contact">Contact me</a></p><br />
</h1>

<div style="margin-left:20px;">
<br /><b>Use firebase for a faster chat!</b><br />
<div id="firebase">
Firebase is a service which provides hyper-fast and flexible databases.<br />
Van2Shout is able to switch its backend from Vanilla's MySQL database to Firebase. Using Firebase will make the shoutbox incredibly fast!<br />
Firebase should be free for all shoutboxes. (The free version is quite limited, but we don't need much) Sign up <a href='http://firebase.com' target='_blank'>here</a>!<br />
<b>After you created your firebase, make sure to add the <a id="fbruleslnk2" href="javascript:show_rules();">Van2Shout security rules</a>!</b><br />
Database URL:&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $this->Form->Input('Plugin.Van2Shout.FBUrl'); ?><br />
Firebase secret:&nbsp;&nbsp;&nbsp;<?php echo $this->Form->Input('Plugin.Van2Shout.FBSecret'); ?><br />
(Leave both fields blank to switch back to MySQL)<br /><br />
<input type="submit" class="Button" style="margin-left:0px;" value="Save" /> <a id="fbruleslnk" href="javascript:show_rules();">Show me Van2Shout's Firebase rules</a> | <a href="javascript:reset_tokens();">Reset firebase tokens</a>
<div id="fbrules" style="display:none;">Go to <?php $url = C('Plugin.Van2Shout.FBUrl', ''); if($url != '') { echo "<a href='".$url."' target='blank'>your firebase</a>"; } else { echo "your firebase"; } ?> and paste the following code at the "Security" tab:<pre><?php echo file_get_contents(PATH_ROOT.DS.'plugins'.DS.'Van2Shout'.DS.'firebase'.DS.'rules.firebase'); ?></pre></div>
</div>
Firebase is a service which provides hyper-fast and flexible databases.<br />
The free plan should provide enough resources for all shoutboxes.<br />
Sign up at <b><a href='https://firebase.com' target='_blank'>firebase.com</a></b> and add the <b><a href="/<?php echo (Gdn::Request()->WebRoot().'/plugins/Van2Shout/firebase/rules.html'); ?>" class="SignInPopup">Firebase security rules</a></b><br />
<a href="javascript:reset_tokens();">Reset firebase tokens</a><br />
<br />
</div>

<table class="AltColumns">
<thead align="left">
<tr>
<th width="25%">Firebase</th><th></th>
</tr>
</thead>
<tbody>
<tr><td>Enable Firebase</td><td><?php echo $this->Form->CheckBox('Plugin.Van2Shout.Firebase.Enable', ''); ?></td></tr>
<tr><td>Firebase URL</td><td><?php echo $this->Form->Input('Plugin.Van2Shout.Firebase.Url'); ?></td></tr>
<tr><td>Firebase secret</td><td><?php echo $this->Form->Input('Plugin.Van2Shout.Firebase.Secret'); ?></td></tr>
</tbody>
</table>

<table class="AltColumns">
<thead align="left">
<tr>
<th width="25%">Option</th><th>Value</th>
</tr>
</thead>
<tbody>
<tr><td>Display on the discussions page</td><td><?php echo $this->Form->CheckBox('Plugin.Van2Shout.ContentAsset', ''); ?></td></tr>
<tr><td>Display on the discussions page</td><td><?php echo $this->Form->CheckBox('Plugin.Van2Shout.DisplayTarget.DiscussionsController', ''); ?></td></tr>
<tr><td>Disable timestamp</td><td><?php echo $this->Form->CheckBox('Plugin.Van2Shout.Timestamp', ''); ?></td></tr>
<tr><td>'Send' button text</td><td><?php echo $this->Form->Input('Plugin.Van2Shout.SendText'); ?></td></tr>
<tr><td>Timestamp colour<br />(Default: grey)</td><td><?php echo $this->Form->Input('Plugin.Van2Shout.TimeColour'); ?></td></tr>
Expand All @@ -56,31 +62,6 @@
</tbody>
</table>

<script type="text/javascript">
function show_rules()
{
document.getElementById('fbruleslnk').href = 'javascript:hide_rules();';
document.getElementById('fbruleslnk2').href = 'javascript:hide_rules();';
document.getElementById('fbruleslnk').innerHTML = 'Hide Van2Shout\'s Firebase rules';
document.getElementById('fbrules').style.display = 'inherit';
}

function hide_rules()
{
document.getElementById('fbruleslnk').href = 'javascript:show_rules();';
document.getElementById('fbruleslnk2').href = 'javascript:show_rules();';
document.getElementById('fbruleslnk').innerHTML = 'Show me Van2Shout\'s Firebase rules';
document.getElementById('fbrules').style.display = 'none';
}

function reset_tokens()
{
$.get(gdn.url('plugin/Van2ShoutData?reset_tokens=1'), function(data) {
gdn.informMessage("Tokens reset.");
});
}
</script>

<table class="AltColumns">
<thead align="left">
<tr>
Expand Down Expand Up @@ -109,3 +90,12 @@ function reset_tokens()
<?php
echo $this->Form->Close();
?>

<script type="text/javascript">
function reset_tokens()
{
$.get(gdn.url('plugin/Van2ShoutData?reset_tokens=1'), function(data) {
gdn.informMessage("Tokens reset.");
});
}
</script>

0 comments on commit 007c3c1

Please sign in to comment.