⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studioparser.php

📁 CRM全套解决方案,全部源代码,支持简体中文
💻 PHP
📖 第 1 页 / 共 2 页
字号:
}

function handleSaveLabels($module_name, $language){
    $the_strings = return_module_language($language, $module_name);
    foreach($_REQUEST as $key=>$value){
        if(substr_count($key, 'label_') == 1 && strcmp($value, 'no_change') != 0){
            $key = substr($key, 6);
            //if(isset($the_strings[$key])){
                create_field_label($module_name, $language, $key, $value, true);
            //}
        }
    }
}

/**
	 * UTIL FUNCTIONS
	 */
/**
	 * STATIC FUNCTION DISABLE INPUTS IN AN HTML STRING
	 * 
	 */
function disableInputs($str) {
    $match = array ("'(<input)([^>]*>)'si" => "\$1 disabled readonly $2",
    "'(<input)([^>]*?type[ ]*=[ ]*[\'\"]submit[\'\"])([^>]*>)'si" => "\$1 disabled readonly style=\"display:none\" $2",
     "'(<select)([^>]*)'si" => "\$1 disabled readonly $2",
    // "'<a .*>(.*)</a[^>]*>'siU"=>"\$1",
"'(href[\ ]*=[\ ]*)([\'])([^\']*)([\'])'si" => "href=\$2javascript:void(0);\$2 alt=\$2\$3\$2", "'(href[\ ]*=[\ ]*)([\"])([^\"]*)([\"])'si" => "href=\$2javascript:void(0)\$2 title=\$2\$3\$2");
    return preg_replace(array_keys($match), array_values($match), $str);
}

function enableLabelEditor($str) {
    global $image_path;
    $image = get_image($image_path . 'edit_inline', "onclick='studiojs.handleLabelClick(\"$2\", 1);' onmouseover='this.style.cursor=\"default\"'");
    $match = array ("'>[^<]*\{(MOD.)([^}]*)\}'si" => "$image<span id='label$2' onclick='studiojs.handleLabelClick(\"$2\", 2);' >\{$1$2}</span><span id='span$2' style='display:none'><input type='text' id='$2' name='$2' msi='label' value='\{$1$2}' onblur='studiojs.endLabelEdit(\"$2\")'></span>");
    $keys = array_keys($match);
    $matches = array();
    preg_match_all($keys[0], $str, $matches, PREG_SET_ORDER);
    foreach($matches as $labelmatch){
        $label_name = 'label_' . $labelmatch[2];
        $this->form .= "\n<input type='hidden' name='$label_name'  id='$label_name' value='no_change'>";

    }
    return preg_replace(array_keys($match), array_values($match), $str);
}



function writeToCache($file, $view, $preview_file=false) {
    if (!is_writable($file)) {
        echo "<br><span style='color:red'>Warning: $file is not writeable. Please make sure it is writeable before continuing</span><br><br>";
    }
	
    if(!$preview_file){
        $file_cache = create_cache_directory('studio/'.$file);
    }else{
        $file_cache = create_cache_directory('studio/'.$preview_file);
    }
    $fp = fopen($file_cache, 'w');
    $view = $this->disableInputs($view);
    if(!$preview_file){
        $view = $this->enableLabelEditor($view);
    }
    fwrite($fp, $view);
    fclose($fp);
    return $this->cacheXTPL($file, $file_cache, $preview_file);
}

function populateRequestFromBuffer($file) {
    $results = array ();
    $temp = fopen($file, 'r');
    $buffer = fread($temp, filesize($file));
    fclose($temp);
    preg_match_all("'name[\ ]*=[\ ]*[\']([^\']*)\''si", $buffer, $results);
    $res = $results[1];
    foreach ($res as $r) {
        $_REQUEST[$r] = $r;
    }
    preg_match_all("'name[\ ]*=[\ ]*[\"]([^\"]*)\"'si", $buffer, $results);
    $res = $results[1];
    foreach ($res as $r) {
        $_REQUEST[$r] = $r;
    }

    $_REQUEST['query'] = true;
    $_REQUEST['advanced'] = true;

}
function cacheXTPL($file, $cache_file, $preview_file = false) {
    global $beanList;
    //now if we have a backup_file lets use that instead of the original
    if($preview_file){
        $file  = $preview_file;
    }
    
    if(!isset($the_module))$the_module = $_SESSION['studio']['module'];
	$files = StudioParser::getFiles($the_module);
	$xtpl = $files[$_SESSION['studio']['selectedFileId']]['php_file'];
	$originalFile = $files[$_SESSION['studio']['selectedFileId']]['template_file'];
	$type = StudioParser::getFileType($files[$_SESSION['studio']['selectedFileId']]['type']);
    $xtpl_fp = fopen($xtpl, 'r');
    $buffer = fread($xtpl_fp, filesize($xtpl));
    fclose($xtpl_fp);
    $cache_file = create_cache_directory('studio/'.$file);
    $xtpl_cache = create_cache_directory('studio/'.$xtpl);
    $module = $this->workingModule;

    $form_string = "require_once('modules/".$module."/Forms.php');";
   
    if ($type == 'edit' || $type == 'detail') {
        if (empty ($_REQUEST['record'])) {
            $buffer = preg_replace('(\$xtpl[\ ]*=)', "\$focus->assign_display_fields('$module'); \$0", $buffer);
        } else {
            $buffer = preg_replace('(\$xtpl[\ ]*=)', "\$focus->retrieve('".$_REQUEST['record']."');\n\$focus->assign_display_fields('$module');\n \$0", $buffer);
        }
    }
    $_REQUEST['query'] = true;
    if (substr_count($file, 'SearchForm') > 0) {
        $temp_xtpl = new XTemplate($file);
        if ($temp_xtpl->exists('advanced')) {

            global $current_language, $beanFiles, $beanList;
            $mods = return_module_language($current_language, 'DynamicLayout');
            $class_name = $beanList[$module];
            require_once ($beanFiles[$class_name]);
            $mod = new $class_name ();

            $this->populateRequestFromBuffer($file);
            $mod->assign_display_fields($module);
            $buffer = str_replace(array ('echo $lv->display();','$search_form->parse("advanced");', '$search_form->out("advanced");', '$search_form->parse("main");', '$search_form->out("main");'), '', $buffer);
            $buffer = str_replace('echo get_form_footer();', '$search_form->parse("main");'."\n".'$search_form->out("main");'."\necho '<br><b>".translate('LBL_ADVANCED', 'DynamicLayout')."</b><br>';".'$search_form->parse("advanced");'."\n".'$search_form->out("advanced");'."\necho get_form_footer();\n \$sugar_config['list_max_entries_per_page'] = 1;", $buffer);
        }
    }else{
    	
    	 if ($type == 'detail') {
        $buffer = str_replace('header(', 'if(false) header(', $buffer);
    }
    }

    $buffer = str_replace($originalFile, $cache_file, $buffer);
    $buffer = "<?php\n\$sugar_config['list_max_entries_per_page'] = 1;\n ?>".$buffer;

    $buffer = str_replace($form_string, '', $buffer);
    $buffer = $this->disableInputs($buffer);
    $xtpl_fp_cache = fopen($xtpl_cache, 'w');
    fwrite($xtpl_fp_cache, $buffer);
    fclose($xtpl_fp_cache);
    return $xtpl_cache;
}

/**
	 * Yahoo Drag & Drop Support
	 */
////<script type="text/javascript" src="modules/Studio/studio.js" ></script>
function yahooJS() {
    $custom_module = $_SESSION['studio']['module'];
    $custom_type = $this->curType;
    return<<<EOQ
	 	<style type='text/css'>
.slot {
	border-width:1px;border-color:#999999;border-style:solid;padding:0px 1px 0px 1px;margin:2px;cursor:move;

}

.slotB {
	border-width:0;cursor:move;

}
</style>

<!-- Namespace source file -->
		
			<script type="text/javascript" src="modules/Studio/JSTransaction.js" ></script>
			<script>
			var jstransaction = new JSTransaction();
			</script>
			
			<!-- Drag and Drop source file -->
			<script src = "include/javascript/yui/dragdrop.js" ></script>
				 	
			<script type="text/javascript" src="modules/Studio/studiodd.js" ></script>	
			<script type="text/javascript" src="modules/Studio/studio.js" ></script>	
			<script>
			
			var gLogger = new ygLogger("Studio");
		    

			 var yahooSlots = [];
			function dragDropInit(){
			
					if (typeof(ygLogger) != "undefined") {
				//ygLogger.init(document.getElementById("logDiv"));
			}
				YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
				
				 gLogger.debug("point mode");
				for(mj = 0; mj <= $this->yahooSlotCount; mj++){
					yahooSlots["slot" + mj] = new ygDDSlot("slot" + mj, "studio");
				}
				for(mj = 0; mj < dyn_field_count; mj++){
					yahooSlots["dyn_field_" + mj] = new ygDDSlot("dyn_field_" + mj, "studio");
				}
				  // initPointMode();
				  yahooSlots['s_field_delete'] =  new YAHOO.util.DDTarget("s_field_delete", 'studio');
			}
			YAHOO.util.Event.addListener(window, "load", dragDropInit);
			var custom_module = '$custom_module';
			var custom_view = '$custom_type';
			
			</script>			
			
EOQ;

}

/**
	 * delete:-1
	 * add:2000
	 * swap: 0 - 1999
	 *
	 */
function addSlotToForm($slot_count, $display_count){
    $this->form .= "\n<input type='hidden' name='slot_$slot_count'  id='slot_$display_count' value='$slot_count'>";
}
function prepSlots() {
    $view = $this->curText;
    $counter = 0;
    $return_view = '';
    $slotCount = 0;
    for ($i = 0; $i < sizeof($this->positions); $i ++) {
        $slot = $this->positions[$i];
        $class = '';
      
        if (empty($this->positions[$i][3])) {
            $slotCount ++;
            $class = " class='slot' ";
             $displayCount = $slotCount. $this->positions[$i][3];
            $this->addSlotToForm($slotCount, $displayCount);
        }else{
        	  $displayCount = $slotCount. $this->positions[$i][3];
        }	


        $explode = explode($slot[0], $view, 2);
        $style = '';
        $explode[0] .= "<div id = 'slot$displayCount'  $class style='cursor: move$style'>";
        $explode[1] = "</div>".$explode[1];
        $return_view .= $explode[0].$slot[4];
        $view = $explode[1];
        $counter ++;
    }
    $this->yahooSlotCount = $slotCount;
    $newView = $return_view.$view;
    $newView = str_replace(array ('<slot>', '</slot>'), array ('', ''), $newView);

    return $newView;
}



function clearWorkingDirectory(){

     $file = 'custom/working/';
      if(file_exists($file)){
      	
            rmdir_recursive($file);
        }
       
        return true;
    
}


/**
	 * UPGRADE TO SMARTY
	 */
function upgradeToSmarty() {
    return str_replace('{', '{$', $this->curText);
}
}
?>

⌨️ 快捷键说明

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