class TagadelicTag in Tagadelic 7.2
class TagadelicTag TagadelicTag contains the tag itself.
Hierarchy
- class \TagadelicTag
Expanded class hierarchy of TagadelicTag
3 string references to 'TagadelicTag'
- TagadelicCloudTest::addTagStub in tests/
TagadelicCloudTest.php - Creates a stub for a tag
- TagadelicCloudTest::testGetCalculatedWeights in tests/
TagadelicCloudTest.php - Get Tags should calculate the weights
- TagadelicTestCase::testAutoloader in tests/
tagadelic.test - testAutoloader Tests if classes are autoloaded. @covers TagadelicCloud, TagadelicTag, TagaDelicDrupalWrapper. @scope public
File
- ./
TagadelicTag.php, line 6
View source
class TagadelicTag {
private $id = 0;
# Identifier of this tag
private $name = "";
# A human readable name for this tag.
private $description = "";
# A human readable piece of HTML-formatted text.
private $link = "";
# Where this tag will point to. If left empty, tag will not be linked. Can be a full url too.
private $count = 1.0E-7;
# Absolute count for the weight. Weight, i.e. tag-size will be extracted from this.
private $dirty = true;
private $weight = 0.0;
private $drupal = NULL;
# Contains the DrupalWrapper, mostly for testablity
/**
* Initalize this tag
* @param id Integer the identifier of this tag
* @param name String a human readable name describing this tag
*/
function __construct($id, $name, $count) {
$this->id = $id;
$this->name = $name;
if ($count != 0) {
$this->count = $count;
}
}
/**
* Magic method to render the Tag.
* turns the tag into an HTML link to its source.
*/
public function __ToString() {
$this
->clean();
$attributes = $options = array();
if (!empty($this->description)) {
$attributes["title"] = $this->description;
}
if ($this->weight > 0) {
$attributes["class"][] = "level{$this->weight}";
}
if (!empty($attributes)) {
$options["attributes"] = $attributes;
}
return $this
->drupal()
->l($this->name, $this->link, $options);
}
/**
* Getter for the ID
* @ingroup getters
* return Integer Identifier
**/
public function get_id() {
return $this->id;
}
/**
* Getter for the name
* @ingroup getters
* return String the human readable name
**/
public function get_name() {
$this
->clean();
return $this->name;
}
/**
* Getter for the description
* @ingroup getters
* return String the human readable description
**/
public function get_description() {
$this
->clean();
return $this->description;
}
/**
* Returns the weight, getter only.
* Will call recalculate to calculate the weight.
* @ingroup getters
* return Float the weight of this tag.
**/
public function get_weight() {
return $this->weight;
}
/**
* Returns the count, getter only.
* @ingroup getters
* return Int the count as provided when Initializing the Object.
**/
public function get_count() {
return $this->count;
}
/**
* Sets the optional description.
* A tag may have a description
* @param $description String a description
*/
public function set_description($description) {
$this->description = $description;
}
/**
* Link to a resource.
* @param link String Optional a link to a resource that represents
* the tag. e.g. a listing with all things tagged with Tag, or
* the article that represents the tag.
*/
public function set_link($link) {
$this->link = $link;
}
/**
* setter for weight
* Operates on $this
* Returns $this
*/
public function set_weight($weight) {
$this->weight = $weight;
return $this;
}
/**
* setter for drupal(Wrapper)
* Operates on $this
* Returns $this
*/
public function set_drupal($drupal) {
$this->drupal = $drupal;
return $this;
}
/**
* Getter for drupal, if not found, will instantiate a default TagaDelicDrupalWrapper
* @return type value in $this::$drupal.
*/
public function drupal() {
if (empty($this->drupal)) {
$this->drupal = new TagaDelicDrupalWrapper();
}
return $this->drupal;
}
/**
* Flag $name and $description as dirty; none-cleaned.
* BEWARE! This will probably lead to double escaping, unless you know what you are doing.
*/
public function force_dirty() {
$this->dirty = true;
}
/**
* Flag $name and $description as safe.
* XSS-escaping and sanitizing is left to implementer.
* BEWARE! Only enforce when you know what you are doing. Seriously!
*/
public function force_clean() {
$this->dirty = false;
}
/**
* Calculates a more evenly distributed value.
*/
public function distributed() {
return log($this->count);
}
/**
* Utility, to enforce XSS filtering on strings before they are
* printed or returned.
**/
private function clean() {
if ($this->dirty) {
$this->name = $this
->drupal()
->check_plain($this->name);
$this->description = $this
->drupal()
->check_plain($this->description);
$this
->force_clean();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TagadelicTag:: |
private | property | ||
TagadelicTag:: |
private | property | ||
TagadelicTag:: |
private | property | ||
TagadelicTag:: |
private | property | ||
TagadelicTag:: |
private | property | ||
TagadelicTag:: |
private | property | ||
TagadelicTag:: |
private | property | ||
TagadelicTag:: |
private | property | ||
TagadelicTag:: |
private | function | Utility, to enforce XSS filtering on strings before they are printed or returned. | |
TagadelicTag:: |
public | function | Calculates a more evenly distributed value. | |
TagadelicTag:: |
public | function | Getter for drupal, if not found, will instantiate a default TagaDelicDrupalWrapper | |
TagadelicTag:: |
public | function | Flag $name and $description as safe. XSS-escaping and sanitizing is left to implementer. BEWARE! Only enforce when you know what you are doing. Seriously! | |
TagadelicTag:: |
public | function | Flag $name and $description as dirty; none-cleaned. BEWARE! This will probably lead to double escaping, unless you know what you are doing. | |
TagadelicTag:: |
public | function | Returns the count, getter only. return Int the count as provided when Initializing the Object. | |
TagadelicTag:: |
public | function | Getter for the description return String the human readable description | |
TagadelicTag:: |
public | function | Getter for the ID return Integer Identifier | |
TagadelicTag:: |
public | function | Getter for the name return String the human readable name | |
TagadelicTag:: |
public | function | Returns the weight, getter only. Will call recalculate to calculate the weight. return Float the weight of this tag. | |
TagadelicTag:: |
public | function | Sets the optional description. A tag may have a description | |
TagadelicTag:: |
public | function | setter for drupal(Wrapper) Operates on $this Returns $this | |
TagadelicTag:: |
public | function | Link to a resource. | |
TagadelicTag:: |
public | function | setter for weight Operates on $this Returns $this | |
TagadelicTag:: |
function | Initalize this tag | ||
TagadelicTag:: |
public | function | Magic method to render the Tag. turns the tag into an HTML link to its source. |