示例#1
0
 /**
  * RaxanElement(css,context)
  * RaxanElement(html,context)
  * @param mixed $css CSS selector string, array of DOMElements, DOMNode, DOMNodeList or RaxanElement
  * @param DOMNode $context
  * @return RaxanElement
  */
 function __construct($css, $context = null)
 {
     parent::__construct();
     $this->_length = 0;
     // set length to 0
     $this->elms = array();
     // setup elements array
     $c = $context;
     $reservedMethods = array('empty', 'clone');
     // get document
     if ($c == null) {
         $this->doc = null;
     } else {
         if ($c instanceof RaxanDOMDocument) {
             $this->doc = $c;
             $c = null;
             // context is document so set it null
         } else {
             if ($c instanceof DOMNode && $c->ownerDocument instanceof RaxanDOMDocument) {
                 $this->doc = $c->ownerDocument;
             } else {
                 $c = $this->doc = null;
             }
         }
     }
     $this->doc = $this->doc ? $this->doc : RaxanWebPage::controller()->document();
     $this->_rootElm = $this->doc->documentElement;
     $css = $css ? $css : $this->_rootElm;
     $this->_context = $c ? $c : $this->_rootElm;
     // assign context element
     if (is_string($css)) {
         $this->_selector = $css;
         if (!$this->isHTML($css)) {
             $dl = $this->doc->cssQuery($css, $this->_context);
         } else {
             // handle html
             $this->_modifiedStack = true;
             if (!$this->doc->isInit()) {
                 $this->doc->initDOMDocument();
             }
             $n = $this->doc->getElementsByTagName('body');
             if ($n->length) {
                 $n = $n->item(0);
                 $f = $this->page->createFragment('<div>' . $css . '</div>');
                 if ($f) {
                     $f = $n->appendChild($f);
                     // append html to body tag
                     $dl = array();
                     foreach ($f->childNodes as $n1) {
                         if ($n1->nodeType == 1) {
                             $dl[] = $n1->cloneNode(true);
                         }
                     }
                     $n->removeChild($f);
                     // remove element
                 }
             }
         }
     } else {
         if ($css instanceof DOMNode) {
             $this->elms[] = $css;
             $this->_length = 1;
         } else {
             if ($css instanceof DOMNodeList) {
                 $dl = $css;
             } else {
                 if ($css instanceof RaxanElement) {
                     $dl = $css->get();
                 } else {
                     if (is_array($css)) {
                         $dl = $css;
                     }
                 }
             }
         }
     }
     if (isset($dl) && $dl) {
         $lastNode = null;
         foreach ($dl as $n) {
             if ($n->nodeType == 1) {
                 if ($lastNode !== $n) {
                     // use $lastNode to help prevent duplicate nodes
                     $this->elms[] = $n;
                     // from being added to matched elements as reported by Damir - On rare occations duplicated elements where returned when using XPath with PHP 5.2.9
                     $this->_length++;
                 }
                 $lastNode = $n;
             }
         }
     }
     return $this;
 }
示例#2
0
 public function __construct($xhtml = '', $charset = null, $type = null)
 {
     parent::__construct();
     $this->_endResponse = false;
     // get instance of Raxan main class
     $this->Raxan = Raxan::singleton();
     // set start time must be set before page_config
     if ($this->showRenderTime) {
         $this->_startTime = Raxan::startTimer();
     }
     // initialize Raxan
     if (!Raxan::$isInit) {
         Raxan::init();
     }
     // add page to page controller array
     self::$pages[$this->objId] = $this;
     if (self::$mPageId == null) {
         self::$mPageId = $this->objId;
     }
     // script dependencies
     $dep = array('jquery');
     $this->registerScript('jquery-ui', 'jquery-ui', $dep);
     $this->registerScript('jquery-tools', 'jquery-tools', $dep);
     $this->registerScript('jquery-ui-utils', 'jquery-ui-utils', $dep);
     $this->registerScript('jquery-ui-effects', 'jquery-ui-effects', $dep);
     $this->registerScript('jquery-ui-interactions', 'jquery-ui-interactions', $dep);
     // call page setup
     if (Raxan::$isDebug) {
         Raxan::debug('Page _config()');
     }
     $this->_config();
     Raxan::triggerSysEvent('page_config', $this);
     // apply default page settings to the specified page object
     $c = Raxan::config();
     if (!isset($this->localizeOnResponse)) {
         $this->localizeOnResponse = $c['page.localizeOnResponse'];
     }
     if (!isset($this->showRenderTime)) {
         $this->showRenderTime = $c['page.showRenderTime'];
     }
     if (!isset($this->initStartupScript)) {
         $this->initStartupScript = $c['page.initStartupScript'];
     }
     if (!isset($this->resetDataOnFirstLoad)) {
         $this->resetDataOnFirstLoad = $c['page.resetDataOnFirstLoad'];
     }
     if (!isset($this->preserveFormContent)) {
         $this->preserveFormContent = $c['page.preserveFormContent'];
     }
     if (!isset($this->disableInlineEvents)) {
         $this->disableInlineEvents = $c['page.disableInlineEvents'];
     }
     if (!isset($this->masterTemplate)) {
         $this->masterTemplate = $c['page.masterTemplate'];
     }
     if (!isset($this->serializeOnPostBack)) {
         $this->serializeOnPostBack = $c['page.serializeOnPostBack'];
     }
     if (!isset($this->degradable)) {
         $this->degradable = $c['page.degradable'];
     }
     // set clientPostbackUrl
     if (!isset($this->clientPostbackUrl)) {
         $this->clientPostbackUrl = Raxan::currentURL();
     }
     // load default settings, charset, etc
     $this->_charset = $charset ? $charset : $c['site.charset'];
     $this->doc = self::createDOM(null, $this->_charset);
     $this->doc->initPageController($this->objId);
     $this->source($xhtml, $type);
     // set document source
     // init postback variables
     $this->isPostBack = $this->isPostback = count($_POST) ? true : false;
     // @todo: deprecate $t->isPostback
     $this->isAjaxRequest = $this->isCallback = isset($_POST['_ajax_call_']) ? true : false;
     if (isset($_GET['embed'])) {
         $em = $_GET['embed'];
         $opt = ($this->isEmbedded = isset($em['js'])) ? $_GET['embed']['js'] : '';
         $this->embedOptions = $opt;
     }
     // get active view. defaults to index view
     $hasVuHandler = false;
     if (isset($_GET['vu'])) {
         preg_match('/[a-z0-9_]+/i', $_GET['vu'], $matches);
         // get view name from url (vu)
         $this->activeView = $matches ? trim($matches[0]) : '';
     }
     if (!$this->activeView) {
         $this->activeView = 'index';
     }
     // call page  _init, _*Views and _load event handlers
     if (Raxan::$isDebug) {
         Raxan::debug('Page _init()');
     }
     $this->_init();
     $this->isInitialized = true;
     Raxan::triggerSysEvent('page_init', $this);
     // check authorization
     if (!$this->_endResponse) {
         if (Raxan::$isDebug) {
             Raxan::debug('Page _authorize()');
         }
         $this->isAuthorized = $this->_authorize();
         $pluginAuth = Raxan::triggerSysEvent('page_authorize', $this);
         if ($this->isAuthorized && $pluginAuth !== null) {
             $this->isAuthorized = $pluginAuth;
         }
     }
     if ($this->isAuthorized || $this->_endResponse) {
         // continue if authized or _endResponse = true
         // initialize view
         if (!$this->_endResponse) {
             $hasVuFile = false;
             $vu = $this->activeView;
             $vuHandler = '_' . $vu . 'View';
             $autov = $this->autoAppendView;
             if ($autov) {
                 if ($autov !== true && is_string($autov)) {
                     $vuFile = str_replace('{view}', $vu, $autov);
                 } else {
                     // default view file name
                     $filePrefix = basename(isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : $_SERVER['SCRIPT_NAME']);
                     $filePrefix = substr($filePrefix, 0, strrpos($filePrefix, '.'));
                     $filePrefix = str_replace(array('/', '\\', ' '), '', $filePrefix);
                     // remove special chars from script name
                     $vuFile = $filePrefix . '.' . $vu . '.php';
                 }
                 $hasVuFile = file_exists($c['views.path'] . $vuFile);
                 if ($hasVuFile) {
                     if (Raxan::$isDebug) {
                         Raxan::debug('Page  - Load view ' . $vuFile);
                     }
                     $this->appendView($vuFile);
                 }
             }
             if ($vu != 'index') {
                 $hasVuHandler = method_exists($this, $vuHandler);
             }
             if ($hasVuHandler || $vu == 'index') {
                 if (Raxan::$isDebug) {
                     Raxan::debug('Page ' . $vuHandler . '()');
                 }
                 $this->{$vuHandler}();
                 // call view handler
             } else {
                 if (!$hasVuFile) {
                     // view handler or file not found
                     Raxan::sendError(Raxan::locale('view_not_found'));
                 }
             }
         }
         // initialize UI Widgets
         $this->initUIWidgets();
         // initialize inline events
         $this->initInlineEvents();
         // initialize preserved state
         $this->initPreservedElements();
         // initialize hidden elments
         $dl = $this->doc->xQuery('//*[@xt-hidefromclient]');
         if ($dl->length) {
             foreach ($dl as $node) {
                 $node->removeAttribute('xt-hidefromclient');
                 $this->hideElementFromClient($node, true);
             }
         }
         // load page and widgets
         if (Raxan::$isDebug) {
             Raxan::debug('Page _load()');
         }
         if (!$this->_endResponse) {
             $this->_load();
             $this->isLoaded = true;
             $this->loadUIWidgets();
             Raxan::triggerSysEvent('page_load', $this);
         }
         // update form elements
         if ($this->preserveFormContent && $this->isPostBack) {
             if (Raxan::$isDebug) {
                 Raxan::debug('Page - Restore Form State');
             }
             $this->updateFormFields();
             // update form fields on postbacks
         }
     } else {
         // if authorization failed then return HTTP: 403
         Raxan::sendError(Raxan::locale('unauth_access'), 403);
     }
 }