? GR0V Shell

GR0V shell

Linux www.koreapackagetour.com 2.6.32-042stab145.3 #1 SMP Thu Jun 11 14:05:04 MSK 2020 x86_64

Path : /home/admin/public_html/old/promice/Admin/src/QuPlupload/Service/
File Upload :
Current File : /home/admin/public_html/old/promice/Admin/src/QuPlupload/Service/PluploadService.php

<?php
/**
 * @Author: Cel Ticó Petit
 * @Contact: cel@cenics.net
 * @Company: Cencis s.c.p.
 */

namespace QuPlupload\Service;

use QuPlupload\Options\PluploadOptions;
use QuPlupload\Entity\PluploadMapperInterface;
use Zend\EventManager\EventManager;
use ZfcBase\EventManager\EventProvider;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceManager;


class PluploadService extends EventProvider implements ServiceManagerAwareInterface
{

    /**
     * @var
     */
    protected $pluploadOptions;

    /**
     * @var
     */
    protected $pluploadModel;

    /**
     * @var
     */
    protected $pluploadEntity;

    /**
     * @var
     */
    protected $pluploadMapper;

    /**
     * @var
     */
    protected $PluploadList;

    /**
     * @var
     */
    protected $ThumbModel;

    /**
     * @var
     */
    protected $RemoveModel;

    /**
     * @var
     */
    protected $serviceManager;



    /**
     * @var string
     */
    protected $DirUploadAbsolute;

    /**
     * @var
     */
    protected $ThumbResize;

    /**
     * @var
     */
    protected $Resize;

    /**
     * @var
     */
    protected $DirUpload;



    /* UPLOAD!!! */


    /**
     * @param $id_parent
     * @param $data
     * @param $model
     * @return bool
     * @throws \Exception
     */
    public function uploadPlupload($id_parent,$data,$model)
    {
       $this->getPluploadOptions();


        $pluploadMapper      = $this->getPluploadMapper();
        $pluploadEntity      = $this->getPluploadEntity();
        $pluploadModel       = $this->getPluploadModel();
        $thumbModel          = $this->getThumbModel();

        $pluploadEntity
        ->setName(      (string) $data['file']['name'])
        ->setType(      (string) $data['file']['type'])
        ->setTmpName(   (string) $data['file']['tmp_name'])
        ->setError(     (int)    $data['file']['error'])
        ->setSize(      (int)    $data['file']['size'])
        ->setIdParent(  (int)    $id_parent)
        ->setModel(     (string) $model)
        ;
        $this->getEventManager()->trigger(__FUNCTION__.'.pre', $this, array('plupload_entity' => $pluploadEntity));

        if(isset($data["chunk"])){

            // UploadModel
            $file = $pluploadModel->PluploadModel($data);
            if($file){



                if(($data["chunk"]+1) == $data["chunks"]){


                    // Get db last id
                    $id = $pluploadMapper->insert($pluploadEntity);


                    // Get size and rename
                    $fileSize = filesize ( $file['filePath'] );
                    $NameRename  =  str_replace('/-','/'.$id.'-',$file['filePath']);
                    rename($file['filePath'],$NameRename);


                    // Thumb
                   $thumbModel->ThumbModel($id.$file['fileName']);


                    // Update Db
                    $pluploadEntity
                        ->setName($id.$file['fileName'])
                        ->setSize($fileSize)
                        ->setIdPlupload($id);
                    $pluploadMapper->update($pluploadEntity);

                }

            }else{

                throw new \Exception('Not writable '.$this->getPluploadOptions()->DirUploadAbsolute);

            }

        }else{

            // Get db last id
            $id = $pluploadMapper->insert($pluploadEntity);

            // Upload and set Name
            $pluploadModel->setId($id);
            $file = $pluploadModel->PluploadModel($data);

            if($file){

                // Thumb
                $thumbModel->ThumbModel($file['fileName']);

                // Update Db
                $pluploadEntity
                    ->setName($file['fileName'])
                    ->setIdPlupload($id);
                $pluploadMapper->update($pluploadEntity);

           }else{

                $pluploadMapper->Remove($id);

                throw new \Exception('Not writable '.$this->getPluploadOptions()->DirUploadAbsolute);

            }

        }

        $this->getEventManager()->trigger(__FUNCTION__.'.post', $this, array('plupload_entity' => $pluploadEntity));


        return true;
    }



    /* REMOVE!! */


    /**
     * @param $id
     * @return bool
     */
    public function PluploadRemove($id)
    {

        $this->getPluploadOptions();

        $pluploadMapper      = $this->getPluploadMapper();
        $RemoveModel         = $this->getRemoveModel();

        $this->getEventManager()->trigger(__FUNCTION__, $this, array('remove_model' => $RemoveModel));


        if($pluploadMapper->find($id)){
            $fileDb = $pluploadMapper->find($id)->getName();
            if($RemoveModel->Remove($fileDb)){
                $pluploadMapper->Remove($id);
            }
        }

        $this->getEventManager()->trigger(__FUNCTION__.'.post', $this, array('remove_model' => $RemoveModel));

        return true;
    }


    /**
     * @param $model
     * @param $id_parent
     * @return bool
     */
    public function pluploadRemoveAll($model,$id_parent)
    {
        $pluploadMapper  = $this->getPluploadMapper();
        $m = $pluploadMapper->findByModel($model,$id_parent);

        if( $m ){
            foreach($m as $r){
                $this->PluploadRemove($r->getIdPlupload());
            }
        }
        return true;
    }


    /**
     * @param $model
     * @param $id_parent
     * @param $id
     * @return bool
     */
    public function pluploadUpdate($model,$id_parent,$id)
    {
        $pluploadMapper      = $this->getPluploadMapper();
        $pluploadEntity      = $this->getPluploadEntity();
        $m = $pluploadMapper->findByModel($model,$id_parent);
        if($m){
            foreach($m as $r){
                $pluploadEntity
                    ->setName($r->getName())
                    ->setType($r->getType())
                    ->setTmpName($r->getTmpName())
                    ->setError($r->getError())
                    ->setSize($r->getSize())
                    ->setIdParent($id)
                    ->setModel($r->getModel())
                    ->setIdPlupload($r->getIdPlupload());
                $pluploadMapper->update($pluploadEntity);
            }
        }
        return true;
    }


    /* GET LIST!! */





    /**
     * @return mixed
     */
    public function getPluploadList()
    {
        if (!$this->PluploadList) {
            $this->setPluploadIdList(0);
        }
        return $this->PluploadList;
    }

    /**
     * @param $id
     * @return $this
     */
    public function setPluploadIdList($id)
    {
        $this->PluploadList = $this->getPluploadMapper()->findByParent($id);
        return $this;
    }


    /**
     * @return mixed
     */
    public function getPluploadIdAndModelList()
    {
        if (!$this->PluploadList) {
            $this->setPluploadIdList(0);
        }
        return $this->PluploadList;
    }

    /**
     * @param $id
     * @param $model
     * @return $this
     */
    public function setPluploadIdAndModelList($id,$model)
    {
        $this->PluploadList = $this->getPluploadMapper()->findByParentByModel($id,$model);
        return $this;
    }





    /* GET SERVICES */
    /* OPTIONS */





    /**
     * GET OPTIONS
     * @return mixed
     */
    public function getPluploadOptions(){

        if (!$this->pluploadOptions) {
            $this->setPluploadOptions(
                $this->getServiceManager()->get('plupload_options')
            );
        }


        return $this->pluploadOptions;
    }

    /**
     * SET OPTIONS
     * @param PluploadOptions $PluploadOptions
     * @return $this
     */
    public function setPluploadOptions(PluploadOptions $PluploadOptions){

        $this->pluploadOptions = $PluploadOptions;

        return $this;
    }








    /* MAPPER */




    /**
     * GET MAPPER
     * @return mixed
     */
    public function getPluploadMapper()
    {
        if (!$this->pluploadMapper) {
            $this->setPluploadMapper(
                $this->getServiceManager()->get('plupload_mapper')
            );
        }
        return $this->pluploadMapper;
    }

    /**
     * SET MAPPER
     * @param PluploadMapperInterface $pluploadMapper
     * @return $this
     */
    public function setPluploadMapper(PluploadMapperInterface $pluploadMapper)
    {
        $this->pluploadMapper = $pluploadMapper;
        return $this;
    }




    /* MODEL PLUPLOAD */




    /**
     * @return mixed
     */
    public function getPluploadModel(){

        if (!$this->pluploadModel) {
            $this->setPluploadModel(
                $this->getServiceManager()->get('plupload_model')
            );
        }

        if(!$this->DirUpload){
            $this->pluploadModel->setUploadDir($this->getPluploadOptions()->DirUploadAbsolute);
        }


        return $this->pluploadModel;
    }
    /**
     * @param $pluploadModel
     * @return $this
     */
    public function setPluploadModel($pluploadModel){

        $this->pluploadModel = $pluploadModel;
        return $this;
    }



    /* MODEL REMOVE */



    /**
     * @return mixed
     */
    public function getRemoveModel(){

        if (!$this->RemoveModel) {
            $this->setRemoveModel(
                $this->getServiceManager()->get('remove_model')
            );
        }

        if(!$this->DirUpload){
            $this->RemoveModel->setUploadDir($this->getPluploadOptions()->DirUploadAbsolute);
        }
        if(!$this->ThumbResize){
            $this->RemoveModel->setThumbResize($this->getPluploadOptions()->ThumbResize);
        }


        return $this->RemoveModel;
    }

    /**
     * @param $RemoveModel
     * @return $this
     */
    public function setRemoveModel($RemoveModel){
        $this->RemoveModel = $RemoveModel;
        return $this;
    }





    /* MODEL THUMB */



    /**
     * @return mixed
     */
    public function getThumbModel(){

        if (!$this->ThumbModel) {
            $this->setThumbModel(
                $this->getServiceManager()->get('thumb_model')
            );
        }

        if(!$this->DirUpload){
            $this->ThumbModel->setUploadDir($this->getPluploadOptions()->DirUploadAbsolute);
        }
        if(!$this->ThumbResize){
            $this->ThumbModel->setThumbResize($this->getPluploadOptions()->ThumbResize);
        }

        return $this->ThumbModel;
    }

    /**
     * @param $ThumbModel
     * @return $this
     */
    public function setThumbModel($ThumbModel){
        $this->ThumbModel = $ThumbModel;
        return $this;
    }


    /* ENTITY */




    /**
     * @return mixed
     */
    public function getPluploadEntity(){

        if (!$this->pluploadEntity) {
            $this->setPluploadEntity(
                $this->getServiceManager()->get('plupload_entity')
            );
        }
        return $this->pluploadEntity;
    }

    /**
     * @param $pluploadEntity
     * @return $this
     */
    public function setPluploadEntity($pluploadEntity){
        $this->pluploadEntity = $pluploadEntity;
        return $this;
    }




    /* SERVICE MANAGER */




    /**
     * @param ServiceManager $serviceManager
     * @return $this
     */
    public function setServiceManager(ServiceManager $serviceManager)
    {
        $this->serviceManager = $serviceManager;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getServiceManager()
    {
        return $this->serviceManager;
    }
}

T1KUS90T
  root-grov@210.1.60.28:~$