Small code cleanup by Falk Doering:
- PHP6 forward compatibility on accessing strings - Better indenting, other cleanups on the plugin API file
This commit is contained in:
@@ -31,7 +31,7 @@ class Serendipity_Import_Pivot extends Serendipity_Import {
|
||||
$res = serendipity_fetchCategories('all');
|
||||
$ret = array(0 => NO_CATEGORY);
|
||||
if (is_array($res)) {
|
||||
foreach ($res as $v) {
|
||||
foreach ($res AS $v) {
|
||||
$ret[$v['categoryid']] = $v['category_name'];
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class Serendipity_Import_Pivot extends Serendipity_Import {
|
||||
|
||||
$i = 0;
|
||||
while (false !== ($dir = readdir($root))) {
|
||||
if ($dir{0} == '.') continue;
|
||||
if ($dir[0] == '.') continue;
|
||||
if (substr($dir, 0, 8) == 'standard') {
|
||||
printf(' · ' . CHECKING_DIRECTORY . '...<br />', $dir);
|
||||
$data = $this->unserialize($this->data['pivot_path'] . '/' . $dir . '/index-' . $dir . '.php');
|
||||
@@ -124,7 +124,7 @@ class Serendipity_Import_Pivot extends Serendipity_Import {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach($data as $entry) {
|
||||
foreach($data AS $entry) {
|
||||
$entryid = str_pad($entry['code'], 5, '0', STR_PAD_LEFT);
|
||||
|
||||
if ($i >= $max_import) {
|
||||
@@ -166,7 +166,7 @@ class Serendipity_Import_Pivot extends Serendipity_Import {
|
||||
$i++;
|
||||
|
||||
if (isset($entrydata['comments']) && count($entrydata['comments']) > 0) {
|
||||
foreach($entrydata['comments'] as $comment) {
|
||||
foreach($entrydata['comments'] AS $comment) {
|
||||
$comment = array('entry_id ' => $entry['id'],
|
||||
'parent_id' => 0,
|
||||
'timestamp' => $this->toTimestamp($comment['date']),
|
||||
|
||||
@@ -314,7 +314,7 @@ function serendipity_db_schema_import($query) {
|
||||
|
||||
$query = trim(str_replace($search, $replace, $query));
|
||||
|
||||
if ($query{0} == '@') {
|
||||
if ($query[0] == '@') {
|
||||
// Errors are expected to happen (like duplicate index creation)
|
||||
return serendipity_db_query(substr($query, 1), false, 'both', false, false, false, true);
|
||||
} else {
|
||||
|
||||
@@ -283,7 +283,7 @@ function serendipity_db_schema_import($query) {
|
||||
}
|
||||
|
||||
$query = trim(str_replace($search, $replace, $query));
|
||||
if ($query{0} == '@') {
|
||||
if ($query[0] == '@') {
|
||||
// Errors are expected to happen (like duplicate index creation)
|
||||
return serendipity_db_query(substr($query, 1), false, 'both', false, false, false, true);
|
||||
} else {
|
||||
|
||||
@@ -158,7 +158,7 @@ function serendipity_db_insert_id($table = '', $id = '') {
|
||||
$query = "SELECT currval('{$serendipity['dbPrefix']}{$table}_{$id}_seq'::text) AS {$id}";
|
||||
$res = $serendipity['dbConn']->prepare($query);
|
||||
$res->execute();
|
||||
foreach($res->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
foreach($res->fetchAll(PDO::FETCH_ASSOC) AS $row) {
|
||||
return $row[$id];
|
||||
}
|
||||
return $serendipity['dbConn']->lastInsertId();
|
||||
@@ -224,7 +224,7 @@ function &serendipity_db_query($sql, $single = false, $result_type = "both", $re
|
||||
$n = 0;
|
||||
|
||||
$rows = array();
|
||||
foreach($serendipity['dbSth']->fetchAll($result_type) as $row) {
|
||||
foreach($serendipity['dbSth']->fetchAll($result_type) AS $row) {
|
||||
if (!empty($assocKey)) {
|
||||
// You can fetch a key-associated array via the two function parameters assocKey and assocVal
|
||||
if (empty($assocVal)) {
|
||||
@@ -266,7 +266,7 @@ function serendipity_db_schema_import($query) {
|
||||
}
|
||||
|
||||
$query = trim(str_replace($search, $replace, $query));
|
||||
if ($query{0} == '@') {
|
||||
if ($query[0] == '@') {
|
||||
// Errors are expected to happen (like duplicate index creation)
|
||||
return serendipity_db_query(substr($query, 1), false, 'both', false, false, false, true);
|
||||
} else {
|
||||
|
||||
@@ -279,7 +279,7 @@ function serendipity_db_schema_import($query) {
|
||||
}
|
||||
|
||||
$query = trim(str_replace($search, $replace, $query));
|
||||
if ($query{0} == '@') {
|
||||
if ($query[0] == '@') {
|
||||
// Errors are expected to happen (like duplicate index creation)
|
||||
return serendipity_db_query(substr($query, 1), false, 'both', false, false, false, true);
|
||||
} else {
|
||||
|
||||
@@ -149,7 +149,7 @@ function serendipity_db_sqlite_fetch_array($res, $type = SQLITE_BOTH)
|
||||
}
|
||||
|
||||
/* strip any slashes, correct fieldname */
|
||||
foreach ($row as $i => $v) {
|
||||
foreach ($row AS $i => $v) {
|
||||
// TODO: If a query of the format 'SELECT a.id, b.text FROM table' is used,
|
||||
// the sqlite extension will give us key indizes 'a.id' and 'b.text'
|
||||
// instead of just 'id' and 'text' like in mysql/postgresql extension.
|
||||
@@ -339,7 +339,7 @@ function serendipity_db_schema_import($query)
|
||||
}
|
||||
|
||||
$query = trim(str_replace($search, $replace, $query));
|
||||
if ($query{0} == '@') {
|
||||
if ($query[0] == '@') {
|
||||
// Errors are expected to happen (like duplicate index creation)
|
||||
return serendipity_db_query(substr($query, 1), false, 'both', false, false, false, true);
|
||||
} else {
|
||||
|
||||
@@ -148,7 +148,7 @@ function serendipity_db_sqlite_fetch_array($res, $type = SQLITE3_BOTH)
|
||||
}
|
||||
|
||||
/* strip any slashes, correct fieldname */
|
||||
foreach ($row as $i => $v) {
|
||||
foreach ($row AS $i => $v) {
|
||||
// TODO: If a query of the format 'SELECT a.id, b.text FROM table' is used,
|
||||
// the sqlite extension will give us key indizes 'a.id' and 'b.text'
|
||||
// instead of just 'id' and 'text' like in mysql/postgresql extension.
|
||||
@@ -165,7 +165,7 @@ function serendipity_db_sqlite_fetch_array($res, $type = SQLITE3_BOTH)
|
||||
|
||||
if ($type != SQLITE3_ASSOC) {
|
||||
$i = 0;
|
||||
foreach($row as $k => $v) {
|
||||
foreach($row AS $k => $v) {
|
||||
$frow[$i] = $v;
|
||||
$i++;
|
||||
}
|
||||
@@ -350,7 +350,7 @@ function serendipity_db_schema_import($query)
|
||||
}
|
||||
|
||||
$query = trim(str_replace($search, $replace, $query));
|
||||
if ($query{0} == '@') {
|
||||
if ($query[0] == '@') {
|
||||
// Errors are expected to happen (like duplicate index creation)
|
||||
return serendipity_db_query(substr($query, 1), false, 'both', false, false, false, true);
|
||||
} else {
|
||||
|
||||
@@ -288,7 +288,7 @@ function serendipity_updateImageInDatabase($updates, $id) {
|
||||
|
||||
$i=0;
|
||||
if (sizeof($updates) > 0) {
|
||||
foreach ($updates as $k => $v) {
|
||||
foreach ($updates AS $k => $v) {
|
||||
$q[] = $k ." = '" . serendipity_db_escape_string($v) . "'";
|
||||
}
|
||||
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}images SET ". implode($q, ',') ." WHERE id = " . (int)$id . " $admin");
|
||||
@@ -339,7 +339,7 @@ function serendipity_deleteImage($id) {
|
||||
}
|
||||
|
||||
serendipity_plugin_api::hook_event('backend_media_delete', $dThumb);
|
||||
foreach($dThumb as $thumb) {
|
||||
foreach($dThumb AS $thumb) {
|
||||
$dfnThumb = $file['path'] . $file['name'] . (!empty($thumb['fthumb']) ? '.' . $thumb['fthumb'] : '') . '.' . $file['extension'];
|
||||
$dfThumb = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $dfnThumb;
|
||||
|
||||
@@ -385,7 +385,7 @@ function serendipity_fetchImages($group = false, $start = 0, $end = 20, $images
|
||||
}
|
||||
@closedir($dir);
|
||||
sort($aTempArray);
|
||||
foreach($aTempArray as $f) {
|
||||
foreach($aTempArray AS $f) {
|
||||
if (strpos($f, $serendipity['thumbSuffix']) !== false) {
|
||||
// This is a s9y thumbnail, skip it.
|
||||
continue;
|
||||
@@ -777,7 +777,7 @@ function serendipity_generateThumbs() {
|
||||
$i=0;
|
||||
$serendipity['imageList'] = serendipity_fetchImagesFromDatabase(0, 0, $total);
|
||||
|
||||
foreach ($serendipity['imageList'] as $k => $file) {
|
||||
foreach ($serendipity['imageList'] AS $k => $file) {
|
||||
$is_image = serendipity_isImage($file);
|
||||
|
||||
if ($is_image && !$file['hotlink']) {
|
||||
@@ -1507,14 +1507,14 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa
|
||||
$dprops = $keywords = array();
|
||||
if ($serendipity['parseMediaOverview']) {
|
||||
$ids = array();
|
||||
foreach ($serendipity['imageList'] as $k => $file) {
|
||||
foreach ($serendipity['imageList'] AS $k => $file) {
|
||||
$ids[] = $file['id'];
|
||||
}
|
||||
$allprops =& serendipity_fetchMediaProperties($ids);
|
||||
}
|
||||
|
||||
if (count($serendipity['imageList']) > 0) {
|
||||
foreach ($serendipity['imageList'] as $k => $file) {
|
||||
foreach ($serendipity['imageList'] AS $k => $file) {
|
||||
if (!($serendipity['authorid'] == $file['authorid'] || $file['authorid'] == '0' || serendipity_checkPermission('adminImagesViewOthers'))) {
|
||||
// This is a fail-safe continue. Basically a non-matching file should already be filtered in SQL.
|
||||
continue;
|
||||
@@ -2789,23 +2789,23 @@ function serendipity_getMediaRaw($filename) {
|
||||
|
||||
$filedata = fread($f, 2);
|
||||
|
||||
if ($filedata{0} != "\xFF") {
|
||||
if ($filedata[0] != "\xFF") {
|
||||
fclose($f);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
while (!$abort && !feof($f) && $filedata{1} != "\xD9") {
|
||||
if ((ord($filedata{1}) < 0xD0) || (ord($filedata{1}) > 0xD7)) {
|
||||
while (!$abort && !feof($f) && $filedata[1] != "\xD9") {
|
||||
if ((ord($filedata[1]) < 0xD0) || (ord($filedata[1]) > 0xD7)) {
|
||||
$ordret = fread($f, 2);
|
||||
$ordstart = ftell($f);
|
||||
$int = unpack('nsize', $ordret);
|
||||
|
||||
if (ord($filedata{1}) == 225) {
|
||||
if (ord($filedata[1]) == 225) {
|
||||
$content = fread($f, $int['size'] - 2);
|
||||
|
||||
if (substr($content, 0, 24) == 'http://ns.adobe.com/xap/') {
|
||||
$ret[] = array(
|
||||
'ord' => ord($filedata{1}),
|
||||
'ord' => ord($filedata[1]),
|
||||
'ordstart' => $ordstart,
|
||||
'int' => $int,
|
||||
'content' => $content
|
||||
@@ -2816,11 +2816,11 @@ function serendipity_getMediaRaw($filename) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($filedata{1} == "\xDA") {
|
||||
if ($filedata[1] == "\xDA") {
|
||||
$abort = true;
|
||||
} else {
|
||||
$filedata = fread($f, 2);
|
||||
if ($filedata{0} != "\xFF") {
|
||||
if ($filedata[0] != "\xFF") {
|
||||
fclose($f);
|
||||
return $ret;
|
||||
}
|
||||
@@ -3180,7 +3180,7 @@ function serendipity_moveMediaDirectory($oldDir, $newDir, $type = 'dir', $item_i
|
||||
// Rename file
|
||||
rename($renameValues[0]['from'], $renameValues[0]['to']);
|
||||
|
||||
foreach($renameValues as $renameData) {
|
||||
foreach($renameValues AS $renameData) {
|
||||
// Rename thumbnail
|
||||
rename($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . (!empty($renameData['fthumb']) ? '.' . $renameData['fthumb'] : '') . '.' . $file['extension'],
|
||||
$serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $newDir . '.' . $renameData['thumb'] . '.' . $file['extension']);
|
||||
@@ -3232,7 +3232,7 @@ function serendipity_moveMediaDirectory($oldDir, $newDir, $type = 'dir', $item_i
|
||||
// Rename file
|
||||
rename($renameValues[0]['from'], $renameValues[0]['to']);
|
||||
|
||||
foreach($renameValues as $renameData) {
|
||||
foreach($renameValues AS $renameData) {
|
||||
// Rename thumbnail
|
||||
rename($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $oldDir . $pick['name'] . (!empty($renameData['fthumb']) ? '.' . $renameData['fthumb'] : '') . '.' . $pick['extension'],
|
||||
$serendipity['serendipityPath'] . $serendipity['uploadPath'] . $newDir . $pick['name'] . '.' . $renameData['thumb'] . '.' . $pick['extension']);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user