Beispiel #1
0
 /**
  * Notify the owner of the file passed as parameter that its file is going
  * to be deleted
  *
  * @param App_Model_File $file
  */
 private function notifyDeletionByEmail(App_Model_File $file)
 {
     try {
         $mail = $this->createMail();
         $subject = __r('[FileZ] Your file "%file_name%" is going to be deleted', array('file_name' => $file->file_name));
         $msg = __r('email_delete_notif (%file_name%, %file_url%, %filez_url%, %available_until%)', array('file_name' => $file->file_name, 'file_url' => $file->getDownloadUrl(), 'filez_url' => url_for('/'), 'available_until' => $file->getAvailableUntil()->toString(Zend_Date::DATE_FULL)));
         $mail->setBodyText($msg);
         $mail->setSubject($subject);
         $mail->addTo($file->uploader_email);
         $mail->send();
         fz_log('Delete notification sent to ' . $file->uploader_email, FZ_LOG_CRON);
     } catch (Exception $e) {
         fz_log('Can\'t send email to ' . $file->uploader_email . ' file_id:' . $file->id, FZ_LOG_CRON_ERROR);
     }
 }
Beispiel #2
0
 /**
  * Share a file url by mail
  */
 public function emailAction()
 {
     $this->secure();
     $user = $this->getUser();
     $file = $this->getFile();
     $this->checkOwner($file, $user);
     set('file', $file);
     // Send mails
     $user = $this->getUser();
     $mail = $this->createMail();
     $subject = __r('[FileZ] "%sender%" wants to share a file with you', array('sender' => $user['firstname'] . ' ' . $user['lastname']));
     $msg = __r('email_share_file (%file_name%, %file_url%, %sender%, %msg%)', array('file_name' => $file->file_name, 'file_url' => $file->getDownloadUrl(), 'msg' => $_POST['msg'], 'sender' => $user['firstname'] . ' ' . $user['lastname']));
     $mail->setBodyText($msg);
     $mail->setSubject($subject);
     $mail->setReplyTo($user['email'], $user['firstname'] . ' ' . $user['lastname']);
     $mail->clearFrom();
     $mail->setFrom($user['email'], $user['firstname'] . ' ' . $user['lastname']);
     $emailValidator = new Zend_Validate_EmailAddress();
     foreach (explode(' ', $_POST['to']) as $email) {
         $email = trim($email);
         if (empty($email)) {
             continue;
         }
         if ($emailValidator->isValid($email)) {
             $mail->addBcc($email);
         } else {
             $msg = __r('Email address "%email%" is incorrect, please correct it.', array('email' => $email));
             return $this->returnError($msg, 'file/email.php');
         }
     }
     try {
         $mail->send();
         return $this->returnSuccessOrRedirect('/');
     } catch (Exception $e) {
         fz_log('Error while sending email', FZ_LOG_ERROR, $e);
         $msg = __('An error occured during email submission. Please try again.');
         return $this->returnError($msg, 'file/email.php');
     }
 }
Beispiel #3
0
        echo $msg;
        ?>
</pre>
        <?php 
    }
    ?>
        </div>
      <?php 
}
?>

      <?php 
if (isset($fz_user)) {
    ?>
        <p id="disk-usage"><?php 
    echo __r('Using %space% of %quota%', array('space' => '<b id="disk-usage-value">' . $fz_user->getDiskUsage() . '</b>', 'quota' => fz_config_get('app', 'user_quota')));
    ?>
.
        </p>
      <?php 
}
?>

      <div id="support">
        <?php 
if (fz_config_get('looknfeel', 'help_url')) {
    ?>
          <a href="<?php 
    echo url_for(fz_config_get('looknfeel', 'help_url'));
    ?>
" class="help" target="#_blank"><?php 
Beispiel #4
0
    echo $file->getDownloadUrl();
    ?>
/view">
        <img src="<?php 
    echo $file->getDownloadUrl();
    ?>
/view" class="preview-image" width="617px"/>
      </a>
    </p>
  <?php 
}
?>

  <p id="availability">
    <?php 
echo __r('Available from %available_from% to %available_until%', array('available_from' => $file->getAvailableFrom()->toString(Zend_Date::DATE_LONG), 'available_until' => '<b>' . $file->getAvailableUntil()->toString(Zend_Date::DATE_LONG) . '</b>'));
?>
  </p>

  <p id="owner">
    <?php 
echo __('Uploaded by:');
?>
 <b><?php 
echo h($uploader);
?>
</b>
  </p>

  <?php 
if ($file->comment) {
Beispiel #5
0
        echo $msg;
        ?>
</pre>
        <?php 
    }
    ?>
        </div>
      <?php 
}
?>

      <?php 
if (isset($fz_user)) {
    ?>
        <p id="disk-usage"><?php 
    echo __r('Using %space% of %quota%', array('space' => '<b id="disk-usage-value">' . $fz_user->getDiskUsage() . '</b>', 'quota' => $fz_user->quota));
    ?>
.
        </p>
      <?php 
}
?>

      <div id="support">
        <?php 
if (fz_config_get('looknfeel', 'help_url')) {
    ?>
          <a href="<?php 
    echo url_for(fz_config_get('looknfeel', 'help_url'));
    ?>
" class="help" target="#_blank"><?php 
Beispiel #6
0
        echo $msg;
        ?>
</pre>
        <?php 
    }
    ?>
        </div>
      <?php 
}
?>

      <?php 
if (isset($user)) {
    ?>
        <p id="disk-usage"><?php 
    echo __r('Using %space% of %quota%', array('space' => '<b id="disk-usage-value">' . bytesToShorthand(Fz_Db::getTable('File')->getTotalDiskSpaceByUser($user)) . '</b>', 'quota' => fz_config_get('app', 'user_quota')));
    ?>
.
        </p>
      <?php 
}
?>

      <div id="support">
        <?php 
if (fz_config_get('looknfeel', 'help_url')) {
    ?>
          <a href="<?php 
    echo url_for(fz_config_get('looknfeel', 'help_url'));
    ?>
" class="help" target="#_blank"><?php 
Beispiel #7
0
 /**
  * Function called on file upload error. A message corresponding to the error
  * code passed as parameter is return to the user. Error codes come from
  * $_FILES['userfile']['error'] plus a custom error code called
  * 'UPLOAD_ERR_QUOTA_EXCEEDED'
  *
  * @param integer $errorCode
  */
 private function onFileUploadError($errorCode = null)
 {
     $response['status'] = 'error';
     $response['statusText'] = __('An error occurred while uploading the file.') . ' ';
     if ($errorCode === null) {
         return $this->returnData($response);
     }
     switch ($errorCode) {
         case UPLOAD_ERR_NO_TMP_DIR:
             fz_log('upload error (Missing a temporary folder)', FZ_LOG_ERROR);
             break;
         case UPLOAD_ERR_CANT_WRITE:
             fz_log('upload error (Failed to write file to disk)', FZ_LOG_ERROR);
             break;
             // These errors come from the client side, let him know what's wrong
         // These errors come from the client side, let him know what's wrong
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             $response['statusText'] .= __('The uploaded file exceeds the max file size.') . ' : (' . ini_get('upload_max_filesize') . ')';
             break;
         case UPLOAD_ERR_PARTIAL:
             $response['statusText'] .= __('The uploaded file was only partially uploaded.');
             break;
         case UPLOAD_ERR_NO_FILE:
             $response['statusText'] .= __('No file was uploaded.');
             break;
         case UPLOAD_ERR_QUOTA_EXCEEDED:
             $response['statusText'] .= __r('You exceeded your disk space quota (%space%).', array('space' => fz_config_get('app', 'user_quota')));
         case UPLOAD_ERR_ALLOWED_EXTS:
             $response['statusText'] .= __r('The file is not allowed to be uploaded. Note that files allowed need to be %allowed_exts%.', array('allowed_exts' => fz_config_get('app', 'allowed_exts')));
     }
     return $this->returnData($response);
 }
Beispiel #8
0
 /**
  * Function used to check if a new or updated user is valid
  *
  * @param $action the action is to update or to create a user. Value 'new' or 'update'.
  * @return array (attribut => error message)
  */
 public function isValid($action = 'new')
 {
     $return = array();
     if (!filter_var($this->email, FILTER_VALIDATE_EMAIL)) {
         $return['email'] = __r('"%s%" is not a valid email.', array('s' => $this->email));
     }
     if (null == $this->username) {
         $return['username'] = __('The username should not be blank');
     }
     if (4 > strlen($this->password)) {
         $return['password'] = __('The password is too short.');
     }
     if ('new' == $action) {
         if ($this->getTable()->findByUsername($this->username) !== null) {
             $return['username'] = __('This username is already used.');
         }
         if ($this->getTable()->findByEmail($this->email) !== null) {
             $return['email'] = __('This email is already used.');
         }
     } elseif ('update' == $action) {
         if (null != $this->getTable()->findByUsername($this->username) && params('id') != $this->getTable()->findByUsername($this->username)->getId()) {
             $return['username'] = __('This username belongs to another user.');
         }
         if (null != $this->getTable()->findByEmail($this->email) && params('id') != $this->getTable()->findByEmail($this->email)->getId()) {
             $return['email'] = __('This email belongs to another user.');
         }
     }
     return $return;
 }
Beispiel #9
0
} else {
    ?>
      <?php 
    echo h($uploader['email']);
    ?>
    <?php 
}
?>
  </p>
  <p>
      <?php 
echo __('Availability');
?>
 :
      <?php 
echo __r('between %available_from% and %available_until%', array('available_from' => $file->getAvailableFrom()->toString(Zend_Date::DATE_LONG), 'available_until' => $file->getAvailableUntil()->toString(Zend_Date::DATE_LONG)));
?>
  </p>
  <?php 
if ($file->comment) {
    ?>
    <p><?php 
    echo __('Comments');
    ?>
 : <?php 
    echo h($file->comment);
    ?>
</p>
  <?php 
}
?>
Beispiel #10
0
function create_link($path, $name)
{
    global $cwd, $useForce;
    echo __g("Linking {$name}...");
    try {
        if (file_exists($path)) {
            if (!file_exists(HOME . DS . $path) || $useForce) {
                if (file_exists(HOME . DS . $path)) {
                    $new_name = HOME . DS . $path . ".bak_dotfiles_installer";
                    while (file_exists($new_name)) {
                        $new_name .= ".copy";
                    }
                    rename(HOME . DS . $path, $new_name);
                }
                symlink($cwd . DS . $path, HOME . DS . $path);
                echo __g("DONE\n");
            } else {
                throw new RuntimeException("{$name} files already exist");
            }
        } else {
            throw new RuntimeException("{$name} files appear to be missing");
        }
    } catch (RuntimeException $e) {
        echo __r("FAIL (" . $e->getMessage() . ")\n");
    }
}
Beispiel #11
0
<h2><?php 
echo __r('Do you really want to delete: %filename%?', array('filename' => '<span class="filename">' . h($file->file_name)));
?>
</span></h2>

<form method="post">
  <p style="padding: 2em 0;">
    <input type="submit" value="<?php 
echo __('Yes, delete that file');
?>
" class="delete"/> |
    <a href="#" onclick="javascript:history.go(-1); return false;"><?php 
echo __('No, go back to previous page');
?>
</a>
  </p>
</form>
Beispiel #12
0
    <td>
      <a href="<?php 
    echo url_for('/admin/users/' . $file->getUploader()->id);
    ?>
">
        <?php 
    echo h($file->getUploader());
    ?>
 (<?php 
    echo h($file->getUploader()->username);
    ?>
)
      </a>
    </td>
    <td><?php 
    echo __r('from %from% to %to%', array('from' => $file->getAvailableFrom()->get(Zend_Date::MONTH) == $file->getAvailableUntil()->get(Zend_Date::MONTH) ? $file->getAvailableFrom()->toString('d') : $file->getAvailableFrom()->toString('d MMMM'), 'to' => '<b>' . $file->getAvailableUntil()->toString('d MMMM') . '</b>'));
    ?>
    </td>
    <td><?php 
    echo $file->getReadableFileSize();
    ?>
</td>
    <td><?php 
    echo (int) $file->download_count;
    ?>
</td>
    <td><a href="<?php 
    echo $file->getDownloadUrl() . '/delete';
    ?>
"><?php 
    echo __('Delete');
Beispiel #13
0
        ?>
<td>
      <a href="<?php 
        echo url_for('/admin/users/' . $user_item->id . '/edit');
        ?>
">
         <?php 
        echo __('Edit');
        ?>
      </a>
    <?php 
        if ($fz_user->id != $user_item->id) {
            // prevents self-deleting
            ?>
        <a onclick='javascript:return confirm (<?php 
            echo json_encode(__r('Are you sure you want to delete the user "%displayname%" (%username%)', array('displayname' => $user_item, 'username' => $user_item->username)));
            ?>
)'
           href="<?php 
            echo url_for('/admin/users/' . $user_item->id . '/delete');
            ?>
">
          <?php 
            echo __('Delete');
            ?>
        </a>
    <?php 
        }
        ?>
    </td><?php 
    }
Beispiel #14
0
    ?>
/extend" class="extend" title="<?php 
    echo __('Extend one more day');
    ?>
">
        <?php 
    echo __('Extend one more day');
    ?>
      </a>
    <?php 
}
?>
  </p>
  <p class="download-counter">
      <?php 
echo $file->download_count == 0 ? __('Never downloaded') : ($file->download_count == 1 ? __('Downloaded once') : __r('Download %x% times', array('x' => (int) $file->download_count)));
// TODO ugly DIY plural ...
?>
  </p>
  <p class="delete">
    <a href="<?php 
echo $file->getDownloadUrl();
?>
/delete" class="delete" title="<?php 
echo __('Delete');
?>
">
      <?php 
echo __('Delete');
?>
    </a>
Beispiel #15
0
<h2><?php 
echo __('Admin dashboard');
?>
</h2>

<?php 
echo __r('Manage %NumberOfUsers% users</a> and %NumberOfFiles% files</a>.', array('NumberOfUsers' => '<a href="' . url_for('admin/users') . '">' . $numberOfUsers, 'NumberOfFiles' => '<a href="' . url_for('admin/files') . '">' . $numberOfFiles));
?>
 (<?php 
echo $totalDiskSpace;
?>
).
Beispiel #16
0
 /**
  * Notify the file's owner by email that its file has been downloaded
  *
  * @param App_Model_File $file
  */
 private function sendFileDownloadedMail(App_Model_File $file)
 {
     if (!$file->notify_uploader) {
         return;
     }
     // find user IP
     // TODO: extract this function to generic place
     $ipaddress = '';
     if ($_SERVER['HTTP_CLIENT_IP']) {
         $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
     } else {
         if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
             $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
         } else {
             if ($_SERVER['HTTP_X_FORWARDED']) {
                 $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
             } else {
                 if ($_SERVER['HTTP_FORWARDED_FOR']) {
                     $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
                 } else {
                     if ($_SERVER['HTTP_FORWARDED']) {
                         $ipaddress = $_SERVER['HTTP_FORWARDED'];
                     } else {
                         if ($_SERVER['REMOTE_ADDR']) {
                             $ipaddress = $_SERVER['REMOTE_ADDR'];
                         } else {
                             $ipaddress = 'UNKNOWN';
                         }
                     }
                 }
             }
         }
     }
     // Send confirmation mail
     $user = Fz_Db::getTable('User')->findById($file->created_by);
     // I don't get why $user = $this->getUser (); doesn't work ???
     $mail = $this->createMail();
     $mail->addTo($user->email);
     $mail->addTo($user->email, $user->firstname . ' ' . $user->lastname);
     $subject = __r('[FileZ] "%file_name%" downloaded', array('file_name' => $file->file_name));
     $msg = __r('email_file_downloaded (%file_name%, %file_url%, %sender%, %ip%)', array('file_name' => $file->file_name, 'file_url' => $file->getDownloadUrl(), 'sender' => $user, 'ip' => $ipaddress));
     $mail->setBodyText($msg);
     $mail->setSubject($subject);
     $mail->setReplyTo($user->email, $user);
     $mail->clearFrom();
     $mail->setFrom(fz_config_get('email', 'from_email'), fz_config_get('email', 'from_name'));
     try {
         $mail->send();
     } catch (Exception $e) {
         fz_log('Can\'t send email "File Downloaded" : ' . $e, FZ_LOG_ERROR);
     }
 }
Beispiel #17
0
  <form method="POST" enctype="multipart/form-data" action="<?php 
echo url_for('upload');
?>
" id="upload-form">
  <input type="hidden" name="MAX_FILE_SIZE" value="<?php 
echo $max_upload_size;
?>
" />
  <div id="file">
    <label for="file-input"><?php 
echo __r('File (Max size: %size%)', array('size' => bytesToShorthand($max_upload_size)));
?>
 :</label>
    <div id="input-file">
      <input type="file" id="file-input" name="file" value="" alt="<?php 
echo __('File');
?>
" />
    </div>
  </div>
  <div id="lifetime">
    <label for="select-lifetime"><?php 
echo __('Lifetime');
?>
 :</label>
    <select id="select-lifetime" name="lifetime" alt="<?php 
echo __('Select a lifetime');
?>
">
      <?php 
$default = fz_config_get('app', 'default_file_lifetime', 10);