Browse files

Commit with current version of original authors code

Previous commit used older version. This version includes updated
elements in original authors code + my theming.
  • Loading branch information...
1 parent c8dfdc0 commit 99e9c03ae28bcef19ca7a88783e21e6e6ab8c856 tveatch committed Mar 5, 2013
Showing with 43 additions and 34 deletions.
  1. +43 −34 mongodbadmin.php
View
77 mongodbadmin.php
@@ -14,7 +14,7 @@
* http://github.com/jwage/php-mongodb-admin
* http://www.twitter.com/jwage
*
- * @author Jonathan H. Wage <hide@address.com>
+ * @author Jonathan H. Wage <jonwage@gmail.com>
* @Theme Ted Veatch
*/
@@ -98,16 +98,16 @@ function linkDocumentReferences($mongo, $document)
$refDb = isset($value['$db']) ? $value['$db'] : $_REQUEST['db'];
- $document[$key]['$ref'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$refDb.'&collection='.$value['$ref'].'">'.$value['$ref'].'</a>';
+ $document[$key]['$ref'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.urlencode($refDb).'&collection='.$value['$ref'].'">'.$value['$ref'].'</a>';
if ($ref['_id'] instanceof MongoId) {
- $document[$key]['$id'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$refDb.'&collection='.$value['$ref'].'&id='.$value['$id'].'">'.$value['$id'].'</a>';
+ $document[$key]['$id'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.urlencode($refDb).'&collection='.$value['$ref'].'&id='.$value['$id'].'">'.$value['$id'].'</a>';
} else {
- $document[$key]['$id'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$refDb.'&collection='.$value['$ref'].'&id='.$value['$id'].'&custom_id=1">'.$value['$id'].'</a>';
+ $document[$key]['$id'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.urlencode($refDb).'&collection='.$value['$ref'].'&id='.$value['$id'].'&custom_id=1">'.$value['$id'].'</a>';
}
if (isset($value['$db'])) {
- $document[$key]['$db'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.$refDb.'">'.$refDb.'</a>';
+ $document[$key]['$db'] = '<a href="'.$_SERVER['PHP_SELF'].'?db='.urlencode($refDb).'">'.$refDb.'</a>';
}
} else {
$document[$key] = linkDocumentReferences($mongo, $value);
@@ -203,6 +203,9 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
$collection = $mongo->selectDB($db)->selectCollection($collection);
if (isset($_REQUEST['custom_id']) || $forceCustomId) {
+ if (is_numeric($id)) {
+ $id = (int) $id;
+ }
$document =$collection->findOne(array('_id' => $id));
} else {
$document = $collection->findOne(array('_id' => new MongoId($id)));
@@ -224,7 +227,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
}
if (isset($document['_id'])) {
- $url = $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] . '&id=' . (string) $document['_id'];
+ $url = $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] . '&id=' . (string) $document['_id'];
if ($customId) {
header('location: ' . $url . '&custom_id=true');
@@ -249,7 +252,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
$mongo->selectDB($_REQUEST['create_db'])->createCollection('__tmp_collection_');
$mongo->selectDB($_REQUEST['create_db'])->dropCollection('__tmp_collection_');
- header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['create_db']);
+ header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['create_db']));
exit;
}
@@ -260,7 +263,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
->selectDB($_REQUEST['db'])
->createCollection($_REQUEST['create_collection']);
- header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['create_collection']);
+ header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['create_collection']);
exit;
}
@@ -271,7 +274,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
->selectCollection($_REQUEST['delete_collection'])
->drop();
- header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db']);
+ header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']));
exit;
}
@@ -280,12 +283,16 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
$collection = $mongo->selectDB($_REQUEST['db'])->selectCollection($_REQUEST['collection']);
if (isset($_REQUEST['custom_id'])) {
- $collection->remove(array('_id' => $_REQUEST['delete_document']));
+ $id = $_REQUEST['delete_document'];
+ if (is_numeric($id)) {
+ $id = (int) $id;
+ }
+ $collection->remove(array('_id' => $id));
} else {
$collection->remove(array('_id' => new MongoId($_REQUEST['delete_document'])));
}
- header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection']);
+ header('location: ' . $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection']);
exit;
}
@@ -299,7 +306,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
unset($document[$_REQUEST['delete_document_field']]);
$coll->save($document);
- $url = $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] . '&id=' . (string) $document['_id'];
+ $url = $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] . '&id=' . (string) $document['_id'];
header('location: ' . $url);
exit;
}
@@ -312,7 +319,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
$document = prepareValueForMongoDB($_REQUEST['value']);
$collection->save($document);
- $url = $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] . '&id=' . (string) $document['_id'];
+ $url = $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] . '&id=' . (string) $document['_id'];
header('location: ' . $url . ($customId ? '&custom_id=1' : null));
exit;
}
@@ -348,19 +355,20 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
K0Jb/y9FXv8vRV7/L0Ve/y9FXv8vRV7/OlBl/zRJYf8vRV7/L0Ve/y9FXv8vRV7/L0Ve/y9FXv8v
RV7/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAA==" type="image/x-icon" />
- <LINK href="mongo.css" rel="stylesheet" type="text/css">
+ <LINK href="mongo.css" rel="stylesheet" type="text/css">
+
</head>
<body>
<div id="content">
- <a href="http://docs.mongodb.org"><div id="mongoLogo"></div></a>
<h1>
+ <a href="http://docs.mongodb.org"><div id="mongoLogo"></div></a>
<?php if (is_array($server)): ?>
<?php if (count($server) > 1): ?>
<select id="server" onChange="document.cookie='mongo_server='+this[this.selectedIndex].value;document.location.reload();return false;">
<?php foreach ($server as $key => $s): ?>
- <option value="<?php echo $key ?>"<?php if (isset($_COOKIE['mongo_server']) && $_COOKIE['mongo_server'] == $key): ?> selected="selected"<?php endif; ?>><?php echo $s ?></option>
+ <option value="<?php echo $key ?>"<?php if (isset($_COOKIE['mongo_server']) && $_COOKIE['mongo_server'] == $key): ?> selected="selected"<?php endif; ?>><?php echo preg_replace('/\/\/(.*):(.*)@/', '//$1:*****@', $s); ?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
@@ -405,11 +413,11 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
<?php $dbs = $mongo->listDBs() ?>
<?php foreach ($dbs['databases'] as $db): if ($db['name'] === 'local' || $db['name'] === 'admin') continue; ?>
<tr>
- <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $db['name'] ?>"><?php echo $db['name'] ?></a></td>
+ <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . urlencode($db['name']) ?>"><?php echo $db['name'] ?></a></td>
<td><?php echo count($mongo->selectDb($db['name'])->listCollections()) ?></td>
<?php if ($readOnly !== true): ?>
- <td><a href="<?php echo $_SERVER['PHP_SELF'] ?>?delete_db=<?php echo $db['name'] ?>" onClick="return confirm('Are you sure you want to delete this database?');">Delete</a></td>
+ <td><a href="<?php echo $_SERVER['PHP_SELF'] ?>?delete_db=<?php echo urlencode($db['name']) ?>" onClick="return confirm('Are you sure you want to delete this database?');">Delete</a></td>
<?php else: ?>
<td>&nbsp;</td>
<?php endif; ?>
@@ -423,7 +431,7 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
<?php if ($readOnly !== true): ?>
<div id="create_form">
- <form action="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>" method="POST">
+ <form action="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo urlencode($_REQUEST['db']) ?>" method="POST">
<label for="create_collection_field">Create Collection</label>
<input type="text" name="create_collection" id="create_collection_field" />
<input type="submit" name="create" value="Save" />
@@ -447,11 +455,11 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
<?php $collections = $mongo->selectDB($_REQUEST['db'])->listCollections() ?>
<?php foreach ($collections as $collection): ?>
<tr>
- <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $collection->getName() ?>"><?php echo $collection->getName() ?></a></td>
+ <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $collection->getName() ?>"><?php echo $collection->getName() ?></a></td>
<td><?php echo $collection->count(); ?></td>
<?php if ($readOnly !== true): ?>
- <td><a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>&delete_collection=<?php echo $collection->getName() ?>" onClick="return confirm('Are you sure you want to delete this collection?');">Delete</a></td>
+ <td><a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo urlencode($_REQUEST['db']) ?>&delete_collection=<?php echo $collection->getName() ?>" onClick="return confirm('Are you sure you want to delete this collection?');">Delete</a></td>
<?php else: ?>
<td>&nbsp;</td>
<?php endif; ?>
@@ -484,7 +492,8 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
->selectCollection($_REQUEST['collection'])
->find()
->limit($limit)
- ->skip($skip);
+ ->skip($skip)
+ ->sort(array('_id' => 1));
}
$total = $cursor->count();
@@ -498,14 +507,14 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
<h2>
<a href="<?php echo $_SERVER['PHP_SELF'] ?>">Databases</a> >>
- <a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>"><?php echo $_REQUEST['db'] ?></a> >>
+ <a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo urlencode($_REQUEST['db']) ?>"><?php echo $_REQUEST['db'] ?></a> >>
<?php echo $_REQUEST['collection'] ?> (<?php echo $cursor->count() ?> Documents)
</h2>
<?php if ($pages > 1): ?>
<div id="pager">
<?php echo $pages ?> pages. Go to page
- <input type="text" name="page" size="4" value="<?php echo $page ?>" onChange="javascript: location.href = '<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?><?php if (isset($_REQUEST['search'])): ?>&search=<?php echo urlencode($_REQUEST['search']) ?><?php endif; ?>&page=' + this.value;" />
+ <input type="text" name="page" size="4" value="<?php echo $page ?>" onChange="javascript: location.href = '<?php echo $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] ?><?php if (isset($_REQUEST['search'])): ?>&search=<?php echo urlencode($_REQUEST['search']) ?><?php endif; ?>&page=' + this.value;" />
<input type="button" name="go" value="Go" />
</div>
<?php endif; ?>
@@ -528,9 +537,9 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
<?php foreach ($cursor as $document): ?>
<tr>
<?php if (is_object($document['_id']) && $document['_id'] instanceof MongoId): ?>
- <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>&id=<?php echo (string) $document['_id'] ?>"><?php echo (string) $document['_id'] ?></a></td>
+ <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] ?>&id=<?php echo (string) $document['_id'] ?>"><?php echo (string) $document['_id'] ?></a></td>
<?php else: ?>
- <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>&id=<?php echo (string) $document['_id'] ?>&custom_id=1"><?php echo (string) $document['_id'] ?></a></td>
+ <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] ?>&id=<?php echo (string) $document['_id'] ?>&custom_id=1"><?php echo (string) $document['_id'] ?></a></td>
<?php endif; ?>
<td>
<?php
@@ -563,9 +572,9 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
?>
</td>
<?php if (is_object($document['_id']) && $document['_id'] instanceof MongoId && $readOnly !== true): ?>
- <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>&delete_document=<?php echo (string) $document['_id'] ?>" onClick="return confirm('Are you sure you want to delete this document?');">Delete</a></td>
+ <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] ?>&delete_document=<?php echo (string) $document['_id'] ?>" onClick="return confirm('Are you sure you want to delete this document?');">Delete</a></td>
<?php elseif ($readOnly !== true): ?>
- <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>&delete_document=<?php echo (string) $document['_id'] ?>&custom_id=1" onClick="return confirm('Are you sure you want to delete this document?');">Delete</a></td>
+ <td><a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] ?>&delete_document=<?php echo (string) $document['_id'] ?>&custom_id=1" onClick="return confirm('Are you sure you want to delete this document?');">Delete</a></td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
@@ -597,8 +606,8 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
<h2>
<a href="<?php echo $_SERVER['PHP_SELF'] ?>">Databases</a> >>
- <a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo $_REQUEST['db'] ?>"><?php echo $_REQUEST['db'] ?></a> >>
- <a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>"><?php echo $_REQUEST['collection'] ?></a> >>
+ <a href="<?php echo $_SERVER['PHP_SELF'] ?>?db=<?php echo urlencode($_REQUEST['db']) ?>"><?php echo $_REQUEST['db'] ?></a> >>
+ <a href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] ?>"><?php echo $_REQUEST['collection'] ?></a> >>
<?php echo $_REQUEST['id'] ?>
</h2>
<?php $document = findMongoDbDocument($_REQUEST['id'], $_REQUEST['db'], $_REQUEST['collection']); ?>
@@ -622,15 +631,15 @@ function findMongoDbDocument($id, $db, $collection, $forceCustomId = false)
<?php endif; ?>
<br/>
<?php if (is_object($document['_id']) && $document['_id'] instanceof MongoId && $readOnly !== true): ?>
- <a class="save_button" href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>&delete_document=<?php echo (string) $document['_id'] ?>" onClick="return confirm('Are you sure you want to delete this document?');">Delete</a>
+ <a class="save_button" href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] ?>&delete_document=<?php echo (string) $document['_id'] ?>" onClick="return confirm('Are you sure you want to delete this document?');">Delete</a>
<?php elseif ($readOnly !== true): ?>
- <a class="save_button" href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . $_REQUEST['db'] . '&collection=' . $_REQUEST['collection'] ?>&delete_document=<?php echo (string) $document['_id'] ?>&custom_id=1" onClick="return confirm('Are you sure you want to delete this document?');">Delete</a>
+ <a class="save_button" href="<?php echo $_SERVER['PHP_SELF'] . '?db=' . urlencode($_REQUEST['db']) . '&collection=' . $_REQUEST['collection'] ?>&delete_document=<?php echo (string) $document['_id'] ?>&custom_id=1" onClick="return confirm('Are you sure you want to delete this document?');">Delete</a>
<?php endif; ?>
<?php endif; ?>
<?php // END ACTION TEMPLATES ?>
- <p id="footer"><sapn class="footer">Created by <a href="http://www.twitter.com/jwage" target="_BLANK">Jonathan H. Wage</a> | Theme by Ted Veatch</span></p>
+ <p id="footer"><span class="footer">Created by <a href="http://www.twitter.com/jwage" target="_BLANK">Jonathan H. Wage</a> | Theme by Ted Veatch</span></p>
</div>
</body>
-</html>
+</html>

0 comments on commit 99e9c03

Please sign in to comment.