I went through tidy and did all the corrections I could find.
User side should be 100%
Admin side had some left in the theme itself....but the MOD should be clean anyway.
Thanks for the help!
Dawg
New RN_Video/Index.php
Code:
<?php
/**********************************************/
/* RN Video by Dawg
/* Version 1.2 Beta
/* This should NOT be used in Production Sites
/*Help and Support at http://www.ravenphpscripts.com
/**********************************************/
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);
// $index = 0;
// $hideleft=1;
$admingid= '25'; //(The number of posts before people can add videos)
include('header.php');
global $user,$cookie,$prefix,$nukeuser,$db,$prefix;
cookiedecode($user);
$username = $cookie[1];
if ($username == "") {
$username = "Anonymous";
}
if (is_user($user)) {
list($uid, $username) = explode(":", $nukeuser);
$querystr = "SELECT user_posts FROM ".$prefix."_users WHERE user_id=$uid" ;
$result = $db->sql_query($querystr) ;
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
$postcount = $row[0];
echo $postcount;
}
if (!isset($op)) $op = '';
switch($op) {
default:
display_video();
break;
case list_video:
list_video();
break;
case list_single_category:
list_single_category();
break;
break;
case video_admin_menu:
video_admin_menu();
}
die();
///////////////////////////////////////// START ADMIN MENU /////////////////////////////////
function video_admin_menu() {
global $postcount, $admingid,$db,$prefix;
?>
<br />
<center>
<a href='modules.php?name=RN_Video&file=user_admin&op=user_add_video_main'><font size='3'>User Video Admin</font></a>
|
<a href='modules.php?name=RN_Video&file=user_admin&op=user_add_video'><font size='3'>Add Video</font></a>
|
<a href='modules.php?name=RN_Video&file=user_admin&op=user_edit_video'><font size='3'>Edit YOUR Videos</font></a>
|
<a href='modules.php?name=RN_Video&file=user_admin&op=user_edit_video'><font size='3' color='#ff0000'>Delete YOUR Videos</font></a>
</center>
<br />
<?
}
///////////////////////////////////////// FINISH ADMIN MENU /////////////////////////////////
///////////////////////////////////////// START NAV MENU /////////////////////////////////
function nav_video() {
global $postcount, $admingid,$db,$prefix;
if ($postcount>=$admingid) {
video_admin_menu();
}
?>
<br />
<center>
<a href='modules.php?name=RN_Video'><font size='3'>Video Home</font></a>
|
<a href='modules.php?name=RN_Video&op=list_single_category'><font size='3'>List Single Category</font></a>
|
<a href='modules.php?name=RN_Video&op=list_video'><font size='3' color='#ff0000'>Category View</font></a>
</center>
<?
}
///////////////////////////////////////// FINISH NAV MENU /////////////////////////////////
///////////////////////////////////////// Start MOST RECENT /////////////////////////////////
function display_video() {
OpenTable();
global $user,$cookie,$prefix,$nukeuser,$db,$prefix;
?>
<center>
<br /><font size='6' color='#0000ff'>Most Recent Videos</font><br />
</center>
<?
nav_video();
?>
<br /><hr width='80%' /><br />
<table width="100%">
<tr>
<?
$query ="SELECT video FROM ".$prefix."_rnvideo WHERE aut='1'";
$result = $db->sql_query($query)
or die ("invalid query in video display");
//$result= $db->sql_query($query);
$rows=$db->sql_numrows($result);
//// Set number of Videos per page here
$ppp=10;
$nop= ceil($rows / $ppp);
$z=0;
echo "<td><p><font size='2'>Page : </font>";
for ($i = 1 ; $i <= $nop ; $i++)
{
echo " <a href='/modules.php?name=RN_Video&page=$i'><font size=2> $i </font></a> ";
}
echo "</p></td>";
if (isset($_GET['page'])){$page = $_GET['page'];}else{$page = 1;}
$start= ($page - 1) * $ppp;
$ranking=0;
$ranking=(($ranking+$ppp)*$page)-($ppp-1);
$query="SELECT video,title,code,counter FROM ".$prefix."_rnvideo WHERE aut='1' ORDER BY time DESC LIMIT $start,$ppp";
$result = $db->sql_query($query);
while($row=$db->sql_fetchrow($result))
{
$video=$row['0'];
$title=$row['1'];
$code=$row['2'];
$counter=$row['3'];
if ($z % 2 != 1)
{
echo "<tr align='center'>";
}
?>
</table><br /><hr width='80%' /><br />
<?
CloseTable();
include('footer.php');
}
///////////////////////////////////////// End List Categories /////////////////////////////////
///////////////////////////////////////// Begin List Single Catergory/////////////////////////////////
function list_single_category() {
OpenTable();
global $user,$cookie,$prefix,$nukeuser,$db,$prefix;
?>
<center>
<br /><font size='6' color='#0000ff'>List Single Categories</font><br />
</center>
<?
nav_video();
?>
<br /><hr width='80%' /><br />
<table width="100%">
<tr>
<?
///// SET CATEGORY HERE BY ID
$value="89";
/// THIS NEEDS TO BE FIXED
$query ="SELECT video FROM ".$prefix."_rnvideo WHERE aut='1' AND category='$value'";
//$query ="SELECT video FROM ".$prefix."_rnvideo WHERE category='73'";
$result = $db->sql_query($query)
or die ("invalid query in video display");
$rows=$db->sql_numrows($result);
// echo "ROWS = $rows";
//// Set number of Videos per page here
$ppp=10;
$nop= ceil($rows / $ppp);
// echo "NOP=$nop";
$z=0;
echo "<td><p><font size='2'>Page : </font>";
for ($i = 1 ; $i <= $nop ; $i++)
{
echo " <a href='/modules.php?name=RN_Video&op=list_single_category&page=$i'><font size=2> $i </font></a> ";
}
echo "</p></td>";
if (isset($_GET['page'])){$page = $_GET['page'];}else{$page = 1;}
$start= ($page - 1) * $ppp;
$ranking=0;
$ranking=(($ranking+$ppp)*$page)-($ppp-1);
$query="SELECT video,title,code,counter FROM ".$prefix."_rnvideo WHERE aut='1' ORDER BY time DESC LIMIT $start,$ppp";
$result = $db->sql_query($query);
while($row=$db->sql_fetchrow($result))
{
$video=$row['0'];
$title=$row['1'];
$code=$row['2'];
$counter=$row['3'];
if ($z % 2 != 1)
{
echo "<tr align='center'>";
}
<?php
/**********************************************/
/* RN Video by Dawg
/* Version 1.2 Beta
/* This should NOT be used in Production Sites
/*Help and Support at http://www.ravenphpscripts.com
/**********************************************/
if (!eregi("admin.php", $_SERVER['PHP_SELF'])) { die ("Access Denied"); }
// $hideleft= "1";
include_once("header.php");
$querystr = "SELECT radminsuper, admlanguage FROM ".$prefix."_authors where aid='$aid'";
$result = $db->sql_query($querystr, $db) or die ("invalied query");
list($radminsuper) = $db->sql_fetchrow($result);
if ($radminsuper==1)
{
switch($op) {
case "admin_video_main":
admin_video_main();
break;
case "add_video_nav":
add_video_nav();
break;
case "edit_bottom_nav":
edit_bottom_nav();
break;
case "Sanitizer":
Sanitizer();
break;
case "add_video":
add_video();
break;
case "add_video2":
add_video2();
break;
case "edit_video":
edit_video();
break;
case "edit_video2":
edit_video2();
break;
case "edit_video3":
edit_video3();
break;
case "admin_category_display":
admin_category_display();
break;
case "admin_category_delete":
admin_category_delete();
break;
case "admin_category_edit":
admin_category_edit();
break;
case "admin_category_edit2":
admin_category_edit2();
break;
case "admin_category_add":
admin_category_add();
break;
case "admin_category_add2":
admin_category_add2();
break;
}
}
else {
OpenTable();
echo "<center>
<font size='3'>Sorry Dude, You Do NOT have Permission to use this feature</font>
<br /><br />
<font size='3'>Contact your Site Admin to be included in this Group</font>
<br /><br />
<a href='modules.php?name=RN_Video'><font size='3'>RN Video Main Page</font></a>
</center>";
CloseTable();
include('footer.php');
}
admin_video_main();
function test()
{
global $admin, $bgcolor2, $prefix, $db,$user,$cookie,$nukeuser;
include_once("header.php");
OpenTable();
?>
<br /><hr width='80%' />
<div align="center">
<p><strong><font size="5"><br />
<font color="#0000FF">Howdy </font></font></strong></p>
<p><img src="modules/RN_Video/images/RN_Video.png" width="400" height="294" /></p>
<p><strong><font color="#0000FF" size="5">Pick a Link above to get started </font></strong><br />
</p>
</div>
<?
CloseTable();
include('footer.php');
}
<?
edit_bottom_nav();
CloseTable();
include('footer.php');
}
////////////////////// Start Edit Video ///////////////////////////
// echo "User ID = $uid";
$user_id = $uid;
// echo "User ID = $user_id";
$query="SELECT video FROM ".$prefix."_rnvideo ORDER BY video DESC";
$result= $db->sql_query($query);
$rows=$db->sql_numrows($result);
if (isset($_GET['page'])){$page = $_GET['page'];}else{$page = 1;}
$start= ($page - 1) * $ppp;
$query="SELECT * FROM ".$prefix."_rnvideo ORDER BY video DESC LIMIT $start,$ppp";
$result=$db->sql_query($query);
while($row=$db->sql_fetchrow($result))
{
<center>
<font size='1'>Page generated in <? $end=microtime();$lapsus=($end-$start); echo $lapsus; ?> seconds
<br />
<font color='#ff0000'><? $time=date("D, d M Y - H:i");echo $time; ?> Server Time</font>
</center>
<?
CloseTable();
include('footer.php');
}
////////////////////// End Edit Video ///////////////////////////
////////////////////// End Edit Video 2///////////////////////////
function edit_video2() {
global $user,$cookie,$prefix,$nukeuser,$db,$prefix;
cookiedecode($user);
$username = $cookie[1];
list($uid, $username) = explode(":", $nukeuser);
$code=Sanitizer($code['0']);
// echo "Code = $code";
///////////////////////////////////////////////////////// END IF /////////////////////////////////////////////////////
Joined: Mar 30, 2006 Posts: 2456 Location: Pittsburgh, Pennsylvania
Posted:
Tue Aug 10, 2010 4:52 pm
Found the problem. You should be using < ?php ? > instead of < ? ? >. Some people my disagree with me, but I would sugest to people not to do this at all. Simply just echo the html out.
I know you are still working on this, but you really need to indent you code better. It is just about impossible to follow.
Found the problem. You should be using < ?php ? > instead of < ? ? >. Some people my disagree with me, but I would sugest to people not to do this at all. Simply just echo the html out.
I know you are still working on this, but you really need to indent you code better. It is just about impossible to follow.
I'm still having problems will report back later.
Thank You for any and all feedback.
Give me a few mins and I will indent it correctly....or so I think...
Joined: Mar 30, 2006 Posts: 2456 Location: Pittsburgh, Pennsylvania
Posted:
Tue Aug 10, 2010 6:40 pm
First thing is that you should not have case statements for "utility functions" like Sanitizer. I'm only going to mention few things to get you started ,and we can refine it later once you have made corrections, removed unneeded code and functions, and general code clean up.
1. I do not think you should be using a function to "generally" filter your variables. You should just validate them as you use them.
2. You need to read this article about MagicQuotes.
Only registered users can see links on this board! Get registered or login to the forums!
3. Instead of strip_tags use the following instead. It will take care of conditionally removing MagicQuotes as discussed above.
4. You do not have to do check_html() on every variable. If it is supposed to be a number just use intval() on it. If it is not an integer it will return 0.
5. htmlentites and htmlspecialchars can get a little tricky, but generally speaking you should only be using these when displaying info on the screen. Either from the user or from the database.
6. addslashes() should only be used when variables are being inserted or used to query the database. You should not do this to variables you are displaying on the screen. You would have to addslashes later if you are doing both.
I hope you got all that If not just ask and later on we can dig a little deeper.
you really need to indent you code better. It is just about impossible to follow.
I worked my way through the main index...and indented the code. I could not really find ANYTHING that said do this like XYZ....so I tried to go about it in a logical fashion....
If I did not get it right...PLEASE CORRECT ME...Show me right and I will do it right.
You talked about the <? and ?> so I changed all of them to <?php
I am still opening and closing....but once we hit the end of all of this....I will go through and echo everything. To me it is easier to write it this way so that when I make changes I can test the code real easy.
Code:
<?php
/**********************************************/
/* RN Video by Dawg
/* Version 1.0 Beta
/* This should NOT be used in Production Sites
/*Help and Support at http://www.ravenphpscripts.com
/**********************************************/
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);
$index = 0;
$hideleft=1;
$admingid= '25'; //(The number of posts before people can add videos)
include('header.php');
global $user,$cookie,$prefix,$nukeuser,$db,$prefix;
cookiedecode($user);
$username = $cookie[1];
if ($username == "")
{
$username = "Anonymous";
}
if (is_user($user))
{
list($uid, $username) = explode(":", $nukeuser);
$querystr = "SELECT user_posts FROM ".$prefix."_users WHERE user_id=$uid" ;
$result = $db->sql_query($querystr) ;
if (!$result)
{
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
$postcount = $row[0];
echo $postcount;
}
if (!isset($op)) $op = '';
switch($op)
{
default:
display_video();
break;
case list_video:
list_video();
break;
case list_single_category:
list_single_category();
break;
case video_admin_menu:
video_admin_menu();
break;
}
die();
///////////////////////////////////////// START ADMIN MENU /////////////////////////////////
function video_admin_menu()
{
global $postcount, $admingid,$db,$prefix;
?>
<br />
<center>
<a href='modules.php?name=RN_Video&file=user_admin&op=user_add_video_main'><font size='3'>User Video Admin</font></a>
|
<a href='modules.php?name=RN_Video&file=user_admin&op=user_add_video'><font size='3'>Add Video</font></a>
|
<a href='modules.php?name=RN_Video&file=user_admin&op=user_edit_video'><font size='3'>Edit YOUR Videos</font></a>
|
<a href='modules.php?name=RN_Video&file=user_admin&op=user_edit_video'><font size='3' color='#ff0000'>Delete YOUR Videos</font></a>
</center>
<br />
<?php
}
///////////////////////////////////////// FINISH ADMIN MENU /////////////////////////////////
///////////////////////////////////////// START NAV MENU /////////////////////////////////
function nav_video()
{
global $postcount, $admingid,$db,$prefix;
if ($postcount>=$admingid)
{
video_admin_menu();
}
?>
<br />
<center>
<a href='modules.php?name=RN_Video'><font size='3'>Video Home</font></a>
|
<a href='modules.php?name=RN_Video&op=list_single_category'><font size='3'>List Single Category</font></a>
|
<a href='modules.php?name=RN_Video&op=list_video'><font size='3' color='#ff0000'>Category View</font></a>
</center>
<?php
}
///////////////////////////////////////// FINISH NAV MENU /////////////////////////////////
///////////////////////////////////////// Start MOST RECENT /////////////////////////////////
function display_video()
{
OpenTable3();
global $user,$cookie,$prefix,$nukeuser,$db,$prefix;
?>
<center>
<br /><font size='6' color='#0000ff'>Most Recent Videos</font><br />
</center>
<?php
nav_video();
?>
<br /><hr color="#0000ff" width='80%'><br />
<table width="100%">
<tr>
<?php
$query ="SELECT video FROM ".$prefix."_rnvideo WHERE aut='1'";
$result = $db->sql_query($query)
or die ("invalid query in video display");
//$result= $db->sql_query($query);
$rows=$db->sql_numrows($result);
//// Set number of Videos per page here
$ppp=10;
$nop= ceil($rows / $ppp);
$z=0;
echo "<td><p><font size='2'>Page : </font>";
for ($i = 1 ; $i <= $nop ; $i++)
{
echo " <a href='/modules.php?name=RN_Video&page=$i'><font size=2> $i </font></a> ";
}
echo "</p></td>";
if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$start= ($page - 1) * $ppp;
$ranking=0;
$ranking=(($ranking+$ppp)*$page)-($ppp-1);
$query="SELECT video,title,code,counter FROM ".$prefix."_rnvideo WHERE aut='1' ORDER BY time DESC LIMIT $start,$ppp";
$result = $db->sql_query($query);
while($row=$db->sql_fetchrow($result))
{
$video=$row['0'];
$title=$row['1'];
$code=$row['2'];
$counter=$row['3'];
if ($z % 2 != 1)
{
echo "<tr align='center'>";
}
?>
</table><br /><hr color="#0000ff" width='80%'><br />
<?php
CloseTable3();
include('footer.php');
}
///////////////////////////////////////// End List Categories /////////////////////////////////
///////////////////////////////////////// Begin List Single Catergory/////////////////////////////////
function list_single_category()
{
OpenTable3();
global $user,$cookie,$prefix,$nukeuser,$db,$prefix;
?>
<center><br /><font size='6' color='#0000ff'>List Single Categories</font><br /></center>
<?php
nav_video();
?>
<br /><hr color="#0000ff" width='80%'><br />
<table width="100%">
<tr>
<?php
///// SET CATEGORY HERE BY ID
$value="89";
///THIS NEEDS TO BE FIXED
$query ="SELECT video FROM ".$prefix."_rnvideo WHERE aut='1' AND category='$value'";
$result = $db->sql_query($query)
or die ("invalid query in video display");
$rows=$db->sql_numrows($result);
// echo "ROWS = $rows";
//// Set number of Videos per page here
$ppp=10;
$nop= ceil($rows / $ppp);
// echo "NOP=$nop";
$z=0;
echo "<td><p><font size='2'>Page : </font>";
for ($i = 1 ; $i <= $nop ; $i++)
{
echo " <a href='/modules.php?name=RN_Video&op=list_single_category&page=$i'><font size=2> $i </font></a> ";
}
echo "</p></td>";
if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$start= ($page - 1) * $ppp;
$ranking=0;
$ranking=(($ranking+$ppp)*$page)-($ppp-1);
$query="SELECT video,title,code,counter FROM ".$prefix."_rnvideo WHERE aut='1' ORDER BY time DESC LIMIT $start,$ppp";
$result = $db->sql_query($query);
while($row=$db->sql_fetchrow($result))
{
$video=$row['0'];
$title=$row['1'];
$code=$row['2'];
$counter=$row['3'];
if ($z % 2 != 1)
{
echo "<tr align='center'>";
}
?>
<td><div align="center">
<?php
echo "<font size='3' color='#0000ff'><b>$title</b></font>";
echo "<br />";
for($i=1;$i < 5;$i++)
{
if(file_get_contents("http://i$i.ytimg.com/vi/$code/default.jpg"))
{
?>
<table><tr><td>
<a href="modules.php?name=RN_Video&file=most_player&video=<?php echo $video; ?>" rel="gb_page_center[640, 425]" title="<?php echo $title; ?>" rev="width: 700px; height: 410px; scrolling: no;"><img src='http://i<?php echo $i; ?>.ytimg.com/vi/<?php echo $code; ?>/default.jpg' width='175' /></a>
</td></tr></table>
<?php
Break;
}
}
?>
<font size='3' color='#0000ff'>Views </font><font size='3' color='#ff0000'><b><?php echo $counter; ?></b></font>
|
<font size='3' color='#0000ff'>Ranking </font><font size='3' color='#ff0000'><b><?php echo $ranking; ?></b></font><br /><hr color="#0000ff" width='80%'><br />
</div></td>
<?php
$z++;
$ranking++;
}
?>
</tr></table>
<br /><hr color="#0000ff" width='80%'><br />
<?php
CloseTable3();
include('footer.php');
}
///////////////////////////////////////// End List Single Catergory/////////////////////////////////
?>
Last edited by Dawg on Sun Aug 22, 2010 5:34 am; edited 1 time in total
I read your link and it makes sence but before I dig into the next part I want to make sure I understand what you are saying.
If I read all this right....I should check to see if MagicQuotes is enabled....and if it is I need to run through stripslashes to get rid of the slashes....Is that correct?
Now we get to the tricky part....Cleaning the code before inserting it.
This is where I always hit a wall becasue I do not really know what I am checking for?
Here is a couple of examples of the main piece of the you tube puzzle...
ChwX__tdqQA
dw2h1qpeU1c
T8taFYpSJs4
This is not an interger....It can have CAPS....lower case.....numbers and symbols in it.
How do I check this or clean this?
I do not expect you to write code for me....A link will do fine...I want to make sure that I clean this code as good as I can to make sure none gets hacked because of something I wrote.
Joined: Aug 29, 2004 Posts: 9136 Location: Arizona
Posted:
Sun Aug 22, 2010 7:14 am
Quote:
4. You do not have to do check_html() on every variable. If it is supposed to be a number just use intval() on it. If it is not an integer it will return 0.
Just to add slightly: you also need to make sure that an integer value of 0 doesn't cause a logic problem which also could do bad things. So, consider someone entering in text data in that field, as Palbin says, it will force the value to a 0. If you are not expressly handling that condition or the code and/or db data is such that a 0 could cause a different kind of failure (either immediate or downstream)... not good also.
Joined: Mar 30, 2006 Posts: 2456 Location: Pittsburgh, Pennsylvania
Posted:
Sun Aug 22, 2010 11:05 am
Dawg wrote:
Palbin,
If I read all this right....I should check to see if MagicQuotes is enabled....and if it is I need to run through stripslashes to get rid of the slashes....Is that correct?
Yes, but if you use check_html() it takes care of the slashes for you if they are enabled. This is important to not because if you strip slashes twice you could be removing legitimate ones (not that you have any).
Basically if you are displaying submitted text or inserting it into the db you should be running check_html() on it. So typically a person would be using check_html() so they would not have to worry about stripping slashes, but you need to be aware for when specific cases come up.
As I said above if you are expecting a certain variable to be a number only you do not have to worry about slashes or check_html() because when you do intval() if one of those characters exist it will return 0.
PHP as some built in functions that can also be used to filter.validate your data.
Only registered users can see links on this board! Get registered or login to the forums!
Specifically look at the is_* functions: is_array, is_numeric, is_string, is_null, is_array, etc.
Also the ctype functions can be used.
Only registered users can see links on this board! Get registered or login to the forums!
The mains ones are: ctype_alnum, ctype_alpha, ctype_digit, etc.
Joined: Mar 30, 2006 Posts: 2456 Location: Pittsburgh, Pennsylvania
Posted:
Sun Aug 22, 2010 11:15 am
Dawg, also about indenting your code. There are no official rules on how to do so. Typically speaking every time you have have a set of {} be that for a function or an if statement etc you should indent the code between those one time. The code will step in or out as you close the bracket.
Take a look at this.
Only registered users can see links on this board! Get registered or login to the forums!
Dawg, also about indenting your code. There are no official rules on how to do so. Typically speaking every time you have have a set of {} be that for a function or an if statement etc you should indent the code between those one time. The code will step in or out as you close the bracket.
Take a look at this.
Only registered users can see links on this board! Get registered or login to the forums!
I have not worked on this as of late...but I wanted to say THANK YOU for this piece of advice!
I am now taking the time to indent the code as I go and WOW that sure has helped me see the logic.
I am hopeing over X-Mas this year I will be able to take the time to revisit this video mod...it is pretty cool.
The Wiki...
Guys...This is one of the best resources around for a guy like me...PLEASE continue to update it with examples.
I can just about recite the Coding Standards
Only registered users can see links on this board! Get registered or login to the forums!
This is the type of things make people like me want to create new stuff for RN!
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