mbmodule.php

来自「SugarCRM5.1 开源PHP客户关系管理系统」· PHP 代码 · 共 751 行 · 第 1/2 页

PHP
751
字号
    function setConfigMD5 ()    {        if (file_exists ( $this->path . '/config.php' ))            $this->config_md5 = md5 ( base64_encode ( serialize ( $this->config ) ) ) ;    }    function build ($basepath)    {        $path = $basepath . '/modules/' . $this->key_name ;        if (mkdir_recursive ( $path ))        {            $this->createClasses ( $path ) ;            if( $this->config['importable'] )                $this->createMenu ( $path ) ;            $this->copyMetaRecursive ( $this->path . '/metadata/', $path . '/metadata/', true ) ;            $this->copyMetaRecursive ( $this->path . '/Dashlets/' . $this->key_name . 'Dashlet/',            						   $path . '/Dashlets/' . $this->key_name . 'Dashlet/', true ) ;            $this->relationships->build ( $basepath ) ;            $this->mblanguage->build ( $path ) ;        }    }    function createClasses ($path)    {        $class = array ( ) ;        $class [ 'name' ] = $this->key_name ;        $class [ 'table_name' ] = strtolower ( $class [ 'name' ] ) ;        $class [ 'extends' ] = 'Basic' ;        $class [ 'requires' ] [] = MB_TEMPLATES . '/basic/Basic.php' ;        $class [ 'requires' ] = array ( ) ;        $class [ 'audited' ] = (! empty ( $this->config [ 'audit' ] )) ? 'true' : 'false' ;        $class [ 'acl' ] = ! empty ( $this->config [ 'acl' ] ) ;        $class [ 'templates' ] = "'basic'" ;        foreach ( $this->iTemplate as $template )        {            if (! empty ( $this->config [ $template ] ))            {                $class [ 'templates' ] .= ",'$template'" ;            }        }        foreach ( $this->config [ 'templates' ] as $template => $a )        {            if ($template == 'basic')                continue ;            $class [ 'templates' ] .= ",'$template'" ;            $class [ 'extends' ] = ucFirst ( $template ) ;            $class [ 'requires' ] [] = MB_TEMPLATES . '/' . $template . '/' . ucfirst ( $template ) . '.php' ;        }        $class [ 'importable' ] = $this->config [ 'importable' ] ;        $this->mbvardefs->updateVardefs () ;        $class [ 'fields' ] = $this->mbvardefs->vardefs [ 'fields' ] ;        $class [ 'fields_string' ] = var_export_helper ( $this->mbvardefs->vardef [ 'fields' ] ) ;        $relationship = array ( ) ;        $class [ 'relationships' ] = var_export_helper ( $this->mbvardefs->vardef [ 'relationships' ] ) ;        $smarty = new Sugar_Smarty ( ) ;        $smarty->left_delimiter = '{{' ;        $smarty->right_delimiter = '}}' ;        $smarty->assign ( 'class', $class ) ;        //write sugar generated class
        $fp = sugar_fopen ( $path . '/' . $class [ 'name' ] . '_sugar.php', 'w' ) ;        fwrite ( $fp, $smarty->fetch ( 'modules/ModuleBuilder/tpls/MBModule/Class.tpl' ) ) ;        fclose ( $fp ) ;        //write vardefs
        $fp = sugar_fopen ( $path . '/vardefs.php', 'w' ) ;        fwrite ( $fp, $smarty->fetch ( 'modules/ModuleBuilder/tpls/MBModule/vardef.tpl' ) ) ;        fclose ( $fp ) ;        if (! file_exists ( $path . '/' . $class [ 'name' ] . '.php' ))        {            $fp = sugar_fopen ( $path . '/' . $class [ 'name' ] . '.php', 'w' ) ;            fwrite ( $fp, $smarty->fetch ( 'modules/ModuleBuilder/tpls/MBModule/DeveloperClass.tpl' ) ) ;            fclose ( $fp ) ;        }        if (! file_exists ( $path . '/metadata' ))            mkdir_recursive ( $path . '/metadata' ) ;        if (! empty ( $this->config [ 'studio' ] ))        {            $fp = sugar_fopen ( $path . '/metadata/studio.php', 'w' ) ;            fwrite ( $fp, $smarty->fetch ( 'modules/ModuleBuilder/tpls/MBModule/Studio.tpl' ) ) ;            fclose ( $fp ) ;        } else        {            if (file_exists ( $path . '/metadata/studio.php' ))                unlink ( $path . '/metadata/studio.php' ) ;        }        if (! file_exists ( $path . '/Forms.php' ))        {            $fp = sugar_fopen ( $path . '/Forms.php', 'w' ) ;            fclose ( $fp ) ;        }    }    function createMenu ($path)    {        $smarty = new Sugar_Smarty ( ) ;        $smarty->assign ( 'moduleName', $this->key_name ) ;        //write sugar generated class        $fp = sugar_fopen ( $path . '/' . 'Menu.php', 'w' ) ;        fwrite ( $fp, $smarty->fetch ( 'modules/ModuleBuilder/tpls/MBModule/Menu.tpl' ) ) ;        fclose ( $fp ) ;    }    function addInstallDefs (&$installDefs)    {        $name = $this->key_name ;        $installDefs [ 'copy' ] [] = array ( 'from' => '<basepath>/SugarModules/modules/' . $name , 'to' => 'modules/' . $name ) ;        $installDefs [ 'beans' ] [] = array ( 'module' => $name , 'class' => $name , 'path' => 'modules/' . $name . '/' . $name . '.php' , 'tab' => $this->config [ 'has_tab' ] ) ;        $this->relationships->addInstallDefs ( $installDefs ) ;    }    function getNodes ()    {        $lSubs = array ( ) ;        $psubs = $this->getProvidedSubpanels () ;        foreach ( $psubs as $sub )        {            $subLabel = $sub ;            if ($subLabel == 'default')            {                $subLabel = $GLOBALS [ 'mod_strings' ] [ 'LBL_DEFAULT' ] ;            }            $lSubs [] = array ( 'name' => $subLabel , 'type' => 'list' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=ListView&view_module=' . $this->name . '&view_package=' . $this->package . '&subpanel=' . $sub . '&subpanelLabel=' . $subLabel . '&local=1' ) ;        }        $searchSubs = array ( ) ;        $dashlets = array( );        $searchSubs [] = array ( 'name' => translate('LBL_BASIC_SEARCH') , 'type' => 'list' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=basic_search&view_module=' . $this->name . '&view_package=' . $this->package  ) ;        $searchSubs [] = array ( 'name' => translate('LBL_ADVANCED_SEARCH') , 'type' => 'list' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=advanced_search&view_module=' . $this->name . '&view_package=' . $this->package  ) ;        $dashlets [] = array('name' => translate('LBL_DASHLETLISTVIEW') , 'type' => 'dashlet' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=dashlet&view_module=' . $this->name . '&view_package=' . $this->package );		$dashlets [] = array('name' => translate('LBL_DASHLETSEARCHVIEW') , 'type' => 'dashletsearch' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=dashletsearch&view_module=' . $this->name . '&view_package=' . $this->package );        $layouts = array (        			 array ( 'name' => translate('LBL_EDITVIEW') , 'type' => 'edit' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=editView&view_module=' . $this->name . '&view_package=' . $this->package ) ,        			 array ( 'name' => $GLOBALS [ 'mod_strings' ] [ 'LBL_DETAILVIEW' ] , 'type' => 'detail' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=detailView&view_module=' . $this->name . '&view_package=' . $this->package ) ,        			 array ( 'name' => $GLOBALS [ 'mod_strings' ] [ 'LBL_LISTVIEW' ] , 'type' => 'list' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=ListView&view_module=' . $this->name . '&view_package=' . $this->package ) ,        			 array ( 'name' => translate('LBL_DASHLET') , 'type' => 'Folder', 'children' => $dashlets, 'action' => 'module=ModuleBuilder&MB=true&action=wizard&dashlet=1&view_module=' . $this->name . '&view_package=' . $this->package  ),        			 array ( 'name' => $GLOBALS [ 'mod_strings' ] [ 'LBL_SEARCH_FORMS' ] , 'action' => 'module=ModuleBuilder&MB=true&action=wizard&search=1&view_module=' . $this->name . '&view_package=' . $this->package , 'type' => 'folder' , 'children' => $searchSubs ) ) ;        $children = array (        	array ( 'name' => translate('LBL_FIELDS') , 'action' => 'module=ModuleBuilder&action=modulefields&view_module=' . $this->name . '&view_package=' . $this->package ) ,        	array ( 'name' => translate('LBL_LABELS') , 'action' => 'module=ModuleBuilder&action=modulelabels&view_module=' . $this->name . '&view_package=' . $this->package ) ,        	array ( 'name' => translate('LBL_RELATIONSHIPS') , 'action' => 'module=ModuleBuilder&action=relationships&view_module=' . $this->name . '&view_package=' . $this->package ) ,        	array ( 'name' => translate('LBL_LAYOUTS') , 'type' => 'Folder' , 'action' => 'module=ModuleBuilder&action=wizard&view_module=' . $this->name . '&view_package=' . $this->package . '&MB=1' , 'children' => $layouts ) ) ;        if (count ( $lSubs ) > 0)        {            $children [] = array ( 'name' => translate('LBL_AVAILABLE_SUBPANELS') , 'type' => 'folder' , 'children' => $lSubs ) ;        }        $nodes = array ( 'name' => $this->name , 'children' => $children , 'action' => 'module=ModuleBuilder&action=module&view_module=' . $this->name . '&view_package=' . $this->package ) ;        return $nodes ;    }    function getProvidedSubpanels ()    {        $this->providedSubpanels = array () ;                $subpanelDir = $this->getModuleDir () . '/metadata/subpanels/' ;        if (file_exists ( $subpanelDir ))        {            $f = dir ( $subpanelDir ) ;            while ( $g = $f->read () )            {                // sanity check to confirm that this is a usable subpanel...                require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationships.php' ;                if (substr ( $g, 0, 1 ) != '.' && AbstractRelationships::validSubpanel ( $subpanelDir . $g ))                {                    $subname = str_replace ( '.php', '', $g ) ;                    $this->providedSubpanels [ $subname ] = $subname ;                }            }        }                return $this->providedSubpanels;    }    function getTypes ()    {        $types = array ( ) ;        $d = dir ( MB_TEMPLATES ) ;        while ( $e = $d->read () )        {            if (substr ( $e, 0, 1 ) != '.')            {                $types [ $e ] = $e ;            }        }        return $types ;    }    function rename ($new_name)    {        $old = $this->getModuleDir () ;        $this->name = $new_name ;        $this->key_name = $this->package_key . '_' . $this->name ;        $new = $this->getModuleDir () ;        if (file_exists ( $new ))        {            return false ;        }        $renamed = rename ( $old, $new ) ;        if ($renamed)        {            $this->renameMetaData ( $new ) ;            $this->renameLanguageFiles ( $new ) ;        }        return $renamed ;    }    function renameLanguageFiles ($new_dir , $duplicate = false)    {        $this->mblanguage->name = $this->name ;        $this->mblanguage->path = $new_dir ;        $this->mblanguage->generateAppStrings () ;        $this->mblanguage->save ( $this->key_name, $duplicate ) ;    }    function renameMetaData ($new_dir)    {        $GLOBALS [ 'log' ]->debug ( 'MBModule.php->renameMetaData: new_dir=' . $new_dir ) ;        if (! file_exists ( $new_dir ))            return ;        $dir = dir ( $new_dir ) ;        while ( $e = $dir->read () )        {            if (substr ( $e, 0, 1 ) != '.')            {                if (is_dir ( $new_dir . '/' . $e ))                {                    $this->renameMetaData ( $new_dir . '/' . $e ) ;                }                if (is_file ( $new_dir . '/' . $e ))                {                    $contents = file_get_contents ( $new_dir . '/' . $e ) ;                    $contents = preg_replace ( '/(\$module_name[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . $this->key_name . '$3', $contents ) ;                    $contents = preg_replace ( '/(\$_module_name[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . strtolower ( $this->key_name ) . '$3', $contents ) ;                    $contents = preg_replace ( '/(\$MODULE_NAME[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . strtoupper ( $this->key_name ) . '$3', $contents ) ;                    $contents = preg_replace ( '/(\$object_name[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . $this->key_name . '$3', $contents ) ;                    $contents = preg_replace ( '/(\$_object_name[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . strtolower ( $this->key_name ) . '$3', $contents ) ;                    $contents = preg_replace ( '/(\$OBJECT_NAME[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . strtoupper ( $this->key_name ) . '$3', $contents ) ;                    $fp = sugar_fopen ( $new_dir . '/' . $e, 'w' ) ;                    fwrite ( $fp, $contents ) ;                    fclose ( $fp ) ;                }            }        }    }    function copy ($new_name)    {        $old = $this->getModuleDir () ;        $count = 0 ;        $this->name = $new_name ;        $this->key_name = $this->package_key . '_' . $this->name ;        $new = $this->getModuleDir () ;        while ( file_exists ( $new ) )        {            $count ++ ;            $this->name = $new_name . $count ;            $this->key_name = $this->package_key . '_' . $this->name ;            $new = $this->getModuleDir () ;        }        $new = $this->getModuleDir () ;        $copied = copy_recursive ( $old, $new ) ;        if ($copied)        {            $this->renameMetaData ( $new ) ;            $this->renameLanguageFiles ( $new, true ) ;        }        return $copied ;    }    function delete ()    {        return rmdir_recursive ( $this->getModuleDir () ) ;    }    function populateFromPost ()    {        foreach ( $this->implementable as $key => $value )        {            $this->config [ $key ] = ! empty ( $_REQUEST [ $key ] ) ;        }        foreach ( $this->always_implement as $key => $value )        {            $this->config [ $key ] = true ;        }        if (! empty ( $_REQUEST [ 'type' ] ))        {            $this->addTemplate ( $_REQUEST [ 'type' ] ) ;        }        if (! empty ( $_REQUEST [ 'label' ] ))        {            $this->config [ 'label' ] = $_REQUEST [ 'label' ] ;        }        $this->config [ 'importable' ] = ! empty( $_REQUEST[ 'importable' ] ) ;    }    function getAvailibleSubpanelDef ($panelName)    {        $filepath = $this->getModuleDir () . "/metadata/subpanels/{$panelName}.php" ;        if (file_exists ( $filepath ))        {            include ($filepath) ;            return $subpanel_layout ;        }        return array ( ) ;    }    function saveAvailibleSubpanelDef ($panelName , $layout)    {        $dir = $this->getModuleDir () . "/metadata/subpanels" ;        $filepath = "$dir/{$panelName}.php" ;        if (mkdir_recursive ( $dir ))        {            // preserve any $module_name entry if one exists
            if (file_exists ( $filepath ))            {                include ($filepath) ;            }            $module_name = (isset ( $module_name )) ? $module_name : $this->key_name ;            $layout = "<?php\n" . '$module_name=\'' . $module_name . "';\n" . '$subpanel_layout = ' . var_export_helper ( $layout ) . ";" ;            $GLOBALS [ 'log' ]->debug ( "About to save this file to $filepath" ) ;            $GLOBALS [ 'log' ]->debug ( $layout ) ;            $fw = sugar_fopen ( $filepath, 'w' ) ;            fwrite ( $fw, $layout ) ;            fclose ( $fw ) ;        }    }    function getLocalSubpanelDef ($panelName)    {    }    function createIcon ()    {        $icondir = $this->package_path . "/icons" ;        mkdir_recursive ( $icondir ) ;        $template = "" ;        foreach ( $this->config [ 'templates' ] as $temp => $val )            $template = $temp ;        copy ( "themes/default/images/icon_$template.gif", "$icondir/icon_" . ucfirst ( $this->key_name ) . ".gif" ) ;        copy ( "include/SugarObjects/templates/$template/icons/$template.gif", "$icondir/" . $this->key_name . ".gif" ) ;        if (file_exists("include/SugarObjects/templates/$template/icons/Create$template.gif"))        	copy ( "include/SugarObjects/templates/$template/icons/Create$template.gif", "$icondir/Create" . $this->key_name . ".gif" ) ;        if (file_exists("include/SugarObjects/templates/$template/icons/{$template}_32.gif"))        	copy ( "include/SugarObjects/templates/$template/icons/{$template}_32.gif", "$icondir/icon_" . $this->key_name . "_32.gif" ) ;    }}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?