diff options
| -rw-r--r-- | attachment_uploader.php | 12 | ||||
| -rw-r--r-- | includes/classes/LibertyContent.php | 14 | ||||
| -rw-r--r-- | includes/classes/LibertyStructure.php | 32 | ||||
| -rw-r--r-- | includes/classes/LibertySystem.php | 21 |
4 files changed, 26 insertions, 53 deletions
diff --git a/attachment_uploader.php b/attachment_uploader.php index dc642de..193cb46 100644 --- a/attachment_uploader.php +++ b/attachment_uploader.php @@ -33,16 +33,10 @@ if ( !isset($_FILES['upload'] ) ) { // 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 ) ) { + if( LibertySystem::requireContentType( $contentTypeHash ) ) { + $gContent = new $contentTypeHash['handler_class'](); + } else { $error = tra( "Undefined handler package path" ); - }else{ - require_once( constant( $pathVar ).$classFile ); - $gContent = new $class(); } } }else{ diff --git a/includes/classes/LibertyContent.php b/includes/classes/LibertyContent.php index 4fe00b2..2567175 100644 --- a/includes/classes/LibertyContent.php +++ b/includes/classes/LibertyContent.php @@ -3404,16 +3404,10 @@ class LibertyContent extends LibertyBase implements BitCacheable { global $gLibertySystem, $gBitSystem; foreach ($gLibertySystem->mContentTypes as $type) { if ($type['content_type_guid'] == $pContentTypeGuid) { - if( !empty( $gBitSystem->mPackages[$type['handler_package']]['path'] ) ) { - $path = $gBitSystem->mPackages[$type['handler_package']]['path'];//constant(strtoupper($type['handler_package']).'_PKG_PATH'); - if( file_exists( $path.$type['handler_file'] ) ) { - include_once($path.$type['handler_file']); - if ( class_exists( $type['handler_class'] ) ) { - $content = new $type['handler_class']; - if (method_exists($content, 'getFilterSql')) { - $content->getFilterSql($pSql, $pBindVars, $pHash); - } - } + if( LibertySystem::requireContentType( $type ) ) { + $content = new $type['handler_class']; + if (method_exists($content, 'getFilterSql')) { + $content->getFilterSql($pSql, $pBindVars, $pHash); } } } diff --git a/includes/classes/LibertyStructure.php b/includes/classes/LibertyStructure.php index 8456f37..80a7c99 100644 --- a/includes/classes/LibertyStructure.php +++ b/includes/classes/LibertyStructure.php @@ -79,12 +79,8 @@ class LibertyStructure extends LibertyBase { $type = &$contentTypes[$ret['content_type_guid']]; if( empty( $type['content_object'] ) && !empty( $gBitSystem->mPackages[$type['handler_package']] ) ) { // create *one* object for each object *type* to call virtual methods. - $handlerFile = $gBitSystem->mPackages[$type['handler_package']]['path'].$type['handler_file']; - if( file_exists( $handlerFile ) ) { - include_once( $handlerFile ); - if( class_exists( $type['handler_class'] ) ) { - $type['content_object'] = new $type['handler_class'](); - } + if( LibertySystem::requireContentType( $type ) ) { + $type['content_object'] = new $type['handler_class'](); } } if( !empty( $type['content_object'] ) && is_object( $type['content_object'] ) ) { @@ -264,12 +260,8 @@ class LibertyStructure extends LibertyBase { $type = &$contentTypes[$res['content_type_guid']]; if( empty( $type['content_object'] ) ) { // create *one* object for each object *type* to call virtual methods. - $handlerFile = $gBitSystem->mPackages[$type['handler_package']]['path'].$type['handler_file']; - if( file_exists( $handlerFile ) ) { - include_once( $handlerFile ); - if( class_exists( $type['handler_class'] ) ) { - $type['content_object'] = new $type['handler_class'](); - } + if( LibertySystem::requireContentType( $type ) ) { + $type['content_object'] = new $type['handler_class'](); } } if( !empty( $pParamHash['thumbnail_size'] ) ) { @@ -944,12 +936,8 @@ class LibertyStructure extends LibertyBase { $type = &$contentTypes[$res['content_type_guid']]; if( empty( $type['content_object'] ) && !empty( $gBitSystem->mPackages[$type['handler_package']] ) ) { // create *one* object for each object *type* to call virtual methods. - $handlerFile = $gBitSystem->mPackages[$type['handler_package']]['path'].$type['handler_file']; - if( file_exists( $handlerFile ) ) { - include_once( $handlerFile ); - if( class_exists( $type['handler_class'] ) ) { - $type['content_object'] = new $type['handler_class'](); - } + if( LibertySystem::requireContentType( $type ) ) { + $type['content_object'] = new $type['handler_class'](); } } if( !empty( $type['content_object'] ) && is_object( $type['content_object'] ) ) { @@ -964,12 +952,8 @@ class LibertyStructure extends LibertyBase { } $pkgPath = strtoupper( $res['handler_package'] ).'_PKG_PATH'; if( defined( $pkgPath ) ) { - $classFile = constant( strtoupper( $res['handler_package'] ).'_PKG_PATH' ).$res['handler_file']; - if( file_exists( $classFile ) ) { - require_once( $classFile ); - if( class_exists( $res['handler_class'] ) ) { - $res['display_url'] = $res['handler_class']::getDisplayUrlFromHash( $res ); - } + if( LibertySystem::requireContentType( $res ) ) { + $res['display_url'] = $res['handler_class']::getDisplayUrlFromHash( $res ); } } $back[] = $res; diff --git a/includes/classes/LibertySystem.php b/includes/classes/LibertySystem.php index 9165fc2..9fcfd8b 100644 --- a/includes/classes/LibertySystem.php +++ b/includes/classes/LibertySystem.php @@ -626,21 +626,22 @@ class LibertySystem extends BitSingleton { } /** - * requireHandlerFile will require_once() the handler file if given the hash found in $gLibertySystem->mContentTypes[content_type_guid] + * requireContentType will require_once() the handler file if given the hash found in $gLibertySystem->mContentTypes[content_type_guid] * * @param array $pContentTypeHash the hash found in $gLibertySystem->mContentTypes[content_type_guid] * @access public * @return TRUE on success, FALSE on failure */ - private function requireHandlerFile( $pContentTypeHash ) { - $ret = FALSE; + public static function requireContentType( $pContentTypeHash ) { $pkgName = strtoupper( $pContentTypeHash['handler_package'] ); - foreach( array( '_PKG_CLASS_PATH', '_PKG_INCLUDE_PATH', '_PKG_PATH' ) as $pkgConstPath ) { - if( defined( $pkgName.$pkgConstPath ) && ($pkgDef = constant( $pkgName.$pkgConstPath )) ) { - $handlerFile = $pkgDef.$pContentTypeHash['handler_file']; - if( is_file( $handlerFile ) ) { - require_once( $handlerFile ); - $ret = TRUE; + if( !($ret = class_exists( $pContentTypeHash['handler_class'] )) ) { + foreach( array( '_PKG_CLASS_PATH', '_PKG_INCLUDE_PATH', '_PKG_PATH' ) as $pkgConstPath ) { + if( defined( $pkgName.$pkgConstPath ) && ($pkgDef = constant( $pkgName.$pkgConstPath )) ) { + $handlerFile = $pkgDef.$pContentTypeHash['handler_file']; + if( is_file( $handlerFile ) ) { + require_once( $handlerFile ); + $ret = class_exists( $pContentTypeHash['handler_class'] ); + } } } } @@ -673,7 +674,7 @@ class LibertySystem extends BitSingleton { if( !isset( $this->mContentTypes ) ) { $this->loadContentTypes(); } - if( !empty( $this->mContentTypes[$pContentTypeGuid] ) && $this->requireHandlerFile( $this->mContentTypes[$pContentTypeGuid] ) ) { + if( !empty( $this->mContentTypes[$pContentTypeGuid] ) && static::requireContentType( $this->mContentTypes[$pContentTypeGuid] ) ) { $ret = $this->mContentTypes[$pContentTypeGuid]['handler_class']; } return $ret; |
