WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.8 is now available!


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Templates, Menus & Design »
  • need a little assistance with coding
  • Print
Pages: [1]   Go Down

Author Topic: need a little assistance with coding  (Read 6512 times)

Offline crnogorac081

  • Posts: 2163
  • Gender: Male
need a little assistance with coding
« on: February 01, 2010, 09:44:08 AM »
Hi,

I am trying to insert dynamic JS into backend's footer

the code is in modify.php file and I used this from droplets, but it is not working..

Code: [Select]

$wb_page_data = str_replace('</body>',$dragscript."\n".'</body>', $wb_page_data );

Or this is working only with droplets ?

Could you please tell me how to make this work ?
Logged
Web developer

WebBird

  • Guest
Re: need a little assistance with coding
« Reply #1 on: February 01, 2010, 10:59:04 AM »
Just put your JS into backend_body.js. WB will load it automagically. (Needs WB 2.8 )
Logged

Offline crnogorac081

  • Posts: 2163
  • Gender: Male
Re: need a little assistance with coding
« Reply #2 on: February 01, 2010, 11:51:40 AM »
I know, but that doesnt solve the issue as I need to call a file:

Code: [Select]
<script type="text/javascript">
    $(document).ready(function(){

        $(function() {
            $("#dragableTable ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
                var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
                $.post("'.WB_URL.'/updateDB.php", order, function(theResponse){
                    $("#dragableResult").html(theResponse);
                });
            }
            });
        });

    });
</script>

So I need to have WB_URL variable inside..

I also trried to use a droplet, but it doesnt work in backend..
« Last Edit: February 01, 2010, 11:54:11 AM by crnogorac081 »
Logged
Web developer

WebBird

  • Guest
Re: need a little assistance with coding
« Reply #3 on: February 01, 2010, 01:48:23 PM »
I have an easy solution for this case. :-D

Create a backend.js, add:

Code: [Select]
function setVar( varname, text )
{
    eval(varname+"=\""+text+"\"");
}

In your modify.php, add somewhere to the HTML:

Code: [Select]
  <script type="text/javascript">setVar( 'WB_URL', '<?php echo WB_URL; ?>' );</script>

In your backend_body.js, use:

Code: [Select]
var WB_URL;
...
$.post( WB_URL+'/update...');
Logged

Offline crnogorac081

  • Posts: 2163
  • Gender: Male
Re: need a little assistance with coding
« Reply #4 on: February 01, 2010, 01:56:24 PM »
Thank mate, but I just found and tested a solution:

Code: [Select]
<?php
// This makes path to current  folder
$filepath=str_replace(basename($_SERVER[&#39;PHP_SELF&#39;]),"",__FILE__);

// if you are not sure where you are, you can uncomment this and see..
//echo $filepath;

// Now we write the code, just like in Droplets
$dragscript = &#39;$(document).ready(function(){ &#39;."\n"; 

$dragscript .= &#39;    $(function() { &#39;."\n";
$dragscript .= &#39;        $("#dragableTable ul").sortable({ opacity: 0.6, cursor: \&#39;move\&#39;, update: function() { &#39;."\n";
$dragscript .= &#39;            var order = $(this).sortable("serialize") + \&#39;&action=updateRecordsListings\&#39;; &#39;."\n";
$dragscript .= &#39;            $.post("&#39;.WB_URL.&#39;/updateDB.php", order, function(theResponse){ &#39;."\n";
$dragscript .= &#39;                $("#dragableResult").html(theResponse); &#39;."\n";
$dragscript .= &#39;            }); &#39;."\n";
$dragscript .= &#39;        } &#39;."\n";
$dragscript .= &#39;        }); &#39;."\n";
$dragscript .= &#39;    }); &#39;."\n";
$dragscript .= &#39; }); &#39;."\n";

// Now we set the filename in my case: backend_body.js (I needed this code to be written in JS, so I can getl  WB_URL from config.php file )

$myFile = $filepath.&#39;/backend_body.js&#39;;
$fh = fopen($myFile, &#39;w&#39;) or die("can&#39;t open file");
fwrite($fh, $dragscript);
fclose($fh);
?>


This is the tutorial how to have PHP code inside Java script (description for search)

Now just another question, will this fwrite work on every server ?

I keep learning php every day..

All best,
Ivan
« Last Edit: February 01, 2010, 01:59:32 PM by crnogorac081 »
Logged
Web developer

WebBird

  • Guest
Re: need a little assistance with coding
« Reply #5 on: February 01, 2010, 04:00:59 PM »
If you (which means in fact "the webserver process") have write permissions in that directory, it should work. With my solution you don't need to create a file dynamically, but it's your choice. ;)
Logged

Offline crnogorac081

  • Posts: 2163
  • Gender: Male
Re: need a little assistance with coding
« Reply #6 on: February 01, 2010, 04:08:24 PM »
Your function is much simplier, I am looking forward to use it in some other cases, but for this specific case I would need to change core code in WB backend theme for this to work...and I would really like to avoid that.. [im working on implementation of drag n drop reordering for modules..]

Well, you have permission to read/write/execute if you are loged in via backend, right ?

The main problem here is that I am working with Backend , so I must avoid to edit header and footer page.. And droplets cant help me..

Thanks a lot for assistance WebBird
« Last Edit: February 01, 2010, 04:32:44 PM by crnogorac081 »
Logged
Web developer

WebBird

  • Guest
Re: need a little assistance with coding
« Reply #7 on: February 01, 2010, 07:28:04 PM »
Quote from: crnogorac081 on February 01, 2010, 04:08:24 PM
Well, you have permission to read/write/execute if you are loged in via backend, right ?

WB Backend permissions <> file system permissions. :wink:

You don't have permissions on file system automatically if you're in WB backend. You should add some error handling to find out what's wrong.
Logged

Offline crnogorac081

  • Posts: 2163
  • Gender: Male
Re: need a little assistance with coding
« Reply #8 on: February 01, 2010, 07:43:52 PM »
Fortunately everything is working fine so far.

Now I am cleaning the code and after that I will post it so everyone can test this reordering..

Logged
Web developer

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Templates, Menus & Design »
  • need a little assistance with coding
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2