AnonSec Team
Server IP : 10.2.73.233  /  Your IP : 216.73.216.223
Web Server : Apache/2.4.59 (Debian)
System : Linux polon 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64
User : www-data ( 33)
PHP Version : 5.6.40-64+0~20230107.71+debian10~1.gbp673146
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/ifk/web/assets/54b90d07/../../protected/Common/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/ifk/web/assets/54b90d07/../../protected/Common/KImage.php
<?php

class KImage extends TComponent {

    private $_data = array();
    private static $_last_id = null;

    private $_id;

    public function __construct() {
        $crit = new TActiveRecordCriteria();
        $crit->OrdersBy['image_id'] = 'desc';
        $this->_id = self::getNextID();
    }

    public function getId() {
        return $this->_id;
    }

    public function __get($name) {
        if (KImageType::t($name)->isValidImageType)
            return $this->getImageFile(KImageType::t($name));
        else
            return new KImageFile();
    }

    public function getImageFile($image_type) {
        if (isset($this->_data[(string) $image_type]) && $this->_data[(string) $image_type] instanceof KImageFile)
            return $this->_data[(string) $image_type];
        else
            return new KImageFile();
    }

    public static function getNextID() {
        if (self::$_last_id === null) {
            $db = TActiveRecordManager::getInstance()->getDbConnection();
            $db->Active = true;
            $db_command = $db->createCommand("SELECT GREATEST(max(u.photo_id), max(n.photo_id), max(p.photo_id), max(coalesce(r.image_id,0))) as max_photo_id from ifk_users u, ifk_newsitems n, ifk_papers p, ifk_rightboxes r");
            self::$_last_id = $db_command->queryScalar() + 1;
        }
        return self::$_last_id++;
    }

    public function load($image_id) {
        $crit = new TActiveRecordCriteria();
        $crit->Condition = "image_id = " . TPropertyValue::ensureInteger($image_id);
        $this->_id = $image_id;
        $images = KImageFile::finder()->findAll($crit);
        foreach ($images as $image) {
            $this->_data[$image->type] = $image;
        }
    }

    public function save($source_image, $image_types = array()) {
        foreach ($image_types as $image_type) {
            
            $imagefile = $this->getImageFile(KImageType::t($image_type));
            
            if ($imagefile instanceof KImageFile) {
                if (! is_null($imagefile->filename) && ! is_null($imagefile->image_id) && ! is_null($imagefile->type)) {
                    $imagefile->delete();
                    if (file_exists(Prado::getApplication()->Parameters['IMAGE_PATH'] . '/' . $imagefile->filename))
                        unlink(Prado::getApplication()->Parameters['IMAGE_PATH'] . '/' . $imagefile->filename);
                    $imagefile = new KImageFile();
                }
                
                $imagefile->image_id = $this->_id;
                $imagefile->type = (string) KImageType::t($image_type);
                $imagefile->filename = str_pad(str_replace('.', '', microtime(true)), 14, "0", STR_PAD_RIGHT) . ".jpg";
                
                $image = KImageManager::refineImage($source_image, KImageType::t($image_type));
                KImageManager::saveImage($image, Prado::getApplication()->Parameters['IMAGE_PATH'] . '/' . $imagefile->filename);
                
                $imagefile->save();
            }
        }
    }

    public function delete() {
        foreach ($this->_data as $imagefile) {
            $imagefile->delete();
        }
    }
}

class KImageFile extends TActiveRecord {

    const TABLE = 'ifk_imagefiles';

    private $_id;

    private $_image_id;

    private $_type;

    private $_filename;

    public function getId() {
        return $this->_id;
    }

    public function setId($value) {
        $this->_id = TPropertyValue::ensureInteger($value);
    }

    public function getImage_id() {
        return $this->_image_id;
    }

    public function setImage_id($value) {
        $this->_image_id = TPropertyValue::ensureInteger($value);
    }

    public function getType() {
        return $this->_type;
    }

    public function setType($value) {
        $this->_type = TPropertyValue::ensureInteger($value);
    }

    public function getFilename() {
        return $this->_filename;
    }

    public function setFilename($value) {
        $this->_filename = TPropertyValue::ensureString($value);
    }

    public function getUrl() {
        return Prado::getApplication()->Parameters['IMAGE_URL'] . "/" . $this->getFilename();
    }

    public static function finder($className = __CLASS__) {
        return parent::finder($className);
    }

    public function delete() {
        if (file_exists(Prado::getApplication()->Parameters['IMAGE_PATH'] . "/" . $this->Filename))
            unlink(Prado::getApplication()->Parameters['IMAGE_PATH'] . "/" . $this->Filename);
        parent::delete();
    }
}

class KImageType {

    private static $_sizedata = array(
        'UserUploadStep' => array(
            'id' => '900',
            'x' => 400,
            'y' => 400
        ),
        'UserOriginal' => array(
            'id' => '100',
            'x' => - 1,
            'y' => - 1
        ),
        'UserPhoto' => array(
            'id' => '110',
            'x' => 200,
            'y' => 250
        ),
        'UserIcon' => array(
            'id' => '120',
            'x' => 60,
            'y' => 60
        ),
        
        'CoverUploadStep' => array(
            'id' => '910',
            'x' => 400,
            'y' => 400
        ),
        'CoverOriginal' => array(
            'id' => '200',
            'x' => - 1,
            'y' => - 1
        ),
        'CoverBasic' => array(
            'id' => '210',
            'x' => 200,
            'y' => 300
        ),
        'CoverIcon' => array(
            'id' => '220',
            'x' => 100,
            'y' => 150
        ),
        'CoverAdminIcon' => array(
            'id' => '230',
            'x' => 50,
            'y' => 75
        ),
        
        'NewsUploadStep' => array(
            'id' => '920',
            'x' => 400,
            'y' => 400
        ),
        'NewsOriginal' => array(
            'id' => '300',
            'x' => - 1,
            'y' => - 1
        ),
        'NewsThumb' => array(
            'id' => '310',
            'x' => 150,
            'y' => 300
        ),
        'NewsAdminIcon' => array(
            'id' => '320',
            'x' => 50,
            'y' => 50
        ),

        'RightBoxUploadStep' => array(
            'id' => '930',
            'x' => 400,
            'y' => 400
        ),
        'RightBoxOriginal' => array(
            'id' => '400',
            'x' => - 1,
            'y' => - 1
        ),
        'RightBoxBasic' => array(
            'id' => '410',
            'x' => 100,
            'y' => 100
        )
    );

    public static function t($m) {
        return new KImageTypeHelper(self::$_sizedata[$m]['id'], self::$_sizedata[$m]['x'], self::$_sizedata[$m]['y']);
    }

    public function getImageTypes() {
        return array_keys(self::$_sizedata);
    }
}

class KImageTypeHelper {

    private $_i;

    public $Width;

    public $Height;

    public $isValidImageType;

    function __construct($id, $width, $height) {
        $this->_i = $id;
        $this->Width = $width;
        $this->Height = $height;
        $this->isValidImageType = is_numeric($id);
    }

    function __toString() {
        return $this->_i;
    }
}

AnonSec - 2021