Beispiel #1
0
 /**
  * Takes a photo and builds it nicely.
  * @param string $fileLocation
  * @param int $memberId
  * @param bool	$skipDir	Don't add profile directory
  */
 public function buildSizedPhotos($fileLocation, $memberId, $skipDir = false)
 {
     $memberData = IPSMember::load($memberId);
     $t_height = $this->settings['member_photo_crop'] ? $this->settings['member_photo_crop'] : 100;
     $t_width = $this->settings['member_photo_crop'] ? $this->settings['member_photo_crop'] : 100;
     $p_max = $memberData['photoMaxKb'];
     $p_width = $memberData['photoMaxWidth'];
     $p_height = $memberData['photoMaxHeight'];
     $ext = IPSText::getFileExtension($fileLocation);
     $needResize = false;
     if (!$memberId) {
         return array('status' => 'cannot_find_member');
     }
     if (IN_ACP) {
         $memberData['photoMaxKb'] = $this->memberData['photoMaxKb'];
         $memberData['photoMaxWidth'] = $this->memberData['photoMaxWidth'];
         $memberData['photoMaxHeight'] = $this->memberData['photoMaxHeight'];
     }
     /* Fix up upload directory */
     $paths = $this->_getProfileUploadPaths($skipDir);
     $storagePath = $this->_getProfileUploadPaths();
     $upload_path = $paths['path'];
     $upload_dir = $paths['dir'];
     /* Does image even exist?  If not, just return (can't rebuild a file that doesn't exist). */
     if (!file_exists($upload_path . '/' . $fileLocation)) {
         return array('final_location' => '', 'final_width' => 0, 'final_height' => 0, 't_final_location' => '', 't_file_name' => '', 't_final_width' => 0, 't_final_height' => 0, 'status' => 'missing_image');
     }
     /* Get kernel library */
     require_once IPS_KERNEL_PATH . 'classImage.php';
     /*noLibHook*/
     /* Fetch image dims */
     $imageDimensions = @getimagesize($upload_path . '/' . $fileLocation);
     /* Do we need to resize? */
     if ($imageDimensions[0] > $t_width or $imageDimensions[1] > $t_height) {
         $needResize = true;
     } else {
         if ($ext == 'gif' && !$this->settings['member_photo_gif_animate']) {
             /* Resize even if smaller to prevent animation */
             $needResize = true;
         }
     }
     /* Overide if we have a GIF and want to keep it animating */
     if ($ext == 'gif' && $this->settings['member_photo_gif_animate']) {
         $needResize = false;
     }
     /** SQUARE THUMBS **/
     if ($needResize) {
         $image = ips_kernel_image::bootstrap('gd');
         $image->init(array('image_path' => $upload_path, 'image_file' => $fileLocation));
         /* If we're uploading a GIF then resize to stop animations */
         if ($ext == 'gif' && !$this->settings['member_photo_gif_animate']) {
             $image->force_resize = true;
         }
         $return = $image->croppedResize($t_width, $t_height);
         $image->writeImage($storagePath['path'] . '/' . 'photo-thumb-' . $memberId . '.' . $ext);
         $t_im['img_width'] = $return['newWidth'];
         $t_im['img_height'] = $return['newHeight'];
         $t_im['img_location'] = count($return) ? $storagePath['dir'] . 'photo-thumb-' . $memberId . '.' . $ext : $upload_dir . $fileLocation;
     } else {
         $_data = IPSLib::scaleImage(array('max_height' => $t_height, 'max_width' => $t_width, 'cur_width' => $imageDimensions[0], 'cur_height' => $imageDimensions[1]));
         $t_im['img_width'] = $_data['img_width'];
         $t_im['img_height'] = $_data['img_height'];
         $t_im['img_location'] = $upload_dir . $fileLocation;
     }
     /** MAIN PHOTO **/
     if ($imageDimensions[0] > $p_width or $imageDimensions[1] > $p_height) {
         $image = ips_kernel_image::bootstrap('gd');
         $image->init(array('image_path' => $upload_path, 'image_file' => $fileLocation));
         $return = $image->resizeImage($p_width, $p_height);
         $image->writeImage($storagePath['path'] . '/' . 'photo-' . $memberId . '.' . $ext);
         $t_real_name = $return['thumb_location'] ? $return['thumb_location'] : $fileLocation;
         $im['img_width'] = $return['newWidth'] ? $return['newWidth'] : $image->cur_dimensions['width'];
         $im['img_height'] = $return['newHeight'] ? $return['newHeight'] : $image->cur_dimensions['height'];
         $return['final_location'] = $storagePath['dir'] . $fileLocation;
     } else {
         $im['img_width'] = $imageDimensions[0];
         $im['img_height'] = $imageDimensions[1];
         $return['final_location'] = $upload_dir . $fileLocation;
     }
     /* Main photo */
     // If we don't rebuild, the image is in the original location - which may not be in the /profile folder */
     //$return['final_location'] = $storagePath['dir'] . $fileLocation;
     $return['final_width'] = $im['img_width'];
     $return['final_height'] = $im['img_height'];
     /* Thumb */
     /* If we don't need to resize, it's same as the main image (which may get moved during IT'S resize) */
     $return['t_final_location'] = $needResize ? $t_im['img_location'] : $return['final_location'];
     $return['t_file_name'] = $t_im['img_location'];
     $return['t_final_width'] = $t_im['img_width'];
     $return['t_final_height'] = $t_im['img_height'];
     $return['status'] = 'ok';
     return $return;
 }
 /**
  * Returns the file extension of the current filename
  *
  * @param	string		Filename
  * @return	@e string
  */
 public function _getFileExtension($file)
 {
     if (class_exists('IPSText')) {
         return IPSText::getFileExtension($file);
     }
     return strtolower(str_replace(".", "", substr($file, strrpos($file, '.'))));
 }
Beispiel #3
0
 private function convert_ccs_articles()
 {
     $main = array('select' => '*', 'from' => 'posts', 'where' => 'post_type = \'post\'');
     $loop = $this->lib->load('ccs_articles', $main);
     $fields = array();
     $this->DB->build(array('select' => '*', 'from' => 'ccs_database_fields', 'where' => 'field_database_id = 1'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         $fields[$row['field_key']] = $row['field_id'];
     }
     while ($row = ipsRegistry::DB('hb')->fetch($this->lib->queryRes)) {
         $categories = $this->_fetchArticleCategories();
         $save = array('member_id' => $row['post_author'], 'record_saved' => strtotime($row['post_date']), 'record_updated' => strtotime($row['post_modified']), 'category_id' => array_key_exists($row['ID'], $categories) ? $categories[$row['ID']] : 1, 'record_locked' => $row['comment_status'] == 'open' ? 0 : 1, 'record_approved' => $row['post_status'] != 'publish' ? 0 : 1);
         if ($fields['article_title']) {
             $save['field_' . $fields['article_title']] = $row['post_title'];
         }
         if ($fields['article_body']) {
             IPSText::getTextClass('bbcode')->parse_bbcode = 0;
             IPSText::getTextClass('bbcode')->parse_html = 1;
             IPSText::getTextClass('bbcode')->parse_emoticons = 1;
             IPSText::getTextClass('bbcode')->parse_nl2br = 0;
             IPSText::getTextClass('bbcode')->parsing_section = 'global';
             $save['field_' . $fields['article_body']] = IPSText::getTextClass('bbcode')->preDisplayParse($this->fixPostData($row['post_content']));
         }
         if ($fields['article_date']) {
             $save['field_' . $fields['article_date']] = strtotime($row['post_date']);
         }
         if ($fields['article_homepage']) {
             $save['field_' . $fields['article_homepage']] = ',1,';
         }
         if ($fields['article_comments']) {
             $save['field_' . $fields['article_comments']] = 1;
         }
         if ($fields['article_expiry']) {
             $save['field_' . $fields['article_expiry']] = '';
         }
         if ($fields['article_cutoff']) {
             $save['field_' . $fields['article_cutoff']] = '';
         }
         if ($fields['article_image']) {
             $save['field_' . $fields['article_image']] = '';
             // Let's try and automatically determine the upload path.
             $uploadPath = ipsRegistry::DB('hb')->buildAndFetch(array('select' => 'option_value', 'from' => 'options', 'where' => "option_name = 'upload_path'"));
             if ($uploadPath['option_value']) {
                 // Does this post have an image? Cue insanity.
                 $meta1 = ipsRegistry::DB('hb')->buildAndFetch(array('select' => 'meta_value', 'from' => 'postmeta', 'where' => "post_id = {$row['ID']} AND meta_key = '_thumbnail_id'"));
                 if ($meta1['meta_value']) {
                     $image = ipsRegistry::DB('hb')->buildAndFetch(array('select' => 'meta_value', 'from' => 'postmeta', 'where' => "meta_key = '_wp_attachment_metadata' AND post_id = {$meta1['meta_value']}"));
                     if ($image['meta_value']) {
                         $metaValue = unserialize($image['meta_value']);
                         if ($metaValue['file']) {
                             $newFileName = md5(uniqid(microtime(), true));
                             $ext = IPSText::getFileExtension($metaValue['file']);
                             if (@copy($uploadPath['option_value'] . '/' . $metaValue['file'], $this->settings['upload_dir'] . '/' . $newFileName . '.' . $ext)) {
                                 $save['field_' . $fields['article_image']] = $newFileName . '.' . $ext;
                             }
                         }
                     }
                 }
             }
         }
         $this->lib->convertArticle($row['ID'], $save);
     }
     $this->lib->next();
 }
Beispiel #4
0
 /**
  * Rebuild Attachment Data
  *
  * @return	@e void
  */
 public function rebuildAttachdata()
 {
     //-----------------------------------------
     // 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', 'limit' => array($dis, 1)));
     $max = intval($tmp['attach_id']);
     //-----------------------------------------
     // Avoid limit...
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'attachments', 'order' => 'attach_id ASC', 'limit' => array($start, $end)));
     $outer = $this->DB->execute();
     //-----------------------------------------
     // Process...
     //-----------------------------------------
     while ($r = $this->DB->fetch($outer)) {
         //-----------------------------------------
         // Get ext
         //-----------------------------------------
         $update = array();
         $update['attach_ext'] = IPSText::getFileExtension($r['attach_file']);
         if ($r['attach_location']) {
             if (is_file($this->settings['upload_dir'] . '/' . $r['attach_location'])) {
                 $update['attach_filesize'] = @filesize($this->settings['upload_dir'] . '/' . $r['attach_location']);
                 if ($r['attach_is_image']) {
                     $dims = @getimagesize($this->settings['upload_dir'] . '/' . $r['attach_location']);
                     if ($dims[0] and $dims[1]) {
                         $update['attach_img_width'] = $dims[0];
                         $update['attach_img_height'] = $dims[1];
                     }
                 }
             }
         }
         if (count($update)) {
             $this->DB->update('attachments', $update, 'attach_id=' . $r['attach_id']);
         }
         $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);
 }
 /**
  * Checks to see if an uploaded image truly is an image
  *
  * @param	string	Image path
  * @return	@e mixed
  */
 public function extractImageData($imagePath)
 {
     $fileExt = IPSText::getFileExtension($imagePath);
     $img_attributes = @getimagesize($imagePath);
     if (!is_array($img_attributes) or !count($img_attributes)) {
         return false;
     } else {
         if (!$img_attributes[2]) {
             return false;
         } else {
             if ($img_attributes[2] == 1 and ($fileExt == 'jpg' or $fileExt == 'jpeg')) {
                 return false;
             }
         }
     }
     $return = array('width' => $img_attributes[0], 'height' => $img_attributes[1], 'fileType' => '');
     switch ($img_attributes[2]) {
         case 1:
             $return['fileType'] = 'gif';
             break;
         case 2:
             $return['fileType'] = 'jpg';
             break;
         case 3:
             $return['fileType'] = 'png';
             break;
     }
     return $return;
 }