+ $filename = VAR_LINKS . s2p("$hash") . $hash . '_download';
+
+ $handle = fopen($filename, 'w');
+ fwrite($handle, $count . NL . time() . NL . $ip);
+ fclose($handle);
+}
+
+function jirafeau_create_upload_finished_box($preview = true) {
+ ?>
+
+ <div id="upload_finished">
+ <p><?php echo t('FILE_UP') ?></p>
+
+ <div id="upload_finished_download_page">
+ <p>
+ <a id="upload_link" href=""><?php echo t('DL_PAGE') ?></a>
+ <a id="upload_link_email" href=""><img id="upload_image_email"/></a>
+ </p><p>
+ <code id=upload_link_text></code>
+ <button id="upload_link_button">📋</button>
+ </p>
+ </div>
+
+ <?php if ($preview == true) {
+ ?>
+ <div id="upload_finished_preview">
+ <p>
+ <a id="preview_link" href=""><?php echo t('VIEW_LINK') ?></a>
+ </p><p>
+ <code id=preview_link_text></code>
+ <button id="preview_link_button">📋</button>
+ </p>
+ </div>
+ <?php
+} ?>
+
+ <div id="upload_direct_download">
+ <p>
+ <a id="direct_link" href=""><?php echo t('DIRECT_DL') ?></a>
+ </p><p>
+ <code id=direct_link_text></code>
+ <button id="direct_link_button">📋</button>
+ </p>
+ </div>
+
+ <div id="upload_delete">
+ <p>
+ <a id="delete_link" href=""><?php echo t('DELETE_LINK') ?></a>
+ </p><p>
+ <code id=delete_link_text></code>
+ <button id="delete_link_button">📋</button>
+ </p>
+ </div>
+
+ <div id="upload_validity">
+ <p><?php echo t('VALID_UNTIL'); ?>:</p>
+ <p id="date"></p>
+ </div>
+</div>
+<?php
+}
+
+function jirafeau_get_expiration_time_options() {
+ return
+ array(
+ array(
+ 'value' => 'minute',
+ 'label' => '1_MIN'
+ ),
+ array(
+ 'value' => 'hour',
+ 'label' => '1_H'
+ ),
+ array(
+ 'value' => 'day',
+ 'label' => '1_D'
+ ),
+ array(
+ 'value' => 'week',
+ 'label' => '1_W'
+ ),
+ array(
+ 'value' => 'fortnight',
+ 'label' => '2_W'
+ ),
+ array(
+ 'value' => 'month',
+ 'label' => '1_M'
+ ),
+ array(
+ 'value' => 'quarter',
+ 'label' => '1_Q'
+ ),
+ array(
+ 'value' => 'year',
+ 'label' => '1_Y'
+ ),
+ array(
+ 'value' => 'none',
+ 'label' => 'NONE'
+ )
+ );
+}
+
+
+
+ /**
+ *
+ * creates the time selection field
+ * @param mixed $cfg
+ * @return void
+ */
+ function jirafeau_create_selection_array($cfg) {
+ echo
+ '<select name="time" id="select_time">';
+
+
+ $expirationTimeOptions = jirafeau_get_expiration_time_options();
+
+ foreach ($expirationTimeOptions as $expirationTimeOption) {
+ $selected = ($expirationTimeOption['value'] === $cfg['availability_default'])? 'selected="selected"' : '';
+ if (true === $cfg['availabilities'][$expirationTimeOption['value']]) {
+ echo '<option value="' . $expirationTimeOption['value'] . '" ' .
+ $selected . '>' . t($expirationTimeOption['label']) . '</option>';
+ }
+ }
+ echo '</select>';
+ }
+
+ function jirafeau_datestr_to_int ($time_str) {
+ $time = time();
+ switch ($time_str) {
+ 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 'fortnight':
+ $time += JIRAFEAU_FORTNIGHT;
+ break;
+ case 'month':
+ $time += JIRAFEAU_MONTH;
+ break;
+ case 'quarter':
+ $time += JIRAFEAU_QUARTER;
+ break;
+ case 'year':
+ $time += JIRAFEAU_YEAR;
+ break;
+ default:
+ $time = JIRAFEAU_INFINITY;
+ break;
+ }
+ return $time;
+}
+
+
+
+
+/**
+ * links or copy a local file
+ * TODO: boolean in config for linking
+ * @param string $filepath
+ * @param $one_time_download is the file a one time download ?
+ * @param $key if not empty, protect the file with this key
+ * @param $time the time of validity of the file
+ * @param $ip uploader's ip
+ * @param $crypt boolean asking to crypt or not
+ * @param $link_name_length size of the link name
+ * @returns an array containing some information
+ * 'error' => information on possible errors
+ * 'link' => the link name of the uploaded file
+ * 'delete_link' => the link code to delete file
+ */
+function jirafeau_copy_local_file($local_file_path, $one_time_download, $key, $time, $ip, $crypt, $link_name_length, $file_hash_method) {
+
+ if (!file_exists($local_file_path)) {
+ return (array(
+ 'error' =>
+ array('has_error' => true,
+ 'why' => t('INTERNAL_ERROR_FILE_NOT_EXIST')),
+ 'link' =>'',
+ 'delete_link' => ''));
+ }
+ if(
+ // sanity check if file can be opened
+ $file = fopen($local_file_path, "r")
+ )
+ {
+ // close file pointer - it's not needed here
+ fclose($file);
+ $time_in_int = jirafeau_datestr_to_int($time);
+ return jirafeau_add_file(
+ jirafeau_create_file_array($local_file_path),
+ $one_time_download,
+ $key,
+ $time_in_int,
+ $ip,
+ $crypt,
+ $link_name_length,
+ $file_hash_method,
+ false
+ );
+ }
+ else {
+ return (array(
+ 'error' =>
+ array('has_error' => true,
+ 'why' => t('INTERNAL_ERROR_FP_OPEN_LOCAL')),
+ 'link' =>'',
+ 'delete_link' => ''));