<?php
class Note
{
private $id;
private $note;
private $rawNote;
private $tags;
private $date;
private $innerHTML;
public function getId ()
{
return $this->id;
}
public function getNote ()
{
return $this->note;
}
public function getRawNote ()
{
return $this->rawNote;
}
public function getTags ()
{
return $this->tags;
}
public function getDate ()
{
return $this->date;
}
public function getInnerHTML ()
{
return $this->innerHTML;
}
function __construct ($id = NULL, $note = NULL, $rawNote, $tags = NULL, $date = NULL)
{
$this->id = $id;
$this->note = $note;
$this->rawNote = $rawNote;
$this->tags = $tags;
$this->date = date ("d/m/Y H:i:s", $date);
$this->createHTML ();
}
function getJSON ()
{
$jsonResponse = new JSONResponse ();
$jsonResponse->addValue("id", $this->id);
$jsonResponse->addValue("note", $this->note);
$jsonResponse->addValue("rawNote", $this->rawNote);
$jsonResponse->addValue("tags", $this->tags);
$jsonResponse->addValue("date", $this->date);
$jsonResponse->addValue("innerHTML", $this->innerHTML);
return $jsonResponse->createJSONString();
}
// Formats a string as a hyperlink
private function hyperlink($text)
{
//"www."
$pattern_preg1 = '#(^|\s)(www|WWW)\.([^\s<>\.]+)\.([^\s\n<>]+)#sm';
$replace_preg1 = '\\1<a href="http://\\2.\\3.\\4" target="_blank" class="link">\\2.\\3.\\4</a>';
//"http://"
$pattern_preg2 = '#(^|[^\"=\]]{1})(http|HTTP|ftp)(s|S)?://([^\s<>\.]+)\.([^\s<>]+)#sm';
$replace_preg2 = '\\1<a href="\\2\\3://\\4.\\5" target="_blank" class="link">\\2\\3://\\4.\\5</a>';
$text = preg_replace($pattern_preg1, $replace_preg1, $text);
$text = preg_replace($pattern_preg2, $replace_preg2, $text);
return $text;
}
// Formats an escpaped string with bold tags and formats string as hyperlink
private function formatNote ($note)
{
$note = preg_replace ("/([^\&]*)\<\;b\>\;([^&]*)\<\;\/b\>\;/", "\\1<b>\\2</b>", $note);
$note = $this->hyperlink ($note);
return $note;
}
public function createHTML ($keywords = NULL)
{
$this->note = $this->rawNote;
$this->innerHTML = "";
$this->innerHTML .= "\n<div class=\"note-title\">";
$this->innerHTML .= $this->date;
$this->innerHTML .= "\n <a href=\"javascript:ShowMessageWindow(" . $this->id . ");\">delete</a>";
$this->innerHTML .= "\n <a id=\"EditLink-" . $this->id . "\" href=\"javascript:EnterEdit(" . $this->id . ");\">edit</a>";
$this->innerHTML .= "\n <span id=\"TagsLabel-" . $this->id . "\">Tags:<b> " . $this->tags . "</b></span>";
$this->innerHTML .= "\n<span style=\"position: relative; width: 500px; display: none\" id=\"Tags-" . $this->id . "\">Tags: <input class=\"note-input\" style=\"padding: 0px; width: 300px;\" id=\"EditTags-" . $this->id . "\" type=\"text\" name=\"tags\" value=\"" . $this->tags . "\"></span>";
$this->innerHTML .= "\n</div>";
$this->innerHTML .= "\n<div id=\"Text-" . $this->id . "\" onDblClick=\"EnterEdit(" . $this->id . ");\" class=\"note-text\">";
//$this->note = htmlentities($this->note, ENT_QUOTES, "UTF-8");
if ($keywords)
{
$searchString = str_replace (" ", "|", $keywords);
$this->note = eregi_replace($searchString, "<span style=\"color: #FF0000;\">\\0</span>", $this->note);
}
// allow bold-tag and replace urls with links
//$this->note = $this->formatNote ($this->note);
//$rawNote is the unformated text for displaying in textarea
//$this->note = str_replace ("\n", "<br>", $this->note);
$this->innerHTML .= $this->note . "</div>";
$this->innerHTML .= "<div id=\"noteContainer-" . $this->id . "\" style=\"display: none; width: 900px;\">";
$this->innerHTML .= "<textarea cols=\"109\" rows=\"3\" name=\"Note\" id=\"EditBox-" . $this->id . "\" onKeyUp=\"ResizeTextBox(" . $this->id . ");\" class=\"note-input\">" . $this->rawNote . "</textarea>";
$this->innerHTML .= "<button type=\"button\" onClick=\"CancelEdit(" . $this->id . ");\" id=\"CancelButton-" . $this->id . "\" class=\"ButtonLeft\">Cancel</button>";
$this->innerHTML .= "<button type=\"button\" onClick=\"editText()\" id=\"OkButton-" . $this->id . "\" class=\"ButtonRight\">Save</button>";
$this->innerHTML .= "</div>";
//$this->innerHTML .= "<input type=\"hidden\" name=\"Edit\" value=\"1\"> ";
//$this->innerHTML .= "<input type=\"hidden\" name=\"Id\" value=\"" . $this->id . "\"> ";
$this->innerHTML .= "<br>";
}
function getHTML ()
{
return $this->innerHTML;
}
}
?>