Permalink
Browse files

Refactor repeated function urlfilesize() into its own file.

  • Loading branch information...
1 parent 5851d65 commit 07326f1e877fd96eb05ca20813f93b9419f65d5d @rosslagerwall committed Jul 10, 2011
Showing with 34 additions and 122 deletions.
  1. +1 −24 addTopicExecute.php
  2. +1 −25 editExecute.php
  3. +1 −24 editPostExecute.php
  4. +29 −0 function.misc.php
  5. +1 −24 pmComposeExecute.php
  6. +1 −25 postExecute.php
View
25 addTopicExecute.php
@@ -14,30 +14,7 @@
include_once("class.User.php");
session_start();
- function urlfilesize($url,$thereturn)
- {
- if (substr($url,0,4)=='http')
- {
- $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
- $x = $x['content-length'];
- }
- else
- {
- $x = @filesize($url);
- }
- if (!$thereturn)
- {
- return $x;
- }
- elseif ($thereturn == 'mb')
- {
- return round($x / (1024*1024),2);
- }
- elseif ($thereturn == 'kb')
- {
- return round($x / (1024),0);
- }
- }
+ include_once("function.misc.php");
$total = trim(file_get_contents("db/topicNo.dat"));
file_put_contents("db/topicNo.dat",($total+1));
View
26 editExecute.php
@@ -14,31 +14,7 @@ function isValidEmail($email)
}
}
-
- function urlfilesize($url,$thereturn)
- {
- if (substr($url,0,4)=='http')
- {
- $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
- $x = $x['content-length'];
- }
- else
- {
- $x = @filesize($url);
- }
- if (!$thereturn)
- {
- return $x;
- }
- elseif ($thereturn == 'mb')
- {
- return round($x / (1024*1024),2);
- }
- elseif ($thereturn == 'kb')
- {
- return round($x / (1024),0);
- }
- }
+ include_once("function.misc.php");
include_once("class.User.php");
session_start();
View
25 editPostExecute.php
@@ -8,30 +8,7 @@
include_once("class.User.php");
session_start();
- function urlfilesize($url,$thereturn)
- {
- if (substr($url,0,4)=='http')
- {
- $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
- $x = $x['content-length'];
- }
- else
- {
- $x = @filesize($url);
- }
- if (!$thereturn)
- {
- return $x;
- }
- elseif ($thereturn == 'mb')
- {
- return round($x / (1024*1024),2);
- }
- elseif ($thereturn == 'kb')
- {
- return round($x / (1024),0);
- }
- }
+ include_once("function.misc.php");
$str = "";
$fileC = file("db/Topics/".$_GET['topicId']."/posts.dat",FILE_IGNORE_NEW_LINES);
View
29 function.misc.php
@@ -0,0 +1,29 @@
+<?php
+ /* Return the size of a remote url or a local file specified by $url.
+ $thereturn specifies the unit returned (either bytes "", MiB "mb" or KiB
+ "kb"). */
+ function urlfilesize($url,$thereturn)
+ {
+ if (substr($url,0,4)=='http')
+ {
+ $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
+ $x = $x['content-length'];
+ }
+ else
+ {
+ $x = @filesize($url);
+ }
+ if (!$thereturn)
+ {
+ return $x;
+ }
+ elseif ($thereturn == 'mb')
+ {
+ return round($x / (1024*1024),2);
+ }
+ elseif ($thereturn == 'kb')
+ {
+ return round($x / (1024),0);
+ }
+ }
+?>
View
25 pmComposeExecute.php
@@ -9,30 +9,7 @@
include("common.php");
- function urlfilesize($url,$thereturn)
- {
- if (substr($url,0,4)=='http')
- {
- $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
- $x = $x['content-length'];
- }
- else
- {
- $x = @filesize($url);
- }
- if (!$thereturn)
- {
- return $x;
- }
- elseif ($thereturn == 'mb')
- {
- return round($x / (1024*1024),2);
- }
- elseif ($thereturn == 'kb')
- {
- return round($x / (1024),0);
- }
- }
+ include_once("function.misc.php");
$fileC = file("db/PMs/".$_GET['userId'].".dat");
View
26 postExecute.php
@@ -1,31 +1,7 @@
<?php
$_POST['reply'] = str_replace("~","",$_POST['reply']);
- function urlfilesize($url,$thereturn)
- {
- if (substr($url,0,4)=='http')
- {
- $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
- $x = $x['content-length'];
- }
- else
- {
- $x = @filesize($url);
- }
- if (!$thereturn)
- {
- return $x;
- }
- elseif ($thereturn == 'mb')
- {
- return round($x / (1024*1024),2);
- }
- elseif ($thereturn == 'kb')
- {
- return round($x / (1024),0);
- }
- }
-
+ include_once("function.misc.php");
include_once("common.php");
$fh = fopen("db/Topics/".$_GET['topicId']."/posts.dat","a");

0 comments on commit 07326f1

Please sign in to comment.