Rewind arrays before foreach loops over all the elements.

(fixed a small typo as well)
This commit is contained in:
green-ponies (jgen) 2012-02-04 15:35:21 -05:00
parent cd1f5d9ed0
commit 3b028696a0
7 changed files with 23 additions and 2 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

@ -40,6 +40,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($name=null) {
if(is_null($name)) {
reset($this->values); // rewind the array to the first element
foreach($this->values as $name => $value) {
$this->save($name);
}

View File

@ -770,6 +770,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;
@ -1002,8 +1004,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,7 @@ class Page {
// store local copy for speed.
$autocache_css = $config->get_bool("autocache_css");
$autocache_js = config->get_bool("autocache_js");
$autocache_js = $config->get_bool("autocache_js");
if (!$autocache_css && !$autocache_js) {
return false; // caching disabled
@ -396,7 +396,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

@ -152,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);
@ -188,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);
}