/** * @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 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; }
public static function factory($conditions) { if ($conditions instanceof BaseClass) { return $conditions; } $select = new self(); if (is_array($conditions) || $conditions instanceof \Traversable) { foreach ($conditions as $name => $condition) { switch ($name) { case 'columns': if (is_array($condition) && array_key_exists(0, $condition) && is_array($condition[0])) { call_user_func_array(array($select, 'columns'), $condition); continue; } $select->columns($condition); break; case 'combine': if (is_array($condition)) { call_user_func_array(array($select, 'combine'), $condition); continue; } $select->combine($condition); break; case 'from': $select->from($condition); break; case 'group': $select->group($condition); break; case 'having': if (is_array($condition) && array_key_exists(1, $condition) && ($condition[1] == PredicateSet::OP_AND || $condition[1] == PredicateSet::OP_OR)) { call_user_func_array(array($select, 'having'), $condition); continue; } $select->having($condition); break; case 'join': call_user_func_array(array($select, 'join'), $condition); break; case 'limit': $select->limit($condition); break; case 'offset': $select->offset($condition); break; case 'order': $select->order($condition); break; case 'where': if (is_array($condition) && array_key_exists(1, $condition) && ($condition[1] == PredicateSet::OP_AND || $condition[1] == PredicateSet::OP_OR)) { call_user_func_array(array($select, 'where'), $condition); continue; } $select->where($condition); break; default: throw new \Exception("Invalid condition ({$name})"); } } return $select; } throw new \Exception(sprintf('Invalid conditions type (%s)', is_object($conditions) ? get_class($conditions) : gettype($conditions))); }