/**
  * Constructor
  *
  * @param Controller $controller The parent controller, necessary to
  *                               create the appropriate form action tag.
  * @param string $name The method on the controller that will return this
  *                     form object.
  * @param FieldSet|FormField $fields All of the fields in the form - a
  *                                   {@link FieldSet} of {@link FormField}
  *                                   objects.
  * @param FieldSet|FormAction $actions All of the action buttons in the
  *                                     form - a {@link FieldSet} of
  *                                     {@link FormAction} objects
  * @param bool $checkCurrentUser If set to TRUE, it will be checked if a
  *                               the user is currently logged in, and if
  *                               so, only a logout button will be rendered
  */
 function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     $this->authenticator_class = 'MemberAuthenticator';
     $customCSS = project() . '/css/member_login.css';
     if (Director::fileExists($customCSS)) {
         Requirements::css($customCSS);
     }
     if (isset($_REQUEST['BackURL'])) {
         $backURL = $_REQUEST['BackURL'];
     } else {
         $backURL = Session::get('BackURL');
     }
     if ($checkCurrentUser && Member::currentUserID()) {
         $fields = new FieldSet();
         $actions = new FieldSet(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
     } else {
         if (!$fields) {
             $fields = new FieldSet(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this), new TextField("Email", _t('Member.EMAIL'), Session::get('SessionForms.MemberLoginForm.Email'), null, $this), new EncryptField("Password", _t('Member.PASSWORD'), null, $this), new CheckboxField("Remember", _t('Member.REMEMBERME', "Remember me next time?"), Session::get('SessionForms.MemberLoginForm.Remember'), $this));
         }
         if (!$actions) {
             $actions = new FieldSet(new FormAction("dologin", _t('Member.BUTTONLOGIN', "Log in")), new FormAction("forgotPassword", _t('Member.BUTTONLOSTPASSWORD', "I've lost my password")));
         }
     }
     if (isset($backURL)) {
         $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
     }
     parent::__construct($controller, $name, $fields, $actions);
 }
 /**
  * Finds the path for specified file.
  *
  * @param string $fileOrUrl
  * @return string|boolean
  */
 protected static function path_for_file($fileOrUrl)
 {
     if (preg_match('{^//|http[s]?}', $fileOrUrl)) {
         return $fileOrUrl;
     } elseif (Director::fileExists($fileOrUrl)) {
         $filePath = preg_replace('/\\?.*/', '', Director::baseFolder() . '/' . $fileOrUrl);
         $prefix = Director::baseURL();
         $mtimesuffix = "";
         $suffix = '';
         if (Requirements::get_suffix_requirements()) {
             $mtimesuffix = "?m=" . filemtime($filePath);
             $suffix = '&';
         }
         if (strpos($fileOrUrl, '?') !== false) {
             if (strlen($suffix) == 0) {
                 $suffix = '?';
             }
             $suffix .= substr($fileOrUrl, strpos($fileOrUrl, '?') + 1);
             $fileOrUrl = substr($fileOrUrl, 0, strpos($fileOrUrl, '?'));
         } else {
             $suffix = '';
         }
         return "{$prefix}{$fileOrUrl}{$mtimesuffix}{$suffix}";
     } else {
         return false;
     }
 }
Exemple #3
0
 public function init()
 {
     parent::init();
     Requirements::javascript(MCE_ROOT . "tiny_mce_src.js");
     Requirements::javascript("jsparty/tiny_mce_improvements.js");
     Requirements::javascript("jsparty/hover.js");
     Requirements::javascript("jsparty/scriptaculous/controls.js");
     Requirements::javascript("cms/javascript/SecurityAdmin.js");
     Requirements::javascript("cms/javascript/LeftAndMain_left.js");
     Requirements::javascript("cms/javascript/LeftAndMain_right.js");
     Requirements::javascript("cms/javascript/CMSMain_left.js");
     Requirements::javascript("cms/javascript/ReportAdmin_left.js");
     Requirements::javascript("cms/javascript/ReportAdmin_right.js");
     Requirements::css("cms/css/ReportAdmin.css");
     // TODO Find a better solution to integrate optional Requirements in a specific order
     if (Director::fileExists("ecommerce/css/DataReportCMSMain.css")) {
         Requirements::css("ecommerce/css/DataReportCMSMain.css");
     }
     if (Director::fileExists("ecommerce/css/DataReportCMSMain.css")) {
         Requirements::javascript("ecommerce/javascript/DataReport.js");
     }
     if (Director::fileExists(project() . "/css/DataReportCMSMain.css")) {
         Requirements::css(project() . "/css/DataReportCMSMain.css");
     }
     if (Director::fileExists(project() . "/css/DataReportCMSMain.css")) {
         Requirements::javascript(project() . "/javascript/DataReport.js");
     }
     // We don't want this showing up in every ajax-response, it should always be present in a CMS-environment
     if (!Director::is_ajax()) {
         Requirements::javascriptTemplate("cms/javascript/tinymce.template.js", array("ContentCSS" => project() . "/css/editor.css", "BaseURL" => Director::absoluteBaseURL(), "Lang" => i18n::get_tinymce_lang()));
     }
 }
 /**
  * Displays random quote from a CSV file located in a assets subfolder
  * Uses template "cwsoft-shortcode/templates/Includes/RandomQuote.ss" for output 
  * 
  * @param $arguments (csv_file = 'subfolder_in_assets/csv_file.csv')
  * @param $content = null
  * @param $parser = null
  * @return processed template RandomQuote.ss
  */
 public static function cwsShortCodeRandomQuoteHandler($arguments, $content = null, $parser = null)
 {
     // only proceed if a CSV file was specified
     if (!isset($arguments['csv_file'])) {
         return;
     }
     $data = array();
     // check if CSV file exists in assets folder
     $csvFile = ASSETS_DIR . '/' . Convert::raw2sql($arguments['csv_file']);
     if (Director::fileExists($csvFile)) {
         $csv = new CSVParser($filename = $csvFile, $delimiter = '|', $enclosure = '"');
         // iterate through imported Quotes|Author entries and store results in array
         $citations = array();
         foreach ($csv as $row) {
             // only store entries with two data fields (quotation and author)
             if (count($row) !== 2) {
                 continue;
             }
             $citations[] = $row;
         }
         // prepare data for output (randomize array and fetch first citation for output)
         shuffle($citations);
         $data = $citations[0];
     }
     // use default citation if CSV file does not exist or is invalid
     if (!(isset($data['Quote']) && isset($data['Author']))) {
         $data['Quote'] = _t('cwsShortCodeRandomQuote.DEFAULT_QUOTE', 'Only who puts his heart and soul in it, can ignite the fire in others.');
         $data['Author'] = _t('cwsShortCodeRandomQuote.DEFAULT_AUTHOR', 'Augustinus');
     }
     // load template and process data
     $template = new SSViewer('RandomQuote');
     return $template->process(new ArrayData($data));
 }
	/**
	 * Constructor
	 *
	 * @param Controller $controller The parent controller, necessary to
	 *                               create the appropriate form action tag.
	 * @param string $name The method on the controller that will return this
	 *                     form object.
	 * @param FieldSet|FormField $fields All of the fields in the form - a
	 *                                   {@link FieldSet} of {@link FormField}
	 *                                   objects.
	 * @param FieldSet|FormAction $actions All of the action buttons in the
	 *                                     form - a {@link FieldSet} of
	 *                                     {@link FormAction} objects
	 * @param bool $checkCurrentUser If set to TRUE, it will be checked if a
	 *                               the user is currently logged in, and if
	 *                               so, only a logout button will be rendered
	 * @param string $authenticatorClassName Name of the authenticator class that this form uses.
	 */
	function __construct($controller, $name, $fields = null, $actions = null,
											 $checkCurrentUser = true) {

		// This is now set on the class directly to make it easier to create subclasses
		// $this->authenticator_class = $authenticatorClassName;

		$customCSS = project() . '/css/member_login.css';
		if(Director::fileExists($customCSS)) {
			Requirements::css($customCSS);
		}
		
		// Focus on the email input when the page is loaded
		Requirements::customScript("
			(function($){
				$(document).ready(function() {
					$('#Email input').focus();
				});
			})(jQuery);
		");

		if(isset($_REQUEST['BackURL'])) {
			$backURL = $_REQUEST['BackURL'];
		} else {
			$backURL = Session::get('BackURL');
		}

		if($checkCurrentUser && Member::currentUserID()) {
			$fields = new FieldSet();
			$actions = new FieldSet(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
		} else {
			if(!$fields) {
				$fields = new FieldSet(
					new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this),
					new TextField("Email", _t('Member.EMAIL', 'Email'), Session::get('SessionForms.MemberLoginForm.Email'), null, $this),
					new PasswordField("Password", _t('Member.PASSWORD', 'Password'))
				);
				if(Security::$autologin_enabled) {
					$fields->push(new CheckboxField(
						"Remember", 
						_t('Member.REMEMBERME', "Remember me next time?")
					));
				}
			}
			if(!$actions) {
				$actions = new FieldSet(
					new FormAction('dologin', _t('Member.BUTTONLOGIN', "Log in")),
					new LiteralField(
						'forgotPassword',
						'<p id="ForgotPassword"><a href="Security/lostpassword">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'
					)
				);
			}
		}

		if(isset($backURL)) {
			$fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
		}

		parent::__construct($controller, $name, $fields, $actions);
	}
    function init()
    {
        if (Director::fileExists(project() . "/css/VimeoGallery.css")) {
            Requirements::css(project() . "/css/VimeoGallery.css");
        } elseif (Director::fileExists('themes/' . project() . "/css/VimeoGallery.css")) {
            Requirements::css('themes/' . project() . "/css/VimeoGallery.css");
        } else {
            Requirements::css("vimeoservice/css/VimeoGallery.css");
        }
        // only include if necessary
        if ($this->ShowVideoInPopup) {
            Requirements::javascript("vimeoservice/javascript/jquery-1.4.4.min.js");
            Requirements::javascript("vimeoservice/javascript/jquery.prettyPhoto.js");
            Requirements::css('vimeoservice/css/prettyPhoto.css');
            $theme = $this->PopupTheme ? $this->PopupTheme : 'default';
            $width = $this->PopupWidth < 1 ? 400 : $this->PopupWidth;
            $height = $this->PopupHeight < 1 ? 225 : $this->PopupHeight;
            Requirements::customScript(<<<JS
\$(document).ready(function(){
\$("a[rel^='prettyPhoto']").prettyPhoto({
theme:'{$theme}',
default_width: {$width},
default_height: {$height},
});
});
JS
);
        }
        parent::init();
    }
 /**
  * Taken from MemberLoginForm::__construct with minor changes
  */
 public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     $customCSS = project() . '/css/member_login.css';
     if (Director::fileExists($customCSS)) {
         Requirements::css($customCSS);
     }
     if (isset($_REQUEST['BackURL'])) {
         $backURL = $_REQUEST['BackURL'];
     } else {
         $backURL = Session::get('BackURL');
     }
     if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
         $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this));
         $actions = new FieldList(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
     } else {
         if (!$fields) {
             $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this));
         }
         if (!$actions) {
             $actions = new FieldList(new FormAction('dologin', _t('GoogleAuthenticator.BUTTONLOGIN', "Log in with Google")));
         }
     }
     if (isset($backURL)) {
         $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
     }
     // Allow GET method for callback
     $this->setFormMethod('GET', true);
     parent::__construct($controller, $name, $fields, $actions);
 }
 /**
  * Gets a thumbnail for this file given a size. If it's an Image,
  * it will render the actual file. If not, it will provide an icon based
  * on the extension.
  * @param  int $w The width of the image
  * @param  int $h The height of the image
  * @return Image_Cached
  */
 public function getPreviewThumbnail($w = null, $h = null)
 {
     if (!$w) {
         $w = $this->owner->config()->grid_thumbnail_width;
     }
     if (!$h) {
         $h = $this->owner->config()->grid_thumbnail_height;
     }
     if ($this->IsImage() && Director::fileExists($this->owner->Filename)) {
         return $this->owner->CroppedImage($w, $h);
     }
     $sizes = Config::inst()->forClass('FileAttachmentField')->icon_sizes;
     sort($sizes);
     foreach ($sizes as $size) {
         if ($w <= $size) {
             if ($this->owner instanceof Folder) {
                 $file = $this->getFilenameForType('_folder', $size);
             } else {
                 $file = $this->getFilenameForType($this->owner->getExtension(), $size);
             }
             if (!file_exists(BASE_PATH . '/' . $file)) {
                 $file = $this->getFilenameForType('_blank', $size);
             }
             return new Image_Cached(Director::makeRelative($file));
         }
     }
 }
 /**
  * Return an image object representing the image in the given format.
  * This image will be generated using generateFormattedImage().
  * The generated image is cached, to flush the cache append ?flush=1 to your URL.
  *
  * Just pass the correct number of parameters expected by the working function
  *
  * @param string $format The name of the format.
  * @return Image_Cached
  */
 public function getFormattedImage($format)
 {
     $args = func_get_args();
     if ($this->ID && $this->Filename && Director::fileExists($this->Filename)) {
         $cacheFile = call_user_func_array(array($this, "cacheFilename"), $args);
         $fullPath = Director::baseFolder() . "/" . $cacheFile;
         if (!file_exists($fullPath) || self::$flush) {
             call_user_func_array(array($this, "generateFormattedImage"), $args);
             // If this image should be compressed, compress it now
             if ($this->getCompressed()) {
                 $compressor = $this->getCompressor();
                 try {
                     $compressor->compress($fullPath)->writeTo($fullPath);
                 } catch (Exception $e) {
                     // Do nothing, leave the uncompressed image in-place
                 }
             }
         }
         $cached = Injector::inst()->createWithArgs('Image_Cached', array($cacheFile));
         // Pass through the title so the templates can use it
         $cached->Title = $this->Title;
         // Pass through the parent, to store cached images in correct folder.
         $cached->ParentID = $this->ParentID;
         return $cached;
     }
 }
 /**
  * Include CSS for page icons. We're not using the JSTree 'types' option
  * because it causes too much performance overhead just to add some icons.
  * 
  * @return String CSS 
  */
 public function generatePageIconsCss()
 {
     $css = '';
     $classes = ClassInfo::subclassesFor('SiteTree');
     foreach ($classes as $class) {
         $obj = singleton($class);
         $iconSpec = $obj->stat('icon');
         if (!$iconSpec) {
             continue;
         }
         // Legacy support: We no longer need separate icon definitions for folders etc.
         $iconFile = is_array($iconSpec) ? $iconSpec[0] : $iconSpec;
         // Legacy support: Add file extension if none exists
         if (!pathinfo($iconFile, PATHINFO_EXTENSION)) {
             $iconFile .= '-file.gif';
         }
         $iconPathInfo = pathinfo($iconFile);
         // Base filename
         $baseFilename = $iconPathInfo['dirname'] . '/' . $iconPathInfo['filename'];
         $fileExtension = $iconPathInfo['extension'];
         $selector = ".page-icon.class-{$class}, li.class-{$class} > a .jstree-pageicon";
         if (Director::fileExists($iconFile)) {
             $css .= "{$selector} { background: transparent url('{$iconFile}') 0 0 no-repeat; }\n";
         } else {
             // Support for more sophisticated rules, e.g. sprited icons
             $css .= "{$selector} { {$iconFile} }\n";
         }
     }
     return $css;
 }
Exemple #11
0
 public function Icon()
 {
     $ext = strtolower($this->getExtension());
     if (Director::fileExists(POSTMARK_PATH . "/images/icons/files/{$ext}_32.gif")) {
         return POSTMARK_RELATIVE_PATH . "/images/icons/files/{$ext}_32.gif";
     }
     return POSTMARK_RELATIVE_PATH . "/images/icons/files/generic_32.gif";
 }
 public function init()
 {
     if (Director::fileExists(project() . "/css/gallery.css")) {
         Requirements::css(project() . "/css/gallery.css");
     } else {
         Requirements::css("basic-galleries/css/gallery.css");
     }
     parent::init();
 }
 public function init()
 {
     if (Director::fileExists(project() . "/css/calendar.css")) {
         Requirements::css(project() . "/css/calendar.css");
     } else {
         Requirements::css("basic-calendar/css/calendar.css");
     }
     parent::init();
 }
 public function init()
 {
     if (Director::fileExists(project() . "/css/files.css")) {
         Requirements::css(project() . "/css/files.css");
     } else {
         Requirements::css("file-listing/css/files.css");
     }
     parent::init();
 }
 public function init()
 {
     if (Director::fileExists(project() . "/css/textpage.css")) {
         Requirements::css(project() . "/css/textpage.css");
     } else {
         Requirements::css("TextPage/css/textpage.css");
     }
     parent::init();
 }
 function init()
 {
     RSSFeed::linkToFeed($this->Link() . "rss");
     if (Director::fileExists(project() . "/css/news.css")) {
         Requirements::css(project() . "/css/news.css");
     } else {
         Requirements::css("basic-news/css/news.css");
     }
     parent::init();
 }
 public function testFileExists()
 {
     $tempFileName = 'DirectorTest_testFileExists.tmp';
     $tempFilePath = TEMP_FOLDER . '/' . $tempFileName;
     // create temp file
     file_put_contents($tempFilePath, '');
     $this->assertTrue(Director::fileExists($tempFilePath), 'File exist check with absolute path');
     $this->assertTrue(Director::fileExists($tempFilePath . '?queryparams=1&foo[bar]=bar'), 'File exist check with query params ignored');
     unlink($tempFilePath);
 }
 public function onAfterInit()
 {
     if (Config::inst()->get("Blog", 'include_default_css')) {
         if (Director::fileExists(project() . "/css/blog.css")) {
             Requirements::css(project() . "/css/blog.css");
         } else {
             Requirements::css("mypswd-blog-tweaks/css/blog.css");
         }
     }
 }
 protected function path_for_file($fileOrUrl)
 {
     if (preg_match('{^//|http[s]?}', $fileOrUrl)) {
         return $fileOrUrl;
     } else {
         if (!Director::fileExists($fileOrUrl)) {
             $fileOrUrl = MODULES_DIR . '/' . $fileOrUrl;
         }
         return parent::path_for_file($fileOrUrl);
     }
 }
 /**
  * Return the relative URL of an icon for the file type,
  * based on the {@link appCategory()} value.
  * Images are searched for in "sapphire/images/app_icons/".
  *
  * @return String
  */
 public function getIcon($file)
 {
     $ext = $this->getExt($file);
     if (!Director::fileExists("themes/" . SSViewer::current_theme() . "/images/icons/file_extension_{$ext}.png")) {
         $ext = $this->appCategory($file);
     }
     if (!Director::fileExists("themes/" . SSViewer::current_theme() . "/images/icons/file_extension_{$ext}.png")) {
         $ext = "generic";
     }
     return "themes/" . SSViewer::current_theme() . "/images/icons/file_extension_{$ext}.png";
 }
 /**
  * Gets the icon for the panel. Use the icon of the subject page when possible, otherwise
  * fall back on a default icon.
  *
  * @return string
  */
 public function Icon()
 {
     $s = $this->Subject ? $this->Subject : "SiteTree";
     $file = Config::inst()->get($s, "icon", Config::INHERITED) . ".png";
     if (!Director::fileExists($file)) {
         $file = Config::inst()->get($s, "icon", Config::INHERITED) . "-file.gif";
     }
     if (!Director::fileExists($file)) {
         $file = "dashboard/images/section-editor.png";
     }
     return $file;
 }
 public function getInitFile()
 {
     if ($this->initFile) {
         return $this->initFile;
     } elseif (Director::fileExists($file = project() . "/javascript/simple_wysiwyg_init.js")) {
         return $file;
     } elseif (Director::fileExists($file = ViewableData::ThemeDir() . "/javascript/simple_wysiwyg_init.js")) {
         return $file;
     } else {
         return self::$default_init_js;
     }
 }
 /**
  * Gets an icon based on the file extension. If an image, use its own source. 
  *
  * @param File
  * @return string The path to the file.
  */
 public static function get_icon($f)
 {
     $ext = $f->Extension;
     if (!Director::fileExists("kickassets/images/{$ext}_64.png")) {
         $ext = $f->appCategory();
     }
     if (!Director::fileExists("kickassets/images/{$ext}_64.png")) {
         $ext = "generic";
     }
     $ext = strtolower($ext);
     return "kickassets/images/{$ext}_64.png";
 }
 /**
  * Sends download request to registered members
  * 
  * @param	object	GET 'filename' request 
  * @return	object	HTTP request
  */
 public function download(SS_HTTPRequest $request)
 {
     $filename = $request->param('Filename');
     if (Member::currentUserID() && $request->isGET() && !empty($filename)) {
         $file = DB::query("SELECT Filename FROM File  WHERE Name = '" . Convert::raw2sql($filename) . "'")->value();
         if (!empty($file) && Director::fileExists($file)) {
             $file_contents = file_get_contents(Director::getAbsFile($file));
             return SS_HTTPRequest::send_file($file_contents, $filename);
         }
     }
     return Security::permissionFailure($this);
 }
    /**
     * Constructor
     *
     * @param Controller $controller The parent controller, necessary to
     *                               create the appropriate form action tag.
     * @param string $name The method on the controller that will return this
     *                     form object.
     * @param FieldList|FormField $fields All of the fields in the form - a
     *                                   {@link FieldList} of {@link FormField}
     *                                   objects.
     * @param FieldList|FormAction $actions All of the action buttons in the
     *                                     form - a {@link FieldList} of
     *                                     {@link FormAction} objects
     * @param bool $checkCurrentUser If set to TRUE, it will be checked if a
     *                               the user is currently logged in, and if
     *                               so, only a logout button will be rendered
     * @param string $authenticatorClassName Name of the authenticator class that this form uses.
     */
    public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
    {
        // This is now set on the class directly to make it easier to create subclasses
        // $this->authenticator_class = $authenticatorClassName;
        $customCSS = project() . '/css/member_login.css';
        if (Director::fileExists($customCSS)) {
            Requirements::css($customCSS);
        }
        if (isset($_REQUEST['BackURL'])) {
            $backURL = $_REQUEST['BackURL'];
        } else {
            $backURL = Session::get('BackURL');
        }
        if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
            $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this));
            $actions = new FieldList(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
        } else {
            if (!$fields) {
                $label = singleton('Member')->fieldLabel(Member::config()->unique_identifier_field);
                $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this), $emailField = new TextField("Email", $label, null, null, $this), new PasswordField("Password", _t('Member.PASSWORD', 'Password')));
                if (Security::config()->remember_username) {
                    $emailField->setValue(Session::get('SessionForms.MemberLoginForm.Email'));
                } else {
                    // Some browsers won't respect this attribute unless it's added to the form
                    $this->setAttribute('autocomplete', 'off');
                    $emailField->setAttribute('autocomplete', 'off');
                }
                if (Security::config()->autologin_enabled) {
                    $fields->push(CheckboxField::create("Remember", _t('Member.KEEPMESIGNEDIN', "Keep me signed in"))->setAttribute('title', sprintf(_t('Member.REMEMBERME', "Remember me next time? (for %d days on this device)"), Config::inst()->get('RememberLoginHash', 'token_expiry_days'))));
                }
            }
            if (!$actions) {
                $actions = new FieldList(new FormAction('dologin', _t('Member.BUTTONLOGIN', "Log in")), new LiteralField('forgotPassword', '<p id="ForgotPassword"><a href="Security/lostpassword">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'));
            }
        }
        if (isset($backURL)) {
            $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
        }
        // Reduce attack surface by enforcing POST requests
        $this->setFormMethod('POST', true);
        parent::__construct($controller, $name, $fields, $actions);
        $this->setValidator(new RequiredFields('Email', 'Password'));
        // Focus on the email input when the page is loaded
        $js = <<<JS
\t\t\t(function() {
\t\t\t\tvar el = document.getElementById("MemberLoginForm_LoginForm_Email");
\t\t\t\tif(el && el.focus && (typeof jQuery == 'undefined' || jQuery(el).is(':visible'))) el.focus();
\t\t\t})();
JS;
        Requirements::customScript($js, 'MemberLoginFormFieldFocus');
    }
 /**
  * Finds the path for specified file.
  *
  * @param string $fileOrUrl
  * @return string|boolean
  */
 protected function path_for_file($fileOrUrl)
 {
     if (preg_match('{^//|http[s]?}', $fileOrUrl)) {
         return $fileOrUrl;
     } elseif (Director::fileExists($fileOrUrl)) {
         $path = pathinfo($fileOrUrl);
         $absoluteFile = Director::getAbsFile(preg_replace('/([^\\?]*)?.*/', '$1', $fileOrUrl));
         $v = '.' . filemtime($absoluteFile) . '.';
         $prefix = Director::baseURL();
         $fileOrUrl = $path['dirname'] . '/' . str_replace('.', $v, $path['basename']);
         return "{$prefix}{$fileOrUrl}";
     } else {
         return false;
     }
 }
 protected function findRequirementFile($fileToFind, $ext)
 {
     $result = $fileToFind;
     $folderList = $this->getFolderList($ext);
     $fileList = $this->getFileList($fileToFind, $ext);
     foreach ($folderList as $folder) {
         foreach ($fileList as $file) {
             if (Director::fileExists($folder . '/' . $file)) {
                 $result = $folder . '/' . $file;
                 break 2;
             }
         }
     }
     return $result;
 }
 /**
  * Constructor
  *
  * @param Controller $controller The parent controller, necessary to
  *                               create the appropriate form action tag.
  * @param string $name The method on the controller that will return this
  *                     form object.
  * @param FieldList|FormField $fields All of the fields in the form - a
  *                                   {@link FieldList} of {@link FormField}
  *                                   objects.
  * @param FieldList|FormAction $actions All of the action buttons in the
  *                                     form - a {@link FieldList} of
  *                                     {@link FormAction} objects
  * @param bool $checkCurrentUser If set to TRUE, it will be checked if a
  *                               the user is currently logged in, and if
  *                               so, only a logout button will be rendered
  * @param string $authenticatorClassName Name of the authenticator class that this form uses.
  */
 function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     // This is now set on the class directly to make it easier to create subclasses
     // $this->authenticator_class = $authenticatorClassName;
     $customCSS = project() . '/css/member_login.css';
     if (Director::fileExists($customCSS)) {
         Requirements::css($customCSS);
     }
     if (isset($_REQUEST['BackURL'])) {
         $_REQUEST['BackURL'] = str_replace("/RegistrationForm", "", $_REQUEST['BackURL']);
         $backURL = $_REQUEST['BackURL'];
     } else {
         if (strpos(Session::get('BackURL'), "/RegistrationForm") > 0) {
             Session::set('BackURL', str_replace("/RegistrationForm", "", Session::get('BackURL')));
         }
         $backURL = str_replace("/RegistrationForm", "", Session::get('BackURL'));
     }
     if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
         $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this));
         $actions = new FieldList(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
     } else {
         if (!$fields) {
             $label = singleton('Member')->fieldLabel(Member::get_unique_identifier_field());
             $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this), new TextField("Email", $label, Session::get('SessionForms.MemberLoginForm.Email'), null, $this), new PasswordField("Password", _t('Member.PASSWORD', 'Password')));
             if (Security::$autologin_enabled) {
                 $fields->push(new CheckboxField("Remember", _t('Member.REMEMBERME', "Remember me next time?")));
             }
         }
         if (!$actions) {
             $actions = new FieldList(new FormAction('dologin', _t('Member.BUTTONLOGIN', "Log in")), new LiteralField('forgotPassword', '<p id="ForgotPassword"><a href="Security/lostpassword">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'), new LiteralField('resendEmail', '<p id="ResendEmail"><a href="Security/verifyemail">' . _t('EmailVerifiedMember.BUTTONRESENDEMAIL', "I've lost my verification email") . '</a></p>'));
         }
     }
     if (isset($backURL)) {
         $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
     }
     parent::__construct($controller, $name, $fields, $actions);
     // Focus on the email input when the page is loaded
     // Only include this if other form JS validation is enabled
     /*		if($this->getValidator()->getJavascriptValidationHandler() != 'none') {
     			Requirements::customScript(<<<JS
     				(function() {
     					var el = document.getElementById("MemberLoginForm_LoginForm_Email");
     					if(el && el.focus) el.focus();
     				})();
     JS
     			);
     		}*/
 }
 public function getFormattedImage($format, $arg1 = null, $arg2 = null)
 {
     if ($this->ID && $this->Filename && Director::fileExists($this->Filename)) {
         $size = getimagesize(Director::baseFolder() . '/' . $this->getField('Filename'));
         $preserveOriginal = false;
         switch (strtolower($format)) {
             case 'croppedimage':
                 $preserveOriginal = $arg1 == $size[0] && $arg2 == $size[1];
                 break;
         }
         if ($preserveOriginal) {
             return $this;
         } else {
             return parent::getFormattedImage($format, $arg1, $arg2);
         }
     }
 }
 public function updateCMSFields(FieldList $fields)
 {
     // owner
     $owner = $this->owner;
     // SSSEO Tabset
     $fields->addFieldToTab('Root', new TabSet('SSSEO'));
     //// Configuration
     $tab = 'Root.SSSEO.Configuration';
     $fields->addFieldsToTab($tab, array(DropdownField::create('CharsetStatus', 'Character Set', $owner->dbObject('CharsetStatus')->enumValues())->setDescription('output: meta charset'), DropdownField::create('CanonicalStatus', 'Canonical Pages', $owner->dbObject('CanonicalStatus')->enumValues())->setDescription('output: link rel="canonical"'), DropdownField::create('TitleStatus', 'Title', $owner->dbObject('TitleStatus')->enumValues())->setDescription('output: meta title'), DropdownField::create('FaviconStatus', 'Favicon', $owner->dbObject('FaviconStatus')->enumValues())->setDescription('enable enhanced PNG favicon output for modern browsers ...and IE'), DropdownField::create('TouchIconStatus', 'Touch Icon', $owner->dbObject('TouchIconStatus')->enumValues())->setDescription('enable touch icons for desktop shortcuts and browser dashboards'), DropdownField::create('AuthorshipStatus', 'Authorship', $owner->dbObject('AuthorshipStatus')->enumValues())->setDescription('enable authorship of pages'), DropdownField::create('FacebookInsightsStatus', 'Facebook Insights', $owner->dbObject('FacebookInsightsStatus')->enumValues())->setDescription('enable Facebook Insights (Facebook Application)'), DropdownField::create('OpenGraphStatus', 'Open Graph', $owner->dbObject('OpenGraphStatus')->enumValues())->setDescription('enable Open Graph'), DropdownField::create('TwitterCardsStatus', 'Twitter Cards', $owner->dbObject('TwitterCardsStatus')->enumValues())->setDescription('enable Twitter Cards'), DropdownField::create('SchemaDotOrgStatus', 'Schema.org', $owner->dbObject('SchemaDotOrgStatus')->enumValues())->setDescription('enable Schema.org'), DropdownField::create('ExtraMetaStatus', 'Custom Metadata', $owner->dbObject('ExtraMetaStatus')->enumValues())->setDescription('allow custom metadata on pages<br />please ensure metadata content is entity encoded!')));
     //// Title
     if ($this->TitleEnabled()) {
         // remove
         // @todo move them, don't recreate them
         // 			$fields->removeByName(array('Title', 'Tagline'));
         $tab = 'Root.SSSEO.Title';
         // add
         $fields->addFieldsToTab($tab, array(TextField::create('Title', 'Title'), TextField::create('TitleSeparator', 'Title Separator')->setAttribute('placeholder', $this->titleSeparatorDefault())->setAttribute('size', 1)->setMaxLength(1)->setDescription('character limit: 1'), TextField::create('Tagline', 'Tagline')->setDescription('optional'), TextField::create('TaglineSeparator', 'Tagline Separator')->setAttribute('placeholder', $this->taglineSeparatorDefault())->setAttribute('size', 1)->setMaxLength(1)->setDescription('character limit: 1'), DropdownField::create('TitlePosition', 'Title Position', $owner->dbObject('TitlePosition')->enumValues())->setDescription('first: <u>Title</u> | Page - Tagline' . '<br />' . 'last: Page - Tagline | <u>Title</u>')));
     }
     //// Favicon
     if ($this->FaviconEnabled()) {
         $tab = 'Root.SSSEO.Favicon';
         // ICO
         if (Director::fileExists('favicon.ico')) {
             $fields->addFieldsToTab($tab, array(ReadonlyField::create('ReadonlyFaviconICO', 'Favicon ICO', 'favicon.ico found')->addExtraClass('success')));
         } else {
             $fields->addFieldsToTab($tab, array(ReadonlyField::create('ReadonlyFaviconICO', 'Favicon ICO', 'favicon.ico not found')->addExtraClass('error')));
         }
         // PNG
         $fields->addFieldsToTab($tab, array(UploadField::create('FaviconPNG', 'Favicon PNG')->setAllowedExtensions(array('png'))->setFolderName('SSSEO/')->setDescription('file format: PNG' . '<br />' . 'pixel dimensions: 152 x 152'), TextField::create('FaviconBG', 'IE10 Tile Background')->setAttribute('placeholder', $this->faviconBGDefault())->setAttribute('size', 6)->setMaxLength(6)->setDescription('format: hexadecimal triplet<br />character limit: 6')));
     }
     //// Touch Icon
     $tab = 'Root.SSSEO.TouchIcon';
     $fields->addFieldsToTab($tab, array(ReadonlyField::create('AppleTouchIconPrecomposed', 'apple-touch-icon-precomposed', 'on'), UploadField::create('TouchIconImage', 'Touch Icon Image')->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'))->setFolderName('SSSEO/TouchIcon/')->setDescription('file format: JPG, PNG, GIF<br />pixel dimensions: 400 x 400 (recommended, minimum 192)<br />pixel ratio: 1:1')));
     //// Facebook Insights
     if ($this->FacebookInsightsEnabled()) {
         $tab = 'Root.SSSEO.FacebookInsights';
         // add
         $fields->addFieldsToTab($tab, array(TextField::create('FacebookAppID', 'Facebook Application ID'), GridField::create('FacebookAdmins', 'Facebook Administrators', $this->owner->FacebookAdmins())->setConfig(GridFieldConfig_RelationEditor::create())));
     }
     //// Authorship
     if ($this->AuthorshipEnabled()) {
         $tab = 'Root.SSSEO.Authorship';
         // add fields
         $fields->addFieldsToTab($tab, array(TextField::create('GoogleProfileID', 'Google+ Profile ID'), TextField::create('FacebookProfileID', 'Facebook Profile ID')));
     }
 }