loooooooads of artists refactoring and tidying

This commit is contained in:
Shish 2015-09-27 01:03:58 +01:00
parent 5d188a94cf
commit 793bc3614b
7 changed files with 938 additions and 929 deletions

2
.gitignore vendored
View file

@ -3,6 +3,8 @@ data
images images
thumbs thumbs
!lib/images !lib/images
*.phar
*.sqlite
# Created by http://www.gitignore.io # Created by http://www.gitignore.io

View file

@ -639,7 +639,7 @@ class Database {
* *
* @param string $query * @param string $query
* @param array $args * @param array $args
* @return mixed|null * @return array|null
*/ */
public function get_row($query, $args=array()) { public function get_row($query, $args=array()) {
$_start = microtime(true); $_start = microtime(true);
@ -702,7 +702,7 @@ class Database {
* Get the ID of the last inserted row. * Get the ID of the last inserted row.
* *
* @param string|null $seq * @param string|null $seq
* @return string * @return int
*/ */
public function get_last_insert_id($seq) { public function get_last_insert_id($seq) {
if($this->engine->name == "pgsql") { if($this->engine->name == "pgsql") {

View file

@ -285,17 +285,18 @@ function validate_input($inputs) {
foreach($inputs as $key => $validations) { foreach($inputs as $key => $validations) {
$flags = explode(',', $validations); $flags = explode(',', $validations);
if(in_array('optional', $flags)) { if(in_array('optional', $flags)) {
if(!isset($_POST[$key])) { if(!isset($_POST[$key]) || trim($_POST[$key]) == "") {
$outputs[$key] = null;
continue; continue;
} }
} }
if(!isset($_POST[$key]) || trim($_POST[$key]) == "") {
if(!isset($_POST[$key])) {
throw new InvalidInput("Input '$key' not set"); throw new InvalidInput("Input '$key' not set");
} }
$value = $_POST[$key]; $value = trim($_POST[$key]);
if(in_array('user_id', $flags)) { if(in_array('user_id', $flags)) {
$id = int_escape($value); $id = int_escape($value);
@ -325,11 +326,33 @@ function validate_input($inputs) {
$outputs[$key] = $value; $outputs[$key] = $value;
} }
else if(in_array('email', $flags)) { else if(in_array('email', $flags)) {
$outputs[$key] = $value; $outputs[$key] = trim($value);
} }
else if(in_array('password', $flags)) { else if(in_array('password', $flags)) {
$outputs[$key] = $value; $outputs[$key] = $value;
} }
else if(in_array('int', $flags)) {
$value = trim($value);
if(empty($value) || !is_numeric($value)) {
throw new InvalidInput("Invalid int: ".html_escape($value));
}
$outputs[$key] = (int)$value;
}
else if(in_array('string', $flags)) {
if(in_array('trim', $flags)) {
$value = trim($value);
}
if(in_array('lower', $flags)) {
$value = strtolower($value);
}
if(in_array('not-empty', $flags)) {
throw new InvalidInput("$key must not be blank");
}
if(in_array('nullify', $flags)) {
if(empty($value)) $value = null;
}
$outputs[$key] = $value;
}
else { else {
throw new InvalidInput("Unknown validation '$validations'"); throw new InvalidInput("Unknown validation '$validations'");
} }

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,7 @@ class ArtistsTheme extends Themelet {
* @param null|int $artistID * @param null|int $artistID
* @param bool $is_admin * @param bool $is_admin
*/ */
public function sidebar_options(/*string*/ $mode, $artistID=NULL, $is_admin=FALSE){ public function sidebar_options(/*string*/ $mode, $artistID=NULL, $is_admin=FALSE) {
global $page, $user; global $page, $user;
$html = ""; $html = "";
@ -77,49 +77,44 @@ class ArtistsTheme extends Themelet {
if($html) $page->add_block(new Block("Manage Artists", $html, "left", 10)); if($html) $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) {
{ global $user;
global $user;
$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']).'">
'.$user->get_auth_html().' '.$user->get_auth_html().'
<table> <table>
@ -135,113 +130,108 @@ class ArtistsTheme extends Themelet {
<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()
{
global $page, $user;
$html = "<form action=".make_link("artist/create")." method='POST'>
".$user->get_auth_html()."
<table>
<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>Members:</td><td><input type='text' name='members' /></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 colspan='2'><input type='submit' value='Submit' /></td></tr>
</table>
";
$page->set_title("Artists");
$page->set_heading("Artists");
$page->add_block(new Block("Artists", $html, "main", 10));
} }
public function list_artists($artists, $pageNumber, $totalPages) public function new_artist_composer() {
{ global $page, $user;
global $user, $page;
$html = "<table id='poolsList' class='zebra'>". $html = "<form action=".make_link("artist/create")." method='POST'>
"<thead><tr>". ".$user->get_auth_html()."
"<th>Name</th>". <table>
"<th>Type</th>". <tr><td>Name:</td><td><input type='text' name='name' /></td></tr>
"<th>Last updater</th>". <tr><td>Aliases:</td><td><input type='text' name='aliases' /></td></tr>
"<th>Posts</th>"; <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>Notes:</td><td><textarea name='notes'></textarea></td></tr>
<tr><td colspan='2'><input type='submit' value='Submit' /></td></tr>
</table>
";
$page->set_title("Artists");
$page->set_heading("Artists");
$page->add_block(new Block("Artists", $html, "main", 10));
}
public function list_artists($artists, $pageNumber, $totalPages) {
global $user, $page;
if(!$user->is_anonymous()) $html .= "<th colspan='2'>Action</th>"; // space for edit link $html = "<table id='poolsList' class='zebra'>".
"<thead><tr>".
"<th>Name</th>".
"<th>Type</th>".
"<th>Last updater</th>".
"<th>Posts</th>";
if(!$user->is_anonymous()) $html .= "<th colspan='2'>Action</th>"; // space for edit link
$html .= "</tr></thead>"; $html .= "</tr></thead>";
$deletionLinkActionArray = $deletionLinkActionArray = array(
array('artist' => 'artist/nuke/' 'artist' => 'artist/nuke/',
, 'alias' => 'artist/alias/delete/' 'alias' => 'artist/alias/delete/',
, 'member' => 'artist/member/delete/' 'member' => 'artist/member/delete/',
); );
$editionLinkActionArray = $editionLinkActionArray = array(
array('artist' => 'artist/edit/' 'artist' => 'artist/edit/',
, 'alias' => 'artist/alias/edit/' 'alias' => 'artist/alias/edit/',
, 'member' => 'artist/member/edit/' 'member' => 'artist/member/edit/',
); );
$typeTextArray = $typeTextArray = array(
array('artist' => 'Artist' 'artist' => 'Artist',
, 'alias' => 'Alias' 'alias' => 'Alias',
, 'member' => 'Member' 'member' => 'Member',
); );
foreach ($artists as $artist) { foreach ($artists as $artist) {
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>". $html .= "<tr>".
"<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) {
{ global $user;
global $user;
$html = $html = '
'<form method="POST" action='.make_link("artist/alias/add").'> <form method="POST" action='.make_link("artist/alias/add").'>
'.$user->get_auth_html().' '.$user->get_auth_html().'
<table> <table>
<tr><td>Alias:</td><td><input type="text" name="aliases" /> <tr><td>Alias:</td><td><input type="text" name="aliases" />
@ -249,277 +239,295 @@ class ArtistsTheme extends Themelet {
<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)
{
global $user;
$html = public function show_new_member_composer($artistID) {
' <form method="POST" action='.make_link("artist/member/add").'> global $user;
$html = '
<form method="POST" action='.make_link("artist/member/add").'>
'.$user->get_auth_html().' '.$user->get_auth_html().'
<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) {
{ global $user;
global $user;
$html = $html = '
' <form method="POST" action='.make_link("artist/url/add").'> <form method="POST" action='.make_link("artist/url/add").'>
'.$user->get_auth_html().' '.$user->get_auth_html().'
<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) {
{ global $user;
global $user;
$html = $html = '
' <form method="POST" action="'.make_link("artist/alias/edited/".$alias['id']).'">
<form method="POST" action="'.make_link("artist/alias/edited/".$alias['id']).'"> '.$user->get_auth_html().'
'.$user->get_auth_html().' <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) {
{ global $user;
global $user;
$html = $html = '
' <form method="POST" action="'.make_link("artist/url/edited/".$url['id']).'">
<form method="POST" action="'.make_link("artist/url/edited/".$url['id']).'"> '.$user->get_auth_html().'
'.$user->get_auth_html().' <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) {
{ global $user;
global $user;
$html = $html = '
' <form method="POST" action="'.make_link("artist/member/edited/".$member['id']).'">
<form method="POST" action="'.make_link("artist/member/edited/".$member['id']).'"> '.$user->get_auth_html().'
'.$user->get_auth_html().' <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 $page;
global $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>";
$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> <tr>
<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) {
{ $html .= $this->render_aliases($aliases, $userIsLogged, $userIsAdmin);
$aliasViewLink = str_replace("_", " ", $aliases[0]['alias_name']); // no link anymore }
$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>";
$html .= "<tr>
<td class='left'>Aliases:</td>
<td class='left'>".$aliasViewLink."</td>";
if ($userIsLogged)
$html .= "<td class='left'>".$aliasEditLink."</td>";
if ($userIsAdmin) if (count($members) > 0) {
$html .= "<td class='left'>".$aliasDeleteLink."</td>"; $html .= $this->render_members($members, $userIsLogged, $userIsAdmin);
}
$html .= "</tr>";
if (count($aliases) > 1) if (count($urls) > 0) {
{ $html .= $this->render_urls($urls, $userIsLogged, $userIsAdmin);
for ($i = 1; $i < count($aliases); $i++) }
{
$aliasViewLink = str_replace("_", " ", $aliases[$i]['alias_name']); // no link anymore
$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>";
$html .= "<tr> $html .= "<tr>
<td class='left'>&nbsp;</td>
<td class='left'>".$aliasViewLink."</td>";
if ($userIsLogged)
$html .= "<td class='left'>".$aliasEditLink."</td>";
if ($userIsAdmin)
$html .= "<td class='left'>".$aliasDeleteLink."</td>";
$html .= "</tr>";
}
}
}
if (count($members) > 0)
{
$memberViewLink = str_replace("_", " ", $members[0]['name']); // no link anymore
$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>";
$html .= "<tr>
<td class='left'>Members:</td>
<td class='left'>".$memberViewLink."</td>";
if ($userIsLogged)
$html .= "<td class='left'>".$memberEditLink."</td>";
if ($userIsAdmin)
$html .= "<td class='left'>".$memberDeleteLink."</td>";
$html .= "</tr>";
if (count($members) > 1)
{
for ($i = 1; $i < count($members); $i++)
{
$memberViewLink = str_replace("_", " ", $members[$i]['name']); // no link anymore
$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>";
$html .= "<tr>
<td class='left'>&nbsp;</td>
<td class='left'>".$memberViewLink."</td>";
if ($userIsLogged)
$html .= "<td class='left'>".$memberEditLink."</td>";
if ($userIsAdmin)
$html .= "<td class='left'>".$memberDeleteLink."</td>";
$html .= "</tr>";
}
}
}
if (count($urls) > 0)
{
$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>";
$urlDeleteLink = "<a href='".make_link("artist/url/delete/".$urls[0]['id'])."'>Delete</a>";
$html .= "<tr>
<td class='left'>URLs:</td>
<td class='left'>".$urlViewLink."</td>";
if ($userIsLogged)
$html .= "<td class='left'>".$urlEditLink."</td>";
if ($userIsAdmin)
$html .= "<td class='left'>".$urlDeleteLink."</td>";
$html .= "</tr>";
if (count($urls) > 1)
{
for ($i = 1; $i < count($urls); $i++)
{
$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>";
$urlDeleteLink = "<a href='".make_link("artist/url/delete/".$urls[$i]['id'])."'>Delete</a>";
$html .= "<tr>
<td class='left'>&nbsp;</td>
<td class='left'>".$urlViewLink."</td>";
if ($userIsLogged)
$html .= "<td class='left'>".$urlEditLink."</td>";
if ($userIsAdmin)
$html .= "<td class='left'>".$urlDeleteLink."</td>";
$html .= "</tr>";
}
}
}
$html .=
"<tr>
<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));
}
/**
* @param $aliases
* @param $userIsLogged
* @param $userIsAdmin
* @return string
*/
private function render_aliases($aliases, $userIsLogged, $userIsAdmin) {
$html = "";
$aliasViewLink = str_replace("_", " ", $aliases[0]['alias_name']); // no link anymore
$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>";
$html .= "<tr>
<td class='left'>Aliases:</td>
<td class='left'>" . $aliasViewLink . "</td>";
if ($userIsLogged)
$html .= "<td class='left'>" . $aliasEditLink . "</td>";
if ($userIsAdmin)
$html .= "<td class='left'>" . $aliasDeleteLink . "</td>";
$html .= "</tr>";
if (count($aliases) > 1) {
for ($i = 1; $i < count($aliases); $i++) {
$aliasViewLink = str_replace("_", " ", $aliases[$i]['alias_name']); // no link anymore
$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>";
$html .= "<tr>
<td class='left'>&nbsp;</td>
<td class='left'>" . $aliasViewLink . "</td>";
if ($userIsLogged)
$html .= "<td class='left'>" . $aliasEditLink . "</td>";
if ($userIsAdmin)
$html .= "<td class='left'>" . $aliasDeleteLink . "</td>";
$html .= "</tr>";
}
}
return $html;
}
/**
* @param $members
* @param $userIsLogged
* @param $userIsAdmin
* @return string
*/
private function render_members($members, $userIsLogged, $userIsAdmin) {
$html = "";
$memberViewLink = str_replace("_", " ", $members[0]['name']); // no link anymore
$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>";
$html .= "<tr>
<td class='left'>Members:</td>
<td class='left'>" . $memberViewLink . "</td>";
if ($userIsLogged)
$html .= "<td class='left'>" . $memberEditLink . "</td>";
if ($userIsAdmin)
$html .= "<td class='left'>" . $memberDeleteLink . "</td>";
$html .= "</tr>";
if (count($members) > 1) {
for ($i = 1; $i < count($members); $i++) {
$memberViewLink = str_replace("_", " ", $members[$i]['name']); // no link anymore
$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>";
$html .= "<tr>
<td class='left'>&nbsp;</td>
<td class='left'>" . $memberViewLink . "</td>";
if ($userIsLogged)
$html .= "<td class='left'>" . $memberEditLink . "</td>";
if ($userIsAdmin)
$html .= "<td class='left'>" . $memberDeleteLink . "</td>";
$html .= "</tr>";
}
}
return $html;
}
/**
* @param $urls
* @param $userIsLogged
* @param $userIsAdmin
* @return string
*/
private function render_urls($urls, $userIsLogged, $userIsAdmin) {
$html = "";
$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>";
$urlDeleteLink = "<a href='" . make_link("artist/url/delete/" . $urls[0]['id']) . "'>Delete</a>";
$html .= "<tr>
<td class='left'>URLs:</td>
<td class='left'>" . $urlViewLink . "</td>";
if ($userIsLogged)
$html .= "<td class='left'>" . $urlEditLink . "</td>";
if ($userIsAdmin)
$html .= "<td class='left'>" . $urlDeleteLink . "</td>";
$html .= "</tr>";
if (count($urls) > 1) {
for ($i = 1; $i < count($urls); $i++) {
$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>";
$urlDeleteLink = "<a href='" . make_link("artist/url/delete/" . $urls[$i]['id']) . "'>Delete</a>";
$html .= "<tr>
<td class='left'>&nbsp;</td>
<td class='left'>" . $urlViewLink . "</td>";
if ($userIsLogged)
$html .= "<td class='left'>" . $urlEditLink . "</td>";
if ($userIsAdmin)
$html .= "<td class='left'>" . $urlDeleteLink . "</td>";
$html .= "</tr>";
}
return $html;
}
return $html;
} }
} }

View file

@ -75,12 +75,12 @@ class ResizeImage extends Extension {
$isanigif = 0; $isanigif = 0;
if($image_obj->ext == "gif"){ if($image_obj->ext == "gif"){
$image_filename = warehouse_path("images", $image_obj->hash); $image_filename = warehouse_path("images", $image_obj->hash);
if(!($fh = @fopen($image_filename, 'rb'))){ //check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473) if(($fh = @fopen($image_filename, 'rb'))) {
return false; //check if gif is animated (via http://www.php.net/manual/en/function.imagecreatefromgif.php#104473)
} while(!feof($fh) && $isanigif < 2) {
while(!feof($fh) && $isanigif < 2) { $chunk = fread($fh, 1024 * 100);
$chunk = fread($fh, 1024 * 100); $isanigif += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
$isanigif += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches); }
} }
} }
if($isanigif == 0){ if($isanigif == 0){
@ -180,51 +180,15 @@ class ResizeImage extends Extension {
if (($image_obj->width != $info[0] ) || ($image_obj->height != $info[1])) { if (($image_obj->width != $info[0] ) || ($image_obj->height != $info[1])) {
throw new ImageResizeException("The current image size does not match what is set in the database! - Aborting Resize."); throw new ImageResizeException("The current image size does not match what is set in the database! - Aborting Resize.");
} }
/* $memory_use = $this->calc_memory_use($info);
Check Memory usage limits
Old check: $memory_use = (filesize($image_filename)*2) + ($width*$height*4) + (4*1024*1024);
New check: memory_use = width * height * (bits per channel) * channels * 2.5
It didn't make sense to compute the memory usage based on the NEW size for the image. ($width*$height*4)
We need to consider the size that we are GOING TO instead.
The factor of 2.5 is simply a rough guideline.
http://stackoverflow.com/questions/527532/reasonable-php-memory-limit-for-image-resize
*/
if (isset($info['bits']) && isset($info['channels']))
{
$memory_use = ($info[0] * $info[1] * ($info['bits'] / 8) * $info['channels'] * 2.5) / 1024;
} else {
//
// If we don't have bits and channel info from the image then assume default values
// of 8 bits per color and 4 channels (R,G,B,A) -- ie: regular 24-bit color
//
$memory_use = ($info[0] * $info[1] * 1 * 4 * 2.5) / 1024;
}
$memory_limit = get_memory_limit(); $memory_limit = get_memory_limit();
if ($memory_use > $memory_limit) { if ($memory_use > $memory_limit) {
throw new ImageResizeException("The image is too large to resize given the memory limits. ($memory_use > $memory_limit)"); throw new ImageResizeException("The image is too large to resize given the memory limits. ($memory_use > $memory_limit)");
} }
/* Calculate the new size of the image */
if ( $height > 0 && $width > 0 ) {
$new_height = $height;
$new_width = $width;
} else {
// Scale the new image
if ($width == 0) $factor = $height/$image_obj->height;
elseif ($height == 0) $factor = $width/$image_obj->width;
else $factor = min( $width / $image_obj->width, $height / $image_obj->height );
$new_width = round( $image_obj->width * $factor ); list($new_height, $new_width) = $this->calc_new_size($image_obj, $width, $height);
$new_height = round( $image_obj->height * $factor );
}
/* Attempt to load the image */ /* Attempt to load the image */
switch ( $info[2] ) { switch ( $info[2] ) {
case IMAGETYPE_GIF: $image = imagecreatefromgif($image_filename); break; case IMAGETYPE_GIF: $image = imagecreatefromgif($image_filename); break;
@ -303,19 +267,65 @@ class ResizeImage extends Extension {
send_event(new ThumbnailGenerationEvent($new_hash, $filetype)); send_event(new ThumbnailGenerationEvent($new_hash, $filetype));
/* Update the database */ /* Update the database */
$database->Execute( $database->Execute("
"UPDATE images SET UPDATE images SET filename = :filename, filesize = :filesize, hash = :hash, width = :width, height = :height
filename = :filename, filesize = :filesize, hash = :hash, width = :width, height = :height WHERE id = :id
WHERE ", array(
id = :id "filename"=>$new_filename, "filesize"=>$new_size, "hash"=>$new_hash,
", "width"=>$new_width, "height"=>$new_height, "id"=>$image_obj->id
array( ));
"filename"=>$new_filename, "filesize"=>$new_size, "hash"=>$new_hash,
"width"=>$new_width, "height"=>$new_height, "id"=>$image_obj->id
)
);
log_info("resize", "Resized Image #{$image_obj->id} - New hash: {$new_hash}"); log_info("resize", "Resized Image #{$image_obj->id} - New hash: {$new_hash}");
} }
/**
* Check Memory usage limits
*
* Old check: $memory_use = (filesize($image_filename)*2) + ($width*$height*4) + (4*1024*1024);
* New check: memory_use = width * height * (bits per channel) * channels * 2.5
*
* It didn't make sense to compute the memory usage based on the NEW size for the image. ($width*$height*4)
* We need to consider the size that we are GOING TO instead.
*
* The factor of 2.5 is simply a rough guideline.
* http://stackoverflow.com/questions/527532/reasonable-php-memory-limit-for-image-resize
*
* @param $info
* @return array
*/
private function calc_memory_use($info) {
if (isset($info['bits']) && isset($info['channels'])) {
return $memory_use = ($info[0] * $info[1] * ($info['bits'] / 8) * $info['channels'] * 2.5) / 1024;
}
else {
// If we don't have bits and channel info from the image then assume default values
// of 8 bits per color and 4 channels (R,G,B,A) -- ie: regular 24-bit color
return $memory_use = ($info[0] * $info[1] * 1 * 4 * 2.5) / 1024;
}
}
/**
* @param Image $image_obj
* @param $width
* @param $height
* @return array
*/
private function calc_new_size(Image $image_obj, $width, $height) {
/* Calculate the new size of the image */
if ($height > 0 && $width > 0) {
$new_height = $height;
$new_width = $width;
return array($new_height, $new_width);
} else {
// Scale the new image
if ($width == 0) $factor = $height / $image_obj->height;
elseif ($height == 0) $factor = $width / $image_obj->width;
else $factor = min($width / $image_obj->width, $height / $image_obj->height);
$new_width = round($image_obj->width * $factor);
$new_height = round($image_obj->height * $factor);
return array($new_height, $new_width);
}
}
} }

9
tests/test-deep.sh Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
php \
-d extension.dir=/usr/lib/php/extensions/no-debug-non-zts-20121212/ \
-d extension=xdebug.so \
-d xdebug.profiler_output_dir=./data/prof/ \
-d xdebug.profiler_enable=1 \
./phpunit.phar \
--config tests/phpunit.xml \
--coverage-clover data/coverage.clover