function SaveArray($array, $filename)
{
    $contents = '<?php
$array = ' . var_export($array, 1) . ';
?>';
    return WriteContents($contents, $filename);
}
function furls_AdminOptions()
{
    global $cutepath, $cute_query_string;
    include $cutepath . '/data/config.php';
    echoheader('user', 'Userfriendly URL Setup');
    $furls = new PluginSettings('Userfriendly_URLs');
    $bhelp = '<p><a href="?mod=options&action=furls">Back</a> / <a href="http://www.brandedthoughts.co.uk/cutewiki/index.php/Userfriendly%20URLs%20Plugin">Help</a></p>';
    switch ($_GET['subaction']) {
        case 'edit':
            $linkdata = $furls->settings['text']['0'];
            $buffer = $bhelp . '
	<p>This version of the plugin only needs to know the path to your include-file and what prefix you want on archived entry and category links.</p>
	<form method="post" action="?mod=options&amp;action=furls&amp;subaction=doadd" class="easyform">
		<div>
			<label for="txtCA">Category</label>
			<input id="txtCA" name="furls[category]" value="' . $linkdata[CA] . '" />
		</div>
		<div>
			<label for="txtAR">Archive prefix</label>
			<input id="txtAR" name="furls[archives]" value="' . $linkdata[AR] . '" />
		</div>
		<div style="padding-top: 10px;"><label for="txtPATH" style="width: 100%;">Path to including file<br /><small>If your including file is located at http://yoursite.com/content/news/index.php, type &quot;/content/news/index.php&quot; in this box. <br />Note that it\'s the full url to the file without &quot;http://yoursite.com/&quot;.</small></label>
			<input style="width: 200px;" id="txtPATH" name="furls[path]" value="' . $linkdata[PATH] . '" />
		</div>
		<div>
		<input type="submit" value="Save" />
		</div>
	</form>';
            break;
        case 'templates':
            // List templates
            $templates_list = array();
            if (!($handle = opendir("{$cutepath}/data"))) {
                die("<center>Can not open directory {$cutepath}/data ");
            }
            while (false !== ($file = readdir($handle))) {
                if (eregi(".tpl", $file)) {
                    $file_arr = explode(".", $file);
                    $templates_list[] = $file_arr[0];
                }
            }
            closedir($handle);
            echo $bhelp;
            echo '<p>This tool will automatically convert your old link, full-link and com-link tags to the new humanlink, 
			humanmorelink and humancomlink tags used by this plugin to create friendly url links to your posts. If you want to reverse 
			the process, check the &quot;reverse&quot; checkbox.</p>
		
		<form method="post" action="?mod=options&amp;action=furls&amp;subaction=dotemplates" class="easyform">
		<div>
			<label for="txtTemplate">Template</label>
		<select id="txtTemplate" name="furls[template]">';
            foreach ($templates_list as $null => $single_template) {
                if ($single_template == "Default") {
                    echo "<option selected=\"selected\" value=\"{$single_template}\">{$single_template}</option>";
                } else {
                    echo "<option value=\"{$single_template}\">{$single_template}</option>";
                }
            }
            echo '</select></div>
   		<div>
			<label for="txtReverse">Reverse</label>
			<input type="checkbox" id="txtReverse" name="furls[reverse]" value="true" />
		</div>
			<div>
				<input type="submit" value="Update my templates" />
			</div>
		</form>';
            break;
        case 'htaccess':
            $info = $furls->settings['text']['0'];
            $rewritebase = dirname($info[PATH]);
            if ($rewritebase != "/") {
                $rewritebase = $rewritebase . "/";
            }
            $includefile = str_replace(dirname($info[PATH]) . "/", "", $info[PATH]);
            $htaccesscont = 'RewriteEngine On
RewriteBase ' . $rewritebase . '
RewriteRule ^' . $info[AR] . '/([0-9]{10})/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)/(.*)\\.html$ ' . $includefile . '?archive=$1&furls_date=$2/$3/$4&aj_go=more&category=$5&id=$6 [QSA]
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)/(.*)\\.html$ ' . $includefile . '?furls_date=$1/$2/$3&aj_go=more&category=$4&id=$5 [QSA]
RewriteRule ^' . $info[CA] . '/(.*)\\.html$ ' . $includefile . '?category=$1 [QSA]';
            echo $bhelp;
            echo '<p>This tool will try to create a .htaccess-file in the location you specify. If you\'ve pointed the plugin to the correct include-file-path, 
	the content shown below should be ready for use. You can add variables to the last part of each rewriterule-line. Say you have your include-code in 
	index.php, but it only shows news if you have show=news in your url; you would then add &quot;&show=news&quot; to the end of each line.</p>
	
	
		<form method="post" action="?mod=options&amp;action=furls&amp;subaction=dohtaccess" class="easyform">
		<div>
			<label style="width: 300px;" for="txtHtaccess">.htaccess contents:</label>
			<textarea style="width: 100%; height: 200px;" wrap="off" id="txtHtaccess" name="furls[htaccess]">' . $htaccesscont . '</textarea>
		</div>
		<div>
		
		<p>The location must be relative to 
	your cutenews directory. If you type just &quot;.htaccess&quot;, the file will be created in your cutenews directory. 
	If you type &quot;../.htaccess&quot;, the file will be created in the parent directory of your cutenews installation.
	If you have cutenews installed in &quot;/content/cutenews&quot; and your include-file in &quot;/&quot;, type &quot;../../.htaccess&quot; in the field (&quot;../&quot; means one directory up).<br /></p>

			<p><span class="warning">This <b>might</b> cause your server to crash - so be warned! Not exactly crash, but create a file that is 
			unreadable/unwritable/assigned to another user than yourself on the host machine, thus in a worst-case scenario rendering 
			your site non-functional. If you\'re uncomfortable 
			risking a server&quot;crash&quot;, you should do this manually by writing and uploading the .htaccess file yourself. 
			The directory you are writing .htaccess to must be writable and readable for this tool to work. (' . $_SERVER["PHP_SELF"] . ')</span></p>
			
			<label for="txtTemplate">Write to file:</label>
			<input id="txtTemplate" name="furls[htaccessfile]" value="../.htaccess" />
		</div>
		
			<div>
				<input type="submit" value="Write file!" />
				
			</div>
		</form>';
            break;
        case 'dohtaccess':
            if (WriteContents(stripslashes($_POST[furls][htaccess]), stripslashes($_POST[furls][htaccessfile])) == "true") {
                echo "{$bhelp} <p>Written to " . stripslashes($_POST[furls][htaccessfile]) . "</p>";
            } else {
                echo "{$bhelp} <p>Couldn't write file - make sure the directory you are writing to is actually writable (CHMOD 777)</p>";
            }
            break;
        case 'dotemplates':
            $templatefile = "{$cutepath}/data/" . stripslashes($_POST[furls][template]) . ".tpl";
            $furl_templatec = GetContents($templatefile);
            if (stripslashes($_POST[furls][reverse]) == "true") {
                $furl_templatec = str_replace("humanmorelink", "full-link", $furl_templatec);
                $furl_templatec = str_replace("humancomlink", "com-link", $furl_templatec);
                $furl_templatec = str_replace("humanlink", "link", $furl_templatec);
                $state = "Original links placed";
            } else {
                $furl_templatec = str_replace("full-link", "humanmorelink", $furl_templatec);
                $furl_templatec = str_replace("com-link", "humancomlink", $furl_templatec);
                $furl_templatec = str_replace("[link]", "[humanlink]", $furl_templatec);
                $furl_templatec = str_replace("[/link]", "[/humanlink]", $furl_templatec);
                $state = "Friendly links placed";
            }
            if (WriteContents($furl_templatec, $templatefile) == "true") {
                echo $bhelp;
                echo "<p>Template <b>" . stripslashes($_POST[furls][template]) . "</b> updated successfully! ({$state})</p>";
            } else {
                echo $bhelp;
                echo "<p>Something bad happened... couldn't write to template-file specified!<br /><a href=\"?mod=options&action=furls\">Back</a></p>";
            }
            break;
        case 'doadd':
            $linkdata = array(CA => stripslashes($_POST[furls][category]), AR => stripslashes($_POST[furls][archives]), PATH => stripslashes($_POST[furls][path]));
            $furls->settings['text']['0'] = $linkdata;
            $buffer = $bhelp . '<p>Saved link info</p>';
            $furls->save();
            break;
        default:
            $info = $furls->settings['text']['0'];
            $buffer .= '
		<ul>
			<li><a href="?mod=options&amp;action=furls&amp;subaction=edit">Edit friendly link settings</a></li>
			<li><a href="?mod=options&amp;action=furls&amp;subaction=templates">Auto-update templates</a></li>
			<li><a href="?mod=options&amp;action=furls&amp;subaction=htaccess">Write required .htaccess-file</a></li>
		</ul>';
            $buffer .= '
		<h2>General help:</h2>
		<p>To make these new links work, you\'ll need to upload the .htaccess-file generated in step two above and place it in the same
		 directory as the file you\'re including show_news.php in resides in. The plugin can also 
		 <a href="?mod=options&amp;action=furls&amp;subaction=htaccess">do this for you</a> if this directory is writable. 
		 Read the warning text given there before pressing submit!</p>
		 
		<p>After uploading the .htaccess-file to the correct directory, you can replace [link][/link], [full-link][/full-link]
		 and [com-link][/com-link] in your templates with [humanlink][/humanlink], [humanmorelink][/humanmorelink] and [humancomlink][/humancomlink] 
		 to make the plugin output your new, more aesthetical URLs. You can also 
		 <a href="?mod=options&amp;action=furls&amp;subaction=templates">make the plugin do this</a> for you.</p>
		 <p>The last thing you need to do is put a &lt;base href=&quot;http://path/&quot; /&gt; tag in the &lt;head&gt; section of your including file. 
		 If your including file is at http://yoursite.org/news/, the base tag href mentioned here should reflect that.</p>
		 <h2>Requirements</h2>
		<p>- Apache with mod_rewrite enabled<br />
		- Linux/Unix or Win32 OS<br />
		- Host must allow .htaccess overrides<br />
		- Host must have FollowSymLinks enabled</p>
		';
    }
    echo $buffer;
    echofooter();
}
Example #3
0
if ($action == 'hash') {
    $users = file($userfile);
    $firstline = 1;
    $out = '<?PHP die("You don\'t have access to open this file."); ?>' . "\n";
    foreach ($users as $user) {
        if ($firstline) {
            unset($firstline);
        } else {
            list($a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l) = explode('|', trim($user));
            $out .= $a . '|' . $b . '|' . $c . '|' . md5($d) . '|' . $e . '|' . $f . '|' . $g . '|' . $h . '|' . $i . '|' . $j . '|' . $k . '|' . $l . "\n";
            echo "<li>Done: {$c}" . ($e ? "(aka {$e})" : '') . "</li>\n";
        }
    }
    if (WriteContents($out, $userfile)) {
        echo '<p style="color:green; font-weight: bold;">Success</p>';
        WriteContents('1', 'data/users-md5');
    } else {
        echo '<p style="color:red; font-weight: bold;">Creating the user file failed. Check permisions.</p>';
    }
    exit;
} else {
    echo '<p>This script will automatically perform the required double-md5 encrpytion required to complete the install of aj-blog.</p>
<p><a href="auto-md5-upgrade.php?action=hash">I understand and want to perform this action</a></p>';
    exit;
}
/* Binary safe file functions */
function WriteContents($contents, $filename)
{
    if ($handle = fopen($filename, 'wb+')) {
        fwrite($handle, $contents);
    } else {