* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
-define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
+require (JIRAFEAU_ROOT.'lib/config.php');
+require (JIRAFEAU_ROOT.'lib/settings.php');
+require (JIRAFEAU_ROOT.'lib/functions.php');
-require(JIRAFEAU_ROOT . 'lib/config.php');
-require(JIRAFEAU_ROOT . 'lib/settings.php');
-require(JIRAFEAU_ROOT . 'lib/functions.php');
+if (isset ($_GET['h']) && !empty ($_GET['h']))
+{
+ $link_name = $_GET['h'];
-if(isset($_GET['h']) && !empty($_GET['h'])) {
- $link_name = $_GET['h'];
+ $delete_code = '';
+ if (isset ($_GET['d']) && !empty ($_GET['d']))
+ $delete_code = $_GET['d'];
- $delete_code = '';
- if(isset($_GET['d']) && !empty($_GET['d']))
- $delete_code = $_GET['d'];
+ if (!ereg ('[0-9a-f]{32}$', $link_name))
+ {
+ header ("HTTP/1.0 404 Not Found");
- if(!ereg('[0-9a-f]{32}$', $link_name)) {
- header("HTTP/1.0 404 Not Found");
-
- require(JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '<div class="error"><p>Error 404: Not Found</p></div>';
- require(JIRAFEAU_ROOT . 'lib/template/footer.php');
- exit;
- }
-
- $link_file = VAR_LINKS . $link_name;
- if(file_exists($link_file)) {
- $content = file($link_file);
- $file_name = trim($content[0]);
- $mime_type = trim($content[1]);
- $file_size = trim($content[2]);
- $key = trim($content[3], NL);
- $time = trim($content[4]);
- $md5 = trim($content[5]);
- $onetime = trim($content[6]);
- $link_code = trim($content[9]);
-
-
-
- if(!file_exists(VAR_FILES . $md5)) {
- jirafeau_delete($link_name);
- require(JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '<div class="error"><p>' . _('File not available.') . '</p></div>';
- require(JIRAFEAU_ROOT . 'lib/template/footer.php');
- exit;
+ require (JIRAFEAU_ROOT.'lib/template/header.php');
+ echo '<div class="error"><p>Error 404: Not Found</p></div>';
+ require (JIRAFEAU_ROOT.'lib/template/footer.php');
+ exit;
}
- if(!empty($delete_code) && $delete_code == $link_code) {
- jirafeau_delete($link_name);
- require(JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '<div class="message"><p>' . _('File has been deleted.') . '</p></div>';
- require(JIRAFEAU_ROOT . 'lib/template/footer.php');
- exit;
- }
+ $link_file = VAR_LINKS.$link_name;
+ if (file_exists ($link_file))
+ {
+ $content = file ($link_file);
+ $file_name = trim ($content[0]);
+ $mime_type = trim ($content[1]);
+ $file_size = trim ($content[2]);
+ $key = trim ($content[3], NL);
+ $time = trim ($content[4]);
+ $md5 = trim ($content[5]);
+ $onetime = trim ($content[6]);
+ $link_code = trim ($content[9]);
+
+ if (!file_exists (VAR_FILES.$md5))
+ {
+ jirafeau_delete ($link_name);
+ require (JIRAFEAU_ROOT.'lib/template/header.php');
+ echo '<div class="error"><p>'._('File not available.').
+ '</p></div>';
+ require (JIRAFEAU_ROOT.'lib/template/footer.php');
+ exit;
+ }
- if($time != JIRAFEAU_INFINITY && time() > $time) {
- jirafeau_delete($link_name);
- require(JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '<div class="error"><p>' . _('The time limit of this file has expired. It has been deleted.') . '</p></div>';
- require(JIRAFEAU_ROOT . 'lib/template/footer.php');
- exit;
- }
+ if (!empty ($delete_code) && $delete_code == $link_code)
+ {
+ jirafeau_delete ($link_name);
+ require (JIRAFEAU_ROOT.'lib/template/header.php');
+ echo '<div class="message"><p>'._('File has been deleted.').
+ '</p></div>';
+ require (JIRAFEAU_ROOT.'lib/template/footer.php');
+ exit;
+ }
- if(!empty($key)) {
- if(!isset($_POST['key'])) {
- require(JIRAFEAU_ROOT . 'lib/template/header.php');
-?>
-<div id="upload">
-<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
-<input type="hidden" name="jirafeau" value="<?php echo JIRAFEAU_VERSION; ?>" />
-<fieldset>
- <legend><?php echo _('Key protection'); ?></legend>
- <table>
- <tr>
- <td><?php echo _('Give the key of this file:'); ?> <input type="password" name="key" /></td>
- </tr>
- <tr>
- <td><input type="submit" value="<?php echo _('I have the right to download this file'); ?>" /></td>
- </tr>
- </table>
-</fieldset>
-</form>
-</div>
-<?php
- require(JIRAFEAU_ROOT . 'lib/template/footer.php');
- exit;
- } else {
- if($key != md5($_POST['key'])) {
- header("HTTP/1.0 403 Forbidden");
+ if ($time != JIRAFEAU_INFINITY && time ()> $time)
+ {
+ jirafeau_delete ($link_name);
+ require (JIRAFEAU_ROOT.'lib/template/header.php');
+ echo '<div class="error"><p>'.
+ _('The time limit of this file has expired.' .
+ 'It has been deleted.') . '</p></div>';
+ require (JIRAFEAU_ROOT.'lib/template/footer.php');
+ exit;
+ }
- require(JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '<div class="error"><p>Error 403: Forbidden</p></div>';
- require(JIRAFEAU_ROOT . 'lib/template/footer.php');
- exit;
+ if (!empty ($key))
+ {
+ if (!isset ($_POST['key']))
+ {
+ require (JIRAFEAU_ROOT.'lib/template/header.php');
+ ?><div id = "upload">
+ <form action =
+ "<?php echo $_SERVER['REQUEST_URI']; ?>" method =
+ "post"> <input type = "hidden" name = "jirafeau" value =
+ "<?php echo JIRAFEAU_VERSION; ?>" /><fieldset>
+ <legend><?php echo _('Key protection');
+ ?></legend> <table> <tr>
+ <td><?php echo _('Give the key of this file:');
+ ?><input type = "password" name =
+ "key" /></td> </tr> <tr> <td><input type =
+ "submit" value =
+ "<?php echo _('I have the right to download this file'); ?>"
+ /></td> </tr> </table> </fieldset> </form> </div>
+ <?php require (JIRAFEAU_ROOT.'lib/template/footer.php');
+ exit;
+ }
+ else
+ {
+ if ($key != md5 ($_POST['key']))
+ {
+ header ("HTTP/1.0 403 Forbidden");
+
+ require (JIRAFEAU_ROOT.'lib/template/header.php');
+ echo '<div class="error"><p>Error 403: Forbidden</p></div>';
+ require (JIRAFEAU_ROOT.'lib/template/footer.php');
+ exit;
+ }
+ }
}
- }
- }
- header('Content-Length: ' . $file_size);
- header('Content-Type: ' . $mime_type);
- if(!jirafeau_is_viewable($mime_type)) {
- header('Content-Disposition: attachment; filename="' . $file_name . '"');
- }
- readfile(VAR_FILES . $md5);
+ header ('Content-Length: ' . $file_size);
+ header ('Content-Type: ' . $mime_type);
+ if (!jirafeau_is_viewable ($mime_type))
+ {
+ header ('Content-Disposition: attachment; filename="' .
+ $file_name . '"');
+ }
+ readfile (VAR_FILES.$md5);
- if($onetime == 'O') {
- jirafeau_delete($link_name);
+ if ($onetime == 'O')
+ jirafeau_delete ($link_name);
+ exit;
}
- exit;
- } else {
- header("HTTP/1.0 404 Not Found");
+ else
+ {
+ header ("HTTP/1.0 404 Not Found");
- require(JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '<div class="error"><p>Error 404: Not Found</p></div>';
- require(JIRAFEAU_ROOT . 'lib/template/footer.php');
+ require (JIRAFEAU_ROOT.'lib/template/header.php');
+ echo '<div class="error"><p>Error 404: Not Found</p></div>';
+ require (JIRAFEAU_ROOT.'lib/template/footer.php');
+ exit;
+ }
+}
+else
+{
+ header ('Location: '.$cfg['web_root']);
exit;
- }
-} else {
- header('Location: ' . $cfg['web_root']);
- exit;
}
?>
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
+define ('DEBUG', true);
-define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
-define('DEBUG', true);
-
-require(JIRAFEAU_ROOT . 'lib/config.php');
-require(JIRAFEAU_ROOT . 'lib/settings.php');
-require(JIRAFEAU_ROOT . 'lib/functions.php');
+require (JIRAFEAU_ROOT . 'lib/config.php');
+require (JIRAFEAU_ROOT . 'lib/settings.php');
+require (JIRAFEAU_ROOT . 'lib/functions.php');
/* check if the destination dirs are writable */
-$writable = is_writable(VAR_FILES) && is_writable(VAR_LINKS);
-
-$res = array();
-if($writable && isset($_POST['jirafeau'])) {
-
- $key = $_POST['key'];
-
- $time = time();
- switch($_POST['time']) {
- case 'minute':
- $time += JIRAFEAU_MINUTE;
- break;
- case 'hour':
- $time += JIRAFEAU_HOUR;
- break;
- case 'day':
- $time += JIRAFEAU_DAY;
- break;
- case 'week':
- $time += JIRAFEAU_WEEK;
- break;
- case 'month':
- $time += JIRAFEAU_MONTH;
- break;
- default:
- $time = JIRAFEAU_INFINITY;
- break;
- }
-
- $res = jirafeau_upload($_FILES['file'], isset($_POST['one_time_download']), $key, $time, $cfg, $_SERVER['REMOTE_ADDR']);
+$writable = is_writable (VAR_FILES) && is_writable (VAR_LINKS);
+
+$res = array ();
+if ($writable && isset ($_POST['jirafeau']))
+{
+
+ $key = $_POST['key'];
+
+ $time = time ();
+ switch ($_POST['time'])
+ {
+ case 'minute':
+ $time += JIRAFEAU_MINUTE;
+ break;
+ case 'hour':
+ $time += JIRAFEAU_HOUR;
+ break;
+ case 'day':
+ $time += JIRAFEAU_DAY;
+ break;
+ case 'week':
+ $time += JIRAFEAU_WEEK;
+ break;
+ case 'month':
+ $time += JIRAFEAU_MONTH;
+ break;
+ default:
+ $time = JIRAFEAU_INFINITY;
+ break;
+ }
+
+ $res =
+ jirafeau_upload ($_FILES['file'], isset ($_POST['one_time_download']),
+ $key, $time, $cfg, $_SERVER['REMOTE_ADDR']);
}
-require(JIRAFEAU_ROOT . 'lib/template/header.php');
+require (JIRAFEAU_ROOT.'lib/template/header.php');
/* Checking for errors. */
-if(!is_writable(VAR_FILES)) {
- add_error (_('The file directory is not writable!'), VAR_FILES);
-}
+if (!is_writable (VAR_FILES))
+ add_error (_('The file directory is not writable!'), VAR_FILES);
-if(!is_writable(VAR_LINKS)) {
- add_error (_('The link directory is not writable!'), VAR_LINKS);
-}
+if (!is_writable (VAR_LINKS))
+ add_error (_('The link directory is not writable!'), VAR_LINKS);
/* Check if the install.php script is still in the directory. */
-if (file_exists(JIRAFEAU_ROOT . 'install.php')) {
- add_error (_('Installer script still present'),
- _('Please make sure to delete the installer script "install.php" before continuing.'));
-}
-
-if(!has_error() && !empty($res)) {
- if($res['error']['has_error']) {
- add_error (_('An error occurred.'), $res['error']['why']);
- } else {
- $link = $cfg['web_root'];
- $delete_link = $cfg['web_root'];
-
- if($cfg['rewrite']) {
- $link .= 'file-' . $res['link'];
- $delete_link .= 'file-' . $res['link'] . '-delete-' . $res['delete_link'];
- } else {
- $link .= 'file.php?h=' . $res['link']; // h because 'h' looks like a jirafeau ;)
- $delete_link .= 'file.php?h=' . $res['link'] . '&d=' . $res['delete_link'];
+if (file_exists (JIRAFEAU_ROOT . 'install.php'))
+ add_error (_('Installer script still present'),
+ _('Please make sure to delete the installer script ' .
+ '"install.php" before continuing.'));
+
+if (!has_error () && !empty ($res))
+{
+ if ($res['error']['has_error'])
+ add_error (_('An error occurred.'), $res['error']['why']);
+ else
+ {
+ $link = $cfg['web_root'];
+ $delete_link = $cfg['web_root'];
+
+ if ($cfg['rewrite'])
+ {
+ $link .= 'file-'.$res['link'];
+ $delete_link .=
+ 'file-'.$res['link'].'-delete-'.$res['delete_link'];
+ }
+ else
+ {
+ /* h because 'h' looks like a jirafeau ;) */
+ $link .= 'file.php?h='.$res['link'];
+ $delete_link .=
+ 'file.php?h='.$res['link'].'&d='.$res['delete_link'];
+ }
+
+ echo '<div class="message">'.NL;
+ echo '<p>'._('File uploaded! Copy the following URL to get it:').
+ '<br />' . NL;
+ echo '<a href="'.$link.'">'.$link.'</a>' . NL;
+
+ if ($time != JIRAFEAU_INFINITY)
+ {
+ echo '<br />'._('This file is valid until the following date:') .
+ '<br /><strong>' . strftime ('%c', $time) . '</strong>';
+ }
+
+ echo '</p></div>';
+
+ echo '<div class="message">' . NL;
+ echo '<p>' . _('Keep the following URL to delete it:') . '<br />' . NL;
+ echo '<a href="' . $delete_link . '">' . $delete_link . '</a>' . NL;
+ echo '</p></div>';
}
-
- echo '<div class="message">' . NL;
- echo '<p>' . _('File uploaded! Copy the following URL to get it:') . '<br />' . NL;
- echo '<a href="' . $link . '">' . $link . '</a>' . NL;
-
- if($time != JIRAFEAU_INFINITY) {
- echo '<br />' . _('This file is valid until the following date:') . '<br /><strong>' . strftime('%c' ,$time) . '</strong>';
- }
-
- echo '</p></div>';
-
- echo '<div class="message">' . NL;
- echo '<p>' . _('Keep the following URL to delete it:') . '<br />' . NL;
- echo '<a href="' . $delete_link . '">' . $delete_link . '</a>' . NL;
- echo '</p></div>';
- }
}
-if(has_error ()) {
+if (has_error ())
show_errors ();
-}
-if(!has_error () && $writable) {
-?>
-
-<div id="upload">
-<form enctype="multipart/form-data" action="<?php echo $cfg['web_root']; ?>" method="post">
-<div><input type="hidden" name="jirafeau" value="<?php echo JIRAFEAU_VERSION; ?>" /></div>
-<fieldset>
- <legend><?php echo _('Upload a file'); ?></legend>
- <p><input type="file" name="file" size="30" /></p>
- <p class="config"><?php printf(_('Maximum file size: %dMB'), jirafeau_get_max_upload_size()/(1024*1024)); ?></p>
- <p><input type="submit" value="<?php echo _('Send in the binary chaos'); ?>" /></p>
-
- <hr />
-
- <div id="moreoptions">
- <p><label><input type="checkbox" name="one_time_download" /> <?php echo _('One time download'); ?></label></p>
- <p><label for="input_key"><?php echo _('File key:'); ?></label> <input type="text" name="key" id="input_key" /></p>
- <p><label for="select_time"><?php echo _('Time limit:'); ?></label>
- <select name="time" id="select_time">
- <option value="none"><?php echo _('None'); ?></option>
- <option value="minute"><?php echo _('One minute'); ?></option>
- <option value="hour"><?php echo _('One hour'); ?></option>
- <option value="day"><?php echo _('One day'); ?></option>
- <option value="week"><?php echo _('One week'); ?></option>
- <option value="month"><?php echo _('One month'); ?></option>
- </select>
- </p>
- </div>
-</fieldset>
-</form>
-</div>
-
-<?php
+if (!has_error () && $writable)
+{
+ ?><div id = "upload">
+ <form enctype = "multipart/form-data" action = "
+ <?php echo $cfg['web_root']; ?>" method =
+ "post"> <div><input type = "hidden" name = "jirafeau" value = "
+ <?php echo JIRAFEAU_VERSION; ?>" /></div> <fieldset>
+ <legend><?php echo _('Upload a file');
+ ?></legend> <p><input type = "file" name = "file" size =
+ "30" /></p> <p class =
+ "config"><?php printf (_('Maximum file size: %dMB'),
+ jirafeau_get_max_upload_size () / (1024 *
+ 1024));
+ ?></p> <p><input type = "submit" value =
+ "<?php echo _('Send in the binary chaos'); ?>" /></p>
+ <hr /><div id = "moreoptions"> <p><label><input type =
+ "checkbox" name =
+ "one_time_download" /><?php echo _('One time download');
+ ?></label></p> <p><label for = "input_key"
+ ><?php echo _('File key:');
+ ?></label> <input type = "text" name = "key" id = "input_key" /></p>
+ <p><label for = "select_time"
+ ><?php echo _('Time limit:');
+ ?></label>
+ <select name = "time" id = "select_time">
+ <option value = "none"><?php echo _('None');
+ ?></option> <option value = "minute"><?php echo _('One minute');
+ ?></option> <option value = "hour"><?php echo _('One hour');
+ ?></option> <option value = "day"><?php echo _('One day');
+ ?></option> <option value = "week"><?php echo _('One week');
+ ?></option> <option value = "month"><?php echo _('One month');
+ ?></option>
+ </select> </p> </div> </fieldset> </form> </div> <?php
}
-require(JIRAFEAU_ROOT . 'lib/template/footer.php');
+require (JIRAFEAU_ROOT.'lib/template/footer.php');
?>
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/');
+define ('NL', "\n");
+define ('QUOTE', "'");
-define('JIRAFEAU_ROOT', dirname(__FILE__) . '/');
-define('NL', "\n");
-define('QUOTE', "'");
+define ('JIRAFEAU_CFG', JIRAFEAU_ROOT.'lib/config.local.php');
+define ('JIRAFEAU_VAR_RAND_LENGTH', 15);
-define('JIRAFEAU_CFG', JIRAFEAU_ROOT . 'lib/config.local.php');
-define('JIRAFEAU_VAR_RAND_LENGTH', 15);
+require (JIRAFEAU_ROOT . 'lib/config.php');
-require(JIRAFEAU_ROOT . 'lib/config.php');
-
-function jirafeau_quoted($str) {
- return QUOTE . str_replace(QUOTE, "\'", $str) . QUOTE;
+function
+jirafeau_quoted ($str)
+{
+ return QUOTE . str_replace (QUOTE, "\'", $str) . QUOTE;
}
-function jirafeau_export_cfg($cfg) {
- $handle = fopen(JIRAFEAU_CFG, 'w');
- fwrite($handle, '<?php' . NL);
- fwrite($handle, '/* ' . _('This file was generated by the install process. You can edit it. Please see config.php to understand the configuration items.') . ' */' . NL);
- foreach($cfg as $key => $item) {
- fwrite($handle, '$cfg[' . jirafeau_quoted($key) . '] = ');
- if(is_bool($item)) {
- fwrite($handle, ($item ? 'true' : 'false'));
- } else if(is_string($item)) {
- fwrite($handle, jirafeau_quoted($item));
- } else {
- fwrite($handle, 'null');
+function
+jirafeau_export_cfg ($cfg)
+{
+ $handle = fopen (JIRAFEAU_CFG, 'w');
+ fwrite ($handle, '<?php' . NL);
+ fwrite ($handle,
+ '/* ' .
+ _ ('This file was generated by the install process. ' .
+ 'You can edit it. Please see config.php to understand the ' .
+ 'configuration items.') . ' */' . NL);
+ foreach ($cfg as $key => $item)
+ {
+ fwrite ($handle, '$cfg[' . jirafeau_quoted ($key) . '] = ');
+ if (is_bool ($item))
+ fwrite ($handle, ($item ? 'true' : 'false'));
+ else if (is_string ($item))
+ fwrite ($handle, jirafeau_quoted ($item));
+ else
+ fwrite ($handle, 'null');
+ fwrite ($handle, ';'.NL);
}
- fwrite($handle, ';' . NL);
- }
- fwrite($handle, '?>'); // no newline at the end of the file to be able to send headers
- fclose($handle);
+ /* No newline at the end of the file to be able to send headers. */
+ fwrite ($handle, '?>');
+ fclose ($handle);
}
-function jirafeau_mkdir($path) {
- if(!file_exists($path)) {
- if(!@mkdir($path, 0755)) {
- return false;
- }
- }
- return true;
+function
+jirafeau_mkdir ($path)
+{
+ if (!file_exists ($path) && !@mkdir ($path, 0755))
+ return false;
+ return true;
}
/**
* @param $path is the file or directory to be tested.
* @return true if $path is writable.
*/
-function jirafeau_is_writable($path) {
- return is_writable($path) || @chmod($path, 0777); // "@" gets rid of error messages.
+function
+jirafeau_is_writable ($path)
+{
+ /* "@" gets rid of error messages. */
+ return is_writable ($path) || @chmod ($path, 0777);
}
-function jirafeau_check_var_dir($path) {
- $mkdir_str1 = _('The following directory could not be created:');
- $mkdir_str2 = _('You should create this directory by hand.');
- $write_str1 = _('The following directory is not writable:');
- $write_str2 = _('You should give the write right to the web server on this directory.');
- $solution_str = _('Here is a solution:');
-
- if(!jirafeau_mkdir($path)) {
- return array(
- 'has_error' => true,
- 'why' => $mkdir_str1 . '<br /><code>' . $path . '</code><br />' . $solution_str . '<br />' . $mkdir_str2
- );
- }
-
- if(!jirafeau_is_writable($path)) {
- return array(
- 'has_error' => true,
- 'why' => $write_str1 . '<br /><code>' . $path . '</code><br />' . $solution_str . '<br />' . $write_str2
- );
- }
-
- foreach(array('files', 'links') as $subdir) {
- $subpath = $path . $subdir;
-
- if(!jirafeau_mkdir($subpath)) {
- return array(
- 'has_error' => true,
- 'why' => $mkdir_str1 . '<br /><code>' . $subpath . '</code><br />' . $solution_str . '<br />' . $mkdir_str2
- );
+function
+jirafeau_check_var_dir ($path)
+{
+ $mkdir_str1 = _('The following directory could not be created:');
+ $mkdir_str2 = _('You should create this directory by hand.');
+ $write_str1 = _('The following directory is not writable:');
+ $write_str2 = _('You should give the write right to the web server on ' .
+ 'this directory.');
+ $solution_str = _('Here is a solution:');
+
+ if (!jirafeau_mkdir ($path) || !jirafeau_is_writable ($path))
+ return array ('has_error' => true,
+ 'why' => $mkdir_str1 . '<br /><code>' .
+ $path . '</code><br />' . $solution_str .
+ '<br />' . $mkdir_str2);
+
+ foreach (array ('files', 'links') as $subdir)
+ {
+ $subpath = $path.$subdir;
+
+ if (!jirafeau_mkdir ($subpath) || !jirafeau_is_writable ($subpath))
+ return array ('has_error' => true,
+ 'why' => $mkdir_str1 . '<br /><code>' .
+ $subpath . '</code><br />' . $solution_str .
+ '<br />' . $mkdir_str2);
}
- if(!jirafeau_is_writable($subpath)) {
- return array(
- 'has_error' => true,
- 'why' => $write_str1 . '<br /><code>' . $subpath . '</code><br />' . $solution_str . '<br />' . $write_str2
- );
- }
-
- }
-
- return array('has_error' => false, 'why' => '');
+ return array ('has_error' => false, 'why' => '');
}
-function jirafeau_add_ending_slash($path) {
- return $path . ((substr($path, -1) == '/') ? '' : '/');
+function
+jirafeau_add_ending_slash ($path)
+{
+ return $path . ((substr ($path, -1) == '/') ? '' : '/');
}
-if(!file_exists(JIRAFEAU_CFG)) {
- // we try to create an empty one
- if(!@touch(JIRAFEAU_CFG)) {
- require(JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '<div class="error"><p>' . _('The local configuration file could not be created. Create a <code>lib/config.local.php</code> file and give the write right to the web server (preferred solution), or give the write right to the web server on the <code>lib</code> directory.') . '</p></div>';
- require(JIRAFEAU_ROOT . 'lib/template/footer.php');
- exit;
- }
+if (!file_exists (JIRAFEAU_CFG))
+{
+ /* We try to create an empty one. */
+ if (!@touch (JIRAFEAU_CFG))
+ {
+ require (JIRAFEAU_ROOT . 'lib/template/header.php');
+ echo '<div class="error"><p>' .
+ _('The local configuration file could not be created. Create a ' .
+ '<code>lib/config.local.php</code> file and give the write ' .
+ 'right to the web server (preferred solution), or give the ' .
+ 'write right to the web server on the <code>lib</code> ' .
+ 'directory.') .
+ '</p></div>';
+ require (JIRAFEAU_ROOT . 'lib/template/footer.php');
+ exit;
+ }
}
-if (!is_writable(JIRAFEAU_CFG) && !@chmod(JIRAFEAU_CFG, '0666')) {
- require(JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '<div class="error"><p>' . _('The local configuration is not writable by the web server. Give the write right to the web server on the <code>lib/config.local.php</code> file.') . '</p></div>';
- require(JIRAFEAU_ROOT . 'lib/template/footer.php');
- exit;
+if (!is_writable (JIRAFEAU_CFG) && !@chmod (JIRAFEAU_CFG, '0666'))
+{
+ require (JIRAFEAU_ROOT . 'lib/template/header.php');
+ echo '<div class="error"><p>' .
+ _('The local configuration is not writable by the web server. ' .
+ 'Give the write right to the web server on the ' .
+ '<code>lib/config.local.php</code> file.') .
+ '</p></div>';
+ require (JIRAFEAU_ROOT . 'lib/template/footer.php');
+ exit;
}
-if(isset($_POST['step']) && isset($_POST['next'])) {
- switch($_POST['step']) {
- case 1:
- $cfg['lang'] = $_POST['lang'];
- jirafeau_export_cfg($cfg);
- break;
-
- case 2:
- $cfg['web_root'] = jirafeau_add_ending_slash($_POST['web_root']);
- $cfg['var_root'] = jirafeau_add_ending_slash($_POST['var_root']);
- jirafeau_export_cfg($cfg);
- break;
-
- default:
- // nothing to do
- }
+if (isset ($_POST['step']) && isset ($_POST['next']))
+{
+ switch ($_POST['step'])
+ {
+ case 1:
+ $cfg['lang'] = $_POST['lang'];
+ jirafeau_export_cfg ($cfg);
+ break;
+
+ case 2:
+ $cfg['web_root'] = jirafeau_add_ending_slash ($_POST['web_root']);
+ $cfg['var_root'] = jirafeau_add_ending_slash ($_POST['var_root']);
+ jirafeau_export_cfg ($cfg);
+ break;
+
+ default: break;
+ }
}
-require(JIRAFEAU_ROOT . 'lib/settings.php');
-require(JIRAFEAU_ROOT . 'lib/template/header.php');
+require (JIRAFEAU_ROOT . 'lib/settings.php');
+require (JIRAFEAU_ROOT . 'lib/template/header.php');
$current = 1;
-if(isset($_POST['next'])) {
- $current = $_POST['step'] + 1;
-} else if(isset($_POST['previous'])) {
- $current = $_POST['step'] - 1;
-} else if(isset($_POST['retry'])) {
- $current = $_POST['step'];
-}
-
-switch($current) {
- case 3:
-?>
-<h2><?php printf(_('Installation of Jirafeau - step %d out of %d'), 3, 3); ?></h2>
-<div id="install">
-<form action="<?php echo basename(__FILE__); ?>" method="post">
-<input type="hidden" name="jirafeau" value="<?php echo JIRAFEAU_VERSION; ?>" />
-<input type="hidden" name="step" value="3" />
-<fieldset>
- <legend><?php echo _('Finalisation'); ?></legend>
- <table>
- <tr>
- <td class="info" colspan="2"><?php echo _('Jirafeau is setting the website according to the configuration you provided.'); ?></td>
- </tr>
- <tr>
- <td class="nav previous"><input type="submit" name="previous" value="<?php echo _('Previous step'); ?>" /></td>
- <td></td>
- </tr>
- </table>
-</fieldset>
-</form>
-</div>
-
-<?php
- $err = jirafeau_check_var_dir($cfg['var_root']);
- if($err['has_error']) {
- echo '<div class="error"><p>' . $err['why'] . '<br />' . NL;
-?>
-<form action="<?php echo basename(__FILE__); ?>" method="post">
-<input type="hidden" name="jirafeau" value="<?php echo JIRAFEAU_VERSION; ?>" />
-<input type="hidden" name="step" value="3" />
-<input type="submit" name="retry" value="<?php echo _('Retry this step'); ?>" />
-</form>
-<?php
- echo '</p></div>';
- } else {
- echo '<div class="message"><p>' . _('Your website is now fully operational:') . '<br /><a href="' . $cfg['web_root'] . '">' . $cfg['web_root'] . '</a></p></div>';
+if (isset ($_POST['next']))
+ $current = $_POST['step'] + 1;
+else if (isset ($_POST['previous']))
+ $current = $_POST['step'] - 1;
+else if (isset ($_POST['retry']))
+ $current = $_POST['step'];
+
+switch ($current)
+{
+case 3:
+ ?><h2><?php printf (_('Installation of Jirafeau - step %d out of %d'),
+ 3, 3);
+ ?></h2> <div id = "install"> <form action =
+ "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
+ "hidden" name = "jirafeau" value =
+ "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
+ "step" value =
+ "3" /><fieldset> <legend><?php echo _('Finalisation');
+ ?></legend> <table> <tr> <td class = "info" colspan =
+ "2"><?php echo
+ _
+ ('Jirafeau is setting the website according to the configuration you provided.');
+ ?></td> </tr> <tr> <td class = "nav previous"><input type =
+ "submit" name = "previous" value =
+ "
+ <?php
+ echo _('Previous step');
+ ?>" /></td> <td></td> </tr>
+ </table> </fieldset> </form> </div>
+ <?php
+ $err = jirafeau_check_var_dir ($cfg['var_root']);
+ if ($err['has_error'])
+ {
+ echo '<div class="error"><p>'.$err['why'].'<br />'.NL;
+ ?><form action = "<?php echo basename(__FILE__); ?>" method =
+ "post"> <input type = "hidden" name = "jirafeau" value =
+ "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
+ "step" value = "3" /><input type = "submit" name =
+ "retry" value =
+ "<?php echo _('Retry this step'); ?>" /></form>
+ <?php echo '</p></div>';
+ }
+ else
+ {
+ echo '<div class="message"><p>' .
+ _('Your website is now fully operational:') .
+ '<br /><a href="' . $cfg['web_root'] . '">' .
+ $cfg['web_root'].'</a></p></div>';
}
break;
- case 2:
-?>
-<h2><?php printf(_('Installation of Jirafeau - step %d out of %d'), 2, 3); ?></h2>
-<div id="install">
-<form action="<?php echo basename(__FILE__); ?>" method="post">
-<input type="hidden" name="jirafeau" value="<?php echo JIRAFEAU_VERSION; ?>" />
-<input type="hidden" name="step" value="2" />
-<fieldset>
- <legend><?php echo _('Information'); ?></legend>
- <table>
- <tr>
- <td class="info" colspan="2"><?php echo _('The base address of Jirafeau is the first part of the URL, until (and including) the last slash. For example: "http://www.example.com/". Do not forget the ending slash!'); ?></td>
- </tr>
- <tr>
- <td class="label"><label for="input_web_root"><?php echo _('Base address:'); ?></label></td>
- <td class="field"><input type="text" name="web_root" id="input_web_root" value="<?php
+case 2:
+ ?><h2><?php printf (_('Installation of Jirafeau - step %d out of %d'),
+ 2, 3);
+ ?></h2> <div id = "install"> <form action =
+ "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
+ "hidden" name = "jirafeau" value =
+ "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
+ "step" value =
+ "2" /><fieldset> <legend><?php echo _('Information');
+ ?></legend> <table> <tr> <td class = "info" colspan =
+ "2"><?php echo
+ _
+ ('The base address of Jirafeau is the first part of the URL, until (and including) the last slash. For example: "http://www.example.com/". Do not forget the ending slash!');
+ ?></td> </tr> <tr> <td class = "label"><label for = "input_web_root"
+ ><?php echo _('Base address:');
+ ?></label></td>
+ <td class = "field"><input type = "text" name = "web_root" id = "input_web_root" value = "<?php
echo (empty($cfg['web_root']) ?
'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__), '', $_SERVER['REQUEST_URI']) :
$cfg['web_root']);
- ?>" size="40" /></td>
- </tr>
- <tr>
- <td class="info" colspan="2"><?php echo _('The data directory is where your files and information about your files will be stored. You should put it outside your web site, or at least restrict the access of this directory. Do not forget the ending slash!'); ?></td>
- </tr>
- <tr>
- <td class="label"><label for="input_var_root"><?php echo _('Data directory:'); ?></label></td>
- <td class="field"><input type="text" name="var_root" id="input_var_root" value="<?php
+ ?>" size = "40" /></td>
+ </tr> <tr> <td class = "info" colspan = "2"><?php echo _('The data directory is where your files and information about your files will be stored. You should put it outside your web site, or at least restrict the access of this directory. Do not forget the ending slash!');
+ ?></td> </tr> <tr> <td class = "label"><label for = "input_var_root"
+ ><?php echo _('Data directory:');
+ ?></label></td>
+ <td class = "field"><input type = "text" name = "var_root" id = "input_var_root" value = "<?php
if(empty($cfg['var_root'])) {
$alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$len_alphanum = strlen($alphanum);
$var = 'var-';
- for($i = 0; $i < JIRAFEAU_VAR_RAND_LENGTH; $i++) {
+ for($i = 0; $i <JIRAFEAU_VAR_RAND_LENGTH; $i++) {
$var .= substr($alphanum, mt_rand(0, $len_alphanum - 1), 1);
}
echo JIRAFEAU_ROOT . $var . '/';
} else {
echo $cfg['var_root'];
}
- ?>" size="40" /></td>
- </tr>
- <tr>
- <td colspan="2">
- <input type="submit" class="navright" name="next" value="<?php echo _('Next step'); ?>" />
- <input type="submit" class="navleft" name="previous" value="<?php echo _('Previous step'); ?>" />
- </td>
- </tr>
- </table>
-</fieldset>
-</form>
-</div>
-<?php
- break;
-
- case 1:
- default:
- $languages = array(
- '' => 'English',
- 'fr_FR.UTF-8' => 'Français'
- );
-?>
-<h2><?php printf(_('Installation of Jirafeau - step %d out of %d'), 1, 3); ?></h2>
-<div id="install">
-<form action="<?php echo basename(__FILE__); ?>" method="post">
-<input type="hidden" name="jirafeau" value="<?php echo JIRAFEAU_VERSION; ?>" />
-<input type="hidden" name="step" value="1" />
-<fieldset>
- <legend><?php echo _('Language'); ?></legend>
- <table>
- <tr>
- <td class="info" colspan="2"><?php echo _('The installation of Jirafeau is internationalised, so you can have it in your own language if the translation is available.'); ?></td>
- </tr>
- <tr>
- <td class="label"><label for="select_lang"><?php echo _('Choose your language:'); ?></label></td>
- <td class="field">
- <select name="lang" id="select_lang">
- <?php
- foreach($languages as $key => $item) {
- echo '<option value="' . $key . '"' . ($key == $cfg['lang'] ? ' selected="selected"' : '') . '>' . $item . '</option>' . NL;
- }
- ?>
- </select>
- </td>
- </tr>
- <tr class="nav">
- <td></td>
- <td class="nav next"><input type="submit" name="next" value="<?php echo _('Next step'); ?>" /></td>
- </tr>
- </table>
-</fieldset>
-</form>
-</div>
-<?php
- break;
+ ?>" size = "40" /></td>
+ </tr> <tr> <td colspan = "2"> <input type = "submit" class = "navright" name = "next" value = "<?php echo _('Next step'); ?>" /><input type = "submit" class = "navleft" name = "previous" value = "<?php echo _('Previous step'); ?>" /></td> </tr> </table> </fieldset> </form> </div> <?php break;
+
+case 1:
+default:
+ $languages = array ('' => 'English', 'fr_FR.UTF-8' => 'Français');
+ ?><h2><?php printf (_('Installation of Jirafeau - step %d out of %d'),
+ 1, 3);
+ ?></h2> <div id = "install"> <form action =
+ "<?php echo basename(__FILE__); ?>" method = "post"> <input type =
+ "hidden" name = "jirafeau" value =
+ "<?php echo JIRAFEAU_VERSION; ?>" /><input type = "hidden" name =
+ "step" value = "1" /><fieldset> <legend><?php echo _('Language');
+ ?></legend> <table> <tr> <td class = "info" colspan =
+ "2"><?php echo
+ _
+ ('The installation of Jirafeau is internationalised, so you can have it in your own language if the translation is available.');
+ ?></td> </tr> <tr> <td class = "label"><label for = "select_lang"
+ ><?php echo _('Choose your language:');
+ ?></label></td>
+ <td class = "field">
+ <select name = "lang" id = "select_lang">
+ <?php foreach ($languages as $key => $item)
+ {
+ echo '<option value="'.$key.'"'.($key ==
+ $cfg['lang'] ? ' selected="selected"'
+ : '').'>'.$item.'</option>'.NL;
+ }
+ ?></select>
+ </td>
+ </tr>
+ <tr class = "nav">
+ <td></td>
+ <td class = "nav next"><input type = "submit" name = "next" value =
+ "<?php echo _('Next step'); ?>" /></td> </tr> </table>
+ </fieldset> </form> </div> <?php break;
}
-require(JIRAFEAU_ROOT . 'lib/template/footer.php');
-
-
-/**
-
- step 3:
- var dir
- verify if they are present and if the are writable
- create them
-
- remove install.php
-
-*/
-
+require (JIRAFEAU_ROOT . 'lib/template/footer.php');
?>
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-function jirafeau_toggle(id) {
- if(document.getElementById(id).style.display == 'block') {
- document.getElementById(id).style.display = 'none';
- } else {
- document.getElementById(id).style.display = 'block';
- }
+function
+jirafeau_toggle (id)
+{
+ if (document.getElementById (id).style.display == 'block')
+ {
+ document.getElementById (id).style.display = 'none';
+ }
+ else
+ {
+ document.getElementById (id).style.display = 'block';
+ }
}
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
/*
* default configuration
* if you want to change this, overwrite in a config.local.php file
*/
-
// don't forget the ending '/'
-$cfg['web_root'] = '';
+ $cfg['web_root'] = '';
$cfg['var_root'] = '';
$cfg['password'] = '';
-if((basename(__FILE__) != 'config.local.php') && file_exists(JIRAFEAU_ROOT . 'lib/config.local.php')) {
- require(JIRAFEAU_ROOT . 'lib/config.local.php');
+if ((basename (__FILE__) != 'config.local.php')
+ && file_exists (JIRAFEAU_ROOT.'lib/config.local.php'))
+{
+ require (JIRAFEAU_ROOT.'lib/config.local.php');
}
?>
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
/**
* transforms a php.ini string representing a value in an integer
* @param $value the value from php.ini
* @returns an integer for this value
*/
-function jirafeau_ini_to_bytes($value) {
- $modifier = substr($value, -1);
- $bytes = substr($value, 0, -1);
- switch(strtoupper($modifier)) {
- case 'P':
- $bytes *= 1024;
- case 'T':
- $bytes *= 1024;
- case 'G':
- $bytes *= 1024;
- case 'M':
- $bytes *= 1024;
- case 'K':
- $bytes *= 1024;
- default:
- break;
- }
- return $bytes;
+function jirafeau_ini_to_bytes ($value)
+{
+ $modifier = substr ($value, -1);
+ $bytes = substr ($value, 0, -1);
+ switch (strtoupper ($modifier))
+ {
+ case 'P':
+ $bytes *= 1024;
+ case 'T':
+ $bytes *= 1024;
+ case 'G':
+ $bytes *= 1024;
+ case 'M':
+ $bytes *= 1024;
+ case 'K':
+ $bytes *= 1024;
+ default:
+ break;
+ }
+ return $bytes;
}
/**
* gets the maximum upload size according to php.ini
* @returns the maximum upload size
*/
-function jirafeau_get_max_upload_size() {
- return min(jirafeau_ini_to_bytes(ini_get('post_max_size')), jirafeau_ini_to_bytes(ini_get('upload_max_filesize')));
+function
+jirafeau_get_max_upload_size ()
+{
+ return min (jirafeau_ini_to_bytes (ini_get ('post_max_size')),
+ jirafeau_ini_to_bytes (ini_get ('upload_max_filesize')));
}
/**
* @param $code the error code
* @returns a string explaining the error
*/
-function jirafeau_upload_errstr($code) {
- switch($code) {
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
- return _('Your file exceeds the maximum authorized file size.');
- break;
+function
+jirafeau_upload_errstr ($code)
+{
+ switch ($code)
+ {
+ case UPLOAD_ERR_INI_SIZE:
+ case UPLOAD_ERR_FORM_SIZE:
+ return _('Your file exceeds the maximum authorized file size. ');
+ break;
- case UPLOAD_ERR_PARTIAL:
- case UPLOAD_ERR_NO_FILE:
- return _('Your file was not uploaded correctly. You may succeed in retrying.');
- break;
+ case UPLOAD_ERR_PARTIAL:
+ case UPLOAD_ERR_NO_FILE:
+ return
+ _
+ ('Your file was not uploaded correctly. You may succeed in retrying. ');
+ break;
- case UPLOAD_ERR_NO_TMP_DIR:
- case UPLOAD_ERR_CANT_WRITE:
- case UPLOAD_ERR_EXTENSION:
- return _('Internal error. You may not succeed in retrying.');
- break;
+ case UPLOAD_ERR_NO_TMP_DIR:
+ case UPLOAD_ERR_CANT_WRITE:
+ case UPLOAD_ERR_EXTENSION:
+ return _('Internal error. You may not succeed in retrying. ');
+ break;
- default:
- break;
- }
- return _('Unknown error.');
+ default:
+ break;
+ }
+ return _('Unknown error. ');
}
/** Remove link and it's file
* @param $link the link's name (hash)
*/
-function jirafeau_delete($link) {
- if(!file_exists(VAR_LINKS . $link))
- return;
+function
+jirafeau_delete ($link)
+{
+ if (!file_exists ( VAR_LINKS . $link))
+ return;
- $content = file(VAR_LINKS . $link);
- $md5 = trim($content[5]);
- unlink(VAR_LINKS . $link);
+ $content = file ( VAR_LINKS . $link);
+ $md5 = trim ($content[5]);
+ unlink ( VAR_LINKS . $link);
- $counter = 1;
- if (file_exists(VAR_FILES . $md5 . '_count')) {
- $content = file(VAR_FILES . $md5 . '_count');
- $counter = trim($content[0]);
- }
- $counter--;
+ $counter = 1;
+ if (file_exists ( VAR_FILES . $md5. '_count'))
+ {
+ $content = file ( VAR_FILES . $md5. '_count');
+ $counter = trim ($content[0]);
+ }
+ $counter--;
- if ($counter >= 1) {
- $handle = fopen(VAR_FILES . $md5 . '_count', 'w');
- fwrite($handle, $counter);
- fclose($handle);
- }
+ if ($counter >= 1)
+ {
+ $handle = fopen ( VAR_FILES . $md5. '_count', 'w');
+ fwrite ($handle, $counter);
+ fclose ($handle);
+ }
- if ($counter == 0 && file_exists(VAR_FILES. $md5)) {
- unlink (VAR_FILES . $md5);
- unlink (VAR_FILES . $md5 . '_count');
- }
+ if ($counter == 0 && file_exists ( VAR_FILES . $md5))
+ {
+ unlink ( VAR_FILES . $md5);
+ unlink ( VAR_FILES . $md5. '_count');
+ }
}
/**
* 'link' => the link name of the uploaded file
* 'delete_link' => the link code to delete file
*/
-function jirafeau_upload($file, $one_time_download, $key, $time, $cfg, $ip) {
- if(empty($file['tmp_name']) || !is_uploaded_file($file['tmp_name'])) {
- return(array('error' => array('has_error' => true, 'why' => jirafeau_upload_errstr($file['error'])), 'link' => '', 'delete_link' => ''));
- }
+function
+jirafeau_upload ($file, $one_time_download, $key, $time, $cfg, $ip)
+{
+ if (empty ($file['tmp_name']) || !is_uploaded_file ($file['tmp_name']))
+ {
+ return (array(
+ 'error' =>
+ array ('has_error' => true,
+ 'why' => jirafeau_upload_errstr ($file['error'])),
+ 'link' => '',
+ 'delete_link' => ''));
+ }
- /* array representing no error */
- $noerr = array('has_error' => false, 'why' => '');
+ /* array representing no error */
+ $noerr = array ('has_error' => false, 'why' => '');
- /* file informations */
- $md5 = md5_file($file['tmp_name']);
- $name = trim($file['name']);
- $mime_type = $file['type'];
- $size = $file['size'];
+ /* file informations */
+ $md5 = md5_file ($file['tmp_name']);
+ $name = trim ($file['name']);
+ $mime_type = $file['type'];
+ $size = $file['size'];
- /* does file already exist ? */
- $rc = false;
- if(file_exists(VAR_FILES . $md5)) {
- $rc = unlink($file['tmp_name']);
- }
- elseif(move_uploaded_file($file['tmp_name'], VAR_FILES . $md5)) {
- $rc = true;
- }
- if(!$rc)
- {
- return(array(
- 'error' => array(
- 'has_error' => true,
- 'why' => _('Internal error during file creation.')),
- 'link' => '',
- 'delete_link' => '')
- );
- }
+ /* does file already exist ? */
+ $rc = false;
+ if (file_exists ( VAR_FILES . $md5))
+ {
+ $rc = unlink ($file['tmp_name']);
+ }
+ elseif (move_uploaded_file ($file['tmp_name'], VAR_FILES . $md5))
+ {
+ $rc = true;
+ }
+ if (!$rc)
+ {
+ return (array(
+ 'error' =>
+ array ('has_error' => true,
+ 'why' => _('Internal error during file creation. ')),
+ 'link' =>'',
+ 'delete_link' => ''));
+ }
- /* increment or create count file */
- $counter=0;
- if(file_exists(VAR_FILES . $md5 . '_count')) {
- $content = file(VAR_FILES . $md5 . '_count');
- $counter = trim($content[0]);
- }
- $counter++;
- $handle = fopen(VAR_FILES . $md5 . '_count', 'w');
- fwrite($handle, $counter);
- fclose($handle);
+ /* increment or create count file */
+ $counter = 0;
+ if (file_exists (VAR_FILES . $md5 . '_count'))
+ {
+ $content = file ( VAR_FILES . $md5. '_count');
+ $counter = trim ($content[0]);
+ }
+ $counter++;
+ $handle = fopen ( VAR_FILES . $md5. '_count', 'w');
+ fwrite ($handle, $counter);
+ fclose ($handle);
- /* Create delete code. */
- $delete_link_code = 0;
- for ($i = 0; $i < 8; $i++)
- $delete_link_code .= dechex(rand(0,16));
+ /* Create delete code. */
+ $delete_link_code = 0;
+ for ($i = 0; $i < 8; $i++)
+ $delete_link_code .= dechex (rand (0, 16));
- /* md5 password or empty */
- $password = '';
- if (!empty($key))
- $password = md5($key);
+ /* md5 password or empty */
+ $password = '';
+ if (!empty ($key))
+ $password = md5 ($key);
- /* create link file */
- $link_tmp_name = VAR_LINKS . $md5 . rand(0, 10000) . '.tmp';
- $handle = fopen($link_tmp_name, 'w');
- fwrite($handle, $name . NL . $mime_type . NL . $size . NL . $password . NL . $time . NL . $md5 . NL . ($one_time_download ? 'O' : 'R') . NL . date('U') . NL . $ip . NL . $delete_link_code . NL);
- fclose($handle);
- $md5_link = md5_file($link_tmp_name);
- if(!rename($link_tmp_name, VAR_LINKS . $md5_link)) {
- unlink($link_tmp_name);
- $counter--;
- if ($counter >= 1) {
- $handle = fopen(VAR_FILES . $md5 . '_count', 'w');
- fwrite($handle, $counter);
- fclose($handle);
- }
- else {
- unlink(VAR_FILES . $md5 . '_count');
- unlink(VAR_FILES . $md5);
+ /* create link file */
+ $link_tmp_name = VAR_LINKS . $md5.rand (0, 10000) . ' .tmp';
+ $handle = fopen ($link_tmp_name, 'w');
+ fwrite ($handle,
+ $name . NL. $mime_type . NL. $size . NL. $password . NL. $time . NL . $md5.
+ NL.($one_time_download ? 'O' : 'R') . NL.date ('U') . NL. $ip . NL.
+ $delete_link_code . NL);
+ fclose ($handle);
+ $md5_link = md5_file ($link_tmp_name);
+ if (!rename ($link_tmp_name, VAR_LINKS . $md5_link))
+ {
+ unlink ($link_tmp_name);
+ $counter--;
+ if ($counter >= 1)
+ {
+ $handle = fopen ( VAR_FILES . $md5. '_count', 'w');
+ fwrite ($handle, $counter);
+ fclose ($handle);
+ }
+ else
+ {
+ unlink ( VAR_FILES . $md5. '_count');
+ unlink ( VAR_FILES . $md5);
+ }
+ return (array(
+ 'error' =>
+ array ('has_error' => true,
+ 'why' => _('Internal error during file creation. ')),
+ 'link' =>'',
+ 'delete_link' => ''));
}
- return(array(
- 'error' => array(
- 'has_error' => true,
- 'why' => _('Internal error during file creation.')),
- 'link' => '',
- 'delete_link' => '')
- );
- }
- return(array('error' => $noerr, 'link' => $md5_link, 'delete_link' => $delete_link_code));
+ return (array ('error' => $noerr,
+ 'link' => $md5_link,
+ 'delete_link' => $delete_link_code));
}
/**
* @param $mime the mime type
* @returns a boolean telling if a mime type is viewable
*/
-function jirafeau_is_viewable($mime) {
- if(!empty($mime)) {
- // actually, verify if mime-type is an image or a text
- $viewable = array('image', 'text');
- $decomposed = explode('/', $mime);
- return in_array($decomposed[0], $viewable);
- }
- return false;
+function
+jirafeau_is_viewable ($mime)
+{
+ if (!empty ($mime))
+ {
+ /* Actually, verify if mime-type is an image or a text. */
+ $viewable = array ('image', 'text');
+ $decomposed = explode ('/', $mime);
+ return in_array ($decomposed[0], $viewable);
+ }
+ return false;
}
* @param $title the error's title
* @param $description is a human-friendly description of the problem.
*/
-function add_error ($title, $description) {
+function
+add_error ($title, $description)
+{
global $error_list;
- $error_list[] = '<p>' . $title . '<br />' . $description . '</p>';
+ $error_list[] = '<p>' . $title. '<br />' . $description. '</p>';
}
/**
* Informs whether any error has been registered yet.
* @return true if there are errors.
*/
-function has_error () {
+function
+has_error ()
+{
global $error_list;
return !empty ($error_list);
}
/**
* Displays all the errors.
*/
-function show_errors () {
- if (has_error ()) {
+function
+show_errors ()
+{
+ if (has_error ())
+ {
global $error_list;
echo '<div class="error">';
- foreach ($error_list as $error) {
+ foreach ($error_list as $error)
+ {
echo $error;
}
echo '</div>';
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
// Jirafeau constants
-
-define('JIRAFEAU_PACKAGE', 'Jirafeau');
-define('JIRAFEAU_VERSION', '0.4');
+define ('JIRAFEAU_PACKAGE', 'Jirafeau');
+define ('JIRAFEAU_VERSION', '0.4');
// directories
-define('VAR_FILES', $cfg['var_root'] . 'files/');
-define('VAR_LINKS', $cfg['var_root'] . 'links/');
+define ('VAR_FILES', $cfg['var_root'] . 'files/');
+define ('VAR_LINKS', $cfg['var_root'] . 'links/');
// i18n
-setlocale(LC_ALL, $cfg['lang']);
+setlocale (LC_ALL, $cfg['lang']);
-bindtextdomain(JIRAFEAU_PACKAGE, JIRAFEAU_ROOT . 'lib/locale');
-textdomain(JIRAFEAU_PACKAGE);
+bindtextdomain (JIRAFEAU_PACKAGE, JIRAFEAU_ROOT.'lib/locale');
+textdomain (JIRAFEAU_PACKAGE);
// useful constants
-if(!defined('NL')) {
- define('NL', "\n");
+if (!defined ('NL'))
+{
+ define ('NL', "\n");
}
-define('JIRAFEAU_INFINITY', -1);
-define('JIRAFEAU_MINUTE', 60); // 60
-define('JIRAFEAU_HOUR', 3600); // JIRAFEAU_MINUTE * 60
-define('JIRAFEAU_DAY', 86400); // JIRAFEAU_HOUR * 24
-define('JIRAFEAU_WEEK', 604800); // JIRAFEAU_DAY * 7
-define('JIRAFEAU_MONTH', 2419200); // JIRAFEAU_WEEK * 4
+define ('JIRAFEAU_INFINITY', -1);
+define ('JIRAFEAU_MINUTE', 60); // 60
+define ('JIRAFEAU_HOUR', 3600); // JIRAFEAU_MINUTE * 60
+define ('JIRAFEAU_DAY', 86400); // JIRAFEAU_HOUR * 24
+define ('JIRAFEAU_WEEK', 604800); // JIRAFEAU_DAY * 7
+define ('JIRAFEAU_MONTH', 2419200); // JIRAFEAU_WEEK * 4
?>