2007-07-19 12:40:28 +02:00
< ? php
/**
2008-03-03 00:24:10 +01:00
* The most common kind of controller ; effectively a controller linked to a { @ link DataObject } .
2007-07-19 12:40:28 +02:00
*
* ContentControllers are most useful in the content - focused areas of a site . This is generally
* the bulk of a site ; however , they may be less appropriate in , for example , the user management
* section of an application .
*
* On its own , content controller does very little . Its constructor is passed a { @ link DataObject }
2007-09-14 21:10:18 +02:00
* which is stored in $this -> dataRecord . Any unrecognised method calls , for example , Title ()
* and Content (), will be passed along to the data record ,
*
2007-07-19 12:40:28 +02:00
* Subclasses of ContentController are generally instantiated by ModelAsController ; this will create
* a controller based on the URLSegment action variable , by looking in the SiteTree table .
2008-03-03 00:24:10 +01:00
*
* @ todo Can this be used for anything other than SiteTree controllers ?
2008-02-25 03:10:37 +01:00
*
* @ package sapphire
* @ subpackage control
2007-07-19 12:40:28 +02:00
*/
class ContentController extends Controller {
2009-09-07 07:39:43 +02:00
2007-07-19 12:40:28 +02:00
protected $dataRecord ;
2009-09-07 07:39:43 +02:00
static $url_handlers = array (
2009-11-08 22:53:57 +01:00
'widget/$ID!' => 'handleWidget'
2009-09-07 07:39:43 +02:00
);
2009-10-15 02:49:49 +02:00
public static $allowed_actions = array (
2009-11-06 04:34:46 +01:00
'PageComments' ,
2009-11-13 22:34:43 +01:00
'successfullyinstalled' ,
'deleteinstallfiles'
2009-10-15 02:49:49 +02:00
);
2007-07-19 12:40:28 +02:00
/**
* The ContentController will take the URLSegment parameter from the URL and use that to look
* up a SiteTree record .
*/
2008-12-04 23:38:32 +01:00
public function __construct ( $dataRecord = null ) {
if ( ! $dataRecord ) {
$dataRecord = new Page ();
if ( $this -> hasMethod ( " Title " )) $dataRecord -> Title = $this -> Title ();
$dataRecord -> URLSegment = get_class ( $this );
$dataRecord -> ID = - 1 ;
}
2007-07-19 12:40:28 +02:00
$this -> dataRecord = $dataRecord ;
$this -> failover = $this -> dataRecord ;
parent :: __construct ();
}
2009-10-11 02:07:00 +02:00
/**
* Return the link to this controller , but force the expanded link to be returned so that form methods and
* similar will function properly .
*
* @ return string
*/
2007-07-19 12:40:28 +02:00
public function Link ( $action = null ) {
2009-10-11 02:07:00 +02:00
return $this -> data () -> Link (( $action ? $action : true ));
2007-07-19 12:40:28 +02:00
}
2009-10-11 02:07:00 +02:00
2007-07-19 12:40:28 +02:00
//----------------------------------------------------------------------------------//
// These flexible data methods remove the need for custom code to do simple stuff
2009-10-11 02:07:08 +02:00
/**
* Return the children of a given page . The parent reference can either be a page link or an ID .
*
* @ param string | int $parentRef
* @ return DataObjectSet
2007-07-19 12:40:28 +02:00
*/
public function ChildrenOf ( $parentRef ) {
2009-10-11 02:07:19 +02:00
$parent = SiteTree :: get_by_link ( $parentRef );
2009-10-11 02:07:08 +02:00
if ( ! $parent && is_numeric ( $parentRef )) {
$parent = DataObject :: get_by_id ( 'SiteTree' , Convert :: raw2sql ( $parentRef ));
}
2009-06-29 06:53:15 +02:00
if ( $parent ) return $parent -> Children ();
2007-07-19 12:40:28 +02:00
}
2009-10-11 02:07:08 +02:00
/**
* @ return DataObjectSet
*/
public function Page ( $link ) {
return SiteTree :: get_by_link ( $link );
2007-07-19 12:40:28 +02:00
}
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
public function init () {
parent :: init ();
2007-08-16 08:27:32 +02:00
2007-07-19 12:40:28 +02:00
// If we've accessed the homepage as /home/, then we should redirect to /.
2008-04-26 08:53:13 +02:00
if ( $this -> dataRecord && $this -> dataRecord instanceof SiteTree
&& RootURLController :: should_be_on_root ( $this -> dataRecord ) && ! $this -> urlParams [ 'Action' ]
&& ! $_POST && ! $_FILES && ! Director :: redirected_to () ) {
2007-07-19 12:40:28 +02:00
$getVars = $_GET ;
unset ( $getVars [ 'url' ]);
2007-08-28 04:49:31 +02:00
if ( $getVars ) $url = " ? " . http_build_query ( $getVars );
else $url = " " ;
2008-04-22 03:45:55 +02:00
Director :: redirect ( $url , 301 );
2007-08-17 05:09:46 +02:00
return ;
2007-07-19 12:40:28 +02:00
}
2008-04-26 08:52:59 +02:00
if ( $this -> dataRecord ) $this -> dataRecord -> extend ( 'contentcontrollerInit' , $this );
else singleton ( 'SiteTree' ) -> extend ( 'contentcontrollerInit' , $this );
2008-04-26 08:49:01 +02:00
if ( Director :: redirected_to ()) return ;
2007-09-14 21:10:18 +02:00
2007-11-09 04:42:04 +01:00
// Check page permissions
2007-11-02 02:11:13 +01:00
if ( $this -> dataRecord && $this -> URLSegment != 'Security' && ! $this -> dataRecord -> can ( 'View' )) {
2009-09-10 04:00:42 +02:00
return Security :: permissionFailure ( $this );
2007-10-02 06:40:08 +02:00
}
2010-04-13 03:43:29 +02:00
2007-11-09 04:42:04 +01:00
// Draft/Archive security check - only CMS users should be able to look at stage/archived content
2008-05-26 08:21:30 +02:00
if ( $this -> URLSegment != 'Security' && ! Session :: get ( 'unsecuredDraftSite' ) && ( Versioned :: current_archived_date () || ( Versioned :: current_stage () && Versioned :: current_stage () != 'Live' ))) {
2009-12-02 10:40:45 +01:00
if ( ! $this -> dataRecord -> canViewStage ( Versioned :: current_stage ())) {
2007-11-09 04:42:04 +01:00
$link = $this -> Link ();
2008-10-12 18:25:29 +02:00
$message = _t ( " ContentController.DRAFT_SITE_ACCESS_RESTRICTION " , 'You must log in with your CMS password in order to view the draft or archived content. <a href="%s">Click here to go back to the published site.</a>' );
2010-04-13 03:33:49 +02:00
Session :: clear ( 'currentStage' );
Session :: clear ( 'archiveDate' );
2009-09-10 04:00:42 +02:00
return Security :: permissionFailure ( $this , sprintf ( $message , " $link ?stage=Live " ));
2007-11-09 04:42:04 +01:00
}
2010-04-13 05:18:10 +02:00
}
2007-11-09 04:42:04 +01:00
2010-04-13 05:18:10 +02:00
// Use theme from the site config
if (( $config = SiteConfig :: current_site_config ()) && $config -> Theme ) {
SSViewer :: set_theme ( $config -> Theme );
}
2007-07-20 06:05:51 +02:00
}
2009-09-07 05:28:23 +02:00
2009-10-11 02:07:25 +02:00
/**
* This acts the same as { @ link Controller :: handleRequest ()}, but if an action cannot be found this will attempt to
* fall over to a child controller in order to provide functionality for nested URLs .
*
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
* @ return SS_HTTPResponse
2009-10-11 02:07:25 +02:00
*/
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
public function handleRequest ( SS_HTTPRequest $request ) {
2009-10-11 02:07:25 +02:00
$child = null ;
$action = $request -> param ( 'Action' );
// If nested URLs are enabled, and there is no action handler for the current request then attempt to pass
// control to a child controller. This allows for the creation of chains of controllers which correspond to a
// nested URL.
if ( $action && SiteTree :: nested_urls () && ! $this -> hasAction ( $action )) {
Translatable :: disable_locale_filter ();
$child = DataObject :: get_one ( 'SiteTree' , sprintf (
" \" ParentID \" = %s AND \" URLSegment \" = '%s' " , $this -> ID , Convert :: raw2sql ( $action )
));
Translatable :: enable_locale_filter ();
}
if ( $child ) {
$request -> shiftAllParams ();
$request -> shift ();
$response = ModelAsController :: controller_for ( $child ) -> handleRequest ( $request );
} else {
Director :: set_current_page ( $this -> data ());
$response = parent :: handleRequest ( $request );
Director :: set_current_page ( null );
}
return $response ;
}
/**
* @ uses ErrorPage :: response_for ()
*/
public function httpError ( $code , $message = null ) {
if ( $this -> request -> isMedia () || ! $response = ErrorPage :: response_for ( $code )) {
parent :: httpError ( $code , $message );
} else {
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
throw new SS_HTTPResponse_Exception ( $response );
2009-10-11 02:07:25 +02:00
}
}
2009-09-07 05:28:23 +02:00
/**
* Handles widgets attached to a page through one or more { @ link WidgetArea } elements .
* Iterated through each $has_one relation with a { @ link WidgetArea }
* and looks for connected widgets by their database identifier .
* Assumes URLs in the following format : < URLSegment >/ widget /< Widget - ID >.
*
* @ return RequestHandler
*/
function handleWidget () {
$SQL_id = $this -> request -> param ( 'ID' );
if ( ! $SQL_id ) return false ;
// find WidgetArea relations
$widgetAreaRelations = array ();
$hasOnes = $this -> dataRecord -> has_one ();
if ( ! $hasOnes ) return false ;
foreach ( $hasOnes as $hasOneName => $hasOneClass ) {
if ( $hasOneClass == 'WidgetArea' || ClassInfo :: is_subclass_of ( $hasOneClass , 'WidgetArea' )) {
$widgetAreaRelations [] = $hasOneName ;
}
}
// find widget
$widget = null ;
foreach ( $widgetAreaRelations as $widgetAreaRelation ) {
if ( $widget ) break ;
$widget = $this -> dataRecord -> $widgetAreaRelation () -> Widgets (
sprintf ( '"Widget"."ID" = %d' , $SQL_id )
) -> First ();
}
if ( ! $widget ) user_error ( 'No widget found' , E_USER_ERROR );
// find controller
$controllerClass = '' ;
foreach ( array_reverse ( ClassInfo :: ancestry ( $widget -> class )) as $widgetClass ) {
$controllerClass = " { $widgetClass } _Controller " ;
if ( class_exists ( $controllerClass )) break ;
}
if ( ! $controllerClass ) user_error (
sprintf ( 'No controller available for %s' , $widget -> class ),
E_USER_ERROR
);
return new $controllerClass ( $widget );
}
2007-09-14 21:10:18 +02:00
2007-07-20 06:05:51 +02:00
/**
* Get the project name
*
* @ return string
*/
function project () {
global $project ;
return $project ;
2007-07-19 12:40:28 +02:00
}
/**
* Returns the associated database record
*/
public function data () {
return $this -> dataRecord ;
}
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
/*--------------------------------------------------------------------------------*/
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
/**
* Returns a fixed navigation menu of the given level .
2008-10-25 13:30:28 +02:00
* @ return DataObjectSet
2007-07-19 12:40:28 +02:00
*/
2008-10-13 22:08:59 +02:00
public function getMenu ( $level = 1 ) {
2007-07-19 12:40:28 +02:00
if ( $level == 1 ) {
2009-03-12 00:04:50 +01:00
$result = DataObject :: get ( " SiteTree " , " \" ShowInMenus \" = 1 AND \" ParentID \" = 0 " );
2007-07-19 12:40:28 +02:00
} else {
$parent = $this -> data ();
$stack = array ( $parent );
2008-10-25 13:30:28 +02:00
if ( $parent ) {
while ( $parent = $parent -> Parent ) {
array_unshift ( $stack , $parent );
}
}
if ( isset ( $stack [ $level - 2 ])) $result = $stack [ $level - 2 ] -> Children ();
2007-07-19 12:40:28 +02:00
}
2007-07-24 05:43:21 +02:00
$visible = array ();
// Remove all entries the can not be viewed by the current user
// We might need to create a show in menu permission
2007-12-13 23:31:58 +01:00
if ( isset ( $result )) {
2007-07-24 05:43:21 +02:00
foreach ( $result as $page ) {
if ( $page -> can ( 'view' )) {
$visible [] = $page ;
}
}
}
return new DataObjectSet ( $visible );
2007-07-19 12:40:28 +02:00
}
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
public function Menu ( $level ) {
return $this -> getMenu ( $level );
}
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
/**
* Returns the default log - in form .
2007-09-14 21:10:18 +02:00
*
* @ todo Check if here should be returned just the default log - in form or
* all available log - in forms ( also OpenID ... )
*/
2007-07-19 12:40:28 +02:00
public function LoginForm () {
2007-09-16 03:48:38 +02:00
return MemberAuthenticator :: get_login_form ( $this );
2007-07-19 12:40:28 +02:00
}
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
public function SilverStripeNavigator () {
$member = Member :: currentUser ();
2010-04-14 05:51:56 +02:00
$items = '' ;
$message = '' ;
2007-09-14 21:10:18 +02:00
2010-04-13 03:33:49 +02:00
if ( Director :: isDev () || Permission :: check ( 'CMS_ACCESS_CMSMain' ) || Permission :: check ( 'VIEW_DRAFT_CONTENT' )) {
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
Requirements :: css ( SAPPHIRE_DIR . '/css/SilverStripeNavigator.css' );
2007-07-19 12:40:28 +02:00
2009-11-30 02:46:37 +01:00
Requirements :: javascript ( SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js' );
2007-07-19 12:40:28 +02:00
Requirements :: customScript ( <<< JS
2009-11-30 02:46:37 +01:00
( function ( $ ) {
2010-04-14 05:52:28 +02:00
$ ( '#switchView a.newWindow' ) . click ( function () {
2009-11-30 02:46:37 +01:00
var w = window . open ( this . href , windowName ( this . target ));
w . focus ();
return false ;
});
function windowName ( suffix ) {
var base = document . getElementsByTagName ( 'base' )[ 0 ] . href . replace ( 'http://' , '' ) . replace ( / \ //g,'_').replace(/\./g,'_');
return base + suffix ;
2007-09-14 21:10:18 +02:00
}
2009-11-30 02:46:37 +01:00
window . name = windowName ( 'site' );
})( jQuery );
2007-07-19 12:40:28 +02:00
JS
);
2010-04-14 05:51:56 +02:00
2007-07-19 12:40:28 +02:00
2010-04-14 05:51:56 +02:00
if ( $this -> dataRecord ) {
$navItemClasses = ClassInfo :: subclassesFor ( 'SilverStripeNavigatorItem' );
array_shift ( $navItemClasses );
// Sort menu items according to priority
$menuPriority = array ();
$i = 0 ;
foreach ( $navItemClasses as $navItemClass ) {
if ( $navItemClass == 'SilverStripeNavigatorItem' ) continue ;
$i ++ ;
$obj = new $navItemClass ();
// This funny litle formula ensures that the first item added with the same priority will be left-most.
$priority = Object :: get_static ( $navItemClass , 'priority' );
$menuPriority [ $priority * 100 - 1 ] = $obj ;
}
ksort ( $menuPriority );
foreach ( $menuPriority as $obj ) {
$text = $obj -> getHTML ( $this -> dataRecord );
if ( $text ) $items .= $text ;
2010-04-14 05:52:28 +02:00
$newMessage = $obj -> getMessage ( $this );
if ( $newMessage ) $message = $newMessage ;
2010-04-14 05:51:56 +02:00
}
2007-07-19 12:40:28 +02:00
}
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
if ( $member ) {
$firstname = Convert :: raw2xml ( $member -> FirstName );
2010-04-14 05:51:56 +02:00
$surname = Convert :: raw2xml ( $member -> Surname );
2009-02-02 00:49:53 +01:00
$logInMessage = _t ( 'ContentController.LOGGEDINAS' , 'Logged in as' ) . " { $firstname } { $surname } - <a href= \" Security/logout \" > " . _t ( 'ContentController.LOGOUT' , 'Log out' ) . " </a> " ;
2007-07-19 12:40:28 +02:00
} else {
2009-04-29 01:40:35 +02:00
$logInMessage = _t ( 'ContentController.NOTLOGGEDIN' , 'Not logged in' ) . " - <a href= \" Security/login \" > " . _t ( 'ContentController.LOGIN' , 'Login' ) . " </a> " ;
2007-07-19 12:40:28 +02:00
}
2009-02-02 00:49:53 +01:00
$viewPageIn = _t ( 'ContentController.VIEWPAGEIN' , 'View Page in:' );
2010-04-14 05:51:56 +02:00
2007-07-19 12:40:28 +02:00
return <<< HTML
< div id = " SilverStripeNavigator " >
< div class = " holder " >
< div id = " logInStatus " >
$logInMessage
</ div >
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
< div id = " switchView " class = " bottomTabs " >
2009-02-02 00:49:53 +01:00
< div class = " blank " > $viewPageIn </ div >
2010-04-14 05:51:56 +02:00
$items
2007-07-19 12:40:28 +02:00
</ div >
</ div >
</ div >
$message
HTML ;
// On live sites we should still see the archived message
} else {
if ( $date = Versioned :: current_archived_date ()) {
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
Requirements :: css ( SAPPHIRE_DIR . '/css/SilverStripeNavigator.css' );
2007-07-19 12:40:28 +02:00
$dateObj = Object :: create ( 'Datetime' , $date , null );
// $dateObj->setVal($date);
2009-02-02 00:49:53 +01:00
return " <div id= \" SilverStripeNavigatorMessage \" > " . _t ( 'ContentController.ARCHIVEDSITEFROM' ) . " <br> " . $dateObj -> Nice () . " </div> " ;
2007-07-19 12:40:28 +02:00
}
}
}
/**
* Returns a page comment system
*/
function PageComments () {
2009-05-26 04:08:18 +02:00
$hasComments = DB :: query ( " SELECT COUNT(*) FROM \" PageComment \" WHERE \" PageComment \" . \" ParentID \" = ' " . Convert :: raw2sql ( $this -> ID ) . " ' " ) -> value ();
2009-05-26 03:56:21 +02:00
if (( $this -> data () && $this -> data () -> ProvideComments ) || ( $hasComments > 0 && PageCommentInterface :: $show_comments_when_disabled )) {
2007-07-19 12:40:28 +02:00
return new PageCommentInterface ( $this , 'PageComments' , $this -> data ());
} else {
if ( isset ( $_REQUEST [ 'executeForm' ]) && $_REQUEST [ 'executeForm' ] == 'PageComments.PostCommentForm' ) {
echo " Comments have been disabled for this page " ;
die ();
}
}
}
2009-10-16 00:30:34 +02:00
function SiteConfig () {
return SiteConfig :: current_site_config ();
}
2007-09-14 21:10:18 +02:00
2007-09-16 18:12:42 +02:00
/**
2010-04-12 05:39:35 +02:00
* Returns the xml : lang and lang attributes .
*
* @ deprecated 2.5 Use ContentLocale () instead and write attribute names suitable to XHTML / HTML
* templates directly in the template .
2007-09-16 18:12:42 +02:00
*/
function LangAttributes () {
2010-04-12 05:39:35 +02:00
$locale = $this -> ContentLocale ();
return " xml:lang= \" $locale\ " lang = \ " $locale\ " " ;
}
/**
* Returns an RFC1766 compliant locale string , e . g . 'fr-CA' .
* Inspects the associated { @ link dataRecord } for a { @ link SiteTree -> Locale } value if present ,
* and falls back to { @ link Translatable :: get_current_locale ()} or { @ link i18n :: default_locale ()},
* depending if Translatable is enabled .
*
* Suitable for insertion into lang = and xml : lang =
* attributes in HTML or XHTML output .
*
* @ return string
*/
function ContentLocale () {
if ( $this -> dataRecord && $this -> dataRecord -> hasExtension ( 'Translatable' )) {
$locale = $this -> dataRecord -> Locale ;
} elseif ( Object :: has_extension ( 'SiteTree' , 'Translatable' )) {
$locale = Translatable :: get_current_locale ();
} else {
2010-04-13 03:05:45 +02:00
$locale = i18n :: get_locale ();
2010-04-12 05:39:35 +02:00
}
return i18n :: convert_rfc1766 ( $locale );
2007-09-16 18:12:42 +02:00
}
2007-09-16 03:48:38 +02:00
2007-07-19 12:40:28 +02:00
/**
* This action is called by the installation system
*/
function successfullyinstalled () {
2007-08-20 07:21:39 +02:00
// The manifest should be built by now, so it's safe to publish the 404 page
2010-04-14 05:31:20 +02:00
$fourohfour = Versioned :: get_one_by_stage ( 'ErrorPage' , 'Stage' , '"ErrorCode" = 404' );
2007-08-20 07:21:39 +02:00
if ( $fourohfour ) {
$fourohfour -> write ();
$fourohfour -> publish ( " Stage " , " Live " );
}
2007-10-02 06:51:22 +02:00
if ( isset ( $_SESSION [ 'StatsID' ]) && $_SESSION [ 'StatsID' ]) {
$url = 'http://ss2stat.silverstripe.com/Installation/installed?ID=' . $_SESSION [ 'StatsID' ];
@ file_get_contents ( $url );
}
2007-07-19 12:40:28 +02:00
$title = new Varchar ( " Title " );
$content = new HTMLText ( " Content " );
$username = Session :: get ( 'username' );
$password = Session :: get ( 'password' );
$title -> setValue ( " Installation Successful " );
global $project ;
2009-11-06 04:35:07 +01:00
$tutorialOnly = ( $project == 'tutorial' ) ? " <p>This website is a simplistic version of a SilverStripe 2 site. To extend this, please take a look at <a href= \" http://doc.silverstripe.org/doku.php?id=tutorials \" >our new tutorials</a>.</p> " : '' ;
2007-07-19 12:40:28 +02:00
$content -> setValue ( <<< HTML
< p style = " margin: 1em 0 " >< b > Congratulations , SilverStripe has been successfully installed .</ b ></ p >
$tutorialOnly
< p > You can start editing your site ' s content by opening < a href = " admin/ " > the CMS </ a >. < br />
& nbsp ; & nbsp ; Email : $username < br />
& nbsp ; & nbsp ; Password : $password < br />
</ p >
< div style = " background:#ddd; border:1px solid #ccc; padding:5px; margin:5px; " >< img src = " cms/images/dialogs/alert.gif " style = " border: none; margin-right: 10px; float: left; " />< p style = " color:red; " > For security reasons you should now delete the install files , unless you are planning to reinstall later . The web server also now only needs write access to the " assets " folder , you can remove write access from all other folders .</ p >
< div style = " margin-left: auto; margin-right: auto; width: 50%; " >< p >< a href = " home/deleteinstallfiles " style = " text-align: center; " > Click here to delete the install files .</ a ></ p ></ div ></ div >
HTML
);
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
return array (
" Title " => $title ,
" Content " => $content ,
);
}
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
function deleteinstallfiles () {
$title = new Varchar ( " Title " );
$content = new HTMLText ( " Content " );
$tempcontent = '' ;
$username = Session :: get ( 'username' );
$password = Session :: get ( 'password' );
2007-09-16 03:48:38 +02:00
2007-07-19 12:40:28 +02:00
$installfiles = array (
'index.php' ,
'install.php' ,
'rewritetest.php' ,
'config-form.css' ,
'config-form.html' ,
'index.html'
);
2007-09-16 03:48:38 +02:00
2007-07-19 12:40:28 +02:00
foreach ( $installfiles as $installfile ) {
2010-04-13 01:14:36 +02:00
if ( file_exists ( BASE_PATH . '/' . $installfile )) {
@ unlink ( BASE_PATH . '/' . $installfile );
2007-07-19 12:40:28 +02:00
}
2007-09-16 03:48:38 +02:00
2010-04-13 01:14:36 +02:00
if ( file_exists ( BASE_PATH . '/' . $installfile )) {
2007-07-19 12:40:28 +02:00
$unsuccessful [] = $installfile ;
}
}
2007-09-16 03:48:38 +02:00
2007-07-19 12:40:28 +02:00
if ( isset ( $unsuccessful )) {
$title -> setValue ( " Unable to delete installation files " );
$tempcontent = " <p style= \" margin: 1em 0 \" >Unable to delete installation files. Please delete the files below manually:</p><ul> " ;
foreach ( $unsuccessful as $unsuccessfulFile ) {
$tempcontent .= " <li> $unsuccessfulFile </li> " ;
}
$tempcontent .= " </ul> " ;
} else {
$title -> setValue ( " Deleted installation files " );
$tempcontent = <<< HTML
< p style = " margin: 1em 0 " > Installation files have been successfully deleted .</ p >
HTML
;
}
$tempcontent .= <<< HTML
< p style = " margin: 1em 0 " > You can start editing your site ' s content by opening < a href = " admin/ " > the CMS </ a >. < br />
& nbsp ; & nbsp ; Email : $username < br />
& nbsp ; & nbsp ; Password : $password < br />
</ p >
HTML
;
$content -> setValue ( $tempcontent );
2007-09-14 21:10:18 +02:00
2007-07-19 12:40:28 +02:00
return array (
" Title " => $title ,
" Content " => $content ,
);
}
}
2007-07-24 05:43:21 +02:00
2009-04-29 01:40:35 +02:00
?>