Spaces:
Sleeping
Sleeping
File size: 28,538 Bytes
07c3cdd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | <?php
/**
* class.headPublisher.php
*
* @package gulliver.system
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public LicensegetExtJsLibraries
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
use ProcessMaker\Plugins\PluginRegistry;
/**
* Class headPublisher
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @package gulliver.system
* @access public
*/
class headPublisher
{
public static $instance = null;
public $scriptFiles = array();
public $cssFiles = array();
public $leimnudLoad = array();
/* extJsSkin init coreLoad flag */
public $extJsInit = 'false';
/* extJsSkin store the current skin for the ExtJs */
public $extJsSkin = '';
/* extJsScript Array, to store the file to be include */
public $extJsScript = array();
/* extJsLibrary Array, to store extended ExtJs lybraries */
public $extJsLibrary = array();
/* extJsContent Array, to store the file to be include in the skin content */
public $extJsContent = array();
/* extVariable array, to store the variables generated in PHP, and used in JavaScript */
public $extVariable = array();
/* variable array, to store the variables generated in PHP, and used in JavaScript */
public $vars = array();
/* tplVariable array, to store the variables for template power */
public $tplVariable = array();
public $translationsFile;
public $leimnudInitString = ' var leimnud = new maborak();
leimnud.make({
zip:true,
inGulliver:true,
modules :"dom,abbr,rpc,drag,drop,app,panel,fx,grid,xmlform,validator,dashboard",
files :""
});';
public $headerScript = '
try{
leimnud.exec(leimnud.fix.memoryLeak);
if(leimnud.browser.isIphone){
leimnud.iphone.make();
}
}catch(e){}';
public $disableHeaderScripts = false;
public $title = '';
/**
* Function headPublisher
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
public function __construct()
{
$this->addScriptFile("/js/maborak/core/maborak.js");
$this->translationsFile = "/js/ext/translation." . SYS_LANG . ".js";
$this->addScriptCode(' var __usernameLogged__ = "' . (isset($_SESSION['USR_USERNAME']) ? $_SESSION['USR_USERNAME'] : '') . '";var SYS_LANG = "' . SYS_LANG . '";');
}
public function &getSingleton()
{
if (self::$instance == null) {
self::$instance = new headPublisher();
}
return self::$instance;
}
/**
* Function setTitle
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string url
* @param eter string LoadType
* @return string
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Function addScriptFile
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string url
* @param eter string LoadType
* @return string
*/
public function addScriptFile($url, $LoadType = 1)
{
if ($LoadType == 1) {
$this->scriptFiles[$url] = $url;
}
if ($LoadType == 2) {
$this->leimnudLoad[$url] = $url;
}
}
public function addCssFile($url)
{
$this->cssFiles[$url] = $url;
}
/**
* Function addInstanceModule
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string instance
* @param eter string module
* @return string
*/
public function addInstanceModule($instance, $module)
{
$this->headerScript .= "leimnud.Package.Load('" . $module . "',{Instance:" . $instance . ",Type:'module'});\n";
}
/**
* Function addClassModule
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string class
* @param eter string module
* @return string
*/
public function addClassModule($class, $module)
{
$this->headerScript .= "leimnud.Package.Load('" . $module . "',{Class:" . $class . ",Type:'module'});\n";
}
/**
* Function addScriptCode
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param eter string script
* @return string
*/
public function addScriptCode($script)
{
$this->headerScript .= $script;
}
/**
* Function printHeader
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
public function printHeader()
{
$jslabel = 'labels/en.js';
if (defined('SYS_LANG')) {
$jslabel = 'labels' . PATH_SEP . SYS_LANG . '.js';
if (!file_exists(PATH_CORE . 'js' . PATH_SEP . $jslabel)) {
$jslabel = 'labels/en.js';
}
}
if (file_exists(PATH_CORE . 'js' . PATH_SEP . $jslabel)) {
$this->addScriptFile('/jscore/' . $jslabel, 1);
}
if ($this->disableHeaderScripts) {
return '';
}
// available js-calendar languages array
$availableJsCalendarLang = array('ca', 'cn', 'cz', 'de', 'en', 'es', 'fr', 'it', 'jp', 'nl', 'pl', 'pt', 'ro', 'ru', 'sv');
// get the system language without locale
$sysLang = explode('-', SYS_LANG);
$sysLang = $sysLang[0];
// verify if the requested lang by the system is supported by js-calendar library, if not set english by default
$sysLang = in_array($sysLang, $availableJsCalendarLang) ? $sysLang : 'en';
$this->addScriptFile("/js/widgets/js-calendar/unicode-letter.js");
//$this->addScriptFile( "/js/widgets/js-calendar/lang/" . $sysLang . ".js" );
$head = '';
$head .= '<TITLE>' . $this->title . "</TITLE>\n";
foreach ($this->cssFiles as $file) {
$head = $head . " <link rel=\"stylesheet\" href=\"" . G::browserCacheFilesUrl($file) . "\">\n";
}
$head = $head . "
<!--//////////////////////////////////********//////////////////////////////////-->
<noscript>
<div>
". G::LoadTranslation( 'ID_ERROR_JS_NOT_AVAILABLE' )."
</div>
</noscript>
<!--//////////////////////////////////********//////////////////////////////////-->
<script type=\"text/javascript\">
var BROWSER_CACHE_FILES_UID = \"" . G::browserCacheFilesGetUid() . "\";
</script>
";
foreach ($this->scriptFiles as $file) {
$head = $head . "<script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl($file) . "\"></script>\n";
}
if (!in_array($this->translationsFile, $this->scriptFiles)) {
$head = $head . "<script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl($this->translationsFile) . "\"></script>\n";
}
$head .= "<script type='text/javascript'>\n";
$head .= $this->leimnudInitString;
foreach ($this->leimnudLoad as $file) {
$head .= " leimnud.Package.Load(false, {Type: 'file', Path: '" . $file . "', Absolute : true});\n";
}
$head .= $this->headerScript;
$head .= "</script>\n";
$head .= "<script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/maborak/core/maborak.loader.js") . "\"></script>\n";
return $head;
}
/**
* Function printRawHeader
* Its prupose is to load el HEADs initialization javascript
* into a single SCRIPT tag, it is usefull when it is needed
* to load a page by leimnud floating panel of by another ajax
* method. (See also RAW skin)
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
public function printRawHeader()
{
$jslabel = '/jscore/labels/en.js';
if (defined('SYS_LANG')) {
$jslabel1 = 'labels' . PATH_SEP . SYS_LANG . '.js';
if (!file_exists(PATH_CORE . 'js' . PATH_SEP . $jslabel1)) {
$jslabel = '/jscore/labels/en.js';
}
}
$head = '';
//$head .= "<script language='javascript'>\n";
foreach ($this->scriptFiles as $file) {
if (($file != "/js/maborak/core/maborak.js") && ($file != $jslabel)) {
$head = $head . " eval(ajax_function(\"" . G::browserCacheFilesUrl($file) . "\", \"\", \"\"));\n";
}
}
foreach ($this->leimnudLoad as $file) {
$head .= " eval(ajax_function('" . $file . "','',''));\n";
}
//Adapts the add events on load to simple javascript sentences.
$this->headerScript = preg_replace('/\s*leimnud.event.add\s*\(\s*window\s*,\s*(?:\'|")load(?:\'|")\s*,\s*function\(\)\{(.+)\}\s*\)\s*;?/', '$1', $this->headerScript);
$head .= $this->headerScript;
//$head .= "</script>\n";
return $head;
}
/**
* Function clearScripts
* Its prupose is to clear all the scripts of the header.
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @return string
*/
public function clearScripts()
{
$this->scriptFiles = array();
$this->leimnudLoad = array();
$this->leimnudInitString = '';
$this->headerScript = '';
}
/**
* Function includeExtJs
* with this function we are using the ExtJs library, this library is not compatible with
* previous libraries, for that reason oHeadPublisher will clear previous libraries like maborak
* we need to check if we need the language file
* this function returns the header needed to render a page using ExtJs
*
* @author Fernando Ontiveros <fernando@colosa.com>
* @access public
* @return string
*/
public function includeExtJs()
{
$this->clearScripts();
$head = "";
$head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/ext-base.js") . "\"></script>\n";
$head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/ext-all.js") . "\"></script>\n";
$head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/jscore/src/PM.js") . "\"></script>\n";
$head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/jscore/src/Sessions.js") . "\"></script>\n";
if (SYS_LANG != 'en') {
$tempLang = str_replace('-', '_', SYS_LANG);
if (file_exists(PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'ext' . PATH_SEP . 'locale' . PATH_SEP . 'ext-lang-' . $tempLang . '.js')) {
$head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/locale/ext-lang-" . $tempLang . ".js") . "\"></script>\n";
} else {
$aux = explode('-', strtolower(SYS_LANG));
if (file_exists(PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'ext' . PATH_SEP . 'locale' . PATH_SEP . 'ext-lang-' . $aux[0] . '.js')) {
$head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/locale/ext-lang-" . $aux[0] . ".js") . "\"></script>\n";
}
}
}
// enabled for particular use
$head .= $this->getExtJsLibraries();
// $head .= " <script type='text/javascript' src='/js/ext/draw2d.js'></script>\n";
// $head .= " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/translation." . SYS_LANG . ".js") . "\"></script>\n";
if (!isset($this->extJsSkin) || $this->extJsSkin == '') {
$this->extJsSkin = 'xtheme-gray';
//$this->extJsSkin = 'gtheme';
}
//$head .= $this->getExtJsStylesheets();
$head .= $this->getExtJsScripts();
$head .= $this->getExtJsVariablesScript();
$oServerConf = & ServerConf::getSingleton();
if ($oServerConf->isRtl(SYS_LANG)) {
$head = $head . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/extjs_rtl.js") . "\"></script>\n";
}
return $head;
}
public function getExtJsStylesheets($skinName)
{
$script = " <link rel='stylesheet' type='text/css' href='/css/$skinName.css' />\n";
//$script .= " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/translation." . SYS_LANG . ".js") . "\"></script>\n";
/*
$script .= " <link rel='stylesheet' type='text/css' href='/skins/ext/ext-all-notheme.css' />\n";
$script .= " <link rel='stylesheet' type='text/css' href='/skins/ext/" . $this->extJsSkin.".css' />\n";
// <!-- DEPRECATED, this will be removed in a future - the three next lines
if (file_exists ( PATH_HTML . 'skins' . PATH_SEP . 'ext' . PATH_SEP . 'pmos-' . $this->extJsSkin . '.css' )) {
$script .= " <link rel='stylesheet' type='text/css' href='/skins/ext/pmos-" . $this->extJsSkin . ".css' />\n";
}
//DEPRECATED, this will be removed in a future -->
//new interactive css decorator
$script .= " <link rel='stylesheet' type='text/css' href='/gulliver/loader?t=extjs-cssExtended&s=".$this->extJsSkin."' />\n";
$script .= " <link rel='stylesheet' type='text/css' href='/images/icons_silk/sprite.css' />\n";
*/
// Load external/plugin css
// NOTE is necesary to move this to decorator server
if (class_exists('ProcessMaker\Plugins\PluginRegistry') && !empty(config("system.workspace"))) {
$oPluginRegistry = PluginRegistry::loadSingleton();
$registeredCss = $oPluginRegistry->getRegisteredCss();
/** @var \ProcessMaker\Plugins\Interfaces\CssFile $cssFile */
foreach ($registeredCss as $cssFile) {
$script .= " <link rel='stylesheet' type='text/css' href='" . $cssFile->getCssFile() . ".css' />\n";
}
}
return $script;
}
public function getExtJsScripts()
{
$script = '';
if (isset($this->extJsScript) && is_array($this->extJsScript)) {
foreach ($this->extJsScript as $key => $file) {
$script = $script . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl($file . ".js") . "\"></script>\n";
}
}
return $script;
}
public function getExtJsVariablesScript()
{
$script = '';
if (count($this->extVariable) > 0) {
$script = "<script language='javascript'>\n";
foreach ($this->extVariable as $key => $val) {
$name = $val['name'];
$value = $val['value'];
$variablesValues = G::json_encode($value);
$variablesValues = $this->stripCodeQuotes($variablesValues);
// var_dump($variablesValues);
// echo "<br>";
$script .= " var $name = " . $variablesValues . ";\n";
/*
if ($val ['type'] == 'number')
$script .= " var $name = $value;\n";
else
$script .= " var $name = '$value';\n";
*/
}
$script .= "</script>\n";
}
return $script;
}
public function getExtJsLibraries()
{
$script = '';
if (isset($this->extJsLibrary) && is_array($this->extJsLibrary)) {
foreach ($this->extJsLibrary as $file) {
$script = $script . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/ext/" . $file . ".js") . "\"></script>\n";
}
}
if (!in_array($this->translationsFile, $this->extJsLibrary)) {
$script = $script . " <script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl($this->translationsFile) . "\"></script>\n";
}
return $script;
}
/**
* add a ExtJS extended library
*
* @author Erik A. Ortiz <erik@colosa.com>
* @access public
* @param (String) http js path library
* @return none
*/
public function usingExtJs($library)
{
if (!is_string($library)) {
throw new Exception('headPublisher::usingExt->ERROR - the parameter should be a js path string');
}
array_push($this->extJsLibrary, $library);
}
/**
* Function setExtSkin
*
* @author Fernando Ontiveros <fernando@colosa.com>
* @access public
* @return string
*/
public function setExtSkin($skin)
{
$this->extJsSkin = $skin;
}
/**
* Function addExtJsScript
* adding a javascript file .
*
* js
* add a js file in the extension Javascript Array,
* later, when we use the includeExtJs function, all the files in this array will be included in the output
* if the second argument is true, the file will not be minified, this is useful for debug purposes.
*
* Feature added - <erik@colosa.com>
* - Hook to find javascript registered from plugins and load them
*
* @author Fernando Ontiveros <fernando@colosa.com>
* @author Erik Amaru Ortiz <erik@colosa.com>
* @access public
* @return string
*/
public function addExtJsScript($filename, $debug = false, $isExternal = false)
{
$sPath = PATH_TPL;
//if the template file doesn't exists, then try with the plugins folders
if (!is_file($sPath . $filename . ".js")) {
$aux = explode(PATH_SEP, $filename);
//check if G_PLUGIN_CLASS is defined, because publisher can be called without an environment
if (count($aux) > 1 && defined('G_PLUGIN_CLASS')) {
$flagPlugin = false;
$keyPlugin = count($aux)-2;
$oPluginRegistry = PluginRegistry::loadSingleton();
if ($oPluginRegistry->isRegisteredFolder($aux[$keyPlugin])) {
$flagPlugin = true;
} else {
$keyPlugin --;
if ($oPluginRegistry->isRegisteredFolder($aux[$keyPlugin])) {
$flagPlugin = true;
}
}
if ($flagPlugin) {
array_push($this->extJsLibrary, 'translation.' . trim($aux[$keyPlugin]) . '.' . SYS_LANG);
$sPath = PATH_PLUGINS;
}
}
}
if (!$isExternal) {
$jsFilename = $sPath . $filename . '.js';
} else {
$jsFilename = $filename . '.js';
}
if (!file_exists($jsFilename)) {
return;
}
$mtime = filemtime($jsFilename);
G::mk_dir(PATH_C . 'ExtJs');
if ($debug) {
$cacheName = str_replace('/', '_', $filename);
$cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $cacheName . '.js';
file_put_contents($cacheFilename, file_get_contents($jsFilename));
} else {
$cacheName = G::encryptOld($mtime . $jsFilename);
$cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $cacheName . '.js';
if (!file_exists($cacheFilename)) {
$content = JSMin::minify(file_get_contents($jsFilename));
file_put_contents($cacheFilename, $content);
}
}
$this->extJsScript[] = '/extjs/' . $cacheName;
//hook for registered javascripts from plugins
if (class_exists('ProcessMaker\Plugins\PluginRegistry') && !empty(config("system.workspace"))) {
$oPluginRegistry = PluginRegistry::loadSingleton();
$pluginJavascripts = $oPluginRegistry->getRegisteredJavascriptBy($filename);
} else {
$pluginJavascripts = array();
}
if (count($pluginJavascripts) > 0) {
if ($debug) {
foreach ($pluginJavascripts as $pluginJsFile) {
$jsPluginCacheName = '';
if (substr($pluginJsFile, - 3) != '.js') {
$pluginJsFile .= '.js';
}
if (file_exists(PATH_PLUGINS . $pluginJsFile)) {
$jsPluginCacheName = str_replace('/', '_', str_replace('.js', '', $pluginJsFile));
$cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $jsPluginCacheName . ".js";
file_put_contents($cacheFilename, file_get_contents(PATH_PLUGINS . $pluginJsFile));
}
if ($jsPluginCacheName != '') {
$this->extJsScript[] = '/extjs/' . $jsPluginCacheName;
}
}
} else {
foreach ($pluginJavascripts as $pluginJsFile) {
$jsPluginCacheName = '';
if (substr($pluginJsFile, - 3) !== '.js') {
$pluginJsFile .= '.js';
}
if (file_exists(PATH_PLUGINS . $pluginJsFile)) {
$mtime = filemtime(PATH_PLUGINS . $pluginJsFile);
$jsPluginCacheName = G::encryptOld($mtime . $pluginJsFile);
$cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $jsPluginCacheName . '.js';
if (!file_exists($cacheFilename)) {
$content = JSMin::minify(file_get_contents(PATH_PLUGINS . $pluginJsFile));
file_put_contents($cacheFilename, $content);
}
}
if ($jsPluginCacheName != '') {
$this->extJsScript[] = '/extjs/' . $jsPluginCacheName;
}
}
}
}
//end hook for registered javascripts from plugins
}
/**
* Function AddContent
* adding a html file .
*
* html.
* the main idea for this function, is to be a replacement to homonymous function in Publisher class.
* with this function you are adding Content to the output, the class HeadPublisher will maintain a list of
* files to render in the body of the output page
*
* @author Fernando Ontiveros <fernando@colosa.com>
* @access public
* @return string
*/
public function AddContent($templateHtml)
{
$this->extJsContent[] = $templateHtml;
}
public function getContent()
{
return $this->extJsContent;
}
/**
* Function assign
* assign a STRING value to a JS variable
* use this function to send from PHP variables to be used in JavaScript
*
* @author Fernando Ontiveros <fernando@colosa.com>
* @access public
* @return string
*/
public function Assign($variable, $value)
{
$this->extVariable[] = array('name' => $variable, 'value' => $value, 'type' => 'string'
);
}
public function AssignVar($name, $value)
{
$this->vars[$name] = $value;
}
public function getVars()
{
return $this->vars;
}
/**
* Function assignNumber
* assign a Number value to a JS variable
* use this function to send from PHP variables to be used in JavaScript
*
* @author Fernando Ontiveros <fernando@colosa.com>
* @access public
* @return string
*/
public function AssignNumber($variable, $value)
{
$this->extVariable[] = array('name' => $variable, 'value' => $value, 'type' => 'number');
}
/**
* Function renderExtJs
* this function returns the content rendered using ExtJs
* extJsContent have an array, and we iterate this array to draw the content
*
* @author Fernando Ontiveros <fernando@colosa.com>
* @access public
* @return string
*/
public function renderExtJs()
{
$body = '';
if (isset($this->extJsContent) && is_array($this->extJsContent)) {
foreach ($this->extJsContent as $key => $file) {
$sPath = PATH_TPL;
//if the template file doesn't exists, then try with the plugins folders
if (!is_file($sPath . $file . ".html")) {
$aux = explode(PATH_SEP, $file);
//check if G_PLUGIN_CLASS is defined, because publisher can be called without an environment
if (count($aux) == 2 && defined('G_PLUGIN_CLASS')) {
$oPluginRegistry = PluginRegistry::loadSingleton();
if ($oPluginRegistry->isRegisteredFolder($aux[0])) {
$sPath = PATH_PLUGINS;
}
}
}
$template = new TemplatePower($sPath . $file . '.html');
$template->prepare();
foreach ($this->getVars() as $k => $v) {
$template->assign($k, $v);
}
$body .= $template->getOutputContent();
}
}
return $body;
}
public function stripCodeQuotes($sJson)
{
$fields = array("editor", "renderer"
);
foreach ($fields as $field) {
$pattern = '/"(' . $field . ')":"[a-zA-Z.()]*"/';
// echo $pattern."<br>";
preg_match($pattern, $sJson, $matches);
// var_dump ($matches);
// echo "<br>";
if (!empty($matches)) {
$rendererMatch = $matches[0];
$replaceBy = explode(":", $matches[0]);
$replaceBy[1] = str_replace('"', '', $replaceBy[1]);
$tmpString = implode(":", $replaceBy);
$sJson = str_replace($rendererMatch, $tmpString, $sJson);
// var_dump ($sJson);
// echo "<br>";
}
}
return $sJson;
}
/**
* Function disableHeaderScripts
* this function sets disableHeaderScripts to true
* to avoid print scripts into the header
*
* @author Enrique Ponce de Leom <enrique@colosa.com>
* @access public
* @return string
*/
public function disableHeaderScripts()
{
$this->disableHeaderScripts = true;
}
/**
* Gets an array that contains the status of the view.
*
* @return array $views
*/
public function getExtJsViewState()
{
$json = new stdClass();
$views = array();
$keyState = "extJsViewState";
$prefixExtJs = "ys-";
$oServerConf = &ServerConf::getSingleton();
$deleteCache = true;
$sjson = $oServerConf->getProperty($keyState);
if ($sjson !== "") {
$json = G::json_decode($sjson);
if ((is_array($json) || is_object($json)) && sizeof($json)){
foreach ($json as $key => $value) {
$views[$key] = $value;
}
}
}
$httpCookies = explode("; ", $_SERVER['HTTP_COOKIE']);
foreach ($httpCookies as $cookie) {
$value = explode("=", $cookie);
if (count($value) > 1 && substr($value[0], 0, 3) === $prefixExtJs) {
$deleteCache = false;
$key = substr($value[0], 3);
$views[$key] = $value[1];
}
}
if ((array)$json != $views) {
$oServerConf->setProperty($keyState, G::json_encode($views));
}
return $views;
}
}
|