public function removeThis() { if (file_exists($this->file_path_server)) { unlink($this->file_path_server); } erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/', str_replace('var/', '', $this->file_path)); erLhcoreClassChat::getSession()->delete($this); }
public static function validateAdminTheme(erLhAbstractModelAdminTheme &$clickform) { $definition = array('Name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'header_content' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'header_css' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'static_content_name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'static_content_hash' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'static_js_content_name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'static_js_content_hash' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'static_css_content_name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'static_css_content_hash' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY)); $form = new ezcInputForm(INPUT_POST, $definition); $Errors = array(); $currentUser = erLhcoreClassUser::instance(); if (!isset($_POST['csfr_token']) || !$currentUser->validateCSFRToken($_POST['csfr_token'])) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('icclicktocallform/form', 'Invalid CSRF token!'); } if (!$form->hasValidData('Name') || $form->Name == '') { $Errors['Name'] = erTranslationClassLhTranslation::getInstance()->getTranslation('icclicktocallform/form', 'Please enter a name'); } else { $clickform->name = $form->Name; } if ($form->hasValidData('header_content')) { $clickform->header_content = $form->header_content; } if ($form->hasValidData('header_css')) { $clickform->header_css = $form->header_css; } $resourcesArray = array('static_content', 'static_js_content', 'static_css_content'); $supportedExtensions = array('zip', 'doc', 'docx', 'ttf', 'pdf', 'xls', 'ico', 'gif', 'xlsx', 'jpg', 'jpeg', 'png', 'bmp', 'rar', '7z', 'css', 'js', 'eot', 'woff', 'woff2', 'svg'); // Validate resources foreach ($resourcesArray as $resource) { if ($form->hasValidData($resource . '_hash') && !empty($form->{$resource . '_hash'})) { $customFields = $currentStaticResources = $clickform->{$resource . '_array'}; foreach ($form->{$resource . '_hash'} as $key => $customFieldType) { if (!erLhcoreClassSearchHandler::isFile($resource . '_file_' . $key, $supportedExtensions) && !isset($currentStaticResources[$key]['file'])) { $Errors[$resource . '_file_' . $key] = erTranslationClassLhTranslation::getInstance()->getTranslation('icclicktocallform/form', 'File not chosen for') . (isset($form->{$resource . '_name'}[$key]) ? ' - ' . htmlspecialchars($form->{$resource . '_name'}[$key]) : ''); } } // If there is no errors upload files if (empty($Errors)) { foreach ($form->{$resource . '_hash'} as $key => $customFieldType) { $customFields[$key]['name'] = $form->{$resource . '_name'}[$key]; $customFields[$key]['hash'] = $key; if (erLhcoreClassSearchHandler::isFile($resource . '_file_' . $key, $supportedExtensions)) { // Check there is already uploaded file and remove it $clickform->removeResource($resource, $key); // Store new file if required $dir = 'var/storageadmintheme/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/' . $clickform->id . '/'; erLhcoreClassChatEventDispatcher::getInstance()->dispatch('admintheme.filedir', array('dir' => &$dir, 'storage_id' => $clickform->id)); erLhcoreClassFileUpload::mkdirRecursive($dir); $customFields[$key]['file'] = erLhcoreClassSearchHandler::moveUploadedFile($resource . '_file_' . $key, $dir . '/', '.'); $customFields[$key]['file_dir'] = $dir; } } $clickform->{$resource} = json_encode($customFields, JSON_HEX_APOS); } } else { $clickform->{$resource} = ''; } } return $Errors; }
public function removeThis() { if (file_exists($this->file_path_server)) { unlink($this->file_path_server); } if ($this->file_path != '') { erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/', str_replace('var/', '', $this->file_path)); } erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.remove_file', array('chat_file' => &$this)); erLhcoreClassChat::getSession()->delete($this); }
public function deletePhoto($attr) { if ($this->{$attr} != '') { if (file_exists($this->{$attr . '_path'} . $this->{$attr})) { unlink($this->{$attr . '_path'} . $this->{$attr}); } if ($this->{$attr . '_path'} != '') { erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/storagetheme/', str_replace('var/storagetheme/', '', $this->{$attr . '_path'})); } erLhcoreClassChatEventDispatcher::getInstance()->dispatch('theme.edit.remove_' . $attr, array('theme' => &$this, 'path_attr' => $attr . '_path', 'name' => $this->{$attr})); $this->{$attr} = ''; $this->{$attr . '_path'} = ''; } }
/** * Removes attributes if required * */ public function removeResource($scope, $key) { $content = $this->{$scope . '_array'}; if (isset($content[$key]['file']) && isset($content[$key]['file_dir'])) { if (file_exists($content[$key]['file_dir'] . $content[$key]['file'])) { unlink($content[$key]['file_dir'] . $content[$key]['file']); erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/storageadmintheme/', str_replace('var/storageadmintheme/', '', $content[$key]['file_dir'])); } // Remove removed attribute unset($content[$key]); // Set attr $this->{$scope . '_array'} = $content; $this->{$scope} = json_encode($content, JSON_HEX_APOS); $this->saveThis(); } }
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $matches = array(); if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $type, $matches)) { $name = $uploadFileName = 'clipboard.' . $matches[1]; } else { $uploadFileName = $name; } if (!preg_match($this->options['accept_file_types_lhc'], $uploadFileName)) { throw new Exception($this->get_error_message('accept_file_types')); return false; } $file = parent::handle_file_upload_parent($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { $fileUpload = new erLhcoreClassModelChatFile(); $fileUpload->size = $file->size; $fileUpload->type = $file->type; $fileUpload->name = $file->name; $fileUpload->date = time(); $fileUpload->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0; $fileUpload->upload_name = isset($this->options['file_name_manual']) && $this->options['file_name_manual'] != '' ? $this->options['file_name_manual'] . ' - ' . $name : $name; $fileUpload->file_path = $this->options['upload_dir']; $fileUpload->chat_id = 0; $matches = array(); if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $fileUpload->type, $matches)) { $fileUpload->extension = $matches[1]; } else { $partsFile = explode('.', $name); $fileUpload->extension = end($partsFile); } $fileUpload->saveThis(); $this->uploadedFile = $fileUpload; } else { throw new Exception($file->error); } return $file; }
public function removeThis() { foreach ($this->content_array as $key => $content) { if ($content['definition']['type'] == 'file' && file_exists($content['filepath'] . $content['filename'])) { unlink($content['filepath'] . $content['filename']); erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/', str_replace('var/', '', $content['filepath'])); } } erLhcoreClassAbstract::getSession()->delete($this); }
public static function storeCollectedInformation($form, $collectedInformation) { $formCollected = new erLhAbstractModelFormCollected(); $formCollected->ip = erLhcoreClassIPDetect::getIP(); $formCollected->ctime = time(); $formCollected->form_id = $form->id; $formCollected->identifier = isset($_POST['identifier']) ? $_POST['identifier'] : (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); $formCollected->saveThis(); // Finish collect information foreach ($collectedInformation as $fieldName => &$params) { if ($params['definition']['type'] == 'file') { $dir = 'var/storageform/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/' . $formCollected->id . '/'; erLhcoreClassChatEventDispatcher::getInstance()->dispatch('form.fill.file_path', array('path' => &$dir, 'storage_id' => $formCollected->id)); erLhcoreClassFileUpload::mkdirRecursive($dir); $file = erLhcoreClassSearchHandler::moveUploadedFile($params['definition']['name'], $dir); $params['filename'] = $file; $params['filepath'] = $dir; erLhcoreClassChatEventDispatcher::getInstance()->dispatch('form.fill.store_file', array('file_params' => &$params)); } } $formCollected->content = serialize($collectedInformation); $formCollected->saveThis(); // Inform user about filled form erLhcoreClassChatMail::informFormFilled($formCollected, array('email' => self::$mainEmail)); }
$imgData = base64_decode(str_replace('data:image/png;base64,', '', $_POST['data'])); $fileData = erLhcoreClassModelChatConfig::fetch('file_configuration'); $data = (array) $fileData->data; if (strlen($imgData) < $data['fs_max'] * 1024 && $imgData != '') { $storageID = false; if ($chat !== false) { $path = 'var/storage/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/' . $chat->id . '/'; $storageID = $chat->id; } else { $path = 'var/storage/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/' . $vid->id . '/'; $storageID = $vid->id; } $response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.storescreenshot.screenshot_path', array('path' => &$path, 'storage_id' => $storageID)); $fileNameHash = sha1($imgData . time()); if ($response === false) { erLhcoreClassFileUpload::mkdirRecursive($path); } file_put_contents($path . $fileNameHash, $imgData); $imageSize = getimagesize($path . $fileNameHash); if ($imageSize) { try { $db = ezcDbInstance::get(); $db->beginTransaction(); if ($chat !== false && $chat->screenshot !== false) { $chat->screenshot->removeThis(); $chat->screenshot_id = 0; } if (is_object($vid) && $vid->screenshot !== false) { $vid->screenshot->removeThis(); $vid->screenshot_id = 0; }
public function removePDF() { if ($this->pdf_file != '' && file_exists($this->pdf_file_path_server)) { unlink($this->pdf_file_path_server); } if ($this->pdf_to_img_converted && $this->pages_pdf_count > 0) { foreach ($this->pages_pdf as $pdfFilePath) { if (file_exists($pdfFilePath)) { unlink($pdfFilePath); } } } erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/', $this->file_path . 'img'); }
public static function convertPDFToPNG(erLhcoreClassModelDocShare &$fileObject) { $pdfFile = $fileObject->pdf_file_path_server; if ($fileObject->pdf_file != '' && file_exists($pdfFile)) { try { $config = erConfigClassLhConfig::getInstance(); $objectData = erLhcoreClassModelChatConfig::fetch('doc_sharer'); $dataDocSharer = (array) $objectData->data; erLhcoreClassFileUpload::mkdirRecursive($fileObject->pdftoimg_path, true, $dataDocSharer['http_user_name'], $dataDocSharer['http_user_group_name']); $ocrParsed = true; // Prepare to run ImageMagick command $descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')); $appendCommand = ''; if ($dataDocSharer['pdftoppm_limit'] > 0) { $appendCommand .= ' -l ' . $dataDocSharer['pdftoppm_limit']; } $command = $dataDocSharer['pdftoppm_path'] . $appendCommand . ' -png -r 200 ' . escapeshellarg($pdfFile) . ' ' . $fileObject->pdftoimg_path . $fileObject->id; // Open color_indexer process $imageProcess = proc_open($command, $descriptors, $pipes); // Close STDIN pipe fclose($pipes[0]); $errorString = ''; $outputString = ''; // Read STDERR do { $errorString .= rtrim(fgets($pipes[2], 1024), "\n"); } while (!feof($pipes[2])); // Wait for process to terminate and store return value $status = proc_get_status($imageProcess); while ($status['running'] !== false) { // Sleep 1/100 second to wait for convert to exit usleep(10000); $status = proc_get_status($imageProcess); } $return = proc_close($imageProcess); $data = ezcBaseFile::findRecursive($fileObject->pdftoimg_path, array("@{$fileObject->id}-.*\\.png@"), array()); $contentPages = array(); $pagesCount = 0; foreach ($data as $key => $file) { $pagesCount++; $parts = explode('-', $file); array_pop($parts); $parts[] = '-' . $pagesCount . '.png'; $newName = implode('', $parts); rename($file, $newName); $file = $newName; chown($file, $dataDocSharer['http_user_name']); chgrp($file, $dataDocSharer['http_user_group_name']); chmod($file, 0664); } $fileObject->pdf_to_img_converted = 1; $fileObject->pages_pdf_count = $pagesCount; $fileObject->saveThis(); } catch (Exception $e) { throw $e; } } }
public static function validateUserPhoto(&$userData, $params = array()) { $Errors = false; if (isset($_FILES["UserPhoto"]) && is_uploaded_file($_FILES["UserPhoto"]["tmp_name"]) && $_FILES["UserPhoto"]["error"] == 0 && erLhcoreClassImageConverter::isPhoto('UserPhoto')) { $Errors = array(); $dir = 'var/userphoto/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/' . $userData->id . '/'; erLhcoreClassChatEventDispatcher::getInstance()->dispatch('user.edit.photo_path', array('dir' => &$dir, 'storage_id' => $userData->id)); $response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('user.edit.photo_store', array('file_post_variable' => 'UserPhoto', 'dir' => &$dir, 'storage_id' => $userData->id)); // There was no callbacks if ($response === false) { erLhcoreClassFileUpload::mkdirRecursive($dir); $file = qqFileUploader::upload($_FILES, 'UserPhoto', $dir); } else { $file = $response['data']; } if (!empty($file["errors"])) { foreach ($file["errors"] as $err) { $Errors[] = $err; } } else { $userData->removeFile(); $userData->filename = $file["data"]["filename"]; $userData->filepath = $file["data"]["dir"]; $response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('user.edit.photo_resize_150', array('mime_type' => $file["data"]['mime_type'], 'user' => $userData)); if ($response === false) { erLhcoreClassImageConverter::getInstance()->converter->transform('photow_150', $userData->file_path_server, $userData->file_path_server); chmod($userData->file_path_server, 0644); } } } return $Errors; }
public function deletePhoto($attr) { if ($this->{$attr} != '') { if (file_exists($this->{$attr . '_path'} . $this->{$attr})) { unlink($this->{$attr . '_path'} . $this->{$attr}); } erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/storagetheme/', str_replace('var/storagetheme/', '', $this->{$attr . '_path'})); $this->{$attr} = ''; $this->{$attr . '_path'} = ''; } }
unset($data['restore_image_data']); } if (isset($data['minimize_image_data'])) { $imgData['minimize_image'] = $data['minimize_image_data']; unset($data['minimize_image_data']); } try { $widgetTheme->setState($data); $widgetTheme->saveThis(); foreach ($imgData as $attr => $dataImage) { $imgDataItem = base64_decode($dataImage); if ($imgDataItem !== false) { $dir = 'var/tmpfiles/'; $fileName = 'data.' . $data[$attr . '_data_ext']; erLhcoreClassChatEventDispatcher::getInstance()->dispatch('theme.temppath', array('dir' => &$dir)); erLhcoreClassFileUpload::mkdirRecursive($dir); $imgPath = $dir . $fileName; file_put_contents($imgPath, $imgDataItem); if (erLhcoreClassImageConverter::isPhotoLocal($imgPath)) { $widgetTheme->movePhoto($attr, true, $imgPath); } } } $widgetTheme->updateThis(); } catch (Exception $e) { $tpl->set('errors', array(erTranslationClassLhTranslation::getInstance()->getTranslation('theme/import', 'Could not import a new theme!'))); } } $tpl->set('updated', true); } else { $tpl->set('errors', array(erTranslationClassLhTranslation::getInstance()->getTranslation('theme/import', 'Invalid file!')));
public function removeThis() { foreach ($this->content_array as $key => $content) { if ($content['definition']['type'] == 'file') { if ($content['filename'] != '') { erLhcoreClassChatEventDispatcher::getInstance()->dispatch('form.remove_file', array('filepath' => $content['filepath'], 'filename' => $content['filename'])); } if ($content['filepath'] != '' && file_exists($content['filepath'] . $content['filename'])) { unlink($content['filepath'] . $content['filename']); erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/', str_replace('var/', '', $content['filepath'])); } } } erLhcoreClassAbstract::getSession()->delete($this); }
public function removeFile() { if ($this->filename != '' || $this->filename != '') { if (file_exists($this->filepath . $this->filename)) { unlink($this->filepath . $this->filename); } if ($this->filepath != '') { erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/userphoto/', str_replace('var/userphoto/', '', $this->filepath)); } erLhcoreClassChatEventDispatcher::getInstance()->dispatch('user.remove_photo', array('user' => &$this)); $this->filepath = ''; $this->filename = ''; $this->saveThis(); } }
public function removeFile() { if ($this->filepath != '') { if (file_exists($this->filepath . $this->filename)) { unlink($this->filepath . $this->filename); } erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/userphoto/', str_replace('var/userphoto/', '', $this->filepath)); $this->filepath = ''; $this->filename = ''; $this->saveThis(); } }