public function noavatarAction()
 {
     $files = new Files();
     $file = $this->_properties->getProperty('avatar_image');
     $this->_properties->deleteProperty('avatar_image');
     $files->deleteFile($file);
     $this->_forward('index');
 }
Beispiel #2
0
 public function uploadimageAction()
 {
     // Where we come from
     $source = $this->_getParam('source');
     // Verify that it is authorized
     if (!in_array($source, array('design', 'profile'))) {
         throw new Stuffpress_Exception("Invalid source specified {$source}");
     }
     // What are we uploading
     $image = $this->_getParam('image');
     $property = "{$image}_image";
     // Was a file uploaded ?
     if (!isset($_FILES['file'])) {
         $this->addErrorMessage('Upload failed: no files received on server end.');
         return $this->_forward('index', $source, 'admin');
     }
     // Validate the uploaded file
     $tmp_file = $_FILES['file']['tmp_name'];
     $file_name = basename($_FILES['file']['name']);
     $file_type = $_FILES['file']['type'];
     $file_ext = substr(trim(substr($file_name, strrpos($file_name, '.')), '.'), 0, 4);
     // returns the ext only
     // Check file size
     if ($_SERVER['CONTENT_LENGTH'] > 2000000) {
         $this->addErrorMessage('Upload failed: your file size is above 2Mbytes.');
         return $this->_forward('index', $source, 'admin');
     }
     // Check file extension
     if (!in_array(strtolower($file_ext), array("gif", "jpg", "png", "jpeg"))) {
         $this->addErrorMessage('Upload failed: we only support jpg, gif and png files.');
         return $this->_forward('index', $source, 'admin');
     }
     // Assign a random name to the file
     $key = Stuffpress_Token::create(32);
     $root = Zend_Registry::get("root");
     $uploaddir = $root . "/upload/";
     $uploadfile = $uploaddir . '/' . $key;
     // Move the file to the upload folder
     if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
         $this->addErrorMessage('Upload failed: your file size is above 2Mbytes.');
         return $this->_forward('index', $source, 'admin');
     }
     // Store the file in the database
     $files = new Files(array(Stuffpress_Db_Table::USER => $this->_application->user->id));
     $file_id = $files->addFile($key, $file_name, "Lifestream custom image", $file_type, $file_ext);
     // Build a thumbnail of the file
     try {
         $files->fitSquare($file_id, 75, 'thumbnails');
     } catch (Exception $e) {
         $message = $e->getMessage();
         $this->addErrorMessage("Upload failed: could not process image ({$message})");
         $files->deleteFile($key);
         return $this->_forward('index', $source, 'admin');
     }
     // Replace the user property with the new file and delete the older one
     $properties = new Properties(array(Properties::KEY => $this->_application->user->id));
     $old_file = $properties->getProperty($property);
     $properties->setProperty($property, $key);
     if ($old_file) {
         $files->deleteFile($old_file);
     }
     // If we are here, everything went smooth
     $this->addStatusMessage('Your file was successfully uploaded');
     return $this->_forward('index', $source, 'admin');
 }
Beispiel #3
0
	public function deleteAction() {
		// Get, check and setup the parameters
		$item_id = $this->getRequest()->getParam("id");
		
		// Get the source
		$source_id	= $this->_properties->getProperty('stuffpress_source');
		
		//Verify if the requested item exist
		$data		= new Data();
		if (!($item	= $data->getItem($source_id, $item_id))) {
			throw new Stuffpress_NotFoundException("This item does not exist.");
		}
		
		// Get the user
		$users 			= new Users();
		$attributes		= $item->getAttributes();
		$user			= $users->getUser($attributes['user_id']);
		
		// Check if we are the owner
		if ($this->_application->user->id != $user->id) {
			throw new Stuffpress_NotFoundException("Not the owner");
		}
				
		// Create the source
		$source		= StuffpressModel::forUser($user->id);
		
		// If an image or audio file, delete the files
		$file = $item->getFile();
		if ($file) {
			$files = new Files();
			$files->deleteFile($file);
		}
		
		// All checks ok, we can delete !
		$data->deleteItem($source_id, $item_id);
		$source->deleteItem($item_id);

		// We should also delete the associated comments
		$comments = new Comments();
		$comments->deleteComments($source->getID(), $item_id);

		// return that everything is fine
		return $this->_helper->json->sendJson(true);
	}
 public function setcoverAction()
 {
     // Get, check and setup the parameters
     $story_id = $this->getRequest()->getParam("story");
     $source_id = $this->getRequest()->getParam("source");
     $item_id = $this->getRequest()->getParam("item");
     //Verify if the requested story exist
     $stories = new Stories();
     if (!($story = $stories->getStory($story_id))) {
         return $this->_helper->json->sendJson(false);
     }
     // Check if we are the owner
     if ($this->_application->user->id != $story->user_id) {
         return $this->_helper->json->sendJson(false);
     }
     //Verify if the requested source exist
     $sources = new Sources();
     if (!($source = $sources->getSource($source_id))) {
         return $this->_helper->json->sendJson(false);
     }
     // Check if we are the owner
     if ($this->_application->user->id != $source['user_id']) {
         return $this->_helper->json->sendJson(false);
     }
     //Verify if the requested item exist
     $data = new Data();
     if (!($item = $data->getItem($source_id, $item_id))) {
         return $this->_helper->json->sendJson(false);
     }
     // Do we have a url ?
     if (!($url = $item->getImageUrl(ImageItem::SIZE_MEDIUM))) {
         return $this->_helper->json->sendJson(false);
     }
     // Get the old image and delete it
     $files = new Files();
     if ($file = $files->getFileFromKey($story->thumbnail)) {
         $files->deleteFile($file->key);
     }
     // Ok, we can set the image
     $this->setKeyImage($story_id, $url);
     return $this->_helper->json->sendJson(true);
 }
Beispiel #5
0
 /**
  * Удаление записей из таблицы
  * @param string $table
  * @param int $id
  * @param array $files
  * @return mixed
  */
 public function deleteTableRow($table, $id, $files = array('image', 'icon', 'file'))
 {
     // Удаление файлов
     if (is_array($files) && !empty($files)) {
         $data = $this->getAllChildren($table, $id);
         for ($i = 0; $i < count($data); $i++) {
             foreach ($files as $value) {
                 if (isset($data[$i][$value]) && $data[$i][$value] != '') {
                     Files::deleteFile($data[$i][$value]);
                 }
             }
         }
     }
     // Получение ветвей дерева
     $tree_branches = $this->getNodeInfo($table, $id);
     $query = 'CALL delete_tree_table_rows(:current_table, :tree_left, :tree_right)';
     $params = array(':current_table' => $this->__getPrefixTableName($table), ':tree_left' => $tree_branches['tree_left'], ':tree_right' => $tree_branches['tree_right']);
     PdoWrap::execute($query, $params);
     // Clearing blank spaces in a tree
     $query = 'CALL update_tree_branches_after_delete(:current_table, :tree_left, :tree_right)';
     $params = array(':current_table' => $this->__getPrefixTableName($table), ':tree_left' => $tree_branches['tree_left'], ':tree_right' => $tree_branches['tree_right']);
     PdoWrap::execute($query, $params);
     // Логирование оперции
     $this->tableLog(PREF . $table, $id, "3");
 }
 public function clearimageAction()
 {
     // What are we deleting ?
     $image = $this->_getParam('image');
     $property = "{$image}_image";
     // Delete file and property
     $files = new Files();
     $file = $this->_properties->getProperty($property);
     $this->_properties->deleteProperty($property);
     if ($file) {
         $files->deleteFile($file);
     }
     return $this->_helper->json->sendJson(false);
 }
Beispiel #7
0
        // Delete the source settings
        $properties = new SourcesProperties(array(Properties::KEY => $source['id']));
        $properties->deleteAllProperties();
        // Remove the source
        $sdb->deleteSource($source['id']);
        // We should also delete the associated comments
        $comments = new Comments();
        $comments->deleteComments($source['id']);
    }
}
// Delete all user files
$fdb = new Files();
$files = $fdb->getFiles();
if ($files && count($files) > 0) {
    foreach ($files as $file) {
        $fdb->deleteFile($file->key);
    }
}
// Delete all stories
$stdb = new Stories();
$stories = $stdb->getStories();
if ($stories && count($stories) > 0) {
    foreach ($stories as $story) {
        $stdb->deleteStory($story['id']);
    }
}
// Delete all widgets
$wdb = new Widgets();
$widgets = $wdb->getWidgets();
if ($widgets && count($widgets) > 0) {
    foreach ($widgets as $widget) {
 protected function _deleteFileFromDb($key)
 {
     $files = new Files();
     $files->deleteFile($key);
 }
Beispiel #9
0
 /**
  * Удаление записей из таблицы
  * @param $table
  * @param $id
  * @param array $files
  * @return mixed
  */
 public function deleteTableRow($table, $id, $files = array('image', 'icon', 'file'))
 {
     // Удаление файлов
     if (is_array($files) && !empty($files)) {
         $data = $this->getRowById($table, $id);
         foreach ($files as $value) {
             if (isset($data[$value]) && $data[$value] != '') {
                 Files::deleteFile($data[$value]);
             }
         }
     }
     $query = 'CALL delete_table_row_by_field(:current_table, :table_cell, :cell_value)';
     $params = array(':current_table' => $this->__getPrefixTableName($table), ':table_cell' => 'id', ':cell_value' => $id);
     PdoWrap::execute($query, $params);
     // Логирование оперции
     $this->tableLog(PREF . $table, $id, "3");
 }
Beispiel #10
0
 /**
  * Удаление записи из таблицы
  * @param string $table
  * @param int $id
  * @return bool
  */
 public function deleteRow($table, $id)
 {
     parent::deleteRow($table, $id);
     // Удаление характеристик
     $query = 'CALL catalog_features_values_delete(:field_item_id)';
     $params = array(':field_item_id' => $id);
     PdoWrap::execute($query, $params);
     // Удаление изображений
     $images = $this->__getImages($id);
     for ($i = 0; $i < count($images); $i++) {
         Files::deleteFile($images[$i]['image']);
     }
     $query = 'CALL catalog_images_delete(:item_id)';
     $params = array(':item_id' => $id);
     PdoWrap::execute($query, $params);
 }
Beispiel #11
0
$username = $_SESSION['username'];
$oFiles = new Files();
$aUserFiles = $oFiles->getFiles($_SESSION['userid']);
$output = "<html>\n  <head>\n  <meta charset='utf-8'>\n  <title>User restricted- Area</title>\n  <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>\n  <script src='js/func.user_area.js' type='text/javascript'></script>\n</head>\n</html>\n<body>\nEingeloogt als User: "******"<strong> " . $username . "</strong>\n<a href='index.php?redirect=logout'>Logout</a>\n<br/>\n\n<div>\n<h2>File upload - overview</h2><br/>\n<form action='user_area.php?upload=1' method='post' name='upload' enctype='multipart/form-data'>\n Wählen Sie hier eine Datei, die Sie uploaden möchten:<br/>\n <input type='file' name='upload' size='100'>\n <input type='submit' name='fileuploader' value='Upload'>\n\n</form>\n</div>";
// here call function to insert new data
if (isset($_GET['upload'])) {
    $filename = $_FILES['upload']['name'];
    $type = $_FILES['upload']['type'];
    $size = $_FILES['upload']['size'];
    $created = date('Y-m-d H:i:s');
    $oFiles->newFile($filename, $type, $size, $created);
    header('Location: user_area.php');
}
// actions von GET abfragen
if (isset($_GET['action']) && $_GET['action'] == "delete") {
    $oFiles->deleteFile($_GET['id']);
    header('Location: user_area.php');
}
if (isset($_GET['renamed']) && isset($_POST['rename_frm_submit'])) {
    $oFiles->renameFile($_POST['fileid'], $_POST['oldfile'], $_POST['newname']);
    header('Location: user_area.php');
}
//show this only when file should be renamed
if (isset($_GET['action']) && $_GET['action'] == "rename") {
    $output .= "<div style='margin: 10px 10px; padding: 10px 10px; background-color: #CCC;' id='file_rename'>\n\t              <span id='close_div'><img src='icons/close.png' style='float:right;' title='close'></span>\n                  <form method='post' action='user_area.php?renamed=1' name='filerename'>\n                  <input type='hidden' name='fileid' value='" . $_GET['id'] . "'>\n                  <input type='hidden' name='oldfile' value='" . $oFiles->getFileNameById($_GET['id']) . "'>\n                  new filename: <input type='text' name='newname' maxlength='100' size='100' value='" . $oFiles->getFileNameById($_GET['id']) . "'><br>\n                  <input type='submit' value='rename' name='rename_frm_submit'>\n                  </form>\n                </div>";
}
//print_r($aUserFiles);
// show this, if user has files uploaded
if ($aUserFiles) {
    $output .= "<div class='filelist'>";
    $output .= "Hier sehen Sie alle Dateien, die Sie hochgeladen haben. <br>\n\t       Wenn Sie in die rechte Spalte auf das Icon klicken, können Sie die Datei löschen, mit dem Icon auf der mittleren Spalte <br>\n\t\t   können Sie es umbenennen. <br><br>";