/** * @param bool $updateNulls * @return bool */ public function store( $updateNulls = false ) { global $_CB_framework, $_PLUGINS; $new = ( $this->get( 'id' ) ? false : true ); $old = new self(); $this->set( 'date', $this->get( 'date', Application::Database()->getUtcDateTime() ) ); if ( isset( $_FILES['file']['tmp_name'] ) && ( ! empty( $_FILES['file']['tmp_name'] ) ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/cbgroupjivefile'; $filePath = $basePath . '/' . (int) $this->group()->get( 'category' ) . '/' . (int) $this->group()->get( 'id' ); CBGroupJive::createDirectory( $basePath, $this->group()->get( 'category' ), $this->group()->get( 'id' ) ); $fileExtension = strtolower( preg_replace( '/[^-a-zA-Z0-9_]/', '', pathinfo( $_FILES['file']['name'], PATHINFO_EXTENSION ) ) ); $fileName = Get::clean( pathinfo( $_FILES['file']['name'], PATHINFO_FILENAME ), GetterInterface::STRING ) . '.' . $fileExtension; $fileId = uniqid(); $newFileName = $fileId . '.' . $fileExtension; if ( ! move_uploaded_file( $_FILES['file']['tmp_name'], $filePath . '/' . $newFileName ) ) { $this->setError( CBTxt::T( 'GROUP_FILE_UPLOAD_FAILED', 'The file [file] failed to upload!', array( '[file]' => $newFileName ) ) ); return false; } else { @chmod( $filePath . '/' . $newFileName, 0755 ); } if ( $this->get( 'file' ) && file_exists( $filePath . '/' . $this->get( 'file' ) ) ) { @unlink( $filePath . '/' . $this->get( 'file' ) ); } $this->set( 'file', $newFileName ); $this->set( 'filename', $fileName ); $params = $this->params(); $params->unsetEntry( 'name' ); $params->unsetEntry( 'extension' ); $params->unsetEntry( 'mimetype' ); $params->unsetEntry( 'filesize' ); $params->set( 'name', $this->name() ); $params->set( 'extension', $this->extension() ); $params->set( 'mimetype', $this->mimeType() ); $params->set( 'filesize', $this->size( true ) ); $this->set( 'params', $params->asJson() ); } elseif ( ! $this->get( 'filename' ) ) { $this->set( 'filename', $this->get( 'file' ) ); } if ( ! $new ) { $old->load( (int) $this->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeUpdateFile', array( &$this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onBeforeCreateFile', array( &$this ) ); } if ( ! parent::store( $updateNulls ) ) { return false; } if ( $old->get( 'id' ) && $this->get( 'file' ) && ( $old->get( 'group' ) != $this->get( 'group' ) ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/cbgroupjivefile'; $oldPath = $basePath . '/' . (int) $old->group()->get( 'category' ) . '/' . (int) $old->group()->get( 'id' ); $newPath = $basePath . '/' . (int) $this->group()->get( 'category' ) . '/' . (int) $this->group()->get( 'id' ); if ( is_dir( $oldPath ) ) { CBGroupJive::createDirectory( $basePath, $this->group()->get( 'category' ), $this->group()->get( 'id' ) ); if ( file_exists( $oldPath . '/' . $this->get( 'file' ) ) ) { @rename( $oldPath . '/' . $this->get( 'file' ), $newPath . '/' . $this->get( 'file' ) ); } } } if ( ! $new ) { $_PLUGINS->trigger( 'gj_onAfterUpdateFile', array( $this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onAfterCreateFile', array( $this ) ); } return true; }
/** * @param bool $updateNulls * @return bool */ public function store( $updateNulls = false ) { global $_CB_framework, $_PLUGINS; $new = ( $this->get( 'id' ) ? false : true ); $old = new self(); $this->set( 'date', $this->get( 'date', Application::Database()->getUtcDateTime() ) ); if ( isset( $_FILES['image']['tmp_name'] ) && ( ! empty( $_FILES['image']['tmp_name'] ) ) ) { static $params = null; if ( ! $params ) { $plugin = $_PLUGINS->getLoadedPlugin( 'user/plug_cbgroupjive/plugins', 'cbgroupjivephoto' ); $params = $_PLUGINS->getPluginParams( $plugin ); } $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/cbgroupjivephoto'; $filePath = $basePath . '/' . (int) $this->group()->get( 'category' ) . '/' . (int) $this->group()->get( 'id' ); CBGroupJive::createDirectory( $basePath, $this->group()->get( 'category' ), $this->group()->get( 'id' ) ); $resample = $params->get( 'groups_photo_resample', 1 ); $aspectRatio = $params->get( 'groups_photo_maintain_aspect_ratio', 1 ); $imageHeight = (int) $params->get( 'groups_photo_image_height', 640 ); if ( ! $imageHeight ) { $imageHeight = 640; } $imageWidth = (int) $params->get( 'groups_photo_image_width', 1280 ); if ( ! $imageWidth ) { $imageWidth = 1280; } $thumbHeight = (int) $params->get( 'groups_photo_thumbnail_height', 320 ); if ( ! $thumbHeight ) { $thumbHeight = 320; } $thumbWidth = (int) $params->get( 'groups_photo_thumbnail_width', 640 ); if ( ! $thumbWidth ) { $thumbWidth = 640; } $conversionType = (int) Application::Config()->get( 'conversiontype', 0 ); $imageSoftware = ( $conversionType == 5 ? 'gmagick' : ( $conversionType == 1 ? 'imagick' : 'gd' ) ); $fileExtension = strtolower( preg_replace( '/[^-a-zA-Z0-9_]/', '', pathinfo( $_FILES['image']['name'], PATHINFO_EXTENSION ) ) ); $fileName = Get::clean( pathinfo( $_FILES['image']['name'], PATHINFO_FILENAME ), GetterInterface::STRING ) . '.' . $fileExtension; $fileId = uniqid(); try { $image = new Image( $imageSoftware, $resample, $aspectRatio ); $image->setName( $fileId ); $image->setSource( $_FILES['image'] ); $image->setDestination( $filePath . '/' ); $image->processImage( $imageWidth, $imageHeight ); $newFileName = $image->getCleanFilename(); $image->setName( 'tn' . $fileId ); $image->processImage( $thumbWidth, $thumbHeight ); if ( $this->get( 'image' ) ) { if ( file_exists( $filePath . '/' . $this->get( 'image' ) ) ) { @unlink( $filePath . '/' . $this->get( 'image' ) ); } if ( file_exists( $filePath . '/tn' . $this->get( 'image' ) ) ) { @unlink( $filePath . '/tn' . $this->get( 'image' ) ); } } $this->set( 'image', $newFileName ); $this->set( 'filename', $fileName ); $params = $this->params(); $params->unsetEntry( 'name' ); $params->unsetEntry( 'extension' ); $params->unsetEntry( 'mimetype' ); $params->unsetEntry( 'filesize' ); $params->unsetEntry( 'filesize_thumbnail' ); $params->unsetEntry( 'height' ); $params->unsetEntry( 'width' ); $params->unsetEntry( 'height_thumbnail' ); $params->unsetEntry( 'width_thumbnail' ); $params->set( 'name', $this->name() ); $params->set( 'extension', $this->extension() ); $params->set( 'mimetype', $this->mimeType() ); $params->set( 'filesize', $this->size( true ) ); $params->set( 'filesize_thumbnail', $this->size( true, true ) ); $params->set( 'height', $this->height() ); $params->set( 'width', $this->width() ); $params->set( 'height_thumbnail', $this->height( true ) ); $params->set( 'width_thumbnail', $this->width( true ) ); $this->set( 'params', $params->asJson() ); } catch ( Exception $e ) { $this->setError( $e->getMessage() ); return false; } } elseif ( ! $this->get( 'filename' ) ) { $this->set( 'filename', $this->get( 'image' ) ); } if ( ! $new ) { $old->load( (int) $this->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeUpdatePhoto', array( &$this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onBeforeCreatePhoto', array( &$this ) ); } if ( ! parent::store( $updateNulls ) ) { return false; } if ( $old->get( 'id' ) && $this->get( 'image' ) && ( $old->get( 'group' ) != $this->get( 'group' ) ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/cbgroupjivephoto'; $oldPath = $basePath . '/' . (int) $old->group()->get( 'category' ) . '/' . (int) $old->group()->get( 'id' ); $newPath = $basePath . '/' . (int) $this->group()->get( 'category' ) . '/' . (int) $this->group()->get( 'id' ); if ( is_dir( $oldPath ) ) { CBGroupJive::createDirectory( $basePath, $this->group()->get( 'category' ), $this->group()->get( 'id' ) ); if ( file_exists( $oldPath . '/' . $this->get( 'image' ) ) ) { @rename( $oldPath . '/' . $this->get( 'image' ), $newPath . '/' . $this->get( 'image' ) ); } if ( file_exists( $oldPath . '/tn' . $this->get( 'image' ) ) ) { @rename( $oldPath . '/tn' . $this->get( 'image' ), $newPath . '/tn' . $this->get( 'image' ) ); } } } if ( ! $new ) { $_PLUGINS->trigger( 'gj_onAfterUpdatePhoto', array( $this, $old ) ); } else { $_PLUGINS->trigger( 'gj_onAfterCreatePhoto', array( $this ) ); } return true; }
/** * @param null|self $object * @return self|bool */ public function copy( $object = null ) { global $_CB_framework, $_PLUGINS; if ( $object === null ) { $object = clone $this; } $old = new self(); $old->load( (int) $object->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeCopyCategory', array( &$object, $old ) ); $copy = parent::copy( $object ); if ( ! $copy ) { return false; } // Copy the groups in this category: $query = 'SELECT *' . "\n FROM " . $this->getDbo()->NameQuote( '#__groupjive_groups' ) . "\n WHERE " . $this->getDbo()->NameQuote( 'category' ) . " = " . (int) $old->get( 'id' ); $this->getDbo()->setQuery( $query ); $groups = $this->getDbo()->loadObjectList( null, '\CB\Plugin\GroupJive\Table\GroupTable', array( $this->getDbo() ) ); /** @var GroupTable[] $groups */ foreach ( $groups as $group ) { $group->set( 'category', (int) $object->get( 'id' ) ); $group->copy(); } // Copy the canvas and logo: if ( $object->get( 'canvas' ) || $object->get( 'logo' ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/plug_cbgroupjive'; $oldPath = $basePath . '/' . (int) $old->get( 'id' ); $newPath = $basePath . '/' . (int) $object->get( 'id' ); if ( is_dir( $oldPath ) ) { CBGroupJive::createDirectory( $basePath, $object->get( 'id' ) ); CBGroupJive::copyDirectory( $oldPath, $newPath ); } } $_PLUGINS->trigger( 'gj_onAfterCopyCategory', array( $object, $old ) ); return $copy; }
/** * @param null|self $object * @return self|bool */ public function copy( $object = null ) { global $_CB_framework, $_PLUGINS; if ( $object === null ) { $object = clone $this; } $old = new self(); $old->load( (int) $object->get( 'id' ) ); $_PLUGINS->trigger( 'gj_onBeforeCopyGroup', array( &$object, $old ) ); $copy = parent::copy( $object ); if ( ! $copy ) { return false; } // Copy the canvas and logo: if ( $object->get( 'canvas' ) || $object->get( 'logo' ) ) { $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/plug_cbgroupjive'; $oldPath = $basePath . '/' . (int) $old->get( 'category' ) . '/' . (int) $old->get( 'id' ); $newPath = $basePath . '/' . (int) $object->get( 'category' ) . '/' . (int) $object->get( 'id' ); if ( is_dir( $oldPath ) ) { CBGroupJive::createDirectory( $basePath, $object->get( 'category' ), $object->get( 'id' ) ); CBGroupJive::copyDirectory( $oldPath, $newPath ); } } $_PLUGINS->trigger( 'gj_onAfterCopyGroup', array( $object, $old ) ); return $copy; }