function __construct($type = self::PANEL, $dry_run = false, $step = false, $manual = false, $internal = false, $build = false) { if ($build) { $build = strtok(substr($build, 1), "?"); $build_params = ArrayUtil::queryStringToArray(strtok("?")); $this->build = $build; } else { if (self::$instance) { return true; } } self::$started = true; if (!defined("NODES")) { define("NODES", 1); } if (!defined("VALUES")) { define("VALUES", 2); } if (!defined("ATTRIBUTES")) { define("ATTRIBUTES", 3); } if (!defined("PAIRS")) { define("PAIRS", 4); } $this->root = sfConfig::get("sf_root_dir"); $this->schemaLocation = $this->root . "/plugins/appFlowerPlugin/schema/appflower.xsd"; // Reading parser YML config //$tmp = sfYaml::load($this->root."/plugins/appFlowerPlugin/config/app.yml"); $this->remove_fields = sfConfig::get("app_parser_remove_fields"); // Context info $this->context = sfContext::getInstance(); // Set Application.. $this->application = $this->context->getConfiguration()->getApplication(); // Set user $this->user = $this->context->getUser(); // Add JS file list //$this->loadJSFilesList(); // Action attributes.. $actionInstance = $this->context->getActionStack()->getLastEntry()->getActionInstance(); $this->attribute_holder = $actionInstance->getVarHolder()->getAll(); // Request $this->request = $actionInstance->getRequest()->getParameterHolder()->getAll(); foreach ($this->request as $param => $value) { if (!array_key_exists($param, $this->attribute_holder)) { $this->attribute_holder[$param] = $value; } } $this->currentUri = $actionInstance->getModuleName() . "/" . $actionInstance->getActionName(); if ($build) { $uri = $build; $module = strtok($build, "/"); $action = strtok("/"); $this->currentUri = $module . "/" . $action; } else { $uri = $actionInstance->getModuleName() . "/" . $actionInstance->getActionName(); $module = $actionInstance->getModuleName(); $action = $actionInstance->getActionName(); } $this->vars[$uri] = $this->attribute_holder; if ($build) { $config_vars = afConfigUtils::getConfigVars(strtok($build, "/"), strtok("/"), $this->context->getRequest()); if ($build_params) { foreach ($build_params as $n => $p) { $config_vars[$n] = $p; } } $this->vars[$uri] = $config_vars; $actionInstance->getVarHolder()->add($config_vars); } // Assign DOM Document.. if (!$build) { $this->readXmlDocument(); } else { $this->readXmlDocument(null, false, $build); } if (sfContext::getInstance()->has('profiler')) { $timer = sfTimerManager::getTimer('afRead'); $timer->addTime(); $timer = sfTimerManager::getTimer('afRender'); } parent::__construct($this->document); $root = $this->document->getElementsByTagName("view")->item(0); $view_type = $root->getAttribute("type"); $dynamic = $root->getAttribute("dynamic"); $actionInstance->view = $view_type; if ($view_type == "layout") { $this->layoutModule = $actionInstance->layoutModule = $root->getAttribute("module"); } $view_type = XmlBaseElementParser::parseValue($view_type, $root, true); $this->set("type", $view_type, $root); // Is this a Dynamic widget? If so, let's create update XML DOM. $this->namespace = $this->document->lookupNamespaceUri("i"); if ($dynamic === "true") { $this->buildXmlDocument($module, $view_type); } // Parser type if ($view_type == "layout") { $this->type = self::PAGE; } else { if ($view_type == "wizard") { $this->type = self::WIZARD; } else { $this->type = self::PANEL; } } // Is this a layout? $this->page = $view_type; try { if (!file_exists($this->schemaLocation) || !is_readable($this->schemaLocation)) { throw new XmlParserException("Was unable to read main schema document. Please check " . $this->schemaLocation . "!"); } else { if ($this->type === self::WIZARD && !isset($this->attribute_holder["current"])) { throw new XmlParserException("The step parameter must be defined in case of wizard layout!"); } } if (isset($this->attribute_holder["current"])) { $this->current = $this->attribute_holder["current"]; } if ($this->type === self::WIZARD && !$this->current) { throw new XmlParserException("The value of step parameter must be either false or a positive number!"); } $this->step = $step; if ($this->type === self::WIZARD && !isset($this->attribute_holder["step"])) { throw new XmlParserException("Required variable step cannot be found in attribute holder!"); } } catch (Exception $e) { throw $e; } if ($dry_run) { return true; } // Reading default footer and sidebar data if (!$build) { $this->parseDefaultPanels(); } // Reading Main XML Schema.. $this->schema = new DOMDocument(); $this->schema->load($this->schemaLocation); // Reading enum values.. $this->fetchEnums(); // Check widget access rights if ($this->type === self::PANEL || $this->type === self::WIZARD) { $this->checkWidgetCredentials(); } $this->enumCheck("i:viewType", $view_type); if ($this->type === self::WIZARD && isset($this->attribute_holder["init"])) { if (!$this->fetch("//i:datastore")->length) { $this->datastore = false; } else { $this->datastore = true; } } if ($build) { $this->runParser($build, "object"); } else { // Create layout if ($this->type === self::PANEL) { $this->panelIdXml = $this->context->getModuleName() . "/" . $this->context->getActionName(); self::$masterLayout = null; $this->layout = new afExtjsPanelLayout(); } else { if (self::$instance === null) { self::$instance = true; } if ($this->type === self::WIZARD) { $this->isTabbed(); if (!$this->tabbedWizard) { $wizattrs = array('id' => 'center_panel', 'title' => ""); } else { $wizattrs = array('id' => 'center_panel', 'title' => "", 'centerType' => 'group'); } $this->layout = new afExtjsWizardLayout($wizattrs); } else { $this->portalIdXml = $this->context->getModuleName() . "/" . $this->context->getActionName(); $this->portalStateObj = afPortalStatePeer::retrieveByIdXml($this->portalIdXml); if (!$this->portalStateObj) { //default values for layout & columns $this->portalConfig = new stdClass(); $this->portalConfig->layoutType = $this->fetch("//i:tab")->length ? afPortalStatePeer::TYPE_TABBED : afPortalStatePeer::TYPE_NORMAL; $this->portalConfig->content = array(); $this->portalConfig->content[0]["portalLayoutType"] = sfConfig::get("app_parser_default_layout", "[100]"); $this->portalConfig->idXml = $this->portalIdXml; } } if ($this->layout) { self::$masterLayout = $this->layout; } } $this->manualMode = $manual; /** * widget help settings * * ticket #300 - radu */ $this->widgetHelpSettings = afWidgetHelpSettingsPeer::retrieveCurrent(); // Application menu.. if ($this->context->getRequest()->getAttribute("af_first_page_request")) { /*$this->parseMenu(null,$this->layout->toolbar); print_r($this->buttons); exit(); foreach($this->buttons as $button) { if(isset($button["menus"])) { for($i = sizeof($button["menus"])-1; $i >= 0; $i--) { $button["menus"][$i]->end(); } } $button["button"]->end(); } sfProjectConfiguration::getActive()->loadHelpers(array('afExtjsToolbar')); */ } if (!$manual) { $this->runParser(1, "content"); } } }
/** * retrieving description and images for some widgets * @author radu */ public function executeRetrieveWidgetsInfo() { $config = $this->hasRequestParameter('config') ? $this->getRequestParameter('config') : false; $portalWidgets = $this->hasRequestParameter('portalWidgets') ? $this->getRequestParameter('portalWidgets') : false; if ($config && $portalWidgets) { $config = json_decode($config); $content = get_object_vars($config->content); unset($config->content); $config->content[$config->layoutItem] = $content; unset($content); $portalWidgets = json_decode($portalWidgets); $i = 0; foreach ($portalWidgets as $pwi => $portalWidgetsFielset) { $i++; $result['rows'][$i]['title'] = $portalWidgetsFielset->title; $result['rows'][$i]['image'] = ''; $result['rows'][$i]['widget'] = ''; $result['rows'][$i]['description'] = ''; $result['rows'][$i]['_selected'] = false; $result['rows'][$i]['_is_leaf'] = false; $result['rows'][$i]['_parent'] = null; $result['rows'][$i]['_id'] = $i; $j = $i; $parentChecked = false; foreach ($portalWidgetsFielset->widgets as $pfwi => $widget) { $j++; $ma = explode('/', $widget); $image = $title = $description = ''; $checked = afPortalStatePeer::searchForWidgetInState($config, $widget); $path = sfConfig::get("sf_root_dir") . '/apps/' . $this->context->getConfiguration()->getApplication() . '/modules/' . $ma[1] . '/config/' . $ma[2] . '.xml'; if (file_exists($path)) { $action_config_vars = afConfigUtils::getConfigVars($ma[1], $ma[2], $this->getRequest()); $dom = new DOMDocument(); if ($dom->load($path)) { foreach ($dom->documentElement->childNodes as $oChildNode) { if ($oChildNode->nodeName == 'i:title') { $title = XmlBaseElementParser::parseValue(trim($oChildNode->nodeValue), $oChildNode, false, $action_config_vars); } if ($oChildNode->nodeName == 'i:description') { $description = XmlBaseElementParser::parseValue(trim($oChildNode->nodeValue), $oChildNode, false, $action_config_vars); $image = $oChildNode->getAttribute('image'); } } /** * if image exists ok, but the images are saved in /images/widgets * same as the widget title, so try to get image */ if (empty($image) && file_exists(sfConfig::get("sf_root_dir") . "/web/images/widgets/" . $title . ".PNG")) { $image = "/images/widgets/" . $title . ".PNG"; } if (!isset($description)) { $description = ""; } $image = empty($image) ? '/appFlowerPlugin/images/defaultWidget.gif' : $image; $image = '<img src="' . $image . '" style="margin-right:5px; border:1px solid #99bbe8; padding:3px;float:left;">'; } $result['rows'][$j]['title'] = $title; $result['rows'][$j]['image'] = $image; $result['rows'][$j]['widget'] = $widget; $result['rows'][$j]['description'] = $description; $result['rows'][$j]['_selected'] = $checked; $result['rows'][$j]['_is_leaf'] = true; $result['rows'][$j]['_parent'] = $i; $result['rows'][$j]['_id'] = $j; if ($checked) { $parentChecked = true; } } } $result['rows'][$i]['_selected'] = $parentChecked; $i = $j; } $result['success'] = true; $result['totalCount'] = count($result['rows']); $result['rows'] = array_values($result['rows']); $info = json_encode($result); } else { $info = json_encode(array('success' => false, 'message' => 'Retrieving widgets information wasn\'t successful!')); } return $this->renderText($info); }
public function get($node, $nodevalue = -1, $array = false) { try { if (is_object($node)) { if ($nodevalue == -1) { if (!property_exists($node, "nodeValue")) { throw new XmlParserException("Bad input parameter, only strings and DOMElement objects are accepted!"); } return trim($array ? explode($array, XmlBaseElementParser::parseValue($node->nodeValue, $node)) : XmlBaseElementParser::parseValue($node->nodeValue, $node)); } else { if (!$node->hasAttribute($nodevalue)) { throw new XmlParserException("Bad input parameter, the " . $node->nodeName . " object has no " . $nodevalue . " attribute!"); } return trim($array ? explode($array, XmlBaseElementParser::parseValue($node->getAttribute($nodevalue), $node, true)) : XmlBaseElementParser::parseValue($node->getAttribute($nodevalue), $node, true)); } } else { return trim($node); } } catch (Exception $e) { throw $e; } }