Permalink
Browse files

Initial Commit

Time spent writing code
Held on to this for a while
I should release this now
  • Loading branch information...
antijingoist committed Jan 24, 2016
0 parents commit 0376b63c44cdec00a98faa1ca74b973feec3721a
Showing 401 changed files with 35,440 additions and 0 deletions.
@@ -0,0 +1,16 @@
## Sample Blog Post

This is just a sample. You can play around with your own text right here.

Markdown
-------------

...is really just ordinary text, *plain and simple*. How is it good for you?

- You just **type naturally**, and the result looks good.
- You **don't have to worry** about clicking formatting buttons.
- Or fiddling with indentation. (Two spaces is all you need.)

To see what else you can do with Markdown (including **tables**, **images**, **numbered lists**, and more) take a look at the [Cheatsheet][1]. And then try it out by typing in this box!

[1]: https://github.com/adam-p/markdown-here/wiki/Markdown-Here-Cheatsheet
@@ -0,0 +1,7 @@
404
---
Custom 404 page, defined in

./content/errors/404.md

You can modify this as you wish, using MarkDown.
@@ -0,0 +1,3 @@
No blog posts created yet.
---
Create blog posts by adding markdown files to your blog directory, under content. Name your files YYYYMMDDHHMM.md, or YYYYMMDDHHMM-Title_With_Underscore_Spaces.md.
@@ -0,0 +1,4 @@
Welcome
Themes & Plugins
Functions
Download
@@ -0,0 +1,46 @@
## Functions

These functions can be used both in themes and plugins.

**sculpt_system(_system property_)**
: Prints out a Sculpt system property. Valid Property options are: `path, content_path, default_look, default_error_path, themes_path, pages_path, error_path, plugin_path`

**site_title()**
: Prints out the website title.

**site_url()**
: Prints out the website url.

**site_tagline()**
: Prints out the site tagline, if one is set.

**sculpt_page_url(_page name_)**
: Get the URL for the provided page name. This takes into account URL rewriting, and will use the pages registered address if the page is registered.

**page_title()**
: Prints out the page name.

**theme_location()**
: Prints out the location of the current theme.

**page_is_registered(_page name_)**
: Returns `true` if a page is registered. Allows you to check if a page is registered before referencing it.

**register_page(_page name_, _page location_)**
: Register a special page. This lets you redirect a page name to any location you specify. This can be used when you want your navigation, or the address in the address bar to say one thing, but use something else. For example, having 'Welcome' in your nav bar send you your home page. These pages can be referenced directly in a plugin or theme using the function `sculpt_special_link();`

**is_text_engine_registered(_engine name_)**
: Returns `true` if a text engine is registered. Allows you to check if a text engine is registered before referencing it.

**register_text_engine(_text engine name_, _text engine location_)**
: Registers a PHP file as a text engine. This allows you to define a page to be rendered as you choose, without the involvement of the default framework.

**show_error(_error name/number_)**
: Displays an error with _error name/number_. If there is a custom error for the error number in the errors folder, that error content will be displayed.

**cache_data(_data_, Optional: _key_)**
: Caches the data in the variable you provide. Key is optional. If no key is provided, it returns a unique identifier as the key that you can store and reference again when needed.

**cache_retrieve(_key_)**
: Returns the data stored with the provided key if it exists. If the data does not exist, it will return NULL.

@@ -0,0 +1,75 @@
## Sculpt CMS

Sculpt CMS is a flat-file CMS designed for straight-forward usage. There is no special markup, and no extra steps. Simply drop your markdown files into the `content/pages` directory to begin. The page title is the file title.

Sculpt is compatible with Markdown Extra, and uses PHPFastCache, Parsedown, and ParsedownExtra.

### Settings
The Sculpt settings are kept in `system/settings.php`. There are a few options available:

#### Site settings
$website_name
: Your Website's name

$website_tagline
: A tagline for your website. This will show in themes that make use of one.

$website_url
: The home URL of your website.

$website_theme
: The name of the theme you want to use. Themes must be in your `extras/themes` directory. For example:
```
$website_theme = "gwsk";
```

$email_address
: If your theme makes use of this, your email address.

$enable_html_support
: when set to true, will allow you to use both HTML and MD files for your site.


#### Cache Settings:
$clear_all_caches
: Set to `true`, and refresh your site to clear all caches. Set to `false` to rebuild the cache.

$cache_time_days
: Time, in days, to keep the cache.

### Plugins
Sculpt is very bare bones. Even the navigation is an optional plugin. You can enable plugins in the `extras/plugins/enabled.php` file. To enable the navigation plugin, for example, add the following line:

enable_plugin("navigation_bar");

### Blog Plugin
Every CMS needs a blog. To use the blog plugin with Sculpt, add the following line to the `extras/plugins/enabled.php` file:

enable_plugin("blog");

Blog pulls it's content from the `content/blog` directory. Files must be Markdown files. The Title of the Blog post is the first line of the Markdown file. The content is the rest. The files are named with the intended timestamp of publication, in the below format:

YYYYMMDDHHMM.md
[4 digit year][two digit month][two digit day][2 digit hours (24 hour time)][2 digit minutes].md

Blog will show your most recent post on the front page with a few recent titles, and a link to Archives. The archives are automatically generated and cached, using your settings.

Blog settings are kept in `extras/plugins/blog/blog_settings.php`. The supported settings are:

$blog_page_title
:

$blog_directory
: Set to the directory you keep your blog files in. Recommended that you do not change this. Default value is:
```
$blog_directory = sculpt_system("content_path") . 'blog';
```

$show_dates
:

$date_format
: Sets the date format for your blog posts. Default value is:
```
'l jS \of F Y h:i:s A'
```
@@ -0,0 +1,27 @@
Themes & Plugins
---
### Themes
Sculpt comes with a Google Web Starter Kit theme, and has a built in, basic theme that it falls back to if there is a significant issue with the theme you intend on using (for instance: theme does not exist).

Themes are installed into the `extras/themes` folder. The theme folder name should be the theme name. You can enable your theme by changing the `$website_theme` variable in the `system/settings.php` file.

Themes require an index.php that contains a `page_text($current_page);`. This is where the rendered Markdown text for each page will be placed. You will generally not need additional php files. You can also use additional functions where needed [(see Functions)](index.php?p=functions).

### Plugins
There are 3 plugins that come with Sculpt: blog, navigation_bar and rand_image.

Random Image (rand_image) is a sample plugin that makes a new function available to the user: `rand_image();`. This function simply checks a folder for files (it assumes all the files are images), and inserts an image tag for a random image from the folder. Source code is below:

```
function rand_image() {
$directory = sculpt_system("content_path") . '/images/rotating/';
if (file_exists($directory)){
$image_list = array_diff(scandir($directory), array('..', '.'));
// find out if count includes empty items
if (count($image_list) > 2) {
$selected_picture = rand(2, count($image_list) - 1);
echo '<img src="' . $directory . $image_list[$selected_picture] . '" />';
}
}
}
```
@@ -0,0 +1,137 @@
<?
// Markdown blogging engine, as a plugin.
include_once("blog/blog_settings.php");
// How about instead of a special page, check current page in pagetext to see if it's registered. then get pagetext processes the page different.
register_page($blog_page_title, 'index.php?p=Blog');
register_text_engine($blog_page_title, "blog/blog_start.php");
function blog_front_page() {
global $blog_directory;
if (file_exists($blog_directory)){
$article_list = array_diff(scandir($blog_directory, 1), array('..', '.'));
if(count($article_list) > 2){
foreach ($article_list as $key=>$article) {
$file_part = pathinfo($article);
if ($file_part['extension'] === 'md' || $file_part['extension'] === 'html') {
$article_date = $file_part['filename'];
if($key === 0) {
echo '<div class=first_post>';
echo '<h2 class="blog_title"><a href=index.php?p=Blog&bp=' . $article_date . '>' . blog_get_title($article_date) . '</a></h2>';
blog_post($article_date, true);
echo '</div>';
} elseif ($key > 4) {
break;
} else {
echo '<h3 class="blog_title"><a href=index.php?p=Blog&bp=' . $article_date . '>' . blog_get_title($article_date) . '</a></h3>';
}
}
}
echo '<p><a href="index.php?p=Blog&bp=archive">View Archives</a></p>';
} else {
show_error("blog_no_posts");
}
} else {
show_error(404);
}
}
function blog_post($post, $is_front = false) {
global $blog_directory;
global $date_format;
$blog_post_file = $blog_directory . '/' . $post . ".md";
if (file_exists($blog_post_file)){
echo '<div class=blog_text>';
if (!($is_front)) {
echo '<p class="blog_timestamp">' . date($date_format, strtotime($post)) . '</p>';
sculpt_parse_markdown_file($blog_post_file, false);
} else {
sculpt_parse_markdown_file($blog_post_file, true);
}
echo '</div>';
}
else {
echo $blog_directory;
show_error(404);
}
}
function blog_archive($year, $month) {
global $blog_directory;
global $date_format;
$page_data = cache_retrieve("blog_archives_" . $year . $month);
if ($page_data == NULL) {
$page_data = $page_data . '<h2>Archives For ' . date('F', mktime(0, 0, 0, $month, 10)) . ', ' . $year . '</h2>';
$page_data = $page_data . '<p><a href="index.php?p=Blog&bp=archive">Back to Archive</a></p>';
if (file_exists($blog_directory)){
$article_list = glob($blog_directory . '/' . $year . $month . "*.md");
foreach ($article_list as $key=>$article) {
$file_part = pathinfo($article);
if ($file_part['extension'] === 'md' || $file_part['extension'] === 'html') {
$article_date = $file_part['filename'];
$page_data = $page_data . '<h3 class="blog_title"><a href=index.php?p=Blog&bp=' . $article_date . '>' . blog_get_title($article_date) . '</a></h3>';
$page_data = $page_data . '<span class="blog_post_date">' . date($date_format, strtotime($article_date)) . '</span>';
}
}
echo $page_data;
cache_data($page_data, "blog_archives_" . $year . $month);
} else {
show_error(404);
}
} else {
echo $page_data;
}
}
function blog_archives_list() {
global $blog_directory;
global $date_format;
$yearmo = "";
$prev_year = "";
if (file_exists($blog_directory)){
$page_data = cache_retrieve("blog_archives");
if($page_data == NULL) {
$article_list = glob($blog_directory . '/*.md');
foreach ($article_list as $key=>$article) {
$file_part = pathinfo($article);
$year = substr($file_part['filename'], 0, 4);
if (!($year === $prev_year)){
$page_data = $page_data . '<h2>' . $year . '</h2>';
$prev_year = $year;
}
$month = substr($file_part['filename'], 4, 2);
if (!($year . $month === $yearmo)) {
$page_data = $page_data . '<h3><a href=index.php?p=Blog&bp=archive&ayr=' . $year . '&amo=' . $month . '>';
$page_data = $page_data . date('F', mktime(0, 0, 0, $month, 10));
$page_data = $page_data . '</a></h3>';
$yearmo = $year . $month;
}
}
echo $page_data;
cache_data($page_data, "blog_archives");
} else {
echo $page_data;
}
} else {
show_error(404);
}
}
function blog_get_title($post) {
global $blog_directory;
$blog_post_file = fopen($blog_directory . '/' . $post . ".md", 'r');
$title = fgets($blog_post_file);
$title = ltrim($title, '## ');
fclose($blog_post_file);
return $title;
}
?>
@@ -0,0 +1,7 @@
<?
$blog_page_title = "Blog";
$blog_directory = sculpt_system("content_path") . 'blog';
$show_dates = true;
$date_format = 'l jS \of F Y h:i:s A';
?>
@@ -0,0 +1,31 @@
<?
$blog_page = _INPUT("bp", "front");
$blog_list_offset = _INPUT("o", 0);
/*
if($blog_page === "front") {
blog_front_page();
} else {
blog_post($blog_page);
}
*/
switch($blog_page) {
case "front":
blog_front_page();
break;
case "archive":
$archive_year = _INPUT("ayr", "");
$archive_month = _INPUT("amo", "");
if ($archive_month === "" || $archive_year === "") {
blog_archives_list(); //switch to archive front
} else {
blog_archive($archive_year, $archive_month);
}
break;
default:
blog_post($blog_page);
break;
}
?>
@@ -0,0 +1,8 @@
<?php
// Add plugins to the plugin folder. They should be at least just the plugin_name.php in the root of plugins, (and if you need additional files, in a subdirectory named accordingly).
// Add plugins using enable_plugin("pluginName"); do not include the extension.
enable_plugin("navigation_bar");
enable_plugin("blog");
enable_plugin("sculpt_site_special");
?>
No changes.
Oops, something went wrong.

0 comments on commit 0376b63

Please sign in to comment.