All pastes #760988 Raw Edit

Stuff

public php v1 · immutable
·published 2007-11-04 15:07 UTC
rendered paste body
<?phpfunction print_r2($var){    echo "<pre>";	print_r($var);    echo "</pre>";}// Make sure no one attempts to run this script "directly"if (!defined('PUN'))	exit;// Tell admin_loader.php that this is indeed a plugin and that it is loadeddefine('PUN_PLUGIN_LOADED', 1);// Display the admin navigation menugenerate_admin_menu($plugin);		//Here starts my code		$the_file = "plugins/topiclists.txt";		$filestring = file_get_contents($the_file);	$array_from_file = unserialize($filestring);		if($_POST["action"]=="create"){				$array_from_file[] = array(									"post_id" => $_POST["post_id_tolist"],									"forums_ids" => $_POST["forum_id_tolist"],									"description" => $_POST["desc_tolist"],									"name" => $_POST["name_tolist"]								);				$serialized = serialize($array_from_file);				//file_put_contents($the_file,$serialized); 		$handle = fopen($the_file, 'w');		fwrite($handle, $serialized);		fclose($handle);		}		elseif($_POST["action"]=="update"){				foreach($array_from_file as $a_list){						$forum_id			= $a_list["forums_ids"];			$post_id			= $a_list["post_id"];			$bbcode_topiclist 	= $a_list["description"]."\n\n";			if ( strstr($forum_id,",") ){				$query 	= "select * from ".$db->prefix."topics where ".$db->prefix."forum_id in ( $forum_id ) order by UPPER(subject) asc";			}			else{				$query 	= "select * from ".$db->prefix."topics where ".$db->prefix."forum_id=$forum_id order by UPPER(subject) asc";			}			$result = $db->query($query);									while($row = $db->fetch_assoc($result)){								$bbcode_topiclist .= "[url=".$pun_config['o_base_url']."/viewtopic.php?id=".$row["id"]."]".$row["subject"]."[/url]\n";			}						$bbcode_topiclist = $db->escape($bbcode_topiclist);			//$bbcode_topiclist = pun_preparsebbcode($bbcode_topiclist);			$query = "UPDATE ".$db->prefix."posts SET message='".$bbcode_topiclist."' where id=$post_id";			$db->query($query);			$query_stack[]= $query;			$error_stack[]= $db->error();		}	}	elseif($_POST["action"]=="delete"){		$array_to_put_in_file = array();		foreach( $array_from_file as $key => $value )		{			if ( $key!=$_POST["list_to_delete"] )			{				$array_to_put_in_file[] = $value;			}		}		$serialized = serialize($array_to_put_in_file);		//file_put_contents($the_file,$serialized);		$handle = fopen($the_file, 'w');		fwrite($handle, $serialized);		fclose($handle);				//lets update the variables in order not to interfer with the rest of the code		$filestring = file_get_contents($the_file);		$array_from_file = unserialize($filestring);	}?>	<div id="exampleplugin" class="blockform">		<h2><span>Topiclists Plugin</span></h2>		<div class="box">			<div class="inbox">				<span style="color: #ff0000"><strong> Please read this note before using this plugin!</strong></span><br />				<p>This plugin allows you to mantanin alphabetical clickable lists of topics of one or more forums in the content a message.<br />				Using this plugin uncarefully may result on serious data losses. If you are performing other operations besides updating your lists, you might <strong>consider backing up your database before proceding.</strong><br />				The posts in which you store the lists must be created previously. Please check their ids carefully as all their content will be overwritten.<br />				Mixing topic ids with post ids is a comon mistake, <strong>make sure you enter the post id and not the topic id.</strong><br />				Depending on the database engine you use it's also recomended to hack the datatype of the message body so the list can fit in it<br />				This plugin doesn't suport list edition, if you need to modify a list you have to create a new one and delete the old one.				</p>			</div>		</div>		<h2 class="block2"><span>Topic Lists</span></h2>		<div class="box">		<form id="example" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">			<div class="inform">				<fieldset>					<legend>Current Lists</legend>						<div class="infldset">							<?php								foreach ($array_from_file as $key => $element){									echo "<strong>Name: </strong>".$element["name"]."<br />";									echo "<strong>List id: </strong>".$key."<br />";									echo "<strong>Description: </strong>".$element["description"]."<br />";									echo "<strong>Post id: </strong>".$element["post_id"]."<br />";									echo "<strong>Forum ids: </strong>".$element["forums_ids"]."<br />";									//echo "<a href=\"".$_SERVER['REQUEST_URI']."?a=b\">delete this list</a>";									echo "<hr />";								}							?>							<br />							<input type="submit" name="action" value="update"  />						</div>				</fieldset>			</div>							<div class="inform">					<fieldset>						<legend>Define a new list.</legend>						<div class="infldset">						<table class="aligntop" cellspacing="0">                			 <tr>                                <th scope="row">Name:</th>                                <td>                                    <input type="text" name="name_tolist" size="50" /><br /> Just a title for personal organization, it won't be displayed anywhere but in the admin panel                                </td>                            </tr>                            <tr>                                <th scope="row">Post ID:</th>                                <td>                                    <input type="text" name="post_id_tolist" size="10"  /> The post where the list will be placed                                </td>                            </tr>                            <tr>                                <th scope="row">Forums ID:</th>                                <td>                                    <input type="text" name="forum_id_tolist" size="10"  /> Insert coma separateed values                                </td>                            </tr>								<tr>									<th scope="row">Description<br />(BBcode allowed)</th>									<td><textarea name="desc_tolist" rows="3" cols="50" ></textarea><br />this text will show on the message body right before the list</td>								</tr>							 <tr>                                <th scope="row"><input type="submit" name="action" value="create" /></th>                                                            </tr>                        </table>						</div>					</fieldset>				</div>				<div class="inform">				<fieldset>					<legend>Delete a list</legend>						<div class="infldset">						<!--<table class="aligntop" cellspacing="0">                			 <tr>                                <th scope="row">Enter list id to delete:</th>                                <td>                                    <input type="text" name="id_list_to_delete" size="3" /> Lists have to be deleted one by one. Insert ONLY ONE id at a time.                                </td>                            </tr>						</table> -->						<select name="list_to_delete">							<option value=""></option><br />							<?php								if(!empty($array_from_file)){									foreach( $array_from_file as $key2 => $value )									{										echo "<option value=\"".$key2."\">".$value["name"]." (".$key2.")</option><br />";									}								}							?>						</select>							 <input type="submit" name="action" value="delete"  /> 						</div>				</fieldset>			</div>			</form>		</div>	</div><?php// Note that the script just ends here. The footer will be included by admin_loader.php.