/components/com_breezingforms/facileforms.process.php
PHP | 6664 lines | 5891 code | 594 blank | 179 comment | 1593 complexity | 4bbee968557cf120285e4689635c3aae MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT, LGPL-3.0, LGPL-2.0, JSON
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * BreezingForms - A Joomla Forms Application
- * @version 1.8
- * @package BreezingForms
- * @copyright (C) 2008-2012 by Markus Bopp
- * @license Released under the terms of the GNU General Public License
- * */
- defined('_JEXEC') or die('Direct Access to this location is not allowed.');
- class bfMobile {
- public $isMobile = false;
- }
- $mainframe = JFactory::getApplication();
- $ff_processor = null;
- define('_FF_PACKBREAKAFTER', 250);
- define('_FF_STATUS_OK', 0);
- define('_FF_STATUS_UNPUBLISHED', 1);
- define('_FF_STATUS_SAVERECORD_FAILED', 2);
- define('_FF_STATUS_SAVESUBRECORD_FAILED', 3);
- define('_FF_STATUS_UPLOAD_FAILED', 4);
- define('_FF_STATUS_SENDMAIL_FAILED', 5);
- define('_FF_STATUS_ATTACHMENT_FAILED', 6);
- define('_FF_STATUS_CAPTCHA_FAILED', 7);
- define('_FF_STATUS_FILE_EXTENSION_NOT_ALLOWED', 8);
- define('_FF_DATA_ID', 0);
- define('_FF_DATA_NAME', 1);
- define('_FF_DATA_TITLE', 2);
- define('_FF_DATA_TYPE', 3);
- define('_FF_DATA_VALUE', 4);
- define('_FF_DATA_FILE_SERVERPATH', 5);
- define('_FF_IGNORE_STRICT', 1);
- define('_FF_TRACE_NAMELIMIT', 100);
- // tracemode bits
- define('_FF_TRACEMODE_EVAL', 8);
- define('_FF_TRACEMODE_PIECE', 16);
- define('_FF_TRACEMODE_FUNCTION', 32);
- define('_FF_TRACEMODE_MESSAGE', 64);
- define('_FF_TRACEMODE_LOCAL', 128);
- define('_FF_TRACEMODE_DIRECT', 256);
- define('_FF_TRACEMODE_APPEND', 512);
- define('_FF_TRACEMODE_DISABLE', 1024);
- define('_FF_TRACEMODE_FIRST', 2048);
- // tracemode masks
- define('_FF_TRACEMODE_PRIORITY', 7);
- define('_FF_TRACEMODE_TOPIC', 120);
- define('_FF_TRACEMODE_VARIABLE', 248);
- // debugging flags
- define('_FF_DEBUG_PATCHEDCODE', 1);
- define('_FF_DEBUG_ENTER', 2);
- define('_FF_DEBUG_EXIT', 4);
- define('_FF_DEBUG_DIRECTIVE', 8);
- define('_FF_DEBUG', 0);
- function ff_trace($msg = null) {
- global $ff_processor;
- if ($ff_processor->dying ||
- ($ff_processor->traceMode & _FF_TRACEMODE_DISABLE) ||
- !($ff_processor->traceMode & _FF_TRACEMODE_MESSAGE))
- return;
- $level = count($ff_processor->traceStack);
- $trc = '';
- for ($l = 0; $l < $level; $l++)
- $trc .= ' ';
- $trc .= BFText::_('COM_BREEZINGFORMS_PROCESS_MSGUNKNOWN') . ": $msg\n";
- $ff_processor->traceBuffer .= htmlspecialchars($trc, ENT_QUOTES);
- if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
- $ff_processor->dumpTrace();
- }
- // ff_trace
- function _ff_trace($line, $msg = null) {
- global $ff_processor;
- // version for patched code
- if ($ff_processor->dying || ($ff_processor->traceMode & _FF_TRACEMODE_DISABLE))
- return;
- $level = count($ff_processor->traceStack);
- if ($msg && ($ff_processor->traceMode & _FF_TRACEMODE_MESSAGE)) {
- $trc = '';
- for ($l = 0; $l < $level; $l++)
- $trc .= ' ';
- $trc .= BFText::_('COM_BREEZINGFORMS_PROCESS_LINE') . " $line: $msg\n";
- $ff_processor->traceBuffer .= htmlspecialchars($trc, ENT_QUOTES);
- if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
- $ff_processor->dumpTrace();
- } // if
- if ($level)
- $ff_processor->traceStack[$level - 1][3] = $line;
- }
- // _ff_trace
- function _ff_getMode(&$newmode, &$name) {
- global $ff_processor;
- $oldmode = $ff_processor->traceMode;
- if (_FF_DEBUG & _FF_DEBUG_ENTER)
- $ff_processor->traceBuffer .=
- htmlspecialchars(
- "\n_FF_DEBUG_ENTER:" .
- "\n Name = $name" .
- "\n Old mode before = " . $ff_processor->dispTraceMode($oldmode) .
- "\n New mode before = " . $ff_processor->dispTraceMode($newmode), ENT_QUOTES
- );
- if (is_null($newmode) || ($newmode & _FF_TRACEMODE_PRIORITY) < ($oldmode & _FF_TRACEMODE_PRIORITY)) {
- $newmode = $oldmode;
- $ret = $oldmode;
- } else {
- $newmode = ($oldmode & ~_FF_TRACEMODE_VARIABLE) | ($newmode & _FF_TRACEMODE_VARIABLE);
- if ($oldmode != $newmode)
- $ff_processor->traceMode = $newmode;
- $ret = ($newmode & _FF_TRACEMODE_LOCAL) ? $oldmode : $newmode;
- } // if
- if (_FF_DEBUG & _FF_DEBUG_ENTER) {
- $ff_processor->traceBuffer .=
- htmlspecialchars(
- "\n Old mode compiled = " . $ff_processor->dispTraceMode($ret) .
- "\n New mode compiled = " . $ff_processor->dispTraceMode($newmode) .
- "\n", ENT_QUOTES
- );
- if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
- $ff_processor->dumpTrace();
- } // if
- return $ret;
- }
- // _ff_getmode
- function _ff_tracePiece($newmode, $name, $line, $type, $id, $pane) {
- global $ff_processor;
- if ($ff_processor->dying || ($ff_processor->traceMode & _FF_TRACEMODE_DISABLE))
- return;
- $oldmode = _ff_getMode($newmode, $name);
- if ($newmode & _FF_TRACEMODE_PIECE) {
- $level = count($ff_processor->traceStack);
- for ($l = 0; $l < $level; $l++)
- $ff_processor->traceBuffer .= ' ';
- $ff_processor->traceBuffer .=
- htmlspecialchars(
- "+" . BFText::_('COM_BREEZINGFORMS_PROCESS_ENTER') . " $name " . BFText::_('COM_BREEZINGFORMS_PROCESS_ATLINE') . " $line\n", ENT_QUOTES
- );
- if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
- $ff_processor->dumpTrace();
- } // if
- array_push($ff_processor->traceStack, array($oldmode, 'p', $name, $line, $type, $id, $pane));
- }
- // _ff_tracePiece
- function _ff_traceFunction($newmode, $name, $line, $type, $id, $pane, &$args) {
- global $ff_processor;
- if ($ff_processor->dying || ($ff_processor->traceMode & _FF_TRACEMODE_DISABLE))
- return;
- $oldmode = _ff_getMode($newmode, $name);
- if ($newmode & _FF_TRACEMODE_FUNCTION) {
- $level = count($ff_processor->traceStack);
- $trc = '';
- for ($l = 0; $l < $level; $l++)
- $trc .= ' ';
- $trc .= "+" . BFText::_('COM_BREEZINGFORMS_PROCESS_ENTER') . " $name(";
- if ($args) {
- $next = false;
- foreach ($args as $arg) {
- if ($next)
- $trc .= ', '; else
- $next = true;
- if (is_null($arg))
- $trc .= 'null';
- else
- if (is_bool($arg)) {
- $trc .= $arg ? 'true' : 'false';
- } else
- if (is_numeric($arg))
- $trc .= $arg;
- else
- if (is_string($arg)) {
- $arg = preg_replace('/([\\s]+)/si', ' ', $arg);
- if (strlen($arg) > _FF_TRACE_NAMELIMIT)
- $arg = substr($arg, 0, _FF_TRACE_NAMELIMIT - 3) . '...';
- $trc .= "'$arg'";
- } else
- if (is_array($arg))
- $trc .= BFText::_('COM_BREEZINGFORMS_PROCESS_ARRAY');
- else
- if (is_object($arg))
- $trc .= BFText::_('COM_BREEZINGFORMS_PROCESS_OBJECT');
- else
- if (is_resource($arg))
- $trc .= BFText::_('COM_BREEZINGFORMS_PROCESS_RESOURCE');
- else
- $trc .= _FACILEFORMS_PROCESS_UNKTYPE;
- } // foreach
- } // if
- $trc .= ") " . BFText::_('COM_BREEZINGFORMS_PROCESS_ATLINE') . " $line\n";
- $ff_processor->traceBuffer .= htmlspecialchars($trc, ENT_QUOTES);
- if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
- $ff_processor->dumpTrace();
- } // if
- array_push($ff_processor->traceStack, array($oldmode, 'f', $name, $line, $type, $id, $pane));
- }
- // _ff_traceFunction
- function _ff_traceExit($line, $retval=null) {
- global $ff_processor;
- if ($ff_processor->dying || ($ff_processor->traceMode & _FF_TRACEMODE_DISABLE))
- return;
- $info = array_pop($ff_processor->traceStack);
- if ($info) {
- $oldmode = $ff_processor->traceMode;
- $newmode = $info[0];
- $kind = $info[1];
- $name = $info[2];
- $type = $info[4];
- $id = $info[5];
- $pane = $info[6];
- if (_FF_DEBUG & _FF_DEBUG_EXIT) {
- $ff_processor->traceBuffer .=
- htmlspecialchars(
- "\n_FF_DEBUG_EXIT:" .
- "\n Info = $kind $name at line $line" .
- "\n Old mode = " . $ff_processor->dispTraceMode($oldmode) .
- "\n New mode = " . $ff_processor->dispTraceMode($newmode) .
- "\n", ENT_QUOTES
- );
- if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
- $ff_processor->dumpTrace();
- } // if
- if ($kind == 'p')
- $visible = $oldmode & _FF_TRACEMODE_PIECE;
- else
- $visible = $oldmode & _FF_TRACEMODE_FUNCTION;
- if ($visible) {
- $level = count($ff_processor->traceStack);
- for ($l = 0; $l < $level; $l++)
- $ff_processor->traceBuffer .= ' ';
- $ff_processor->traceBuffer .=
- htmlspecialchars(
- "-" . BFText::_('COM_BREEZINGFORMS_PROCESS_LEAVE') . " $name " . BFText::_('COM_BREEZINGFORMS_PROCESS_ATLINE') . " $line\n", ENT_QUOTES
- );
- if ($oldmode & _FF_TRACEMODE_DIRECT)
- $ff_processor->dumpTrace();
- } // if
- if ($oldmode != $newmode)
- $ff_processor->traceMode =
- ($oldmode & ~_FF_TRACEMODE_VARIABLE) | ($newmode & _FF_TRACEMODE_VARIABLE);
- } else {
- $ff_processor->traceBuffer .= htmlspecialchars(BFText::_('COM_BREEZINGFORMS_PROCESS_WARNSTK') . "\n", ENT_QUOTES);
- if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
- $ff_processor->dumpTrace();
- $type = $id = $pane = null;
- $name = BFText::_('COM_BREEZINGFORMS_PROCESS_UNKNOWN');
- } // if
- return $retval;
- }
- // _ff_traceExit
- function _ff_errorHandler($errno, $errstr, $errfile, $errline) {
- global $ff_processor, $ff_mossite, $database;
- $database = JFactory::getDBO();
- if (isset($ff_processor->dying) && $ff_processor->dying)
- return;
- $msg = "\n<strong>*** " . htmlspecialchars(BFText::_('COM_BREEZINGFORMS_PROCESS_EXCAUGHT'), ENT_QUOTES) . " ***</strong>\n" .
- htmlspecialchars(BFText::_('COM_BREEZINGFORMS_PROCESS_PHPLEVEL') . ' ', ENT_QUOTES);
- $fail = false;
- if (!defined('E_DEPRECATED')) {
- define('E_DEPRECATED', 8192);
- }
- switch ($errno) {
- case E_WARNING : $msg .= "E_WARNING";
- break;
- case E_NOTICE : $msg .= "E_NOTICE";
- break;
- case E_USER_ERROR : $msg .= "E_USER_ERROR";
- $fail = true;
- break;
- case E_USER_WARNING: $msg .= "E_USER_WARNING";
- break;
- case E_USER_NOTICE : $msg .= "E_USER_NOTICE";
- break;
- case E_DEPRECATED : $msg .= "E_DEPRECATED";
- break;
- case 2048 :
- if (_FF_IGNORE_STRICT)
- return;
- $msg .= "E_STRICT";
- break;
- default : $msg .= $errno;
- $fail = true;
- } // switch
- $msg .= htmlspecialchars(
- "\n" . BFText::_('COM_BREEZINGFORMS_PROCESS_PHPFILE') . " $errfile\n" .
- BFText::_('COM_BREEZINGFORMS_PROCESS_PHPLINE') . " $errline\n", ENT_QUOTES
- );
- $n = 0;
- if (isset($ff_processor)) {
- $n = count($ff_processor->traceStack);
- }
- if ($n) {
- $info = $ff_processor->traceStack[$n - 1];
- $name = htmlspecialchars($info[2] . ' ' . BFText::_('COM_BREEZINGFORMS_PROCESS_ATLINE') . ' ' . $info[3], ENT_QUOTES);
- $type = $info[4];
- $id = $info[5];
- $pane = $info[6];
- if ($type && $id && $ff_processor->runmode != _FF_RUNMODE_FRONTEND) {
- $url = $ff_mossite . '/administrator/index.php?option=com_breezingforms&format=html&tmpl=component';
- $what = $id;
- switch ($type) {
- case 'f':
- $url .=
- '&act=editpage' .
- '&task=editform' .
- '&form=' . $ff_processor->form;
- if ($ff_processor->formrow->package != '')
- $url .= '&pkg=' . urlencode($ff_processor->formrow->package);
- if ($pane > 0)
- $url .= '&tabpane=' . $pane;
- $what = 'form ' . $ff_processor->formrow->name;
- break;
- case 'e':
- $page = 1;
- foreach ($ff_processor->rows as $row)
- if ($row->id == $id) {
- $page = $row->page;
- $what = $row->name;
- break;
- } // if
- $what = 'element ' . $what;
- $url .=
- '&act=editpage' .
- '&task=edit' .
- '&form=' . $ff_processor->form .
- '&page=' . $page .
- '&ids[]=' . $id;
- if ($ff_processor->formrow->package != '')
- $url .= '&pkg=' . urlencode($ff_processor->formrow->package);
- if ($pane > 0)
- $url .= '&tabpane=' . $pane;
- break;
- case 'p':
- $package = '';
- $database->setQuery("select name, package from #__facileforms_pieces where id=$id");
- $rows = $database->loadObjectList();
- if (count($rows)) {
- $package = $rows[0]->package;
- $what = $rows[0]->name;
- }
- $what = 'piece ' . $what;
- $url .=
- '&act=managepieces' .
- '&task=edit' .
- '&ids[]=' . $id;
- if ($package != '')
- $url .= '&pkg=' . urlencode($package);
- break;
- case 's':
- $package = '';
- $database->setQuery("select name, package from #__facileforms_scripts where id=$id");
- $rows = $database->loadObjectList();
- if (count($rows)) {
- $package = $rows[0]->package;
- $what = $rows[0]->name;
- }
- $what = 'script ' . $what;
- $url .=
- '&act=managescripts' .
- '&task=edit' .
- '&ids[]=' . $id;
- if ($package != '')
- $url .= '&pkg=' . urlencode($package);
- break;
- default:
- $url = null;
- } // switch
- if ($url)
- $name = '<a href="#" ' .
- 'onMouseOver="window.status=\'Open ' . $what . '\';return true;" ' .
- 'onMouseOut="window.status=\'\';return true;" ' .
- 'onClick="ff_redirectParent(\'' . htmlspecialchars($url, ENT_QUOTES) . '\');return true;"' .
- '>' . $name . '</a>';
- } // if
- $msg .= htmlspecialchars(BFText::_('COM_BREEZINGFORMS_PROCESS_LASTPOS'), ENT_QUOTES) . ' ' . $name . "\n";
- } // if
- $msg .= htmlspecialchars(BFText::_('COM_BREEZINGFORMS_PROCESS_ERRMSG') . " $errstr\n\n", ENT_QUOTES);
- if ($fail) {
- if (isset($ff_processor)) {
- $ff_processor->traceBuffer .= $msg;
- $ff_processor->suicide();
- }
- } else
- if (isset($ff_processor)) {
- if (($ff_processor->traceMode & _FF_TRACEMODE_DISABLE) == 0) {
- $ff_processor->traceBuffer .= $msg;
- if ($ff_processor->traceMode & _FF_TRACEMODE_DIRECT)
- $ff_processor->dumpTrace();
- }
- } // if
- }
- // _ff_errorHandler
- class HTML_facileFormsProcessor {
- var $okrun = null; // running is allowed
- var $ip = null; // visitor ip
- var $agent = null; // visitor agent
- var $browser = null; // visitors browser
- var $opsys = null; // visitors operating system
- var $provider = null; // visitors provider
- var $submitted = null; // submit date/time
- var $formrow = null; // form row
- var $form = null; // form #
- var $form_id = null; // html form id
- var $page = null; // page id
- var $target = null; // target form name
- var $rows = null; // element rows
- var $rowcount = null; // # of element rows
- var $runmode = null; // current run mode _FF_RUNMODE_...
- var $inline = null; // inline preview
- var $inframe = null; // running in a frame
- var $template = null; // 0-frontend 1-backend
- var $homepage = null; // home page
- var $mospath = null; // mos absolute path
- var $images = null; // ff_images path
- var $uploads = null; // ff_uploads path
- var $border = null; // show border
- var $align = null; // form alignment
- var $top = null; // top margin
- var $suffix = null; // class name suffix
- var $status = null; // submit return status
- var $message = null; // submit return message
- var $record_id = null; // id of saved record
- var $submitdata = null; // submitted data
- var $savedata = null; // data for db save
- var $maildata = null; // data for mail notification
- var $sfdata = null;
- var $xmldata = null; // data for xml attachment
- var $mb_xmldata = null; // data for mailback attachments
- var $queryCols = null; // query column definitions
- var $queryRows = null; // query rows
- var $showgrid = null; // show grid in preview
- var $findtags = null; // tags to be replaced
- var $replacetags = null; // tag replacements
- var $dying = null; // form is dying
- var $errrep = null; // remember old error reporting
- var $traceMode = null; // trace mode
- var $traceStack = null; // trace stack
- var $traceBuffer = null; // trace buffer
- var $user_id = null;
- var $username = null;
- var $user_full_name = null;
- var $mailbackRecipients = array();
- var $editable = null;
- var $editable_override = null;
- var $sendNotificationAfterPayment = false;
- public $draggableDivIds = array();
- public $isMobile = false;
- public $quickmode = null;
-
- function HTML_facileFormsProcessor(
- $runmode, // _FF_RUNMODE_FRONTEND, ..._BACKEND, ..._PREVIEW
- $inframe, // run in iframe
- $form, // form id
- $page = 1, // page #
- $border = 0, // show border
- $align = 1, // align code
- $top = 0, // top margin
- $target = '', // target form name
- $suffix = '', // class name suffix
- $editable = 0, $editable_override = 0) {
- global $database, $ff_config, $ff_mossite, $ff_mospath, $ff_processor;
- $ff_processor = $this;
- $database = JFactory::getDBO();
- $this->dying = false;
- $this->runmode = $runmode;
- $this->inframe = $inframe;
- $this->form = $form;
- $this->page = $page;
- $this->border = $border;
- $this->align = $align;
- $this->top = $top;
- $this->target = $target;
- $this->suffix = trim($suffix);
- $this->editable = $editable;
- $this->editable_override = $editable_override;
- if (!class_exists('JBrowser')) {
- require_once(JPATH_SITE . '/libraries/joomla/environment/browser.php');
- }
- $this->ip = $_SERVER['REMOTE_ADDR'];
- $this->agent = JBrowser::getInstance()->getAgentString();
- $this->browser = JBrowser::getInstance()->getAgentString();
- $jbrowserInstance = JBrowser::getInstance();
- $this->opsys = $jbrowserInstance->getPlatform();
- if ($ff_config->getprovider == 0)
- $this->provider = BFText::_('COM_BREEZINGFORMS_PROCESS_UNKNOWN');
- else {
- $host = @GetHostByAddr($this->ip);
- $this->provider = preg_replace('/^./', '', strchr($host, '.'));
- } // if
- $this->submitted = date('Y-m-d H:i:s');
- /*
- $format = JText::_('DATE_FORMAT_LC2');
- if ( !$format ) {
- $this->submitted = date('Y-m-d H:i:s');
- }else{
- $config = JFactory::getConfig();
- $offset = $config->getValue('config.offset');
- $instance = JFactory::getDate(date('Y-m-d H:i:s'));
- $instance->setOffset($offset);
- $this->submitted = $instance->toFormat($format);
- } */
- $this->formrow = new facileFormsForms($database);
- $this->formrow->load($form);
- if ($this->formrow->published) {
- $database->setQuery(
- "select * from #__facileforms_elements " .
- "where form=" . $this->form . " and published=1 " .
- "order by page, ordering"
- );
- $this->rows = $database->loadObjectList();
- $this->rowcount = count($this->rows);
- } // if
- $this->inline = 0;
- $this->template = 0;
- $this->form_id = "ff_form" . $form;
- if ($runmode == _FF_RUNMODE_FRONTEND) {
- $this->homepage = $ff_mossite;
- } else {
- if ($this->inframe) {
- $this->homepage = $ff_mossite . '/administrator/index.php?tmpl=component';
- if ($this->formrow->runmode == 2)
- $this->template++;
- } else {
- $this->template++;
- if ($runmode == _FF_RUNMODE_PREVIEW) {
- $this->inline = 1;
- $this->form_id = "adminForm";
- } // if
- $this->homepage = 'index.php?tmpl=component';
- } // if
- } // if
- $this->mospath = $ff_mospath;
- $this->mossite = $ff_mossite;
- $this->findtags =
- array(
- '{ff_currentpage}',
- '{ff_lastpage}',
- '{ff_name}',
- '{ff_title}',
- '{ff_homepage}',
- '{mospath}',
- '{mossite}'
- );
- $this->replacetags =
- array(
- $this->page,
- $this->formrow->pages,
- $this->formrow->name,
- $this->formrow->title,
- $this->homepage,
- $this->mospath,
- $this->mossite
- );
- $this->images = str_replace($this->findtags, $this->replacetags, $ff_config->images);
- $this->findtags[] = '{ff_images}';
- $this->replacetags[] = $this->images;
- $this->uploads = str_replace($this->findtags, $this->replacetags, $ff_config->uploads);
- $this->findtags[] = '{ff_uploads}';
- $this->replacetags[] = $this->uploads;
- // CONTENTBUILDER
- $this->findtags[] = '{CBSite}';
- $this->replacetags[] = JPATH_SITE;
- $this->findtags[] = '{cbsite}';
- $this->replacetags[] = JPATH_SITE;
- $this->showgrid =
- $runmode == _FF_RUNMODE_PREVIEW
- && $this->formrow->prevmode > 0
- && $ff_config->gridshow == 1
- && $ff_config->gridsize > 1;
- $this->okrun = $this->formrow->published;
- if ($this->okrun)
- switch ($this->runmode) {
- case _FF_RUNMODE_FRONTEND:
- $this->okrun = ($this->formrow->runmode == 0 || $this->formrow->runmode == 1);
- break;
- case _FF_RUNMODE_BACKEND:
- $this->okrun = ($this->formrow->runmode == 0 || $this->formrow->runmode == 2);
- break;
- default:;
- } // switch
- $this->traceMode = _FF_TRACEMODE_FIRST;
- $this->traceStack = array();
- $this->traceBuffer = null;
- }
- // HTML_facileFormsProcessor
- function dispTraceMode($mode) {
- if (!is_int($mode))
- return $mode;
- $m = '(';
- if ($mode & _FF_TRACEMODE_FIRST)
- $m .= 'first ';
- $m .= ( $mode & _FF_TRACEMODE_DIRECT ? 'direct' : $mode & _FF_TRACEMODE_APPEND ? 'append' : 'popup');
- if ($mode & _FF_TRACEMODE_DISABLE)
- $m .= ' disable';
- else {
- switch ($mode & _FF_TRACEMODE_PRIORITY) {
- case 0: $m .= ' minimum';
- break;
- case 1: $m .= ' low';
- break;
- case 2: $m .= ' normal';
- break;
- case 3: $m .= ' high';
- break;
- default: $m .= ' maximum';
- break;
- } // switch
- $m .= $mode & _FF_TRACEMODE_LOCAL ? ' local' : ' global';
- switch ($mode & _FF_TRACEMODE_TOPIC) {
- case 0 : $m .= ' none';
- break;
- case _FF_TRACEMODE_TOPIC: $m .= ' all';
- break;
- default:
- if ($mode & _FF_TRACEMODE_EVAL)
- $m .= ' eval';
- if ($mode & _FF_TRACEMODE_PIECE)
- $m .= ' piece';
- if ($mode & _FF_TRACEMODE_FUNCTION)
- $m .= ' function';
- if ($mode & _FF_TRACEMODE_MESSAGE)
- $m .= ' message';
- } // switch
- } // if
- return $m . ')';
- }
- // dispTraceMode
- function trim(&$code) {
- $len = strlen($code);
- if (!$len)
- return false;
- if (strpos(" \t\r\n", $code{0}) === false && strpos(" \t\r\n", $code{$len - 1}) === false)
- return true;
- $code = trim($code);
- return $code != '';
- }
- // trim
- function nonblank(&$code) {
- return preg_match("/[^\\s]+/si", $code);
- }
- // nonblank
- function getClassName($classdef) {
- $name = '';
- if (strpos($classdef, ';') === false)
- $name = $classdef;
- else {
- $defs = explode(';', $classdef);
- $name = $defs[$this->template];
- } // if
- if ($this->trim($name))
- $name .= $this->suffix;
- return $name;
- }
- // getClassName
- function expJsValue($mixed, $indent='') {
- if (is_null($mixed))
- return $indent . 'null';
- if (is_bool($mixed))
- return $mixed ? $indent . 'true' : $indent . 'false';
- if (is_numeric($mixed))
- return $indent . $mixed;
- if (is_string($mixed))
- return
- $indent . "'" .
- str_replace(
- array("\\", "'", "\r", "<", "\n"), array("\\\\", "\\'", "\\r", "\\074", "\\n'+" . nl() . $indent . "'"), $mixed
- ) .
- "'";
- if (is_array($mixed)) {
- $dst = $indent . '[' . nl();
- $next = false;
- foreach ($mixed as $value) {
- if ($next)
- $dst .= "," . nl(); else
- $next = true;
- $dst .= $this->expJsValue($value, $indent . "\t");
- } // foreach
- return $dst . nl() . $indent . ']';
- } // if
- if (is_object($mixed)) {
- $dst = $indent . '{' . nl();
- $arr = get_object_vars($mixed);
- $next = false;
- foreach ($arr as $key => $value) {
- if ($next)
- $dst .= "," . nl(); else
- $next = true;
- $dst .= $indent . $key . ":" . nl() . $this->expJsValue($value, $indent . "\t");
- } // foreach
- return $dst . nl() . $indent . '}';
- } // if
- // not supported types
- if (is_resource($mixed))
- return $indent . "'" . BFText::_('COM_BREEZINGFORMS_PROCESS_RESOURCE') . "'";
- return $indent . "'" . BFText::_('COM_BREEZINGFORMS_PROCESS_UNKNOWN') . "'";
- }
- // expJsValue
- function expJsVar($name, $mixed) {
- return $name . ' = ' . $this->expJsValue($mixed) . ';' . nl();
- }
- // expJsVar
- function dumpTrace() {
- if ($this->traceMode & _FF_TRACEMODE_DIRECT) {
- $html = ob_get_contents();
- ob_end_clean();
- echo htmlspecialchars($html, ENT_QUOTES) . $this->traceBuffer;
- ob_start();
- $this->traceBuffer = null;
- return;
- } // if
- if (!$this->traceBuffer)
- return;
- if ($this->traceMode & _FF_TRACEMODE_APPEND) {
- echo '<pre>' . $this->traceBuffer . '</pre>';
- $this->traceBuffer = null;
- return;
- } // if
- echo
- '<script type="text/javascript">' . nl() .
- '<!--' . nl() .
- $this->expJsVar('if(typeof ff_processor != "undefined")ff_processor.traceBuffer', $this->traceBuffer);
- if ($this->dying)
- echo 'onload = ff_traceWindow();' . nl();
- echo
- '-->' . nl() .
- '</script>' . nl();
- $this->traceBuffer = null;
- }
- // dumpTrace
- function traceEval($name) {
- if (($this->traceMode & _FF_TRACEMODE_DISABLE) ||
- !($this->traceMode & _FF_TRACEMODE_EVAL) ||
- $this->dying)
- return;
- $level = count($this->traceStack);
- for ($l = 0; $l < $level; $l++)
- $this->traceBuffer .= ' ';
- $this->traceBuffer .= htmlspecialchars("eval($name)\n", ENT_QUOTES);
- if ($this->traceMode & _FF_TRACEMODE_DIRECT)
- $this->dumpTrace();
- }
- // traceEval
- function suicide() {
- if ($this->dying)
- return false;
- $this->dying = true;
- $this->errrep = error_reporting(0);
- return true;
- }
- // suicide
- function bury() {
- if (!$this->dying)
- return false;
- if ($this->traceMode & _FF_TRACEMODE_DIRECT)
- $this->dumpTrace();
- ob_end_clean();
- if ($this->traceMode & _FF_TRACEMODE_DIRECT)
- echo '</pre>'; else
- $this->dumpTrace();
- error_reporting($this->errrep);
- restore_error_handler();
- return true;
- }
- // bury
- function findToken(&$code, &$spos, &$offs) {
- $srch = '#(function|return|_ff_trace|ff_trace[ \\t]*\\(|//|/\*|\*/|\\\\"|\\\\\'|{|}|\(|\)|;|"|\'|\n)#si';
- $match = array();
- if (!preg_match($srch, $code, $match, PREG_OFFSET_CAPTURE, $spos))
- return '';
- $token = strtolower($match[0][0]);
- $offs = $match[0][1];
- $spos = $offs + strlen($token);
- return $token;
- }
- // findToken
- function findRealToken(&$code, &$spos, &$offs, &$line) {
- $linecmt = $blockcmt = false;
- $quote = null;
- for (;;) {
- $token = preg_replace('/[ \\t]*/', '', $this->findToken($code, $spos, $offs));
- switch ($token) {
- case '':
- return '';
- case 'function':
- case 'return';
- case 'ff_trace(';
- case '{':
- case '}':
- case '(':
- case ')':
- case ';':
- if (!$linecmt && !$blockcmt && !$quote)
- return $token;
- break;
- case "\n":
- $line++;
- $linecmt = false;
- break;
- case '//':
- if (!$blockcmt && !$quote)
- $linecmt = true;
- break;
- case '/*':
- if (!$linecmt && !$quote)
- $longcmt = true;
- break;
- case '"':
- case "'":
- if ($quote == $token)
- $quote = null;
- else
- if (!$linecmt && !$blockcmt && !$quote)
- $quote = $token;
- break;
- default:
- break;
- } // switch
- } // for
- }
- // findRealToken
- function patchCode($mode, $code, $name, $type, $id, $pane) {
- $flevel = $cpos = $spos = $offs = 0;
- $bye = false;
- $fstack = array();
- $line = 1;
- if ($type && $id) {
- $type = "'$type'";
- if (!$pane)
- $pane = 'null';
- } else
- $type = $id = $pane = 'null';
- $name = str_replace("'", "\\'", $name);
- $dst = "_ff_tracePiece($mode,'$name',$line,$type,$id,$pane);";
- while (!$bye) {
- switch ($this->findRealToken($code, $spos, $offs, $line)) {
- case '': $bye = true;
- break;
- case 'function':
- $brk = false;
- while (!$brk) {
- // consume tokens until finding the opening bracket
- switch ($this->findRealToken($code, $spos, $offs, $line)) {
- case '': $bye = $brk = true;
- break;
- case '{':
- $dst .=
- substr($code, $cpos, $spos - $cpos) .
- '$_ff_traceArgs = func_get_args();' .
- '_ff_traceFunction(' . $mode . ',__FUNCTION__,' . $line . ',' . $type . ',' . $id . ',' . $pane . ',$_ff_traceArgs);' .
- '$_ff_traceArgs=null;';
- $cpos = $spos;
- if ($flevel)
- array_push($fstack, $flevel);
- $flevel = 1;
- $brk = true;
- break;
- default:;
- } // switch
- } // while
- break;
- case 'return':
- $dst .= substr($code, $cpos, $spos - $cpos);
- $cpos = $spos;
- $brk = false;
- while (!$brk) {
- // consume tokens until semicolon found
- switch ($this->findRealToken($code, $spos, $offs, $line)) {
- case '': $bye = $brk = true;
- break;
- case ';':
- $arg = substr($code, $cpos, $offs - $cpos);
- if ($this->nonblank($arg))
- $dst .= ' _ff_traceExit(' . $line . ',' . $arg . ');';
- else
- $dst .= ' _ff_traceExit(' . $line . ');';
- $cpos = $spos;
- $brk = true;
- break;
- default:;
- } // switch
- } // while
- break;
- case 'ff_trace(':
- $dst .= substr($code, $cpos, $offs - $cpos);
- $cpos = $spos;
- $brk = false;
- $lvl = 0;
- while (!$brk) {
- // consume tokens until finding the closing bracket
- switch ($this->findRealToken($code, $spos, $offs, $line)) {
- case '': $bye = $brk = true;
- break;
- case '(': $lvl++;
- break;
- case ')':
- if ($lvl)
- $lvl--; else
- $brk = true;
- break;
- default:;
- } // switch
- } // while
- $par = $offs == $cpos ? '' : substr($code, $cpos, $offs - $cpos);
- $dst .= " _ff_trace($line";
- if ($this->nonblank($par))
- $dst .= ',';
- break;
- case '{':
- if ($flevel > 0)
- $flevel++;
- break;
- case '}';
- if ($flevel > 0) {
- $flevel--;
- if (!$flevel) {
- $dst .= substr($code, $cpos, $offs - $cpos) . ' _ff_traceExit(' . $line . ');}';
- $cpos = $spos;
- if (count($fstack))
- $flevel = array_pop($fstack);
- } // if
- } // if
- break;
- default:
- } // switch
- } // while
- $spos = strlen($code);
- if ($cpos < $spos)
- $dst .= substr($code, $cpos, $spos - $cpos);
- $line--;
- $dst .= "_ff_traceExit($line);";
- if (_FF_DEBUG & _FF_DEBUG_PATCHEDCODE) {
- $this->traceBuffer .=
- htmlspecialchars(
- "\n_FF_DEBUG_PATCHEDCODE:" .
- "\n Mode = " . $this->dispTraceMode($mode) .
- "\n Name = $name" .
- "\n Link = $type $id $pane" .
- "\n------ begin patched code ------" .
- "\n$dst" .
- "\n------- end patched code -------" .
- "\n", ENT_QUOTES
- );
- if ($this->traceMode & _FF_TRACEMODE_DIRECT)
- $this->dumpTrace();
- } // if
- return $dst;
- }
- // patchCode
- function prepareEvalCode(&$code, $name, $type, $id, $pane) {
- if ($this->dying)
- return false;
- if (!$this->nonblank($code))
- return false;
- $code .= "\n/*'/*\"/**/;"; // closes all comments and strings that my be open
- $disable = ($this->traceMode & _FF_TRACEMODE_DISABLE) ? true : false;
- if (!$disable) {
- $mode = 'null';
- $srch =
- '#' .
- '^[\\s]*(//\+trace|/\*\+trace)' .
- '[ \\t]*([\\w]+)?' .
- '[ \\t]*([\\w]+)?' .
- '[ \\t]*([\\w]+)?' .
- '[ \\t]*([\\w]+)?' .
- '[ \\t]*([\\w]+)?' .
- '[ \\t]*([\\w]+)?' .
- '[ \\t]*(\\*/|\\r\\n)?' .
- '#';
- $match = array();
- if (preg_match($srch, $code, $match)) {
- $mode = 2;
- $append = $direct = $xeval = $piece = $func = $msg = false;
- $local = $def = true;
- for ($m = 2; $m < count($match); $m++)
- switch ($match[$m]) {
- // disable
- case 'dis' :
- case 'disable' : $disable = true;
- break;
- // mode
- case 'pop' :
- case 'popup' : $direct = $append = false;
- break;
- case 'app' :
- case 'append' : $append = true;
- $direct = false;
- break;
- case 'dir' :
- case 'direct' : $direct = true;
- $append = false;
- break;
- // priority
- case 'min' :
- case 'minimum' : $mode = 0;
- break;
- case 'low' : $mode = 1;
- break;
- case 'nor' :
- case 'normal' : $mode = 2;
- break;
- case 'hig' :
- case 'high' : $mode = 3;
- break;
- case 'max' :
- case 'maximum' : $mode = 4;
- break;
- // scope
- case 'glo' :
- case 'global' : $local = false;
- break;
- case 'loc' :
- case 'local' : $local = true;
- break;
- // topics
- case 'all' : $def = false;
- $xeval = $piece = $func = $msg = true;
- break;
- case 'non' :
- case 'none' : $def = $xeval = $piece = $func = $msg = false;
- break;
- case 'eva' :
- case 'eval' : $def = false;
- $xeval = true;
- break;
- case 'pie' :
- case 'piece' : $def = false;
- $piece = true;
- break;
- case 'fun' :
- case 'function': $def = false;
- $func = true;
- break;
- case 'mes' :
- case 'message' : $def = false;
- $msg = true;
- break;
- default : break;
- } // switch
- if ($def) {
- $xeval = false;
- $piece = $func = $msg = true;
- }
- if ($xeval)
- $mode |= _FF_TRACEMODE_EVAL;
- if ($piece)
- $mode |= _FF_TRACEMODE_PIECE;
- if ($func)
- $mode |= _FF_TRACEMODE_FUNCTION;
- if ($msg)
- $mode |= _FF_TRACEMODE_MESSAGE;
- if ($local)
- $mode |= _FF_TRACEMODE_LOCAL;
- $first = ($this->traceMode & _FF_TRACEMODE_FIRST) ? true : false;
- if ($first) {
- $oldMode = $this->traceMode;
- $this->traceMode = 0;
- if ($disable)
- $this->traceMode |= _FF_TRACEMODE_DISABLE;
- if ($append)
- $this->traceMode |= _FF_TRACEMODE_APPEND;
- if ($direct) {
- $this->traceMode |= _FF_TRACEMODE_DIRECT;
- $html = ob_get_contents();
- ob_end_clean();
- echo '<pre>' . htmlspecialchars($html, ENT_QUOTES);
- ob_start();
- } // if
- } else
- $disable = false;
- if (_FF_DEBUG & _FF_DEBUG_DIRECTIVE) {
- $_deb = "\n_FF_DEBUG_DIRECTIVE:";
- if ($first)
- $_deb .= "\n Previous mode=" . $this->dispTraceMode($oldMode);
- $_deb .=
- "\n Trace mode =" . $this->dispTraceMode($this->traceMode) .
- "\n New mode =" . $this->dispTraceMode($mode) .
- "\n";
- $this->traceBuffer .= htmlspecialchars($_deb, ENT_QUOTES);
- if ($this->traceMode & _FF_TRACEMODE_DIRECT)
- $this->dumpTrace();
- } // if
- } // if trace directive
- if (!$disable) {
- if (!$name) {
- $name = preg_replace('/([\\s]+)/si', ' ', $code);
- if (strlen($name) > _FF_TRACE_NAMELIMIT)
- $name = substr($code, 0, _FF_TRACE_NAMELIMIT - 3) . '...';
- } // if
- $code = $this->patchCode($mode, $code, $name, $type, $id, $pane);
- } // if
- } // if trace not disabled
- $code = str_replace($this->findtags, $this->replacetags, $code);
- return true;
- }
- // prepareEvalCode
- function getPieceById($id, $name=null) {
- if ($this->dying)
- return '';
- global $database;
- $database = JFactory::getDBO();
- $database->setQuery(
- 'select code, name from #__facileforms_pieces ' .
- 'where id=' . $id . ' and published=1 '
- );
- $rows = $database->loadObjectList();
- if ($rows && count($rows)) {
- $name = $rows[0]->name;
- return $rows[0]->code;
- } // if
- return '';
- }
- // getPieceById
- function getPieceByName($name, $id=null) {
- if ($this->dying)
- return '';
- global $database;
- $database = JFactory::getDBO();
- $database->setQuery(
- 'select id, code from #__facileforms_pieces ' .
- 'where name=\'' . $name . '\' and published=1 ' .
- 'order by id desc'
- );
- $rows = $database->loadObjectList();
- if ($rows && count($rows)) {
- $id = $rows[0]->id;
- return $rows[0]->code;
- } // if
- return '';
- }
- // getPieceByName
- function execPiece($code, $name, $type, $id, $pane) {
- $ret = '';
- if ($this->prepareEvalCode($code, $name, $type, $id, $pane)) {
- $this->traceEval($name);
- $ret = eval($code);
- } // if
- return $ret;
- }
- // execPiece
- function execPieceById($id) {
- $name = null;
- $code = $this->getPieceById($id, $name);
- return $this->execPiece($code, BFText::_('COM_BREEZINGFORMS_PROCESS_PIECE') . " $name", 'p', $id, null);
- }
- // execPieceById
- function execPieceByName($name) {
- $id = null;
- $code = $this->getPieceByName($name, $id);
- return $this->execPiece($code, BFText::_('COM_BREEZINGFORMS_PROCESS_PIECE') . " $name", 'p', $id, null);
- }
- // execPieceByName
- function replaceCode($code, $name, $type, $id, $pane) {
- if ($this->dying)
- return '';
- $p1 = 0;
- $l = strlen($code);
- $c = '';
- $n = 0;
- while ($p1 < $l) {
- $p2 = strpos($code, '<?php', $p1);
- if ($p2 === false)
- $p2 = $l;
- $c .= substr($code, $p1, $p2 - $p1);
- $p1 = $p2;
- if ($p1 < $l) {
- $p1 += 5;
- $p2 = strpos($code, '?>', $p1);
- if ($p2 === false)
- $p2 = $l;
- $n++;
- $c .= $this->execPiece(substr($code, $p1, $p2 - $p1), $name . "[$n]", $type, $id, $pane);
- if ($this->dying)
- return '';
- $p1 = $p2 + 2;
- } // if
- } // while
- return str_replace($this->findtags, $this->replacetags, $c);
- }
- // replaceCode
- function compileQueryCol(&$elem, &$coldef) {
- $coldef->comp = array();
- if ($this->trim(str_replace($this->findtags, $this->replacetags, $coldef->value))) {
- $c = $p1 = 0;
- $l = strlen($coldef->value);
- while ($p1 < $l) {
- $p2 = strpos($coldef->value, '<?php', $p1);
- if ($p2 === false)
- $p2 = $l;
- $coldef->comp[$c] = array(
- false,
- str_replace(
- $this->findtags, $this->replacetags, trim(substr($coldef->value, $p1, $p2 - $p1))
- )
- );
- if ($this->trim($coldef->comp[$c][1]))
- $c++;
- $p1 = $p2;
- if ($p1 < $l) {
- $p1 += 5;
- $p2 = strpos($coldef->value, '?>', $p1);
- if ($p2 === false)
- $p2 = $l;
- $coldef->comp[$c] = array(true, substr($coldef->value, $p1, $p2 - $p1));
- if ($this->prepareEvalCode(
- $coldef->comp[$c][1], BFText::_('COM_BREEZINGFORMS_PROCESS_QVALUEOF') . " " . $elem->name . "::" . $coldef->name, 'e', $elem->id, 2
- )
- )
- $c++;
- $p1 = $p2 + 2;
- } // if
- } // while
- if ($c > count($coldef->comp))
- array_pop($coldef->comp);
- } // if non-empty
- }
- // compileQueryCol
- function execQueryValue($code, &$elem, &$row, &$coldef, $value) {
- $this->traceEval(BFText::_('COM_BREEZINGFORMS_PROCESS_QVALUEOF') . " " . $elem->name . "::" . $coldef->name);
- return eval($code);
- }
- // execQueryValue
- function execQuery(&$elem, &$valrows, &$coldefs) {
- $ret = null;
- $code = $elem->data2;
- if ($this->prepareEvalCode($code, BFText::_('COM_BREEZINGFORMS_PROCESS_QPIECEOF') . " " . $elem->name, 'e', $elem->id, 1)) {
- $rows = array();
- $this->traceEval(BFText::_('COM_BREEZINGFORMS_PROCESS_QPIECEOF') . " " . $elem->name);
- eval($code);
- $rcnt = count($rows);
- $ccnt = count($coldefs);
- $valrows = array();
- for ($r = 0; $r < $rcnt; $r++) {
- $row = &$rows[$r];
- $valrow = array();
- for ($c = 0; $c < $ccnt; $c++) {
- $coldef = &$coldefs[$c];
- $cname = $coldef->name;
- $value = isset($row->$cname) ? str_replace($this->findtags, $this->replacetags, $row->$cname) : '';
- $xcnt = count($coldef->comp);
- if (!$xcnt)
- $valrow[] = $value;
- else {
- $val = '';
- for ($x =…
Large files files are truncated, but you can click here to view the full file