Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
Defcon
Regular
Regular


Joined: Mar 10, 2005
Posts: 90

PostPosted: Thu Aug 16, 2007 3:46 am Reply with quote

Hye all!!

I would like to develop a modules base on RavenNuke(tm) v2.20.00 requirement. Frankly, i already done develop song requester script using PHP script and now i would like to design it for RavenNuke(tm) v2.20.00 modules. Therefor i need to know & understand any "fundamental rules" and how to develop a modules base on RavenNuke(tm) v2.20.00 requirement.

Base on Module Creator - By Disipal Designs

Code:


<?php
/****************************************************************************/
/*  Generated by Module Creator - By Disipal Designs (www.disipal.net)      */
/*  PHP-Nuke Tools v4.00                                                    */
/****************************************************************************/
if (!defined('MODULE_FILE')) {
   die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
include("header.php");
define('INDEX_FILE', true);
OpenTable();
echo"<--- YOUR SCRIPT HERE --->";
CloseTable();
include("footer.php");

?>


So how bout RavenNuke(tm) v2.20.00? Any guide i must follow it? beside that i also need any URL + How to create modules reference . Thanxs for ur help/reply pall!
 
View user's profile Send private message Visit poster's website
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9456
Location: Arizona

PostPosted: Thu Aug 16, 2007 5:35 am Reply with quote

What you have above will work just fine. Simply replace the line

echo"<--- YOUR SCRIPT HERE --->";

with your own code for the module.

You may find that you will need to change some of your HTML to be XHTML compliant and/or might have to tweak any formatting that you may have hard coded.

I would also re-use the existing database connection by changing your database calls to use the $db object

There are plenty of examples of these things in existing RavenNuke modules.

Good luck!

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Defcon
PostPosted: Thu Aug 16, 2007 1:23 pm Reply with quote

montego wrote:
What you have above will work just fine. Simply replace the line

echo"<--- YOUR SCRIPT HERE --->";

with your own code for the module.

You may find that you will need to change some of your HTML to be XHTML compliant and/or might have to tweak any formatting that you may have hard coded.

I would also re-use the existing database connection by changing your database calls to use the $db object

There are plenty of examples of these things in existing RavenNuke modules.

Good luck!


Hye again montego!!!, thanxs for your feedback and i really appreciate it. Phew!! I still dont understand so much some of rules "how to develop a modules" for PHPNUKE. Maybe for some normal "echo" i can do it but for some dynamic scripting definitely i need someone to help me. huhuhu Here we go.. as like u see image before:

Image

And my code for that (Save as "index.php" inside modules folder name as "Song_Request"):

Code:


<?php
if (!defined('MODULE_FILE')) {
   die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
include("header.php");
include("modules/Song_Request/config.php");
OpenTable();
echo "Your ip is: ".$ip."<br />";
if (isset($_PxST['submit'])) {
if (empty($_PxST['song'])) {
echo "Sorry, you haven't supplied the song title!<br />";
$reg = "no";
}
if (empty($_PxST['artist'])) {
echo "Sorry, you haven't supplied the artists name!<br />";
$reg = "no";
}
if (empty($_PxST['name'])) {
echo "Sorry, you haven't supplied your name<br />";
$reg = "no";
}

  $sql = "SELECT COUNT(*) FROM request_song WHERE ip='{$ip}'";
  $result = mysql_query($sql);
  if (mysql_result($result, 0) > 3) {
echo "Sorry, your ip has already wished for one song, you can not wish for <br />another until the DJ's have seen your request!<br />";
$reg = "no";
}
if ($reg == "yes") {
    $sql = "INSERT INTO request_song(song, artist, name, ip)
            VALUES('{$_PxST['song']}', '{$_PxST['artist']}', '{$_PxST['name']}', '{$ip}')";
    mysql_query($sql);
}
}
echo "<form action='modules/Song_Request/index.php' ethodm='POST'>";
echo "<table>";
echo "<tr><td>Song title: </td><td><input type=\"text\" name=\"song\" value=\"\"></td></tr>";
echo "<tr><td>Artist: </td><td><input type=\"text\" name=\"artist\" value=\"\"></td></tr>";
echo "<tr><td>Your name: </td><td><input type=\"text\" name=\"name\" value=\"\"></td></tr>";
echo "</table>";
echo "<input type='submit' name='submit' value='Send!'>";
echo "</form>";
CloseTable();
include("footer.php");
?>


ethodm = method
$_PxST = $_POST


But after i fill up that form n submit i got error like image below:

Image

Can someone tell me what to do?

Thanxs

*p/s For our infomation that PHP script is 100% working if running without PHPNUKE engine/stand alone
 
evaders99
Former Moderator in Good Standing


Joined: Apr 30, 2004
Posts: 3221

PostPosted: Thu Aug 16, 2007 11:09 pm Reply with quote

Do not use a text field with the name "name" - it is reserved for phpNuke's usage of a module name

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Defcon
PostPosted: Fri Aug 17, 2007 2:03 am Reply with quote

evaders99 wrote:
Do not use a text field with the name "name" - it is reserved for phpNuke's usage of a module name


Hye evader99!!! Yes u right!!! Image Thanxs a lot for ur reply!!!
 
Defcon
PostPosted: Fri Aug 17, 2007 2:39 am Reply with quote

Ok now i already done with submit request page, thanxs to evader99 help me to solve it. So i would like to continue at another section. A page that view a song that already submitted by requester. On my normal PHP page i already done like image below:

Image

Where my output on table got a field of:

-ID
-Song
-Artist
-Requested by
-IP
-Delete

Ok now i got a problem to "embed" it as PHPNUKE modules. After i put a code as PHPNUKE modules code that page become blank. Here is my code, look simple but i cant trace where i wrong. Thanxs guys!!

Code:


<?php
if (!defined('MODULE_FILE')) {
   die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
include("header.php");
OpenTable();
echo "<table width='600' border='1'>";
echo "<tr><td>ID</td><td>Song</td><td>Artist</td><td>Requested by</td><td>IP</td><td>Delete</td></tr>";
if ($_GET['del']) {
$delete = $_GET['del'];
$delque = "DELETE FROM request_song WHERE id='{$delete}'";
mysql_query($delque);
}
$query = "SELECT * FROM request_song ORDER BY id ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$id = $row['id'];
$song = $row['song'];
$artist = $row['artist'];
$nama = $row['nama'];
$ip = $row['ip'];
echo "<tr><td>".$id."</td><td>".$song."</td><td>".$artist."</td><td>".$nama."</td><td>".$ip."</td><td><a href='?del=".$id."'>Delete</a></td></tr>";
CloseTable();
include("footer.php");
?>
 
Gremmie
Former Moderator in Good Standing


Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Fri Aug 17, 2007 6:58 am Reply with quote

Turn on error reporting in your config.php and re-run it.

You should also protect against SQL injection:

$delete = intval($_GET['del']);

_________________
Only registered users can see links on this board! Get registered or login! - An Event Calendar for PHP-Nuke
Only registered users can see links on this board! Get registered or login! - A Google Maps Nuke Module 
View user's profile Send private message
CodyG
Life Cycles Becoming CPU Cycles


Joined: Jan 02, 2003
Posts: 712
Location: Vancouver Island

PostPosted: Fri Aug 17, 2007 9:33 am Reply with quote

Great Topic!
worship

_________________
"We want to see if life is ubiquitous." D.Goldin 
View user's profile Send private message
Defcon
PostPosted: Fri Aug 17, 2007 10:03 am Reply with quote

Gremmie wrote:
Turn on error reporting in your config.php and re-run it.

You should also protect against SQL injection:

$delete = intval($_GET['del']);


Hye Gremmie, thanxs for ur posting and also ur security advice. i really appreciate it. Thanxs a lot dude!

Ok after i turn on reporting in config.php, detecting where that error and fix it. It's running!! But only can view only 1 requested data for all. For example like image below:

Image

It supposed be like this (running on normal PHP page scripting)

Image

Here is my full script for this modules

Code:


<?php
if (!defined('MODULE_FILE')) {
   die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
include("header.php");
include("modules/Song_Request/config.php");
OpenTable();
echo "<table width='600' border='1'>";
echo "<tr><td>ID</td><td>Song</td><td>Artist</td><td>Requested by</td><td>IP</td><td>Delete</td></tr>";
if ($_GET['del']) {
$delete = intval($_GET['del']);
$delque = "DELETE FROM request_song WHERE id='{$delete}'";
mysql_query($delque);
}
$query = "SELECT * FROM request_song ORDER BY id ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$id = $row['id'];
$song = $row['song'];
$artist = $row['artist'];
$nama = $row['nama'];
$ip = $row['ip'];
}
echo "<tr><td>".$id."</td><td>".$song."</td><td>".$artist."</td><td>".$nama."</td><td>".$ip."</td><td><a href='?del=".$id."'>Delete</a></td></tr>";
CloseTable();
include("footer.php");
?>


Base on what i understand, scripting on that modules look like i have to create "auto generate" table for all of requested song. But on my script i only put 1 only for example:

Code:


echo "<tr><td>".$id."</td><td>".$song."</td><td>".$artist."</td><td>".$nama."</td><td>".$ip."</td><td><a href='?del=".$id."'>Delete</a></td></tr>";


On normal PHP page i will generate automatically table base on how many request submitted. Can someone help me by this issue? Thanxs
 
Gremmie
PostPosted: Fri Aug 17, 2007 10:33 am Reply with quote

You need to move your echo statement inside the while loop. Then it will echo a line (a table row) for each row in the database query. As it is now, you are only outputing the last row in the query.

Outside of the while loop you then need to close your <table> that you opened earlier.
 
Defcon
PostPosted: Fri Aug 17, 2007 12:22 pm Reply with quote

Gremmie wrote:
You need to move your echo statement inside the while loop. Then it will echo a line (a table row) for each row in the database query. As it is now, you are only outputing the last row in the query.

Outside of the while loop you then need to close your <table> that you opened earlier.


Yo Gremmie ImageImageImage!!!!

It works!! See image below!!

Image

Thanxs a lot bro!!

Ok now on delete url path i didnt get a righ path. Like image below:

Image

Let say if i click on that delete url it will goes like this for example:
Only registered users can see links on this board! Get registered or login!

*29 = is a ID number

Where my code for delete is:

Code:


<td><a href='?del=".$id."'>Delete</a></td>


So what a right path url should i put here for this modules?

Beside that, may i know on PHPNUKE let say from index.php file to link/hyperlink with other page in a same modules folder what's a right hyperlink path/code? Some modules i see they using &file=other_page ( modules.php?name=modules_name&file=other_page ) and some other (sorry i forget that key path/words) So which one is a best way n more practical?

Well again all of my friends here, thanxs a lot i really appreciate urs!!
 
Gremmie
PostPosted: Fri Aug 17, 2007 12:48 pm Reply with quote

You want the delete link to look like this:
Code:


modules.php?name=Your_Module_Name&del=29


(Also remember to use &amp; for & in your generated <a> tags for HTML compliance).

Nuke uses the name parameter to "route" to your module. If you do not supply a file parameter, it loads your module's index.php file. If you do supply a file parameter, it will load the file named by the parameter.

For example:

modules.php?name=My_Module

will load modules/My_Module/index.php

modules.php?name=My_Module&file=myFile

will load modules/My_Module/myFile.php

Hope that helps.
 
Defcon
PostPosted: Mon Aug 27, 2007 1:47 am Reply with quote

Hye Gremmie!!! Thanxs a lot for ur explaination, really help me a lot during this modules development. PHP scripting for PHPNUKE engine really cool :p

Ok now i got a question again, what i want to do now is a section for DJ login. On normal PHP scripting it working like image below where DJ can login and web visitor can see who's currently login as DJ:

Image
DJ Login interface

Image
DJ Login successfully

Image
PHP page where web visitor can see who's currently as DJ and others info

So from my normal PHP scripting i "embed" as PHPNuke modules like image below.

Image

That page running without any error but when DJ put a correct password it failed to login.

Here is a normal PHP code for DJ Login page:

Code:


<?php
include ("config.php");   

if ($mode == "1") {

if (!isset($dj)) {
echo "<form name=\"form1\" ethodm=\"PxST\" action=\"update2.php\">
  <p><b>Welcome to the DJ select page. Please choose your name and input your password.</b><br>
    <select name=\"newdj\" id=\"newdj\">
    <option>--Choose Your Name--</option>";
$query="SELECT * FROM currentdj ORDER BY `dj` ASC";
$result=mysql_query($query);
   while($row = mysql_fetch_array($result)) {
      $edj = "$row[dj]";
      $ename = "$row[djxname]";
       echo "<option value=\"$edj\">$ename</option>";
    }
echo "</select>
      <b>Password: </b>
    <input name=\"password\" type=\"password\" id=\"password\">
</p>
  <p>
    <input type=\"submit\" name=\"Submit\" value=\"Update DJ\">
</p>
</form>";
 } else {
echo "<form name=\"form1\" ethodm=\"PxST\" action=\"update2.php\">
<input type=\"hidden\" value=\"$dj\" name=\"olddj\">
  <p><b>$djxname is still signed on. If you are $djxname, please input your password to sign off.</b><br>
<b>Name: </b>$djxname
      <b>Password: </b>
    <input name=\"password1\" type=\"password\" id=\"password1\"><br>You may also contact $adminname for an override if needed.
</p>
  <p>
    <input type=\"submit\" name=\"Submit\" value=\"Update DJ\">
</p>
</form>";
 }
 } else {
 echo "<b>DJ Status is currently in Automatic mode. To switch to Manual mode, have $adminname change the setting in the administration panel.</b>";
 }
 echo "<br><br><font size=\"-1\"><strong>Powered by DJ Status v$version </strong></font>";
 ?>



This is a normal PHP code for DJ Login authentic process:

Code:


<?php

include ("config.php");

if ($mode == "1") {

if (isset($dj)) {

   $query="SELECT * FROM currentdj WHERE dj = '$dj'";
   $result=mysql_query($query);
   while($row = mysql_fetch_array($result)) {
        $pass = "$row[password]";
}

$password1 = $_PxST['password1'];

if (("$password1" == "$pass") or ("$password1" == "$adminpass")) {


   $resultID = mysql_query("UPDATE currentdj SET active = '0' WHERE dj = '$dj'") or die(mysql_error());
   if ($resultID == TRUE) {
      print "DJ $djxname has been set to inactive. (SUCCESSFUL)";
   } else {
      print "DJ $djxname is still set to active, please try again. (NOT SUCCESSFUL)";
   }
} else {
echo "<b>INCORRECT PASSWORD</b>";
}   
} else {
///////////////////////////////////////////////////
   $query="SELECT * FROM currentdj WHERE dj = '$newdj'";
   $result=mysql_query($query);
   while($row = mysql_fetch_array($result)) {
        $pass = "$row[password]";
}       

$password = $_PxST['password'];

if (("$password" == "$pass") or ("$password" == "$adminpass"))  {



   $resultID = mysql_query("UPDATE currentdj SET active = '1' WHERE dj = '$newdj'") or die(mysql_error());
   if ($resultID == TRUE) {
      print "You (DJ #$newdj) have been set to active. (SUCCESSFUL)";
   } else {
      print "You (DJ #$newdj) have NOT been set to active, please try again. (NOT SUCCESSFUL)";
   }
   
} else {
echo "<b>INCORRECT PASSWORD</b>";
}
}
 } else {
 echo "<b>DJ Status is currently in Automatic mode. To switch to Manual mode, have $adminname change the setting in the administration panel.</b>";
 }
 echo "<br><br><font size=\"-1\"><strong>Powered by DJ Status v$version </strong></font>";
   ?>



ethodm = method
PxST = POST


Can someone here kindly tell me where is my mistake? Thanxs you.

*p/s i already turn on error reporting in config.php but for this issue it didnt show up any error reporting.
 
evaders99
PostPosted: Mon Aug 27, 2007 1:59 pm Reply with quote

While phpNuke's config.php does contain the data to connect to the database, it does not actually create the database connection. You'd have to include phpNuke's mainfile.php to open an active database connection.

(It is preferred that you use phpNuke's database abstraction layer)
Code:


$db->sql_query
Rather than
mysql_query
 
montego
PostPosted: Tue Aug 28, 2007 6:00 am Reply with quote

Also, btw, when you include mainfile.php, you will not want to re-include config.php as it has already been taken care of by bringing in mainfile.php.
 
Defcon
PostPosted: Tue Aug 28, 2007 7:40 am Reply with quote

Hye evaders99 & montego, thanxs again for ur reply. I really sorry because i didnt explain clearly that config.php file inside this code:

Code:


include ("config.php");


Actually that config.php contains with a script to allow connection with Shoutcast server. Here is full syntax:

Code:


<?php

# Shoutcast
$scdef = "RADIO-OFFLINE";       // Default station name to display when server or stream is down
$scip = "radio.pukipukimak.net";       // ip or url of shoutcast server
$scport = "8008";       // port of shoutcast server
$scpass = "pukipuki2007";       // password to shoutcast server

# Admin Panel
$adminname = "admin";    // Name to display when in manual mode
$adminpass = "pass1234";   // Password for the administration panel

$version = "1.0.2";   

// Shoutcast Server Stats
$scfp = @fsockopen("$scip", $scport, &$errno, &$errstr, 10);
 if(!$scfp) {
  $scsuccs=1;
# echo'<strong>'.$scdef.' is Offline</strong><br>';
 }
if($scsuccs!=1){
 fputs($scfp,"GET /admin.cgi?pass=$scpass&mode=viewxml HTTP/1.0\r\nUser-Agent: DJ Status v$version \r\n\r\n");
 while(!feof($scfp)) {
  $page .= fgets($scfp, 1000);
 }
//define  xml elements
 $loop = array("STREAMSTATUS", "BITRATE", "SERVERTITLE", "CURRENTLISTENERS", "AIM", "ICQ");
 $y=0;
 while($loop[$y]!=''){
  $pageed = ereg_replace(".*<$loop[$y]>", "", $page);
  $scphp = strtolower($loop[$y]);
  $$scphp = ereg_replace("</$loop[$y]>.*", "", $pageed);
  if($loop[$y]==SERVERGENRE || $loop[$y]==SERVERTITLE || $loop[$y]==SONGTITLE || $loop[$y]==SERVERTITLE || $loop[$y]==AIM || $loop[$y]==ICQ)
   $$scphp = urldecode($$scphp);

// uncomment the next line to see all variables
#echo'$'.$scphp.' = '.$$scphp.'<br>';
  $y++;
 }
//end intro xml elements

//get song info and history
 $pageed = ereg_replace(".*<SONGHISTORY>", "", $page);
 $pageed = ereg_replace("<SONGHISTORY>.*", "", $pageed);
 $songatime = explode("<SONG>", $pageed);
 $r=1;
 while($songatime[$r]!=""){
  $t=$r-1;
  $playedat[$t] = ereg_replace(".*<PLAYEDAT>", "", $songatime[$r]);
  $playedat[$t] = ereg_replace("</PLAYEDAT>.*", "", $playedat[$t]);
  $song[$t] = ereg_replace(".*<TITLE>", "", $songatime[$r]);
  $song[$t] = ereg_replace("</TITLE>.*", "", $song[$t]);
  $song[$t] = urldecode($song[$t]);
  $dj[$t] = ereg_replace(".*<SERVERTITLE>", "", $page);
  $dj[$t] = ereg_replace("</SERVERTITLE>.*", "", $pageed);
$r++;
 }
//end song info

fclose($scfp);
}

if (file_exists($filename))  {
$nodb = "1";
}

if (isset($nodb) == FALSE) {
include ("dbconnect.php");
}

?>


Ok now to i rename that file with radioxconnect.php where i wish nobody will missunderstanding that file with config.php inside PHPNUKE engine.

So that code supposed to be like this:

Code:


<?php

include ("radioxconnect.php");

if ($mode == "1") {

if (isset($dj)) {

   $query="SELECT * FROM currentdj WHERE dj = '$dj'";
   $result=mysql_query($query);
   while($row = mysql_fetch_array($result)) {
        $pass = "$row[password]";
}

$password1 = $_PxST['password1'];

if (("$password1" == "$pass") or ("$password1" == "$adminpass")) {


   $resultID = mysql_query("UPDATE currentdj SET active = '0' WHERE dj = '$dj'") or die(mysql_error());
   if ($resultID == TRUE) {
      print "DJ $djxname has been set to inactive. (SUCCESSFUL)";
   } else {
      print "DJ $djxname is still set to active, please try again. (NOT SUCCESSFUL)";
   }
} else {
echo "<b>INCORRECT PASSWORD</b>";
}   
} else {
///////////////////////////////////////////////////
   $query="SELECT * FROM currentdj WHERE dj = '$newdj'";
   $result=mysql_query($query);
   while($row = mysql_fetch_array($result)) {
        $pass = "$row[password]";
}       

$password = $_PxST['password'];

if (("$password" == "$pass") or ("$password" == "$adminpass"))  {



   $resultID = mysql_query("UPDATE currentdj SET active = '1' WHERE dj = '$newdj'") or die(mysql_error());
   if ($resultID == TRUE) {
      print "You (DJ #$newdj) have been set to active. (SUCCESSFUL)";
   } else {
      print "You (DJ #$newdj) have NOT been set to active, please try again. (NOT SUCCESSFUL)";
   }
   
} else {
echo "<b>INCORRECT PASSWORD</b>";
}
}
 } else {
 echo "<b>DJ Status is currently in Automatic mode. To switch to Manual mode, have $adminname change the setting in the administration panel.</b>";
 }
 echo "<br><br><font size=\"-1\"><strong>Powered by DJ Status v$version </strong></font>";
   ?>



ethodm = method
PxST = POST


Until today i cant find out what's my mistake, it is because that include ("radioxconnect.php"); got a "incompatible variable" that already be use inside PHPNUKE or else?

Btw montego, thanxs for your posting. However i would like to double confirm with you it is you mean by last posting is when we include mainfile.php that file already "include" with config.php?

Thanxs.
 
montego
PostPosted: Tue Aug 28, 2007 7:14 pm Reply with quote

I would look at an existing module's index.php to see how it opens up. Pattern off of that. You should see an include or require up front (use include_once or better require_once) of mainfile.php. You will need this in order to use the $db object to make your calls to your existing tables within your nuke database.

For your shoutcast server connection, it may be entirely possible that your host does not allow the fsockopen() function of PHP. Some host disable this. Just wanted to mention this in case you isolate an issue being that specific call. BTW, while you are in development of the script, you will want to lose the "@" sign in front of that function call so that you see any errors that call produces.

Another thing to keep in mind is that the nuke modules are "called" through the following type of URL:
Only registered users can see links on this board! Get registered or login! other parameters.

What does this mean to YOU as a module developer? ALL includes within your module code must be relative to where modules.php is at, which is in your web root. Therefore, be careful to make sure your inclusion of scripts that are under a different directory than modules.php is relative... Wink
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©