Commit 1e175efd authored by Dave Lane's avatar Dave Lane
Browse files

co-branding content updates as well as prev/next text update, and disclaimer link

parent 351211fa
......@@ -591,7 +591,7 @@ function processPages() {
{
show_on_front: "page",
page_on_front: outline[0].wpID,
oeru_theme_menu_create: 1
oeru_course_menu_create: 1
},
function(err, a) {
if (err) {
......
......@@ -2,7 +2,7 @@
/* jshint node: true, multistr: true, trailing: true, esnext: true */
"use strict";
const VERSION = "1.1.1",
const VERSION = "1.2.0",
JQUERY = "http://code.jquery.com/jquery-2.1.1.min.js",
FILEPATH = "/home/www/www";
......@@ -12,6 +12,7 @@ var jsdom = require("jsdom"),
mkdirp = require("mkdirp"),
path = require("path"),
wordpress = require("wordpress"),
uri = require("uri-js"),
iframes, h5p,
theme;
......@@ -30,22 +31,42 @@ var pages = [], // list of page URLs to be processed
urls = {}, // map of original URLs to course URLs
parent_ids = {}, // map from URL to wp page id
pi = 0, // process index
base_url = "https://wikieducator.org", // no trailing slash
wp,
base_url = "",
opt,
options = {};
const doc = `Usage:
course [options] OUTLINE PAGEPREFIX
course -h | --help
course --version
Options:
Note: you may need to enclose argument values (e.g. BRAND, LOGO and PASS) in ''!
Options:
-b BRAND, --brand=BRAND Menubar brand [default: OCL4Ed].
-n NAME, --name=NAME Institution name/label.
-l LOGO, --logo=LOGO Institution logo.
-k LOGOLINK, --link=LOGOLINK Institution link.
--nameN=NAMEN --logoN=LOGON --linkN=LOGOLINKN Additional Institutions for cobranding, where N = 2-5.
--previous=PREVTEXT --next=NEXTTEXT Alternative text (e.g. translation).
--caption=CAPTION Caption for logo, e.g. Partner, Sponsor, etc.
-n NAME, --name=NAME Institution Name string.
--name2=NAME_2
--caption2=CAPTION_2
--logo2=LOGO_2
--link2=LOGOLINK_2 Additional Institution for cobranding.
--name3=NAME_3
--caption3=CAPTION_3
--logo3=LOGO_3
--link3=LOGOLINK_3 Additional Institution for cobranding.
--name4=NAME_4
--caption4=CAPTION_4
--logo4=LOGO_4
--link4=LOGOLINK_4 Additional Institution for cobranding.
--name5=NAME_5
--caption5=CAPTION_5
--logo5=LOGO_5
--link5=LOGOLINK_5 Additional Institution for cobranding.
--previous=PREVTEXT
--next=NEXTTEXT Alternative text (e.g. language translation).
--disclaimer=DISCLAIMERLINK Link to disclaimer info.
-t THEME, --theme=THEME Desired theme [default: default].
-u URLPREFIX, --urlprefix=URLPREFIX Filesystem URL component.
......@@ -65,13 +86,21 @@ Options:
--debugout Show content to be written.
-h, --help Show this help.
--version Display version.
`;
opt = docopt(doc, { version: VERSION });
console.log('one...');
opt = docopt(doc, {exit: false});
console.log(
`========================= ${new Date().toJSON()} =========================`
);
console.log(opt);
// work out the base_url for Wiki pages
console.log('Outline = ', opt['OUTLINE']);
base_url = getBaseURL(opt);
console.log('base_url: ', base_url);
//
// deal with other options
if (opt["--theme"]) {
theme = require("./themes/" + opt["--theme"]);
}
......@@ -83,9 +112,35 @@ if (opt["--h5p"]) {
}
if (opt["--link"] && opt["--link"].indexOf("//") === -1) {
opt["--link"] = "https://" + opt["--link"];
// work with other links, too, if present.
if (opt["--link2"] && opt["--link2"].indexOf("//") === -1) {
opt["--link2"] = "https://" + opt["--link2"];
if (opt["--link3"] && opt["--link3"].indexOf("//") === -1) {
opt["--link3"] = "https://" + opt["--link3"];
if (opt["--link4"] && opt["--link4"].indexOf("//") === -1) {
opt["--link4"] = "https://" + opt["--link4"];
if (opt["--link5"] && opt["--link5"].indexOf("//") === -1) {
opt["--link5"] = "https://" + opt["--link5"];
}
}
}
}
}
if (opt["--logo"] && opt["--logo"].indexOf("//") === -1) {
opt["--logo"] = opt["--urlprefix"] + "/img/" + opt["--logo"];
// work with other logos, too, if present.
if (opt["--logo2"] && opt["--logo2"].indexOf("//") === -1) {
opt["--logo2"] = opt["--urlprefix"] + "/img/" + opt["--logo2"];
if (opt["--logo3"] && opt["--logo3"].indexOf("//") === -1) {
opt["--logo3"] = opt["--urlprefix"] + "/img/" + opt["--logo3"];
if (opt["--logo4"] && opt["--logo4"].indexOf("//") === -1) {
opt["--logo4"] = opt["--urlprefix"] + "/img/" + opt["--logo4"];
if (opt["--logo5"] && opt["--logo5"].indexOf("//") === -1) {
opt["--logo5"] = opt["--urlprefix"] + "/img/" + opt["--logo5"];
}
}
}
}
}
if (opt["--options"]) {
opt["--options"].split(";").forEach(x => {
......@@ -130,6 +185,17 @@ if (opt["--wpurl"]) {
getOutline();
}
function getBaseURL(opt) {
let u = uri.parse(opt['OUTLINE']);
console.log('u: ', u);
base_url = u.scheme + '://' + u.host;
if (u.port) {
console.log("adding port: ", u.port);
base_url += ':' + u.port;
}
return base_url;
}
function pageToURL(p) {
val = opt["--urlprefix"] +
p.replace(opt.PAGEPREFIX, "").replace("?", "").replace("%3F", "");
......@@ -486,9 +552,9 @@ function processPage(pi) {
nl = urls[pages[np]];
}
if (opt["--previous"] && opt["--next"]) {
pt = opt["--previous"];
nt = opt["--next"];
}
pt = opt["--previous"];
nt = opt["--next"];
}
theme.prevnext($, pl, nl, pt, nt);
}
......@@ -566,7 +632,6 @@ function processPage(pi) {
}
});
console.log("opt: "+opt);
theme.process($, opt);
// if using analytics, install at the bottom of the page
......@@ -630,22 +695,30 @@ function processPage(pi) {
console.log("######");
}
try {
//console.log("---- data1 ----");
//console.log(data);
//console.log("---- data2 ----");
wp.newPost(page_desc, function(err, data) {
if (err) {
console.log(pi, pages[pi], err);
console.log('...error...')
console.log(page_desc, pi, pages[pi], err);
process.exit(9);
} else {
console.log('...no error, saving in WP...')
console.log(pi, "wp saved:", data);
outline[pi].wpID = data;
}
console.log("processing page...")
console.log( arguments );
setImmediate(processPages);
});
} catch (e) {
console.log(pi, "!!!error writing to wp");
console.log("------");
console.log( arguments );
console.log("------1");
console.log(outline[pi]);
console.log("------");
console.log("page_desc", page_desc);
console.log("------2");
//console.log("page_desc", page_desc);
setImmediate(processPages);
}
} else {
......@@ -664,20 +737,24 @@ function processPage(pi) {
}
function oeruMenuCreate() {
console.log('*********** start oeruMenuCreate **************');
// find out the methods this WordPress install supports
wp.listMethods(function(err, methods) {
if (err) {
console.log(`Unable to retrieve list of XMLRPC methods ${err}`);
process.exit(10);
} else {
// if oeru_theme.menu_create is supported, invoke it
if (methods.indexOf("oeru_theme.menu_create") > -1) {
wp.authenticatedCall("oeru_theme.menu_create", function(error, data) {
console.log('got XMLRPC Methods');
// if oeru_course.menu_create is supported, invoke it
if (methods.indexOf("oeru_course.menu_create") > -1) {
console.log('trying to create a menu... ');
wp.authenticatedCall("oeru_course.menu_create", function(error, data) {
console.log('completed XMLRPC call... ');
if (error) {
console.log(`Menu creation failed: ${error}`);
process.exit(11);
} else {
console.log("Menu created", data);
console.log("Menu created");
}
});
}
......@@ -687,13 +764,14 @@ function oeruMenuCreate() {
function processPages() {
console.log(`---- processPages(pi=${pi}) ----`);
console.log('outline[0]: ', outline[0]);
if (pi >= pages.length) {
wp.authenticatedCall(
"wp.setOptions",
{
show_on_front: "page",
page_on_front: outline[0].wpID,
oeru_theme_menu_create: 1
oeru_course_menu_create: 1
},
function(err, a) {
if (err) {
......@@ -783,6 +861,7 @@ function getOutline() {
}
$sub = $(this).children("ul");
info.base_url = base_url;
info.text = text;
info.wkpage = wkpage;
info.url = url;
......
......@@ -37,8 +37,8 @@ wp.listMethods(function(error, methods) {
console.log(`Unable to retrieve method list: ${error}`);
} else {
console.log('XMLRCP methods', methods);
if (opt['--wpmenu'] && methods.indexOf('oeru_theme.menu_create') > -1) {
wp.authenticatedCall('oeru_theme.menu_create', function(error, data) {
if (opt['--wpmenu'] && methods.indexOf('oeru_course.menu_create') > -1) {
wp.authenticatedCall('oeru_course.menu_create', function(error, data) {
if (error) {
console.log(`Menu creation failed: ${error}`);
} else {
......@@ -48,4 +48,3 @@ wp.listMethods(function(error, methods) {
}
}
});
......@@ -45,7 +45,10 @@ module.exports = {
);
},
footer: function($, opt, pages, pi) {
console.log('in footer: ', opt);
var p = opt["--urlprefix"] + "/img/";
$(".printfooter").remove();
$("#footer")
......
......@@ -45,23 +45,59 @@ module.exports = {
.attr("src")
.replace("/icons/", "/buttons/");
var footerlogo = "",
contentURL = `https://wikieducator.org${outlineItem.wkpage}`;
if (opt["--logo"]) {
footerlogo = `<img src="${opt[
"--logo"
]}" alt="institution logo" style="float: right;">`;
if (opt["--link"]) {
footerlogo = `<a href="${opt["--link"]}">${footerlogo}</a>`;
contentURL = `${outlineItem.base_url}${outlineItem.wkpage}`;
if (opt['--logo']) {
alt_tag = "institution logo";
if (opt['--name']) { alt_tag = `${alt_tag} for ${opt['--name']}`; }
footerlogo = `<img src="${opt['--logo']}" alt="${alt_tag}" />`;
if (opt["--link"]) { footerlogo = `<a href="${opt["--link"]}" title="${alt_tag}">${footerlogo}</a>`; }
if (opt["--caption"]) { footerlogo = `${footerlogo}<p class="caption">${opt["--caption"]}</p>`; }
footerlogo = `<div class="logo first">${footerlogo}</div>`;
if (opt['--link2']) {
alt_tag2 = "institution logo";
if (opt['--name2']) { alt_tag2 = `${alt_tag2} for ${opt['--name2']}`; }
footerlogo2 = `<img src="${opt['--logo2']}" alt="${alt_tag2}" />`;
if (opt["--link2"]) { footerlogo2 = `<a href="${opt["--link2"]}" title="${alt_tag2}">${footerlogo2}</a>`; }
if (opt["--caption2"]) { footerlogo2 = `${footerlogo2}<p class="caption">${opt["--caption2"]}</p>`; }
footerlogo2 = `<div class="logo second">${footerlogo2}</div>`;
footerlogo = footerlogo + footerlogo2;
if (opt['--link3']) {
alt_tag3 = "institution logo";
if (opt['--name3']) { alt_tag3 = `${alt_tag3} for ${opt['--name3']}`; }
footerlogo3 = `<img src="${opt['--logo3']}" alt="${alt_tag3}" />`;
if (opt["--link3"]) { footerlogo3 = `<a href="${opt["--link3"]}" title="${alt_tag3}">${footerlogo3}</a>`; }
if (opt["--caption3"]) { footerlogo3 = `${footerlogo3}<p class="caption">${opt["--caption3"]}</p>`; }
footerlogo3 = `<div class="logo third">${footerlogo3}</div>`;
footerlogo = footerlogo + footerlogo3;
if (opt['--link4']) {
alt_tag4 = "institution logo";
if (opt['--name4']) { alt_tag4 = `${alt_tag4} for ${opt['--name4']}`; }
footerlogo4 = `<img src="${opt['--logo4']}" alt="${alt_tag4}" />`;
if (opt["--link4"]) { footerlogo4 = `<a href="${opt["--link4"]}" title="${alt_tag4}">${footerlogo4}</a>`; }
if (opt["--caption4"]) { footerlogo4 = `${footerlogo4}<p class="caption">${opt["--caption4"]}</p>`; }
footerlogo4 = `<div class="logo fourth">${footerlogo4}</div>`;
footerlogo = footerlogo + footerlogo4;
if (opt['--link5']) {
alt_tag5 = "institution logo";
if (opt['--name5']) { alt_tag5 = `${alt_tag5} for ${opt['--name5']}`; }
footerlogo5 = `<img src="${opt['--logo5']}" alt="${alt_tag5}" />`;
if (opt["--link5"]) { footerlogo5 = `<a href="${opt["--link5"]}" title="${alt_tag5}">${footerlogo5}</a>`; }
if (opt["--caption5"]) { footerlogo5 = `${footerlogo5}<p class="caption">${opt["--caption5"]}</p>`; }
footerlogo5 = `<div class="logo fifth">${footerlogo5}</div>`;
footerlogo = footerlogo + footerlogo5;
}
}
}
}
}
// because there's always a subfooter, we'll put a divider on the bottom of the footer logo if there is one
if (footerlogo != "") { footerlogo = `<div class="logos">${footerlogo}</div><div class="clear" /><div class="rule"/>`; }
divider = ' | ';
disclaimer = "";
if (opt['--disclaimer']) { disclaimer = ` ${divider} <a href="${opt['--disclaimer']}">Disclaimer</a>`; }
notices = `<div class="copyright"><a href="${contentURL}" title="original content in WikiEducator" target="WikiEducator">Content</a> is available under the <a rel="license" href="https://wikieducator.org/WikiEducator:Copyrights" title="WikiEducator:Copyrights">Creative Commons Attribution Share Alike License</a>. <a href="https://creativecommons.org/licenses/by-sa/4.0/"><img class="cc" src="${iconsrc}" alt="Creative Commons Attribution Share-Alike License"></a></div><div class="links"><a href="https://wikieducator.org/WikiEducator:Privacy_policy">Privacy Policy</a>${divider}<a href="https://wikieducator.org${outlineItem.wkpage}?action=history">Authors</a>${disclaimer}</div>`;
$(".printfooter").remove();
$("body").append(`
<footer>
[oeru_advanced_footer content='${footerlogo}
<a href="${contentURL}" title="original content in WikiEducator" target="WikiEducator">Content</a> is available under the
<a rel="license" href="https://wikieducator.org/WikiEducator:Copyrights" title="WikiEducator:Copyrights">Creative Commons Attribution Share Alike License</a>.
<a href="https://wikieducator.org/WikiEducator:Privacy_policy">Privacy Policy</a> | <a href="https://wikieducator.org${outlineItem.wkpage}?action=history">Authors</a><a href="http://creativecommons.org/licenses/by-sa/3.0/"><img class="cc" src="${iconsrc}" alt="Creative Commons Attribution Share-Alike License"></a>']
</footer>`);
$("body").append(`<footer>[oeru_advanced_footer content='${footerlogo}<div class="notices">${notices}</div>']</footer>`);
$("footer img.cc").attr("src", iconsrc);
},
......
......@@ -9,8 +9,8 @@ import MySQLdb
#node = '/home/ubuntu/.nvm/versions/node/v4.2.1/bin/node'
node = '/usr/bin/nodejs'
#weurl = 'https://wikieducator.org'
weurl = 'https://c.wikieducator.org'
#weurl = 'https://wikieducator.org'
weurl = 'https://c.wikieducator.org'
#osdir = '/home/data/wikieducator.org/course-snapshot/src'
osdir = '/home/data/c.wikieducator.org/course-snapshot/src'
debug = 1;
......@@ -59,7 +59,7 @@ if not debug:
WHERE id=%s""",
(row['id'],))
db.commit()
else:
else:
print 'not updating db status'
result = 0
errmsg = ''
......@@ -105,22 +105,27 @@ else:
if 'logo' in opt and opt['logo']:
args.extend(['--logo', opt['logo'],
'--link', opt['link'],
'--caption', opt['caption'],
'--name', opt['name']])
if 'logo2' in opt and opt['logo2']:
args.extend(['--logo2', opt['logo2'],
'--link2', opt['link2'],
'--caption2', opt['caption2'],
'--name2', opt['name2']])
if 'logo3' in opt and opt['logo3']:
args.extend(['--logo3', opt['logo3'],
'--link3', opt['link3'],
'--caption3', opt['caption3'],
'--name3', opt['name3']])
if 'logo4' in opt and opt['logo4']:
args.extend(['--logo4', opt['logo4'],
'--link4', opt['link4'],
'--caption4', opt['caption4'],
'--name4', opt['name4']])
if 'logo5' in opt and opt['logo5']:
args.extend(['--logo5', opt['logo5'],
'--link5', opt['link5'],
'--caption5', opt['caption5'],
'--name5', opt['name5']])
if 'previous' in opt and opt['previous']:
args.extend(['--previous', opt['previous']])
......@@ -130,14 +135,14 @@ if 'disclaimer' in opt and opt['disclaimer']:
args.extend(['--disclaimer', opt['disclaimer']])
args.extend([opt['outline'], title])
if debug:
if debug:
print '======== args ========='
print args
log = open(options.get('log', '/dev/null'), 'a')
err = open(options.get('errlog', '/dev/null'), 'a')
result = subprocess.call(args, stdout=log, stderr=err)
if debug:
if debug:
print "Result:", result
if not debug:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment