Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic vars fix #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 87 additions & 3 deletions cfg.d/z_pages.pl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
$c->{plugins}{"Screen::Page::New"}{params}{disable} = 0;
$c->{plugins}{"Screen::Admin::PageCreate"}{params}{disable} = 0;

# make all pages public
# Explicitly specify xapian indexing method
$c->{xapian}->{indexing_methods} = {} unless defined $c->{xapian}->{indexing_methods};
$c->{xapian}->{indexing_methods}->{'EPrints::MetaField::Page'} = 'text';

# Make all pages public
push @{$c->{public_roles}}, "+page/view";

# Redirect /page/nice-name to /id/page/x?nice-name
Expand All @@ -37,7 +41,8 @@
my( %o ) = @_;

if( $o{uri} =~ m|^$o{urlpath}/page/([^*]+)| ||
$o{uri} =~ m|^$o{urlpath}/(information\|policies\|contact).html| )
$o{uri} =~ m|^$o{urlpath}/(information\|policies\|contact).html| ||
$o{uri} =~ m|^$o{urlpath}/(help)/?$|i )
{
my $path = EPrints::DataObj::Page::tidy_path( $1 );
my $session = new EPrints::Session;
Expand Down Expand Up @@ -69,13 +74,92 @@

}, id => 'easy_pages_nice_url_redirect' );

######################################################################
#
# =pod Description for $c->{get_easy_page_substitutions}
#
# =over
#
# =item $repository->config('get_easy_page_substitutions')->($class_name, $repository)
#
# Requires C<$repository>.
# Returns an array of substitutions in array context,
# or an arrayref of substitutions otherwise.
# Substitutions would ideally be an object attribute,
# rather than being defined in this getter,
# and are intended for use by EPrints::DataObj::Page's
# put_here method/subroutine.
#
# =cut
#
######################################################################

$c->{get_easy_page_substitutions} = sub
{
my $class_name = shift; # Only a string - not a blessed object
# - so no $repository available from it.
my $repository = shift; # Subsequently, $repository needs to be passed in.

my @static_folder = (
path => "static",
scheme => "https",
host => 1,
);

my $static_folder = $repository->get_url(@static_folder)
->abs(
$repository->config('base_url')
);
# Upgrade cgi folder to relevant scheme
# as per settings in @cgi_folder array.

# The commented out approach of path => 'cgi'
# only works when https_cgiroot or http_cgiroot are defined in config,
# and has been commented out and only perl_url is defined in config,
# with a comment saying the base url configs such as perl_url should be depreciated.
# my @cgi_folder = (
# path => "cgi",
# scheme => "https",
# host => 1,
# );

my $cgi_folder = $repository->get_url(@static_folder)
->abs(
$repository->config('base_url')
)->as_string.
'/cgi';
# Literally appending the string '/cgi'
# to the end of the static url.

# The Substitutions we are getting...
my @values_in_order = (
'ADMIN-EMAIL' => $repository->config('adminemail'),
'ARCHIVE-NAME' => $repository->html_phrase('archive_name')->toString,
'ARCHIVE-URL' => $static_folder->as_string, # Assuming static folder is root!
# Is it always?
# Am I better off getting secure host from config?
'CGI-URL' => $cgi_folder,
);

return wantarray? @values_in_order:
\@values_in_order;
};

$c->{set_page_automatic_fields} = sub
{
my( $page ) = @_;

if( !$page->is_set( "path" ) )
{
$page->set_value( "path", EPrints::DataObj::Page::tidy_path( $page->get_value( "title" ) ) );
$page->set_value(
"path",
EPrints::DataObj::Page::tidy_path(
EPrints::DataObj::Page->put_here(
$page->repository,
$page->get_value( "title" ),
)
)
);
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions lang/en/phrases/page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@
<epp:phrase id="Plugin/Screen/Admin/PageCreate:title">Create a Page</epp:phrase>
<epp:phrase id="Plugin/Screen/Admin/PageCreate:page_created">A new page has been created. Go to <a href="/cgi/users/home?screen=Listing&amp;dataset=page">'Manage records > Pages'</a> to start editing.</epp:phrase>

<!-- Page Replacements / Substitutions -->
<epp:phrase id="EPrints/MetaField/Page:render_input_field_actual:replacements:instant_admin_email_link"><a href="mailto:PUT-ADMIN-EMAIL-HERE">PUT-ADMIN-EMAIL-HERE</a></epp:phrase>
<epp:phrase id="EPrints/MetaField/Page:render_input_field_actual:replacements:instant_archive_link"><a href="PUT-ARCHIVE-URL-HERE" target="_blank" rel="">PUT-ARCHIVE-NAME-HERE</a></epp:phrase>
</epp:phrases>
90 changes: 90 additions & 0 deletions lang/en/static/javascript/auto/65_easy_pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

// Called by EPrints::MetaField::Page::render_input_field_actual
var initTinyMCE_for_easy_pages = function(id,replacements, preview_substitutions){

tinymce.init({

// Setup:
setup: function (ed) {
ed.on(

// On Initialisation:
'init', function (e) {

// Switch to default font on load:
ed.execCommand("fontName", false, "HelveticaNeueLTPro-Roman");
this.getDoc().body.style.fontFamily = 'HelveticaNeueLTPro-Roman';

}
);
},

// General:
selector: id,
resize: 'both',
height: 500,
width: 700,
//cache_suffix: '?'+ new Date().getTime(), // Doesn't appear to work with 4.6.1 so commented out in favour of manually adding to the end of content_css further below.
relative_urls : true,
//document_base_url : 'http://example.eprints.org/', - as a value unique to each repository, this should be passed in or commented out/left at default.

// Functionality:
plugins: [
'advlist autolink lists link image charmap print anchor',
'searchreplace visualblocks code fullscreen preview_with_css_branding', // unique preview variation.
'insertdatetime media table contextmenu paste code textpattern', // textpattern 4.9.1 not in richtext ingredient
// and so added with/alongside easy_pages implementation
],

// Custom values for preview_with
preview_substitutions: preview_substitutions,
preview_data_uri_embedded_fonts: '/style/easy_pages_preview_data_uri_embedded_fonts.css?'+ new Date().getTime(),
//preview_substitutions, //shorthand for - preview_substitutions: preview_substitutions,

// Styling:
content_css: [
'/style/auto.css?'+ new Date().getTime(),
'/style/easy_pages_imports.css?'+ new Date().getTime(),
],
//font_css: ['/style/easy-pages-fonts.css'], // Can put @font-face statements here instead of relying on those in main.min.css if desired.

// Get rid of blue outlines around text you are entering.
inline_boundaries: false,
content_style: ".mce-container {"+
"border: 0px !important;"+
"}"+
"* [contentEditable='true']:focus"+
"{ outline-style: none ; }",


// Fonts available to use/select from UI:
font_formats: "Regular HelveticaNeue LT Pro='HelveticaNeueLTPro-Roman',helvetica;"+
"Italic HelveticaNeue LT Pro='HelveticaNeueLTPro-It';"+
"Bold HelveticaNeue LT Pro='HelveticaNeueLTPro-Bd';"+
"Bold Italic HelveticaNeue LT Pro='HelveticaNeueLTPro-BdIt';"+
"Generic Sans-Serif Family Font=sans-serif;",

// UI:
menubar: 'edit insert view format table tools',
toolbar: 'undo redo | insert | styleselect | bold italic | fontselect fontsizeselect | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code preview_with_css_branding',
link_list: [
{title: 'PUT-ARCHIVE-NAME-HERE', value: 'PUT-ARCHIVE-URL-HERE'},
{title: 'PUT-ADMIN-EMAIL-HERE', value: 'PUT-ADMIN-EMAIL-HERE'},
],

// Find and replace patterns
textpattern_patterns: [

// Use find and replace values declared here:
//{start: 'INSTANTLY-INSERT-SOMETHING-HERE', replacement: 'something'},

// Use values sent from Perl
// - i.e. where
// my %replacements = ( 'INSTANTLY-INSERT-THE-VALUE-FOR-THIS-KEY' => 'something' );
//{start: 'INSTANTLY-INSERT-THE-VALUE-FOR-THIS-KEY', replacement: replacements['INSTANTLY-INSERT-THE-VALUE-FOR-THIS-KEY']},
{start: 'INSTANT-ADMIN-EMAIL-LINK', replacement: replacements['INSTANT-ADMIN-EMAIL-LINK']},
{start: 'INSTANT-ARCHIVE-LINK', replacement: replacements['INSTANT-ARCHIVE-LINK']},
]

});
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preview plugin based on TinyMCE 4.6.1 Production plugin, with customisations.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading