initial commit in new repo

sql-version-freeze
Ro 6 years ago
parent eec14d30d5
commit 6f7fed59f3

@ -0,0 +1 @@
{ "presets": ["env"] }

13
.gitignore vendored

@ -0,0 +1,13 @@
content/
node_modules/
.sass-cache/
.cache/
content/folio-images
.ftpconfig
.vscode/
config.development.json
*.swp
/_migrations/
/config.json
/_maintenance/
*.DS_Store

@ -0,0 +1,109 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var MemoryStore = require('memorystore')(session)
var flash = require('connect-flash');
var theme = "default";
var app = express();
// view engine setup
app.set('views', path.join(__dirname, '../themes'));
app.set('view engine', 'pug');
//app.use(express.static(__dirname+'/content/data'));
app.use(express.static(__dirname + '../content/folio-images'));
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
//app.use(require('node-compass')({mode: 'expanded', css:'styles', sass: 'styles', project: path.join(__dirname, 'src')}));
app.use(express.static(path.join(__dirname, '../content')));
app.use(express.static(path.join(__dirname, '../themes')));
// Why Do we need this key ?
/**
app.use(session({
secret: '1KqZ18W8KskE1iSw',
saveUninitialized: false,
resave: false,
cookie:{maxAge:608800000}
}));
**/
app.use(session({
store: new MemoryStore({
checkPeriod: 86400000 // prune expired entries every 24h
}),
secret: '1KqZ18W8KskE1iSw',
saveUninitialized: false,
resave: false,
cookie: { maxAge: 608800000 }
}))
app.use(flash());
//sections
var front = require('./routes/front/index')(session);
var back = require('./routes/back/index');
//api
var folioLibrary = require('./api/content/folio');
var blogLibrary = require('./api/content/posts');
var projectLibrary = require('./api/content/project');
var bookmarkLibrary = require('./api/content/bookmarks');
var postLibrary = require('./api/content/posts');
var mailer = require('./api/content/mailer');
// API PATHS
app.use('/api/folio', folioLibrary);
app.use('/api/projects', projectLibrary);
app.use('/api/bookmarks', bookmarkLibrary);
app.use('/api/posts', postLibrary);
app.use('/api/blog', blogLibrary);
// PAGES
app.use('/', front);
app.use('/@/dashboard', back);
//app.use('/mailer', mailer);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render(theme+'/error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render(theme+'/error', {
message: err.message,
error: {}
});
});
module.exports = app;

@ -0,0 +1,101 @@
module.exports = function (sequelize, DataTypes) {
var Bookmark = sequelize.define('Bookmark', {
id: {
type: DataTypes.INTEGER,
unique: true,
allowNull: false,
autoIncrement: true,
primaryKey: true
},
url: {
type: DataTypes.STRING(500),
unique: false,
allowNull: true
},
source: {
type: DataTypes.STRING(500),
allowNull: true
},
title: {
type: DataTypes.STRING(500),
unique: false,
allowNull: true
},
image: {
type: DataTypes.STRING(500),
unique: false,
allowNull: true
},
comments: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
author: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
tags: {
type: DataTypes.ARRAY(DataTypes.TEXT),
unique: false,
allowNull: true
},
listed: {
type: DataTypes.BOOLEAN,
unique: false,
allowNull: true
}
}, {
timestamps: true,
// don't delete database entries but set the newly added attribute deletedAt
// to the current date (when deletion was done). paranoid will only work if
// timestamps are enabled
paranoid: true,
// don't use camelcase for automatically added attributes but underscore style
// so updatedAt will be updated_at
underscored: true,
// disable the modification of table names; By default, sequelize will automatically
// transform all passed model names (first parameter of define) into plural.
// if you don't want that, set the following
freezeTableName: false,
// define the table's name
tableName: 'Bookmarks',
// Enable optimistic locking. When enabled, sequelize will add a version count attriubte
// to the model and throw an OptimisticLockingError error when stale instances are saved.
// Set to true or a string with the attribute name you want to use to enable.
version: true
});
return Bookmark;
};
/**
var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
var Bookmark = new mongoose.Schema({
url: String,
source:String,
title:String,
image: String,
comments:Array,
created: String,
edited: String,
author:Object,
tags:Array,
listed:Boolean
}, {
collection: 'bookmarks'
});
module.exports = mongoose.model('Bookmark', Bookmark);
**/

@ -0,0 +1,94 @@
module.exports = function (sequelize, DataTypes) {
var FolioProject = sequelize.define('FolioProject', {
type: {
type: DataTypes.STRING(500),
unique: false,
allowNull: true
},
description: {
type: DataTypes.STRING(500),
allowNull: true
},
url: {
type: DataTypes.STRING(500),
unique: false,
allowNull: true
},
tools: {
type: DataTypes.STRING(500),
unique: false,
allowNull: true
},
title: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
slug: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
images: {
type: DataTypes.STRING(2000),
unique: false,
allowNull: true
},
sortIndex: {
type: DataTypes.INTEGER,
unique: false,
allowNull: true
}
}, {
timestamps: true,
// don't delete database entries but set the newly added attribute deletedAt
// to the current date (when deletion was done). paranoid will only work if
// timestamps are enabled
paranoid: true,
// don't use camelcase for automatically added attributes but underscore style
// so updatedAt will be updated_at
underscored: true,
// disable the modification of table names; By default, sequelize will automatically
// transform all passed model names (first parameter of define) into plural.
// if you don't want that, set the following
freezeTableName: false,
// define the table's name
tableName: 'Folio',
// Enable optimistic locking. When enabled, sequelize will add a version count attriubte
// to the model and throw an OptimisticLockingError error when stale instances are saved.
// Set to true or a string with the attribute name you want to use to enable.
version: true
});
return FolioProject;
};
/**
var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
var Bookmark = new mongoose.Schema({
url: String,
source:String,
title:String,
image: String,
comments:Array,
created: String,
edited: String,
author:Object,
tags:Array,
listed:Boolean
}, {
collection: 'bookmarks'
});
module.exports = mongoose.model('Bookmark', Bookmark);
**/

@ -0,0 +1,116 @@
module.exports = function (sequelize, DataTypes) {
var Post = sequelize.define('Post', {
uuid: {
type: DataTypes.STRING(50),
unique: true,
allowNull: false
},
title: {
type: DataTypes.STRING(500),
allowNull: true
},
slug: {
type: DataTypes.STRING(500),
unique: false,
allowNull: true
},
tags: {
type: DataTypes.STRING(2000),
unique: false,
allowNull: true
},
entry_html: {
type: DataTypes.TEXT,
unique: false,
allowNull: true
},
entry_plaintext: {
type: DataTypes.TEXT,
unique: false,
allowNull: true
},
feature_image: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
page: {
type: DataTypes.BOOLEAN,
unique: false,
allowNull: true
},
author_id: {
type: DataTypes.INTEGER,
unique: false,
allowNull: true
}
}, {
timestamps: true,
// don't delete database entries but set the newly added attribute deletedAt
// to the current date (when deletion was done). paranoid will only work if
// timestamps are enabled
paranoid: true,
// don't use camelcase for automatically added attributes but underscore style
// so updatedAt will be updated_at
underscored: true,
// disable the modification of table names; By default, sequelize will automatically
// transform all passed model names (first parameter of define) into plural.
// if you don't want that, set the following
freezeTableName: false,
// define the table's name
tableName: 'Posts',
// Enable optimistic locking. When enabled, sequelize will add a version count attriubte
// to the model and throw an OptimisticLockingError error when stale instances are saved.
// Set to true or a string with the attribute name you want to use to enable.
version: true
});
return Post;
};
/**
post: {
"id": "59711abc12d3ab0bd61c3abc",
"uuid": "ec630e45-3342-4d7f-a24c-e448263c975b",
"title": "Welcome to Ghost",
"slug": "welcome-to-ghost",
"mobiledoc": "{\"version\":\"0.3.1\",\"markups\":[],\"atoms\":[],\"cards\":[[\"card-markdown\",{\"cardName\":\"card-markdown\",\"markdown\":\"You're live nice!\"}]],\"sections\":[[10,0]]}",
"html": "<p>You're live! Nice.</p>",
"plaintext": "You're live! Nice.",
"amp": "Not what you think!",
"feature_image": "/content/images/2014/12/my-image.png",
"featured": false,
"page": false,
"status": "published",
"locale": null,
"visibility": "public",
"meta_title": null,
"meta_description": null,
"author_id": "59711abc78f1ab0bd61c3efg",
"created_at": "2014-04-15T12:36:28.353Z",
"created_by": "59711abc78f1ab0bd61c3efg",
"updated_at": "2014-04-15T12:36:28.353Z",
"updated_by": "59711abc78f1ab0bd61c3efg",
"published_at": "2014-04-15T12:36:28.363Z",
"published_by": "59711abc78f1ab0bd61c3efg",
"custom_excerpt": null,
"codeinjection_head": null,
"codeinjection_foot": null,
"og_image": null,
"og_title": null,
"og_description": null,
"twitter_image": null,
"twitter_title": null,
"twitter_description": null
}
**/

@ -0,0 +1,80 @@
module.exports = function (sequelize, DataTypes) {
var User = sequelize.define('User', {
avatar: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
handle: {
type: DataTypes.STRING,
unique: true,
allowNull: true
},
email: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
role: {
type: DataTypes.STRING,
unique: false,
allowNull: true
},
password: {
type: DataTypes.STRING,
unique: true,
allowNull: false
}
}, {
timestamps: true,
// don't delete database entries but set the newly added attribute deletedAt
// to the current date (when deletion was done). paranoid will only work if
// timestamps are enabled
paranoid: true,
// don't use camelcase for automatically added attributes but underscore style
// so updatedAt will be updated_at
underscored: true,
// disable the modification of table names; By default, sequelize will automatically
// transform all passed model names (first parameter of define) into plural.
// if you don't want that, set the following
freezeTableName: false,
// define the table's name
tableName: 'Users',
// Enable optimistic locking. When enabled, sequelize will add a version count attriubte
// to the model and throw an OptimisticLockingError error when stale instances are saved.
// Set to true or a string with the attribute name you want to use to enable.
version: true
});
return User;
};
/**
var User = new mongoose.Schema({
avatar: String,
handle: String,
firstname: String,
lastname: String,
email: String,
password: String,
bio: {
type: String,
default: 'I\'m actually really interesting, but, alas, I am kind of lazy.'
},
role: {
type: String,
default: 'client'
},
created_at: Date,
last_login: Date
}, {
collection: 'users'
});
module.exports = mongoose.model('User', User);
**/

@ -0,0 +1,51 @@
'use strict';
var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var basename = path.basename(__filename);
var env = process.env.NODE_ENV || 'development';
var config = require('../../config.json')[env];
var db = {};
//console.log(config.database);
/**
if (config.use_env_variable) {
var sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
var sequelize = new Sequelize(config.local.database, config.local.user, config.local.password, config.local.options);
}
**/
var sequelize = new Sequelize(config.database, config.user, config.password, config.options);
/**
sequelize.authenticate().then(() => {
console.log("Success!");
}).catch((err) => {
console.log(""+err);
});
**/
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
var model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
//db.Sequelize = Sequelize;
module.exports = db;

@ -0,0 +1,339 @@
var express = require('express');
var router = express.Router();
var Models = require('../../models');
var DateUtils = require('../../utils/DateUtils');
var hljs = require('highlight.js/lib/highlight');
var hljs_md = require('highlight.js/lib/languages/markdown');
hljs.registerLanguage('markdown', hljs_md);
//--------------------------
// Index
//--------------------------
router.get('/', function (req, res) {
var loggedIn = false
if (req.session.user)
loggedIn = true;
Models.Post.findAll({
order: [
['id', 'DESC']
],
limit: 10
}).then(function (posts) {
res.render('dash/index', {
title: 'Dashboard',
user_status: loggedIn,
items: posts
});
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
//next(err);
})
});
//--------------------------
// SETTINGS
//--------------------------
router.get('/settings/', function (req, res) {
if (req.session.user) {
res.render('dash/settings', {
title: 'Dashboard | Settings',
mode: 'admin'
});
} else {
res.redirect('/@/dashboard');
}
});
//--------------------------
// ENTRIES
//--------------------------
router.get('/entries/:page?', function (req, res) {
var pageNum = req.params.page;
if(pageNum == "" || pageNum == null) pageNum = 1;
var offset = ((pageNum*5) -5);
if (req.session.user) {
Models.Post.findAll({
order: [
['id', 'DESC']
]
}).then(function (posts) {
var count = Math.round(posts.length / 6);
//console.log("COUNT: "+count);
var pageItems = [];
var itemLimit = 6;
var rangeStart = (pageNum * itemLimit) - itemLimit;
for (var i = 0; i < itemLimit; i++) {
try {
if (posts[i + rangeStart].id != null) {
pageItems.push(posts[i + rangeStart]);
}
} catch (e) {
//console.log(e)
}
}
res.render('dash/entries-index', {
title: 'Dashbord Entries',
mode: 'admin',
items: pageItems,
page_index: pageNum,
page_count: count
});
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
//next(err);
})
} else {
res.redirect('/@/dashboard');
}
});
//--------------------------
// BLOG POST ADD DISPLAY
//--------------------------
router.get('/entries/add/', function (req, res) {
if (req.session.user) {
res.render('dash/entry-edit', {
title: 'Add Entry',
mode: 'admin',
edit: false
});
} else {
res.redirect('/@/dashboard');
}
});
//--------------------------
// BLOG POST EDIT DISPLAY
//--------------------------
router.get('/entries/edit/:id', function (req, res) {
if (req.session.user) {
Models.Post.findOne({
where: {
slug: req.params.id
}
}).then(entry => {
let featured_img = JSON.parse(entry.feature_image);
let featured = 'null';
if (featured_img.length != 0)
featured = featured_img[0].substr(7, featured_img[0].length);
let pretty = hljs.highlight('markdown', entry.entry_plaintext).value;
let newdate = new Date(entry.created_at);
let formattedDate = newdate.getFullYear()+"-"+newdate.getMonth()+"-"+newdate.getDate();
console.log(DateUtils.getDate('null', 'full'));
res.render('dash/entry-edit', {
title: 'Edit Entry',
mode: 'admin',
post: entry,
date:formattedDate,
colored: pretty,
html: entry.entry_plaintext,
feature: featured,
edit: true
});
}).then(function (value) {
console.log("VALUE: " + value);
}).catch(function (err) {
console.log(err);
})
} else {
res.redirect('/@/dashboard');
}
});
/**
//--------------------------
// MAIN FIPAMO DISPLAY
//--------------------------
router.get('/fipamo/', function (req, res) {
if (req.session.user) {
Models.Bookmark.findAll({
order: [['id', 'DESC']]
}).then(function (saved) {
res.render('admin/admin-fipamo-index', {
title: 'Manage Saved',
mode: 'admin',
saved: saved
});
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
//next(err);
})
} else {
res.redirect('/admin');
}
});
router.get('/fipamo/edit/:id', function (req, res) {
if (req.session.user) {
Models.Bookmark.findOne({
where: {
id: req.params.id
}
}).then(saved => {
res.render('admin/admin-fipamo-edit', {
title: 'FIPAMO | EDIT ' + saved.title,
mode: 'admin',
bookmark: saved,
edit: true
});
}).then(function (value) {
console.log("VALUE: " + value);
}).catch(function (err) {
console.log(err);
})
} else {
res.redirect('/admin');
}
});
//--------------------------
// MAIN FOLIO DISPLAY
//--------------------------
router.get('/folio/', function (req, res) {
if (req.session.user) {
Models.FolioProject.findAll().then(function (projects) {
res.render('folio-hub', {
title: 'manage folio',
mode: 'admin',
projects: projects
});
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
//next(err);
})
} else {
res.redirect('/admin');
}
});
//--------------------------
// PROJECT DISPLAY
//--------------------------
router.get('/folio/:id', function (req, res) {
if (req.session.user) {
console.log(req.params.id)
Models.FolioProject.findOne({
where: {
slug: req.params.id
}
}).then(function (project) {
//var item = project[0]
res.render('folio-project-display', {
title: project.title,
project: project,
edit: true,
mode: 'admin'
});
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
//next(err);
});
} else {
res.redirect('/admin');
}
});
router.get('/folio/task/add', function (req, res) {
if (req.user) {
res.render('folio-project-display', {
title: 'Add New Project',
edit: false,
mode: 'admin'
});
} else {
res.redirect('/admin');
}
});
//--------------------------
// ADMIN PAGE
//--------------------------
router.get('/admin/:include/:id?', function (req, res) {
if (req.user) {
if (req.user.role == 2) {
switch (req.params.include) {
case "edit-project":
FolioProject.findById(req.params.id).exec().then(function (project) {
res.render('includes/folio-project', {
formTitle: "EDIT " + project.title,
project: project,
mode: req.params.include
});
}).catch(function (err) {
//console.log(err)
});
break
case "add-project":
res.render('includes/folio-project', {
formTitle: 'Fo r mle ss ADMIN | Add New Project',
mode: req.params.include
});
break
case "folio-hub":
FolioProject.find().exec().then(function (entries) {
//res.json(entries);
res.render('content/folio-hub', {
title: 'Fo r mle ss ADMIN | Folio Manager',
entries: entries
});
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
next(err);
});
break
}
}
} else {
res.json({
message: 'NOT AUTHORIZED'
});
}
});
router.get('/includes/admin-menu/', function (req, res) {
if (req.user) {
if (req.user == 1) {
res.render('client-panel')
} else {
res.render('includes/admin-menu', {
title: 'Fo r mle ss | Admin',
user_status: "What up, random entity",
name: "What up, " + req.user.firstname
})
}
} else {
res.render('index', {
title: 'Fo r mle ss',
user_status: "What up, random entity"
});
}
});
router.get('/content/admin/', function (req, res) {
if (req.user) {
if (req.user == 1) {
res.render('client-panel')
} else {
res.render('content/admin', {
title: 'Fo r mle ss | Admin'
})
}
} else {
res.render('content/index', {
title: 'Fo r mle ss'
});
}
});
*/
module.exports = router;

@ -0,0 +1,46 @@
var express = require('express');
var router = express.Router();
var Models = require('../../models');
var config = require('../../../config.json');
router.get('/:page_num?', function (req, res) {
var page_num = req.params.page_num;
var pageNum = page_num;
if (page_num == null)
pageNum = 1
Models.Bookmark.findAll({
order: [['id', 'DESC']]
}).then(function (bookmarks) {
//console.log("num: "+pageNum);
//real page count
var count = Math.floor(bookmarks.length / 10);
var pageItems = [];
var itemLimit = 10;
var rangeStart = (pageNum * itemLimit) - itemLimit;
//console.log("RANGE START "+rangeStart);
for (var i = 0; i < itemLimit; i++) {
try {
if (bookmarks[i + rangeStart].id != null) {
//console.log(bookmarks[i+rangeStart]._id )
pageItems.push(bookmarks[i + rangeStart]);
}
} catch (e) {
//console.log(e)
}
}
//console.log("items count: "+pageItems.length)
res.render(config.theme+'/fipamo', {
theme: config.theme,
title: 'The Twelfth House | Fipamo',
page_index: pageNum,
page_count: Math.round(bookmarks.length / 10),
items: pageItems,
mode: 'bookmarks'
});
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
console.log(err);
})
});
router.get('/:id', function (req, res) {});
module.exports = router;

@ -0,0 +1,112 @@
var express = require('express');
var router = express.Router();
var Models = require('../../models');
var bCrypt = require('bcrypt-nodejs');
var config = require('../../../config.json');
module.exports = function (session) {
//--------------------------
// Index
//--------------------------
router.get('/:page?', function (req, res) {
if (req.params.page == null || req.params.page == "") {
Models.FolioProject.findAll({
limit: 5,
order: [
['id', 'DESC']
]
}).then(entries => {
Models.Post.findAll({
limit: 5,
order: [
['id', 'DESC']
]
}).then(posts => {
Models.Bookmark.findAll({
limit: 5,
order: [
['id', 'DESC']
]
}).then(saved => {
res.render(config.theme + '/index', {
theme: config.theme,
title: 'The Twelfth House | Home of creative technologist, beat maker and over-thinker, Ro',
user_status: "What up, random person",
mode: 'index',
folio: entries,
posts: posts,
bookmarks: saved
});
}).catch(err => {
console.log(err);
})
})
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
console.log(err);
})
} else {
switch (req.params.page) {
case "dashboard":
console.log('here')
break;
default:
console.log(req.params.page)
break;
}
}
});
//--------------------------
// Login
//--------------------------
/* Handle Login POST */
router.post('/login', function (req, res, next) {
Models.User.findOne({
where: {
handle: req.body.handle
}
}).then(user => {
if (!isValidPassword(user, req.body.password)) {
console.log('Invalid Password');
//return done(null, false, req.flash('message', 'Invalid Password')); // redirect back to login page
return res.json({
message: 'CHECK YOUR PASSWORD'
});
}
let session = req.session;
session.user = user;
res.redirect('/@/dashboard');
//return done(null, user);
}).catch(err => {
console.log(err);
return res.json({
message: 'NOT FOUND BOSS'
});
})
});
//--------------------------
// Logout
//--------------------------
router.post('/logout', function (req, res, next) {
req.logout();
return res.json({
message: 'LOGGED OUT'
});
});
return router;
}
var isValidPassword = function (user, password) {
return bCrypt.compareSync(password, user.password);
}

@ -0,0 +1,68 @@
var express = require('express');
var router = express.Router();
var Models = require('../../models');
var config = require('../../../config.json');
router.get('/', function(req, res) {
res.redirect('/blog/page/1');
});
router.get('/page/:page_num?', function (req, res) {
var page_num = req.params.page_num;
var pageNum = page_num;
if (page_num == null)
pageNum = 1
Models.Post.findAll({
order: [['id', 'DESC']]
}).then(function (post) {
//console.log("num: "+pageNum);
//real page count
var count = Math.floor(post.length / 6);
var pageItems = [];
var itemLimit = 6;
var rangeStart = (pageNum * itemLimit) - itemLimit;
//console.log("RANGE START "+rangeStart);
for (var i = 0; i < itemLimit; i++) {
try {
if (post[i + rangeStart].id != null) {
pageItems.push(post[i + rangeStart]);
}
} catch (e) {
//console.log(e)
}
}
//console.log("items count: "+pageItems.length)
res.render(config.theme+'/blog', {
theme: config.theme,
title: 'The Twelfth House | Thoughts and Such',
page_index: pageNum,
page_count: Math.round(post.length / 6),
items: pageItems,
mode: 'blog'
});
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
console.log(err);
})
});
router.get('/:id', function(req, res) {
Models.Post.findOne({where:{slug: req.params.id}}).then((post) => {
console.log(post.feature_image)
res.render(config.theme+'/blog-post', {
theme: config.theme,
title: post.title,
entry: post.entry_html,
feature_image: JSON.parse(post.feature_image),
mode:'blog'
});
}).catch((err) => {
console.log(err);
});
});
module.exports = router;

@ -0,0 +1,37 @@
var express = require('express');
var router = express.Router();
var Models = require('../../models');
var config = require('../../../config.json');
router.get('/', function(req, res) {
Models.FolioProject.findAll({order:[['sortIndex', 'DESC']]}).then(projects=> {
res.render(config.theme+'/work', {
theme: config.theme,
title: 'The Twelfth House | Creative Works and Projects',
projects: projects,
mode: 'projects'
});
}).then(function(value) {
//console.log(value);
}).catch(function(err) {
//next(err);
})
});
router.get('/:id', function(req, res) {
Models.FolioProject.findOne({where:{slug: req.params.id}}).then((project) => {
res.render(config.theme+'/work-project', {
title: project.title,
type: project.type,
desc: project.description,
images: JSON.parse(project.images),
mode:'folio',
url:project.url
});
}).catch((err) => {
console.log(err);
});
});
module.exports = router;

@ -0,0 +1,95 @@
module.exports = {
decodeHTML: function(string, quote_style) {
var optTemp = 0,
i = 0,
noquotes = false;
if (typeof quote_style === 'undefined') {
quote_style = 2;
}
string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
var OPTS = {
'ENT_NOQUOTES': 0,
'ENT_HTML_QUOTE_SINGLE': 1,
'ENT_HTML_QUOTE_DOUBLE': 2,
'ENT_COMPAT': 2,
'ENT_QUOTES': 3,
'ENT_IGNORE': 4
};
if (quote_style === 0) {
noquotes = true;
}
if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
quote_style = [].concat(quote_style);
for (i = 0; i < quote_style.length; i++) {
// Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
if (OPTS[quote_style[i]] === 0) {
noquotes = true;
} else if (OPTS[quote_style[i]]) {
optTemp = optTemp | OPTS[quote_style[i]];
}
}
quote_style = optTemp;
}
if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
// string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
}
if (!noquotes) {
string = string.replace(/&quot;/g, '"');
}
// Put this in last place to avoid escape being double-decoded
string = string.replace(/&amp;/g, '&');
return string;
},
cleanString: function(str) {
return (str + '').replace(/\\(.?)/g, function(s, n1) {
switch (n1) {
case '\\':
return '\\';
case '0':
return '\u0000';
case '':
return '';
default:
return n1;
}
});
},
cleanString: function(string) {
var clean = string.replace(/(^\-+|[^a-zA-Z0-9\/_| -]+|\-+$)/g, '').toLowerCase().replace(/[\/_| -]+/g, '-');
return clean;
},
getDate: function(type, rawdate) {
var day = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCDate()) : String(new Date().getUTCDate()));
var month = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCMonth()+1) : String(new Date().getUTCMonth()+1));
var year = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCFullYear()) : String(new Date().getUTCFullYear()));
var hour = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCHours()) : String(new Date().getUTCHours()));
var minute = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCMinutes()) : String(new Date().getUTCMinutes()));
var seconds = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCSeconds()) : String(new Date().getUTCSeconds()));
var millisecond = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCMilliseconds()) : String(new Date().getUTCMilliseconds()));
if (day.length == 1)
day = String("0" + day);
if (month.length == 1)
month = String("0" + month);
switch (type) {
case "day":
return day;
break;
case "month":
return month;
break;
case "year":
return year;
break;
case "stamp":
return String(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + seconds+"."+millisecond);
break
default:
return String(year + "-" + month + "-" + day + " : " + hour + "-" + minute + "-" + seconds);
break;
}
}
};

@ -0,0 +1,112 @@
var roles = {
hnic: {
"client_admin": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"client_user": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"client_project": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"folio_project": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"bookmark": {
"create": true,
"read": true,
"update": true,
"delete": true
}
},
client: {
"client_admin": {
"create": false,
"read": true,
"update": false,
"delete": false
},
"client_user": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"client_project": {
"create": true,
"read": true,
"update": true,
"delete": false
},
"folio_project": {
"create": false,
"read": false,
"update": false,
"delete": false
}
},
user: {
"client_admin": {
"create": false,
"read": false,
"update": false,
"delete": false
},
"client_user": {
"create": false,
"read": true,
"update": false,
"delete": false
},
"client_project": {
"create": false,
"read": true,
"update": true,
"delete": false
},
"folio_project": {
"create": false,
"read": false,
"update": false,
"delete": false
},
"bookmark": {
"create": true,
"read": true,
"update": true,
"delete": true
}
}
};
module.exports = {
TASK_CREATE: 'create',
TASK_UPDATE: 'update',
TASK_READ: 'read',
TASK_DELETE: 'delete',
OBJECT_CLIENT_ADMIN: 'client_admin',
OBJECT_CLIENT_USER: 'client_user',
OBJECT_PROJECT_CLIENT: 'client_project',
OBJECT_PROJECT_FOLIO: 'folio_project',
OBJECT_BOOKMARK: 'bookmark',
check: function(role, object, task) {
for (var i = 0; i < object.length; i++) {
if(!roles[role][object[i]][task])
return false
}
return true;
},
hey: function() {}
};

@ -0,0 +1,104 @@
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('./brain/app');
var debug = require('debug')('thetwelfthhouse:server');
var http = require('http');
var models = require('./brain/models');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '2700');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
models.sequelize.sync().then(function() {
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, function() {
debug('Express server listening on port ' + server.address().port);
});
server.on('error', onError);
server.on('listening', onListening);
});
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string' ?
'Pipe ' + port :
'Port ' + port
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string' ?
'pipe ' + addr :
'port ' + addr.port;
debug('Listening on ' + bind);
}

@ -0,0 +1,63 @@
{
"name": "the-twelfth-house",
"version": "3.0.0",
"private": true,
"description": "The personal site of Roland X. Pulliam",
"repository": "https://code.playvicio.us/Are0h/thetwelfthhouse",
"theme": "default",
"scripts": {
"start": "forever start init.js",
"stop": "forever stop init.js",
"dev": "nodemon init.js",
"watch-front-scripts": "parcel watch themes/$npm_package_theme/src/com/Start.jsx --out-dir themes/$npm_package_theme/assets/js --out-file start.min.js --public-url /$npm_package_theme/assets/js",
"watch-front-styles": "stylus -w -m -o themes/$npm_package_theme/assets/css themes/$npm_package_theme/src/styles/base.styl",
"build-front-kit": "uglifyjs node_modules/scramble-text/dist/ScrambleText.min.js node_modules/animejs/anime.min.js node_modules/reframe.js/dist/reframe.min.js -c -o themes/$npm_package_theme/assets/js/toolkit.min.js",
"watch-back-scripts": "parcel watch themes/dash/src/com/Start.jsx --out-dir themes/dash/assets/js --out-file dash.min.js --public-url /dash/assets/js",