Skip to content

Commit

Permalink
Updated core framework files.
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Dec 19, 2019
1 parent 9fa5c84 commit 3fcf5a7
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 57 deletions.
8 changes: 4 additions & 4 deletions entity/MessageBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public function __construct() {
$this->setStyle([
'width'=>'75%',
'border'=>'1px double white',
'height'=>'150px',
'height'=>'130px',
'margin'=>'0px',
'z-index'=>'3000',
'z-index'=>'100',
'position'=>'fixed',
'background-color'=>'rgba(0,0,0,0.7)',
'color'=>'white',
'height'=>'auto',
'top'=> (self::getCount()*5).'px',
'left'=> (self::getCount()*5).'px'
'top'=> (self::getCount()*10).'px',
'left'=> (self::getCount()*10).'px'
]);
$this->_createHeader();
$this->_createBody();
Expand Down
5 changes: 2 additions & 3 deletions entity/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ public static function theme($name=null){
* @see Theme::usingTheme()
*/
private function usingTheme($themeName=null) {
if($themeName === null){
if($themeName === null && $this->theme === null){
$themeName = SiteConfig::getBaseThemeName();
}
else{
Expand Down Expand Up @@ -990,5 +990,4 @@ private function _getHead(){
}
return $headNode;
}
}

}
80 changes: 80 additions & 0 deletions entity/phpStructs/LinkedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,86 @@ public function contains(&$el){
return false;
}
}
/**
* Insert new element in the middle of the list.
* The method will try to insert new element at the given position. If the
* position is index 0, the element will be inserted at the start of the
* list. If the position equals to the number of elements in the list, then the
* element will be inserted at the end of the list. If position is between
* 0 and LinkedList::size(), then the element will be inserted in the
* middle. The element will be not inserted in only two cases:
* <ul>
* <li>Position is not between 0 and LinkedList::size() inclusive.</li>
* <li>The list accepts only a specific number of elements and its full.</li>
* </ul>
* Note that the element at the specified index will be moved to the
* next position and the new element will replace it.
* @param mixed $el The new element that will be inserted.
* @param int $position The index at which the element will be inserted in.
* @return boolean If the element is inserted, the method will return true.
* If not, the method will return false.
*/
public function insert(&$el,$position) {
if($this->validateSize()){
$size = $this->size();
if($size == 0 && $position == 0){
//empty list and insert at start.
return $this->add($el);
}
else if($size == 1 && $position == 0){
//list size is 1 and position = 0. inser at the start.
$newNode = new Node($el, $this->head);
$this->head = $newNode;
$this->tail = $this->head->next();
$this->size++;
return true;
}
else if($size == 1 && $position == 1){
//list size is 1 and position = 1. inser at the end.
$newNode = new Node($el);
$this->tail = $newNode;
$this->head->setNext($this->tail);
$this->size++;
return true;
}
else if($position == $size){
//insert at the end.
return $this->add($el);
}
else{
if($position < $size){
//insert in the middle or at the start
if($position == 0){
//inser at the start.
$newNode = new Node($el, $this->head);
$this->head = $newNode;
$this->size++;
return true;
}
else{
//insert in the middle.
$pointer = 1;
$currentNode = $this->head;
$nextToCurrent = $currentNode->next();
while ($currentNode != null){
if($pointer == $position){
$newNode = new Node($el,$nextToCurrent);
$currentNode->setNext($newNode);
$this->size++;
return true;
}
else{
$currentNode = $nextToCurrent;
$nextToCurrent = $nextToCurrent->next();
}
$pointer++;
}
}
}
}
}
return false;
}
/**
* Returns the first element that was added to the list.
* @return mixed The first element that was added to the list. If the list
Expand Down
159 changes: 142 additions & 17 deletions entity/phpStructs/html/HTMLNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* A class that represents HTML element.
*
* @author Ibrahim
* @version 1.7.8
* @version 1.7.9
*/
class HTMLNode {
/**
Expand Down Expand Up @@ -248,6 +248,84 @@ public function __construct($name='div') {
}
$this->useOriginalTxt = false;
}
/**
* Sets multiple attributes at once.
* @param array $attrsArr An associative array that has attributes names
* and values.. The indices will represents
* attributes names and the value of each index represents the values of
* the attributes.
* @return boolean|array If the given value does not represents an array,
* the method will return false. Other than that, the method will return
* an associative array. The indices of the array will be the names of the
* attributes and the values will be booleans. If an attribute is set, the
* value of the index will be set to true. If not set, the index will be
* set to false.
* @since 1.7.9
*/
public function setAttributes($attrsArr) {
if(gettype($attrsArr) == 'array'){
$retVal=[];
foreach ($attrsArr as $attr => $val){
$retVal[$attr] = $this->setAttribute($attr, $val);
}
return $retVal;
}
return false;
}
/**
* Returns the value of the attribute 'id' of the element.
* @return string|null If the attribute 'id' is set, the method will return
* its value. If not set, the method will return null.
* @since 1.7.9
*/
public function getID() {
return $this->getAttribute('id');
}
/**
* Returns the value of the attribute 'class' of the element.
* @return string|null If the attribute 'class' is set, the method will return
* its value. If not set, the method will return null.
* @since 1.7.9
*/
public function getClassName() {
return $this->getAttribute('class');
}
/**
* Returns the value of the attribute 'title' of the element.
* @return string|null If the attribute 'title' is set, the method will return
* its value. If not set, the method will return null.
* @since 1.7.9
*/
public function getTitle() {
return $this->getAttribute('title');
}
/**
* Returns the value of the attribute 'tabindex' of the element.
* @return string|null If the attribute 'tabindex' is set, the method will return
* its value. If not set, the method will return null.
* @since 1.7.9
*/
public function getTabIndex() {
return $this->getAttribute('tabindex');
}
/**
* Returns the value of the attribute 'dir' of the element.
* @return string|null If the attribute 'dir' is set, the method will return
* its value. If not set, the method will return null.
* @since 1.7.9
*/
public function getWritingDir() {
return $this->getAttribute('dir');
}
/**
* Returns the value of the attribute 'name' of the element.
* @return string|null If the attribute 'name' is set, the method will return
* its value. If not set, the method will return null.
* @since 1.7.9
*/
public function getName() {
return $this->getAttribute('name');
}
/**
* Validates the name of the node.
* @param string $name The name of the node in lower case.
Expand Down Expand Up @@ -620,7 +698,7 @@ private static function _fromHTMLTextHelper_00($nodeArr) {
}
if($isBaseSet){
foreach ($chNode['attributes'] as $attr => $val){
$htmlNode->getBase()->setAttribute($attr, $val);
$htmlNode->getBaseNode()->setAttribute($attr, $val);
}
}
}
Expand Down Expand Up @@ -966,7 +1044,7 @@ public function getNodeName(){
return $this->name;
}
/**
* Returns an array of all node attributes with the values
* Returns an associative array of all node attributes alongside the values.
* @return array|null an associative array. The keys will act as the attribute
* name and the value will act as the value of the attribute. If the node
* is a text node, the method will return null.
Expand All @@ -979,33 +1057,34 @@ public function getAttributes() {
* Sets a value for an attribute.
* @param string $name The name of the attribute. If the attribute does not
* exist, it will be created. If already exists, its value will be updated.
* Note that if the node type is text node,
* the attribute will never be created.
* @param string $val The value of the attribute. Default is empty string.
* Note that if the node type is text node, the attribute will never be created.
* @param string $val The value of the attribute. Default is empty string. Note
* that if the value has any extra spaces, they will be trimmed.
* @return boolean If the attribute is set, the method will return true. The
* method will return false only if the given name is empty string
* or the name of the attribute is 'dir' and the value is not 'ltr' or 'rtl'.
* @since 1.0
*/
public function setAttribute($name,$val=''){
$trimmedName = trim($name);
$trimmedVal = trim($val);
if(!$this->isTextNode() && !$this->isComment() && strlen($trimmedName) != 0){
$lower = strtolower($trimmedName);
$isValid = $this->_validateName($lower);
if($isValid){
if($lower == 'dir'){
$lowerVal = strtolower($val);
$lowerVal = strtolower($trimmedVal);
if($lowerVal == 'ltr' || $lowerVal == 'rtl'){
$this->attributes[$lower] = $lowerVal;
return true;
}
}
else if($trimmedName == 'style'){
$styleArr = $this->_styleArray($val);
$styleArr = $this->_styleArray($trimmedVal);
return $this->setStyle($styleArr);
}
else{
$this->attributes[$lower] = $val;
$this->attributes[$lower] = $trimmedVal;
return true;
}
}
Expand Down Expand Up @@ -1083,11 +1162,20 @@ public function setWritingDir($val){
}
/**
* Sets the value of the attribute 'class' of the node.
* @param string $val The value to set.
* @param string $val The name of the class.
* @param boolean $override If this parameter is set to false and the node
* has a class already set, the given class name will be appended to the
* existing one. Default is true which means the attribute will be set as
* new.
* @since 1.2
*/
public function setClassName($val){
$this->setAttribute('class',$val);
public function setClassName($val,$override=true){
if($override === true){
$this->setAttribute('class',$val);
}
else{
$this->setAttribute('class', $this->getClassName().' '.$val);
}
}
/**
* Sets the value of the attribute 'name' of the node.
Expand Down Expand Up @@ -1185,11 +1273,45 @@ public function removeChild($node) {
}
return $this->null;
}
/**
* Insert new HTML element at specific position.
* @param HTMLNode $el The new element that will be inserted. It is possible
* to insert child elements to the element if the following conditions are
* met:
* <ul>
* <li>If the node is not a text node.</li>
* <li>The node is not a comment node.</li>
* <li>The note is not a void node.</li>
* <li>The note is not it self. (making a node as a child of it self)</li>
* </ul>
* @param int $position The position at which the element will be added.
* it must be a value between 0 and <code>HTMLNode::childrenCount()</code> inclusive.
* @return boolean If the element is inserted, the method will return true.
* Other than that, it will return false.
* @since 1.7.9
*/
public function insert($el,$position) {
$retVal = false;
if(!$this->isTextNode() && !$this->isComment() && $this->mustClose()){
if(($el instanceof HTMLNode) && $el !== $this){
$retVal = $this->childrenList->insert($el, $position);
if($retVal === true){
$el->_setParent($this);
}
}
}
return $retVal;
}
/**
* Adds new child node.
* @param HTMLNode $node The node that will be added. The node can have
* child nodes only if 3 conditions are met. If the node is not a text node
* , the node is not a comment node and the node must have ending tag.
* child nodes only if 4 conditions are met:
* <ul>
* <li>If the node is not a text node.</li>
* <li>The node is not a comment node.</li>
* <li>The note is not a void node.</li>
* <li>The note is not it self. (making a node as a child of it self)</li>
* </ul>
* @since 1.0
*/
public function addChild($node) {
Expand Down Expand Up @@ -1263,7 +1385,9 @@ public function setText($text,$escHtmlEntities=true) {
* Returns the value of the text that this node represents.
* @return string If the node is a text node or a comment node,
* the method will return the text in the body of the node. If not,
* the method will return empty string.
* the method will return empty string. Note that if the node represents
* a text node and HTML entities where escaped while setting its text, the
* returned value will have HTML entities escaped.
* @since 1.0
*/
public function getText() {
Expand All @@ -1273,8 +1397,9 @@ public function getText() {
return '';
}
/**
*
* @return type
* Returns the original text which was set in the body of the node.
* This only applies to text nodes and comment nodes.
* @return string The original text without any modifications.
*/
public function getOriginalText() {
return $this->originalText;
Expand Down
Loading

0 comments on commit 3fcf5a7

Please sign in to comment.