Skip to content
Permalink
Browse files

Logic changes, comments, etc.

  • Loading branch information...
Jon Belelieu Jon Belelieu
Jon Belelieu authored and Jon Belelieu committed Jul 5, 2015
1 parent e9d8e4b commit 19d2c241e9495363ab6c1f3f5865a8894c22096c
@@ -1,7 +1,7 @@
<?php namespace App;
/**
* This is the primary "Controller" for the application.
* Primary "Controller" for the application.
*
* @author jbelelieu
* @date 6/28/15
@@ -88,19 +88,29 @@ public function getOutput()
* Set the page we are requesting.
*
* @param string $page
*
* @return $this
*/
public function setPage($page)
{
$this->page = htmlentities($page);
return $this;
}
/**
* Set the category of the requested page.
*
* @param string $category
*
* @return $this
*/
public function setCategory($category)
{
$this->category = htmlentities($category);
return $this;
}
@@ -128,6 +138,8 @@ protected function determineLanguage()
*/
protected function setLanguage($lang = '')
{
$lang = substr($lang, 0, 2);
$find = dirname(dirname(__FILE__)) . '/wiki/' . filter_var($lang, FILTER_SANITIZE_STRING);
if (file_exists($find)) $_SESSION['bd_language'] = $lang;
@@ -169,6 +181,9 @@ private function getDefaultChanges()
'wiki_theme' => BD_THEME,
'wiki_base_url' => $base,
'branding_color' => BD_BRANDING_COLOR,
'page' => $this->page,
'category' => $this->category,
'currentLanguage' => \App\getLanguage(),
'languages' => $this->buildLanguages(),
'query' => '',
'navigation' => $this->structure->getHtml(),
@@ -181,23 +196,13 @@ private function getDefaultChanges()
*/
private function buildLanguages()
{
$languages = '';
$languages = array();
$scan = dirname(dirname(__FILE__)) . '/wiki';
$scan_mirror = dirname(dirname(__FILE__)) . '/app/views/' . BD_THEME;
foreach (scandir($scan) as $item) {
if (is_dir($scan . '/' . $item) && $item != '.' && $item != '..') {
// The directory must exist in the theme as well.
if (! file_exists($scan_mirror . '/' . $item)) continue;
$languages .= '<span class="flag">';
$languages .= '<a href="' . \App\getBaseUrl() . '/index.php?c=' . $this->category . '&p=' . $this->page . '&lang=' . $item . '">';
$languages .= '<img src="' . \App\getBaseUrl() . '/app/views/' . BD_THEME . '/assets/img/' . $item . '.png" border="0" />';
$languages .= '</a>';
$languages .= '</span>';
if (is_dir($scan . '/' . $item) && strlen($item) == 2 && $item != '.' && $item != '..') {
$languages[] = $item;
}
}
@@ -76,26 +76,18 @@ public function build()
$temp = array();
$up = 0;
foreach ($pieces as $item) {
if (empty($item)) continue;
$up++;
$temp[] = $item;
// $finalItem = '';
// if ($up == sizeof($pieces)) $finalItem .= '<a href="' . BD_BASE_URL . '?c=' . $this->category . '&p=' . $this->page . '">';
$checkForName = ltrim(implode('/', $temp), '/');
// $finalItem .= \App\findName($checkForName);
// if ($up == sizeof($pieces)) $finalItem .= '</a>';
$format[] = \App\findName($checkForName);
}
$ret = '<a href="' . \App\getBaseUrl() . '">' . BD_NAME . '</a>';
// Homepage
if (sizeof($format) == 1) {
return $ret . $this->separator . $format['0'];
} else {
@@ -3,10 +3,14 @@
use \Michelf\MarkdownExtra as Markdown;
/**
* This class is used to take raw markdown files and prepare them for public consumption.
* This class is used to take raw pages (markdown files) and prepare them for public consumption.
*
* @author j-belelieu
* @date 7/3/15
* @author jbelelieu
* @date 7/3/15
* @package Banana Dance Lite
* @link http://www.bananadance.org/
* @license GPL-3.0
* @link http://www.opensource.org/licenses/gpl-3.0.html
*/
class ParsePage {
@@ -15,7 +19,7 @@ class ParsePage {
/**
* @var string
*/
private $internalHeadings = '';
private $internalHeadings = array();
/**
* @var string
@@ -56,6 +60,8 @@ public function getContent()
/**
* Get the internal links for a page in the form of a formatted <ul>.
*
* @return string
*/
public function getHeadings()
@@ -88,67 +94,87 @@ public function process()
{
$this->content = $this->markdown->transform($this->rawData);
$this->parseInnerHeadings();
$this->standardReplacements();
$this->content = $this->parseInnerHeadings();
return $this;
}
/**
* Custom replacements available on all pages. Establish standard
* replacements within the "config/custom_replacements.php" file.
*
* @return bool
*/
private function standardReplacements()
{
$replacements = include dirname(dirname(__FILE__)) . '/wiki/config/custom_replacements.php';
$lang = \App\getLanguage();
$useArray = $replacements[$lang];
// If the user requested a language other than english but there
// are no entries for that language, try to default to english.
if (empty($useArray) && $lang != BD_DEFAULT_LANGUAGE) {
if (empty($replacements[BD_DEFAULT_LANGUAGE])) return false;
$useArray = $replacements[BD_DEFAULT_LANGUAGE];
}
$keys = array_keys($useArray);
$values = array_values($useArray);
$this->content = str_replace($keys, $values, $this->content);
return true;
}
/**
* Builds a list of page headings for easy access and internal linking.
*
* @return string Final page with added <a name> tags.
*/
private function parseInnerHeadings()
{
$this->internalHeadings = '<ul id="innerHeadings">';
$found = false;
$exp = explode("\n", $this->content);
$newContent = '';
foreach ($exp as $line) {
$check = substr(trim($line), 0, 4);
if ($check == '<h1>' || $check == '<h2>' || $check == '<h3>' || $check == '<h4>') {
switch ($check) {
case '<h1>':
$class = 'h1';
break;
case '<h2>':
$class = 'h2';
break;
$class = 'h2'; break;
case '<h3>':
$class = 'h3';
break;
$class = 'h3'; break;
case '<h4>':
$class = 'h4';
break;
$class = 'h4'; break;
default:
$class = 'h1';
}
$found = true;
$aName = str_replace(' ', '_', strtolower(preg_replace("/[^A-Za-z0-9 ]/", '', strip_tags($line))));
$this->internalHeadings .= '<li class="' . $class . '"><a href="#' . $aName . '">' . trim(substr($line, 4)) . '</a></li>';
$this->internalHeadings[$aName] = array(
'class' => $class,
'name' => trim(substr($line, 4)),
);
// Add the anchor to the page's content.
$newContent .= '<a class="anchor" name="' . $aName . '"></a>' . "\n" . $line . "\n";
}
else {
$newContent .= $line . "\n";
}
}
$this->internalHeadings .= '</ul>';
if (! $found) $this->internalHeadings = '';
return $newContent;
}
@@ -34,7 +34,7 @@ class Search {
*/
public function __construct()
{
$this->setSearchDir();
$this->searchDir = dirname(dirname(__FILE__)) . '/wiki/' . \App\getLanguage();
}
@@ -47,9 +47,9 @@ public function __construct()
*/
public function setSearchDir($dir = '')
{
$this->searchDir = dirname(dirname(__FILE__)) . '/wiki/' . \App\getLanguage();
$check = $this->searchDir . '/' . trim($dir, '/');
if (! empty($dir)) $this->searchDir .= '/' . trim($dir, '/');
if (file_exists($check)) $this->searchDir = $check;
return $this;
}
@@ -105,6 +105,7 @@ public function run($inputDir = '')
$contents = file_get_contents($file);
// This is so ugly it hurts. One day I will fix this nonsense.
if (stripos($contents, $this->query) !== false) {
$find = preg_match('/' . $pattern . $this->query . $pattern . '/i', $contents, $m);
if ($find) {
@@ -39,7 +39,7 @@ public function __construct($page, $category = '')
$wikiDir = dirname(dirname(__FILE__)) . '/wiki/' . \App\getLanguage();
$this->orderMap = include dirname(dirname(__FILE__)) . '/app/config/structure_order.php';
$this->orderMap = include dirname(dirname(__FILE__)) . '/wiki/config/structure_order.php';
$this->nav = $this->build($wikiDir);
}
@@ -79,10 +79,8 @@ private function build($dir)
$contents = array();
foreach (scandir($dir) as $node) {
if (substr($node, 0, 1) == '.') continue;
$name = $this->cleanName($node);
$path = $dir . DIRECTORY_SEPARATOR . $node;
$componentArray = $this->buildLinkComponents($path);
@@ -92,7 +90,6 @@ private function build($dir)
} else {
$contents[$node] = \App\buildLink($componentArray, $node);
}
}
$contents = $this->sortArray($contents);
@@ -159,13 +156,20 @@ private function sortArray(array $array)
$ordered = array();
foreach($this->orderMap as $key) {
if (array_key_exists($key, $array)) {
$ordered[$key] = $array[$key];
unset($array[$key]);
$exp = explode('/', $key);
$page = array_pop($exp);
$categories = implode('/', $exp);
$find = '?c=' . $categories . '&p=' . $page;
if ($myKey = array_search($find, $array)) {
$ordered[$key] = $array[$myKey];
unset($array[$myKey]);
}
}
return $ordered + $array;
return array_merge($ordered, $array);
}
Oops, something went wrong.

0 comments on commit 19d2c24

Please sign in to comment.
You can’t perform that action at this time.