Merge pull request #116 from green-ponies/speed_tweaks

More Speed tweaks
This commit is contained in:
Shish Moom 2012-02-07 21:53:00 -08:00
commit 3b99605521
11 changed files with 64 additions and 20 deletions

View file

@ -24,6 +24,8 @@ class FavoritesTheme extends Themelet {
$i_favorites = count($username_array);
$html = "$i_favorites people:";
reset($username_array); // rewind to first element in array.
foreach($username_array as $row) {
$username = html_escape($row);
$html .= "<br><a href='".make_link("user/$username")."'>$username</a>";

View file

@ -41,6 +41,8 @@ class LogDatabaseTheme extends Themelet {
</thead>
<tbody>\n";
$n = 0;
reset($events); // rewind to first element in array.
foreach($events as $event) {
$oe = ($n++ % 2 == 0) ? "even" : "odd";
$c = $this->pri_to_col($event['priority']);

View file

@ -41,6 +41,9 @@ class Ratings implements Extension {
while(true) {
$images = Image::find_images($n, 100, Tag::explode($_POST["query"]));
if(count($images) == 0) break;
reset($images); // rewind to first element in array.
foreach($images as $image) {
send_event(new RatingSetEvent($image, $user, $_POST['rating']));
}

View file

@ -188,6 +188,7 @@ class DatabaseConfig extends BaseConfig {
*/
public function save(/*string*/ $name=null) {
if(is_null($name)) {
reset($this->values); // rewind the array to the first element
foreach($this->values as $name => $value) {
$this->save(/*string*/ $name);
}

View file

@ -781,6 +781,8 @@ class Image {
}
}
reset($terms); // rewind to first element in array.
// turn each term into a specific type of querylet
foreach($terms as $term) {
$negative = false;
@ -1013,8 +1015,15 @@ class Tag {
}
}
/**
* This function takes a list (array) of tags and changes any tags that have aliases
*
* @param $tags Array of tags
* @return Array of tags
*/
public static function resolve_list($tags) {
$tags = Tag::explode($tags);
reset($tags); // rewind array to the first element.
$new = array();
foreach($tags as $tag) {
$new_set = explode(' ', Tag::resolve_alias($tag));

View file

@ -291,7 +291,11 @@ class Page {
{
global $config;
if (!$config->get_bool("autocache_css") && !$config->get_bool("autocache_js")) {
// store local copy for speed.
$autocache_css = $config->get_bool("autocache_css");
$autocache_js = $config->get_bool("autocache_js");
if (!$autocache_css && !$autocache_js) {
return false; // caching disabled
}
@ -309,7 +313,7 @@ class Page {
$data_href = get_base_href();
/* ----- CSS Files ----- */
if ($config->get_bool("autocache_css"))
if ($autocache_css)
{
// First get all the CSS from the lib directory
$contents_from_lib = '';
@ -376,7 +380,7 @@ class Page {
/* ----- JavaScript Files ----- */
if ($config->get_bool("autocache_js"))
if ($autocache_js)
{
$data = '';
$js_files = glob("lib/*.js");
@ -394,7 +398,7 @@ class Page {
// Minify the JS if enabled.
if ($config->get_bool("autocache_min_js")){
// not supported yet.
// TODO: add support for Minifying CSS files.
// TODO: add support for Minifying JS files.
}
// compute the MD5 sum of the concatenated JavaScript files

View file

@ -35,14 +35,17 @@ class CommentListTheme extends Themelet {
// parts for each image
$position = 10;
$comment_limit = $config->get_int("comment_list_count", 10);
$comment_captcha = $config->get_bool('comment_captcha');
foreach($images as $pair) {
$image = $pair[0];
$comments = $pair[1];
$thumb_html = $this->build_thumb_html($image);
$comment_html = "";
$comment_limit = $config->get_int("comment_list_count", 10);
$comment_count = count($comments);
if($comment_limit > 0 && $comment_count > $comment_limit) {
$hidden = $comment_count - $comment_limit;
@ -59,7 +62,7 @@ class CommentListTheme extends Themelet {
}
} else {
if ($can_post) {
if(!$config->get_bool('comment_captcha')) {
if(!$comment_captcha) {
$comment_html .= $this->build_postbox($image->id);
}
else {

View file

@ -69,23 +69,28 @@ class TagListTheme extends Themelet {
*/
public function display_popular_block(Page $page, $tag_infos) {
global $config;
// store local copies for speed.
$info_link = $config->get_string('info_link');
$tag_list_num = $config->get_bool("tag_list_numbers");
$html = "";
$n = 0;
foreach($tag_infos as $row) {
$tag = $row['tag'];
$h_tag = html_escape($tag);
$h_tag_no_underscores = str_replace("_", " ", $h_tag);
$count = $row['count'];
if($n++) $html .= "\n<br/>";
if(!is_null($config->get_string('info_link'))) {
$link = str_replace('$tag', $tag, $config->get_string('info_link'));
$html .= " <a class='tag_info_link' href='$link'>?</a>";
if(!is_null($info_link)) {
$link = str_replace('$tag', $tag, $info_link);
$html .= ' <a class="tag_info_link" href="'.$link.'">?</a>';
}
$link = $this->tag_link($row['tag']);
$html .= " <a class='tag_name' href='$link'>$h_tag_no_underscores</a>";
if($config->get_bool("tag_list_numbers")) {
$html .= " <span class='tag_count'>$count</span>";
$html .= ' <a class="tag_name" href="$link">'.$h_tag_no_underscores.'</a>';
if($tag_list_num) {
$html .= ' <span class="tag_count">'.$count.'</span>';
}
}
@ -103,19 +108,23 @@ class TagListTheme extends Themelet {
public function display_refine_block(Page $page, $tag_infos, $search) {
global $config;
// store local copy for speed.
$info_link = $config->get_string('info_link');
$html = "";
$n = 0;
foreach($tag_infos as $row) {
$tag = $row['tag'];
$h_tag = html_escape($tag);
$h_tag_no_underscores = str_replace("_", " ", $h_tag);
if($n++) $html .= "\n<br/>";
if(!is_null($config->get_string('info_link'))) {
$link = str_replace('$tag', $tag, $config->get_string('info_link'));
$html .= " <a class='tag_info_link' href='$link'>?</a>";
if(!is_null($info_link)) {
$link = str_replace('$tag', $tag, $info_link);
$html .= ' <a class="tag_info_link" href="'.$link.'">?</a>';
}
$link = $this->tag_link($row['tag']);
$html .= " <a class='tag_name' href='$link'>$h_tag_no_underscores</a>";
$html .= ' <a class="tag_name" href="'.$link.'">'.$h_tag_no_underscores.'</a>';
$html .= $this->ars($tag, $search);
}

View file

@ -58,6 +58,8 @@ class Upload extends SimpleExtension {
$this->is_full = false;
}
else {
// TODO: This size limit should be configureable by the admin...
// currently set to 100 MB
$this->is_full = $free_num < 100*1024*1024;
}
@ -150,12 +152,14 @@ class Upload extends SimpleExtension {
$tags = ''; // Tags aren't changed when uploading. Set to null to stop PHP warnings.
if(count($_FILES)) {
reset($_FILES); // rewind to first element in array.
foreach($_FILES as $file) {
$ok = $this->try_upload($file, $tags, $source, $image_id);
break; // leave the foreach loop.
}
}
else {
reset($_POST); // rewind to first element in array.
foreach($_POST as $name => $value) {
if(substr($name, 0, 3) == "url" && strlen($value) > 0) {
$ok = $this->try_transload($value, $tags, $source, $image_id);
@ -186,9 +190,11 @@ class Upload extends SimpleExtension {
$source = isset($_POST['source']) ? $_POST['source'] : null;
$ok = true;
foreach($_FILES as $file) {
reset($_FILES); // rewind to first element in array.
$ok = $ok & $this->try_upload($file, $tags, $source);
}
foreach($_POST as $name => $value) {
reset($_POST); // rewind to first element in array.
if(substr($name, 0, 3) == "url" && strlen($value) > 0) {
$ok = $ok & $this->try_transload($value, $tags, $source);
}

View file

@ -18,6 +18,7 @@ class UploadTheme extends Themelet {
$upload_list = "";
$upload_count = $config->get_int('upload_count');
for($i=0; $i<$upload_count; $i++)
{
$a=$i+1;
@ -53,7 +54,7 @@ class UploadTheme extends Themelet {
<a href='#' onclick='$js'>".
"<img src='ext/upload/minus.png' /></a>";
if($a==$config->get_int('upload_count')){
if($a == $upload_count){
$upload_list .="<img id='wrapper' src='ext/upload/plus.png' />";
}else{
$js1 = 'javascript:$(function() {

View file

@ -25,6 +25,10 @@ class CustomCommentListTheme extends CommentListTheme {
// parts for each image
$position = 10;
$comment_captcha = $config->get_bool('comment_captcha');
$comment_limit = $config->get_int("comment_list_count", 10);
foreach($images as $pair) {
$image = $pair[0];
$comments = $pair[1];
@ -42,7 +46,7 @@ class CustomCommentListTheme extends CommentListTheme {
$r = class_exists("Ratings") ? "<b>Rating</b> ".Ratings::rating_to_human($image->rating) : "";
$comment_html = "<b>Date</b> $p $s <b>User</b> $un $s $r<br><b>Tags</b> $t<p>&nbsp;";
$comment_limit = $config->get_int("comment_list_count", 10);
$comment_count = count($comments);
if($comment_limit > 0 && $comment_count > $comment_limit) {
$hidden = $comment_count - $comment_limit;
@ -57,7 +61,7 @@ class CustomCommentListTheme extends CommentListTheme {
$comment_html .= $this->build_postbox($image->id);
}
else {
if(!$config->get_bool('comment_captcha')) {
if(!$comment_captcha) {
$comment_html .= $this->build_postbox($image->id);
}
else {