dos2unixification

This commit is contained in:
Shish 2009-11-24 14:07:18 +00:00
parent 4e95149c4b
commit 95eadbdd1f
9 changed files with 2078 additions and 2078 deletions

View File

@ -1,494 +1,494 @@
<?php <?php
class ArtistsTheme extends Themelet { class ArtistsTheme extends Themelet {
public function get_author_editor_html($author) { public function get_author_editor_html($author) {
$h_author = html_escape($author); $h_author = html_escape($author);
return "<tr><td>Author</td><td><input class='editor_author' type='text' name='tag_edit__author' value='$h_author'></td></tr>"; return "<tr><td>Author</td><td><input class='editor_author' type='text' name='tag_edit__author' value='$h_author'></td></tr>";
} }
public function display_artists(){ public function display_artists(){
global $page; global $page;
$page->set_title("Artists"); $page->set_title("Artists");
$page->set_heading("Artists"); $page->set_heading("Artists");
$page->add_block(new Block("Artists", $html, "main", 10)); $page->add_block(new Block("Artists", $html, "main", 10));
//$this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages); //$this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages);
} }
public function sidebar_options($mode, $artistID=NULL, $is_admin=FALSE){ public function sidebar_options($mode, $artistID=NULL, $is_admin=FALSE){
global $page; global $page;
if($mode == "neutral"){ if($mode == "neutral"){
$html = "<form method='post' action='".make_link("artist/new_artist")."'> $html = "<form method='post' action='".make_link("artist/new_artist")."'>
<input type='submit' name='edit' id='edit' value='New Artist'/> <input type='submit' name='edit' id='edit' value='New Artist'/>
</form>"; </form>";
} }
if($mode == "editor"){ if($mode == "editor"){
$html = "<form method='post' action='".make_link("artist/new_artist")."'> $html = "<form method='post' action='".make_link("artist/new_artist")."'>
<input type='submit' name='edit' id='edit' value='New Artist'/> <input type='submit' name='edit' id='edit' value='New Artist'/>
</form> </form>
<form method='post' action='".make_link("artist/edit_artist")."'> <form method='post' action='".make_link("artist/edit_artist")."'>
<input type='submit' name='edit' id='edit' value='Edit Artist'/> <input type='submit' name='edit' id='edit' value='Edit Artist'/>
<input type='hidden' name='artist_id' value='".$artistID."'> <input type='hidden' name='artist_id' value='".$artistID."'>
</form>"; </form>";
if($is_admin){ if($is_admin){
$html .= "<form method='post' action='".make_link("artist/nuke_artist")."'> $html .= "<form method='post' action='".make_link("artist/nuke_artist")."'>
<input type='submit' name='edit' id='edit' value='Delete Artist'/> <input type='submit' name='edit' id='edit' value='Delete Artist'/>
<input type='hidden' name='artist_id' value='".$artistID."'> <input type='hidden' name='artist_id' value='".$artistID."'>
</form>"; </form>";
} }
$html .= "<form method='post' action='".make_link("artist/add_alias")."'> $html .= "<form method='post' action='".make_link("artist/add_alias")."'>
<input type='submit' name='edit' id='edit' value='Add Alias'/> <input type='submit' name='edit' id='edit' value='Add Alias'/>
<input type='hidden' name='artist_id' value='".$artistID."'> <input type='hidden' name='artist_id' value='".$artistID."'>
</form> </form>
<form method='post' action='".make_link("artist/add_member")."'> <form method='post' action='".make_link("artist/add_member")."'>
<input type='submit' name='edit' id='edit' value='Add Member'/> <input type='submit' name='edit' id='edit' value='Add Member'/>
<input type='hidden' name='artist_id' value='".$artistID."'> <input type='hidden' name='artist_id' value='".$artistID."'>
</form> </form>
<form method='post' action='".make_link("artist/add_url")."'> <form method='post' action='".make_link("artist/add_url")."'>
<input type='submit' name='edit' id='edit' value='Add Url'/> <input type='submit' name='edit' id='edit' value='Add Url'/>
<input type='hidden' name='artist_id' value='".$artistID."'> <input type='hidden' name='artist_id' value='".$artistID."'>
</form>"; </form>";
} }
$page->add_block(new Block("Manage Artists", $html, "left", 10)); $page->add_block(new Block("Manage Artists", $html, "left", 10));
} }
public function show_artist_editor($artist, $aliases, $members, $urls) public function show_artist_editor($artist, $aliases, $members, $urls)
{ {
$artistName = $artist['name']; $artistName = $artist['name'];
$artistNotes = $artist['notes']; $artistNotes = $artist['notes'];
$artistID = $artist['id']; $artistID = $artist['id'];
// aliases // aliases
$aliasesString = ""; $aliasesString = "";
$aliasesIDsString = ""; $aliasesIDsString = "";
foreach ($aliases as $alias) foreach ($aliases as $alias)
{ {
$aliasesString .= $alias["alias_name"]." "; $aliasesString .= $alias["alias_name"]." ";
$aliasesIDsString .= $alias["alias_id"]." "; $aliasesIDsString .= $alias["alias_id"]." ";
} }
$aliasesString = rtrim($aliasesString); $aliasesString = rtrim($aliasesString);
$aliasesIDsString = rtrim($aliasesIDsString); $aliasesIDsString = rtrim($aliasesIDsString);
// members // members
$membersString = ""; $membersString = "";
$membersIDsString = ""; $membersIDsString = "";
foreach ($members as $member) foreach ($members as $member)
{ {
$membersString .= $member["name"]." "; $membersString .= $member["name"]." ";
$membersIDsString .= $member["id"]." "; $membersIDsString .= $member["id"]." ";
} }
$membersString = rtrim($membersString); $membersString = rtrim($membersString);
$membersIDsString = rtrim($membersIDsString); $membersIDsString = rtrim($membersIDsString);
// urls // urls
$urlsString = ""; $urlsString = "";
$urlsIDsString = ""; $urlsIDsString = "";
foreach ($urls as $url) foreach ($urls as $url)
{ {
$urlsString .= $url["url"]."\n"; $urlsString .= $url["url"]."\n";
$urlsIDsString .= $url["id"]." "; $urlsIDsString .= $url["id"]." ";
} }
$urlsString = substr($urlsString, 0, strlen($urlsString) -1); $urlsString = substr($urlsString, 0, strlen($urlsString) -1);
$urlsIDsString = rtrim($urlsIDsString); $urlsIDsString = rtrim($urlsIDsString);
$html = $html =
' '
<form method="POST" action="'.make_link("artist/edited/".$artist['id']).'"> <form method="POST" action="'.make_link("artist/edited/".$artist['id']).'">
<table> <table>
<tr><td>Name:</td><td><input type="text" name="name" value="'.$artistName.'" /> <tr><td>Name:</td><td><input type="text" name="name" value="'.$artistName.'" />
<input type="hidden" name="id" value="'.$artistID.'" /></td></tr> <input type="hidden" name="id" value="'.$artistID.'" /></td></tr>
<tr><td>Alias:</td><td><input type="text" name="aliases" value="'.$aliasesString.'" /> <tr><td>Alias:</td><td><input type="text" name="aliases" value="'.$aliasesString.'" />
<input type="hidden" name="aliasesIDs" value="'.$aliasesIDsString.'" /></td></tr> <input type="hidden" name="aliasesIDs" value="'.$aliasesIDsString.'" /></td></tr>
<tr><td>Members:</td><td><input type="text" name="members" value="'.$membersString.'" /> <tr><td>Members:</td><td><input type="text" name="members" value="'.$membersString.'" />
<input type="hidden" name="membersIDs" value="'.$membersIDsString.'" /></td></tr> <input type="hidden" name="membersIDs" value="'.$membersIDsString.'" /></td></tr>
<tr><td>URLs:</td><td><textarea name="urls">'.$urlsString.'</textarea> <tr><td>URLs:</td><td><textarea name="urls">'.$urlsString.'</textarea>
<input type="hidden" name="urlsIDs" value="'.$urlsIDsString.'" /></td></tr> <input type="hidden" name="urlsIDs" value="'.$urlsIDsString.'" /></td></tr>
<tr><td>Notes:</td><td><textarea name="notes">'.$artistNotes.'</textarea></td></tr> <tr><td>Notes:</td><td><textarea name="notes">'.$artistNotes.'</textarea></td></tr>
<tr><td colspan="2"><input type="submit" value="Submit" /></td></tr> <tr><td colspan="2"><input type="submit" value="Submit" /></td></tr>
</table> </table>
</form> </form>
'; ';
global $page; global $page;
$page->add_block(new Block("Edit artist", $html, "main", 10)); $page->add_block(new Block("Edit artist", $html, "main", 10));
} }
public function new_artist_composer() public function new_artist_composer()
{ {
global $page; global $page;
$html = "<form action=".make_link("artist/create")." method='POST'> $html = "<form action=".make_link("artist/create")." method='POST'>
<table> <table>
<tr><td>Name:</td><td><input type='text' name='name' /></td></tr> <tr><td>Name:</td><td><input type='text' name='name' /></td></tr>
<tr><td>Aliases:</td><td><input type='text' name='aliases' /></td></tr> <tr><td>Aliases:</td><td><input type='text' name='aliases' /></td></tr>
<tr><td>Members:</td><td><input type='text' name='members' /></td></tr> <tr><td>Members:</td><td><input type='text' name='members' /></td></tr>
<tr><td>URLs:</td><td><textarea name='urls'></textarea></td></tr> <tr><td>URLs:</td><td><textarea name='urls'></textarea></td></tr>
<tr><td>Notes:</td><td><textarea name='notes'></textarea></td></tr> <tr><td>Notes:</td><td><textarea name='notes'></textarea></td></tr>
<tr><td colspan='2'><input type='submit' value='Submit' /></td></tr> <tr><td colspan='2'><input type='submit' value='Submit' /></td></tr>
</table> </table>
"; ";
$page->set_title("Artists"); $page->set_title("Artists");
$page->set_heading("Artists"); $page->set_heading("Artists");
$page->add_block(new Block("Artists", $html, "main", 10)); $page->add_block(new Block("Artists", $html, "main", 10));
} }
public function list_artists($artists, $pageNumber, $totalPages) public function list_artists($artists, $pageNumber, $totalPages)
{ {
global $user, $page; global $user, $page;
$html = "<table id='poolsList' class='zebra'>". $html = "<table id='poolsList' class='zebra'>".
"<thead><tr>". "<thead><tr>".
"<th>Name</th>". "<th>Name</th>".
"<th>Type</th>". "<th>Type</th>".
"<th>Last updater</th>". "<th>Last updater</th>".
"<th>Posts</th>"; "<th>Posts</th>";
if(!$user->is_anonymous()) $html .= "<th colspan='2'>Action</th>"; // space for edit link if(!$user->is_anonymous()) $html .= "<th colspan='2'>Action</th>"; // space for edit link
$html .= "</tr></thead>"; $html .= "</tr></thead>";
$n = 0; $n = 0;
$deletionLinkActionArray = $deletionLinkActionArray =
array('artist' => 'artist/nuke/' array('artist' => 'artist/nuke/'
, 'alias' => 'artist/alias/delete/' , 'alias' => 'artist/alias/delete/'
, 'member' => 'artist/member/delete/' , 'member' => 'artist/member/delete/'
); );
$editionLinkActionArray = $editionLinkActionArray =
array('artist' => 'artist/edit/' array('artist' => 'artist/edit/'
, 'alias' => 'artist/alias/edit/' , 'alias' => 'artist/alias/edit/'
, 'member' => 'artist/member/edit/' , 'member' => 'artist/member/edit/'
); );
$typeTextArray = $typeTextArray =
array('artist' => 'Artist' array('artist' => 'Artist'
, 'alias' => 'Alias' , 'alias' => 'Alias'
, 'member' => 'Member' , 'member' => 'Member'
); );
foreach ($artists as $artist) foreach ($artists as $artist)
{ {
$oe = ($n++ % 2 == 0) ? "even" : "odd"; $oe = ($n++ % 2 == 0) ? "even" : "odd";
if ($artist['type'] != 'artist') if ($artist['type'] != 'artist')
$artist['name'] = str_replace("_", " ", $artist['name']); $artist['name'] = str_replace("_", " ", $artist['name']);
$elementLink = "<a href='".make_link("artist/view/".$artist['artist_id'])."'>".str_replace("_", " ", $artist['name'])."</a>"; $elementLink = "<a href='".make_link("artist/view/".$artist['artist_id'])."'>".str_replace("_", " ", $artist['name'])."</a>";
$artist_link = "<a href='".make_link("artist/view/".$artist['artist_id'])."'>".str_replace("_", " ", $artist['artist_name'])."</a>"; $artist_link = "<a href='".make_link("artist/view/".$artist['artist_id'])."'>".str_replace("_", " ", $artist['artist_name'])."</a>";
$user_link = "<a href='".make_link("user/".$artist['user_name'])."'>".$artist['user_name']."</a>"; $user_link = "<a href='".make_link("user/".$artist['user_name'])."'>".$artist['user_name']."</a>";
$edit_link = "<a href='".make_link($editionLinkActionArray[$artist['type']].$artist['id'])."'>Edit</a>"; $edit_link = "<a href='".make_link($editionLinkActionArray[$artist['type']].$artist['id'])."'>Edit</a>";
$del_link = "<a href='".make_link($deletionLinkActionArray[$artist['type']].$artist['id'])."'>Delete</a>"; $del_link = "<a href='".make_link($deletionLinkActionArray[$artist['type']].$artist['id'])."'>Delete</a>";
$html .= "<tr class='$oe'>". $html .= "<tr class='$oe'>".
"<td class='left'>".$elementLink; "<td class='left'>".$elementLink;
//if ($artist['type'] == 'member') //if ($artist['type'] == 'member')
// $html .= " (member of ".$artist_link.")"; // $html .= " (member of ".$artist_link.")";
//if ($artist['type'] == 'alias') //if ($artist['type'] == 'alias')
// $html .= " (alias for ".$artist_link.")"; // $html .= " (alias for ".$artist_link.")";
$html .= "</td>". $html .= "</td>".
"<td>".$typeTextArray[$artist['type']]."</td>". "<td>".$typeTextArray[$artist['type']]."</td>".
"<td>".$user_link."</td>". "<td>".$user_link."</td>".
"<td>".$artist['posts']."</td>"; "<td>".$artist['posts']."</td>";
if(!$user->is_anonymous()) $html .= "<td>".$edit_link."</td>"; if(!$user->is_anonymous()) $html .= "<td>".$edit_link."</td>";
if($user->is_admin()) $html .= "<td>".$del_link."</td>"; if($user->is_admin()) $html .= "<td>".$del_link."</td>";
$html .= "</tr>"; $html .= "</tr>";
} }
$html .= "</tbody></table>"; $html .= "</tbody></table>";
$page->set_title("Artists"); $page->set_title("Artists");
$page->set_heading("Artists"); $page->set_heading("Artists");
$page->add_block(new Block("Artists", $html, "main", 10)); $page->add_block(new Block("Artists", $html, "main", 10));
$this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages); $this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages);
} }
public function show_new_alias_composer($artistID) public function show_new_alias_composer($artistID)
{ {
$html = $html =
'<form method="POST" action='.make_link("artist/alias/add").'> '<form method="POST" action='.make_link("artist/alias/add").'>
<table> <table>
<tr><td>Alias:</td><td><input type="text" name="aliases" /> <tr><td>Alias:</td><td><input type="text" name="aliases" />
<input type="hidden" name="artistID" value='.$artistID.' /></td></tr> <input type="hidden" name="artistID" value='.$artistID.' /></td></tr>
<tr><td colspan="2"><input type="submit" value="Submit" /></td></tr> <tr><td colspan="2"><input type="submit" value="Submit" /></td></tr>
</table> </table>
</form> </form>
'; ';
global $page; global $page;
$page->add_block(new Block("Artist Aliases", $html, "main", 20)); $page->add_block(new Block("Artist Aliases", $html, "main", 20));
} }
public function show_new_member_composer($artistID) public function show_new_member_composer($artistID)
{ {
$html = $html =
' <form method="POST" action='.make_link("artist/member/add").'> ' <form method="POST" action='.make_link("artist/member/add").'>
<table> <table>
<tr><td>Members:</td><td><input type="text" name="members" /> <tr><td>Members:</td><td><input type="text" name="members" />
<input type="hidden" name="artistID" value='.$artistID.' /></td></tr> <input type="hidden" name="artistID" value='.$artistID.' /></td></tr>
<tr><td colspan="2"><input type="submit" value="Submit" /></td></tr> <tr><td colspan="2"><input type="submit" value="Submit" /></td></tr>
</table> </table>
</form> </form>
'; ';
global $page; global $page;
$page->add_block(new Block("Artist members", $html, "main", 30)); $page->add_block(new Block("Artist members", $html, "main", 30));
} }
public function show_new_url_composer($artistID) public function show_new_url_composer($artistID)
{ {
$html = $html =
' <form method="POST" action='.make_link("artist/url/add").'> ' <form method="POST" action='.make_link("artist/url/add").'>
<table> <table>
<tr><td>URL:</td><td><textarea name="urls"></textarea> <tr><td>URL:</td><td><textarea name="urls"></textarea>
<input type="hidden" name="artistID" value='.$artistID.' /></td></tr> <input type="hidden" name="artistID" value='.$artistID.' /></td></tr>
<tr><td colspan="2"><input type="submit" value="Submit" /></td></tr> <tr><td colspan="2"><input type="submit" value="Submit" /></td></tr>
</table> </table>
</form> </form>
'; ';
global $page; global $page;
$page->add_block(new Block("Artist URLs", $html, "main", 40)); $page->add_block(new Block("Artist URLs", $html, "main", 40));
} }
public function show_alias_editor($alias) public function show_alias_editor($alias)
{ {
$html = $html =
' '
<form method="POST" action="'.make_link("artist/alias/edited/".$alias['id']).'"> <form method="POST" action="'.make_link("artist/alias/edited/".$alias['id']).'">
<label for="alias">Alias:</label> <label for="alias">Alias:</label>
<input type="text" name="alias" value="'.$alias['alias'].'" /> <input type="text" name="alias" value="'.$alias['alias'].'" />
<input type="hidden" name="aliasID" value="'.$alias['id'].'" /> <input type="hidden" name="aliasID" value="'.$alias['id'].'" />
<input type="submit" value="Submit" /> <input type="submit" value="Submit" />
</form> </form>
'; ';
global $page; global $page;
$page->add_block(new Block("Edit Alias", $html, "main", 10)); $page->add_block(new Block("Edit Alias", $html, "main", 10));
} }
public function show_url_editor($url) public function show_url_editor($url)
{ {
$html = $html =
' '
<form method="POST" action="'.make_link("artist/url/edited/".$url['id']).'"> <form method="POST" action="'.make_link("artist/url/edited/".$url['id']).'">
<label for="url">URL:</label> <label for="url">URL:</label>
<input type="text" name="url" value="'.$url['url'].'" /> <input type="text" name="url" value="'.$url['url'].'" />
<input type="hidden" name="urlID" value="'.$url['id'].'" /> <input type="hidden" name="urlID" value="'.$url['id'].'" />
<input type="submit" value="Submit" /> <input type="submit" value="Submit" />
</form> </form>
'; ';
global $page; global $page;
$page->add_block(new Block("Edit URL", $html, "main", 10)); $page->add_block(new Block("Edit URL", $html, "main", 10));
} }
public function show_member_editor($member) public function show_member_editor($member)
{ {
$html = $html =
' '
<form method="POST" action="'.make_link("artist/member/edited/".$member['id']).'"> <form method="POST" action="'.make_link("artist/member/edited/".$member['id']).'">
<label for="member">Member name:</label> <label for="member">Member name:</label>
<input type="text" name="name" value="'.$member['name'].'" /> <input type="text" name="name" value="'.$member['name'].'" />
<input type="hidden" name="memberID" value="'.$member['id'].'" /> <input type="hidden" name="memberID" value="'.$member['id'].'" />
<input type="submit" value="Submit" /> <input type="submit" value="Submit" />
</form> </form>
'; ';
global $page; global $page;
$page->add_block(new Block("Edit Member", $html, "main", 10)); $page->add_block(new Block("Edit Member", $html, "main", 10));
} }
public function show_artist($artist, $aliases, $members, $urls, $images, $userIsLogged, $userIsAdmin) public function show_artist($artist, $aliases, $members, $urls, $images, $userIsLogged, $userIsAdmin)
{ {
global $user, $event, $page; global $user, $event, $page;
$artist_link = "<a href='".make_link("post/list/".$artist['name']."/1")."'>".str_replace("_", " ", $artist['name'])."</a>"; $artist_link = "<a href='".make_link("post/list/".$artist['name']."/1")."'>".str_replace("_", " ", $artist['name'])."</a>";
$n = 0; $n = 0;
$html = "<table id='poolsList' class='zebra'> $html = "<table id='poolsList' class='zebra'>
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<th></th>"; <th></th>";
if ($userIsLogged) if ($userIsLogged)
$html .= "<th></th>"; $html .= "<th></th>";
if ($userIsAdmin) if ($userIsAdmin)
$html .= "<th></th>"; $html .= "<th></th>";
$html .= " <tr> $html .= " <tr>
</thead> </thead>
<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'> <tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'>
<td class='left'>Name:</td> <td class='left'>Name:</td>
<td class='left'>".$artist_link."</td>"; <td class='left'>".$artist_link."</td>";
if ($userIsLogged) $html .= "<td></td>"; if ($userIsLogged) $html .= "<td></td>";
if ($userIsAdmin) $html .= "<td></td>"; if ($userIsAdmin) $html .= "<td></td>";
$html .= "</tr>"; $html .= "</tr>";
if (count($aliases) > 0) if (count($aliases) > 0)
{ {
$aliasViewLink = str_replace("_", " ", $aliases[0]['alias_name']); // no link anymore $aliasViewLink = str_replace("_", " ", $aliases[0]['alias_name']); // no link anymore
$aliasEditLink = "<a href='".make_link("artist/alias/edit/".$aliases[0]['alias_id'])."'>Edit</a>"; $aliasEditLink = "<a href='".make_link("artist/alias/edit/".$aliases[0]['alias_id'])."'>Edit</a>";
$aliasDeleteLink = "<a href='".make_link("artist/alias/delete/".$aliases[0]['alias_id'])."'>Delete</a>"; $aliasDeleteLink = "<a href='".make_link("artist/alias/delete/".$aliases[0]['alias_id'])."'>Delete</a>";
$html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'> $html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'>
<td class='left'>Aliases:</td> <td class='left'>Aliases:</td>
<td class='left'>".$aliasViewLink."</td>"; <td class='left'>".$aliasViewLink."</td>";
if ($userIsLogged) if ($userIsLogged)
$html .= "<td class='left'>".$aliasEditLink."</td>"; $html .= "<td class='left'>".$aliasEditLink."</td>";
if ($userIsAdmin) if ($userIsAdmin)
$html .= "<td class='left'>".$aliasDeleteLink."</td>"; $html .= "<td class='left'>".$aliasDeleteLink."</td>";
$html .= "</tr>"; $html .= "</tr>";
if (count($aliases) > 1) if (count($aliases) > 1)
{ {
for ($i = 1; $i < count($aliases); $i++) for ($i = 1; $i < count($aliases); $i++)
{ {
$aliasViewLink = str_replace("_", " ", $aliases[$i]['alias_name']); // no link anymore $aliasViewLink = str_replace("_", " ", $aliases[$i]['alias_name']); // no link anymore
$aliasEditLink = "<a href='".make_link("artist/alias/edit/".$aliases[$i]['alias_id'])."'>Edit</a>"; $aliasEditLink = "<a href='".make_link("artist/alias/edit/".$aliases[$i]['alias_id'])."'>Edit</a>";
$aliasDeleteLink = "<a href='".make_link("artist/alias/delete/".$aliases[$i]['alias_id'])."'>Delete</a>"; $aliasDeleteLink = "<a href='".make_link("artist/alias/delete/".$aliases[$i]['alias_id'])."'>Delete</a>";
$html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'> $html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'>
<td class='left'>&nbsp;</td> <td class='left'>&nbsp;</td>
<td class='left'>".$aliasViewLink."</td>"; <td class='left'>".$aliasViewLink."</td>";
if ($userIsLogged) if ($userIsLogged)
$html .= "<td class='left'>".$aliasEditLink."</td>"; $html .= "<td class='left'>".$aliasEditLink."</td>";
if ($userIsAdmin) if ($userIsAdmin)
$html .= "<td class='left'>".$aliasDeleteLink."</td>"; $html .= "<td class='left'>".$aliasDeleteLink."</td>";
$html .= "</tr>"; $html .= "</tr>";
} }
} }
} }
if (count($members) > 0) if (count($members) > 0)
{ {
$memberViewLink = str_replace("_", " ", $members[0]['name']); // no link anymore $memberViewLink = str_replace("_", " ", $members[0]['name']); // no link anymore
$memberEditLink = "<a href='".make_link("artist/member/edit/".$members[0]['id'])."'>Edit</a>"; $memberEditLink = "<a href='".make_link("artist/member/edit/".$members[0]['id'])."'>Edit</a>";
$memberDeleteLink = "<a href='".make_link("artist/member/delete/".$members[0]['id'])."'>Delete</a>"; $memberDeleteLink = "<a href='".make_link("artist/member/delete/".$members[0]['id'])."'>Delete</a>";
$html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'> $html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'>
<td class='left'>Members:</td> <td class='left'>Members:</td>
<td class='left'>".$memberViewLink."</td>"; <td class='left'>".$memberViewLink."</td>";
if ($userIsLogged) if ($userIsLogged)
$html .= "<td class='left'>".$memberEditLink."</td>"; $html .= "<td class='left'>".$memberEditLink."</td>";
if ($userIsAdmin) if ($userIsAdmin)
$html .= "<td class='left'>".$memberDeleteLink."</td>"; $html .= "<td class='left'>".$memberDeleteLink."</td>";
$html .= "</tr>"; $html .= "</tr>";
if (count($members) > 1) if (count($members) > 1)
{ {
for ($i = 1; $i < count($members); $i++) for ($i = 1; $i < count($members); $i++)
{ {
$memberViewLink = str_replace("_", " ", $members[$i]['name']); // no link anymore $memberViewLink = str_replace("_", " ", $members[$i]['name']); // no link anymore
$memberEditLink = "<a href='".make_link("artist/member/edit/".$members[$i]['id'])."'>Edit</a>"; $memberEditLink = "<a href='".make_link("artist/member/edit/".$members[$i]['id'])."'>Edit</a>";
$memberDeleteLink = "<a href='".make_link("artist/member/delete/".$members[$i]['id'])."'>Delete</a>"; $memberDeleteLink = "<a href='".make_link("artist/member/delete/".$members[$i]['id'])."'>Delete</a>";
$html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'> $html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'>
<td class='left'>&nbsp;</td> <td class='left'>&nbsp;</td>
<td class='left'>".$memberViewLink."</td>"; <td class='left'>".$memberViewLink."</td>";
if ($userIsLogged) if ($userIsLogged)
$html .= "<td class='left'>".$memberEditLink."</td>"; $html .= "<td class='left'>".$memberEditLink."</td>";
if ($userIsAdmin) if ($userIsAdmin)
$html .= "<td class='left'>".$memberDeleteLink."</td>"; $html .= "<td class='left'>".$memberDeleteLink."</td>";
$html .= "</tr>"; $html .= "</tr>";
} }
} }
} }
if (count($urls) > 0) if (count($urls) > 0)
{ {
$urlViewLink = "<a href='".str_replace("_", " ", $urls[0]['url'])."' target='_blank'>".str_replace("_", " ", $urls[0]['url'])."</a>"; $urlViewLink = "<a href='".str_replace("_", " ", $urls[0]['url'])."' target='_blank'>".str_replace("_", " ", $urls[0]['url'])."</a>";
$urlEditLink = "<a href='".make_link("artist/url/edit/".$urls[0]['id'])."'>Edit</a>"; $urlEditLink = "<a href='".make_link("artist/url/edit/".$urls[0]['id'])."'>Edit</a>";
$urlDeleteLink = "<a href='".make_link("artist/url/delete/".$urls[0]['id'])."'>Delete</a>"; $urlDeleteLink = "<a href='".make_link("artist/url/delete/".$urls[0]['id'])."'>Delete</a>";
$html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'> $html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'>
<td class='left'>URLs:</td> <td class='left'>URLs:</td>
<td class='left'>".$urlViewLink."</td>"; <td class='left'>".$urlViewLink."</td>";
if ($userIsLogged) if ($userIsLogged)
$html .= "<td class='left'>".$urlEditLink."</td>"; $html .= "<td class='left'>".$urlEditLink."</td>";
if ($userIsAdmin) if ($userIsAdmin)
$html .= "<td class='left'>".$urlDeleteLink."</td>"; $html .= "<td class='left'>".$urlDeleteLink."</td>";
$html .= "</tr>"; $html .= "</tr>";
if (count($urls) > 1) if (count($urls) > 1)
{ {
for ($i = 1; $i < count($urls); $i++) for ($i = 1; $i < count($urls); $i++)
{ {
$urlViewLink = "<a href='".str_replace("_", " ", $urls[$i]['url'])."' target='_blank'>".str_replace("_", " ", $urls[$i]['url'])."</a>"; $urlViewLink = "<a href='".str_replace("_", " ", $urls[$i]['url'])."' target='_blank'>".str_replace("_", " ", $urls[$i]['url'])."</a>";
$urlEditLink = "<a href='".make_link("artist/url/edit/".$urls[$i]['id'])."'>Edit</a>"; $urlEditLink = "<a href='".make_link("artist/url/edit/".$urls[$i]['id'])."'>Edit</a>";
$urlDeleteLink = "<a href='".make_link("artist/url/delete/".$urls[$i]['id'])."'>Delete</a>"; $urlDeleteLink = "<a href='".make_link("artist/url/delete/".$urls[$i]['id'])."'>Delete</a>";
$html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'> $html .= "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'>
<td class='left'>&nbsp;</td> <td class='left'>&nbsp;</td>
<td class='left'>".$urlViewLink."</td>"; <td class='left'>".$urlViewLink."</td>";
if ($userIsLogged) if ($userIsLogged)
$html .= "<td class='left'>".$urlEditLink."</td>"; $html .= "<td class='left'>".$urlEditLink."</td>";
if ($userIsAdmin) if ($userIsAdmin)
$html .= "<td class='left'>".$urlDeleteLink."</td>"; $html .= "<td class='left'>".$urlDeleteLink."</td>";
$html .= "</tr>"; $html .= "</tr>";
} }
} }
} }
$html .= $html .=
"<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'> "<tr class='".(($n++ % 2 == 0) ? "even" : "odd")."'>
<td class='left'>Notes:</td> <td class='left'>Notes:</td>
<td class='left'>".$artist["notes"]."</td>"; <td class='left'>".$artist["notes"]."</td>";
if ($userIsLogged) $html .= "<td></td>"; if ($userIsLogged) $html .= "<td></td>";
if ($userIsAdmin) $html .= "<td></td>"; if ($userIsAdmin) $html .= "<td></td>";
//TODO how will notes be edited? On edit artist? (should there be an editartist?) or on a editnotes? //TODO how will notes be edited? On edit artist? (should there be an editartist?) or on a editnotes?
//same question for deletion //same question for deletion
$html .= "</tr> $html .= "</tr>
</table>"; </table>";
$page->set_title("Artist"); $page->set_title("Artist");
$page->set_heading("Artist"); $page->set_heading("Artist");
$page->add_block(new Block("Artist", $html, "main", 10)); $page->add_block(new Block("Artist", $html, "main", 10));
//we show the images for the artist //we show the images for the artist
$artist_images = ""; $artist_images = "";
foreach($images as $image) { foreach($images as $image) {
$thumb_html = $this->build_thumb_html($image); $thumb_html = $this->build_thumb_html($image);
$artist_images .= '<span class="thumb">'. $artist_images .= '<span class="thumb">'.
'<a href="$image_link">'.$thumb_html.'</a>'. '<a href="$image_link">'.$thumb_html.'</a>'.
'</span>'; '</span>';
} }
$page->add_block(new Block("Artist Images", $artist_images, "main", 20)); $page->add_block(new Block("Artist Images", $artist_images, "main", 20));
} }
} }
?> ?>

View File

@ -1,43 +1,43 @@
<?php <?php
class FavoritesTheme extends Themelet { class FavoritesTheme extends Themelet {
public function get_voter_html(Image $image, $is_favorited) { public function get_voter_html(Image $image, $is_favorited) {
global $page, $user; global $page, $user;
$i_image_id = int_escape($image->id); $i_image_id = int_escape($image->id);
if(!$is_favorited) { if(!$is_favorited) {
$html = "<form action='".make_link("change_favorite")."' method='POST'> $html = "<form action='".make_link("change_favorite")."' method='POST'>
<input type='hidden' name='image_id' value='$i_image_id'> <input type='hidden' name='image_id' value='$i_image_id'>
<input type='hidden' name='favorite_action' value='set'> <input type='hidden' name='favorite_action' value='set'>
<input type='submit' value='Favorite'> <input type='submit' value='Favorite'>
</form> </form>
"; ";
} }
else { else {
$html = "<form action='".make_link("change_favorite")."' method='POST'> $html = "<form action='".make_link("change_favorite")."' method='POST'>
<input type='hidden' name='image_id' value='$i_image_id'> <input type='hidden' name='image_id' value='$i_image_id'>
<input type='hidden' name='favorite_action' value='unset'> <input type='hidden' name='favorite_action' value='unset'>
<input type='submit' value='Un-Favorite'> <input type='submit' value='Un-Favorite'>
</form> </form>
"; ";
} }
return $html; return $html;
} }
public function display_people($username_array) { public function display_people($username_array) {
global $page; global $page;
$i_favorites = count($username_array); $i_favorites = count($username_array);
$html = "$i_favorites people:"; $html = "$i_favorites people:";
foreach($username_array as $row) { foreach($username_array as $row) {
$username = html_escape($row['name']); $username = html_escape($row['name']);
$html .= "<br><a href='".make_link("user/$username")."'>$username</a>"; $html .= "<br><a href='".make_link("user/$username")."'>$username</a>";
} }
$page->add_block(new Block("Favorited By", $html, "left", 25)); $page->add_block(new Block("Favorited By", $html, "left", 25));
} }
} }
?> ?>

View File

@ -1,395 +1,395 @@
<?php <?php
/** /**
* Name: [Beta] Forum * Name: [Beta] Forum
* Author: Sein Kraft <mail@seinkraft.info> * Author: Sein Kraft <mail@seinkraft.info>
* Alpha <alpha@furries.com.ar> * Alpha <alpha@furries.com.ar>
* License: GPLv2 * License: GPLv2
* Description: Rough forum extension * Description: Rough forum extension
* Documentation: * Documentation:
*/ */
class Forum extends SimpleExtension { class Forum extends SimpleExtension {
public function onInitExt($event) { public function onInitExt($event) {
global $config, $database; global $config, $database;
// shortcut to latest // shortcut to latest
if ($config->get_int("forum_version") < 1) if ($config->get_int("forum_version") < 1)
{ {
$database->create_table("forum_threads", " $database->create_table("forum_threads", "
id SCORE_AIPK, id SCORE_AIPK,
sticky SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, sticky SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
title VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
date DATETIME NOT NULL, date DATETIME NOT NULL,
uptodate DATETIME NOT NULL, uptodate DATETIME NOT NULL,
INDEX (date) INDEX (date)
"); ");
$database->create_table("forum_posts", $database->create_table("forum_posts",
" id SCORE_AIPK, " id SCORE_AIPK,
thread_id INTEGER NOT NULL, thread_id INTEGER NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
date DATETIME NOT NULL, date DATETIME NOT NULL,
message TEXT, message TEXT,
INDEX (date), INDEX (date),
FOREIGN KEY (thread_id) REFERENCES forum_threads (id) ON UPDATE CASCADE ON DELETE CASCADE FOREIGN KEY (thread_id) REFERENCES forum_threads (id) ON UPDATE CASCADE ON DELETE CASCADE
"); ");
$config->set_int("forum_version", 1); $config->set_int("forum_version", 1);
$config->set_int("forumTitleSubString", 25); $config->set_int("forumTitleSubString", 25);
$config->set_int("forumThreadsPerPage", 15); $config->set_int("forumThreadsPerPage", 15);
$config->set_int("forumPostsPerPage", 15); $config->set_int("forumPostsPerPage", 15);
$config->set_int("forumMaxCharsPerPost", 512); $config->set_int("forumMaxCharsPerPost", 512);
log_info("forum", "extension installed"); log_info("forum", "extension installed");
} }
} }
public function onSetupBuilding(SetupBuildingEvent $event) { public function onSetupBuilding(SetupBuildingEvent $event) {
$sb = new SetupBlock("Forum"); $sb = new SetupBlock("Forum");
$sb->add_int_option("forumTitleSubString", "Title max long: "); $sb->add_int_option("forumTitleSubString", "Title max long: ");
$sb->add_int_option("forumThreadsPerPage", "<br>Threads per page: "); $sb->add_int_option("forumThreadsPerPage", "<br>Threads per page: ");
$sb->add_int_option("forumPostsPerPage", "<br>Posts per page: "); $sb->add_int_option("forumPostsPerPage", "<br>Posts per page: ");
$sb->add_int_option("forumMaxCharsPerPost", "<br>Max chars per post: "); $sb->add_int_option("forumMaxCharsPerPost", "<br>Max chars per post: ");
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
public function onUserPageBuilding($event) { public function onUserPageBuilding($event) {
global $page, $user, $database; global $page, $user, $database;
$threads_count = $database->db->GetOne("SELECT COUNT(*) FROM forum_threads WHERE user_id=?", array($event->display_user->id)); $threads_count = $database->db->GetOne("SELECT COUNT(*) FROM forum_threads WHERE user_id=?", array($event->display_user->id));
$posts_count = $database->db->GetOne("SELECT COUNT(*) FROM forum_posts WHERE user_id=?", array($event->display_user->id)); $posts_count = $database->db->GetOne("SELECT COUNT(*) FROM forum_posts WHERE user_id=?", array($event->display_user->id));
$days_old = ((time() - strtotime($event->display_user->join_date)) / 86400) + 1; $days_old = ((time() - strtotime($event->display_user->join_date)) / 86400) + 1;
$threads_rate = sprintf("%.1f", ($threads_count / $days_old)); $threads_rate = sprintf("%.1f", ($threads_count / $days_old));
$posts_rate = sprintf("%.1f", ($posts_count / $days_old)); $posts_rate = sprintf("%.1f", ($posts_count / $days_old));
$event->add_stats("Forum threads: $threads_count, $threads_rate per day"); $event->add_stats("Forum threads: $threads_count, $threads_rate per day");
$event->add_stats("Forum posts: $posts_count, $posts_rate per day"); $event->add_stats("Forum posts: $posts_count, $posts_rate per day");
} }
public function onPageRequest($event) { public function onPageRequest($event) {
global $page, $user; global $page, $user;
if($event->page_matches("forum")) { if($event->page_matches("forum")) {
switch($event->get_arg(0)) { switch($event->get_arg(0)) {
case "index": case "index":
{ {
$this->show_last_threads($page, $event, $user->is_admin()); $this->show_last_threads($page, $event, $user->is_admin());
if(!$user->is_anonymous()) $this->theme->display_new_thread_composer($page); if(!$user->is_anonymous()) $this->theme->display_new_thread_composer($page);
break; break;
} }
case "view": case "view":
{ {
$threadID = int_escape($event->get_arg(1)); $threadID = int_escape($event->get_arg(1));
$pageNumber = int_escape($event->get_arg(2)); $pageNumber = int_escape($event->get_arg(2));
$this->show_posts($event, $user->is_admin()); $this->show_posts($event, $user->is_admin());
if($user->is_admin()) $this->theme->add_actions_block($page, $threadID); if($user->is_admin()) $this->theme->add_actions_block($page, $threadID);
if(!$user->is_anonymous()) $this->theme->display_new_post_composer($page, $threadID); if(!$user->is_anonymous()) $this->theme->display_new_post_composer($page, $threadID);
break; break;
} }
case "new": case "new":
{ {
global $page; global $page;
$this->theme->display_new_thread_composer($page); $this->theme->display_new_thread_composer($page);
break; break;
} }
case "create": case "create":
{ {
$redirectTo = "forum/index"; $redirectTo = "forum/index";
if (!$user->is_anonymous()) if (!$user->is_anonymous())
{ {
list($hasErrors, $errors) = $this->valid_values_for_new_thread(); list($hasErrors, $errors) = $this->valid_values_for_new_thread();
if($hasErrors) if($hasErrors)
{ {
$this->theme->display_error($page, "Error", $errors); $this->theme->display_error($page, "Error", $errors);
$this->theme->display_new_thread_composer($page, $_POST["message"], $_POST["title"], false); $this->theme->display_new_thread_composer($page, $_POST["message"], $_POST["title"], false);
break; break;
} }
$newThreadID = $this->save_new_thread($user); $newThreadID = $this->save_new_thread($user);
$this->save_new_post($newThreadID, $user); $this->save_new_post($newThreadID, $user);
$redirectTo = "forum/view/".$newThreadID."/1"; $redirectTo = "forum/view/".$newThreadID."/1";
} }
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link($redirectTo)); $page->set_redirect(make_link($redirectTo));
break; break;
} }
case "delete": case "delete":
$threadID = int_escape($event->get_arg(1)); $threadID = int_escape($event->get_arg(1));
$postID = int_escape($event->get_arg(2)); $postID = int_escape($event->get_arg(2));
if ($user->is_admin()) {$this->delete_post($postID);} if ($user->is_admin()) {$this->delete_post($postID);}
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("forum/view/".$threadID)); $page->set_redirect(make_link("forum/view/".$threadID));
break; break;
case "nuke": case "nuke":
$threadID = int_escape($event->get_arg(1)); $threadID = int_escape($event->get_arg(1));
if ($user->is_admin()) if ($user->is_admin())
$this->delete_thread($threadID); $this->delete_thread($threadID);
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("forum/index")); $page->set_redirect(make_link("forum/index"));
break; break;
case "answer": case "answer":
if (!$user->is_anonymous()) if (!$user->is_anonymous())
{ {
list($hasErrors, $errors) = $this->valid_values_for_new_post(); list($hasErrors, $errors) = $this->valid_values_for_new_post();
if ($hasErrors) if ($hasErrors)
{ {
$this->theme->display_error($page, "Error", $errors); $this->theme->display_error($page, "Error", $errors);
$this->theme->display_new_post_composer($page, $_POST["threadID"], $_POST["message"], $_POST["title"], false); $this->theme->display_new_post_composer($page, $_POST["threadID"], $_POST["message"], $_POST["title"], false);
break; break;
} }
$threadID = int_escape($_POST["threadID"]); $threadID = int_escape($_POST["threadID"]);
$this->save_new_post($threadID, $user); $this->save_new_post($threadID, $user);
} }
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("forum/view/".$threadID."/1")); $page->set_redirect(make_link("forum/view/".$threadID."/1"));
break; break;
default: default:
{ {
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("forum/index")); $page->set_redirect(make_link("forum/index"));
//$this->theme->display_error($page, "Invalid action", "You should check forum/index."); //$this->theme->display_error($page, "Invalid action", "You should check forum/index.");
break; break;
} }
} }
} }
} }
private function get_total_pages_for_thread($threadID) private function get_total_pages_for_thread($threadID)
{ {
global $database, $config; global $database, $config;
$result = $database->get_row("SELECT COUNT(1) AS count FROM forum_posts WHERE thread_id = ?", array($threadID)); $result = $database->get_row("SELECT COUNT(1) AS count FROM forum_posts WHERE thread_id = ?", array($threadID));
return ceil($result["count"] / $config->get_int("forumPostsPerPage")); return ceil($result["count"] / $config->get_int("forumPostsPerPage"));
} }
private function valid_values_for_new_thread() private function valid_values_for_new_thread()
{ {
$hasErrors = false; $hasErrors = false;
$errors = ""; $errors = "";
if (!array_key_exists("title", $_POST)) if (!array_key_exists("title", $_POST))
{ {
$hasErrors = true; $hasErrors = true;
$errors .= "<div id='error'>No title supplied.</div>"; $errors .= "<div id='error'>No title supplied.</div>";
} }
else if (strlen($_POST["title"]) == 0) else if (strlen($_POST["title"]) == 0)
{ {
$hasErrors = true; $hasErrors = true;
$errors .= "<div id='error'>You cannot have an empty title.</div>"; $errors .= "<div id='error'>You cannot have an empty title.</div>";
} }
else if (strlen(mysql_real_escape_string(html_escape($_POST["title"]))) > 255) else if (strlen(mysql_real_escape_string(html_escape($_POST["title"]))) > 255)
{ {
$hasErrors = true; $hasErrors = true;
$errors .= "<div id='error'>Your title is too long.</div>"; $errors .= "<div id='error'>Your title is too long.</div>";
} }
if (!array_key_exists("message", $_POST)) if (!array_key_exists("message", $_POST))
{ {
$hasErrors = true; $hasErrors = true;
$errors .= "<div id='error'>No message supplied.</div>"; $errors .= "<div id='error'>No message supplied.</div>";
} }
else if (strlen($_POST["message"]) == 0) else if (strlen($_POST["message"]) == 0)
{ {
$hasErrors = true; $hasErrors = true;
$errors .= "<div id='error'>You cannot have an empty message.</div>"; $errors .= "<div id='error'>You cannot have an empty message.</div>";
} }
return array($hasErrors, $errors); return array($hasErrors, $errors);
} }
private function valid_values_for_new_post() private function valid_values_for_new_post()
{ {
$hasErrors = false; $hasErrors = false;
$errors = ""; $errors = "";
if (!array_key_exists("threadID", $_POST)) if (!array_key_exists("threadID", $_POST))
{ {
$hasErrors = true; $hasErrors = true;
$errors = "<div id='error'>No thread ID supplied.</div>"; $errors = "<div id='error'>No thread ID supplied.</div>";
} }
else if (strlen($_POST["threadID"]) == 0) else if (strlen($_POST["threadID"]) == 0)
{ {
$hasErrors = true; $hasErrors = true;
$errors = "<div id='error'>No thread ID supplied.</div>"; $errors = "<div id='error'>No thread ID supplied.</div>";
} }
else if (is_numeric($_POST["threadID"])) else if (is_numeric($_POST["threadID"]))
if (!array_key_exists("message", $_POST)) if (!array_key_exists("message", $_POST))
{ {
$hasErrors = true; $hasErrors = true;
$errors .= "<div id='error'>No message supplied.</div>"; $errors .= "<div id='error'>No message supplied.</div>";
} }
else if (strlen($_POST["message"]) == 0) else if (strlen($_POST["message"]) == 0)
{ {
$hasErrors = true; $hasErrors = true;
$errors .= "<div id='error'>You cannot have an empty message.</div>"; $errors .= "<div id='error'>You cannot have an empty message.</div>";
} }
return array($hasErrors, $errors); return array($hasErrors, $errors);
} }
private function get_thread_title($threadID) private function get_thread_title($threadID)
{ {
global $database; global $database;
$result = $database->get_row("SELECT t.title FROM forum_threads AS t WHERE t.id = ? ", array($threadID)); $result = $database->get_row("SELECT t.title FROM forum_threads AS t WHERE t.id = ? ", array($threadID));
return $result["title"]; return $result["title"];
} }
private function show_last_threads(Page $page, $event, $showAdminOptions = false) private function show_last_threads(Page $page, $event, $showAdminOptions = false)
{ {
global $config, $database; global $config, $database;
$pageNumber = $event->get_arg(1); $pageNumber = $event->get_arg(1);
if(is_null($pageNumber) || !is_numeric($pageNumber)) if(is_null($pageNumber) || !is_numeric($pageNumber))
$pageNumber = 0; $pageNumber = 0;
else if ($pageNumber <= 0) else if ($pageNumber <= 0)
$pageNumber = 0; $pageNumber = 0;
else else
$pageNumber--; $pageNumber--;
$threadsPerPage = $config->get_int('forumThreadsPerPage', 15); $threadsPerPage = $config->get_int('forumThreadsPerPage', 15);
$threads = $database->get_all( $threads = $database->get_all(
"SELECT f.id, f.sticky, f.title, f.date, f.uptodate, u.name AS user_name, u.email AS user_email, u.admin AS user_admin, sum(1) - 1 AS response_count ". "SELECT f.id, f.sticky, f.title, f.date, f.uptodate, u.name AS user_name, u.email AS user_email, u.admin AS user_admin, sum(1) - 1 AS response_count ".
"FROM forum_threads AS f ". "FROM forum_threads AS f ".
"INNER JOIN users AS u ". "INNER JOIN users AS u ".
"ON f.user_id = u.id ". "ON f.user_id = u.id ".
"INNER JOIN forum_posts AS p ". "INNER JOIN forum_posts AS p ".
"ON p.thread_id = f.id ". "ON p.thread_id = f.id ".
"GROUP BY f.id, f.sticky, f.title, f.date, u.name, u.email, u.admin ". "GROUP BY f.id, f.sticky, f.title, f.date, u.name, u.email, u.admin ".
"ORDER BY f.sticky ASC, f.uptodate DESC LIMIT ?, ?" "ORDER BY f.sticky ASC, f.uptodate DESC LIMIT ?, ?"
, array($pageNumber * $threadsPerPage, $threadsPerPage) , array($pageNumber * $threadsPerPage, $threadsPerPage)
); );
$totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM forum_threads") / $threadsPerPage); $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM forum_threads") / $threadsPerPage);
$this->theme->display_thread_list($page, $threads, $showAdminOptions, $pageNumber + 1, $totalPages); $this->theme->display_thread_list($page, $threads, $showAdminOptions, $pageNumber + 1, $totalPages);
} }
private function show_posts($event, $showAdminOptions = false) private function show_posts($event, $showAdminOptions = false)
{ {
global $config, $database, $user; global $config, $database, $user;
$threadID = $event->get_arg(1); $threadID = $event->get_arg(1);
$pageNumber = $event->get_arg(2); $pageNumber = $event->get_arg(2);
if(is_null($pageNumber) || !is_numeric($pageNumber)) if(is_null($pageNumber) || !is_numeric($pageNumber))
$pageNumber = 0; $pageNumber = 0;
else if ($pageNumber <= 0) else if ($pageNumber <= 0)
$pageNumber = 0; $pageNumber = 0;
else else
$pageNumber--; $pageNumber--;
$postsPerPage = $config->get_int('forumPostsPerPage', 15); $postsPerPage = $config->get_int('forumPostsPerPage', 15);
$posts = $database->get_all( $posts = $database->get_all(
"SELECT p.id, p.date, p.message, u.name as user_name, u.email AS user_email, u.admin AS user_admin ". "SELECT p.id, p.date, p.message, u.name as user_name, u.email AS user_email, u.admin AS user_admin ".
"FROM forum_posts AS p ". "FROM forum_posts AS p ".
"INNER JOIN users AS u ". "INNER JOIN users AS u ".
"ON p.user_id = u.id ". "ON p.user_id = u.id ".
"WHERE thread_id = ? ". "WHERE thread_id = ? ".
"ORDER BY p.date ASC ". "ORDER BY p.date ASC ".
"LIMIT ?, ? " "LIMIT ?, ? "
, array($threadID, $pageNumber * $postsPerPage, $postsPerPage) , array($threadID, $pageNumber * $postsPerPage, $postsPerPage)
); );
$totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM forum_posts WHERE thread_id = ?", array($threadID)) / $postsPerPage); $totalPages = ceil($database->db->GetOne("SELECT COUNT(*) FROM forum_posts WHERE thread_id = ?", array($threadID)) / $postsPerPage);
$threadTitle = $this->get_thread_title($threadID); $threadTitle = $this->get_thread_title($threadID);
$this->theme->display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber + 1, $totalPages); $this->theme->display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber + 1, $totalPages);
} }
private function save_new_thread($user) private function save_new_thread($user)
{ {
$title = mysql_real_escape_string(html_escape($_POST["title"])); $title = mysql_real_escape_string(html_escape($_POST["title"]));
$sticky = html_escape($_POST["sticky"]); $sticky = html_escape($_POST["sticky"]);
if($sticky == ""){ if($sticky == ""){
$sticky = "N"; $sticky = "N";
} }
global $database; global $database;
$database->execute(" $database->execute("
INSERT INTO forum_threads INSERT INTO forum_threads
(title, sticky, user_id, date, uptodate) (title, sticky, user_id, date, uptodate)
VALUES VALUES
(?, ?, ?, now(), now())", (?, ?, ?, now(), now())",
array($title, $sticky, $user->id)); array($title, $sticky, $user->id));
$result = $database->get_row("SELECT LAST_INSERT_ID() AS threadID", array()); $result = $database->get_row("SELECT LAST_INSERT_ID() AS threadID", array());
log_info("forum", "Thread {$result["threadID"]} created by {$user->name}"); log_info("forum", "Thread {$result["threadID"]} created by {$user->name}");
return $result["threadID"]; return $result["threadID"];
} }
private function save_new_post($threadID, $user) private function save_new_post($threadID, $user)
{ {
global $config; global $config;
$userID = $user->id; $userID = $user->id;
$message = mysql_real_escape_string(html_escape($_POST["message"])); $message = mysql_real_escape_string(html_escape($_POST["message"]));
$max_characters = $config->get_int('forumMaxCharsPerPost'); $max_characters = $config->get_int('forumMaxCharsPerPost');
$message = substr($message, 0, $max_characters); $message = substr($message, 0, $max_characters);
global $database; global $database;
$database->execute("INSERT INTO forum_posts $database->execute("INSERT INTO forum_posts
(thread_id, user_id, date, message) (thread_id, user_id, date, message)
VALUES VALUES
(?, ?, now(), ?)" (?, ?, now(), ?)"
, array($threadID, $userID, $message)); , array($threadID, $userID, $message));
$result = $database->get_row("SELECT LAST_INSERT_ID() AS postID", array()); $result = $database->get_row("SELECT LAST_INSERT_ID() AS postID", array());
log_info("forum", "Post {$result["postID"]} created by {$user->name}"); log_info("forum", "Post {$result["postID"]} created by {$user->name}");
$database->execute("UPDATE forum_threads SET uptodate=now() WHERE id=?", array ($threadID)); $database->execute("UPDATE forum_threads SET uptodate=now() WHERE id=?", array ($threadID));
} }
private function retrieve_posts($threadID, $pageNumber) private function retrieve_posts($threadID, $pageNumber)
{ {
global $database, $config; global $database, $config;
$postsPerPage = $config->get_int('forumPostsPerPage', 15); $postsPerPage = $config->get_int('forumPostsPerPage', 15);
return $database->get_all( return $database->get_all(
"SELECT p.id, p.date, p.message, u.name as user_name, u.email AS user_email, u.admin AS user_admin ". "SELECT p.id, p.date, p.message, u.name as user_name, u.email AS user_email, u.admin AS user_admin ".
"FROM forum_posts AS p ". "FROM forum_posts AS p ".
"INNER JOIN users AS u ". "INNER JOIN users AS u ".
"ON p.user_id = u.id ". "ON p.user_id = u.id ".
"WHERE thread_id = ? ". "WHERE thread_id = ? ".
"ORDER BY p.date ASC ". "ORDER BY p.date ASC ".
"LIMIT ?, ? " "LIMIT ?, ? "
, array($threadID, ($pageNumber - 1) * $postsPerPage, $postsPerPage)); , array($threadID, ($pageNumber - 1) * $postsPerPage, $postsPerPage));
} }
private function delete_thread($threadID) private function delete_thread($threadID)
{ {
global $database; global $database;
$database->execute("DELETE FROM forum_threads WHERE id = ?", array($threadID)); $database->execute("DELETE FROM forum_threads WHERE id = ?", array($threadID));
$database->execute("DELETE FROM forum_posts WHERE thread_id = ?", array($threadID)); $database->execute("DELETE FROM forum_posts WHERE thread_id = ?", array($threadID));
} }
private function delete_post($postID) private function delete_post($postID)
{ {
global $database; global $database;
$database->execute("DELETE FROM forum_posts WHERE id = ?", array($postID)); $database->execute("DELETE FROM forum_posts WHERE id = ?", array($postID));
} }
} }
?> ?>

View File

@ -1,229 +1,229 @@
<?php <?php
class ForumTheme extends Themelet { class ForumTheme extends Themelet {
public function display_thread_list(Page $page, $threads, $showAdminOptions, $pageNumber, $totalPages) public function display_thread_list(Page $page, $threads, $showAdminOptions, $pageNumber, $totalPages)
{ {
if (count($threads) == 0) if (count($threads) == 0)
$html = "There are no threads to show."; $html = "There are no threads to show.";
else else
$html = $this->make_thread_list($threads, $showAdminOptions); $html = $this->make_thread_list($threads, $showAdminOptions);
$page->set_title(html_escape("Forum")); $page->set_title(html_escape("Forum"));
$page->set_heading(html_escape("Forum")); $page->set_heading(html_escape("Forum"));
$page->add_block(new Block("Forum", $html, "main", 10)); $page->add_block(new Block("Forum", $html, "main", 10));
$this->display_paginator($page, "forum/index", null, $pageNumber, $totalPages); $this->display_paginator($page, "forum/index", null, $pageNumber, $totalPages);
} }
public function display_new_thread_composer(Page $page, $threadText = null, $threadTitle = null) public function display_new_thread_composer(Page $page, $threadText = null, $threadTitle = null)
{ {
global $config, $user; global $config, $user;
$max_characters = $config->get_int('forumMaxCharsPerPost'); $max_characters = $config->get_int('forumMaxCharsPerPost');
$postUrl = make_link("forum/create"); $postUrl = make_link("forum/create");
$html = '<form action="'.$postUrl.'" method="POST">'; $html = '<form action="'.$postUrl.'" method="POST">';
if (!is_null($threadTitle)) if (!is_null($threadTitle))
$threadTitle = html_escape($threadTitle); $threadTitle = html_escape($threadTitle);
if(!is_null($threadText)) if(!is_null($threadText))
$threadText = html_escape($threadText); $threadText = html_escape($threadText);
$html .= " $html .= "
<table style='width: 500px;'> <table style='width: 500px;'>
<tr><td>Title:</td><td><input type='text' name='title' value='$threadTitle'></td></tr> <tr><td>Title:</td><td><input type='text' name='title' value='$threadTitle'></td></tr>
<tr><td>Message:</td><td><textarea id='message' name='message' >$threadText</textarea></td></tr> <tr><td>Message:</td><td><textarea id='message' name='message' >$threadText</textarea></td></tr>
<tr><td></td><td><small>Max characters alowed: $max_characters.</small></td></tr>"; <tr><td></td><td><small>Max characters alowed: $max_characters.</small></td></tr>";
if($user->is_admin()){ if($user->is_admin()){
$html .= "<tr><td colspan='2'><label for='sticky'>Sticky:</label><input name='sticky' type='checkbox' value='Y' /></td></tr>"; $html .= "<tr><td colspan='2'><label for='sticky'>Sticky:</label><input name='sticky' type='checkbox' value='Y' /></td></tr>";
} }
$html .= "<tr><td colspan='2'><input type='submit' value='Submit' /></td></tr> $html .= "<tr><td colspan='2'><input type='submit' value='Submit' /></td></tr>
</table> </table>
</form> </form>
"; ";
$blockTitle = "Write a new thread"; $blockTitle = "Write a new thread";
$page->set_title(html_escape($blockTitle)); $page->set_title(html_escape($blockTitle));
$page->set_heading(html_escape($blockTitle)); $page->set_heading(html_escape($blockTitle));
$page->add_block(new Block($blockTitle, $html, "main", 20)); $page->add_block(new Block($blockTitle, $html, "main", 20));
} }
public function display_new_post_composer(Page $page, $threadID) public function display_new_post_composer(Page $page, $threadID)
{ {
global $config; global $config;
$max_characters = $config->get_int('forumMaxCharsPerPost'); $max_characters = $config->get_int('forumMaxCharsPerPost');
$postUrl = make_link("forum/answer"); $postUrl = make_link("forum/answer");
$html = '<form action="'.$postUrl.'" method="POST">'; $html = '<form action="'.$postUrl.'" method="POST">';
$html .= '<input type="hidden" name="threadID" value="'.$threadID.'" />'; $html .= '<input type="hidden" name="threadID" value="'.$threadID.'" />';
$html .= " $html .= "
<table style='width: 500px;'> <table style='width: 500px;'>
<tr><td>Message:</td><td><textarea id='message' name='message' ></textarea> <tr><td>Message:</td><td><textarea id='message' name='message' ></textarea>
<tr><td></td><td><small>Max characters alowed: $max_characters.</small></td></tr> <tr><td></td><td><small>Max characters alowed: $max_characters.</small></td></tr>
</td></tr>"; </td></tr>";
$html .= "<tr><td colspan='2'><input type='submit' value='Submit' /></td></tr> $html .= "<tr><td colspan='2'><input type='submit' value='Submit' /></td></tr>
</table> </table>
</form> </form>
"; ";
$blockTitle = "Answer to this thread"; $blockTitle = "Answer to this thread";
$page->add_block(new Block($blockTitle, $html, "main", 30)); $page->add_block(new Block($blockTitle, $html, "main", 30));
} }
public function display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber, $totalPages) public function display_thread($posts, $showAdminOptions, $threadTitle, $threadID, $pageNumber, $totalPages)
{ {
global $config, $page/*, $user*/; global $config, $page/*, $user*/;
$theme_name = $config->get_string('theme'); $theme_name = $config->get_string('theme');
$data_href = $config->get_string('base_href'); $data_href = $config->get_string('base_href');
$base_href = $config->get_string('base_href'); $base_href = $config->get_string('base_href');
$html = ""; $html = "";
$n = 0; $n = 0;
$html = "<table id='postList' class='zebra'>". $html = "<table id='postList' class='zebra'>".
"<thead><tr>". "<thead><tr>".
"<th>User</th>". "<th>User</th>".
"<th>Message</th>". "<th>Message</th>".
"</tr></thead>"; "</tr></thead>";
foreach ($posts as $post) foreach ($posts as $post)
{ {
$message = $post["message"]; $message = $post["message"];
$tfe = new TextFormattingEvent($message); $tfe = new TextFormattingEvent($message);
send_event($tfe); send_event($tfe);
$message = $tfe->formatted; $message = $tfe->formatted;
$message = str_replace('\n\r', '<br>', $message); $message = str_replace('\n\r', '<br>', $message);
$message = str_replace('\r\n', '<br>', $message); $message = str_replace('\r\n', '<br>', $message);
$message = str_replace('\n', '<br>', $message); $message = str_replace('\n', '<br>', $message);
$message = str_replace('\r', '<br>', $message); $message = str_replace('\r', '<br>', $message);
$message = stripslashes($message); $message = stripslashes($message);
$user = "<a href='".make_link("user/".$post["user_name"]."")."'>".$post["user_name"]."</a>"; $user = "<a href='".make_link("user/".$post["user_name"]."")."'>".$post["user_name"]."</a>";
$poster = User::by_name($post["user_name"]); $poster = User::by_name($post["user_name"]);
$gravatar = $poster->get_avatar_html(); $gravatar = $poster->get_avatar_html();
$oe = ($n++ % 2 == 0) ? "even" : "odd"; $oe = ($n++ % 2 == 0) ? "even" : "odd";
if ($post["user_admin"] == "Y") { if ($post["user_admin"] == "Y") {
$rank = "<sup>admin</sup>"; $rank = "<sup>admin</sup>";
} else { } else {
$rank = "<sup>user</sup>"; $rank = "<sup>user</sup>";
} }
$postID = $post['id']; $postID = $post['id'];
//if($user->is_admin()){ //if($user->is_admin()){
//$delete_link = "<a href=".make_link("forum/delete/".$threadID."/".$postID).">Delete</a>"; //$delete_link = "<a href=".make_link("forum/delete/".$threadID."/".$postID).">Delete</a>";
//} else { //} else {
//$delete_link = ""; //$delete_link = "";
//} //}
if($showAdminOptions){ if($showAdminOptions){
$delete_link = "<a href=".make_link("forum/delete/".$threadID."/".$postID).">Delete</a>"; $delete_link = "<a href=".make_link("forum/delete/".$threadID."/".$postID).">Delete</a>";
}else{ }else{
$delete_link = ""; $delete_link = "";
} }
$html .= "<tr class='$oe'>". $html .= "<tr class='$oe'>".
"<td class='forum_user'>".$user."<br>".$rank."<br>".$gravatar."</td>". "<td class='forum_user'>".$user."<br>".$rank."<br>".$gravatar."</td>".
"<td class='forum_message'>".$message."</td>"."</tr> "<td class='forum_message'>".$message."</td>"."</tr>
<tr class='$oe'> <tr class='$oe'>
<td class='forum_subuser'><small>".autodate($post["date"])."</small></td> <td class='forum_subuser'><small>".autodate($post["date"])."</small></td>
<td class='forum_submessage'>".$delete_link."</td> <td class='forum_submessage'>".$delete_link."</td>
</tr>"; </tr>";
} }
$html .= "</tbody></table>"; $html .= "</tbody></table>";
$this->display_paginator($page, "forum/view/".$threadID, null, $pageNumber, $totalPages); $this->display_paginator($page, "forum/view/".$threadID, null, $pageNumber, $totalPages);
$page->set_title(html_escape($threadTitle)); $page->set_title(html_escape($threadTitle));
$page->set_heading(html_escape($threadTitle)); $page->set_heading(html_escape($threadTitle));
$page->add_block(new Block("Thread", $html, "main", 20)); $page->add_block(new Block("Thread", $html, "main", 20));
} }
public function add_actions_block(Page $page, $threadID) public function add_actions_block(Page $page, $threadID)
{ {
$html = '<a href="'.make_link("forum/nuke/".$threadID).'">Delete this thread and its posts.</a>'; $html = '<a href="'.make_link("forum/nuke/".$threadID).'">Delete this thread and its posts.</a>';
$page->add_block(new Block("Admin Actions", $html, "main", 40)); $page->add_block(new Block("Admin Actions", $html, "main", 40));
} }
private function make_thread_list($threads, $showAdminOptions) private function make_thread_list($threads, $showAdminOptions)
{ {
$html = "<table id='threadList' class='zebra'>". $html = "<table id='threadList' class='zebra'>".
"<thead><tr>". "<thead><tr>".
"<th>Title</th>". "<th>Title</th>".
"<th>Author</th>". "<th>Author</th>".
"<th>Updated</th>". "<th>Updated</th>".
"<th>Responses</th>"; "<th>Responses</th>";
if($showAdminOptions) if($showAdminOptions)
{ {
$html .= "<th>Actions</th>"; $html .= "<th>Actions</th>";
} }
$html .= "</tr></thead><tbody>"; $html .= "</tr></thead><tbody>";
$n = 0; $n = 0;
foreach($threads as $thread) foreach($threads as $thread)
{ {
$oe = ($n++ % 2 == 0) ? "even" : "odd"; $oe = ($n++ % 2 == 0) ? "even" : "odd";
global $config; global $config;
$titleSubString = $config->get_int('forumTitleSubString'); $titleSubString = $config->get_int('forumTitleSubString');
if ($titleSubString < strlen($thread["title"])) if ($titleSubString < strlen($thread["title"]))
{ {
$title = substr($thread["title"], 0, $titleSubString); $title = substr($thread["title"], 0, $titleSubString);
$title = $title."..."; $title = $title."...";
} else { } else {
$title = $thread["title"]; $title = $thread["title"];
} }
if($thread["sticky"] == "Y"){ if($thread["sticky"] == "Y"){
$sticky = "Sticky: "; $sticky = "Sticky: ";
} else { } else {
$sticky = ""; $sticky = "";
} }
$html .= "<tr class='$oe'>". $html .= "<tr class='$oe'>".
'<td class="left">'.$sticky.'<a href="'.make_link("forum/view/".$thread["id"]).'">'.$title."</a></td>". '<td class="left">'.$sticky.'<a href="'.make_link("forum/view/".$thread["id"]).'">'.$title."</a></td>".
'<td><a href="'.make_link("user/".$thread["user_name"]).'">'.$thread["user_name"]."</a></td>". '<td><a href="'.make_link("user/".$thread["user_name"]).'">'.$thread["user_name"]."</a></td>".
"<td>".autodate($thread["uptodate"])."</td>". "<td>".autodate($thread["uptodate"])."</td>".
"<td>".$thread["response_count"]."</td>"; "<td>".$thread["response_count"]."</td>";
if ($showAdminOptions) if ($showAdminOptions)
$html .= '<td><a href="'.make_link("forum/nuke/".$thread["id"]).'" title="Delete '.$title.'">Delete</a></td>'; $html .= '<td><a href="'.make_link("forum/nuke/".$thread["id"]).'" title="Delete '.$title.'">Delete</a></td>';
$html .= "</tr>"; $html .= "</tr>";
} }
$html .= "</tbody></table>"; $html .= "</tbody></table>";
return $html; return $html;
} }
} }
?> ?>

View File

@ -1,374 +1,374 @@
<?php <?php
class NotesTheme extends Themelet { class NotesTheme extends Themelet {
public function note_button($image_id) { public function note_button($image_id) {
return ' return '
<script type="text/javascript"> <script type="text/javascript">
function confirm_action() { function confirm_action() {
var r=confirm("Are You Sure?"); var r=confirm("Are You Sure?");
if (r==true) { if (r==true) {
return true; return true;
} }
else { else {
return false; return false;
} }
} }
</script> </script>
<!-- <a href="#" id="addnotelink" >Add a note</a> --> <!-- <a href="#" id="addnotelink" >Add a note</a> -->
<form action="" method=""> <form action="" method="">
<input type="button" id="addnote" value="Add Note"> <input type="button" id="addnote" value="Add Note">
<input type="hidden" name="image_id" value="'.$image_id.'"> <input type="hidden" name="image_id" value="'.$image_id.'">
</form> </form>
'; ';
} }
public function request_button($image_id) { public function request_button($image_id) {
return ' return '
<form action="'.make_link("note/add_request").'" method="POST"> <form action="'.make_link("note/add_request").'" method="POST">
<input id="noterequest" type="submit" value="Add Note Request"> <input id="noterequest" type="submit" value="Add Note Request">
<input type="hidden" name="image_id" value="'.$image_id.'"> <input type="hidden" name="image_id" value="'.$image_id.'">
</form> </form>
'; ';
} }
public function nuke_notes_button($image_id) { public function nuke_notes_button($image_id) {
return ' return '
<form action="'.make_link("note/nuke_notes").'" method="POST" "> <form action="'.make_link("note/nuke_notes").'" method="POST" ">
<input id="noterequest" type="submit" value="Nuke Notes" onclick="return confirm_action()"> <input id="noterequest" type="submit" value="Nuke Notes" onclick="return confirm_action()">
<input type="hidden" name="image_id" value="'.$image_id.'"> <input type="hidden" name="image_id" value="'.$image_id.'">
</form> </form>
'; ';
} }
public function nuke_requests_button($image_id) { public function nuke_requests_button($image_id) {
return ' return '
<form action="'.make_link("note/nuke_requests").'" method="POST"> <form action="'.make_link("note/nuke_requests").'" method="POST">
<input id="noterequest" type="submit" value="Nuke Requests" onclick="return confirm_action()"> <input id="noterequest" type="submit" value="Nuke Requests" onclick="return confirm_action()">
<input type="hidden" name="image_id" value="'.$image_id.'"> <input type="hidden" name="image_id" value="'.$image_id.'">
</form> </form>
'; ';
} }
public function search_notes_page(Page $page) { //IN DEVELOPMENT, NOT FULLY WORKING public function search_notes_page(Page $page) { //IN DEVELOPMENT, NOT FULLY WORKING
$html = '<form method="GET" action="/furpiledbeta/post/list/note="> $html = '<form method="GET" action="/furpiledbeta/post/list/note=">
<input id="search_input" type="text" name="search"/> <input id="search_input" type="text" name="search"/>
<input type="submit" style="display: none;" value="Find"/> <input type="submit" style="display: none;" value="Find"/>
</form>'; </form>';
$page->set_title(html_escape("Search Note")); $page->set_title(html_escape("Search Note"));
$page->set_heading(html_escape("Search Note")); $page->set_heading(html_escape("Search Note"));
$page->add_block(new Block("Search Note", $html, "main", 10)); $page->add_block(new Block("Search Note", $html, "main", 10));
} }
// check action POST on form // check action POST on form
public function display_note_system(Page $page, $image_id, $recovered_notes, $adminOptions) { public function display_note_system(Page $page, $image_id, $recovered_notes, $adminOptions) {
$html = "<script type='text/javascript'> $html = "<script type='text/javascript'>
notes = ["; notes = [";
foreach($recovered_notes as $note) foreach($recovered_notes as $note)
{ {
$parsedNote = $note["note"]; $parsedNote = $note["note"];
$parsedNote = str_replace("\n", "\\n", $parsedNote); $parsedNote = str_replace("\n", "\\n", $parsedNote);
$parsedNote = str_replace("\r", "\\r", $parsedNote); $parsedNote = str_replace("\r", "\\r", $parsedNote);
$html .= "{'x1':'".$note["x1"]."', ". $html .= "{'x1':'".$note["x1"]."', ".
"'y1':'".$note["y1"]."',". "'y1':'".$note["y1"]."',".
"'height':'".$note["height"]."',". "'height':'".$note["height"]."',".
"'width':'".$note["width"]."',". "'width':'".$note["width"]."',".
"'note':'".$parsedNote."',". "'note':'".$parsedNote."',".
"'note_id':'".$note["id"]. "'note_id':'".$note["id"].
"'},"; "'},";
} }
if (count($recovered_notes) > 0) if (count($recovered_notes) > 0)
{ {
substr($html, 0, strlen($html) - 1); // remove final comma substr($html, 0, strlen($html) - 1); // remove final comma
} }
$html .= "]; $html .= "];
"; ";
$html .= "$(document).ready(function() { $html .= "$(document).ready(function() {
$('#main_image').imgNotes(); //If your notes data is is not named notes pass it $('#main_image').imgNotes(); //If your notes data is is not named notes pass it
$('#cancelnote').click(function(){ $('#cancelnote').click(function(){
$('#main_image').imgAreaSelect({ hide: true }); $('#main_image').imgAreaSelect({ hide: true });
$('#noteform').hide(); $('#noteform').hide();
}); });
$('#EditCancelNote').click(function() { $('#EditCancelNote').click(function() {
$('#main_image').imgAreaSelect({ hide: true }); $('#main_image').imgAreaSelect({ hide: true });
$('#noteEditForm').hide(); $('#noteEditForm').hide();
}); });
$('#addnote').click(function(){ $('#addnote').click(function(){
$('#noteEditForm').hide(); $('#noteEditForm').hide();
$('#main_image').imgAreaSelect({ onSelectChange: showaddnote, x1: 120, y1: 90, x2: 280, y2: 210 }); $('#main_image').imgAreaSelect({ onSelectChange: showaddnote, x1: 120, y1: 90, x2: 280, y2: 210 });
return false; return false;
}); });
$('.note').click(function() { $('.note').click(function() {
$('#noteform').hide(); $('#noteform').hide();
var imgOffset = $('#main_image').offset(); var imgOffset = $('#main_image').offset();
var x1 = parseInt(this.style.left) - imgOffset.left; var x1 = parseInt(this.style.left) - imgOffset.left;
var y1 = parseInt(this.style.top) - imgOffset.top; var y1 = parseInt(this.style.top) - imgOffset.top;
var width = parseInt(this.style.width); var width = parseInt(this.style.width);
var height = parseInt(this.style.height); var height = parseInt(this.style.height);
var text = $(this).next('.notep').text().replace(/([^>]?)\\n{2}/g, '$1\\n'); var text = $(this).next('.notep').text().replace(/([^>]?)\\n{2}/g, '$1\\n');
var id = $(this).next('.notep').next('.noteID').text(); var id = $(this).next('.notep').next('.noteID').text();
$('#main_image').imgAreaSelect({ onSelectChange: showeditnote, x1: x1, y1: y1, x2: x1 + width, y2: y1 + height }); $('#main_image').imgAreaSelect({ onSelectChange: showeditnote, x1: x1, y1: y1, x2: x1 + width, y2: y1 + height });
setEditNoteData(x1, y1, width, height, text, id); setEditNoteData(x1, y1, width, height, text, id);
}); });
}); });
function showaddnote (img, area) { function showaddnote (img, area) {
imgOffset = $(img).offset(); imgOffset = $(img).offset();
form_left = parseInt(imgOffset.left) + parseInt(area.x1); form_left = parseInt(imgOffset.left) + parseInt(area.x1);
form_top = parseInt(imgOffset.top) + parseInt(area.y1) + parseInt(area.height)+5; form_top = parseInt(imgOffset.top) + parseInt(area.y1) + parseInt(area.height)+5;
$('#noteform').css({ left: form_left + 'px', top: form_top + 'px'}); $('#noteform').css({ left: form_left + 'px', top: form_top + 'px'});
$('#noteform').show(); $('#noteform').show();
$('#noteform').css('z-index', 10000); $('#noteform').css('z-index', 10000);
$('#NoteX1').val(area.x1); $('#NoteX1').val(area.x1);
$('#NoteY1').val(area.y1); $('#NoteY1').val(area.y1);
$('#NoteHeight').val(area.height); $('#NoteHeight').val(area.height);
$('#NoteWidth').val(area.width); $('#NoteWidth').val(area.width);
} }
function showeditnote (img, area) { function showeditnote (img, area) {
imgOffset = $(img).offset(); imgOffset = $(img).offset();
form_left = parseInt(imgOffset.left) + area.x1; form_left = parseInt(imgOffset.left) + area.x1;
form_top = parseInt(imgOffset.top) + area.y2; form_top = parseInt(imgOffset.top) + area.y2;
$('#noteEditForm').css({ left: form_left + 'px', top: form_top + 'px'}); $('#noteEditForm').css({ left: form_left + 'px', top: form_top + 'px'});
$('#noteEditForm').show(); $('#noteEditForm').show();
$('#noteEditForm').css('z-index', 10000); $('#noteEditForm').css('z-index', 10000);
$('#EditNoteX1').val(area.x1); $('#EditNoteX1').val(area.x1);
$('#EditNoteY1').val(area.y1); $('#EditNoteY1').val(area.y1);
$('#EditNoteHeight').val(area.height); $('#EditNoteHeight').val(area.height);
$('#EditNoteWidth').val(area.width); $('#EditNoteWidth').val(area.width);
} }
function setEditNoteData(x1, y1, width, height, text, id) function setEditNoteData(x1, y1, width, height, text, id)
{ {
$('#EditNoteX1').val(x1); $('#EditNoteX1').val(x1);
$('#EditNoteY1').val(y1); $('#EditNoteY1').val(y1);
$('#EditNoteHeight').val(height); $('#EditNoteHeight').val(height);
$('#EditNoteWidth').val(width); $('#EditNoteWidth').val(width);
$('#EditNoteNote').text(text); $('#EditNoteNote').text(text);
$('#EditNoteID').val(id); $('#EditNoteID').val(id);
$('#DeleteNoteNoteID').val(id); $('#DeleteNoteNoteID').val(id);
} }
</script> </script>
<div id='noteform'> <div id='noteform'>
<form id='NoteAddForm' action='".make_link("note/add_note")."' method='POST'> <form id='NoteAddForm' action='".make_link("note/add_note")."' method='POST'>
<input type='hidden' name='image_id' value='".$image_id."' /> <input type='hidden' name='image_id' value='".$image_id."' />
<input name='note_x1' type='hidden' value='' id='NoteX1' /> <input name='note_x1' type='hidden' value='' id='NoteX1' />
<input name='note_y1' type='hidden' value='' id='NoteY1' /> <input name='note_y1' type='hidden' value='' id='NoteY1' />
<input name='note_height' type='hidden' value='' id='NoteHeight' /> <input name='note_height' type='hidden' value='' id='NoteHeight' />
<input name='note_width' type='hidden' value='' id='NoteWidth' /> <input name='note_width' type='hidden' value='' id='NoteWidth' />
<table> <table>
<tr> <tr>
<td colspan='2'> <td colspan='2'>
<textarea name='note_text' id='NoteNote' ></textarea> <textarea name='note_text' id='NoteNote' ></textarea>
</td> </td>
</tr> </tr>
<tr> <tr>
<td><input type='submit' value='Add Note' /></td> <td><input type='submit' value='Add Note' /></td>
<td><input type='button' value='Cancel' id='cancelnote' /></td> <td><input type='button' value='Cancel' id='cancelnote' /></td>
</tr> </tr>
</table> </table>
</form> </form>
</div> </div>
<div id='noteEditForm'> <div id='noteEditForm'>
<form id='NoteEditForm' action='".make_link("note/edit_note")."' method='POST'> <form id='NoteEditForm' action='".make_link("note/edit_note")."' method='POST'>
<input type='hidden' name='image_id' value='".$image_id."' /> <input type='hidden' name='image_id' value='".$image_id."' />
<input type='hidden' name='note_id' id='EditNoteID' value='' /> <input type='hidden' name='note_id' id='EditNoteID' value='' />
<input name='note_x1' type='hidden' value='' id='EditNoteX1' /> <input name='note_x1' type='hidden' value='' id='EditNoteX1' />
<input name='note_y1' type='hidden' value='' id='EditNoteY1' /> <input name='note_y1' type='hidden' value='' id='EditNoteY1' />
<input name='note_height' type='hidden' value='' id='EditNoteHeight' /> <input name='note_height' type='hidden' value='' id='EditNoteHeight' />
<input name='note_width' type='hidden' value='' id='EditNoteWidth' /> <input name='note_width' type='hidden' value='' id='EditNoteWidth' />
<table> <table>
<tr> <tr>
<td colspan='2'> <td colspan='2'>
<textarea name='note_text' id='EditNoteNote' ></textarea> <textarea name='note_text' id='EditNoteNote' ></textarea>
</td> </td>
</tr> </tr>
<tr> <tr>
<td><input type='submit' value='Save Note' /></td> <td><input type='submit' value='Save Note' /></td>
<td><input type='button' value='Cancel' id='EditCancelNote' /></td> <td><input type='button' value='Cancel' id='EditCancelNote' /></td>
</tr> </tr>
</table> </table>
</form>"; </form>";
if($adminOptions) if($adminOptions)
$html .= " $html .= "
<form id='NoteDeleteForm' action='".make_link("note/delete_note")."' method='POST'> <form id='NoteDeleteForm' action='".make_link("note/delete_note")."' method='POST'>
<input type='hidden' name='image_id' value='".$image_id."' /> <input type='hidden' name='image_id' value='".$image_id."' />
<input type='hidden' name='note_id' value='' id='DeleteNoteNoteID' /> <input type='hidden' name='note_id' value='' id='DeleteNoteNoteID' />
<table> <table>
<tr> <tr>
<td><input type='submit' value='Delete note' /></td> <td><input type='submit' value='Delete note' /></td>
</tr> </tr>
</table> </table>
</form> </form>
"; ";
$html .= "</div>"; $html .= "</div>";
$page->add_block(new Block(null, $html, "main", 1)); $page->add_block(new Block(null, $html, "main", 1));
} }
public function display_note_list($images, $pageNumber, $totalPages) { public function display_note_list($images, $pageNumber, $totalPages) {
global $page; global $page;
$pool_images = ''; $pool_images = '';
foreach($images as $pair) { foreach($images as $pair) {
$image = $pair[0]; $image = $pair[0];
$thumb_html = $this->build_thumb_html($image); $thumb_html = $this->build_thumb_html($image);
$pool_images .= '<span class="thumb">'. $pool_images .= '<span class="thumb">'.
'<a href="$image_link">'.$thumb_html.'</a>'. '<a href="$image_link">'.$thumb_html.'</a>'.
'</span>'; '</span>';
} }
$this->display_paginator($page, "note/list", null, $pageNumber, $totalPages); $this->display_paginator($page, "note/list", null, $pageNumber, $totalPages);
$page->set_title("Notes"); $page->set_title("Notes");
$page->set_heading("Notes"); $page->set_heading("Notes");
$page->add_block(new Block("Notes", $pool_images, "main", 20)); $page->add_block(new Block("Notes", $pool_images, "main", 20));
} }
public function display_note_requests($images, $pageNumber, $totalPages) { public function display_note_requests($images, $pageNumber, $totalPages) {
global $page; global $page;
$pool_images = ''; $pool_images = '';
foreach($images as $pair) { foreach($images as $pair) {
$image = $pair[0]; $image = $pair[0];
$thumb_html = $this->build_thumb_html($image); $thumb_html = $this->build_thumb_html($image);
$pool_images .= '<span class="thumb">'. $pool_images .= '<span class="thumb">'.
'<a href="$image_link">'.$thumb_html.'</a>'. '<a href="$image_link">'.$thumb_html.'</a>'.
'</span>'; '</span>';
} }
$this->display_paginator($page, "requests/list", null, $pageNumber, $totalPages); $this->display_paginator($page, "requests/list", null, $pageNumber, $totalPages);
$page->set_title("Note Requests"); $page->set_title("Note Requests");
$page->set_heading("Note Requests"); $page->set_heading("Note Requests");
$page->add_block(new Block("Note Requests", $pool_images, "main", 20)); $page->add_block(new Block("Note Requests", $pool_images, "main", 20));
} }
public function display_histories($histories, $pageNumber, $totalPages) { public function display_histories($histories, $pageNumber, $totalPages) {
global $user, $page; global $user, $page;
$html = "<table id='poolsList' class='zebra'>". $html = "<table id='poolsList' class='zebra'>".
"<thead><tr>". "<thead><tr>".
"<th>Image</th>". "<th>Image</th>".
"<th>Note</th>". "<th>Note</th>".
"<th>Body</th>". "<th>Body</th>".
"<th>Updater</th>". "<th>Updater</th>".
"<th>Date</th>"; "<th>Date</th>";
if(!$user->is_anonymous()){ if(!$user->is_anonymous()){
$html .= "<th>Action</th>"; $html .= "<th>Action</th>";
} }
$html .= "</tr></thead>". $html .= "</tr></thead>".
"<tbody>"; "<tbody>";
$n = 0; $n = 0;
foreach($histories as $history) { foreach($histories as $history) {
$oe = ($n++ % 2 == 0) ? "even" : "odd"; $oe = ($n++ % 2 == 0) ? "even" : "odd";
$image_link = "<a href='".make_link("post/view/".$history['image_id'])."'>".$history['image_id']."</a>"; $image_link = "<a href='".make_link("post/view/".$history['image_id'])."'>".$history['image_id']."</a>";
$history_link = "<a href='".make_link("note/history/".$history['note_id'])."'>".$history['note_id'].".".$history['review_id']."</a>"; $history_link = "<a href='".make_link("note/history/".$history['note_id'])."'>".$history['note_id'].".".$history['review_id']."</a>";
$user_link = "<a href='".make_link("user/".$history['user_name'])."'>".$history['user_name']."</a>"; $user_link = "<a href='".make_link("user/".$history['user_name'])."'>".$history['user_name']."</a>";
$revert_link = "<a href='".make_link("note/revert/".$history['note_id']."/".$history['review_id'])."'>Revert</a>"; $revert_link = "<a href='".make_link("note/revert/".$history['note_id']."/".$history['review_id'])."'>Revert</a>";
$html .= "<tr class='$oe'>". $html .= "<tr class='$oe'>".
"<td>".$image_link."</td>". "<td>".$image_link."</td>".
"<td>".$history_link."</td>". "<td>".$history_link."</td>".
"<td style='text-align:left;'>".$history['note']."</td>". "<td style='text-align:left;'>".$history['note']."</td>".
"<td>".$user_link."</td>". "<td>".$user_link."</td>".
"<td>".autodate($history['date'])."</td>"; "<td>".autodate($history['date'])."</td>";
if(!$user->is_anonymous()){ if(!$user->is_anonymous()){
$html .= "<td>".$revert_link."</td>"; $html .= "<td>".$revert_link."</td>";
} }
} }
$html .= "</tr></tbody></table>"; $html .= "</tr></tbody></table>";
$page->set_title("Note Updates"); $page->set_title("Note Updates");
$page->set_heading("Note Updates"); $page->set_heading("Note Updates");
$page->add_block(new Block("Note Updates", $html, "main", 10)); $page->add_block(new Block("Note Updates", $html, "main", 10));
$this->display_paginator($page, "note/updated", null, $pageNumber, $totalPages); $this->display_paginator($page, "note/updated", null, $pageNumber, $totalPages);
} }
public function display_history($histories, $pageNumber, $totalPages) { public function display_history($histories, $pageNumber, $totalPages) {
global $user, $page; global $user, $page;
$html = "<table id='poolsList' class='zebra'>". $html = "<table id='poolsList' class='zebra'>".
"<thead><tr>". "<thead><tr>".
"<th>Image</th>". "<th>Image</th>".
"<th>Note</th>". "<th>Note</th>".
"<th>Body</th>". "<th>Body</th>".
"<th>Updater</th>". "<th>Updater</th>".
"<th>Date</th>"; "<th>Date</th>";
if(!$user->is_anonymous()){ if(!$user->is_anonymous()){
$html .= "<th>Action</th>"; $html .= "<th>Action</th>";
} }
$html .= "</tr></thead>". $html .= "</tr></thead>".
"<tbody>"; "<tbody>";
$n = 0; $n = 0;
foreach($histories as $history) { foreach($histories as $history) {
$oe = ($n++ % 2 == 0) ? "even" : "odd"; $oe = ($n++ % 2 == 0) ? "even" : "odd";
$image_link = "<a href='".make_link("post/view/".$history['image_id'])."'>".$history['image_id']."</a>"; $image_link = "<a href='".make_link("post/view/".$history['image_id'])."'>".$history['image_id']."</a>";
$history_link = "<a href='".make_link("note/history/".$history['note_id'])."'>".$history['note_id'].".".$history['review_id']."</a>"; $history_link = "<a href='".make_link("note/history/".$history['note_id'])."'>".$history['note_id'].".".$history['review_id']."</a>";
$user_link = "<a href='".make_link("user/".$history['user_name'])."'>".$history['user_name']."</a>"; $user_link = "<a href='".make_link("user/".$history['user_name'])."'>".$history['user_name']."</a>";
$revert_link = "<a href='".make_link("note/revert/".$history['note_id']."/".$history['review_id'])."'>Revert</a>"; $revert_link = "<a href='".make_link("note/revert/".$history['note_id']."/".$history['review_id'])."'>Revert</a>";
$html .= "<tr class='$oe'>". $html .= "<tr class='$oe'>".
"<td>".$image_link."</td>". "<td>".$image_link."</td>".
"<td>".$history_link."</td>". "<td>".$history_link."</td>".
"<td style='text-align:left;'>".$history['note']."</td>". "<td style='text-align:left;'>".$history['note']."</td>".
"<td>".$user_link."</td>". "<td>".$user_link."</td>".
"<td>".autodate($history['date'])."</td>"; "<td>".autodate($history['date'])."</td>";
if(!$user->is_anonymous()){ if(!$user->is_anonymous()){
$html .= "<td>".$revert_link."</td>"; $html .= "<td>".$revert_link."</td>";
} }
} }
$html .= "</tr></tbody></table>"; $html .= "</tr></tbody></table>";
$page->set_title("Note History"); $page->set_title("Note History");
$page->set_heading("Note History"); $page->set_heading("Note History");
$page->add_block(new Block("Note History", $html, "main", 10)); $page->add_block(new Block("Note History", $html, "main", 10));
$this->display_paginator($page, "note/updated", null, $pageNumber, $totalPages); $this->display_paginator($page, "note/updated", null, $pageNumber, $totalPages);
} }
} }
?> ?>

View File

@ -1,54 +1,54 @@
<?php <?php
/* /*
* Name: XML Sitemap * Name: XML Sitemap
* Author: Sein Kraft <mail@seinkraft.info> * Author: Sein Kraft <mail@seinkraft.info>
* License: GPLv2 * License: GPLv2
* Description: Adds sitemap.xml on request. * Description: Adds sitemap.xml on request.
* Documentation: * Documentation:
*/ */
class XMLSitemap extends SimpleExtension { class XMLSitemap extends SimpleExtension {
public function onPageRequest($event) { public function onPageRequest($event) {
if($event->page_matches("sitemap.xml")) { if($event->page_matches("sitemap.xml")) {
$images = Image::find_images(0, 50, array()); $images = Image::find_images(0, 50, array());
$this->do_xml($images); $this->do_xml($images);
} }
} }
private function do_xml($images) { private function do_xml($images) {
global $page; global $page;
$page->set_mode("data"); $page->set_mode("data");
$page->set_type("application/xml"); $page->set_type("application/xml");
$data = ""; $data = "";
foreach($images as $image) { foreach($images as $image) {
$link = make_http(make_link("post/view/{$image->id}")); $link = make_http(make_link("post/view/{$image->id}"));
$posted = date("Y-m-d", $image->posted_timestamp); $posted = date("Y-m-d", $image->posted_timestamp);
$data .= " $data .= "
<url> <url>
<loc>$link</loc> <loc>$link</loc>
<lastmod>$posted</lastmod> <lastmod>$posted</lastmod>
<changefreq>monthly</changefreq> <changefreq>monthly</changefreq>
<priority>0.8</priority> <priority>0.8</priority>
</url> </url>
"; ";
} }
$base_href = make_http(make_link("post/list")); $base_href = make_http(make_link("post/list"));
$xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?"."> $xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?".">
<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"> <urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">
<url> <url>
<loc>$base_href</loc> <loc>$base_href</loc>
<lastmod>2009-01-01</lastmod> <lastmod>2009-01-01</lastmod>
<changefreq>monthly</changefreq> <changefreq>monthly</changefreq>
<priority>1</priority> <priority>1</priority>
</url> </url>
$data $data
</urlset> </urlset>
"; ";
$page->set_data($xml); $page->set_data($xml);
} }
} }
?> ?>

View File

@ -1,219 +1,219 @@
<?php <?php
/* /*
* Name: Tag History * Name: Tag History
* Author: Bzchan <bzchan@animemahou.com> * Author: Bzchan <bzchan@animemahou.com>
* Description: Keep a record of tag changes * Description: Keep a record of tag changes
*/ */
class Tag_History implements Extension { class Tag_History implements Extension {
var $theme; var $theme;
public function receive_event(Event $event) { public function receive_event(Event $event) {
global $config, $database, $page, $user; global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof InitExtEvent)) { if(($event instanceof InitExtEvent)) {
$config->set_default_int("history_limit", -1); $config->set_default_int("history_limit", -1);
// shimmie is being installed so call install to create the table. // shimmie is being installed so call install to create the table.
if($config->get_int("ext_tag_history_version") < 3) { if($config->get_int("ext_tag_history_version") < 3) {
$this->install(); $this->install();
} }
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("tag_history")) if(($event instanceof PageRequestEvent) && $event->page_matches("tag_history"))
{ {
if($event->get_arg(0) == "revert") if($event->get_arg(0) == "revert")
{ {
// this is a request to revert to a previous version of the tags // this is a request to revert to a previous version of the tags
if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) { if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
$this->process_revert_request($_POST['revert']); $this->process_revert_request($_POST['revert']);
} }
} }
else if($event->count_args() == 1) else if($event->count_args() == 1)
{ {
// must be an attempt to view a tag history // must be an attempt to view a tag history
$image_id = int_escape($event->get_arg(0)); $image_id = int_escape($event->get_arg(0));
$this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id)); $this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id));
} }
else { else {
$this->theme->display_global_page($page, $this->get_global_tag_history()); $this->theme->display_global_page($page, $this->get_global_tag_history());
} }
} }
if(($event instanceof DisplayingImageEvent)) if(($event instanceof DisplayingImageEvent))
{ {
// handle displaying a link on the view page // handle displaying a link on the view page
$this->theme->display_history_link($page, $event->image->id); $this->theme->display_history_link($page, $event->image->id);
} }
if(($event instanceof ImageDeletionEvent)) if(($event instanceof ImageDeletionEvent))
{ {
// handle removing of history when an image is deleted // handle removing of history when an image is deleted
$this->delete_all_tag_history($event->image->id); $this->delete_all_tag_history($event->image->id);
} }
if(($event instanceof SetupBuildingEvent)) { if(($event instanceof SetupBuildingEvent)) {
$sb = new SetupBlock("Tag History"); $sb = new SetupBlock("Tag History");
$sb->add_label("Limit to "); $sb->add_label("Limit to ");
$sb->add_int_option("history_limit"); $sb->add_int_option("history_limit");
$sb->add_label(" entires per image"); $sb->add_label(" entires per image");
$sb->add_label("<br>(-1 for unlimited)"); $sb->add_label("<br>(-1 for unlimited)");
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
if(($event instanceof TagSetEvent)) { if(($event instanceof TagSetEvent)) {
$this->add_tag_history($event->image, $event->tags); $this->add_tag_history($event->image, $event->tags);
} }
} }
protected function install() protected function install()
{ {
global $database; global $database;
global $config; global $config;
if($config->get_int("ext_tag_history_version") < 1) { if($config->get_int("ext_tag_history_version") < 1) {
$database->create_table("tag_histories", " $database->create_table("tag_histories", "
id SCORE_AIPK, id SCORE_AIPK,
image_id INTEGER NOT NULL, image_id INTEGER NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
user_ip SCORE_INET NOT NULL, user_ip SCORE_INET NOT NULL,
tags TEXT NOT NULL, tags TEXT NOT NULL,
date_set DATETIME NOT NULL, date_set DATETIME NOT NULL,
INDEX(image_id), INDEX(image_id),
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
"); ");
$config->set_int("ext_tag_history_version", 3); $config->set_int("ext_tag_history_version", 3);
} }
if($config->get_int("ext_tag_history_version") == 1) { if($config->get_int("ext_tag_history_version") == 1) {
$database->Execute("ALTER TABLE tag_histories ADD COLUMN user_id INTEGER NOT NULL"); $database->Execute("ALTER TABLE tag_histories ADD COLUMN user_id INTEGER NOT NULL");
$database->Execute("ALTER TABLE tag_histories ADD COLUMN date_set DATETIME NOT NULL"); $database->Execute("ALTER TABLE tag_histories ADD COLUMN date_set DATETIME NOT NULL");
$config->set_int("ext_tag_history_version", 2); $config->set_int("ext_tag_history_version", 2);
} }
if($config->get_int("ext_tag_history_version") == 2) { if($config->get_int("ext_tag_history_version") == 2) {
$database->Execute("ALTER TABLE tag_histories ADD COLUMN user_ip CHAR(15) NOT NULL"); $database->Execute("ALTER TABLE tag_histories ADD COLUMN user_ip CHAR(15) NOT NULL");
$config->set_int("ext_tag_history_version", 3); $config->set_int("ext_tag_history_version", 3);
} }
} }
/* /*
* this function is called when a revert request is received * this function is called when a revert request is received
*/ */
private function process_revert_request($revert_id) private function process_revert_request($revert_id)
{ {
global $page; global $page;
// check for the nothing case // check for the nothing case
if($revert_id=="nothing") if($revert_id=="nothing")
{ {
// tried to set it too the same thing so ignore it (might be a bot) // tried to set it too the same thing so ignore it (might be a bot)
// go back to the index page with you // go back to the index page with you
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link()); $page->set_redirect(make_link());
return; return;
} }
$revert_id = int_escape($revert_id); $revert_id = int_escape($revert_id);
// lets get this revert id assuming it exists // lets get this revert id assuming it exists
$result = $this->get_tag_history_from_revert($revert_id); $result = $this->get_tag_history_from_revert($revert_id);
if($result==null) if($result==null)
{ {
// there is no history entry with that id so either the image was deleted // there is no history entry with that id so either the image was deleted
// while the user was viewing the history, someone is playing with form // while the user was viewing the history, someone is playing with form
// variables or we have messed up in code somewhere. // variables or we have messed up in code somewhere.
die("Error: No tag history with specified id was found."); die("Error: No tag history with specified id was found.");
} }
// lets get the values out of the result // lets get the values out of the result
$stored_result_id = $result->fields['id']; $stored_result_id = $result->fields['id'];
$stored_image_id = $result->fields['image_id']; $stored_image_id = $result->fields['image_id'];
$stored_tags = $result->fields['tags']; $stored_tags = $result->fields['tags'];
// all should be ok so we can revert by firing the SetUserTags event. // all should be ok so we can revert by firing the SetUserTags event.
send_event(new TagSetEvent(Image::by_id($stored_image_id), $stored_tags)); send_event(new TagSetEvent(Image::by_id($stored_image_id), $stored_tags));
// all should be done now so redirect the user back to the image // all should be done now so redirect the user back to the image
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$stored_image_id")); $page->set_redirect(make_link("post/view/$stored_image_id"));
} }
public function get_tag_history_from_revert($revert_id) public function get_tag_history_from_revert($revert_id)
{ {
global $database; global $database;
$row = $database->execute(" $row = $database->execute("
SELECT tag_histories.*, users.name SELECT tag_histories.*, users.name
FROM tag_histories FROM tag_histories
JOIN users ON tag_histories.user_id = users.id JOIN users ON tag_histories.user_id = users.id
WHERE tag_histories.id = ?", array($revert_id)); WHERE tag_histories.id = ?", array($revert_id));
return ($row ? $row : null); return ($row ? $row : null);
} }
public function get_tag_history_from_id($image_id) public function get_tag_history_from_id($image_id)
{ {
global $database; global $database;
$row = $database->get_all(" $row = $database->get_all("
SELECT tag_histories.*, users.name SELECT tag_histories.*, users.name
FROM tag_histories FROM tag_histories
JOIN users ON tag_histories.user_id = users.id JOIN users ON tag_histories.user_id = users.id
WHERE image_id = ? WHERE image_id = ?
ORDER BY tag_histories.id DESC", ORDER BY tag_histories.id DESC",
array($image_id)); array($image_id));
return ($row ? $row : array()); return ($row ? $row : array());
} }
public function get_global_tag_history() public function get_global_tag_history()
{ {
global $database; global $database;
$row = $database->get_all(" $row = $database->get_all("
SELECT tag_histories.*, users.name SELECT tag_histories.*, users.name
FROM tag_histories FROM tag_histories
JOIN users ON tag_histories.user_id = users.id JOIN users ON tag_histories.user_id = users.id
ORDER BY tag_histories.id DESC ORDER BY tag_histories.id DESC
LIMIT 100"); LIMIT 100");
return ($row ? $row : array()); return ($row ? $row : array());
} }
/* /*
* this function is called when an image has been deleted * this function is called when an image has been deleted
*/ */
private function delete_all_tag_history($image_id) private function delete_all_tag_history($image_id)
{ {
global $database; global $database;
$database->execute("DELETE FROM tag_histories WHERE image_id = ?", array($image_id)); $database->execute("DELETE FROM tag_histories WHERE image_id = ?", array($image_id));
} }
/* /*
* this function is called just before an images tag are changed * this function is called just before an images tag are changed
*/ */
private function add_tag_history($image, $tags) private function add_tag_history($image, $tags)
{ {
global $database; global $database;
global $config; global $config;
global $user; global $user;
$new_tags = Tag::implode($tags); $new_tags = Tag::implode($tags);
$old_tags = Tag::implode($image->get_tag_array()); $old_tags = Tag::implode($image->get_tag_array());
if($new_tags == $old_tags) return; if($new_tags == $old_tags) return;
// add a history entry // add a history entry
$allowed = $config->get_int("history_limit"); $allowed = $config->get_int("history_limit");
if($allowed == 0) return; if($allowed == 0) return;
$row = $database->execute(" $row = $database->execute("
INSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set) INSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set)
VALUES (?, ?, ?, ?, now())", VALUES (?, ?, ?, ?, now())",
array($image->id, $new_tags, $user->id, $_SERVER['REMOTE_ADDR'])); array($image->id, $new_tags, $user->id, $_SERVER['REMOTE_ADDR']));
// if needed remove oldest one // if needed remove oldest one
if($allowed == -1) return; if($allowed == -1) return;
$entries = $database->db->GetOne("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id)); $entries = $database->db->GetOne("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id));
if($entries > $allowed) if($entries > $allowed)
{ {
// TODO: Make these queries better // TODO: Make these queries better
$min_id = $database->db->GetOne("SELECT MIN(id) FROM tag_histories WHERE image_id = ?", array($image->id)); $min_id = $database->db->GetOne("SELECT MIN(id) FROM tag_histories WHERE image_id = ?", array($image->id));
$database->execute("DELETE FROM tag_histories WHERE id = ?", array($min_id)); $database->execute("DELETE FROM tag_histories WHERE id = ?", array($min_id));
} }
} }
} }
add_event_listener(new Tag_History(), 40); // in before tags are actually set, so that "get current tags" works add_event_listener(new Tag_History(), 40); // in before tags are actually set, so that "get current tags" works
?> ?>

View File

@ -1,174 +1,174 @@
<?php <?php
/** /**
* Name: Random Tip * Name: Random Tip
* Author: Sein Kraft <mail@seinkraft.info> * Author: Sein Kraft <mail@seinkraft.info>
* License: GPLv2 * License: GPLv2
* Description: Show a random line of text in the subheader space * Description: Show a random line of text in the subheader space
* Documentation: * Documentation:
* Formatting is done with HTML * Formatting is done with HTML
*/ */
class Tips extends SimpleExtension { class Tips extends SimpleExtension {
public function onInitExt($event) { public function onInitExt($event) {
global $config, $database; global $config, $database;
if ($config->get_int("ext_tips_version") < 1){ if ($config->get_int("ext_tips_version") < 1){
$database->create_table("tips", " $database->create_table("tips", "
id SCORE_AIPK, id SCORE_AIPK,
enable SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, enable SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
image TEXT NOT NULL, image TEXT NOT NULL,
text TEXT NOT NULL, text TEXT NOT NULL,
INDEX (id) INDEX (id)
"); ");
$database->execute(" $database->execute("
INSERT INTO tips (enable, image, text) INSERT INTO tips (enable, image, text)
VALUES (?, ?, ?)", VALUES (?, ?, ?)",
array("Y", "coins.png", "Do you like this extension? Please support us for developing new ones. <a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8235933\" target=\"_blank\">Donate through paypal</a>.")); array("Y", "coins.png", "Do you like this extension? Please support us for developing new ones. <a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8235933\" target=\"_blank\">Donate through paypal</a>."));
$config->set_int("ext_tips_version", 1); $config->set_int("ext_tips_version", 1);
log_info("tips", "extension installed"); log_info("tips", "extension installed");
} }
} }
public function onPageRequest($event) { public function onPageRequest($event) {
global $page, $user; global $page, $user;
$this->getTip(); $this->getTip();
if($event->page_matches("tips")) { if($event->page_matches("tips")) {
switch($event->get_arg(0)) { switch($event->get_arg(0)) {
case "list": case "list":
{ {
if($user->is_admin()) { if($user->is_admin()) {
$this->manageTips(); $this->manageTips();
$this->getAll(); $this->getAll();
} }
break; break;
} }
case "new": case "new":
{ {
break; break;
} }
case "save": case "save":
{ {
if($user->is_admin()) { if($user->is_admin()) {
$this->saveTip(); $this->saveTip();
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("tips/list")); $page->set_redirect(make_link("tips/list"));
} }
break; break;
} }
case "status": case "status":
{ {
if($user->is_admin()) { if($user->is_admin()) {
$tipID = int_escape($event->get_arg(1)); $tipID = int_escape($event->get_arg(1));
$this->setStatus($tipID); $this->setStatus($tipID);
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("tips/list")); $page->set_redirect(make_link("tips/list"));
} }
break; break;
} }
case "delete": case "delete":
{ {
if($user->is_admin()) { if($user->is_admin()) {
$tipID = int_escape($event->get_arg(1)); $tipID = int_escape($event->get_arg(1));
$this->deleteTip($tipID); $this->deleteTip($tipID);
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("tips/list")); $page->set_redirect(make_link("tips/list"));
} }
break; break;
} }
} }
} }
} }
public function onUserBlockBuilding($event) { public function onUserBlockBuilding($event) {
global $user; global $user;
if($user->is_admin()) { if($user->is_admin()) {
$event->add_link("Tips Editor", make_link("tips/list")); $event->add_link("Tips Editor", make_link("tips/list"));
} }
} }
private function manageTips() { private function manageTips() {
$data_href = get_base_href(); $data_href = get_base_href();
$url = $data_href."/ext/tips/images/"; $url = $data_href."/ext/tips/images/";
$dirPath = dir('./ext/tips/images'); $dirPath = dir('./ext/tips/images');
$images = array(); $images = array();
while(($file = $dirPath->read()) !== false) { while(($file = $dirPath->read()) !== false) {
if($file[0] != ".") { if($file[0] != ".") {
$images[] = trim($file); $images[] = trim($file);
} }
} }
$dirPath->close(); $dirPath->close();
sort($images); sort($images);
$this->theme->manageTips($url, $images); $this->theme->manageTips($url, $images);
} }
private function saveTip() { private function saveTip() {
global $database; global $database;
$enable = isset($_POST["enable"]) ? "Y" : "N"; $enable = isset($_POST["enable"]) ? "Y" : "N";
$image = html_escape($_POST["image"]); $image = html_escape($_POST["image"]);
$text = $_POST["text"]; $text = $_POST["text"];
$database->execute(" $database->execute("
INSERT INTO tips (enable, image, text) INSERT INTO tips (enable, image, text)
VALUES (?, ?, ?)", VALUES (?, ?, ?)",
array($enable, $image, $text)); array($enable, $image, $text));
} }
private function getTip() { private function getTip() {
global $database; global $database;
$data_href = get_base_href(); $data_href = get_base_href();
$url = $data_href."/ext/tips/images/"; $url = $data_href."/ext/tips/images/";
$tip = $database->get_row("SELECT * ". $tip = $database->get_row("SELECT * ".
"FROM tips ". "FROM tips ".
"WHERE enable = 'Y' ". "WHERE enable = 'Y' ".
"ORDER BY RAND() ". "ORDER BY RAND() ".
"LIMIT 1"); "LIMIT 1");
if($tip) { if($tip) {
$this->theme->showTip($url, $tip); $this->theme->showTip($url, $tip);
} }
} }
private function getAll() { private function getAll() {
global $database; global $database;
$data_href = get_base_href(); $data_href = get_base_href();
$url = $data_href."/ext/tips/images/"; $url = $data_href."/ext/tips/images/";
$tips = $database->get_all("SELECT * FROM tips ORDER BY id ASC"); $tips = $database->get_all("SELECT * FROM tips ORDER BY id ASC");
$this->theme->showAll($url, $tips); $this->theme->showAll($url, $tips);
} }
private function setStatus($tipID) { private function setStatus($tipID) {
global $database; global $database;
$tip = $database->get_row("SELECT * FROM tips WHERE id = ? ", array($tipID)); $tip = $database->get_row("SELECT * FROM tips WHERE id = ? ", array($tipID));
if($tip['enable'] == "Y") { if($tip['enable'] == "Y") {
$enable = "N"; $enable = "N";
} elseif($tip['enable'] == "N") { } elseif($tip['enable'] == "N") {
$enable = "Y"; $enable = "Y";
} }
$database->execute("UPDATE tips SET enable = ? WHERE id = ?", array ($enable, $tipID)); $database->execute("UPDATE tips SET enable = ? WHERE id = ?", array ($enable, $tipID));
} }
private function deleteTip($tipID) { private function deleteTip($tipID) {
global $database; global $database;
$database->execute("DELETE FROM tips WHERE id = ?", array($tipID)); $database->execute("DELETE FROM tips WHERE id = ?", array($tipID));
} }
} }
?> ?>

View File

@ -1,99 +1,99 @@
<?php <?php
class TipsTheme extends Themelet { class TipsTheme extends Themelet {
public function manageTips($url, $images) { public function manageTips($url, $images) {
global $page; global $page;
$select = "<select name='image'><option value=''>- Select Image -</option>"; $select = "<select name='image'><option value=''>- Select Image -</option>";
foreach($images as $image){ foreach($images as $image){
$select .= "<option style='background-image:url(".$url.$image."); background-repeat:no-repeat; padding-left:20px;' value=\"".$image."\">".$image."</option>\n"; $select .= "<option style='background-image:url(".$url.$image."); background-repeat:no-repeat; padding-left:20px;' value=\"".$image."\">".$image."</option>\n";
} }
$select .= "</select>"; $select .= "</select>";
$html = " $html = "
<form action='".make_link("tips/save")."' method='POST'> <form action='".make_link("tips/save")."' method='POST'>
<table> <table>
<tr> <tr>
<td>Enable:</td> <td>Enable:</td>
<td><input name='enable' type='checkbox' value='Y' checked/></td> <td><input name='enable' type='checkbox' value='Y' checked/></td>
</tr> </tr>
<tr> <tr>
<td>Image:</td> <td>Image:</td>
<td>{$select}</td> <td>{$select}</td>
</tr> </tr>
<tr> <tr>
<td>Message:</td> <td>Message:</td>
<td><textarea name='text'></textarea></td> <td><textarea name='text'></textarea></td>
</tr> </tr>
<tr> <tr>
<td colspan='2'><input type='submit' value='Submit' /></td> <td colspan='2'><input type='submit' value='Submit' /></td>
</tr> </tr>
</table> </table>
</form> </form>
"; ";
$page->set_title("Tips List"); $page->set_title("Tips List");
$page->set_heading("Tips List"); $page->set_heading("Tips List");
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
$page->add_block(new Block("Add Tip", $html, "main", 10)); $page->add_block(new Block("Add Tip", $html, "main", 10));
} }
public function showTip($url, $tip) { public function showTip($url, $tip) {
global $page; global $page;
$img = ""; $img = "";
if(!empty($tip['image'])) { if(!empty($tip['image'])) {
$img = "<img src=".$url.$tip['image']." /> "; $img = "<img src=".$url.$tip['image']." /> ";
} }
$html = "<div id='tips'>".$img.$tip['text']."</div>"; $html = "<div id='tips'>".$img.$tip['text']."</div>";
$page->add_block(new Block(null, $html, "subheading", 10)); $page->add_block(new Block(null, $html, "subheading", 10));
} }
public function showAll($url, $tips){ public function showAll($url, $tips){
global $user, $page; global $user, $page;
$html = "<table id='poolsList' class='zebra'>". $html = "<table id='poolsList' class='zebra'>".
"<thead><tr>". "<thead><tr>".
"<th>ID</th>". "<th>ID</th>".
"<th>Enabled</th>". "<th>Enabled</th>".
"<th>Image</th>". "<th>Image</th>".
"<th>Text</th>"; "<th>Text</th>";
if($user->is_admin()){ if($user->is_admin()){
$html .= "<th>Action</th>"; $html .= "<th>Action</th>";
} }
$html .= "</tr></thead>"; $html .= "</tr></thead>";
$n = 0; $n = 0;
foreach ($tips as $tip) foreach ($tips as $tip)
{ {
$oe = ($n++ % 2 == 0) ? "even" : "odd"; $oe = ($n++ % 2 == 0) ? "even" : "odd";
$tip_enable = ($tip['enable'] == "Y") ? "Yes" : "No"; $tip_enable = ($tip['enable'] == "Y") ? "Yes" : "No";
$set_link = "<a href='".make_link("tips/status/".$tip['id'])."'>".$tip_enable."</a>"; $set_link = "<a href='".make_link("tips/status/".$tip['id'])."'>".$tip_enable."</a>";
$html .= "<tr class='$oe'>". $html .= "<tr class='$oe'>".
"<td>".$tip['id']."</td>". "<td>".$tip['id']."</td>".
"<td>".$set_link."</td>". "<td>".$set_link."</td>".
( (
empty($tip['image']) ? empty($tip['image']) ?
"<td></td>" : "<td></td>" :
"<td><img src=".$url.$tip['image']." /></td>" "<td><img src=".$url.$tip['image']." /></td>"
). ).
"<td class='left'>".$tip['text']."</td>"; "<td class='left'>".$tip['text']."</td>";
$del_link = "<a href='".make_link("tips/delete/".$tip['id'])."'>Delete</a>"; $del_link = "<a href='".make_link("tips/delete/".$tip['id'])."'>Delete</a>";
if($user->is_admin()){ if($user->is_admin()){
$html .= "<td>".$del_link."</td>"; $html .= "<td>".$del_link."</td>";
} }
$html .= "</tr>"; $html .= "</tr>";
} }
$html .= "</tbody></table>"; $html .= "</tbody></table>";
$page->add_block(new Block("All Tips", $html, "main", 20)); $page->add_block(new Block("All Tips", $html, "main", 20));
} }
} }
?> ?>