Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

adding a page that lives in Extensions, but acts like vanilla

2

Comments

  • sure, just a sec
  • ithcyithcy New
    edited February 2006
    that was it - i didn't have $Context->Session->Check($Context); in there.
    <?php /* Extension Name: Files Tab Extension Extension Url: http://www.htmlephant.com/ Description: Adds a Files tab to the menu, which diaplays a list of files from an FTP server along with a request system. Will not display without proper permissions. Version: 1.0 Author: ithcy (based upon Trabus's Namewhore Tab extension) Author Url: http://www.htmlephant.com [isdir] => 1 [perms] => drwxr-xr-x [number] => 2 [owner] => xxxxxxxx [group] => xxxxxxxx [size] => 4096 [month] => Feb [day] => 9 [time/year] => 10:30 [name] => xxxxxxxx */ if (!@$Context) { include_once("../../appg/settings.php"); include_once("../../appg/init_vanilla.php"); } $Context->Session->Check($Context); // You should cut & paste this language definition into your conf/your_language.php file // (replace "your_language" with your chosen language, of course): $Context->Dictionary['FilesTabPageTitle'] = 'Files'; $Qualified = (in_array($Context->Session->UserID, array("1","31","2031"))) ? true : false; if ($Qualified && (in_array($Context->SelfUrl, array("index.php", "categories.php", "comments.php", "search.php", "post.php", "account.php", "settings.php")))) { // running from one of the other tabs $Menu->AddTab("Files", "Files", "extensions/FilesTab/default.php?PostBackAction=FTPList", "FilesTab", '', 4, true); } elseif ($Qualified && ($Context->SelfUrl == "default.php")) { // running from the Files tab $Menu->AddTab("Files", "Files", "extensions/FilesTab/default.php?PostBackAction=FTPList", "FilesTab", '', 4, true); $Menu->CurrentTab = "Files"; $Panel->CssClass = "FilesPanel"; $Panel->BodyCssClass = "Files"; $Context->PageTitle = $Context->GetDefinition("FilesTabPageTitle"); require("FTPsettings.php"); class FTPList extends Control { function FTPList(&$Context) { $this->Name = 'FTPList'; $this->Control($Context); } function Render() { if ($this->PostBackAction == 'FTPList') { global $ftp_settings; global $Context; $ftp_path = $ftp_settings['root']; $path = ""; if (isset($_GET['p'])) { $unsafe_path = urldecode($_GET['p']); $safe_path = preg_replace("/;.+/","",$unsafe_path); $path .= $safe_path; $ftp_path .= $safe_path; }; $conn_id = ftp_connect($ftp_settings['host']); $login_result = ftp_login($conn_id, $ftp_settings['user'], $ftp_settings['pass']); if($ftp_settings['passive_mode']) { ftp_pasv ($conn_id, true); } ftp_chdir($conn_id, $ftp_path); $raw_contents = ftp_rawlist($conn_id, "."); $parsed = array(); $i = 0; foreach ($raw_contents as $current) { $split = preg_split("[ ]", $current, 9, PREG_SPLIT_NO_EMPTY); if ($split[0] != "total") { $parsed[$i]['isdir'] = $split[0]{0} === "d"; $parsed[$i]['perms'] = $split[0]; $parsed[$i]['number'] = $split[1]; $parsed[$i]['owner'] = $split[2]; $parsed[$i]['group'] = $split[3]; $parsed[$i]['size'] = $split[4]; $parsed[$i]['month'] = $split[5]; $parsed[$i]['day'] = $split[6]; $parsed[$i]['time/year'] = $split[7]; $parsed[$i]['name'] = $split[8]; $i++; } } $FileList = "Path: $path<br />\n<br />\n"; foreach($parsed as $line) { $link = $line['name']; $ulink = urlencode($path . "/" . $link); if ($line['isdir']) { $link = "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=$ulink&PostBackAction=FTPList\">$link</a>"; } else { $link = "<a href=\"ftp://${ftp_settings['user']}:${ftp_settings['pass']}@${ftp_settings['host']}${ftp_path}/$link\">$link</a>\n"; } $FileList .= "$link<br />\n"; } $FileList .= ""; echo($FileList); } } } $FTPList = $Context->ObjectFactory->NewContextObject($Context, "FTPList"); $Page->AddRenderControl($Head, $Configuration['CONTROL_POSITION_HEAD']); $Page->AddRenderControl($Menu, $Configuration['CONTROL_POSITION_MENU']); $Page->AddRenderControl($Panel, $Configuration['CONTROL_POSITION_PANEL']); $Page->AddRenderControl($FTPList, $Configuration['CONTROL_POSITION_BODY_ITEM']); $Page->AddRenderControl($Foot, $Configuration['CONTROL_POSITION_FOOT']); $Page->AddRenderControl($PageEnd, $Configuration['CONTROL_POSITION_PAGE_END']); $Page->FireEvents(); } else { header("location:".GetUrl($Configuration, "index.php")); } ?>

    it is working, tentatively. (see below)
  • ithcyithcy New
    edited February 2006
    but now i'm getting more errors about undefined junk and i feel it has something to do with includes which are coming from another file and not expecting to be inside the extensions folder:

    Notice: Undefined property: Dictionary in (my folder)/library/Framework/Framework.Class.Context.php on line 102

    Warning: array_key_exists(): The second argument should be either an array or an object in (my folder)/library/Framework/Framework.Class.Context.php on line 102


    another stupid question-
    $Menu->AddTab("Files", "Files", "extensions/FilesTab/default.php?PostBackAction=FTPList", "FilesTab", '', '4', '1');

    why doesn't this add the tab at the right end? grrr
  • I suspect $ForcePosition has something to do with it.
  • me too, but that's supposedly the way it's done...
  • NickENickE New
    edited February 2006
    By the way, just for the record, the page manager dosn't edit settings.php file. What you're probably seeing is it reading in the extension file to it can include the other extensions behind it before building the page and exiting.
  • MarkMark Vanilla Staff
    sorry dude, but I'm way too loaded to figure this out right now. Hopefully tomorrow I will have a clear head.
  • NickENickE New
    edited February 2006
    I don't really know if this is what you're looking for, but if you want to access it like index.php?Page=Whatever, the following worked for me:
    
    <?php
    /*
    Extension Name: Custom Page
    Extension Url: http://lussumo.com/docs
    Description: Adds a completely useless custom page.
    Version: 1.0
    Author: SirNot
    Author Url: N/A
    */
    
    if(@$Menu)
    {
    	$Menu->AddToDelegate('PreRender', 'Menu_CustomPage');
    	
    	function Menu_CustomPage(&$Form)
    	{
    		$Form->AddTab('My Custom Page', 'my_custom_page', '.?Page=MyCustomPage', '');
    	}
    }
    
    if($Context->SelfUrl == 'index.php' && ForceIncomingString('Page', '') == 'MyCustomPage')
    {
    	class CustomPage
    	{
    		function CustomPage(&$Context)
    		{
    			$this->Context = &$Context;
    		}
    		
    		function Render()
    		{
    			echo('Whatever you want in here');
    		}
    	}
    	
    	//include the other extensions before we exit
    	$CurFile = 'include($Configuration[\'EXTENSIONS_PATH\']."'.
    		substr(strrchr(str_replace("\\", '/', dirname(__FILE__)), 
    		'/'), 1).'/'.basename(__FILE__).'");';
    	$ExtensionFile = preg_replace("/(.*?)([\r\n]+)/", '\\1', file('./conf/extensions.php'));
    	$ArrIndex = array_search($CurFile, $ExtensionFile);
    	if($ArrIndex) //shouldn't be 0 anyways, so we don't need ===
    	{
    		$ArrLen = count($ExtensionFile) - 1; //for the php end tag
    		for($ArrIndex++; $ArrIndex < $ArrLen; $ArrIndex++) eval($ExtensionFile[$ArrIndex]);
    	}
    	
    	$Context->Session->Check($Configuration);
    	$CustomPage = $Context->ObjectFactory->NewContextObject($Context, 'CustomPage');
    	
    	$Context->PageTitle = 'My Custom Page';
    	$Menu->CurrentTab = 'my_custom_page';
    	$Panel->CssClass = 'DiscussionPanel';
    	$Body->CssClass = 'Discussions';
    	
    	$Page->AddRenderControl($Head, $Configuration["CONTROL_POSITION_HEAD"]);
    	$Page->AddRenderControl($Menu, $Configuration["CONTROL_POSITION_MENU"]);
    	$Page->AddRenderControl($Panel, $Configuration["CONTROL_POSITION_PANEL"]);
    	$Page->AddRenderControl($CustomPage, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
    	$Page->AddRenderControl($Foot, $Configuration["CONTROL_POSITION_FOOT"]);
    	$Page->AddRenderControl($PageEnd, $Configuration["CONTROL_POSITION_PAGE_END"]);
    	
    	$Page->FireEvents();
    	exit();
    }
    ?>
  • ithcyithcy New
    edited February 2006
    SirNot... thanks! That has almost done it.

    in fact there are no more errors - there is only one small problem.
    i need the charset for this page only to be iso-8859-1. it was working in the old page because i could set $Configuration['CHARSET'] immediately after including appg/settings.php and before appg/init_vanilla.php.

    however, when the custom page is loaded from index.php, those 2 appg files are included before the extension loads, and so the charset in the http header is set to utf-8. when i change $Configuration['CHARSET'] = 'iso-8859-1' in this page, it is changed in the xml declaration only, and that is not good enough for firefox. it's still utf-8 in the header.

    can you think of any way around this without adding a conditional (if page is my custom page, change charset) to appg/init_vanilla.php?

    again, thanks, your method has helped immensely.
  • NickENickE New
    edited February 2006
    I believe you can just stick a second header() call in right before the class declaration and it'll override the previous Content-Type header set in headers.php. Worked with php5.

    Eg.
    if($Context->SelfUrl == 'index.php' && ForceIncomingString('Page', '') == 'MyCustomPage')
    {
    	header('Content-type: text/html; charset=iso-8859-1');
    	
    	class CustomPage
    	{
  • really? i'll give that a try.
  • that did it! thanks man, you rock. everything works now.

    this is a handy extension, so when i add a few more features i'll post it here.
  • Well, isn't it essentially what the page manager does?
  • what? this extension? no, it's an interface to an ftp server.
  • NickENickE New
    edited February 2006
    oh, I thought you meant as a page adder.
  • well that part was useful too =)
  • It would be awkward if this extension was dependant on the pagemanager extension.
  • it's not dependent on any extension.
  • I was talking to sirnot; I agree with you :D
  • NickENickE New
    edited February 2006
    Well I wasn't saying it should rely on it, I was just under the (wrong) impression that he was saying he might release the page creation part of it as an extension, and was pointing out it might be somewhat redundant to have two extensions for the same purpose.
This discussion has been closed.