Jump to content

Could Someone Please Debug This?


Zero3X

Recommended Posts

Heya,

 

I was wondering if someone could debug this script for me. I realize it's not the tidest script (and probably not the most efficiant in the world) but it was quite late when I wrote it and I can't be bothered to rewrite it.

 

First off here's the insertbefore function I call quite a lot:

<?php
function insertbefore($stringtosearchin, $wordtofind, $stringtoinsert) {        //Insert a string before a string.
str_replace($wordtofind,$wordtofind.$stringtoinsert,$stringtosearchin);
}
?>

 

Now here's the actual code. Basically it should add a few values to a table then create and add some stuff to some files. The edited files are then included so the functions in then can be activated.

 

I've still got to write something to delete the additions but I'd rather have this debugged first.

 

The MySQL and database selection is made in config.php by the way.

 

<title>Feed Plugin Install</title>
<p>This script could take several minutes to run. You will be redirected to the login page once it has finished.</p>
<p> </p>
<?php
include("../pluginframework.php");
include("../../lib/config.php");
$pluginname = "Feed Creator"; //The name of your plugin
$pluginauthor = "Al Wilde"; //The author or authors
$pluginloaction = "plugins/Feed_Creator"; //The location relative to the base view panel directory (where panel.php is).
$installstatus = "1"; //The install status. As this is the installer set it to 1.

$pluginnamestrip = str_replace(' ', '', $pluginname);       //Clean the plugin name so we can use it later...
$pluginnameclean = str_replace("\'", '', $pluginnamestrip);



//Inserts the plugin name, author, location and install status into the database.
mysql_select_db($dbname, $con);
$insert = "INSERT INTO plugin_lister (pluginname, pluginauthor, fileloc, installed)
VALUES ('".$pluginname."', '".$pluginauthor."', '".$pluginloaction."', '".$installstatus."')";
mysql_query($insert,$con);
$pluginid = mysql_insert_id()
//If you need to create tables put the code here.

//If you need to put data in the databases put the code here.

//If you need to create any files put the code here.
$filecreate1 = "../../pages/feedcreator.php";
$file1open = fopen($filecreate1,"w");
$file1cont = "                                      <?php \n
                                                    $".$pluginnameclean." = ".$pluginid."; \n
                                                    $result = mysql_query('SELECT * FROM plugin_lister \n
                                                    WHERE id='".$pluginnameclean."''); \n

                                                    $pluginname = $row['pluginname']; \n
                                                    $pluginauthor = $row['pluginauthor']; \n
                                                    $pluginloaction = $row['fileloc']; \n
												$installstatus = $row['installed']; \n
												?> \n

												<body> \n
												<div id='apDiv1'> \n
												  <div> \n
													<h1>Create A Feed</h1> \n
													<p>This will allow you to create a feed of posts from your blog. This feed will not include any images, just a table and all the posts you've made.</p> \n
													<form id='form1' name='form1' method='post' action='../scripts/feedcreator.php'> \n
													  <p>1.      \n
														Choose a blog:  \n
														<select name='page' id='page'> \n
														  <?php View_Panel_Page_Lister(); ?> \n
														</select> \n
														- \n
												  <input name='desc' type='text' id='desc' size='70' maxlength='70' /> \n
													  </p> \n
													  <p>2. Create the feed by clicking \n
														<label> \n
														  <input type='submit' name='submit' id='submit' value='Submit' /> \n
														</label> \n
													  </p> \n
													</form> \n
													<p>Powered by the <?php echo $pluginname; ?> plugin by <?php echo $pluginauthor ?>.</p> \n
												  </div> \n
												</div> \n
												</body> \n
												</html> \n";
fwrite($file1open, $file1cont); 
fclose($file1open);


$filecreate2 = "../../scripts/feedcreator.php";
$file2open = fopen($filecreate2,"w");
$file2cont = "<?php
include ('../lib/config.php');
$'.$pluginnameclean.' = '.$pluginid.'; \n
$result = mysql_query('SELECT * FROM plugin_lister \n
WHERE id=''.$pluginnameclean.'''); \n

$pluginname = $row['pluginname']; \n
$pluginauthor = $row['pluginauthor']; \n
$pluginloaction = $row['fileloc']; \n
$installstatus = $row['installed']; \n

$tablename = $_POST['page'];

$tablenamestrip = str_replace(' ', '', $tablename);
$tablenameclean = str_replace('\'', '', $tablenamestrip);

$query = 'SELECT post, author, date FROM $tablenameclean'; 

$result = mysql_query($query) or die(mysql_error());
echo '<border='0'>';
while($row = mysql_fetch_array($result)){
echo '<tr>';
echo '<td>'.$row['post'].'</td>';
echo '</tr>';
echo '<tr>';
echo '<td><h5>Posted by'. $row['author'] .'on'. $row['date'].'</h5></td>';
echo '</tr>';
}
echo '<tr>';
echo '<td><h5>Powered by the Feed Creator Plugin for View Panel.</h5></td>';
echo '</tr>';
echo '</table>'; 
?>";
fwrite($file2open, $file2cont); 
fclose($file2open);

//If you need to edit any files put the code here.
$fileedit1 = "../../navs/editblogsubnav.php";
$file1open = fopen($fileedit1,"a");
													$fileedit1handle = "<?php insertbefore('<div id='apDiv2'><a href='?blogcreate=1'>Create A Blog</a> | <a href='?blogdestroy=1'>Delete A Blog</a> | <a              href='?editblog=1'>Add Posts</a> | <a href='?editblog=2'>Edit Posts</a> | <a href='?editblog=3'>Delete Posts</a> </div>', '</div></body></html>', ' | <a href='?createfeed=1'>Create A Feed</a>'); 
													str_replace('".$fileedit1handle."', ' ', '".$fileedit1handle."');?>";
fwrite($file1open, $fileedit1handle); 
fclose($file1open);

$fileedit2 = "../../navs/navigationcontrol.php";
$file2cont = fopen($fileedit2,"a");
$fileedit2handle = "insertbefore(<?php
if ($home == 1) {
include('pages/panel.php');
include('panelsubnav.php');
      } elseif ($settings == 1) {
	  include('pages/settings.php');
	  include('navs/panelsubnav.php');
  } elseif ($about == 1) {
           include('pages/about.php');
  } elseif ($editblog == 1) {
           include('pages/addposts.php');
	   include('navs/editblogsubnav.php');
  } elseif ($editblog == 2) {
           include('pages/editblog.php');
	   include('navs/editblogsubnav.php');
  } elseif ($editblog == 3) {
           include('pages/deleteposts.php');
	   include('navs/editblogsubnav.php');
  } elseif ($sqlreader == 1) {
           include('pages/sqlreader.php');
  } elseif ($export == 1) {
           include('pages/exportfeed.php');
	   include('navs/editblogsubnav.php');
  } elseif ($plugins == 1) {
           include('pages/plugins.php');
	   include('navs/panelsubnav.php');
  } elseif ($blogcreate == 1) {
           include('pages/addblog.php');
	   include('navs/editblogsubnav.php');
  } elseif ($blogdestroy == 1) {
           include('pages/deleteblog.php');
	   include('navs/editblogsubnav.php');
  } elseif ($help == 1) {
           header('Location: help/index.php');
  } elseif ($filereader == 1) {
           include('pages/fileview.php');
  } 
?> , ' } elseif ($filereader == 1) {include('pages/fileview.php');} ?>', '} elseif ($feedcreator == 1) {
           header('Location: pages/feedcreator.php');
	   include('navs/editblogsubnav.php');');
str_replace('".$fileedit2handle."', ' ', '".$fileedit2handle."');";
fwrite($file2open, $file2cont); 
fclose($file2open);

$fileedit3 = "../../lib/config.php";
$file3cont = fopen($fileedit3,"a");
$fileedit3handle = "<?php include ('../plugins/insertbefore('$displayname = $_COOKIE['View_Panel_ID'];
$editblog = $_GET['editblog'];
$about = $_GET['about']; 
$home = $_GET['home']; 
$settings = $_GET['settings'];
$export = $_GET['export'];
$plugins = $_GET['plugins'];
$tablemanagement = $_GET['tablemanagement'];
$sqlreader = $_GET['sqlreader'];
$filereader = $_GET['filereader'];
$blogcreate = $_GET['blogcreate'];
$blogdestroy = $_GET['blogdestroy'];', '$blogdestroy = $_GET['blogdestroy'];', '$feedcreator = $_GET['createfeed']'); 
							   str_replace('".$fileedit3handle."', ' ', '".$fileedit3handle."');?>";
fwrite($file3open, $file3cont); 
fclose($file3open);
//Put any other code here.
include (fileedit1);
include (fileedit2);
include (fileedit3);
echo "The plugin has now been installed and you may now use whatever it adds or takes away from View Panel. Click <a href='../../login.php'>here</a> to return to the login page.";
?>

Link to comment
Share on other sites

function insertbefore($stringtosearchin, $wordtofind, $stringtoinsert) {        //Insert a string before a string.
   str_replace($wordtofind,$wordtofind.$stringtoinsert,$stringtosearchin);
}

 

This code does nothing until you add a return before str_replace. Equally doing nothing is:

 

$fileedit1handle = "<?php insertbefore

 

You may want to pick up some tutorial on how to properly write PHP code as your code is flawed in multiple sections of your code, a rewrite would be a good option in this case.

Link to comment
Share on other sites

function insertbefore($stringtosearchin, $wordtofind, $stringtoinsert) {        //Insert a string before a string.
   str_replace($wordtofind,$wordtofind.$stringtoinsert,$stringtosearchin);
}

 

This code does nothing until you add a return before str_replace. Equally doing nothing is:

 

$fileedit1handle = "<?php insertbefore

 

You may want to pick up some tutorial on how to properly write PHP code as your code is flawed in multiple sections of your code, a rewrite would be a good option in this case.

 

I didn't think this would work. But I guess it's the product of being up at about 3AM after an insanely busy day. The stuff I do at times like that usually turn out flawed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.