Skip to content

Commit

Permalink
Compatibility with Riak
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Dec 7, 2014
1 parent 44feef3 commit 040ef0d
Show file tree
Hide file tree
Showing 20 changed files with 205 additions and 69 deletions.
11 changes: 10 additions & 1 deletion lhc_web/lib/core/lhchat/lhchateventdispatcher.php
Expand Up @@ -4,6 +4,8 @@ class erLhcoreClassChatEventDispatcher {

private $listeners = array();

const STOP_WORKFLOW = 1;

public function listen($event, $callback)
{
$this->listeners[$event][] = $callback;
Expand All @@ -14,9 +16,16 @@ public function dispatch($event, $param = array())
if (isset($this->listeners[$event])){
foreach ($this->listeners[$event] as $listener)
{
call_user_func_array($listener, array($param));
$responseData = call_user_func_array($listener, array($param));

// We finish executing callback like one of callbacks finished workflow and does not allow more particular callback executions
if (isset($responseData['status']) && $responseData['status'] === self::STOP_WORKFLOW){
return $responseData;
}
}
}

return false;
}

static private $evenDispather = NULL;
Expand Down
6 changes: 5 additions & 1 deletion lhc_web/lib/core/lhcore/lhfileupload.php
@@ -1,7 +1,9 @@
<?php

class erLhcoreClassFileUpload extends UploadHandler {


public $uploadedFile = false;

protected function get_file_name($name, $type = null, $index = null, $content_range = null) {
$name = sha1($name . erLhcoreClassModelForgotPassword::randomPassword(40).time());
return md5($this->get_unique_filename(
Expand Down Expand Up @@ -86,6 +88,8 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro

$chat->has_unread_messages = 1;
$chat->updateThis();

$this->uploadedFile = $fileUpload;
}

return $file;
Expand Down
6 changes: 5 additions & 1 deletion lhc_web/lib/core/lhcore/lhfileuploadadmin.php
@@ -1,7 +1,9 @@
<?php

class erLhcoreClassFileUploadAdmin extends erLhcoreClassFileUpload {


public $uploadedFile = false;

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) {

$matches = array();
Expand Down Expand Up @@ -41,6 +43,8 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
}

$fileUpload->saveThis();

$this->uploadedFile = $fileUpload;
} else {
throw new Exception($file->error);
}
Expand Down
9 changes: 8 additions & 1 deletion lhc_web/lib/core/lhcore/lhsys.php
Expand Up @@ -390,7 +390,7 @@ static function init()
}

$instance->SiteDir = $siteDir;
$instance->WWWDir = $wwwDir;
$instance->WWWDirImages = $instance->WWWDir = $wwwDir;
$instance->IndexFile = erConfigClassLhConfig::getInstance()->getSetting( 'site', 'force_virtual_host', false) === false ? '/index.php' : '';
$instance->RequestURI = str_replace('//','/',$requestUri);
$instance->QueryString = $queryString;
Expand Down Expand Up @@ -442,11 +442,18 @@ function wwwDir()
return $this->WWWDir;
}

function wwwImagesDir()
{
return $this->WWWDirImages;
}

/// The path to where all the code resides
public $SiteDir;
/// The access path of the current site view
/// The relative directory path of the vhless setup
public $WWWDir;

public $WWWDirImages;

// The www dir used in links formating
public $WWWDirLang;
Expand Down
2 changes: 2 additions & 0 deletions lhc_web/lib/core/lhform/lhformrenderer.php
Expand Up @@ -531,6 +531,8 @@ public static function storeCollectedInformation($form, $collectedInformation) {

$params['filename'] = $file;
$params['filepath'] = $dir;

erLhcoreClassChatEventDispatcher::getInstance()->dispatch('form.fill.store_file',array('file_params' => & $params));
}
}

Expand Down
13 changes: 10 additions & 3 deletions lhc_web/lib/models/lhabstract/erlhabstractmodelformcollected.php
Expand Up @@ -114,9 +114,16 @@ public static function fetch($id)
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']));
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']));
}
}
}

Expand Down
58 changes: 41 additions & 17 deletions lhc_web/lib/models/lhabstract/erlhabstractmodelwidgettheme.php
Expand Up @@ -385,6 +385,16 @@ public function moveOperatorIntroPhoto()
{
$this->movePhoto('operator_image');
}

public function getContentAttribute($attr)
{
$response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('theme.download_image.'.$attr, array('theme' => $this, 'attr' => $attr));
if ($response === false) {
return file_get_contents($this->{$attr.'_path'}.'/'.$this->$attr);
} else {
return $response['filedata'];
}
}

public function movePhoto($attr, $isLocal = false, $localFile = false)
{
Expand All @@ -393,17 +403,24 @@ public function movePhoto($attr, $isLocal = false, $localFile = false)
if ($this->id != null){
$dir = 'var/storagetheme/' . date('Y') . 'y/' . date('m') . '/' . date('d') .'/' . $this->id . '/';

erLhcoreClassChatEventDispatcher::getInstance()->dispatch('theme.edit.'.$attr.'_path',array('dir' => & $dir, 'storage_id' => $this->id));
$response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('theme.edit.'.$attr.'_path',array('dir' => & $dir, 'storage_id' => $this->id));

erLhcoreClassFileUpload::mkdirRecursive( $dir );

if ($isLocal == false) {
$this->$attr = erLhcoreClassSearchHandler::moveUploadedFile('AbstractInput_'.$attr, $dir . '/','.' );
} else {
$this->$attr = erLhcoreClassSearchHandler::moveLocalFile($localFile, $dir . '/','.' );
}

$this->{$attr.'_path'} = $dir;

$response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('theme.edit.store_'.$attr,array(
'theme' => & $this,
'path_attr' => $attr.'_path',
'name' => $this->$attr,
'file_path' => $this->{$attr.'_path'} . $this->$attr));

} else {
$this->{$attr.'_pending'} = true;
}
Expand All @@ -416,8 +433,15 @@ public function deletePhoto($attr)
unlink($this->{$attr.'_path'} . $this->$attr);
}

erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/storagetheme/',str_replace('var/storagetheme/','',$this->{$attr.'_path'}));

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'} = '';
}
Expand Down Expand Up @@ -502,7 +526,7 @@ public function __get($var)
$this->logo_image_url = false;

if ($this->logo_image != ''){
$this->logo_image_url = erLhcoreClassSystem::instance()->wwwDir().'/'.$this->logo_image_path . $this->logo_image;
$this->logo_image_url = ($this->logo_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ) .'/'.$this->logo_image_path . $this->logo_image;
}

return $this->logo_image_url;
Expand All @@ -512,7 +536,7 @@ public function __get($var)
$this->operator_image_url = false;

if ($this->operator_image != ''){
$this->operator_image_url = erLhcoreClassSystem::instance()->wwwDir().'/'.$this->operator_image_path . $this->operator_image;
$this->operator_image_url = ($this->operator_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ).'/'.$this->operator_image_path . $this->operator_image;
}

return $this->operator_image_url;
Expand All @@ -521,8 +545,8 @@ public function __get($var)
case 'copyright_image_url':
$this->copyright_image_url = false;

if ($this->copyright_image != ''){
$this->copyright_image_url = erLhcoreClassSystem::instance()->wwwDir().'/'.$this->copyright_image_path . $this->copyright_image;
if ($this->copyright_image != ''){
$this->copyright_image_url = ($this->copyright_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ).'/'.$this->copyright_image_path . $this->copyright_image;
}

return $this->copyright_image_url;
Expand All @@ -533,7 +557,7 @@ public function __get($var)
$this->need_help_image_url = false;

if ($this->need_help_image != ''){
$this->need_help_image_url = erLhcoreClassSystem::instance()->wwwDir().'/'.$this->need_help_image_path . $this->need_help_image;
$this->need_help_image_url = ($this->need_help_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ).'/'.$this->need_help_image_path . $this->need_help_image;
}

return $this->need_help_image_url;
Expand All @@ -543,7 +567,7 @@ public function __get($var)
$this->online_image_url = false;

if ($this->online_image != ''){
$this->online_image_url = erLhcoreClassSystem::instance()->wwwDir().'/'.$this->online_image_path . $this->online_image;
$this->online_image_url = ($this->online_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ).'/'.$this->online_image_path . $this->online_image;
}

return $this->online_image_url;
Expand All @@ -553,7 +577,7 @@ public function __get($var)
$this->offline_image_url = false;

if ($this->offline_image != ''){
$this->offline_image_url = erLhcoreClassSystem::instance()->wwwDir().'/'.$this->offline_image_path . $this->offline_image;
$this->offline_image_url = ($this->offline_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ) .'/'.$this->offline_image_path . $this->offline_image;
}

return $this->offline_image_url;
Expand All @@ -565,7 +589,7 @@ public function __get($var)
$this->url_operator_photo = false;

if($this->need_help_image != ''){
$this->url_operator_photo = '<img src="'.erLhcoreClassSystem::instance()->wwwDir().'/'.$this->need_help_image_path . $this->need_help_image.'"/>';
$this->url_operator_photo = '<img src="'. ($this->need_help_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ) .'/'.$this->need_help_image_path . $this->need_help_image.'"/>';
}
return $this->url_operator_photo;
break;
Expand All @@ -575,7 +599,7 @@ public function __get($var)
$this->online_image_url_img = false;

if($this->online_image != ''){
$this->online_image_url_img = '<img src="'.erLhcoreClassSystem::instance()->wwwDir().'/'.$this->online_image_path . $this->online_image.'"/>';
$this->online_image_url_img = '<img src="'.($this->online_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ) .'/'.$this->online_image_path . $this->online_image.'"/>';
}
return $this->online_image_url_img;
break;
Expand All @@ -585,7 +609,7 @@ public function __get($var)
$this->offline_image_url_img = false;

if($this->offline_image != ''){
$this->offline_image_url_img = '<img src="'.erLhcoreClassSystem::instance()->wwwDir().'/'.$this->offline_image_path . $this->offline_image.'"/>';
$this->offline_image_url_img = '<img src="'.($this->offline_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ) .'/'.$this->offline_image_path . $this->offline_image.'"/>';
}
return $this->offline_image_url_img;
break;
Expand All @@ -595,7 +619,7 @@ public function __get($var)
$this->logo_image_url_img = false;

if ($this->logo_image != '') {
$this->logo_image_url_img = '<img src="'.erLhcoreClassSystem::instance()->wwwDir().'/'.$this->logo_image_path . $this->logo_image.'"/>';
$this->logo_image_url_img = '<img src="'.($this->logo_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ).'/'.$this->logo_image_path . $this->logo_image.'"/>';
}

return $this->logo_image_url_img;
Expand All @@ -606,7 +630,7 @@ public function __get($var)
$this->copyright_image_url_img = false;

if ($this->copyright_image != '') {
$this->copyright_image_url_img = '<img src="'.erLhcoreClassSystem::instance()->wwwDir().'/'.$this->copyright_image_path . $this->copyright_image.'"/>';
$this->copyright_image_url_img = '<img src="'.($this->copyright_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ).'/'.$this->copyright_image_path . $this->copyright_image.'"/>';
}

return $this->copyright_image_url_img;
Expand All @@ -616,7 +640,7 @@ public function __get($var)
$this->operator_image_url_img = false;

if ($this->operator_image != '') {
$this->operator_image_url_img = '<img src="'.erLhcoreClassSystem::instance()->wwwDir().'/'.$this->operator_image_path . $this->operator_image.'"/>';
$this->operator_image_url_img = '<img src="'.($this->operator_image_path != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ).'/'.$this->operator_image_path . $this->operator_image.'"/>';
}

return $this->operator_image_url_img;
Expand Down
8 changes: 6 additions & 2 deletions lhc_web/lib/models/lhchat/erlhcoreclassmodelchatfile.php
Expand Up @@ -43,8 +43,12 @@ public function removeThis()
unlink($this->file_path_server);
}

erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/', str_replace('var/', '', $this->file_path));

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);
}

Expand Down
14 changes: 9 additions & 5 deletions lhc_web/lib/models/lhuser/erlhcoreclassmodeluser.php
Expand Up @@ -127,7 +127,7 @@ public function __get($param)
break;

case 'photo_path':
$this->photo_path = erLhcoreClassSystem::instance()->wwwDir() .'/'. $this->filepath . $this->filename;
$this->photo_path = ($this->filepath != '' ? erLhcoreClassSystem::instance()->wwwDir() : erLhcoreClassSystem::instance()->wwwImagesDir() ) .'/'. $this->filepath . $this->filename;
return $this->photo_path;
break;

Expand Down Expand Up @@ -316,14 +316,18 @@ public function saveThis(){
}

public function removeFile()
{
if ($this->filepath != '') {
{
if ($this->filename != '' || $this->filename != '') {
if ( file_exists($this->filepath . $this->filename) ) {
unlink($this->filepath . $this->filename);
}

erLhcoreClassFileUpload::removeRecursiveIfEmpty('var/userphoto/',str_replace('var/userphoto/','',$this->filepath));

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();
Expand Down
10 changes: 9 additions & 1 deletion lhc_web/modules/lhfile/downloadfile.php
Expand Up @@ -7,7 +7,15 @@
if ( $hash == md5($file->name.'_'.$file->chat_id) ) {
header('Content-type: '.$file->type);
header('Content-Disposition: attachment; filename="'.$file->id.'-'.$file->chat_id.'.'.$file->extension.'"');
echo file_get_contents($file->file_path_server);

$response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.download', array('chat_file' => $file));

// There was no callbacks or file not found etc, we try to download from standard location
if ($response === false) {
echo file_get_contents($file->file_path_server);
} else {
echo $response['filedata'];
}
}

} catch (Exception $e) {
Expand Down
6 changes: 6 additions & 0 deletions lhc_web/modules/lhfile/new.php
Expand Up @@ -14,6 +14,12 @@
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.new.file_path',array('path' => & $path));

$upload_handler = new erLhcoreClassFileUploadAdmin(array('user_id' => $currentUser->getUserID(), 'file_name_manual' => $_POST['Name'], 'upload_dir' => $path, 'download_via_php' => true,'max_file_size' => $data['fs_max']*1024, 'accept_file_types_lhc' => '/\.('.$data['ft_op'].')$/i'));

if ($upload_handler->uploadedFile instanceof erLhcoreClassModelChatFile)
{
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.file_new_admin.file_store', array('chat_file' => $upload_handler->uploadedFile));
}

$tpl->set('file_uploaded',true);
} catch (Exception $e) {
$tpl->set('errors',array($e->getMessage()));
Expand Down

0 comments on commit 040ef0d

Please sign in to comment.