📄 studioparser.php
字号:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* The contents of this file are subject to the SugarCRM Public License Version
* 1.1.3 ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* All copies of the Covered Code must include on each user interface screen:
* (i) the "Powered by SugarCRM" logo and
* (ii) the SugarCRM copyright notice
* in the same form as they appear in the distribution. See full license for
* requirements.
*
* The Original Code is: SugarCRM Open Source
* The Initial Developer of the Original Code is SugarCRM, Inc.
* Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.;
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
// $Id: StudioParser.php,v 1.17 2006/09/06 03:46:39 majed Exp $
require_once('include/utils/file_utils.php');
/**
* interface for studio parsers
*/
class StudioParser {
var $positions = array ();
var $rows = array ();
var $cols = array ();
var $curFile = '';
var $curText = '';
var $form;
var $labelEditor = true;
var $curType = 'detail';
var $fieldEditor = true;
function getFileType($type, $setType=true){
switch($type){
case 'EditView':
case 'SearchForm': $type= 'edit';break;
case 'ListView': $type= 'list';break;
default: $type= 'detail';
}
if($setType){
$this->curType = $type;
}
return $type;
}
function getParsers($file){
if(substr_count($file, 'DetailView.html') > 0 || substr_count($file, 'EditView.html' ) > 0) return array('default'=>'StudioParser', array('StudioParser', 'StudioRowParser'));
if(substr_count($file, 'ListView.html' ) > 0) return array('default'=>'XTPLListViewParser', array('XTPLListViewParser'));
return array('default'=>'StudioParser', array('StudioParser'));
}
function parseRows($str){
preg_match_all("'(<tr[^>]*)>(.*?)(</tr[^>]*>)'si", $str, $this->rows,PREG_SET_ORDER);
}
function getMaxPosition(){
$max = 0;
for($i = 0; $i < count($this->positions) ; $i++){
if($this->positions[$i][2] >= $max){
$max = $this->positions[$i][2] + 1;
}
}
return $max;
}
function parsePositions($str) {
preg_match_all("'<span[^>]*sugar=[\'\"]+([a-zA-Z\_]*)([0-9]+)([b]*)[\'\"]+[^>]*>(.*?)</span[ ]*sugar=[\'\"]+[a-zA-Z0-9\_]*[\'\"]+>'si", $str, $this->positions, PREG_SET_ORDER);
}
function parseCols($str){
preg_match_all("'(<td[^>]*?)>(.*?)(</td[^>]*?>)'si", $str, $this->cols,PREG_SET_ORDER);
}
function parse($str){
$this->parsePositions($str);
}
function positionCount($str) {
$result = array ();
return preg_match_all("'<span[^>]*sugar=[\'\"]+([a-zA-Z\_]*)([0-9]+)([b]*)[\'\"]+[^>]*>(.*?)</span[ ]*sugar=[\'\"]+[a-zA-Z0-9\_]*[\'\"]+>'si", $str, $result, PREG_SET_ORDER)/2;
}
function rowCount($str) {
$result = array ();
return preg_match_all("'(<tr[^>]*>)(.*?)(</tr[^>]*>)'si", $str, $result);
}
function loadFile($file) {
$this->curFile = $file;
$this->curText = file_get_contents($file);
$this->form = <<<EOQ
</form>
<form name='studio' method='POST'>
<input type='hidden' name='action' value='save'>
<input type='hidden' name='module' value='Studio'>
EOQ;
}
function buildImageButtons($buttons,$horizontal=true){
$text = '<table cellspacing=2><tr>';
foreach($buttons as $button){
if(!$horizontal){
$text .= '</tr><tr>';
}
if(!empty($button['plain'])){
$text .= <<<EOQ
<td valign='center' {$button['actionScript']}>
EOQ;
}else{
$text .= <<<EOQ
<td valign='center' class='button' style='cursor:default' onmousedown='this.className="buttonOn";return false;' onmouseup='this.className="button"' onmouseout='this.className="button"' {$button['actionScript']} >
EOQ;
}
$text .= "{$button['image']} {$button['text']}</td>";
}
$text .= '</tr></table>';
return $text;
}
function generateButtons(){
global $image_path;
$imageSave = get_image($image_path. 'studio_save', '');
$imagePublish = get_image($image_path. 'studio_publish', '');
$imageHistory = get_image($image_path. 'studio_history', '');
$imageAddRows = get_image($image_path.'studio_addRows', '');
$imageUndo = get_image($image_path.'studio_undo', '');
$imageRedo = get_image($image_path.'studio_redo', '');
$imageAddField = get_image($image_path. 'studio_addField', '');
$buttons = array();
$buttons[] = array('image'=>$imageUndo,'text'=>$GLOBALS['mod_strings']['LBL_BTN_UNDO'],'actionScript'=>"onclick='jstransaction.undo()'" );
$buttons[] = array('image'=>$imageRedo,'text'=>$GLOBALS['mod_strings']['LBL_BTN_REDO'],'actionScript'=>"onclick='jstransaction.redo()'" );
$buttons[] = array('image'=>$imageAddField,'text'=>$GLOBALS['mod_strings']['LBL_BTN_ADDCUSTOMFIELD'],'actionScript'=>"onclick='studiopopup.display();return false;'" );
$buttons[] = array('image'=>$imageAddRows,'text'=>$GLOBALS['mod_strings']['LBL_BTN_ADDROWS'],'actionScript'=>"onclick='if(!confirmNoSave())return false;document.location.href=\"index.php?module=Studio&action=EditLayout&parser=StudioRowParser\"'" ,);
$buttons[] = array('image'=>$imageAddRows,'text'=>$GLOBALS['mod_strings']['LBL_BTN_TABINDEX'],'actionScript'=>"onclick='if(!confirmNoSave())return false;document.location.href=\"index.php?module=Studio&action=EditLayout&parser=TabIndexParser\"'" ,);
$buttons[] = array('image'=>'', 'text'=>'-', 'actionScript'=>'', 'plain'=>true);
$buttons[] = array('image'=>$imageSave,'text'=>$GLOBALS['mod_strings']['LBL_BTN_SAVE'],'actionScript'=>"onclick='studiojs.save(\"studio\", false);'");
$buttons[] = array('image'=>$imagePublish,'text'=>$GLOBALS['mod_strings']['LBL_BTN_SAVEPUBLISH'],'actionScript'=>"onclick='studiojs.save(\"studio\", true);'");
$buttons[] = array('image'=>$imageHistory,'text'=>$GLOBALS['mod_strings']['LBL_BTN_HISTORY'],'actionScript'=>"onclick='if(!confirmNoSave())return false;document.location.href=\"index.php?module=Studio&action=wizard&wizard=ManageBackups&setFile={$_SESSION['studio']['selectedFileId']}\"'");
return $buttons;
}
function getFormButtons(){
$buttons = $this->generateButtons();
return $this->buildImageButtons($buttons);
}
function getForm(){
return $this->form . <<<EOQ
</form>
EOQ;
}
function getFiles($module, $fileId=false){
if(empty($GLOBALS['studioDefs'][$module])){
require_once('modules/'. $module . '/metadata/studio.php');
}
if($fileId){
return $GLOBALS['studioDefs'][$module][$fileId];
}
return $GLOBALS['studioDefs'][$module];
}
function getWorkingFile($file, $refresh = false){
$workingFile = 'working/' . $file;
$customFile = create_custom_directory($workingFile);
if($refresh || !file_exists($customFile)){
copy($file, $customFile);
}
return $customFile;
}
function getSwapWith($value){
return $value * 2 - 1;
}
function handleSave() {
$fileDef = $this->getFiles($_SESSION['studio']['module'], $_SESSION['studio']['selectedFileId']);
$type = $this->getFileType($fileDef['type']);
$view = $this->curText;
$counter = 0;
$return_view = '';
$slotCount = 0;
$slotLookup = array();
for ($i = 0; $i < sizeof($this->positions); $i ++) {
//used for reverse lookups to figure out where the associated slot is
$slotLookup[$this->positions[$i][2]][$this->positions[$i][3]] = array('position'=>$i, 'value'=>$this->positions[$i][4]);
}
$customFields = $this->focus->custom_fields->getAllBeanFieldsView($type, 'html');
//now we set it to the new values
for ($i = 0; $i < sizeof($this->positions); $i ++) {
$slot = $this->positions[$i];
if (empty($slot[3])) {
$slotCount ++;
//if the value in the request doesn't equal our current slot then something should be done
if(isset($_REQUEST['slot_'.$slotCount]) && $_REQUEST['slot_'.$slotCount] != $slotCount){
$swapValue = $_REQUEST['slot_'.$slotCount] ;
//if its an int then its a simple swap
if(is_numeric($swapValue)){
$swapWith = $this->positions[$this->getSwapWith($swapValue)];
//label
$slotLookup[$slot[2]]['']['value'] = $this->positions[ $slotLookup[$swapWith[2]]['']['position']][4];
//html
$slotLookup[$slot[2]]['b']['value'] = $this->positions[ $slotLookup[$swapWith[2]]['b']['position']][4];
}
//now check if its a delete action
if(strcmp('add:delete', $swapValue) == 0){
//label
$slotLookup[$slot[2]][$slot[3]]['value'] = ' ';
//html
$slotLookup[$slot[2]]['b']['value'] = ' ';
}else{
//now handle the adding of custom fields
if(substr_count($swapValue, 'add:')){
$addfield = explode('add:', $_REQUEST['slot_'.$slotCount], 2);
//label
$slotLookup[$slot[2]][$slot[3]]['value'] = $customFields[$addfield[1]]['label'] ;
//html
$slotLookup[$slot[2]]['b']['value'] = $customFields[$addfield[1]]['html'];
}
}
}
}
}
for ($i = 0; $i < sizeof($this->positions); $i ++) {
$slot = $this->positions[$i];
$explode = explode($slot[0], $view, 2);
$explode[0] .= "<span sugar='". $slot[1] . $slot[2]. $slot[3]. "'>";
$explode[1] = "</span sugar='" .$slot[1] ."'>".$explode[1];
$return_view .= $explode[0].$slotLookup[$slot[2]][$slot[3]]['value'];
$view = $explode[1];
$counter ++;
}
$return_view .= $view;
$this->saveFile('', $return_view);
return $return_view;
}
function saveFile($file = '', $contents = false) {
if (empty ($file)) {
$file = $this->curFile;
}
$fp = fopen($file, 'w');
if ($contents) {
fwrite($fp, $contents);
} else {
fwrite($fp, $this->curText);
}
fclose($fp);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -