Welcome To myPHPNuke.com

  Create An Account Home  ·  Topics  ·  Stats  ·  Your Account  ·  Submit News  ·  Top 10 May 22, 2013  

  Main Menu

  Just SOME MPN Driven Sites!!

  What Is myPHPNuke?
myPHPNuke Introduction
Would you like to contribute to our website or software?

Just Click Here and tell us about yourself.
Printer Friendly Page   Printer Friendly Page Send this Story to a Friend  Send this story to a friend

Using PHP and Java Script in Blocks.
Kiril, 31 January 2002

How to use PHP and Java Script in Side Blocks. This is not the prettiest hack, but it works. Many users have asked how to use PHP and/or Java Script in blocks. Technically you can't, the only thing the blocks will allow is strict simple HTML without giving you problems. As with most everything in the world of coding, there is a way around this.

The following tutorial will show you how to insert a PHP file into a custom block so you can see how this works. This file can contain anything you want, for this demo we will create a custom user link block that does the following.



  • Provide a link so the user can check their Private Messages
  • Provide a link so the user can check for new forum posts since their last visit.
  • Provide a link to the user for checking their mail.


Now that we have our task outlined, lets get on with the coding.

1) Create a new file (userlinks.php). This is the file we will "include" in the custom block.

2) Now lets put something into this file. Cut and paste the code BETWEEN the START & END comments.

/*********** START OUR CODE ***********

!!! CODE !!!

<?php
    include_once("extention.inc");
    include_once("mainfile.$phpEx");
    echo "<br />";
    echo "<a href='viewpmsg.$phpEx' title='" . translate("Check to see if you have any new \nPrivate Messages since your last visit") . "'>" . translate("Check Your Private Messages") . "</a>";
    echo "<br /><br />\n";
    echo "<a href='mailbox.$phpEx' title='" . translate("Check your mailbox\nfor new messages") . "'>" . translate("Check Your Mail") . "</a>";
    echo "<br /><br />\n";
    echo "<a href='lastview.$phpEx' title='" . translate("Check to see if any new forum posts \nhave been made since your last visit") . "'>" . translate("Any New Forum Posts?") . "</a>";
    echo "<br /><br />\n";
?>

*********** END OUR CODE ***********/

Good deal, we have a new PHP file we can use in a custom block.

3) Save the file and upload it to your remote server into the root of your MPN install. Remember, you can "include" other PHP files, use Java Script, etc... in this file if you want. Basically you can do anything here, the only constraint will be the size of your block. Remember the default block width is 150 pixels, so keep this in mind when designing your custom block.

4) Now you will need to open your theme.php file for the theme that you are using on your site. If you want this work for all the themes you have available on your site, you will need to add this code to each and everyone of them. Thanks to Bharat Mediratta from the Gallery Team for this code.

Please follow the steps below.

a) Open your default theme.php file.

b) Scroll down the page until you find the function named "themesidebox".

c) Insert the following code after the " { " but before anything else.


/********* CUT BELOW *********

!!! CODE !!!


    if (@file_exists($content)) {
                 $fp = fopen ($content, "r");
                 $content = fread($fp, filesize($content));
                 fclose ($fp);
                 $content = "?>$content<?";
                 $content = eval($content);
        } else if (eregi("^http", $content)) {
                 $content = trim($content);
                 $fp = fopen ($content, "r");
                 $content = fread($fp, 65535);
                 fclose ($fp);
        }

********** END CODE ***********/

d) When your done the themesidebox function should look something like this:

/********** START COMPARE EXAMPLE ***********

!!! CODE !!!


    function themesidebox($title, $content) {
          if (@file_exists($content)) {
                 $fp = fopen ($content, "r");
                 $content = fread($fp, filesize($content));
                 fclose ($fp);
                 $content = "?>$content<?";
                 $content = eval($content);
         } else if (eregi("^http", $content)) {
                 $content = trim($content);
                 $fp = fopen ($content, "r");
                 $content = fread($fp, 65535);
                 fclose ($fp);
         }

         echo "<table><tr><td>\n";

********** REST OF THE CODE FOLLOWS **********/

e) Save the changed theme.php and upload it to the appropriate theme folder on your web server. Remember, this change MUST be added to ALL themes you have available for users on your site.

4) Now go to the blocks administration menu, create a new custom block and name it "User Links" or whatever you want.

5) Inside this block we want to use the code we just wrote, however we can't insert it directly, so instead we will call it using HTML.

The syntax is as follows (this is what you enter in your custom block):

http://yourdomain.com/path-to-MPN-Root/userlinks.php

6) Save the custom block and your done. Your probably saying, NO WAY, this can't work. Well, it does. :)

Now go and check out your handy work. Yup, it works.

Easy enough heh?

Kiril Threndor

Back to Main


[ Back to MPN 1.8.8 Tutorials | Sections Index ]



  ChatBox II
smartvicky >  
sailwell >  hi
sailwell >  any body in?
sailwell >  i have instalation problem
sailwell >  any one help me
duke-leto >  kiril are you on here?
santeriablooms29 >  hello good day....



Click here to open the chatbox...
0 people chatting right now.