/** * Uploads category or group canvas or logo * * @param string $type * @param CategoryTable|GroupTable $row * @return bool */ static public function uploadImage( $type = 'canvas', &$row ) { global $_CB_framework, $_PLUGINS; if ( ( ! $type ) || ( ! in_array( $type, array( 'canvas', 'logo' ) ) ) ) { return false; } $method = Application::Input()->get( 'post/' . $type . '_method', null, GetterInterface::INT ); if ( $method === 0 ) { return true; } static $params = null; if ( ! $params ) { $plugin = $_PLUGINS->getLoadedPlugin( 'user', 'cbgroupjive' ); $params = $_PLUGINS->getPluginParams( $plugin ); } $basePath = $_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/plug_cbgroupjive'; if ( $row instanceof GroupTable ) { $imagePath = $basePath . '/' . (int) $row->get( 'category' ) . '/' . (int) $row->get( 'id' ); } else { $imagePath = $basePath . '/' . (int) $row->get( 'id' ); } if ( ( ( $method === null ) || ( $method === 1 ) ) && isset( $_FILES[$type]['tmp_name'] ) && ( ! empty( $_FILES[$type]['tmp_name'] ) ) ) { if ( $row instanceof GroupTable ) { self::createDirectory( $basePath, $row->get( 'category' ), $row->get( 'id' ) ); } else { self::createDirectory( $basePath, $row->get( 'id' ) ); } $resample = $params->get( $type . '_resample', 1 ); $aspectRatio = $params->get( $type . '_maintain_aspect_ratio', 1 ); $imageHeight = (int) $params->get( $type . '_image_height', 640 ); if ( ! $imageHeight ) { $imageHeight = 640; } $imageWidth = (int) $params->get( $type . '_image_width', 1280 ); if ( ! $imageWidth ) { $imageWidth = 1280; } $thumbHeight = (int) $params->get( $type . '_thumbnail_height', 320 ); if ( ! $thumbHeight ) { $thumbHeight = 320; } $thumbWidth = (int) $params->get( $type . '_thumbnail_width', 640 ); if ( ! $thumbWidth ) { $thumbWidth = 640; } $conversionType = (int) Application::Config()->get( 'conversiontype', 0 ); $imageSoftware = ( $conversionType == 5 ? 'gmagick' : ( $conversionType == 1 ? 'imagick' : 'gd' ) ); $imageId = uniqid(); try { $image = new \CBLib\Image\Image( $imageSoftware, $resample, $aspectRatio ); $image->setName( $imageId ); $image->setSource( $_FILES[$type] ); $image->setDestination( $imagePath . '/' ); $image->processImage( $imageWidth, $imageHeight ); $newFileName = $image->getCleanFilename(); $image->setName( 'tn' . $imageId ); $image->processImage( $thumbWidth, $thumbHeight ); if ( $row->get( $type ) ) { $oldImage = $imagePath . '/' . $row->get( $type ); if ( file_exists( $oldImage ) ) { @unlink( $oldImage ); } $oldThumbnail = $imagePath . '/tn' . $row->get( $type ); if ( file_exists( $oldThumbnail ) ) { @unlink( $oldThumbnail ); } } $row->set( $type, $newFileName ); } catch ( \Exception $e ) { $row->setError( $e->getMessage() ); return false; } } elseif ( ( $method === 2 ) && $row->get( $type ) ) { $image = $imagePath . '/' . $row->get( $type ); if ( file_exists( $image ) ) { @unlink( $image ); } $thumbnail = $imagePath . '/tn' . $row->get( $type ); if ( file_exists( $thumbnail ) ) { @unlink( $thumbnail ); } $row->set( $type, '' ); } return true; }
/** * @param cbautoactionsActionTable $trigger * @param UserTable $user */ public function execute( $trigger, $user ) { global $_CB_database; if ( ! $this->installed() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NOT_INSTALLED', ':: Action [action] :: CB GroupJive is not installed', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } return; } foreach ( $trigger->getParams()->subTree( 'groupjive' ) as $row ) { /** @var ParamsInterface $row */ switch( (int) $row->get( 'mode', 1, GetterInterface::INT ) ) { case 3: $owner = $row->get( 'owner', null, GetterInterface::STRING ); if ( ! $owner ) { $owner = (int) $user->get( 'id' ); } else { $owner = (int) $trigger->getSubstituteString( $owner ); } if ( ! $owner ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_OWNER', ':: Action [action] :: CB GroupJive skipped due to missing owner', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $name = $trigger->getSubstituteString( $row->get( 'name', null, GetterInterface::STRING ) ); if ( ! $name ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_NAME', ':: Action [action] :: CB GroupJive skipped due to missing name', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $category = new CategoryTable(); $category->load( array( 'name' => $name ) ); if ( ! $category->get( 'id' ) ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_CATEGORY', ':: Action [action] :: CB GroupJive skipped due to missing category', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $category->set( 'published', 1 ); $category->set( 'user_id', $owner ); $category->set( 'name', $name ); $category->set( 'description', $trigger->getSubstituteString( $row->get( 'description', null, GetterInterface::STRING ) ) ); $category->set( 'access', 1 ); $category->set( 'create_access', 0 ); $category->set( 'types', $row->get( 'types', '1|*|2|*|3', GetterInterface::STRING ) ); $category->set( 'ordering', 1 ); if ( ! $category->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_FAILED', ':: Action [action] :: CB GroupJive failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $category->getError() ) ) ); continue; } } break; case 2: $owner = $row->get( 'owner', null, GetterInterface::STRING ); if ( ! $owner ) { $owner = (int) $user->get( 'id' ); } else { $owner = (int) $trigger->getSubstituteString( $owner ); } if ( ! $owner ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_OWNER', ':: Action [action] :: CB GroupJive skipped due to missing owner', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $categoryId = (int) $row->get( 'category', -1, GetterInterface::INT ); $category = new CategoryTable(); if ( $categoryId == -1 ) { $name = $trigger->getSubstituteString( $row->get( 'category_name', null, GetterInterface::STRING ) ); if ( ! $name ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_CAT_NAME', ':: Action [action] :: CB GroupJive skipped due to missing category name', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $category->load( array( 'name' => $name ) ); if ( ! $category->get( 'id' ) ) { $category->set( 'published', 1 ); $category->set( 'user_id', $owner ); $category->set( 'name', $name ); $category->set( 'description', $trigger->getSubstituteString( $row->get( 'category_description', null, GetterInterface::STRING ) ) ); $category->set( 'access', 1 ); $category->set( 'create_access', 0 ); $category->set( 'types', $row->get( 'category_types', '1|*|2|*|3', GetterInterface::STRING ) ); $category->set( 'ordering', 1 ); if ( ! $category->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_FAILED', ':: Action [action] :: CB GroupJive failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $category->getError() ) ) ); } continue; } } } else { $category->load( (int) $categoryId ); } if ( ! $category->get( 'id' ) ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_CATEGORY', ':: Action [action] :: CB GroupJive skipped due to missing category', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $name = $trigger->getSubstituteString( $row->get( 'name', null, GetterInterface::STRING ) ); if ( ! $name ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_NAME', ':: Action [action] :: CB GroupJive skipped due to missing name', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $group = new GroupTable(); $join = false; if ( $row->get( 'unique', 1, GetterInterface::BOOLEAN ) ) { $group->load( array( 'category' => (int) $category->get( 'id' ), 'user_id' => (int) $owner, 'name' => $name ) ); } else { $group->load( array( 'category' => (int) $category->get( 'id' ), 'name' => $name ) ); if ( $row->get( 'autojoin', 1, GetterInterface::BOOLEAN ) ) { $join = true; } } if ( ! $group->get( 'id' ) ) { $group->set( 'published', 1 ); $group->set( 'category', (int) $category->get( 'id' ) ); $group->set( 'user_id', $owner ); $group->set( 'name', $name ); $group->set( 'description', $trigger->getSubstituteString( $row->get( 'description', null, GetterInterface::STRING ) ) ); $group->set( 'types', (int) $row->get( 'type', 1, GetterInterface::INT ) ); $group->set( 'ordering', 1 ); if ( ! $group->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_FAILED', ':: Action [action] :: CB GroupJive failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $group->getError() ) ) ); } continue; } } elseif ( $join ) { $groupUser = new \CB\Plugin\GroupJive\Table\UserTable( $_CB_database ); $groupUser->load( array( 'group' => (int) $group->get( 'id' ), 'user_id' => (int) $user->get( 'id' ) ) ); if ( ! $groupUser->get( 'id' ) ) { $groupUser->set( 'user_id', (int) $user->get( 'id' ) ); $groupUser->set( 'group', (int) $group->get( 'id' ) ); $groupUser->set( 'status', (int) $row->get( 'group_status', 1, GetterInterface::INT ) ); if ( ! $groupUser->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_FAILED', ':: Action [action] :: CB GroupJive failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $groupUser->getError() ) ) ); } continue; } } } break; case 4: $groups = $row->get( 'groups', null, GetterInterface::STRING ); if ( $groups ) { $groups = explode( '|*|', $groups ); cbArrayToInts( $groups ); foreach ( $groups as $groupId ) { $group = new GroupTable(); $group->load( (int) $groupId ); if ( $group->get( 'id' ) ) { $groupUser = new \CB\Plugin\GroupJive\Table\UserTable( $_CB_database ); $groupUser->load( array( 'group' => (int) $group->get( 'id' ), 'user_id' => (int) $user->get( 'id' ) ) ); if ( $groupUser->get( 'id' ) && ( $groupUser->get( 'status' ) != 4 ) ) { $groupUser->delete(); } } } } break; case 1: default: $groups = $row->get( 'groups', null, GetterInterface::STRING ); if ( $groups ) { $groups = explode( '|*|', $groups ); cbArrayToInts( $groups ); foreach ( $groups as $groupId ) { $group = new GroupTable(); $group->load( (int) $groupId ); if ( $group->get( 'id' ) ) { $groupUser = new \CB\Plugin\GroupJive\Table\UserTable( $_CB_database ); $groupUser->load( array( 'group' => (int) $group->get( 'id' ), 'user_id' => (int) $user->get( 'id' ) ) ); if ( ! $groupUser->get( 'id' ) ) { $groupUser->set( 'user_id', (int) $user->get( 'id' ) ); $groupUser->set( 'group', (int) $group->get( 'id' ) ); $groupUser->set( 'status', (int) $row->get( 'status', 1, GetterInterface::INT ) ); if ( ! $groupUser->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_FAILED', ':: Action [action] :: CB GroupJive failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $groupUser->getError() ) ) ); } continue; } } } } } break; } } }