diff --git a/.gitignore b/.gitignore index 393c2c285..8627db1fa 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ application/modules/smilies/static/img web.config robots.txt .user.ini + +/vendor/ diff --git a/README.md b/README.md index 5e409b98b..1a194471d 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,15 @@ Ilch 2.0 ist der direkte Nachfolger der Ilch Versionen 1.1. - Aufrufen der "/index.php" - Den Bildschirmanweisungen folgen +### Installation der Entwicklerversion +- Dateien in das Webverzeichnis legen +- [Composer installieren](https://getcomposer.org/download/) (falls noch nicht geschehen) +- `composer install` ausführen, um die Abhängigkeiten zu laden +- Aufrufen der "/index.php" +- Den Bildschirmanweisungen folgen + ### Voraussetzungen -- PHP Version 5.4 +- PHP Version 5.5 - MySQL, MariaDB oder Equivalent ### Support/Dokumentation diff --git a/application/libraries/Ilch/Design/Base.php b/application/libraries/Ilch/Design/Base.php index 06c6aaacf..812109099 100644 --- a/application/libraries/Ilch/Design/Base.php +++ b/application/libraries/Ilch/Design/Base.php @@ -248,8 +248,6 @@ public function escape($string) */ public function getHtmlFromBBCode($bbcode) { - require_once APPLICATION_PATH.'/libraries/jbbcode/Parser.php'; - $parser = new \JBBCode\Parser(); $parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet()); diff --git a/application/libraries/Ilch/Loader.php b/application/libraries/Ilch/Loader.php index fcd6bacf2..2db7e28cb 100644 --- a/application/libraries/Ilch/Loader.php +++ b/application/libraries/Ilch/Loader.php @@ -6,70 +6,39 @@ namespace Ilch; -require_once APPLICATION_PATH.'/libraries/Ilch/Functions.php'; - +/** + * Class Loader for loading classes of modules + */ class Loader { - /** - * @var string[] - */ - protected $namespaces = ['Ilch']; - /** * Initialize "spl_autoload_register". */ public function __construct() { - /** - * Loads all needed files for the given class. - * - * @param string $class - * @throws \InvalidArgumentException - */ - spl_autoload_register(function ($class) { - $class = str_replace('\\', '/', $class); - $classParts = explode('/', $class); - $path = APPLICATION_PATH; - $type = 'modules'; - - /* - * Libraries path handling. - */ - foreach ($this->namespaces as $nameSpace) { - if (strpos($classParts[0], $nameSpace) !== false) { - $type = 'libraries'; - $path = $path.'/libraries'; - break; - } - } - - /* - * Modules path handling. - */ - if ($type == 'modules') { - $lastClassPart = $classParts[count($classParts)-1]; - unset($classParts[count($classParts)-1]); - $classParts = array_map('strtolower', $classParts); - $class = implode('/', $classParts).'/'.$lastClassPart; - } - - /* - * General loading handling. - */ - if (file_exists($path.'/'. $class . '.php')) { - require_once($path.'/'. $class . '.php'); - } - }); + spl_autoload_register([$this, 'loadModuleClass']); } /** - * Adds loader namespace. - * - * @param string $namespace + * Load a module class + * @param string $class */ - public function registNamespace($namespace) + private function loadModuleClass($class) { - $this->namespaces[$namespace] = $namespace; + $class = str_replace('\\', '/', $class); + $classParts = explode('/', $class); + + $lastClassPart = array_pop($classParts); + $classParts = array_map('strtolower', $classParts); + + $filePath = APPLICATION_PATH . '/' . implode('/', $classParts) . '/'.$lastClassPart . '.php'; + + /* + * General loading handling. + */ + if (file_exists($filePath)) { + require $filePath; + } } } diff --git a/application/libraries/jbbcode/CodeDefinition.php b/application/libraries/jbbcode/CodeDefinition.php deleted file mode 100644 index 99dba5961..000000000 --- a/application/libraries/jbbcode/CodeDefinition.php +++ /dev/null @@ -1,310 +0,0 @@ -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; - } -} diff --git a/application/libraries/jbbcode/CodeDefinitionBuilder.php b/application/libraries/jbbcode/CodeDefinitionBuilder.php deleted file mode 100644 index 14ea72cd4..000000000 --- a/application/libraries/jbbcode/CodeDefinitionBuilder.php +++ /dev/null @@ -1,157 +0,0 @@ -tagName = $tagName; - $this->replacementText = $replacementText; - } - - /** - * Sets the tag name the CodeDefinition should be built with. - * - * @param $tagName the tag name for the new CodeDefinition - */ - public function setTagName($tagName) - { - $this->tagName = $tagName; - return $this; - } - - /** - * Sets the replacement text that the new CodeDefinition should be - * built with. - * - * @param $replacementText the replacement text for the new CodeDefinition - */ - public function setReplacementText($replacementText) - { - $this->replacementText = $replacementText; - return $this; - } - - /** - * Set whether or not the built CodeDefinition should use the {option} bbcode - * argument. - * - * @param $option ture iff the definition includes an option - */ - public function setUseOption($option) - { - $this->useOption = $option; - return $this; - } - - /** - * Set whether or not the built CodeDefinition should allow its content - * to be parsed and evaluated as bbcode. - * - * @param $parseContent true iff the content should be parsed - */ - public function setParseContent($parseContent) - { - $this->parseContent = $parseContent; - return $this; - } - - /** - * Sets the nest limit for this code definition. - * - * @param $nestLimit a positive integer, or -1 if there is no limit. - * @throws InvalidArgumentException if the nest limit is invalid - */ - public function setNestLimit($limit) - { - if (!is_int($limit) || ($limit <= 0 && -1 != $limit)) { - throw new InvalidArgumentException("A nest limit must be a positive integer " . - "or -1."); - } - $this->nestLimit = $limit; - return $this; - } - - /** - * Sets the InputValidator that option arguments should be validated with. - * - * @param $validator the InputValidator instance to use - */ - public function setOptionValidator(\JBBCode\InputValidator $validator) - { - $this->optionValidator = $validator; - return $this; - } - - /** - * Sets the InputValidator that body ({param}) text should be validated with. - * - * @param $validator the InputValidator instance to use - */ - public function setBodyValidator(\JBBCode\InputValidator $validator) - { - $this->bodyValidator = $validator; - return $this; - } - - /** - * Removes the attached option validator if one is attached. - */ - public function removeOptionValidator() - { - $this->optionValidator = null; - return $this; - } - - /** - * Removes the attached body validator if one is attached. - */ - public function removeBodyValidator() - { - $this->bodyValidator = null; - return $this; - } - - /** - * Builds a CodeDefinition with the current state of the builder. - * - * @return a new CodeDefinition instance - */ - public function build() - { - $definition = CodeDefinition::construct($this->tagName, - $this->replacementText, - $this->useOption, - $this->parseContent, - $this->nestLimit, - $this->optionValidator, - $this->bodyValidator); - return $definition; - } - - -} diff --git a/application/libraries/jbbcode/CodeDefinitionSet.php b/application/libraries/jbbcode/CodeDefinitionSet.php deleted file mode 100644 index 1b166503a..000000000 --- a/application/libraries/jbbcode/CodeDefinitionSet.php +++ /dev/null @@ -1,22 +0,0 @@ -{param}'); - array_push($this->definitions, $builder->build()); - - /* [i] italics tag */ - $builder = new CodeDefinitionBuilder('i', '{param}'); - array_push($this->definitions, $builder->build()); - - /* [u] italics tag */ - $builder = new CodeDefinitionBuilder('u', '{param}'); - array_push($this->definitions, $builder->build()); - - $urlValidator = new \JBBCode\validators\UrlValidator(); - - /* [url] link tag */ - $builder = new CodeDefinitionBuilder('url', '{param}'); - $builder->setParseContent(false)->setBodyValidator($urlValidator); - array_push($this->definitions, $builder->build()); - - /* [url=http://example.com] link tag */ - $builder = new CodeDefinitionBuilder('url', '{param}'); - $builder->setUseOption(true)->setParseContent(true)->setOptionValidator($urlValidator); - array_push($this->definitions, $builder->build()); - - /* [img] image tag */ - $builder = new CodeDefinitionBuilder('img', ''); - $builder->setUseOption(false)->setParseContent(false)->setBodyValidator($urlValidator); - array_push($this->definitions, $builder->build()); - - /* [img=alt text] image tag */ - $builder = new CodeDefinitionBuilder('img', ''); - $builder->setUseOption(true); - array_push($this->definitions, $builder->build()); - - /* [color] color tag */ - $builder = new CodeDefinitionBuilder('color', '{param}'); - $builder->setUseOption(true)->setOptionValidator(new \JBBCode\validators\CssColorValidator()); - array_push($this->definitions, $builder->build()); - } - - /** - * Returns an array of the default code definitions. - */ - public function getCodeDefinitions() - { - return $this->definitions; - } - -} diff --git a/application/libraries/jbbcode/DocumentElement.php b/application/libraries/jbbcode/DocumentElement.php deleted file mode 100644 index 01eaca41f..000000000 --- a/application/libraries/jbbcode/DocumentElement.php +++ /dev/null @@ -1,65 +0,0 @@ -setTagName("Document"); - $this->setNodeId(0); - } - - /** - * (non-PHPdoc) - * @see JBBCode.ElementNode::getAsBBCode() - * - * Returns the BBCode representation of this document - * - * @return this document's bbcode representation - */ - public function getAsBBCode() - { - $s = ""; - foreach ($this->getChildren() as $child) - $s .= $child->getAsBBCode(); - - return $s; - } - - /** - * (non-PHPdoc) - * @see JBBCode.ElementNode::getAsHTML() - * - * Documents don't add any html. They only exist as a container for their children, so getAsHTML() simply iterates through the - * document's children, returning their html. - * - * @return the HTML representation of this document - */ - public function getAsHTML() - { - $s = ""; - foreach ($this->getChildren() as $child) - $s .= $child->getAsHTML(); - - return $s; - } - - public function accept(NodeVisitor $visitor) - { - $visitor->visitDocumentElement($this); - } - -} diff --git a/application/libraries/jbbcode/ElementNode.php b/application/libraries/jbbcode/ElementNode.php deleted file mode 100644 index 4cf897cca..000000000 --- a/application/libraries/jbbcode/ElementNode.php +++ /dev/null @@ -1,233 +0,0 @@ -children = []; - $this->nestDepth = 0; - } - - /** - * Accepts the given NodeVisitor. This is part of an implementation - * of the Visitor pattern. - * - * @param $nodeVisitor the visitor attempting to visit this node - */ - public function accept(NodeVisitor $nodeVisitor) - { - $nodeVisitor->visitElementNode($this); - } - - /** - * Gets the CodeDefinition that defines this element. - * - * @return this element's code definition - */ - public function getCodeDefinition() - { - return $this->codeDefinition; - } - - /** - * Sets the CodeDefinition that defines this element. - * - * @param codeDef the code definition that defines this element node - */ - public function setCodeDefinition(CodeDefinition $codeDef) - { - $this->codeDefinition = $codeDef; - $this->setTagName($codeDef->getTagName()); - } - - /** - * Returns the tag name of this element. - * - * @return the element's tag name - */ - public function getTagName() - { - return $this->tagName; - } - - /** - * Returns the attribute (used as the option in bbcode definitions) of this element. - * - * @return the attribute of this element - */ - public function getAttribute() - { - return $this->attribute; - } - - /** - * Returns all the children of this element. - * - * @return an array of this node's child nodes - */ - public function getChildren() - { - return $this->children; - } - - /** - * (non-PHPdoc) - * @see JBBCode.Node::getAsText() - * - * Returns the element as text (not including any bbcode markup) - * - * @return the plain text representation of this node - */ - public function getAsText() - { - if ($this->codeDefinition) { - return $this->codeDefinition->asText($this); - } else { - $s = ""; - foreach ($this->getChildren() as $child) - $s .= $child->getAsText(); - return $s; - } - } - - /** - * (non-PHPdoc) - * @see JBBCode.Node::getAsBBCode() - * - * Returns the element as bbcode (with all unclosed tags closed) - * - * @return the bbcode representation of this element - */ - public function getAsBBCode() - { - $str = "[".$this->tagName; - if ($this->attribute != null) { - $str .= "=" . $this->attribute; - } - $str .= "]"; - foreach ($this->getChildren() as $child) { - $str .= $child->getAsBBCode(); - } - $str .= "[/".$this->tagName."]"; - - return $str; - } - - /** - * (non-PHPdoc) - * @see JBBCode.Node::getAsHTML() - * - * Returns the element as html with all replacements made - * - * @return the html representation of this node - */ - public function getAsHTML() - { - if ($this->codeDefinition) { - return $this->codeDefinition->asHtml($this); - } else { - return ""; - } - } - - /** - * Adds a child to this node's content. A child may be a TextNode, or - * another ElementNode... or anything else that may extend the - * abstract Node class. - * - * @param child the node to add as a child - */ - public function addChild(Node $child) - { - array_push($this->children, $child); - $child->setParent($this); - } - - /** - * Removes a child from this node's contnet. - * - * @param child the child node to remove - */ - public function removeChild(Node $child) - { - foreach ($this->children as $key => $value) { - if ($value == $child) - unset($this->children[$key]); - } - } - - /** - * Sets the tag name of this element node. - * - * @param tagName the element's new tag name - */ - public function setTagName($tagName) - { - $this->tagName = $tagName; - } - - /** - * Sets the attribute (option) of this element node. - * - * @param attribute the attribute of this element node - */ - public function setAttribute($attribute) - { - $this->attribute = $attribute; - } - - /** - * Traverses the parse tree upwards, going from parent to parent, until it finds a - * parent who has the given tag name. Returns the parent with the matching tag name - * if it exists, otherwise returns null. - * - * @param str the tag name to search for - * - * @return the closest parent with the given tag name - */ - public function closestParentOfType($str) - { - $str = strtolower($str); - $currentEl = $this; - - while (strtolower($currentEl->getTagName()) != $str && $currentEl->hasParent()) { - $currentEl = $currentEl->getParent(); - } - - if (strtolower($currentEl->getTagName()) != $str) { - return null; - } else { - return $currentEl; - } - } - -} diff --git a/application/libraries/jbbcode/InputValidator.php b/application/libraries/jbbcode/InputValidator.php deleted file mode 100644 index 677470964..000000000 --- a/application/libraries/jbbcode/InputValidator.php +++ /dev/null @@ -1,20 +0,0 @@ -nodeid; - } - - /** - * Returns this node's immediate parent. - * - * @return the node's parent - */ - public function getParent() - { - return $this->parent; - } - - /** - * Determines if this node has a parent. - * - * @return true if this node has a parent, false otherwise - */ - public function hasParent() - { - return $this->parent != null; - } - - /** - * Returns true if this is a text node. Returns false otherwise. - * (Overridden by TextNode to return true) - * - * @return true if this node is a text node - */ - public function isTextNode() - { - return false; - } - - /** - * Accepts a NodeVisitor - * - * @param nodeVisitor the NodeVisitor traversing the graph - */ - abstract public function accept(NodeVisitor $nodeVisitor); - - /** - * Returns this node as text (without any bbcode markup) - * - * @return the plain text representation of this node - */ - abstract public function getAsText(); - - /** - * Returns this node as bbcode - * - * @return the bbcode representation of this node - */ - abstract public function getAsBBCode(); - - /** - * Returns this node as HTML - * - * @return the html representation of this node - */ - abstract public function getAsHTML(); - - /** - * Sets this node's parent to be the given node. - * - * @param parent the node to set as this node's parent - */ - public function setParent(Node $parent) - { - $this->parent = $parent; - } - - /** - * Sets this node's nodeid - * - * @param nodeid this node's node id - */ - public function setNodeId($nodeid) - { - $this->nodeid = $nodeid; - } - -} diff --git a/application/libraries/jbbcode/NodeVisitor.php b/application/libraries/jbbcode/NodeVisitor.php deleted file mode 100644 index 1dd228a97..000000000 --- a/application/libraries/jbbcode/NodeVisitor.php +++ /dev/null @@ -1,20 +0,0 @@ -reset(); - $this->bbcodes = []; - } - - /** - * Adds a simple (text-replacement only) bbcode definition - * - * @param string $tagName the tag name of the code (for example the b in [b]) - * @param string $replace the html to use, with {param} and optionally {option} for replacements - * @param boolean $useOption whether or not this bbcode uses the secondary {option} replacement - * @param boolean $parseContent whether or not to parse the content within these elements - * @param integer $nestLimit an optional limit of the number of elements of this kind that can be nested within - * each other before the parser stops parsing them. - * @param InputValidator $optionValidator the validator to run {option} through - * @param BodyValidator $bodyValidator the validator to run {param} through (only used if $parseContent == false) - */ - public function addBBCode($tagName, $replace, $useOption = false, $parseContent = true, $nestLimit = -1, - InputValidator $optionValidator = null, InputValidator $bodyValidator = null) - { - $builder = new CodeDefinitionBuilder($tagName, $replace); - - $builder->setUseOption($useOption); - $builder->setParseContent($parseContent); - $builder->setNestLimit($nestLimit); - - if ($optionValidator) { - $builder->setOptionValidator($optionValidator); - } - - if ($bodyValidator) { - $builder->setBodyValidator($bodyValidator); - } - - $this->addCodeDefinition($builder->build()); - } - - /** - * Adds a complex bbcode definition. You may subclass the CodeDefinition class, instantiate a definition of your new - * class and add it to the parser through this method. - * - * @param CodeDefinition $definition the bbcode definition to add - */ - public function addCodeDefinition( CodeDefinition $definition ) - { - array_push($this->bbcodes, $definition); - } - - /** - * Adds a set of CodeDefinitions. - * - * @param CodeDefinitionSet $set the set of definitions to add - */ - public function addCodeDefinitionSet(CodeDefinitionSet $set) { - foreach ($set->getCodeDefinitions() as $def) { - $this->addCodeDefinition($def); - } - } - - /** - * Returns the entire parse tree as text. Only {param} content is returned. BBCode markup will be ignored. - * - * @return a text representation of the parse tree - */ - public function getAsText() - { - return $this->treeRoot->getAsText(); - } - - /** - * Returns the entire parse tree as bbcode. This will be identical to the inputted string, except unclosed tags - * will be closed. - * - * @return a bbcode representation of the parse tree - */ - public function getAsBBCode() - { - return $this->treeRoot->getAsBBCode(); - } - - /** - * Returns the entire parse tree as HTML. All BBCode replacements will be made. This is generally the method - * you will want to use to retrieve the parsed bbcode. - * - * @return a parsed html string - */ - public function getAsHTML() - { - return $this->treeRoot->getAsHTML(); - } - - /** - * Accepts the given NodeVisitor at the root. - * - * @param nodeVisitor a NodeVisitor - */ - public function accept(NodeVisitor $nodeVisitor) - { - $this->treeRoot->accept($nodeVisitor); - } - /** - * Constructs the parse tree from a string of bbcode markup. - * - * @param string $str the bbcode markup to parse - */ - public function parse( $str ) - { - /* Set the tree root back to a fresh DocumentElement. */ - $this->reset(); - - $parent = $this->treeRoot; - $tokenizer = new Tokenizer($str); - - while ($tokenizer->hasNext()) { - $parent = $this->parseStartState($parent, $tokenizer); - if ($parent->getCodeDefinition() && false === - $parent->getCodeDefinition()->parseContent()) { - /* We're inside an element that does not allow its contents to be parseable. */ - $this->parseAsTextUntilClose($parent, $tokenizer); - $parent = $parent->getParent(); - } - } - - /* We parsed ignoring nest limits. Do a O(n) traversal to remove any elements that - * are nested beywond their CodeDefinition's nest limit. */ - $this->removeOverNestedElements(); - } - - /** - * Removes any elements that are nested beyond their nest limit from the parse tree. This - * method is now deprecated. In a future release its access privileges will be made - * protected. - * - * @deprecated - */ - public function removeOverNestedElements() - { - $nestLimitVisitor = new \JBBCode\visitors\NestLimitVisitor(); - $this->accept($nestLimitVisitor); - } - - /** - * Removes the old parse tree if one exists. - */ - protected function reset() - { - // remove any old tree information - $this->treeRoot = new DocumentElement(); - /* The document element is created with nodeid 0. */ - $this->nextNodeid = 1; - } - - /** - * Determines whether a bbcode exists based on its tag name and whether or not it uses an option - * - * @param string $tagName the bbcode tag name to check - * @param boolean $usesOption whether or not the bbcode accepts an option - * - * @return true if the code exists, false otherwise - */ - public function codeExists( $tagName, $usesOption = false ) - { - foreach ($this->bbcodes as $code) { - if (strtolower($tagName) == $code->getTagName() && $usesOption == $code->usesOption()) { - return true; - } - } - - return false; - } - - /** - * Returns the CodeDefinition of a bbcode with the matching tag name and usesOption parameter - * - * @param string $tagName the tag name of the bbcode being searched for - * @param boolean $usesOption whether or not the bbcode accepts an option - * - * @return CodeDefinition if the bbcode exists, null otherwise - */ - public function getCode( $tagName, $usesOption = false ) - { - foreach ($this->bbcodes as $code) { - if (strtolower($tagName) == $code->getTagName() && $code->usesOption() == $usesOption) { - return $code; - } - } - - return null; - } - - /** - * Adds a set of default, standard bbcode definitions commonly used across the web. - * - * This method is now deprecated. Please use DefaultCodeDefinitionSet and - * addCodeDefinitionSet() instead. - * - * @deprecated - */ - public function loadDefaultCodes() - { - $defaultSet = new DefaultCodeDefinitionSet(); - $this->addCodeDefinitionSet($defaultSet); - } - - /** - * Creates a new text node with the given parent and text string. - * - * @param $parent the parent of the text node - * @param $string the text of the text node - * - * @return the newly created TextNode - */ - protected function createTextNode(ElementNode $parent, $string) - { - $textNode = new TextNode($string); - $textNode->setNodeId(++$this->nextNodeid); - $parent->addChild($textNode); - return $textNode; - } - - /** - * jBBCode parsing logic is loosely modelled after a FSM. While not every function maps - * to a unique DFSM state, each function handles the logic of one or more FSM states. - * This function handles the beginning parse state when we're not currently in a tag - * name. - * - * @param $parent the current parent node we're under - * @param $tokenizer the tokenizer we're using - * - * @return the new parent we should use for the next iteration. - */ - protected function parseStartState(ElementNode $parent, Tokenizer $tokenizer) - { - $next = $tokenizer->next(); - - if ('[' == $next) { - return $this->parseTagOpen($parent, $tokenizer); - } else { - $this->createTextNode($parent, $next); - /* Drop back into the main parse loop which will call this - * same method again. */ - return $parent; - } - } - - /** - * This function handles parsing the beginnings of an open tag. When we see a [ - * at an appropriate time, this function is entered. - * - * @param $parent the current parent node - * @param $tokenizer the tokenizer we're using - * - * @return the new parent node - */ - protected function parseTagOpen(ElementNode $parent, Tokenizer $tokenizer) - { - - if (!$tokenizer->hasNext()) { - /* The [ that sent us to this state was just a trailing [, not the - * opening for a new tag. Treat it as such. */ - $this->createTextNode($parent, '['); - return $parent; - } - - $next = $tokenizer->next(); - - /* This while loop could be replaced by a recursive call to this same method, - * which would likely be a lot clearer but I decided to use a while loop to - * prevent stack overflow with a string like [[[[[[[[[...[[[. - */ - while ('[' == $next) { - /* The previous [ was just a random bracket that should be treated as text. - * Continue until we get a non open bracket. */ - $this->createTextNode($parent, '['); - if (!$tokenizer->hasNext()) { - $this->createTextNode($parent, '['); - return $parent; - } - $next = $tokenizer->next(); - } - - /* At this point $next is either ']' or plain text. */ - if (']' == $next) { - $this->createTextNode($parent, '['); - $this->createTextNode($parent, ']'); - return $parent; - } else { - /* $next is plain text... likely a tag name. */ - return $this->parseTag($parent, $tokenizer, $next); - } - } - - /** - * This is the next step in parsing a tag. It's possible for it to still be invalid at this - * point but many of the basic invalid tag name conditions have already been handled. - * - * @param $parent the current parent element - * @param $tokenizer the tokenizer we're using - * @param $tagContent the text between the [ and the ], assuming there is actually a ] - * - * @return the new parent element - */ - protected function parseTag(ElementNode $parent, Tokenizer $tokenizer, $tagContent) - { - - $next; - if (!$tokenizer->hasNext() || ($next = $tokenizer->next()) != ']') { - /* This is a malformed tag. Both the previous [ and the tagContent - * is really just plain text. */ - $this->createTextNode($parent, '['); - $this->createTextNode($parent, $tagContent); - return $parent; - } - - /* This is a well-formed tag consisting of [something] or [/something], but - * we still need to ensure that 'something' is a valid tag name. Additionally, - * if it's a closing tag, we need to ensure that there was a previous matching - * opening tag. - */ - - /* There could be an attribute. */ - $tagPieces = explode('=', $tagContent); - $tmpTagName = $tagPieces[0]; - - $actualTagName; - if ('/' == $tmpTagName[0]) { - /* This is a closing tag name. */ - $actualTagName = substr($tmpTagName, 1); - } else { - $actualTagName = $tmpTagName; - } - - if ('/' == $tmpTagName[0]) { - /* This is attempting to close an open tag. We must verify that there exists an - * open tag of the same type and that there is no option (options on closing - * tags don't make any sense). */ - $elToClose = $parent->closestParentOfType($actualTagName); - if (null == $elToClose || count($tagPieces) > 1) { - /* Closing an unopened tag or has an option. Treat everything as plain text. */ - $this->createTextNode($parent, '['); - $this->createTextNode($parent, $tagContent); - $this->createTextNode($parent, ']'); - return $parent; - } else { - /* We're closing $elToClose. In order to do that, we just need to return - * $elToClose's parent, since that will change our effective parent to be - * elToClose's parent. */ - return $elToClose->getParent(); - } - } - - /* Verify that this is a known bbcode tag name. */ - if ('' == $actualTagName || !$this->codeExists($actualTagName, count($tagPieces) > 1)) { - /* This is an invalid tag name! Treat everything we've seen as plain text. */ - $this->createTextNode($parent, '['); - $this->createTextNode($parent, $tagContent); - $this->createTextNode($parent, ']'); - return $parent; - } - - /* If we're here, this is a valid opening tag. Let's make a new node for it. */ - $el = new ElementNode(); - $el->setNodeId(++$this->nextNodeid); - $code = $this->getCode($actualTagName, count($tagPieces) > 1); - $el->setCodeDefinition($code); - if (count($tagPieces) > 1) { - /* We have an attribute we should save. */ - unset($tagPieces[0]); - $el->setAttribute(implode('=', $tagPieces)); - } - $parent->addChild($el); - return $el; - } - - /** - * Handles parsing elements whose CodeDefinitions disable parsing of element - * contents. This function uses a rolling window of 3 tokens until it finds the - * appropriate closing tag or reaches the end of the token stream. - * - * @param $parent the current parent element - * @param $tokenizer the tokenizer we're using - */ - protected function parseAsTextUntilClose(ElementNode $parent, Tokenizer $tokenizer) - { - /* $parent's code definition doesn't allow its contents to be parsed. Here we use - * a sliding of window of three tokens until we find [ /tagname ], signifying the - * end of the parent. */ - if (!$tokenizer->hasNext()) { - return $parent; - } - $prevPrev = $tokenizer->next(); - if (!$tokenizer->hasNext()) { - $this->createTextNode($parent, $prevPrev); - return $parent; - } - $prev = $tokenizer->next(); - if (!$tokenizer->hasNext()) { - $this->createTextNode($parent, $prevPrev); - $this->createTextNode($parent, $prev); - return $parent; - } - $curr = $tokenizer->next(); - while ('[' != $prevPrev || '/'.$parent->getTagName() != strtolower($prev) || - ']' != $curr) { - $this->createTextNode($parent, $prevPrev); - $prevPrev = $prev; - $prev = $curr; - if (!$tokenizer->hasNext()) { - $this->createTextNode($parent, $prevPrev); - $this->createTextNode($parent, $prev); - return $parent; - } - $curr = $tokenizer->next(); - } - } - -} diff --git a/application/libraries/jbbcode/TextNode.php b/application/libraries/jbbcode/TextNode.php deleted file mode 100644 index b237b7f09..000000000 --- a/application/libraries/jbbcode/TextNode.php +++ /dev/null @@ -1,102 +0,0 @@ -value = $val; - } - - public function accept(NodeVisitor $visitor) - { - $visitor->visitTextNode($this); - } - - /** - * (non-PHPdoc) - * @see JBBCode.Node::isTextNode() - * - * returns true - */ - public function isTextNode() - { - return true; - } - - /** - * Returns the text string value of this text node. - * - * @return string - */ - public function getValue() - { - return $this->value; - } - - /** - * (non-PHPdoc) - * @see JBBCode.Node::getAsText() - * - * Returns the text representation of this node. - * - * @return this node represented as text - */ - public function getAsText() - { - return $this->getValue(); - } - - /** - * (non-PHPdoc) - * @see JBBCode.Node::getAsBBCode() - * - * Returns the bbcode representation of this node. (Just its value) - * - * @return this node represented as bbcode - */ - public function getAsBBCode() - { - return $this->getValue(); - } - - /** - * (non-PHPdoc) - * @see JBBCode.Node::getAsHTML() - * - * Returns the html representation of this node. (Just its value) - * - * @return this node represented as HTML - */ - public function getAsHTML() - { - return $this->getValue(); - } - - /** - * Edits the text value contained within this text node. - * - * @param newValue the new text value of the text node - */ - public function setValue($newValue) - { - $this->value = $newValue; - } - -} diff --git a/application/libraries/jbbcode/Tokenizer.php b/application/libraries/jbbcode/Tokenizer.php deleted file mode 100644 index ebb319b41..000000000 --- a/application/libraries/jbbcode/Tokenizer.php +++ /dev/null @@ -1,105 +0,0 @@ -tokens, substr($str, $strStart, $index - $strStart)); - $strStart = $index; - } - - /* Add the [ or ] to the tokens array. */ - array_push($this->tokens, $str[$index]); - $strStart = $index+1; - } - } - - if ($strStart < strlen($str)) { - /* There are still characters in the buffer. Add them to the tokens. */ - array_push($this->tokens, substr($str, $strStart, strlen($str) - $strStart)); - } - } - - /** - * Returns true iff there is another token in the token stream. - */ - public function hasNext() - { - return count($this->tokens) > 1 + $this->i; - } - - /** - * Advances the token stream to the next token and returns the new token. - */ - public function next() - { - if (!$this->hasNext()) { - return null; - } else { - return $this->tokens[++$this->i]; - } - } - - /** - * Retrieves the current token. - */ - public function current() - { - if ($this->i < 0) { - return null; - } else { - return $this->tokens[$this->i]; - } - } - - /** - * Moves the token stream back a token. - */ - public function stepBack() - { - if ($this->i > -1) { - $this->i--; - } - } - - /** - * Restarts the tokenizer, returning to the beginning of the token stream. - */ - public function restart() - { - $this->i = -1; - } - - /** - * toString method that returns the entire string from the current index on. - */ - public function toString() - { - return implode('', array_slice($this->tokens, $this->i + 1)); - } - -} diff --git a/application/libraries/jbbcode/composer.json b/application/libraries/jbbcode/composer.json deleted file mode 100644 index e64dab5b7..000000000 --- a/application/libraries/jbbcode/composer.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "jbbcode/jbbcode", - "type": "library", - "description": "A lightweight but extensible BBCode parser written in PHP 5.3.", - "keywords": ["BBCode", "BB"], - "homepage": "http://jbbcode.com/", - "license": "MIT", - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "3.7.*" - }, - "config": { - "bin-dir": "/usr/local/bin" - }, - "authors": [ - { - "name": "Jackson Owens", - "email": "jackson_owens@brown.edu", - "homepage": "http://jbowens.org/", - "role": "Developer" - } - ], - "autoload": { - "psr-0": { - "JBBCode": "." - } - }, - "minimum-stability": "stable" -} diff --git a/application/libraries/jbbcode/validators/CssColorValidator.php b/application/libraries/jbbcode/validators/CssColorValidator.php deleted file mode 100644 index ce51fa487..000000000 --- a/application/libraries/jbbcode/validators/CssColorValidator.php +++ /dev/null @@ -1,30 +0,0 @@ -getChildren() as $child) { - $child->accept($this); - } - } - - public function visitTextNode(\JBBCode\TextNode $textNode) - { - /* Nothing to do. Text nodes don't have tag names or children. */ - } - - public function visitElementNode(\JBBCode\ElementNode $elementNode) - { - $tagName = strtolower($elementNode->getTagName()); - - /* Update the current depth for this tag name. */ - if (isset($this->depth[$tagName])) { - $this->depth[$tagName]++; - } else { - $this->depth[$tagName] = 1; - } - - /* Check if $elementNode is nested too deeply. */ - if ($elementNode->getCodeDefinition()->getNestLimit() != -1 && - $elementNode->getCodeDefinition()->getNestLimit() < $this->depth[$tagName]) { - /* This element is nested too deeply. We need to remove it and not visit any - * of its children. */ - $elementNode->getParent()->removeChild($elementNode); - } else { - /* This element is not nested too deeply. Visit all of the children. */ - foreach ($elementNode->getChildren() as $child) { - $child->accept($this); - } - } - - /* Now that we're done visiting this node, decrement the depth. */ - $this->depth[$tagName]--; - } - -} diff --git a/application/libraries/jbbcode/visitors/SmileyVisitor.php b/application/libraries/jbbcode/visitors/SmileyVisitor.php deleted file mode 100644 index b9086d01a..000000000 --- a/application/libraries/jbbcode/visitors/SmileyVisitor.php +++ /dev/null @@ -1,42 +0,0 @@ -getChildren() as $child) { - $child->accept($this); - } - } - - function visitTextNode(\JBBCode\TextNode $textNode) - { - /* Convert :) into an image tag. */ - $textNode->setValue(str_replace(':)', - ':)', - $textNode->getValue())); - } - - function visitElementNode(\JBBCode\ElementNode $elementNode) - { - /* We only want to visit text nodes within elements if the element's - * code definition allows for its content to be parsed. - */ - if ($elementNode->getCodeDefinition()->parseContent()) { - foreach ($elementNode->getChildren() as $child) { - $child->accept($this); - } - } - } - -} diff --git a/application/libraries/jbbcode/visitors/TagCountingVisitor.php b/application/libraries/jbbcode/visitors/TagCountingVisitor.php deleted file mode 100644 index a72b9dd72..000000000 --- a/application/libraries/jbbcode/visitors/TagCountingVisitor.php +++ /dev/null @@ -1,60 +0,0 @@ -getChildren() as $child) { - $child->accept($this); - } - } - - public function visitTextNode(\JBBCode\TextNode $textNode) - { - // Nothing to do here, text nodes do not have tag names or children - } - - public function visitElementNode(\JBBCode\ElementNode $elementNode) - { - $tagName = strtolower($elementNode->getTagName()); - - // Update this tag name's frequency - if (isset($this->frequencies[$tagName])) { - $this->frequencies[$tagName]++; - } else { - $this->frequencies[$tagName] = 1; - } - - // Visit all the node's childrens - foreach ($elementNode->getChildren() as $child) { - $child->accept($this); - } - - } - - /** - * Retrieves the frequency of the given tag name. - * - * @param $tagName the tag name to look up - */ - public function getFrequency($tagName) - { - if (!isset($this->frequencies[$tagName])) { - return 0; - } else { - return $this->frequencies[$tagName]; - } - } - -} diff --git a/application/libraries/password_compat/LICENSE.md b/application/libraries/password_compat/LICENSE.md deleted file mode 100644 index 1efc565fc..000000000 --- a/application/libraries/password_compat/LICENSE.md +++ /dev/null @@ -1,7 +0,0 @@ -Copyright (c) 2012 Anthony Ferrara - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/application/libraries/password_compat/password.php b/application/libraries/password_compat/password.php deleted file mode 100644 index 1670fda3b..000000000 --- a/application/libraries/password_compat/password.php +++ /dev/null @@ -1,314 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @copyright 2012 The Authors - */ - -namespace { - - if (!defined('PASSWORD_BCRYPT')) { - /** - * PHPUnit Process isolation caches constants, but not function declarations. - * So we need to check if the constants are defined separately from - * the functions to enable supporting process isolation in userland - * code. - */ - define('PASSWORD_BCRYPT', 1); - define('PASSWORD_DEFAULT', PASSWORD_BCRYPT); - define('PASSWORD_BCRYPT_DEFAULT_COST', 10); - } - - if (!function_exists('password_hash')) { - - /** - * Hash the password using the specified algorithm - * - * @param string $password The password to hash - * @param int $algo The algorithm to use (Defined by PASSWORD_* constants) - * @param array $options The options for the algorithm to use - * - * @return string|false The hashed password, or false on error. - */ - function password_hash($password, $algo, array $options = []) { - if (!function_exists('crypt')) { - trigger_error("Crypt must be loaded for password_hash to function", E_USER_WARNING); - return null; - } - if (is_null($password) || is_int($password)) { - $password = (string) $password; - } - if (!is_string($password)) { - trigger_error("password_hash(): Password must be a string", E_USER_WARNING); - return null; - } - if (!is_int($algo)) { - trigger_error("password_hash() expects parameter 2 to be long, " . gettype($algo) . " given", E_USER_WARNING); - return null; - } - $resultLength = 0; - switch ($algo) { - case PASSWORD_BCRYPT: - $cost = PASSWORD_BCRYPT_DEFAULT_COST; - if (isset($options['cost'])) { - $cost = $options['cost']; - if ($cost < 4 || $cost > 31) { - trigger_error(sprintf("password_hash(): Invalid bcrypt cost parameter specified: %d", $cost), E_USER_WARNING); - return null; - } - } - // The length of salt to generate - $raw_salt_len = 16; - // The length required in the final serialization - $required_salt_len = 22; - $hash_format = sprintf("$2y$%02d$", $cost); - // The expected length of the final crypt() output - $resultLength = 60; - break; - default: - trigger_error(sprintf("password_hash(): Unknown password hashing algorithm: %s", $algo), E_USER_WARNING); - return null; - } - $salt_requires_encoding = false; - if (isset($options['salt'])) { - switch (gettype($options['salt'])) { - case 'NULL': - case 'boolean': - case 'integer': - case 'double': - case 'string': - $salt = (string) $options['salt']; - break; - case 'object': - if (method_exists($options['salt'], '__tostring')) { - $salt = (string) $options['salt']; - break; - } - case 'array': - case 'resource': - default: - trigger_error('password_hash(): Non-string salt parameter supplied', E_USER_WARNING); - return null; - } - if (PasswordCompat\binary\_strlen($salt) < $required_salt_len) { - trigger_error(sprintf("password_hash(): Provided salt is too short: %d expecting %d", PasswordCompat\binary\_strlen($salt), $required_salt_len), E_USER_WARNING); - return null; - } elseif (0 == preg_match('#^[a-zA-Z0-9./]+$#D', $salt)) { - $salt_requires_encoding = true; - } - } else { - $buffer = ''; - $buffer_valid = false; - if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) { - $buffer = mcrypt_create_iv($raw_salt_len, MCRYPT_DEV_URANDOM); - if ($buffer) { - $buffer_valid = true; - } - } - if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes')) { - $buffer = openssl_random_pseudo_bytes($raw_salt_len); - if ($buffer) { - $buffer_valid = true; - } - } - if (!$buffer_valid && @is_readable('/dev/urandom')) { - $f = fopen('/dev/urandom', 'r'); - $read = PasswordCompat\binary\_strlen($buffer); - while ($read < $raw_salt_len) { - $buffer .= fread($f, $raw_salt_len - $read); - $read = PasswordCompat\binary\_strlen($buffer); - } - fclose($f); - if ($read >= $raw_salt_len) { - $buffer_valid = true; - } - } - if (!$buffer_valid || PasswordCompat\binary\_strlen($buffer) < $raw_salt_len) { - $bl = PasswordCompat\binary\_strlen($buffer); - for ($i = 0; $i < $raw_salt_len; $i++) { - if ($i < $bl) { - $buffer[$i] = $buffer[$i] ^ chr(mt_rand(0, 255)); - } else { - $buffer .= chr(mt_rand(0, 255)); - } - } - } - $salt = $buffer; - $salt_requires_encoding = true; - } - if ($salt_requires_encoding) { - // encode string with the Base64 variant used by crypt - $base64_digits = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - $bcrypt64_digits = - './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - - $base64_string = base64_encode($salt); - $salt = strtr(rtrim($base64_string, '='), $base64_digits, $bcrypt64_digits); - } - $salt = PasswordCompat\binary\_substr($salt, 0, $required_salt_len); - - $hash = $hash_format . $salt; - - $ret = crypt($password, $hash); - - if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != $resultLength) { - return false; - } - - return $ret; - } - - /** - * Get information about the password hash. Returns an array of the information - * that was used to generate the password hash. - * - * array( - * 'algo' => 1, - * 'algoName' => 'bcrypt', - * 'options' => array( - * 'cost' => PASSWORD_BCRYPT_DEFAULT_COST, - * ), - * ) - * - * @param string $hash The password hash to extract info from - * - * @return array The array of information about the hash. - */ - function password_get_info($hash) { - $return = [ - 'algo' => 0, - 'algoName' => 'unknown', - 'options' => [], - ]; - if (PasswordCompat\binary\_substr($hash, 0, 4) == '$2y$' && PasswordCompat\binary\_strlen($hash) == 60) { - $return['algo'] = PASSWORD_BCRYPT; - $return['algoName'] = 'bcrypt'; - list($cost) = sscanf($hash, "$2y$%d$"); - $return['options']['cost'] = $cost; - } - return $return; - } - - /** - * Determine if the password hash needs to be rehashed according to the options provided - * - * If the answer is true, after validating the password using password_verify, rehash it. - * - * @param string $hash The hash to test - * @param int $algo The algorithm used for new password hashes - * @param array $options The options array passed to password_hash - * - * @return boolean True if the password needs to be rehashed. - */ - function password_needs_rehash($hash, $algo, array $options = []) { - $info = password_get_info($hash); - if ($info['algo'] != $algo) { - return true; - } - switch ($algo) { - case PASSWORD_BCRYPT: - $cost = isset($options['cost']) ? $options['cost'] : PASSWORD_BCRYPT_DEFAULT_COST; - if ($cost != $info['options']['cost']) { - return true; - } - break; - } - return false; - } - - /** - * Verify a password against a hash using a timing attack resistant approach - * - * @param string $password The password to verify - * @param string $hash The hash to verify against - * - * @return boolean If the password matches the hash - */ - function password_verify($password, $hash) { - if (!function_exists('crypt')) { - trigger_error("Crypt must be loaded for password_verify to function", E_USER_WARNING); - return false; - } - $ret = crypt($password, $hash); - if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != PasswordCompat\binary\_strlen($hash) || PasswordCompat\binary\_strlen($ret) <= 13) { - return false; - } - - $status = 0; - for ($i = 0; $i < PasswordCompat\binary\_strlen($ret); $i++) { - $status |= (ord($ret[$i]) ^ ord($hash[$i])); - } - - return $status === 0; - } - } - -} - -namespace PasswordCompat\binary { - - if (!function_exists('PasswordCompat\\binary\\_strlen')) { - - /** - * Count the number of bytes in a string - * - * We cannot simply use strlen() for this, because it might be overwritten by the mbstring extension. - * In this case, strlen() will count the number of *characters* based on the internal encoding. A - * sequence of bytes might be regarded as a single multibyte character. - * - * @param string $binary_string The input string - * - * @internal - * @return int The number of bytes - */ - function _strlen($binary_string) { - if (function_exists('mb_strlen')) { - return mb_strlen($binary_string, '8bit'); - } - return strlen($binary_string); - } - - /** - * Get a substring based on byte limits - * - * @see _strlen() - * - * @param string $binary_string The input string - * @param int $start - * @param int $length - * - * @internal - * @return string The substring - */ - function _substr($binary_string, $start, $length) { - if (function_exists('mb_substr')) { - return mb_substr($binary_string, $start, $length, '8bit'); - } - return substr($binary_string, $start, $length); - } - - /** - * Check if current PHP version is compatible with the library - * - * @return boolean the check result - */ - function check() { - static $pass = NULL; - - if (is_null($pass)) { - if (function_exists('crypt')) { - $hash = '$2y$04$usesomesillystringfore7hnbRJHxXVLeakoG8K30oukPsA.ztMG'; - $test = crypt("password", $hash); - $pass = $test == $hash; - } else { - $pass = false; - } - } - return $pass; - } - - } -} \ No newline at end of file diff --git a/application/modules/user/service/Password.php b/application/modules/user/service/Password.php index de5c2a2f7..b62b88809 100644 --- a/application/modules/user/service/Password.php +++ b/application/modules/user/service/Password.php @@ -20,9 +20,6 @@ class Password */ public function __construct($algorithm = null) { - if (version_compare(PHP_VERSION, '5.5.0', '<')) { - require_once APPLICATION_PATH . '/libraries/password_compat/password.php'; - } if (null === $algorithm) { $algorithm = PASSWORD_DEFAULT; } diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..c6c99e91a --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "ilchcms/ilch-2.0", + "description": "CMS for Clans and Communities", + "type": "project", + "license": "GPLv2", + "minimum-stability": "stable", + "config": { + "platform": { + "php": "5.5" + } + }, + "require": { + "php": ">=5.5", + "jbbcode/jbbcode": "^1.3" + }, + "require-dev": {}, + "autoload": { + "psr-0": { "": "application/libraries/" }, + "files": ["application/libraries/Ilch/Functions.php"] + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 000000000..664c3fa5a --- /dev/null +++ b/composer.lock @@ -0,0 +1,70 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "01f42cfdab308867dbdd6ab0b1a2deaf", + "content-hash": "418c3cdd1366816ad4ca86e653cd9179", + "packages": [ + { + "name": "jbbcode/jbbcode", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/jbowens/jBBCode.git", + "reference": "645b6a1c0afa92b7d029d3417ebd8b60a5c578b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jbowens/jBBCode/zipball/645b6a1c0afa92b7d029d3417ebd8b60a5c578b3", + "reference": "645b6a1c0afa92b7d029d3417ebd8b60a5c578b3", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "autoload": { + "psr-0": { + "JBBCode": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jackson Owens", + "email": "jackson_owens@alumni.brown.edu", + "homepage": "http://jbowens.org/", + "role": "Developer" + } + ], + "description": "A lightweight but extensible BBCode parser written in PHP 5.3.", + "homepage": "http://jbbcode.com/", + "keywords": [ + "BB", + "bbcode" + ], + "time": "2014-07-06 05:48:20" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.5" + }, + "platform-dev": [], + "platform-overrides": { + "php": "5.5" + } +} diff --git a/index.php b/index.php index 02b2235b0..9f65bde5a 100644 --- a/index.php +++ b/index.php @@ -4,8 +4,8 @@ * @package ilch */ -if (!version_compare(phpversion(), '5.4.0', '>=')) { - die('Ilch CMS 2.* needed minimum php version 5.4.0'); +if (!version_compare(phpversion(), '5.5.0', '>=')) { + die('Ilch CMS 2.* needed minimum php version 5.5.0'); } @ini_set('display_errors', 'on'); @@ -36,10 +36,9 @@ $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http'; define('BASE_URL', $protocol.'://'.$_SERVER['HTTP_HOST'].REWRITE_BASE); - -require_once APPLICATION_PATH.'/libraries/Ilch/Loader.php'; +//register autoloaders +require ROOT_PATH . '/vendor/autoload.php'; $loader = new \Ilch\Loader(); -$loader->registNamespace('Thumb'); \Ilch\Registry::set('startTime', microtime(true));