Ejemplo n.º 1
2
 function generatePDF()
 {
     // tempfolder
     $tmpBaseFolder = TEMP_FOLDER . '/shopsystem';
     $tmpFolder = project() ? "{$tmpBaseFolder}/" . project() : "{$tmpBaseFolder}/site";
     if (is_dir($tmpFolder)) {
         Filesystem::removeFolder($tmpFolder);
     }
     if (!file_exists($tmpFolder)) {
         Filesystem::makeFolder($tmpFolder);
     }
     $baseFolderName = basename($tmpFolder);
     //Get site
     Requirements::clear();
     $link = Director::absoluteURL($this->pdfLink() . "/?view=1");
     $response = Director::test($link);
     $content = $response->getBody();
     $content = utf8_decode($content);
     $contentfile = "{$tmpFolder}/" . $this->PublicURL . ".html";
     if (!file_exists($contentfile)) {
         // Write to file
         if ($fh = fopen($contentfile, 'w')) {
             fwrite($fh, $content);
             fclose($fh);
         }
     }
     return $contentfile;
 }
 static function get_data_dir()
 {
     if (isset(self::$data_dir)) {
         return self::$data_dir;
     }
     return project() . '/testdata/';
 }
    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();
    }
Ejemplo n.º 4
0
	/**
	 * 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);
	}
Ejemplo n.º 5
0
 /**
  * Gets a namespace for all _t() translation functions
  *
  * @return string
  */
 public static function generate_i18n_namespace()
 {
     if ($namespace = SilverSmithDefaults::get('DefaultNamespace')) {
         return $namespace;
     }
     return ucwords(project());
 }
 /**
  * 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);
 }
Ejemplo n.º 7
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()));
     }
 }
 /**
  * looked-up the email template_paths.
  * if not set, will look up both theme folder and project folder
  * in both cases, email folder exsits or Email folder exists
  * return an array containing all folders pointing to the bunch of email templates
  *
  * @return array
  */
 public static function template_paths()
 {
     if (!isset(self::$template_paths)) {
         if (class_exists('SiteConfig') && ($config = SiteConfig::current_site_config()) && $config->Theme) {
             $theme = $config->Theme;
         } elseif (SSViewer::current_custom_theme()) {
             $theme = SSViewer::current_custom_theme();
         } elseif (SSViewer::current_theme()) {
             $theme = SSViewer::current_theme();
         } else {
             $theme = false;
         }
         if ($theme) {
             if (file_exists("../" . THEMES_DIR . "/" . $theme . "/templates/email")) {
                 self::$template_paths[] = THEMES_DIR . "/" . $theme . "/templates/email";
             }
             if (file_exists("../" . THEMES_DIR . "/" . $theme . "/templates/Email")) {
                 self::$template_paths[] = THEMES_DIR . "/" . $theme . "/templates/Email";
             }
         }
         $project = project();
         if (file_exists("../" . $project . '/templates/email')) {
             self::$template_paths[] = $project . '/templates/email';
         }
         if (file_exists("../" . $project . '/templates/Email')) {
             self::$template_paths[] = $project . '/templates/Email';
         }
     } else {
         if (is_string(self::$template_paths)) {
             self::$template_paths = array(self::$template_paths);
         }
     }
     return self::$template_paths;
 }
Ejemplo n.º 9
0
 public function init()
 {
     parent::init();
     // 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" => (SSViewer::current_theme() ? "themes/" . SSViewer::current_theme() : project()) . "/css/editor.css", "BaseURL" => Director::absoluteBaseURL(), "Lang" => i18n::get_tinymce_lang()));
     }
     Requirements::javascript('cms/javascript/CMSMain.js');
     Requirements::javascript('cms/javascript/CMSMain_left.js');
     Requirements::javascript('cms/javascript/CMSMain_right.js');
     Requirements::javascript('sapphire/javascript/UpdateURL.js');
     /**
      * HACK ALERT: Project-specific requirements
      * 
      * We need a better way of including all of the CSS that *might* be used by this application.
      * Perhaps the ajax responses can include some instructions to go get more CSS / JavaScript?
      */
     Requirements::css("survey/css/SurveyFilter.css");
     Requirements::javascript("survey/javascript/SurveyResponses.js");
     Requirements::javascript("survey/javascript/FormResponses.js");
     Requirements::javascript("parents/javascript/NotifyMembers.js");
     Requirements::css("tourism/css/SurveyCMSMain.css");
     Requirements::javascript("tourism/javascript/QuotasReport.js");
     Requirements::javascript("sapphire/javascript/ReportField.js");
     Requirements::javascript("ptraining/javascript/BookingList.js");
     Requirements::javascript("forum/javascript/ForumAccess.js");
     Requirements::javascript('gallery/javascript/GalleryPage_CMS.js');
 }
Ejemplo n.º 10
0
/**
 * Entity data listener
 *
 * @param array $data
 *
 * @return void
 */
function listener_data_entity(array &$data) : void
{
    foreach ($data as $id => $item) {
        $item['id'] = $id;
        $item = data_entity($item);
        $item['attr'] = data_order($item['attr'], ['sort' => 'asc']);
        $data[$id] = $item;
    }
    if (!($entities = all('entity', ['project_id' => project('ids')]))) {
        return;
    }
    $attrs = all('attr', ['project_id' => project('ids')], ['index' => ['entity_id', 'uid']]);
    foreach ($entities as $id => $item) {
        if (!empty($data[$id])) {
            message(_('Can not use reserved Id %s for Entity %s', $id, $item['name']));
            continue;
        }
        $item = array_replace($data['content'], $item);
        $item['model'] = 'eav';
        if (!empty($attrs[$id])) {
            foreach ($attrs[$id] as $uid => $attr) {
                if (empty($item['attr'][$uid])) {
                    $attr['col'] = 'value';
                    $attr['eav_id'] = $attr['id'];
                    unset($attr['id'], $attr['uid'], $attr['project_id']);
                    $item['attr'][$uid] = $attr;
                }
            }
        }
        unset($item['project_id']);
        $item = data_entity($item);
        $item['attr'] = data_order($item['attr'], ['sort' => 'asc']);
        $data[$id] = $item;
    }
}
Ejemplo n.º 11
0
 /**
  * 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);
 }
 /**
  * Returns the path for the compiled JS file. Falls back on
  * the project dir if {@link self::$compiled_path} is undefined.
  *
  * @return string
  */
 public function getCompiledPath()
 {
     $new_file = basename($this->uncompiledFile, ".coffee") . ".js";
     if (!$this->config()->compiled_path) {
         return project() . "/javascript/" . $new_file;
     }
     return $this->config()->compiled_path . "/" . $new_file;
 }
Ejemplo n.º 13
0
Archivo: url.php Proyecto: akilli/qnd
/**
 * Project media URL
 *
 * @param string $path
 *
 * @return string
 */
function url_media(string $path = '') : string
{
    static $base;
    if ($base === null) {
        $base = '/asset/' . project('id') . '/media';
    }
    return $base . ($path ? '/' . $path : '');
}
 /**
  * this is mainly a test harness
  * @return [type] [description]
  */
 public function setupMailer()
 {
     Requirements::clear();
     $this->parseVariables(true);
     if (empty($this->from)) {
         $this->from = Email::config()->admin_email;
     }
     $headers = $this->customHeaders;
     if (project()) {
         $headers['X-SilverStripeSite'] = project();
     }
     $to = $this->to;
     $from = $this->from;
     $subject = $this->subject;
     if ($sendAllTo = $this->config()->send_all_emails_to) {
         $subject .= " [addressed to {$to}";
         $to = $sendAllTo;
         if ($this->cc) {
             $subject .= ", cc to {$this->cc}";
         }
         if ($this->bcc) {
             $subject .= ", bcc to {$this->bcc}";
         }
         $subject .= ']';
         unset($headers['Cc']);
         unset($headers['Bcc']);
     } else {
         if ($this->cc) {
             $headers['Cc'] = $this->cc;
         }
         if ($this->bcc) {
             $headers['Bcc'] = $this->bcc;
         }
     }
     if ($ccAllTo = $this->config()->cc_all_emails_to) {
         if (!empty($headers['Cc']) && trim($headers['Cc'])) {
             $headers['Cc'] .= ', ' . $ccAllTo;
         } else {
             $headers['Cc'] = $ccAllTo;
         }
     }
     if ($bccAllTo = $this->config()->bcc_all_emails_to) {
         if (!empty($headers['Bcc']) && trim($headers['Bcc'])) {
             $headers['Bcc'] .= ', ' . $bccAllTo;
         } else {
             $headers['Bcc'] = $bccAllTo;
         }
     }
     if ($sendAllfrom = $this->config()->send_all_emails_from) {
         if ($from) {
             $subject .= " [from {$from}]";
         }
         $from = $sendAllfrom;
     }
     Requirements::restore();
     return self::mailer()->setupMailer($to, $from, $subject, $this->attachments, $headers);
 }
 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/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/textpage.css")) {
         Requirements::css(project() . "/css/textpage.css");
     } else {
         Requirements::css("TextPage/css/textpage.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 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");
         }
     }
 }
 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();
 }
Ejemplo n.º 21
0
 public function init()
 {
     parent::init();
     Requirements::css(CMS_DIR . '/css/ReportAdmin.css');
     // Set custom options for TinyMCE specific to ReportAdmin
     HtmlEditorConfig::get('cms')->setOption('ContentCSS', project() . '/css/editor.css');
     HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang());
     // Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
     Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js');
 }
Ejemplo n.º 22
0
 /**
  * Pushes a class and template manifest instance that include tests onto the
  * top of the loader stacks.
  */
 public static function use_test_manifest()
 {
     $classManifest = new SS_ClassManifest(BASE_PATH, true, isset($_GET['flush']));
     SS_ClassLoader::instance()->pushManifest($classManifest, false);
     SapphireTest::set_test_class_manifest($classManifest);
     SS_TemplateLoader::instance()->pushManifest(new SS_TemplateManifest(BASE_PATH, project(), true, isset($_GET['flush'])));
     Config::inst()->pushConfigStaticManifest(new SS_ConfigStaticManifest(BASE_PATH, true, isset($_GET['flush'])));
     // Invalidate classname spec since the test manifest will now pull out new subclasses for each internal class
     // (e.g. Member will now have various subclasses of DataObjects that implement TestOnly)
     DataObject::clear_classname_spec_cache();
 }
Ejemplo n.º 23
0
function picture_footer()
{
    if (project() && project()->type() == 'picture') {
        echo '<script type="text/javascript">
jQuery(document).ready(function($){
  $("#PMP-picture img").parent("a").colorbox({rel:"group", speed:350,width:"85%",initialWidth:"300",initialHeight:"100",
  opacity:0.8,loop:false,scrolling:false,escKey:false,arrowKey:false,top:false,right:false,bottom:false,left:false});
});
</script>';
    }
}
 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;
     }
 }
Ejemplo n.º 25
0
 function export()
 {
     if ($_REQUEST['baseurl']) {
         $base = $_REQUEST['baseurl'];
         if (substr($base, -1) != '/') {
             $base .= '/';
         }
         Director::setBaseURL($base);
     }
     $folder = '/tmp/static-export/' . project();
     if (!project()) {
         $folder .= 'site';
     }
     if (!file_exists($folder)) {
         mkdir($folder, Filesystem::$folder_create_mask, true);
     }
     $f1 = Director::baseFolder() . '/assets';
     $f2 = Director::baseFolder() . '/' . project();
     `cd {$folder}; ln -s {$f1}; ln -s {$f2}`;
     $baseFolder = basename($folder);
     if ($folder && file_exists($folder)) {
         $pages = DataObject::get("SiteTree");
         foreach ($pages as $page) {
             $subfolder = "{$folder}/{$page->URLSegment}";
             $contentfile = "{$folder}/{$page->URLSegment}/index.html";
             // Make the folder
             if (!file_exists($subfolder)) {
                 mkdir($subfolder, Filesystem::$folder_create_mask);
             }
             // Run the page
             Requirements::clear();
             $controllerClass = "{$page->class}_Controller";
             if (class_exists($controllerClass)) {
                 $controller = new $controllerClass($page);
                 $pageContent = $controller->run(array());
                 // Write to file
                 if ($fh = fopen($contentfile, 'w')) {
                     fwrite($fh, $pageContent->getBody());
                     fclose($fh);
                 }
             }
         }
         copy("{$folder}/home/index.html", "{$folder}/index.html");
         `cd /tmp/static-export; tar -czhf {$baseFolder}.tar.gz {$baseFolder}`;
         $content = file_get_contents("/tmp/static-export/{$baseFolder}.tar.gz");
         Filesystem::removeFolder('/tmp/static-export');
         HTTP::sendFileToBrowser($content, "{$baseFolder}.tar.gz");
         return null;
     } else {
         echo _t('StaticExporter.ONETHATEXISTS', "Please specify a folder that exists");
     }
 }
    /**
     * 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');
    }
 function export()
 {
     // specify custom baseurl for publishing to other webroot
     if (isset($_REQUEST['baseurl'])) {
         $base = $_REQUEST['baseurl'];
         if (substr($base, -1) != '/') {
             $base .= '/';
         }
         Director::setBaseURL($base);
     }
     // setup temporary folders
     $tmpBaseFolder = TEMP_FOLDER . '/static-export';
     $tmpFolder = project() ? "{$tmpBaseFolder}/" . project() : "{$tmpBaseFolder}/site";
     if (!file_exists($tmpFolder)) {
         Filesystem::makeFolder($tmpFolder);
     }
     $baseFolderName = basename($tmpFolder);
     // symlink /assets
     $f1 = ASSETS_PATH;
     $f2 = Director::baseFolder() . '/' . project();
     `cd {$tmpFolder}; ln -s {$f1}; ln -s {$f2}`;
     // iterate through all instances of SiteTree
     $pages = DataObject::get("SiteTree");
     foreach ($pages as $page) {
         $subfolder = "{$tmpFolder}/" . trim($page->RelativeLink(null, true), '/');
         $contentfile = "{$tmpFolder}/" . trim($page->RelativeLink(null, true), '/') . '/index.html';
         // Make the folder
         if (!file_exists($subfolder)) {
             Filesystem::makeFolder($subfolder);
         }
         // Run the page
         Requirements::clear();
         $link = Director::makeRelative($page->Link());
         $response = Director::test($link);
         // Write to file
         if ($fh = fopen($contentfile, 'w')) {
             fwrite($fh, $response->getBody());
             fclose($fh);
         }
     }
     // copy homepage (URLSegment: "home") to webroot
     copy("{$tmpFolder}/home/index.html", "{$tmpFolder}/index.html");
     // archive all generated files
     `cd {$tmpBaseFolder}; tar -czhf {$baseFolderName}.tar.gz {$baseFolderName}`;
     $archiveContent = file_get_contents("{$tmpBaseFolder}/{$baseFolderName}.tar.gz");
     // remove temporary files and folder
     Filesystem::removeFolder($tmpBaseFolder);
     // return as download to the client
     $response = SS_HTTPRequest::send_file($archiveContent, "{$baseFolderName}.tar.gz", 'application/x-tar-gz');
     echo $response->output();
 }
 public function init()
 {
     parent::init();
     //set the report we are currently viewing from the URL
     $this->reportClass = isset($this->urlParams['ReportClass']) && $this->urlParams['ReportClass'] !== 'index' ? $this->urlParams['ReportClass'] : null;
     $allReports = SS_Report::get_reports();
     $this->reportObject = isset($allReports[$this->reportClass]) ? $allReports[$this->reportClass] : null;
     // Set custom options for TinyMCE specific to ReportAdmin
     HtmlEditorConfig::get('cms')->setOption('content_css', project() . '/css/editor.css');
     HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang());
     // Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
     Requirements::block(FRAMEWORK_DIR . '/javascript/HtmlEditorField.js');
     Requirements::javascript(REPORTS_DIR . '/javascript/ReportAdmin.js');
 }
 /**
  * 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
     			);
     		}*/
 }
Ejemplo n.º 30
0
 /**
  * 单独页面
  * @param $page
  */
 public function page($page)
 {
     if (\ULib\Router::$begin_status) {
         lib()->load('project', 'menu')->add("project", new \ULib\Project($page, 0));
         lib()->add('menu', new \ULib\Menu(true));
         set_title(project()->title(), site_title(false));
         theme()->header_add("<script>var PM_PAGE_ID = " . project()->id() . ";</script>", 40);
         theme()->set_desc(project()->desc());
         theme()->set_keywords(project()->keywords());
         header("Content-Type:text/html; charset=utf-8");
         $this->__view('comm/header.php');
         $this->__view('project/page.php');
         $this->__view('comm/footer.php');
     } else {
         $this->__load_404();
     }
 }