Skip to content
Permalink
Browse files Browse the repository at this point in the history
adding bbcode , new html editor, change guestbook view
  • Loading branch information
kinimodmeyer committed Feb 18, 2014
1 parent afaca48 commit 381e15f
Show file tree
Hide file tree
Showing 207 changed files with 8,095 additions and 66 deletions.
2 changes: 1 addition & 1 deletion application/layouts/2columns/index.php
Expand Up @@ -36,6 +36,6 @@
</div>
<div class="container credit">
<p class="muted credit">© Ilch CMS | <?php echo '<a href="'.$this->getUrl(array('module' => 'admin', 'controller' => 'admin', 'action' => 'index')).'">Administrator</a>'; ?></p>
</div>
</div>
</body>
</html>
25 changes: 25 additions & 0 deletions application/libraries/Ilch/Design/Base.php
Expand Up @@ -208,6 +208,31 @@ public function escape($string)
return htmlspecialchars($string, ENT_QUOTES);
}

/**
* Gets html from bbcode.
*
* @param string $bbcode
* @return string
*/
public function getHtmlFromBBCode($bbcode)
{
require_once APPLICATION_PATH.'/libraries/jbbcode/Parser.php';

$parser = new \JBBCode\Parser();
$parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet());

$builder = new \JBBCode\CodeDefinitionBuilder('quote', '<div class="quote">{param}</div>');
$parser->addCodeDefinition($builder->build());

$builder = new \JBBCode\CodeDefinitionBuilder('code', '<pre class="code">{param}</pre>');
$builder->setParseContent(false);
$parser->addCodeDefinition($builder->build());

$parser->parse($bbcode);

return $parser->getAsHTML();
}

/**
* Creates a full url for the given parts.
*
Expand Down
11 changes: 6 additions & 5 deletions application/libraries/Ilch/Layout/Frontend.php
Expand Up @@ -78,10 +78,11 @@ public function getHeader()
<link href="'.$this->getStaticUrl('css/global.css').'" rel="stylesheet">
<link href="'.$this->getStaticUrl('css/ui-lightness/jquery-ui.css').'" rel="stylesheet">
<link href="'.$this->getStaticUrl('../application/modules/user/static/css/user.css').'" rel="stylesheet">
<script src="'.$this->getStaticUrl('js/jquery.js').'"></script>
<script src="'.$this->getStaticUrl('js/bootstrap.js').'"></script>
<script src="'.$this->getStaticUrl('js/jquery-ui.js').'"></script>';
<script type="text/javascript" src="'.$this->getStaticUrl('js/jquery.js').'"></script>
<script type="text/javascript" src="'.$this->getStaticUrl('js/bootstrap.js').'"></script>
<script type="text/javascript" src="'.$this->getStaticUrl('js/jquery-ui.js').'"></script>
<script type="text/javascript" src="'.$this->getStaticUrl('js/ckeditor/ckeditor.js').'"></script>
<script type="text/javascript" src="'.$this->getStaticUrl('js/ilch.js').'"></script>';
return $html;
}
}

}
Binary file added application/libraries/jbbcode/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions application/libraries/jbbcode/.gitignore
@@ -0,0 +1,2 @@
composer.lock
vendor
310 changes: 310 additions & 0 deletions application/libraries/jbbcode/CodeDefinition.php
@@ -0,0 +1,310 @@
<?php

namespace JBBCode;

/**
* This class represents a BBCode Definition. You may construct instances of this class directly,
* usually through the CodeDefinitionBuilder class, to create text replacement bbcodes, or you
* may subclass it to create more complex bbcode definitions.
*
* @author jbowens
*/
class CodeDefinition
{
/* NOTE: THIS PROPERTY SHOULD ALWAYS BE LOWERCASE; USE setTagName() TO ENSURE THIS */
protected $tagName;

/* Whether or not this CodeDefinition uses an option parameter. */
protected $useOption;

/* The replacement text to be used for simple CodeDefinitions */
protected $replacementText;

/* Whether or not to parse elements of this definition's contents */
protected $parseContent;

/* How many of this element type may be nested within each other */
protected $nestLimit;

/* How many of this element type have been seen */
protected $elCounter;

/* The input validator to run options through */
protected $optionValidator;

/* The input validator to run the body ({param}) through */
protected $bodyValidator;

/**
* Constructs a new CodeDefinition.
*/
public static function construct($tagName, $replacementText, $useOption = false,
$parseContent = true, $nestLimit = -1, $optionValidator = null,
$bodyValidator = null)
{
$def = new CodeDefinition();
$def->elCounter = 0;
$def->setTagName($tagName);
$def->setReplacementText($replacementText);
$def->useOption = $useOption;
$def->parseContent = $parseContent;
$def->nestLimit = $nestLimit;
$def->optionValidator = $optionValidator;
$def->bodyValidator = $bodyValidator;
return $def;
}

/**
* Constructs a new CodeDefinition.
*
* This constructor is deprecated. You should use the static construct() method or the
* CodeDefinitionBuilder class to construct a new CodeDefiniton.
*
* @deprecated
*/
public function __construct()
{
/* WARNING: This function is deprecated and will be made protected in a future
* version of jBBCode. */
$this->parseContent = true;
$this->useOption = false;
$this->nestLimit = -1;
$this->elCounter = 0;
$this->optionValidator = null;
$this->bodyValidator = null;
}

/**
* Determines if the arguments to the given element are valid based on
* any validators attached to this CodeDefinition.
*
* @param $el the ElementNode to validate
* @return true if the ElementNode's {option} and {param} are OK, false if they're not
*/
public function hasValidInputs(ElementNode $el)
{
if ($this->usesOption() && $this->optionValidator &&
!$this->optionValidator->validate($el->getAttribute())) {
/* The option argument to $el does not pass the option validator. */
return false;
}

if (!$this->parseContent() && $this->bodyValidator) {
/* We only evaluate the content if we're not parsing the content. */
$content = "";
foreach ($el->getChildren() as $child) {
$content .= $child->getAsBBCode();
}
if (!$this->bodyValidator->validate($content)) {
/* The content of the element is not valid. */
return false;
}
}

return true;
}

/**
* Accepts an ElementNode that is defined by this CodeDefinition and returns the HTML
* markup of the element. This is a commonly overridden class for custom CodeDefinitions
* so that the content can be directly manipulated.
*
* @param $el the element to return an html representation of
*
* @return the parsed html of this element (INCLUDING ITS CHILDREN)
*/
public function asHtml(ElementNode $el)
{
if (!$this->hasValidInputs($el)) {
return $el->getAsBBCode();
}

$html = $this->getReplacementText();

if ($this->usesOption()) {
$html = str_ireplace('{option}', $el->getAttribute(), $html);
}

if ($this->parseContent()) {
$content = "";
foreach ($el->getChildren() as $child)
$content .= $child->getAsHTML();
} else {
$content = "";
foreach ($el->getChildren() as $child)
$content .= $child->getAsBBCode();
}

$html = str_ireplace('{param}', $content, $html);

return $html;
}

/**
* Accepts an ElementNode that is defined by this CodeDefinition and returns the text
* representation of the element. This may be overridden by a custom CodeDefinition.
*
* @param $el the element to return a text representation of
*
* @return the text representation of $el
*/
public function asText(ElementNode $el)
{
if (!$this->hasValidInputs($el)) {
return $el->getAsBBCode();
}

$s = "";
foreach ($el->getChildren() as $child)
$s .= $child->getAsText();
return $s;
}

/**
* Returns the tag name of this code definition
*
* @return this definition's associated tag name
*/
public function getTagName()
{
return $this->tagName;
}

/**
* Returns the replacement text of this code definition. This usually has little, if any meaning if the
* CodeDefinition class was extended. For default, html replacement CodeDefinitions this returns the html
* markup for the definition.
*
* @return the replacement text of this CodeDefinition
*/
public function getReplacementText()
{
return $this->replacementText;
}

/**
* Returns whether or not this CodeDefinition uses the optional {option}
*
* @return true if this CodeDefinition uses the option, false otherwise
*/
public function usesOption()
{
return $this->useOption;
}

/**
* Returns whether or not this CodeDefnition parses elements contained within it,
* or just treats its children as text.
*
* @return true if this CodeDefinition parses elements contained within itself
*/
public function parseContent()
{
return $this->parseContent;
}

/**
* Returns the limit of how many elements defined by this CodeDefinition may be
* nested together. If after parsing elements are nested beyond this limit, the
* subtrees formed by those nodes will be removed from the parse tree. A nest
* limit of -1 signifies no limit.
*/
public function getNestLimit()
{
return $this->nestLimit;
}

/**
* Sets the tag name of this CodeDefinition
*
* @deprecated
*
* @param the new tag name of this definition
*/
public function setTagName($tagName)
{
$this->tagName = strtolower($tagName);
}

/**
* Sets the html replacement text of this CodeDefinition
*
* @deprecated
*
* @param the new replacement text
*/
public function setReplacementText($txt)
{
$this->replacementText = $txt;
}

/**
* Sets whether or not this CodeDefinition uses the {option}
*
* @deprecated
*
* @param boolean $bool
*/
public function setUseOption($bool)
{
$this->useOption = $bool;
}

/**
* Sets whether or not this CodeDefinition allows its children to be parsed as html
*
* @deprecated
*
* @param boolean $bool
*/
public function setParseContent($bool)
{
$this->parseContent = $bool;
}

/**
* Increments the element counter. This is used for tracking depth of elements of the same type for next limits.
*
* @deprecated
*
* @return void
*/
public function incrementCounter()
{
$this->elCounter++;
}

/**
* Decrements the element counter.
*
* @deprecated
*
* @return void
*/
public function decrementCounter()
{
$this->elCounter--;
}

/**
* Resets the element counter.
*
* @deprecated
*/
public function resetCounter()
{
$this->elCounter = 0;
}

/**
* Returns the current value of the element counter.
*
* @deprecated
*
* @return int
*/
public function getCounter()
{
return $this->elCounter;
}
}

0 comments on commit 381e15f

Please sign in to comment.