isFeatureActive( "liberty_display_status" ) ){ $error = KernelTools::tra( "You must save the content to upload an attachment." ); }elseif( !isset( $gLibertySystem->mContentTypes[$_REQUEST['liberty_attachments']['content_type_guid']] ) ){ $error = KernelTools::tra( "You are attempting to upload a file to an invalid content type" ); }else{ // load up the requested content type handler class $contentType = $_REQUEST['liberty_attachments']['content_type_guid']; $contentTypeHash = $gLibertySystem->mContentTypes[$contentType]; $class = $contentTypeHash['handler_class']; $classFile = $contentTypeHash['handler_file']; $package = $contentTypeHash['handler_package']; $pathVar = strtoupper($package).'_PKG_PATH'; if( !defined( $pathVar ) ) { $error = KernelTools::tra( "Undefined handler package path" ); }else{ require_once( constant( $pathVar ).$classFile ); $gContent = new $class(); } } }else{ // if we don't have a valid content_id or content_type_guid we can't do nothing for you $error = "You have not specified a content item or content type to associate this upload with"; } if( isset( $gContent ) ){ $storeHash = $_REQUEST['liberty_attachments']; // Keep a copy in the right place as well so primary works. $storeHash['liberty_attachments'] = $_REQUEST['liberty_attachments']; if ( !$gContent->isValid() ){ // if we dont have a content object for this attachment yet, lets create a draft. $storeHash['content_status_id'] = -5; }else{ // else we'll skip storing the content $storeHash['skip_content_store'] = true; } // store the attachment. if ( !$gContent->store( $storeHash ) ) { $error = $gContent->mErrors; }else{ // Load up the new attachment. if ( !empty($storeHash['upload_store'] ) ) { foreach ( $storeHash['upload_store'] as $id => $file ) { if ( $id != 'existing' ) { foreach ( $file as $key => $data ) { $gContent->mStorage[$data['attachment_id']] = $gContent->getAttachment( $data['attachment_id'] ); } } } } } } if ( !is_null( $error ) ){ if ( is_array( $error ) ){ $error = implode("\n", $error); } $gBitSmarty->assign('errors', $error); }else{ // @Todo is this stuff necessary? $gContent->load(); // Make them come out in the right order if( !empty( $gContent->mStorage ) ) { ksort( $gContent->mStorage ); } } $gBitSmarty->assign( 'gContent', $gContent ); $gBitSmarty->assign( 'libertyUploader', true ); $gBitSmarty->assign( 'uploadTab', true ); if( !empty( $_REQUEST['liberty_attachments']['primary_label'] ) ) { $gBitSmarty->assign('primary_label', $_REQUEST['liberty_attachments']['primary_label']); } if( isset( $_REQUEST['liberty_attachments']['form_id'] ) ){ $gBitSmarty->assign( 'form_id', $_REQUEST['liberty_attachments']['form_id'] ); } echo $gBitSystem->display( 'bitpackage:liberty/attachment_uploader.tpl', null, [ 'format'=>'none', 'display_mode' => 'display' ]); ?>