Exemplo n.º 1
0
 protected function _rebuildAttachmentThumbs()
 {
     $img = '<img src="' . $this->settings['skin_acp_url'] . '/images/loading_anim.gif" alt="-" /> ';
     require_once IPS_KERNEL_PATH . 'classImage.php';
     /*noLibHook*/
     require_once IPS_KERNEL_PATH . 'classImageGd.php';
     /*noLibHook*/
     //-----------------------------------------
     // Set up
     //-----------------------------------------
     $done = 0;
     $start = intval($this->request['st']) >= 0 ? intval($this->request['st']) : 0;
     $end = intval($this->request['pergo']) ? intval($this->request['pergo']) : 100;
     $dis = $end + $start;
     $output = array();
     //-----------------------------------------
     // Got any more?
     //-----------------------------------------
     $tmp = $this->DB->buildAndFetch(array('select' => 'attach_id', 'from' => 'attachments', 'where' => "attach_rel_module IN('post','msg')", 'limit' => array($dis, 1)));
     $max = intval($tmp['attach_id']);
     //-----------------------------------------
     // Avoid limit...
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'attachments', 'where' => "attach_rel_module IN('post','msg')", 'order' => 'attach_id ASC', 'limit' => array($start, $end)));
     $outer = $this->DB->execute();
     //-----------------------------------------
     // Process...
     //-----------------------------------------
     while ($r = $this->DB->fetch($outer)) {
         if ($r['attach_is_image']) {
             if ($r['attach_thumb_location'] and $r['attach_thumb_location'] != $r['attach_location']) {
                 if (is_file($this->settings['upload_dir'] . '/' . $r['attach_thumb_location'])) {
                     if (!@unlink($this->settings['upload_dir'] . '/' . $r['attach_thumb_location'])) {
                         continue;
                     }
                 }
             }
             $attach_data = array();
             $thumbnail = preg_replace("/^(.*)\\.(.+?)\$/", "\\1_thumb.\\2", $r['attach_location']);
             $image = new classImageGd();
             $image->init(array('image_path' => $this->settings['upload_dir'], 'image_file' => $r['attach_location']));
             $image->force_resize = false;
             $return = $image->resizeImage($this->settings['siu_width'], $this->settings['siu_height']);
             if (!$return['noResize']) {
                 $image->writeImage($this->settings['upload_dir'] . '/' . $thumbnail);
                 $attach_data['attach_thumb_location'] = $thumbnail;
             } else {
                 $attach_data['attach_thumb_location'] = $r['attach_location'];
             }
             $attach_data['attach_thumb_width'] = intval($return['newWidth'] ? $return['newWidth'] : $image->cur_dimensions['width']);
             $attach_data['attach_thumb_height'] = intval($return['newHeight'] ? $return['newHeight'] : $image->cur_dimensions['height']);
             if (count($attach_data)) {
                 $this->DB->update('attachments', $attach_data, 'attach_id=' . $r['attach_id']);
             }
             unset($image);
         }
         $done++;
     }
     //-----------------------------------------
     // Finish - or more?...
     //-----------------------------------------
     if (!$done and !$max) {
         //-----------------------------------------
         // Done..
         //-----------------------------------------
         $this->registry->output->multipleRedirectHit($this->settings['base_url'] . '&module=setup&section=finalize&do=rebuildStatusUpdates', $img . ' Rebuilt Attachment Thumbnails');
     } else {
         //-----------------------------------------
         // More..
         //-----------------------------------------
         $thisgoeshere = sprintf("Rebuilding Attachments - Up to %s processed so far, continuing...", $dis);
         $text = $thisgoeshere . '<br />' . implode("<br />", $output);
         $this->registry->output->multipleRedirectHit($this->settings['base_url'] . "&module=setup&section=finalize&do=rebuildAttachThumbs&pergo={$this->request['pergo']}&st={$dis}", $img . $text);
     }
 }
 /**
  * Uploads and saves file
  *
  * @return	mixed	void, or an array of new insert ids
  */
 public function processMultipleUploads()
 {
     /* INIT */
     $this->error = '';
     $this->getUploadFormSettings();
     /* Check the upload directory */
     if (!$this->checkUploadDirectory()) {
         if ($this->error) {
             return;
         }
     }
     /* Can Upload */
     if (!$this->attach_stats['allow_uploads']) {
         $this->error = 'upload_failed';
         return;
     }
     /* Setup Attachment Types */
     if (!$this->registry->cache()->getCache('attachtypes') or !is_array($this->registry->cache()->getCache('attachtypes'))) {
         $attachtypes = array();
         $this->DB->build(array('select' => 'atype_extension,atype_mimetype,atype_post,atype_img', 'from' => 'attachments_type', 'where' => "atype_post=1"));
         $this->DB->execute();
         while ($r = $this->DB->fetch()) {
             $attachtypes[$r['atype_extension']] = $r;
         }
         $this->registry->cache()->updateCacheWithoutSaving('attachtypes', $attachtypes);
     }
     /* Attachment Library */
     $classToLoad = IPSLib::loadLibrary(IPS_KERNEL_PATH . 'classUpload.php', 'classUpload');
     $upload = new $classToLoad();
     /* Set up the library */
     $upload->out_file_dir = $this->upload_path;
     $upload->max_file_size = $this->attach_stats['max_single_upload'] ? $this->attach_stats['max_single_upload'] : 1000000000;
     $upload->make_script_safe = 1;
     $upload->force_data_ext = 'ipb';
     /* Populate allowed extensions */
     if (is_array($this->registry->cache()->getCache('attachtypes')) and count($this->registry->cache()->getCache('attachtypes'))) {
         /* SKINNOTE: I had to add [attachtypes] to this cache to make it work, may need fixing? */
         //$tmp = $this->registry->cache()->getCache('attachtypes');
         foreach ($this->registry->cache()->getCache('attachtypes') as $idx => $data) {
             if ($data['atype_post']) {
                 $upload->allowed_file_ext[] = $data['atype_extension'];
             }
         }
     }
     /* Attempt to upload everything int he $_FILES array */
     $upload_results = array();
     if (isset($_FILES) && is_array($_FILES) && count($_FILES)) {
         foreach ($_FILES as $_field_name => $data) {
             if (!$_FILES[$_field_name]['size']) {
                 continue;
             }
             /* Set File Name */
             $upload->out_file_name = $this->type . '-' . $this->memberData['member_id'] . '-' . time() % $_FILES[$_field_name]['size'];
             /* Set File Name */
             $upload->upload_form_field = $_field_name;
             /* Attachment Data Array */
             $attach_data = array('attach_ext' => "", 'attach_file' => "", 'attach_location' => "", 'attach_thumb_location' => "", 'attach_hits' => 0, 'attach_date' => time(), 'attach_post_key' => $this->attach_post_key, 'attach_member_id' => $this->memberData['member_id'], 'attach_rel_id' => $this->attach_rel_id, 'attach_rel_module' => $this->type, 'attach_filesize' => 0);
             /* Upload... */
             $upload->process();
             /* Error Check */
             if ($upload->error_no) {
                 switch ($upload->error_no) {
                     case 1:
                         // No upload
                         $upload_results[$_field_name] = 'upload_no_file';
                         break;
                     case 2:
                         // Invalid file ext
                         $upload_results[$_field_name] = 'invalid_mime_type';
                         break;
                     case 3:
                         // Too big...
                         $upload_results[$_field_name] = 'upload_too_big';
                         break;
                     case 4:
                         // Cannot move uploaded file
                         $upload_results[$_field_name] = 'upload_failed';
                         break;
                     case 5:
                         // Possible XSS attack (image isn't an image)
                         $upload_results[$_field_name] = 'upload_failed';
                         break;
                 }
             }
             /* Still Here */
             if ($upload->saved_upload_name and @is_file($upload->saved_upload_name)) {
                 /* Strip off { } and [ ] */
                 $upload->original_file_name = str_replace(array('[', ']', '{', '}'), "", $upload->original_file_name);
                 $attach_data['attach_filesize'] = @filesize($upload->saved_upload_name);
                 $attach_data['attach_location'] = $this->upload_dir . $upload->parsed_file_name;
                 $attach_data['attach_file'] = $upload->original_file_name;
                 $attach_data['attach_is_image'] = $upload->is_image;
                 $attach_data['attach_ext'] = $upload->real_file_extension;
                 if ($attach_data['attach_is_image'] == 1) {
                     require_once IPS_KERNEL_PATH . 'classImage.php';
                     /*noLibHook*/
                     require_once IPS_KERNEL_PATH . 'classImageGd.php';
                     /*noLibHook*/
                     /* Main attachment */
                     if (!empty($this->settings['attach_img_max_w']) and !empty($this->settings['attach_img_max_h'])) {
                         $image = new classImageGd();
                         $image->init(array('image_path' => $this->upload_path, 'image_file' => $upload->parsed_file_name));
                         if ($imgData = $image->resizeImage($this->settings['attach_img_max_w'], $this->settings['attach_img_max_h'])) {
                             $image->writeImage($this->upload_path . '/' . $upload->parsed_file_name);
                             if (is_array($imgData)) {
                                 $attach_data['attach_img_width'] = $imgData['newWidth'];
                                 $attach_data['attach_img_height'] = $imgData['newHeight'];
                             }
                         }
                     }
                     /* Thumb nail */
                     $image = new classImageGd();
                     $image->force_resize = true;
                     $image->init(array('image_path' => $this->upload_path, 'image_file' => $upload->parsed_file_name));
                     if ($this->attach_settings['siu_thumb']) {
                         $_thumbName = preg_replace('#^(.*)\\.(\\w+?)$#', "\\1_thumb.\\2", $upload->parsed_file_name);
                         if ($thumb_data = $image->resizeImage($this->attach_settings['siu_width'], $this->attach_settings['siu_height'])) {
                             $image->writeImage($this->upload_path . '/' . $_thumbName);
                             if (is_array($thumb_data)) {
                                 $thumb_data['thumb_location'] = $_thumbName;
                             }
                         }
                     }
                     if ($thumb_data['thumb_location']) {
                         $attach_data['attach_img_width'] = $thumb_data['originalWidth'];
                         $attach_data['attach_img_height'] = $thumb_data['originalHeight'];
                         $attach_data['attach_thumb_width'] = $thumb_data['newWidth'];
                         $attach_data['attach_thumb_height'] = $thumb_data['newHeight'];
                         $attach_data['attach_thumb_location'] = $this->upload_dir . $thumb_data['thumb_location'];
                     }
                 }
                 /* Add into Database */
                 $this->DB->insert('attachments', $attach_data);
                 $upload_results[$_field_name] = $this->DB->getInsertId();
             }
         }
     }
     return $upload_results;
 }
Exemplo n.º 3
0
 /**
  * Convert an attachment
  *
  * @access	public
  * @param 	integer		Foreign ID number
  * @param 	array 		Data to insert to table
  * @param 	string 		Path to avatars folder
  * @param	boolean		If true, loads file data from database, rather than move file
  * @param	boolean		If true, loads member data from parent application
  * @return 	boolean		Success or fail
  **/
 public function convertAttachment($id, $info, $path, $db = false, $useparent = false)
 {
     //-----------------------------------------
     // Make sure we have everything we need
     //-----------------------------------------
     // Check GD
     if (!function_exists(gd_info)) {
         $this->error('GD is not installed. Please install GD before converting attachments');
     }
     if (!$id) {
         $this->logError($id, 'No ID number provided');
         return false;
     }
     if (!$info['attach_rel_id']) {
         $this->logError($id, 'No relative ID provided');
         return false;
     }
     if (!$db and !$path) {
         $this->logError($id, 'No path provided');
         return false;
     }
     if (!$info['attach_file']) {
         $this->logError($id, 'No filename provided');
         return false;
     }
     if (!$db and !$info['attach_location']) {
         $this->logError($id, 'No location provided');
         return false;
     }
     if ($db and !$info['data']) {
         $this->logError($id, 'No file data provided');
         return false;
     }
     //-----------------------------------------
     // Check upload dir
     //-----------------------------------------
     $pathCheck = $this->_checkUploadDirectory($info['attach_date'] ? $info['attach_date'] : 0);
     $upload_dir = $upload_path = NULL;
     if ($pathCheck['upload_path'] == NULL) {
         $this->logError($id, 'Your IP.Board uploads path has not been configured. Message: ' . $pathCheck['error']);
         return false;
     } else {
         $upload_dir = $pathCheck['upload_dir'];
         $upload_path = $pathCheck['upload_path'];
     }
     //-----------------------------------------
     // Got attachment types?
     //-----------------------------------------
     if (!$this->registry->cache()->getCache('attachtypes') or !is_array($this->registry->cache()->getCache('attachtypes'))) {
         $attachtypes = array();
         $this->DB->build(array('select' => '*', 'from' => 'attachments_type', 'where' => "atype_post=1"));
         $this->DB->execute();
         while ($r = $this->DB->fetch()) {
             $attachtypes[$r['atype_extension']] = $r;
         }
         $this->registry->cache()->updateCacheWithoutSaving('attachtypes', $attachtypes);
     }
     //-----------------------------------------
     // Set up array
     //-----------------------------------------
     $attach_data = array('attach_ext' => "", 'attach_file' => $info['attach_file'], 'attach_location' => "", 'attach_thumb_location' => "", 'attach_hits' => $info['attach_hits'], 'attach_date' => $info['attach_date'], 'attach_temp' => 0, 'attach_member_id' => $this->memberData['member_id'], 'attach_rel_id' => 0, 'attach_rel_module' => $info['attach_rel_module'], 'attach_filesize' => 0, 'attach_parent_id' => $info['attach_parent_id'], 'attach_img_width' => 0, 'attach_img_height' => 0, 'attach_thumb_width' => 0, 'attach_thumb_height' => 0, 'attach_post_key' => !$info['attach_post_key'] ? md5($info['attach_rel_id'] . $info['attach_rel_module']) : $info['attach_post_key']);
     //-----------------------------------------
     // Populate allowed extensions
     //-----------------------------------------
     $allowed_file_ext = array();
     if (is_array($this->registry->cache()->getCache('attachtypes')) and count($this->registry->cache()->getCache('attachtypes'))) {
         /* SKINNOTE: I had to add [attachtypes] to this cache to make it work, may need fixing? */
         //$tmp = $this->registry->cache()->getCache('attachtypes');
         foreach ($this->registry->cache()->getCache('attachtypes') as $idx => $data) {
             if ($data['atype_post']) {
                 $allowed_file_ext[] = $data['atype_extension'];
             }
         }
     }
     //-------------------------------------------------
     // Do we have allowed file_extensions?
     //-------------------------------------------------
     $attach_data['attach_ext'] = $this->_getFileExtension($info['attach_file']);
     if (!in_array($attach_data['attach_ext'], $allowed_file_ext)) {
         $this->logError($id, "invalid_mime_type for file name: {$info['attach_file']}");
         return false;
     }
     $attach_file = str_replace('.' . $attach_data['attach_ext'], "", $info['attach_file']);
     $isImage = in_array($attach_data['attach_ext'], array('gif', 'jpeg', 'jpg', 'jpe', 'png'));
     $attach_data['attach_member_id'] = $info['attach_member_id'] ? $this->getLink($info['attach_member_id'], 'members', true, $useparent) : 0;
     $attach_location = $info['attach_rel_module'] . '-' . $info['attach_member_id'] . '-' . str_replace('.', '', microtime(TRUE)) . '.' . ($isImage ? $attach_data['attach_ext'] : 'ipb');
     // Create the file from the db if that's the case
     if ($db) {
         $this->createFile($attach_location, $info['data'], $info['attach_filesize'], $pathCheck['upload_path']);
     } else {
         // Check the file actually exists
         if (!file_exists($path . '/' . $info['attach_location'])) {
             $this->logError($id, 'Could not locate file ' . $path . '/' . $info['attach_location']);
             return false;
         }
         // Now move it!
         if (!@copy($path . '/' . $info['attach_location'], $pathCheck['upload_path'] . '/' . $attach_location)) {
             $e = error_get_last();
             $this->logError($id, 'Could not move file - attempted to move ' . $path . '/' . $info['attach_location'] . ' to ' . $pathCheck['upload_path'] . '/' . $attach_location . '<br />' . $e['message'] . '<br /><br />');
             return false;
         }
         @chmod($pathCheck['upload_path'] . '/' . $attach_location, 0777);
     }
     $attach_data['attach_filesize'] = @filesize($pathCheck['upload_path'] . '/' . $attach_location);
     if ($isImage) {
         require_once IPS_KERNEL_PATH . "classImage.php";
         require_once IPS_KERNEL_PATH . "classImageGd.php";
         $image = new classImageGd();
         $image->force_resize = true;
         $image->init(array('image_path' => $pathCheck['upload_path'], 'image_file' => $attach_location));
         if ($this->settings['siu_thumb'] && $this->settings['siu_width'] && $this->settings['siu_height']) {
             $_thumbName = preg_replace("#^(.*)\\.(\\w+?)\$#", "\\1_thumb.\\2", $attach_location);
             if ($thumb_data = $image->resizeImage($this->settings['siu_width'], $this->settings['siu_height'])) {
                 $image->writeImage($pathCheck['upload_path'] . '/' . $_thumbName);
                 if (is_array($thumb_data)) {
                     $thumb_data['thumb_location'] = $pathCheck['upload_dir'] . $_thumbName;
                 }
             }
         }
         if ($thumb_data['thumb_location']) {
             $attach_data['attach_thumb_width'] = $thumb_data['newWidth'];
             $attach_data['attach_thumb_height'] = $thumb_data['newHeight'];
             $attach_data['attach_thumb_location'] = $thumb_data['thumb_location'];
         }
         $dimensions = getimagesize($pathCheck['upload_path'] . '/' . $attach_location);
         $attach_data['attach_img_width'] = $dimensions[0];
         $attach_data['attach_img_height'] = $dimensions[1];
     }
     //-----------------------------------------
     // Insert
     //-----------------------------------------
     // Handle links
     switch ($info['attach_rel_module']) {
         case 'post':
             $attach_data['attach_rel_id'] = $this->getLink($info['attach_rel_id'], 'posts', true);
             $attach_data['attach_parent_id'] = $this->getLink($info['attach_parent_id'], 'topics', true);
             $post = $this->DB->buildAndFetch(array('select' => 'post_key', 'from' => 'posts', 'where' => "pid='{$attach_data['attach_rel_id']}'"));
             $attach_data['attach_post_key'] = $post['post_key'];
             break;
         case 'msg':
             $attach_data['attach_rel_id'] = $this->getLink($info['attach_rel_id'], 'pm_posts', true);
             $attach_data['attach_parent_id'] = $this->getLink($info['attach_parent_id'], 'pms', true);
             break;
         case 'blogentry':
             $attach_data['attach_rel_id'] = $this->getLink($info['attach_rel_id'], 'blog_entries', true);
             break;
         case 'tracker':
             $attach_data['attach_rel_id'] = $this->getLink($info['attach_rel_id'], 'tracker_posts', true);
             break;
         case 'ccs':
             $attach_data['attach_rel_id'] = $this->getLink($info['attach_rel_id'], 'ccs_articles', true);
             break;
         default:
             $this->logError($id, 'Invalid Module');
             return false;
             break;
     }
     if ($attach_data['attach_rel_id'] == 0) {
         $this->logError($id, $info['attach_rel_module'] . ' resource not found.');
         return false;
     }
     // STRICT likes to complain about everything...
     $attach_data['attach_is_image'] = intval($isImage);
     $attach_data['attach_location'] = $pathCheck['upload_dir'] . $attach_location;
     // Dropped fields
     unset($attach_data['attach_temp']);
     unset($attach_data['attach_approved']);
     if ($this->usingExtendedInserts) {
         $attach_data['attach_id'] = $id;
         $this->extendedInserts['attachments'][] = $this->DB->compileInsertString($attach_data);
         $inserted_id = $id;
     } else {
         $this->DB->insert('attachments', $attach_data);
         $inserted_id = $this->DB->getInsertId();
     }
     // Update module attachment count cache
     switch ($info['attach_rel_module']) {
         case 'post':
             $this->DB->update('topics', array('topic_hasattach' => 1), "tid='{$attach_data['attach_parent_id']}'");
             break;
         case 'msg':
             $this->DB->update('message_topics', array('mt_hasattach' => 1), "mt_id='{$attach_data['attach_parent_id']}'");
             break;
     }
     $this->addLink($inserted_id, $id, 'attachments');
     return true;
 }
 /**
  * Saves the member's avatar
  *
  * @param		INT			Member's ID to save
  * @param		string		Upload field name [Default is "upload_avatar"]
  * @param		string		Avatar URL Field [Default is "avatar_url"]
  * @param		string		Gallery Avatar Directory Field [Default is "avatar_gallery"]
  * @param		string		Gallery Avatar Image Field [Default is "avatar_image"]
  * @author		Brandon Farber, Stolen By Matt 'Haxor' Mecham
  * <code>
  * Excepton Codes:
  * NO_MEMBER_ID:				A valid member ID was not passed.
  * NO_PERMISSION:				You do not have permission to change the avatar
  * UPLOAD_NO_IMAGE:				Nothing to upload
  * UPLOAD_INVALID_FILE_EXT:		Incorrect file extension (not an image)
  * UPLOAD_TOO_LARGE:			Upload is larger than allowed
  * UPLOAD_CANT_BE_MOVED:		Upload cannot be moved into the uploads directory
  * UPLOAD_NOT_IMAGE:			Upload is not an image, despite what the file extension says!
  * NO_AVATAR_TO_SAVE:			Nothing to save!
  * </code>
  */
 public function saveNewAvatar($member_id, $uploadFieldName = 'upload_avatar', $urlFieldName = 'avatar_url', $galleryFieldName = 'avatar_gallery', $avatarGalleryImage = 'avatar_image', $gravatarFieldName = 'gravatar_email')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $avatar = array();
     list($p_width, $p_height) = explode("x", strtolower($this->settings['avatar_dims']));
     if (!$member_id) {
         throw new Exception("NO_MEMBER_ID");
     }
     $member = IPSMember::load($member_id, 'extendedProfile,groups');
     if (!$member['member_id']) {
         throw new Exception("NO_MEMBER_ID");
     }
     //-----------------------------------------
     // Allowed to upload pics for administrators?
     //-----------------------------------------
     if (IPS_AREA != 'public') {
         if ($member['g_access_cp'] and !$this->registry->getClass('class_permissions')->checkPermission('member_photo_admin', 'members', 'members')) {
             throw new Exception("NO_PERMISSION");
         }
     }
     //-----------------------------------------
     // Upload?
     //-----------------------------------------
     if ($_FILES[$uploadFieldName]['name'] != "" and $_FILES[$uploadFieldName]['name'] != "none") {
         $this->settings['upload_dir'] = str_replace('&#46;', '.', $this->settings['upload_dir']);
         $real_name = 'av-' . $member_id;
         require_once IPS_KERNEL_PATH . 'classUpload.php';
         $upload = new classUpload();
         $upload->out_file_name = $real_name;
         $upload->out_file_dir = $this->settings['upload_dir'];
         $upload->max_file_size = $this->settings['avup_size_max'] * 1024 * 8;
         // Allow xtra for compression
         $upload->upload_form_field = $uploadFieldName;
         //-----------------------------------------
         // Populate allowed extensions
         //-----------------------------------------
         if (is_array($this->cache->getCache('attachtypes')) and count($this->cache->getCache('attachtypes'))) {
             foreach ($this->cache->getCache('attachtypes') as $data) {
                 if ($data['atype_photo']) {
                     if ($data['atype_extension'] == 'swf' and $this->settings['disable_flash']) {
                         continue;
                     }
                     $upload->allowed_file_ext[] = $data['atype_extension'];
                 }
             }
         }
         //-----------------------------------------
         // Upload...
         //-----------------------------------------
         $upload->process();
         //-----------------------------------------
         // Error?
         //-----------------------------------------
         if ($upload->error_no) {
             switch ($upload->error_no) {
                 case 1:
                     // No upload
                     throw new Exception("UPLOAD_NO_IMAGE");
                     break;
                 case 2:
                     // Invalid file ext
                     throw new Exception("UPLOAD_INVALID_FILE_EXT");
                     break;
                 case 3:
                     // Too big...
                     throw new Exception("UPLOAD_TOO_LARGE");
                     break;
                 case 4:
                     // Cannot move uploaded file
                     throw new Exception("UPLOAD_CANT_BE_MOVED");
                     break;
                 case 5:
                     // Possible XSS attack (image isn't an image)
                     throw new Exception("UPLOAD_NOT_IMAGE");
                     break;
             }
         }
         $real_name = $upload->parsed_file_name;
         $im = array();
         if (!$this->settings['disable_ipbsize'] and $upload->file_extension != '.swf') {
             $imageDimensions = getimagesize($this->settings['upload_dir'] . '/' . $real_name);
             if ($imageDimensions[0] > $p_width or $imageDimensions[1] > $p_height) {
                 require_once IPS_KERNEL_PATH . "classImage.php";
                 require_once IPS_KERNEL_PATH . "classImageGd.php";
                 $image = new classImageGd();
                 $image->init(array('image_path' => $this->settings['upload_dir'], 'image_file' => $real_name));
                 $return = $image->resizeImage($p_width, $p_height);
                 $image->writeImage($this->settings['upload_dir'] . '/' . $real_name);
                 $im['img_width'] = $return['newWidth'] ? $return['newWidth'] : $image->cur_dimensions['width'];
                 $im['img_height'] = $return['newHeight'] ? $return['newHeight'] : $image->cur_dimensions['height'];
             } else {
                 $im['img_width'] = $imageDimensions[0];
                 $im['img_height'] = $imageDimensions[1];
             }
         } else {
             $w = intval($this->request['man_width']) ? intval($this->request['man_width']) : $p_width;
             $h = intval($this->request['man_height']) ? intval($this->request['man_height']) : $p_height;
             $im['img_width'] = $w > $p_width ? $p_width : $w;
             $im['img_height'] = $h > $p_height ? $p_height : $h;
         }
         //-----------------------------------------
         // Set the "real" avatar..
         //-----------------------------------------
         $avatar['avatar_location'] = $real_name;
         $avatar['avatar_size'] = $im['img_width'] . 'x' . $im['img_height'];
         $avatar['avatar_type'] = 'upload';
     } else {
         if ($this->request[$urlFieldName] and IPSText::xssCheckUrl($this->request[$urlFieldName]) === true) {
             $ext = explode(",", $this->settings['avatar_ext']);
             $checked = 0;
             $av_ext = preg_replace("/^.*\\.(\\S+)\$/", "\\1", $this->request[$urlFieldName]);
             foreach ($ext as $v) {
                 if (strtolower($v) == strtolower($av_ext)) {
                     if ($v == 'swf' and $this->settings['disable_flash']) {
                         throw new Exception("INVALID_FILE_EXT");
                     }
                     $checked = 1;
                     break;
                 }
             }
             if ($checked != 1) {
                 throw new Exception("INVALID_FILE_EXT");
             }
             if (!$this->settings['disable_ipbsize']) {
                 if (!($img_size = @getimagesize($this->request[$urlFieldName]))) {
                     $img_size[0] = $p_width;
                     $img_size[1] = $p_height;
                 }
                 $im = IPSLib::scaleImage(array('max_width' => $p_width, 'max_height' => $p_height, 'cur_width' => $img_size[0], 'cur_height' => $img_size[1]));
             } else {
                 $w = intval($this->request['man_width']) ? intval($this->request['man_width']) : $p_width;
                 $h = intval($this->request['man_height']) ? intval($this->request['man_height']) : $p_height;
                 $im['img_width'] = $w > $p_width ? $p_width : $w;
                 $im['img_height'] = $h > $p_height ? $p_height : $h;
             }
             $avatar['avatar_location'] = trim($this->request[$urlFieldName]);
             $avatar['avatar_size'] = $im['img_width'] . 'x' . $im['img_height'];
             $avatar['avatar_type'] = 'url';
         } else {
             if (isset($this->request[$galleryFieldName]) and $this->request[$avatarGalleryImage]) {
                 $directory = '';
                 if ($this->request[$galleryFieldName]) {
                     $directory = preg_replace("/[^\\s\\w_-]/", "", urldecode($this->request[$galleryFieldName]));
                     if ($directory) {
                         $directory .= '/';
                     }
                 }
                 $filename = preg_replace("/[^\\s\\w\\._\\-\\[\\]\\(\\)]/", "", urldecode($this->request[$avatarGalleryImage]));
                 if (file_exists(DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_avatars/' . $directory . $filename)) {
                     $avatar['avatar_location'] = $directory . $filename;
                     $avatar['avatar_size'] = '';
                     $avatar['avatar_type'] = 'local';
                 }
             } else {
                 if ($this->request[$gravatarFieldName] && $this->request[$gravatarFieldName] && $this->settings['allow_gravatars']) {
                     $avatar['avatar_location'] = strtolower($this->request[$gravatarFieldName]);
                     $avatar['avatar_type'] = 'gravatar';
                 }
             }
         }
     }
     //-----------------------------------------
     // No avatar image?
     //-----------------------------------------
     if (!count($avatar)) {
         throw new Exception("NO_AVATAR_TO_SAVE");
     } else {
         if ($avatar['avatar_type'] != 'upload') {
             foreach (array('swf', 'jpg', 'jpeg', 'gif', 'png') as $ext) {
                 if (@file_exists($this->settings['upload_dir'] . "/av-" . $member_id . "." . $ext)) {
                     @unlink($this->settings['upload_dir'] . "/av-" . $member_id . "." . $ext);
                 }
             }
         }
     }
     //-----------------------------------------
     // Store and redirect
     //-----------------------------------------
     IPSMember::save($member_id, array('extendedProfile' => $avatar));
     return TRUE;
 }
Exemplo n.º 5
0
 /**
  * Rebuild Post Thumbnails
  *
  * @return	@e void
  */
 public function rebuildThumbnails()
 {
     require_once IPS_KERNEL_PATH . 'classImage.php';
     /*noLibHook*/
     require_once IPS_KERNEL_PATH . 'classImageGd.php';
     /*noLibHook*/
     //-----------------------------------------
     // Set up
     //-----------------------------------------
     $done = 0;
     $start = intval($this->request['st']) >= 0 ? intval($this->request['st']) : 0;
     $end = intval($this->request['pergo']) ? intval($this->request['pergo']) : 100;
     $dis = $end + $start;
     $output = array();
     //-----------------------------------------
     // Got any more?
     //-----------------------------------------
     $tmp = $this->DB->buildAndFetch(array('select' => 'attach_id', 'from' => 'attachments', 'where' => "attach_rel_module IN('post','msg')", 'limit' => array($dis, 1)));
     $max = intval($tmp['attach_id']);
     //-----------------------------------------
     // Avoid limit...
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'attachments', 'where' => "attach_rel_module IN('post','msg')", 'order' => 'attach_id ASC', 'limit' => array($start, $end)));
     $outer = $this->DB->execute();
     //-----------------------------------------
     // Process...
     //-----------------------------------------
     while ($r = $this->DB->fetch($outer)) {
         if ($r['attach_is_image']) {
             if ($r['attach_thumb_location'] and $r['attach_thumb_location'] != $r['attach_location']) {
                 if (is_file($this->settings['upload_dir'] . '/' . $r['attach_thumb_location'])) {
                     if (!@unlink($this->settings['upload_dir'] . '/' . $r['attach_thumb_location'])) {
                         $output[] = $this->lang->words['re_noremove'] . $r['attach_thumb_location'];
                         continue;
                     }
                 }
             }
             $attach_data = array();
             $thumbnail = preg_replace("/^(.*)\\.(.+?)\$/", "\\1_thumb.\\2", $r['attach_location']);
             $image = new classImageGd();
             $image->init(array('image_path' => $this->settings['upload_dir'], 'image_file' => $r['attach_location']));
             $image->force_resize = false;
             $return = $image->resizeImage($this->settings['siu_width'], $this->settings['siu_height']);
             if (!$return['noResize']) {
                 $image->writeImage($this->settings['upload_dir'] . '/' . $thumbnail);
                 $attach_data['attach_thumb_location'] = $thumbnail;
             } else {
                 $attach_data['attach_thumb_location'] = $r['attach_location'];
             }
             $attach_data['attach_thumb_width'] = intval($return['newWidth'] ? $return['newWidth'] : $image->cur_dimensions['width']);
             $attach_data['attach_thumb_height'] = intval($return['newHeight'] ? $return['newHeight'] : $image->cur_dimensions['height']);
             if (count($attach_data)) {
                 $this->DB->update('attachments', $attach_data, 'attach_id=' . $r['attach_id']);
                 $output[] = $this->lang->words['re_resized'] . $r['attach_location'];
             }
             unset($image);
         }
         $done++;
     }
     //-----------------------------------------
     // Finish - or more?...
     //-----------------------------------------
     if (!$done and !$max) {
         //-----------------------------------------
         // Done..
         //-----------------------------------------
         $text = $this->lang->words['re_rebuildcomp'] . '<br />' . implode("<br />", $output);
         $url = "{$this->settings['base_url']}{$this->form_code}";
     } else {
         //-----------------------------------------
         // More..
         //-----------------------------------------
         $thisgoeshere = sprintf($this->lang->words['re_thisgoeshere'], $dis);
         $text = $thisgoeshere . '<br />' . implode("<br />", $output);
         $url = "{$this->settings['base_url']}{$this->form_code}&do={$this->request['do']}&pergo={$this->request['pergo']}&st={$dis}";
     }
     //-----------------------------------------
     // Bye....
     //-----------------------------------------
     $this->_specialRedirect($url, $text);
 }