Beispiel #1
0
 public function bindImage($elementName)
 {
     $file = JRequest::getVar($elementName, '', 'FILES');
     if (!isset($file['tmp_name']) || empty($file['tmp_name'])) {
         return false;
     }
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     // @task: Test if the folder containing the badges exists
     if (!JFolder::exists(DISCUSS_BADGES_PATH)) {
         JFolder::create(DISCUSS_BADGES_PATH);
     }
     // @task: Test if the folder containing uploaded badges exists
     if (!JFolder::exists(DISCUSS_BADGES_UPLOADED)) {
         JFolder::create(DISCUSS_BADGES_UPLOADED);
     }
     require_once DISCUSS_CLASSES . '/simpleimage.php';
     $image = new SimpleImage();
     $image->load($file['tmp_name']);
     if ($image->getWidth() > 64 || $image->getHeight() > 64) {
         return false;
     }
     $storage = DISCUSS_BADGES_UPLOADED;
     $name = md5($this->id . DiscussHelper::getDate()->toMySQL()) . $image->getExtension();
     // @task: Create the necessary path
     $path = $storage . '/' . $this->id;
     if (!JFolder::exists($path)) {
         JFolder::create($path);
     }
     // @task: Copy the original image into the storage path
     JFile::copy($file['tmp_name'], $path . '/' . $name);
     // @task: Resize to the 16x16 favicon
     $image->resize(DISCUSS_BADGES_FAVICON_WIDTH, DISCUSS_BADGES_FAVICON_HEIGHT);
     $image->save($path . '/' . 'favicon_' . $name);
     $this->avatar = $this->id . '/' . $name;
     $this->thumbnail = $this->id . '/' . 'favicon_' . $name;
     return $this->store();
 }