added spaces (coding convention)
Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
parent
951006dd10
commit
c2d8738285
11 changed files with 336 additions and 330 deletions
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
if(class_exists('BaseObject'))
|
if (class_exists('BaseObject')) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
require_once('boot.php');
|
require_once('boot.php');
|
||||||
|
|
||||||
|
@ -18,8 +19,9 @@ class BaseObject {
|
||||||
* Same as get_app from boot.php
|
* Same as get_app from boot.php
|
||||||
*/
|
*/
|
||||||
public function get_app() {
|
public function get_app() {
|
||||||
if(self::$app)
|
if (self::$app) {
|
||||||
return self::$app;
|
return self::$app;
|
||||||
|
}
|
||||||
|
|
||||||
self::$app = get_app();
|
self::$app = get_app();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
if(class_exists('Conversation'))
|
if (class_exists('Conversation')) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
require_once('boot.php');
|
require_once('boot.php');
|
||||||
require_once('object/BaseObject.php');
|
require_once('object/BaseObject.php');
|
||||||
|
@ -28,7 +29,7 @@ class Conversation extends BaseObject {
|
||||||
* Set the mode we'll be displayed on
|
* Set the mode we'll be displayed on
|
||||||
*/
|
*/
|
||||||
private function set_mode($mode) {
|
private function set_mode($mode) {
|
||||||
if($this->get_mode() == $mode)
|
if ($this->get_mode() == $mode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$a = $this->get_app();
|
$a = $this->get_app();
|
||||||
|
@ -92,11 +93,11 @@ class Conversation extends BaseObject {
|
||||||
*/
|
*/
|
||||||
public function add_thread($item) {
|
public function add_thread($item) {
|
||||||
$item_id = $item->get_id();
|
$item_id = $item->get_id();
|
||||||
if(!$item_id) {
|
if (!$item_id) {
|
||||||
logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG);
|
logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($this->get_thread($item->get_id())) {
|
if ($this->get_thread($item->get_id())) {
|
||||||
logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG);
|
logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -104,11 +105,11 @@ class Conversation extends BaseObject {
|
||||||
/*
|
/*
|
||||||
* Only add will be displayed
|
* Only add will be displayed
|
||||||
*/
|
*/
|
||||||
if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
|
if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
|
||||||
logger('[WARN] Conversation::add_thread : Thread is a mail ('. $item->get_id() .').', LOGGER_DEBUG);
|
logger('[WARN] Conversation::add_thread : Thread is a mail ('. $item->get_id() .').', LOGGER_DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($item->get_data_value('verb') === ACTIVITY_LIKE || $item->get_data_value('verb') === ACTIVITY_DISLIKE) {
|
if ($item->get_data_value('verb') === ACTIVITY_LIKE || $item->get_data_value('verb') === ACTIVITY_DISLIKE) {
|
||||||
logger('[WARN] Conversation::add_thread : Thread is a (dis)like ('. $item->get_id() .').', LOGGER_DEBUG);
|
logger('[WARN] Conversation::add_thread : Thread is a (dis)like ('. $item->get_id() .').', LOGGER_DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -132,13 +133,14 @@ class Conversation extends BaseObject {
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
foreach($this->threads as $item) {
|
foreach ($this->threads as $item) {
|
||||||
if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid'))
|
if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$item_data = $item->get_template_data($conv_responses);
|
$item_data = $item->get_template_data($conv_responses);
|
||||||
|
|
||||||
if(!$item_data) {
|
if (!$item_data) {
|
||||||
logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
|
logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -156,9 +158,10 @@ class Conversation extends BaseObject {
|
||||||
* _ false on failure
|
* _ false on failure
|
||||||
*/
|
*/
|
||||||
private function get_thread($id) {
|
private function get_thread($id) {
|
||||||
foreach($this->threads as $item) {
|
foreach ($this->threads as $item) {
|
||||||
if($item->get_id() == $id)
|
if ($item->get_id() == $id) {
|
||||||
return $item;
|
return $item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
if(class_exists('Item'))
|
if (class_exists('Item')) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
require_once('object/BaseObject.php');
|
require_once('object/BaseObject.php');
|
||||||
require_once('include/text.php');
|
require_once('include/text.php');
|
||||||
|
@ -181,19 +182,19 @@ class Item extends BaseObject {
|
||||||
$location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
|
$location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
|
||||||
|
|
||||||
$searchpath = "search?tag=";
|
$searchpath = "search?tag=";
|
||||||
$tags=array();
|
$tags = array();
|
||||||
$hashtags = array();
|
$hashtags = array();
|
||||||
$mentions = array();
|
$mentions = array();
|
||||||
|
|
||||||
|
|
||||||
/*foreach(explode(',',$item['tag']) as $tag){
|
/*foreach (explode(',',$item['tag']) as $tag){
|
||||||
$tag = trim($tag);
|
$tag = trim($tag);
|
||||||
if ($tag!="") {
|
if ($tag!="") {
|
||||||
$t = bbcode($tag);
|
$t = bbcode($tag);
|
||||||
$tags[] = $t;
|
$tags[] = $t;
|
||||||
if($t[0] == '#')
|
if ($t[0] == '#')
|
||||||
$hashtags[] = $t;
|
$hashtags[] = $t;
|
||||||
elseif($t[0] == '@')
|
elseif ($t[0] == '@')
|
||||||
$mentions[] = $t;
|
$mentions[] = $t;
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
@ -258,7 +259,7 @@ class Item extends BaseObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
$tagger = '';
|
$tagger = '';
|
||||||
if(feature_enabled($conv->get_profile_owner(),'commtag')) {
|
if (feature_enabled($conv->get_profile_owner(),'commtag')) {
|
||||||
$tagger = array(
|
$tagger = array(
|
||||||
'add' => t("add tag"),
|
'add' => t("add tag"),
|
||||||
'class' => "",
|
'class' => "",
|
||||||
|
@ -503,7 +504,7 @@ class Item extends BaseObject {
|
||||||
*/
|
*/
|
||||||
protected function set_parent($item) {
|
protected function set_parent($item) {
|
||||||
$parent = $this->get_parent();
|
$parent = $this->get_parent();
|
||||||
if($parent) {
|
if ($parent) {
|
||||||
$parent->remove_child($this);
|
$parent->remove_child($this);
|
||||||
}
|
}
|
||||||
$this->parent = $item;
|
$this->parent = $item;
|
||||||
|
@ -734,9 +735,9 @@ class Item extends BaseObject {
|
||||||
$conv = $this->get_conversation();
|
$conv = $this->get_conversation();
|
||||||
$this->wall_to_wall = false;
|
$this->wall_to_wall = false;
|
||||||
|
|
||||||
if($this->is_toplevel()) {
|
if ($this->is_toplevel()) {
|
||||||
if($conv->get_mode() !== 'profile') {
|
if ($conv->get_mode() !== 'profile') {
|
||||||
if($this->get_data_value('wall') AND !$this->get_data_value('self')) {
|
if ($this->get_data_value('wall') AND !$this->get_data_value('self')) {
|
||||||
// On the network page, I am the owner. On the display page it will be the profile owner.
|
// On the network page, I am the owner. On the display page it will be the profile owner.
|
||||||
// This will have been stored in $a->page_contact by our calling page.
|
// This will have been stored in $a->page_contact by our calling page.
|
||||||
// Put this person as the wall owner of the wall-to-wall notice.
|
// Put this person as the wall owner of the wall-to-wall notice.
|
||||||
|
@ -745,7 +746,7 @@ class Item extends BaseObject {
|
||||||
$this->owner_photo = $a->page_contact['thumb'];
|
$this->owner_photo = $a->page_contact['thumb'];
|
||||||
$this->owner_name = $a->page_contact['name'];
|
$this->owner_name = $a->page_contact['name'];
|
||||||
$this->wall_to_wall = true;
|
$this->wall_to_wall = true;
|
||||||
} elseif($this->get_data_value('owner-link')) {
|
} elseif ($this->get_data_value('owner-link')) {
|
||||||
|
|
||||||
$owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link')));
|
$owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link')));
|
||||||
$alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link')));
|
$alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link')));
|
||||||
|
|
|
@ -1,51 +1,51 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* this test tests the contains_attribute function
|
* this test tests the contains_attribute function
|
||||||
*
|
*
|
||||||
* @package test.util
|
* @package test.util
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** required, it is the file under test */
|
/** required, it is the file under test */
|
||||||
require_once('include/text.php');
|
require_once('include/text.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestCase for the contains_attribute function
|
* TestCase for the contains_attribute function
|
||||||
*
|
*
|
||||||
* @author Alexander Kampmann
|
* @author Alexander Kampmann
|
||||||
* @package test.util
|
* @package test.util
|
||||||
*/
|
*/
|
||||||
class ContainsAttributeTest extends PHPUnit_Framework_TestCase {
|
class ContainsAttributeTest extends PHPUnit_Framework_TestCase {
|
||||||
/**
|
/**
|
||||||
* test attribute contains
|
* test attribute contains
|
||||||
*/
|
*/
|
||||||
public function testAttributeContains1() {
|
public function testAttributeContains1() {
|
||||||
$testAttr="class1 notclass2 class3";
|
$testAttr="class1 notclass2 class3";
|
||||||
$this->assertTrue(attribute_contains($testAttr, "class3"));
|
$this->assertTrue(attribute_contains($testAttr, "class3"));
|
||||||
$this->assertFalse(attribute_contains($testAttr, "class2"));
|
$this->assertFalse(attribute_contains($testAttr, "class2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test attribute contains
|
* test attribute contains
|
||||||
*/
|
*/
|
||||||
public function testAttributeContains2() {
|
public function testAttributeContains2() {
|
||||||
$testAttr="class1 not-class2 class3";
|
$testAttr="class1 not-class2 class3";
|
||||||
$this->assertTrue(attribute_contains($testAttr, "class3"));
|
$this->assertTrue(attribute_contains($testAttr, "class3"));
|
||||||
$this->assertFalse(attribute_contains($testAttr, "class2"));
|
$this->assertFalse(attribute_contains($testAttr, "class2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test with empty input
|
* test with empty input
|
||||||
*/
|
*/
|
||||||
public function testAttributeContainsEmpty() {
|
public function testAttributeContainsEmpty() {
|
||||||
$testAttr="";
|
$testAttr="";
|
||||||
$this->assertFalse(attribute_contains($testAttr, "class2"));
|
$this->assertFalse(attribute_contains($testAttr, "class2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test input with special chars
|
* test input with special chars
|
||||||
*/
|
*/
|
||||||
public function testAttributeContainsSpecialChars() {
|
public function testAttributeContainsSpecialChars() {
|
||||||
$testAttr="--... %\$ä() /(=?}";
|
$testAttr="--... %\$ä() /(=?}";
|
||||||
$this->assertFalse(attribute_contains($testAttr, "class2"));
|
$this->assertFalse(attribute_contains($testAttr, "class2"));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,141 +8,141 @@
|
||||||
/** required, it is the file under test */
|
/** required, it is the file under test */
|
||||||
require_once('include/text.php');
|
require_once('include/text.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestCase for the expand_acl function
|
* TestCase for the expand_acl function
|
||||||
*
|
*
|
||||||
* @author Alexander Kampmann
|
* @author Alexander Kampmann
|
||||||
* @package test.util
|
* @package test.util
|
||||||
*/
|
*/
|
||||||
class ExpandAclTest extends PHPUnit_Framework_TestCase {
|
class ExpandAclTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test expand_acl, perfect input
|
* test expand_acl, perfect input
|
||||||
*/
|
*/
|
||||||
public function testExpandAclNormal() {
|
public function testExpandAclNormal() {
|
||||||
$text='<1><2><3>';
|
$text='<1><2><3>';
|
||||||
$this->assertEquals(array(1, 2, 3), expand_acl($text));
|
$this->assertEquals(array(1, 2, 3), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test with a big number
|
* test with a big number
|
||||||
*/
|
*/
|
||||||
public function testExpandAclBigNumber() {
|
public function testExpandAclBigNumber() {
|
||||||
$text='<1><'.PHP_INT_MAX.'><15>';
|
$text='<1><'.PHP_INT_MAX.'><15>';
|
||||||
$this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));
|
$this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test with a string in it.
|
* test with a string in it.
|
||||||
*
|
*
|
||||||
* TODO: is this valid input? Otherwise: should there be an exception?
|
* TODO: is this valid input? Otherwise: should there be an exception?
|
||||||
*/
|
*/
|
||||||
public function testExpandAclString() {
|
public function testExpandAclString() {
|
||||||
$text="<1><279012><tt>";
|
$text="<1><279012><tt>";
|
||||||
$this->assertEquals(array(1, 279012), expand_acl($text));
|
$this->assertEquals(array(1, 279012), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test with a ' ' in it.
|
* test with a ' ' in it.
|
||||||
*
|
*
|
||||||
* TODO: is this valid input? Otherwise: should there be an exception?
|
* TODO: is this valid input? Otherwise: should there be an exception?
|
||||||
*/
|
*/
|
||||||
public function testExpandAclSpace() {
|
public function testExpandAclSpace() {
|
||||||
$text="<1><279 012><32>";
|
$text="<1><279 012><32>";
|
||||||
$this->assertEquals(array(1, "279", "32"), expand_acl($text));
|
$this->assertEquals(array(1, "279", "32"), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test empty input
|
* test empty input
|
||||||
*/
|
*/
|
||||||
public function testExpandAclEmpty() {
|
public function testExpandAclEmpty() {
|
||||||
$text="";
|
$text="";
|
||||||
$this->assertEquals(array(), expand_acl($text));
|
$this->assertEquals(array(), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test invalid input, no < at all
|
* test invalid input, no < at all
|
||||||
*
|
*
|
||||||
* TODO: should there be an exception?
|
* TODO: should there be an exception?
|
||||||
*/
|
*/
|
||||||
public function testExpandAclNoBrackets() {
|
public function testExpandAclNoBrackets() {
|
||||||
$text="According to documentation, that's invalid. "; //should be invalid
|
$text="According to documentation, that's invalid. "; //should be invalid
|
||||||
$this->assertEquals(array(), expand_acl($text));
|
$this->assertEquals(array(), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test invalid input, just open <
|
* test invalid input, just open <
|
||||||
*
|
*
|
||||||
* TODO: should there be an exception?
|
* TODO: should there be an exception?
|
||||||
*/
|
*/
|
||||||
public function testExpandAclJustOneBracket1() {
|
public function testExpandAclJustOneBracket1() {
|
||||||
$text="<Another invalid string"; //should be invalid
|
$text="<Another invalid string"; //should be invalid
|
||||||
$this->assertEquals(array(), expand_acl($text));
|
$this->assertEquals(array(), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test invalid input, just close >
|
* test invalid input, just close >
|
||||||
*
|
*
|
||||||
* TODO: should there be an exception?
|
* TODO: should there be an exception?
|
||||||
*/
|
*/
|
||||||
public function testExpandAclJustOneBracket2() {
|
public function testExpandAclJustOneBracket2() {
|
||||||
$text="Another invalid> string"; //should be invalid
|
$text="Another invalid> string"; //should be invalid
|
||||||
$this->assertEquals(array(), expand_acl($text));
|
$this->assertEquals(array(), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test invalid input, just close >
|
* test invalid input, just close >
|
||||||
*
|
*
|
||||||
* TODO: should there be an exception?
|
* TODO: should there be an exception?
|
||||||
*/
|
*/
|
||||||
public function testExpandAclCloseOnly() {
|
public function testExpandAclCloseOnly() {
|
||||||
$text="Another> invalid> string>"; //should be invalid
|
$text="Another> invalid> string>"; //should be invalid
|
||||||
$this->assertEquals(array(), expand_acl($text));
|
$this->assertEquals(array(), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test invalid input, just open <
|
* test invalid input, just open <
|
||||||
*
|
*
|
||||||
* TODO: should there be an exception?
|
* TODO: should there be an exception?
|
||||||
*/
|
*/
|
||||||
public function testExpandAclOpenOnly() {
|
public function testExpandAclOpenOnly() {
|
||||||
$text="<Another< invalid string<"; //should be invalid
|
$text="<Another< invalid string<"; //should be invalid
|
||||||
$this->assertEquals(array(), expand_acl($text));
|
$this->assertEquals(array(), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test invalid input, open and close do not match
|
* test invalid input, open and close do not match
|
||||||
*
|
*
|
||||||
* TODO: should there be an exception?
|
* TODO: should there be an exception?
|
||||||
*/
|
*/
|
||||||
public function testExpandAclNoMatching1() {
|
public function testExpandAclNoMatching1() {
|
||||||
$text="<Another<> invalid <string>"; //should be invalid
|
$text="<Another<> invalid <string>"; //should be invalid
|
||||||
$this->assertEquals(array(), expand_acl($text));
|
$this->assertEquals(array(), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test invalid input, open and close do not match
|
* test invalid input, open and close do not match
|
||||||
*
|
*
|
||||||
* TODO: should there be an exception?
|
* TODO: should there be an exception?
|
||||||
*/
|
*/
|
||||||
public function testExpandAclNoMatching2() {
|
public function testExpandAclNoMatching2() {
|
||||||
$text="<1>2><3>";
|
$text="<1>2><3>";
|
||||||
// The angles are delimiters which aren't important
|
// The angles are delimiters which aren't important
|
||||||
// the important thing is the numeric content, this returns array(1,2,3) currently
|
// the important thing is the numeric content, this returns array(1,2,3) currently
|
||||||
// we may wish to eliminate 2 from the results, though it isn't harmful
|
// we may wish to eliminate 2 from the results, though it isn't harmful
|
||||||
// It would be a better test to figure out if there is any ACL input which can
|
// It would be a better test to figure out if there is any ACL input which can
|
||||||
// produce this $text and fix that instead.
|
// produce this $text and fix that instead.
|
||||||
// $this->assertEquals(array(), expand_acl($text));
|
// $this->assertEquals(array(), expand_acl($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test invalid input, empty <>
|
* test invalid input, empty <>
|
||||||
*
|
*
|
||||||
* TODO: should there be an exception? Or array(1, 3)
|
* TODO: should there be an exception? Or array(1, 3)
|
||||||
* (This should be array(1,3) - mike)
|
* (This should be array(1,3) - mike)
|
||||||
*/
|
*/
|
||||||
public function testExpandAclEmptyMatch() {
|
public function testExpandAclEmptyMatch() {
|
||||||
$text="<1><><3>";
|
$text="<1><><3>";
|
||||||
$this->assertEquals(array(1,3), expand_acl($text));
|
$this->assertEquals(array(1,3), expand_acl($text));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -44,23 +44,23 @@ function q($sql) {
|
||||||
$args=func_get_args();
|
$args=func_get_args();
|
||||||
|
|
||||||
//last parameter is always (in this test) uid, so, it should be 11
|
//last parameter is always (in this test) uid, so, it should be 11
|
||||||
if($args[count($args)-1]!=11) {
|
if ($args[count($args)-1]!=11) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(3==count($args)) {
|
if (3==count($args)) {
|
||||||
//first call in handle_body, id only
|
//first call in handle_body, id only
|
||||||
if($result[0]['id']==$args[1]) {
|
if ($result[0]['id']==$args[1]) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
//second call in handle_body, name
|
//second call in handle_body, name
|
||||||
if($result[0]['name']===$args[1]) {
|
if ($result[0]['name']===$args[1]) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//third call in handle_body, nick or attag
|
//third call in handle_body, nick or attag
|
||||||
if($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) {
|
if ($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$inform='';
|
$inform='';
|
||||||
$str_tags='';
|
$str_tags='';
|
||||||
foreach($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
|
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$inform='';
|
$inform='';
|
||||||
$str_tags='';
|
$str_tags='';
|
||||||
foreach($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
|
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$inform='';
|
$inform='';
|
||||||
$str_tags='';
|
$str_tags='';
|
||||||
foreach($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
|
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* this file contains tests for the template engine
|
* this file contains tests for the template engine
|
||||||
*
|
*
|
||||||
* @package test.util
|
* @package test.util
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** required, it is the file under test */
|
/** required, it is the file under test */
|
||||||
require_once('include/template_processor.php');
|
require_once('include/template_processor.php');
|
||||||
require_once('include/text.php');
|
require_once('include/text.php');
|
||||||
|
|
||||||
|
@ -13,30 +13,30 @@ class TemplateMockApp {
|
||||||
public $theme_info=array();
|
public $theme_info=array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!function_exists('current_theme')) {
|
if (!function_exists('current_theme')) {
|
||||||
function current_theme() {
|
function current_theme() {
|
||||||
return 'clean';
|
return 'clean';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!function_exists('x')) {
|
if (!function_exists('x')) {
|
||||||
function x($s,$k = NULL) {
|
function x($s,$k = NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!function_exists('get_app')) {
|
if (!function_exists('get_app')) {
|
||||||
function get_app() {
|
function get_app() {
|
||||||
return new TemplateMockApp();
|
return new TemplateMockApp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestCase for the template engine
|
* TestCase for the template engine
|
||||||
*
|
*
|
||||||
* @author Alexander Kampmann
|
* @author Alexander Kampmann
|
||||||
* @package test.util
|
* @package test.util
|
||||||
*/
|
*/
|
||||||
class TemplateTest extends PHPUnit_Framework_TestCase {
|
class TemplateTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
@ -58,167 +58,167 @@ class TemplateTest extends PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals('Hello Anna!', $text);
|
$this->assertEquals('Hello Anna!', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleVariableInt() {
|
public function testSimpleVariableInt() {
|
||||||
$tpl='There are $num new messages!';
|
$tpl='There are $num new messages!';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$num'=>172));
|
$text=replace_macros($tpl, array('$num'=>172));
|
||||||
|
|
||||||
$this->assertEquals('There are 172 new messages!', $text);
|
$this->assertEquals('There are 172 new messages!', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConditionalElse() {
|
public function testConditionalElse() {
|
||||||
$tpl='There{{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
|
$tpl='There{{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
|
||||||
|
|
||||||
$text1=replace_macros($tpl, array('$num'=>1));
|
$text1=replace_macros($tpl, array('$num'=>1));
|
||||||
$text22=replace_macros($tpl, array('$num'=>22));
|
$text22=replace_macros($tpl, array('$num'=>22));
|
||||||
|
|
||||||
$this->assertEquals('There is 1 new message!', $text1);
|
$this->assertEquals('There is 1 new message!', $text1);
|
||||||
$this->assertEquals('There are 22 new messages!', $text22);
|
$this->assertEquals('There are 22 new messages!', $text22);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConditionalNoElse() {
|
public function testConditionalNoElse() {
|
||||||
$tpl='{{ if $num!=0 }}There are $num new messages!{{ endif }}';
|
$tpl='{{ if $num!=0 }}There are $num new messages!{{ endif }}';
|
||||||
|
|
||||||
$text0=replace_macros($tpl, array('$num'=>0));
|
$text0=replace_macros($tpl, array('$num'=>0));
|
||||||
$text22=replace_macros($tpl, array('$num'=>22));
|
$text22=replace_macros($tpl, array('$num'=>22));
|
||||||
|
|
||||||
$this->assertEquals('', $text0);
|
$this->assertEquals('', $text0);
|
||||||
$this->assertEquals('There are 22 new messages!', $text22);
|
$this->assertEquals('There are 22 new messages!', $text22);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConditionalFail() {
|
public function testConditionalFail() {
|
||||||
$tpl='There {{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
|
$tpl='There {{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
|
||||||
|
|
||||||
$text1=replace_macros($tpl, array());
|
$text1=replace_macros($tpl, array());
|
||||||
|
|
||||||
//$this->assertEquals('There is 1 new message!', $text1);
|
//$this->assertEquals('There is 1 new message!', $text1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleFor() {
|
public function testSimpleFor() {
|
||||||
$tpl='{{ for $messages as $message }} $message {{ endfor }}';
|
$tpl='{{ for $messages as $message }} $message {{ endfor }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$messages'=>array('message 1', 'message 2')));
|
$text=replace_macros($tpl, array('$messages'=>array('message 1', 'message 2')));
|
||||||
|
|
||||||
$this->assertEquals(' message 1 message 2 ', $text);
|
$this->assertEquals(' message 1 message 2 ', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFor() {
|
public function testFor() {
|
||||||
$tpl='{{ for $messages as $message }} from: $message.from to $message.to {{ endfor }}';
|
$tpl='{{ for $messages as $message }} from: $message.from to $message.to {{ endfor }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$messages'=>array(array('from'=>'Mike', 'to'=>'Alex'), array('from'=>'Alex', 'to'=>'Mike'))));
|
$text=replace_macros($tpl, array('$messages'=>array(array('from'=>'Mike', 'to'=>'Alex'), array('from'=>'Alex', 'to'=>'Mike'))));
|
||||||
|
|
||||||
$this->assertEquals(' from: Mike to Alex from: Alex to Mike ', $text);
|
$this->assertEquals(' from: Mike to Alex from: Alex to Mike ', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testKeyedFor() {
|
public function testKeyedFor() {
|
||||||
$tpl='{{ for $messages as $from=>$to }} from: $from to $to {{ endfor }}';
|
$tpl='{{ for $messages as $from=>$to }} from: $from to $to {{ endfor }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$messages'=>array('Mike'=>'Alex', 'Sven'=>'Mike')));
|
$text=replace_macros($tpl, array('$messages'=>array('Mike'=>'Alex', 'Sven'=>'Mike')));
|
||||||
|
|
||||||
$this->assertEquals(' from: Mike to Alex from: Sven to Mike ', $text);
|
$this->assertEquals(' from: Mike to Alex from: Sven to Mike ', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForEmpty() {
|
public function testForEmpty() {
|
||||||
$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}';
|
$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$messages'=>array()));
|
$text=replace_macros($tpl, array('$messages'=>array()));
|
||||||
|
|
||||||
$this->assertEquals('messages: ', $text);
|
$this->assertEquals('messages: ', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForWrongType() {
|
public function testForWrongType() {
|
||||||
$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}';
|
$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$messages'=>11));
|
$text=replace_macros($tpl, array('$messages'=>11));
|
||||||
|
|
||||||
$this->assertEquals('messages: ', $text);
|
$this->assertEquals('messages: ', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForConditional() {
|
public function testForConditional() {
|
||||||
$tpl='new messages: {{for $messages as $message}}{{ if $message.new }} $message.text{{endif}}{{ endfor }}';
|
$tpl='new messages: {{for $messages as $message}}{{ if $message.new }} $message.text{{endif}}{{ endfor }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$messages'=>array(
|
$text=replace_macros($tpl, array('$messages'=>array(
|
||||||
array('new'=>true, 'text'=>'new message'),
|
array('new'=>true, 'text'=>'new message'),
|
||||||
array('new'=>false, 'text'=>'old message'))));
|
array('new'=>false, 'text'=>'old message'))));
|
||||||
|
|
||||||
$this->assertEquals('new messages: new message', $text);
|
$this->assertEquals('new messages: new message', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConditionalFor() {
|
public function testConditionalFor() {
|
||||||
$tpl='{{ if $enabled }}new messages:{{for $messages as $message}} $message.text{{ endfor }}{{endif}}';
|
$tpl='{{ if $enabled }}new messages:{{for $messages as $message}} $message.text{{ endfor }}{{endif}}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$enabled'=>true,
|
$text=replace_macros($tpl, array('$enabled'=>true,
|
||||||
'$messages'=>array(
|
'$messages'=>array(
|
||||||
array('new'=>true, 'text'=>'new message'),
|
array('new'=>true, 'text'=>'new message'),
|
||||||
array('new'=>false, 'text'=>'old message'))));
|
array('new'=>false, 'text'=>'old message'))));
|
||||||
|
|
||||||
$this->assertEquals('new messages: new message old message', $text);
|
$this->assertEquals('new messages: new message old message', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFantasy() {
|
public function testFantasy() {
|
||||||
$tpl='Fantasy: {{fantasy $messages}}';
|
$tpl='Fantasy: {{fantasy $messages}}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$messages'=>'no no'));
|
$text=replace_macros($tpl, array('$messages'=>'no no'));
|
||||||
|
|
||||||
$this->assertEquals('Fantasy: {{fantasy no no}}', $text);
|
$this->assertEquals('Fantasy: {{fantasy no no}}', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInc() {
|
public function testInc() {
|
||||||
$tpl='{{inc field_input.tpl with $field=$myvar}}{{ endinc }}';
|
$tpl='{{inc field_input.tpl with $field=$myvar}}{{ endinc }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$myvar'=>array('myfield', 'label', 'value', 'help')));
|
$text=replace_macros($tpl, array('$myvar'=>array('myfield', 'label', 'value', 'help')));
|
||||||
|
|
||||||
$this->assertEquals(" \n"
|
$this->assertEquals(" \n"
|
||||||
." <div class='field input'>\n"
|
." <div class='field input'>\n"
|
||||||
." <label for='id_myfield'>label</label>\n"
|
." <label for='id_myfield'>label</label>\n"
|
||||||
." <input name='myfield' id='id_myfield' value=\"value\">\n"
|
." <input name='myfield' id='id_myfield' value=\"value\">\n"
|
||||||
." <span class='field_help'>help</span>\n"
|
." <span class='field_help'>help</span>\n"
|
||||||
." </div>\n", $text);
|
." </div>\n", $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIncNoVar() {
|
public function testIncNoVar() {
|
||||||
$tpl='{{inc field_input.tpl }}{{ endinc }}';
|
$tpl='{{inc field_input.tpl }}{{ endinc }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$field'=>array('myfield', 'label', 'value', 'help')));
|
$text=replace_macros($tpl, array('$field'=>array('myfield', 'label', 'value', 'help')));
|
||||||
|
|
||||||
$this->assertEquals(" \n <div class='field input'>\n <label for='id_myfield'>label</label>\n"
|
$this->assertEquals(" \n <div class='field input'>\n <label for='id_myfield'>label</label>\n"
|
||||||
." <input name='myfield' id='id_myfield' value=\"value\">\n"
|
." <input name='myfield' id='id_myfield' value=\"value\">\n"
|
||||||
." <span class='field_help'>help</span>\n"
|
." <span class='field_help'>help</span>\n"
|
||||||
." </div>\n", $text);
|
." </div>\n", $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDoubleUse() {
|
public function testDoubleUse() {
|
||||||
$tpl='Hello $name! {{ if $enabled }} I love you! {{ endif }}';
|
$tpl='Hello $name! {{ if $enabled }} I love you! {{ endif }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$name'=>'Anna', '$enabled'=>false));
|
$text=replace_macros($tpl, array('$name'=>'Anna', '$enabled'=>false));
|
||||||
|
|
||||||
$this->assertEquals('Hello Anna! ', $text);
|
$this->assertEquals('Hello Anna! ', $text);
|
||||||
|
|
||||||
$tpl='Hey $name! {{ if $enabled }} I hate you! {{ endif }}';
|
$tpl='Hey $name! {{ if $enabled }} I hate you! {{ endif }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$name'=>'Max', '$enabled'=>true));
|
$text=replace_macros($tpl, array('$name'=>'Max', '$enabled'=>true));
|
||||||
|
|
||||||
$this->assertEquals('Hey Max! I hate you! ', $text);
|
$this->assertEquals('Hey Max! I hate you! ', $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIncDouble() {
|
public function testIncDouble() {
|
||||||
$tpl='{{inc field_input.tpl with $field=$var1}}{{ endinc }}'
|
$tpl='{{inc field_input.tpl with $field=$var1}}{{ endinc }}'
|
||||||
.'{{inc field_input.tpl with $field=$var2}}{{ endinc }}';
|
.'{{inc field_input.tpl with $field=$var2}}{{ endinc }}';
|
||||||
|
|
||||||
$text=replace_macros($tpl, array('$var1'=>array('myfield', 'label', 'value', 'help'),
|
$text=replace_macros($tpl, array('$var1'=>array('myfield', 'label', 'value', 'help'),
|
||||||
'$var2'=>array('myfield2', 'label2', 'value2', 'help2')));
|
'$var2'=>array('myfield2', 'label2', 'value2', 'help2')));
|
||||||
|
|
||||||
$this->assertEquals(" \n"
|
$this->assertEquals(" \n"
|
||||||
." <div class='field input'>\n"
|
." <div class='field input'>\n"
|
||||||
." <label for='id_myfield'>label</label>\n"
|
." <label for='id_myfield'>label</label>\n"
|
||||||
." <input name='myfield' id='id_myfield' value=\"value\">\n"
|
." <input name='myfield' id='id_myfield' value=\"value\">\n"
|
||||||
." <span class='field_help'>help</span>\n"
|
." <span class='field_help'>help</span>\n"
|
||||||
." </div>\n"
|
." </div>\n"
|
||||||
." \n"
|
." \n"
|
||||||
." <div class='field input'>\n"
|
." <div class='field input'>\n"
|
||||||
." <label for='id_myfield2'>label2</label>\n"
|
." <label for='id_myfield2'>label2</label>\n"
|
||||||
." <input name='myfield2' id='id_myfield2' value=\"value2\">\n"
|
." <input name='myfield2' id='id_myfield2' value=\"value2\">\n"
|
||||||
." <span class='field_help'>help2</span>\n"
|
." <span class='field_help'>help2</span>\n"
|
||||||
." </div>\n", $text);
|
." </div>\n", $text);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -33,13 +33,13 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals($text, $retext);
|
$this->assertEquals($text, $retext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlify and put in a document
|
* xmlify and put in a document
|
||||||
*/
|
*/
|
||||||
public function testXmlifyDocument() {
|
public function testXmlifyDocument() {
|
||||||
$tag="<tag>I want to break</tag>";
|
$tag="<tag>I want to break</tag>";
|
||||||
$xml=xmlify($tag);
|
$xml=xmlify($tag);
|
||||||
$text='<text>'.$xml.'</text>';
|
$text='<text>'.$xml.'</text>';
|
||||||
|
|
||||||
$xml_parser=xml_parser_create();
|
$xml_parser=xml_parser_create();
|
||||||
//should be possible to parse it
|
//should be possible to parse it
|
||||||
|
@ -48,10 +48,10 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$this->assertEquals(array('TEXT'=>array(0)),
|
$this->assertEquals(array('TEXT'=>array(0)),
|
||||||
$index);
|
$index);
|
||||||
$this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)),
|
$this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)),
|
||||||
$values);
|
$values);
|
||||||
|
|
||||||
xml_parser_free($xml_parser);
|
xml_parser_free($xml_parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,9 +33,9 @@ class Color {
|
||||||
$color = str_replace("#", "", $hex);
|
$color = str_replace("#", "", $hex);
|
||||||
|
|
||||||
// Make sure it's 6 digits
|
// Make sure it's 6 digits
|
||||||
if( strlen($color) === 3 ) {
|
if ( strlen($color) === 3 ) {
|
||||||
$color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
|
$color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
|
||||||
} else if( strlen($color) != 6 ) {
|
} else if ( strlen($color) != 6 ) {
|
||||||
throw new Exception("HEX color needs to be 6 or 3 digits long");
|
throw new Exception("HEX color needs to be 6 or 3 digits long");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,19 +112,19 @@ class Color {
|
||||||
*/
|
*/
|
||||||
public static function hslToHex( $hsl = array() ){
|
public static function hslToHex( $hsl = array() ){
|
||||||
// Make sure it's HSL
|
// Make sure it's HSL
|
||||||
if(empty($hsl) || !isset($hsl["H"]) || !isset($hsl["S"]) || !isset($hsl["L"]) ) {
|
if (empty($hsl) || !isset($hsl["H"]) || !isset($hsl["S"]) || !isset($hsl["L"]) ) {
|
||||||
throw new Exception("Param was not an HSL array");
|
throw new Exception("Param was not an HSL array");
|
||||||
}
|
}
|
||||||
|
|
||||||
list($H,$S,$L) = array( $hsl['H']/360,$hsl['S'],$hsl['L'] );
|
list($H,$S,$L) = array( $hsl['H']/360,$hsl['S'],$hsl['L'] );
|
||||||
|
|
||||||
if( $S == 0 ) {
|
if ( $S == 0 ) {
|
||||||
$r = $L * 255;
|
$r = $L * 255;
|
||||||
$g = $L * 255;
|
$g = $L * 255;
|
||||||
$b = $L * 255;
|
$b = $L * 255;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if($L<0.5) {
|
if ($L<0.5) {
|
||||||
$var_2 = $L*(1+$S);
|
$var_2 = $L*(1+$S);
|
||||||
} else {
|
} else {
|
||||||
$var_2 = ($L+$S) - ($S*$L);
|
$var_2 = ($L+$S) - ($S*$L);
|
||||||
|
@ -183,7 +183,7 @@ class Color {
|
||||||
*/
|
*/
|
||||||
public static function rgbToHex( $rgb = array() ){
|
public static function rgbToHex( $rgb = array() ){
|
||||||
// Make sure it's RGB
|
// Make sure it's RGB
|
||||||
if(empty($rgb) || !isset($rgb["R"]) || !isset($rgb["G"]) || !isset($rgb["B"]) ) {
|
if (empty($rgb) || !isset($rgb["R"]) || !isset($rgb["G"]) || !isset($rgb["B"]) ) {
|
||||||
throw new Exception("Param was not an RGB array");
|
throw new Exception("Param was not an RGB array");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ class Color {
|
||||||
*/
|
*/
|
||||||
public function makeGradient( $amount = self::DEFAULT_ADJUST ) {
|
public function makeGradient( $amount = self::DEFAULT_ADJUST ) {
|
||||||
// Decide which color needs to be made
|
// Decide which color needs to be made
|
||||||
if( $this->isLight() ) {
|
if ( $this->isLight() ) {
|
||||||
$lightColor = $this->_hex;
|
$lightColor = $this->_hex;
|
||||||
$darkColor = $this->darken($amount);
|
$darkColor = $this->darken($amount);
|
||||||
} else {
|
} else {
|
||||||
|
@ -387,7 +387,7 @@ class Color {
|
||||||
*/
|
*/
|
||||||
private function _darken( $hsl, $amount = self::DEFAULT_ADJUST){
|
private function _darken( $hsl, $amount = self::DEFAULT_ADJUST){
|
||||||
// Check if we were provided a number
|
// Check if we were provided a number
|
||||||
if( $amount ) {
|
if ( $amount ) {
|
||||||
$hsl['L'] = ($hsl['L'] * 100) - $amount;
|
$hsl['L'] = ($hsl['L'] * 100) - $amount;
|
||||||
$hsl['L'] = ($hsl['L'] < 0) ? 0:$hsl['L']/100;
|
$hsl['L'] = ($hsl['L'] < 0) ? 0:$hsl['L']/100;
|
||||||
} else {
|
} else {
|
||||||
|
@ -406,7 +406,7 @@ class Color {
|
||||||
*/
|
*/
|
||||||
private function _lighten( $hsl, $amount = self::DEFAULT_ADJUST){
|
private function _lighten( $hsl, $amount = self::DEFAULT_ADJUST){
|
||||||
// Check if we were provided a number
|
// Check if we were provided a number
|
||||||
if( $amount ) {
|
if ( $amount ) {
|
||||||
$hsl['L'] = ($hsl['L'] * 100) + $amount;
|
$hsl['L'] = ($hsl['L'] * 100) + $amount;
|
||||||
$hsl['L'] = ($hsl['L'] > 100) ? 1:$hsl['L']/100;
|
$hsl['L'] = ($hsl['L'] > 100) ? 1:$hsl['L']/100;
|
||||||
} else {
|
} else {
|
||||||
|
@ -446,23 +446,23 @@ class Color {
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
private static function _huetorgb( $v1,$v2,$vH ) {
|
private static function _huetorgb( $v1,$v2,$vH ) {
|
||||||
if( $vH < 0 ) {
|
if ( $vH < 0 ) {
|
||||||
$vH += 1;
|
$vH += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $vH > 1 ) {
|
if ( $vH > 1 ) {
|
||||||
$vH -= 1;
|
$vH -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (6*$vH) < 1 ) {
|
if ( (6*$vH) < 1 ) {
|
||||||
return ($v1 + ($v2 - $v1) * 6 * $vH);
|
return ($v1 + ($v2 - $v1) * 6 * $vH);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (2*$vH) < 1 ) {
|
if ( (2*$vH) < 1 ) {
|
||||||
return $v2;
|
return $v2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (3*$vH) < 2 ) {
|
if ( (3*$vH) < 2 ) {
|
||||||
return ($v1 + ($v2-$v1) * ( (2/3)-$vH ) * 6);
|
return ($v1 + ($v2-$v1) * ( (2/3)-$vH ) * 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,9 +481,9 @@ class Color {
|
||||||
$color = str_replace("#", "", $hex);
|
$color = str_replace("#", "", $hex);
|
||||||
|
|
||||||
// Make sure it's 6 digits
|
// Make sure it's 6 digits
|
||||||
if( strlen($color) == 3 ) {
|
if ( strlen($color) == 3 ) {
|
||||||
$color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
|
$color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
|
||||||
} else if( strlen($color) != 6 ) {
|
} else if ( strlen($color) != 6 ) {
|
||||||
throw new Exception("HEX color needs to be 6 or 3 digits long");
|
throw new Exception("HEX color needs to be 6 or 3 digits long");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,12 +78,12 @@ function frio_item_photo_links(App $a, &$body_info) {
|
||||||
$occurence = 1;
|
$occurence = 1;
|
||||||
$p = bb_find_open_close($body_info['html'], "<a", ">");
|
$p = bb_find_open_close($body_info['html'], "<a", ">");
|
||||||
|
|
||||||
while($p !== false && ($occurence++ < 500)) {
|
while ($p !== false && ($occurence++ < 500)) {
|
||||||
$link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
|
$link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
|
||||||
$matches = array();
|
$matches = array();
|
||||||
|
|
||||||
preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
|
preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
|
||||||
if($matches) {
|
if ($matches) {
|
||||||
// Replace the link for the photo's page with a direct link to the photo itself
|
// Replace the link for the photo's page with a direct link to the photo itself
|
||||||
$newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
|
$newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,12 @@ function frost_item_photo_links(App $a, &$body_info) {
|
||||||
|
|
||||||
$occurence = 1;
|
$occurence = 1;
|
||||||
$p = bb_find_open_close($body_info['html'], "<a", ">");
|
$p = bb_find_open_close($body_info['html'], "<a", ">");
|
||||||
while($p !== false && ($occurence++ < 500)) {
|
while ($p !== false && ($occurence++ < 500)) {
|
||||||
$link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
|
$link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
|
||||||
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
|
preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
|
||||||
if($matches) {
|
if ($matches) {
|
||||||
|
|
||||||
// Replace the link for the photo's page with a direct link to the photo itself
|
// Replace the link for the photo's page with a direct link to the photo itself
|
||||||
$newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
|
$newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
|
||||||
|
|
Loading…
Reference in a new issue