diff options
Diffstat (limited to 'utils/modules/news.php')
| -rw-r--r-- | utils/modules/news.php | 49 | 
1 files changed, 39 insertions, 10 deletions
diff --git a/utils/modules/news.php b/utils/modules/news.php index 032c342..b59b7fd 100644 --- a/utils/modules/news.php +++ b/utils/modules/news.php @@ -17,9 +17,9 @@ class NewsEntry {  	public $userid;  	public $icon; -  public function show() +  public function show($newspage)    { -		global $users, $DATA_DIR, $ICONS_DIR, $NEWS_PAGE; +		global $users, $DATA_DIR, $ICONS_DIR;  		if(!isset($users)) $users = new Users($DATA_DIR . "/users.xml"); @@ -35,7 +35,7 @@ class NewsEntry {      $str .= "  <div class=\"news_time\">" .  			date("D M jS Y G:i", $this->time) . "</div>\n";      $str .= "  <div class=\"news_title\">\n"; -		$str .= "    <a href=\"?page=".$NEWS_PAGE."&newsid=".$this->time."\">" . +		$str .= "    <a href=\"?page=".$newspage."&newsid=".$this->time."\">" .        htmlspecialchars_decode($this->title, ENT_QUOTES) . "</a>\n";  		$str .= "  </div>\n";  		$str .= "  <div class=\"news_user\">By: " . $userid . "</div>\n"; @@ -80,13 +80,32 @@ class News {    private $file;    private $news = array(); +  public $newspage;    // Admin config    public $admin_title = "News";    public $admin_submodules = array("New entry" => "new",  																	 "Edit entry" => "edit", -																	 "Delete entry" => "delete"); +																	 "Delete entry" => "delete", +                                   "Config" => "config"); +  public function admin_config($action, $vars) +  { +    switch($action) { +    case "update": +      $this->newspage = $vars["newspage"]; +			$this->write(); +			break; +			 +    default: +      $form = new Form("update"); +      $form->addWidget(new LineEdit("News page (single):", "newspage", $this->newspage)); +      $form->addWidget(new Button("Update")); +      $form->render(); +      break; +    } +  } +    public function admin_add($action, $vars)  	{  		global $UID, $ICONS_DIR; @@ -109,7 +128,7 @@ class News {  												 $UID, $vars["icon"]);  			echo "<div class=\"preview\">\n";  			echo "<div class=\"content\">\n"; -			echo $n->show(); +			echo $n->show($this->newspage);  			echo "</div>\n";  			echo "</div>\n";  			echo "<p>Looking ok?</p>"; @@ -166,7 +185,7 @@ class News {  												 $vars["category"], $vars["description"], $UID, $vars["icon"]);  			echo "<div class=\"preview\">\n";  			echo "<div class=\"content\">\n"; -			echo $n->show(); +			echo $n->show($this->newspage);  			echo "</div>\n";  			echo "</div>\n";  			echo "<p>Looking ok?</p>"; @@ -265,6 +284,10 @@ class News {    public function admin($sub, $action, $vars)    {      switch($sub) { +    case "config": +			$this->admin_config($action, $vars); +      break; +      case "new":  			$this->admin_add($action, $vars);        break; @@ -308,7 +331,7 @@ class News {  		if($single) {  			if($newsid && $this->news[$newsid]) {  				//			$str .= $this->show($number, $module); -				$str .= $this->news[$newsid]->show(); +				$str .= $this->news[$newsid]->show($this->newspage);  			} else {  				$str .= "<strong>No such news entry!</strong>\n";  			} @@ -328,7 +351,7 @@ class News {      foreach($this->news as $newsentry) {        if($newsentry->category == $category || $category == "all") { -				$str .= $newsentry->show(); +				$str .= $newsentry->show($this->newspage);  				$number--;        }        if(!$number) return $str; @@ -343,10 +366,12 @@ class News {    public function write()    { +    global $DATA_DIR; +      $fp = fopen($this->file, "w");      fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); -    fwrite($fp, "<news>\n"); +    fwrite($fp, "<news newspage=\"".xmlenc($this->newspage)."\">\n");      foreach($this->news as $newsentry) {  			$newsentry->write($fp);      } @@ -354,7 +379,7 @@ class News {      fclose($fp); -		$rss = new RSS($this->file, "rss.xml"); +		$rss = new RSS($this->file, $DATA_DIR."/rss.xml");  		$rss->write();    } @@ -363,6 +388,10 @@ class News {      $dom = new DomDocument;      $dom->preserveWhiteSpace = FALSE;      $dom->load($this->file); + +		$n = $dom->documentElement; +		$this->newspage = $n->getAttribute('newspage'); +      $params = $dom->getElementsByTagName('newsentry');      foreach ($params as $param) {  | 
