.
*
* @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' || 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);
}
/**
* Get the project name
*
* @return string
*/
function project() {
global $project;
return $project;
}
/**
* Returns the associated database record
*/
public function data() {
return $this->dataRecord;
}
/*--------------------------------------------------------------------------------*/
/**
* Returns a fixed navigation menu of the given level.
* @return SS_List
*/
public function getMenu($level = 1) {
if($level == 1) {
$result = DataObject::get("SiteTree", "\"ShowInMenus\" = 1 AND \"ParentID\" = 0");
} else {
$parent = $this->data();
$stack = array($parent);
if($parent) {
while($parent = $parent->Parent) {
array_unshift($stack, $parent);
}
}
if(isset($stack[$level-2])) $result = $stack[$level-2]->Children();
}
$visible = array();
// Remove all entries the can not be viewed by the current user
// We might need to create a show in menu permission
if(isset($result)) {
foreach($result as $page) {
if($page->canView()) {
$visible[] = $page;
}
}
}
return new ArrayList($visible);
}
public function Menu($level) {
return $this->getMenu($level);
}
/**
* Returns the default log-in form.
*
* @todo Check if here should be returned just the default log-in form or
* all available log-in forms (also OpenID...)
*/
public function LoginForm() {
return MemberAuthenticator::get_login_form($this);
}
public function SilverStripeNavigator() {
$member = Member::currentUser();
$items = '';
$message = '';
if(Director::isDev() || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) {
if($this->dataRecord) {
Requirements::css(CMS_DIR . '/css/SilverStripeNavigator.css');
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(CMS_DIR . '/javascript/SilverStripeNavigator.js');
$return = $nav = SilverStripeNavigator::get_for_record($this->dataRecord);
$items = $return['items'];
$message = $return['message'];
}
if($member) {
$firstname = Convert::raw2xml($member->FirstName);
$surname = Convert::raw2xml($member->Surname);
$logInMessage = _t('ContentController.LOGGEDINAS', 'Logged in as') ." {$firstname} {$surname} - ". _t('ContentController.LOGOUT', 'Log out'). "";
} else {
$logInMessage = _t('ContentController.NOTLOGGEDIN', 'Not logged in') ." - ". _t('ContentController.LOGIN', 'Login') ."";
}
$viewPageIn = _t('ContentController.VIEWPAGEIN', 'View Page in:');
return <<
$message
HTML;
// On live sites we should still see the archived message
} else {
if($date = Versioned::current_archived_date()) {
Requirements::css(CMS_DIR . '/css/SilverStripeNavigator.css');
$dateObj = Datetime::create($date, null);
// $dateObj->setVal($date);
return "". _t('ContentController.ARCHIVEDSITEFROM') ."
" . $dateObj->Nice() . "
";
}
}
}
function SiteConfig() {
if(method_exists($this->dataRecord, 'getSiteConfig')) {
return $this->dataRecord->getSiteConfig();
} else {
return SiteConfig::current_site_config();
}
}
/**
* 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.
*/
function LangAttributes() {
Deprecation::notice('2.5', 'Use ContentLocale() instead and write attribute names suitable to XHTML/HTML instead.');
$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(class_exists('Translatable') && Object::has_extension('SiteTree', 'Translatable')) {
$locale = Translatable::get_current_locale();
} else {
$locale = i18n::get_locale();
}
return i18n::convert_rfc1766($locale);
}
/**
* This action is called by the installation system
*/
function successfullyinstalled() {
// The manifest should be built by now, so it's safe to publish the 404 page
$fourohfour = Versioned::get_one_by_stage('ErrorPage', 'Stage', '"ErrorCode" = 404');
if($fourohfour) {
$fourohfour->write();
$fourohfour->publish("Stage", "Live");
}
// TODO Allow this to work when allow_url_fopen=0
if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
$url = 'http://ss2stat.silverstripe.com/Installation/installed?ID=' . $_SESSION['StatsID'];
@file_get_contents($url);
}
global $project;
$data = new ArrayData(array(
'Project' => Convert::raw2xml($project),
'Username' => Convert::raw2xml(Session::get('username')),
'Password' => Convert::raw2xml(Session::get('password')),
));
return array(
"Title" => DBField::create_field('Varchar', "Title", "Installation Successful"),
"Content" => $data->renderWith('Install_successfullyinstalled'),
);
}
function deleteinstallfiles() {
if(!Permission::check("ADMIN")) return Security::permissionFailure($this);
$title = new Varchar("Title");
$content = new HTMLText('Content');
// We can't delete index.php as it might be necessary for URL routing without mod_rewrite.
// There's no safe way to detect usage of mod_rewrite across webservers,
// so we have to assume the file is required.
$installfiles = array(
'install.php',
'config-form.css',
'config-form.html',
'index.html'
);
$unsuccessful = new ArrayList();
foreach($installfiles as $installfile) {
if(file_exists(BASE_PATH . '/' . $installfile)) {
@unlink(BASE_PATH . '/' . $installfile);
}
if(file_exists(BASE_PATH . '/' . $installfile)) {
$unsuccessful->push(new ArrayData(array('File' => $installfile)));
}
}
$data = new ArrayData(array(
'Username' => Convert::raw2xml(Session::get('username')),
'Password' => Convert::raw2xml(Session::get('password')),
'UnsuccessfulFiles' => $unsuccessful
));
$content->setValue($data->renderWith('Install_deleteinstallfiles'));
return array(
"Title" => $title,
"Content" => $content,
);
}
}