/** * Pre-execute action - before every action * * @author Sergey Startsev */ public function preExecute() { $module_name = $this->getModuleName(); $action_name = $this->getActionName(); // init widget uri $this->widgetUri = "{$module_name}/{$action_name}"; // getting xml file path $xmlCU = new afConfigUtils($module_name); $xml_path = $xmlCU->getConfigFilePath($action_name . '.xml', true); // initialize dom document $this->dom_xml = new DOMDocument(); $this->dom_xml->preserveWhiteSpace = false; $this->dom_xml->formatOutput = true; $this->dom_xml->load($xml_path); $this->dom_xml_xpath = new DOMXPath($this->dom_xml); // getting datasource class $peerClassName = $this->getDatasource(); if (!empty($peerClassName) && class_exists($peerClassName)) { $modelClassName = constant("{$peerClassName}::OM_CLASS"); $formClassName = "{$modelClassName}Form"; $this->tryToLoadObjectFromRequest($peerClassName); if (!$this->object) { $this->createNewObject($modelClassName); } $this->createAndConfigureForm($formClassName); } }
function XmlValidator($path = null, $security = false, $cli = false, $cache_only = false, $idxml = null) { $this->root = sfConfig::get("sf_root_dir"); if (!$security) { $this->schema = $this->root . "/plugins/appFlowerPlugin/schema/appflower.xsd"; } else { $this->schema = $this->root . "/access/access.xsd"; } if (!$cli) { $this->application = sfContext::getInstance()->getConfiguration()->getApplication(); $sf = sfContext::getInstance(); $action = $sf->getActionName(); $module = $sf->getModuleName(); } try { if (!$cli) { if (!$path && !trim($action)) { throw new Exception("Unbale to create class, action name argument is missing!"); } else { if (!$path && !trim($module)) { throw new Exception("Unbale to create class, module name argument is missing!"); } } if (!$path) { $fileCU = new afConfigUtils($module); $file = $fileCU->getConfigFilePath($action . '.xml', true); } else { $file = $path; } } if (!file_exists($this->schema)) { throw new XmlValidatorException("The schema file doesn't exist!"); } else { if (!is_readable($this->schema)) { throw new XmlValidatorException("Unbale to read the schema file!"); } } } catch (Exception $e) { throw $e; } libxml_use_internal_errors(true); $this->cache_only = $cache_only; if (trim($idxml)) { $this->idxml = $idxml; } //appflower:validator-cache cache yes if (!$cli) { $this->hash = sha1_file($file); $this->readXmlDocument($file); } }
/** * Returns the XML config DOM document or null. */ public static function getOptionalDoc($module, $action) { $afCU = new afConfigUtils($module); $path = $afCU->getConfigFilePath("{$action}.xml"); if ($path) { $doc = new DOMDocument(); $doc->load($path); return $doc; } return null; }
/** * Returns true for actions with XML config. */ protected function isAppFlowerAction($actionInstance) { $afCU = new afConfigUtils($actionInstance->getModuleName()); return $afCU->getConfigFilePath($actionInstance->getActionName() . ".xml"); }
private function readTemplates() { $this->widgets = $this->getWidgets(); $attribute_holder = sfContext::getInstance()->getActionStack()->getLastEntry()->getActionInstance()->getVarHolder(); $this->multi = true; if ($this->type !== self::WIZARD) { if (!isset($this->process["parses"][0]["areas"]["sidebar"])) { $this->process["parses"][0]["areas"]["sidebar"] = $this->defaultPanels["sidebar"]; } if (!isset($this->process["parses"][0]["areas"]["footer"])) { $this->process["parses"][0]["areas"]["footer"] = $this->defaultPanels["footer"]; } } // Processing afWidgetSelector settings, adding extra widgets. // TODO: Some parts must be changed in 1165!! if ($this->portalStateObj) { $layoutType = $this->portalStateObj->getLayoutType(); $content = $this->portalStateObj->getContent(); $tabs = $this->process["parses"][$this->iteration]["areas"]["content"]["tabs"]; $tabbed = $layoutType == afPortalStatePeer::TYPE_TABBED; foreach ($content as $item) { if ($tabbed) { $title = isset($item["tabTitle"]) ? $item["tabTitle"] : $item["portalTitle"]; } else { $title = null; } foreach ($tabs as $tkk => &$tab) { $tab_id = $tabbed ? $tab["attributes"]["id"] : null; $newtab = true; if (!$title || $tab["attributes"]["title"] == $title) { if (isset($item["portalColumns"])) { foreach ($item["portalColumns"] as $column) { foreach ($column as $component) { $tmp[0] = strtok($component->idxml, "/"); $tmp[1] = strtok("/"); $found = false; foreach ($tab["components"] as $data) { if ($data["module"] == $tmp[0] && $data["name"] == $tmp[1]) { $found = true; break; } } if (!$found) { if ($tmp[0] != '' && $tmp[1] != '') { $this->process["parses"][$this->iteration]["areas"]["content"]["tabs"][$tkk]["components"][self::getComponentKey($tmp[1])] = array("name" => $tmp[1], "module" => $tmp[0], "column" => 0, "refresh" => 0, "container" => "true", "parsable" => "true", "permissions" => "*", "priority" => 0, "params" => null); } else { /** * @todo - check #1274 * I've added conditional statement here to solve problems * caused by invalid afPropelState object */ } } } } } $newtab = false; break; } } if (!$newtab) { continue; } if ($newtab) { $tk = count($this->process["parses"][$this->iteration]["areas"]["content"]["tabs"]); $this->process["parses"][$this->iteration]["areas"]["content"]["tabs"][$tk] = array("attributes" => array("title" => $title, "name" => "", "container" => "true", "parsable" => "true", "permissions" => "*", "priority" => 0, "id" => "tab" . ((int) preg_replace("/[^0-9]+/", "", $tab_id) + 1))); if ($item["portalColumns"][0] != array()) { foreach ($item["portalColumns"] as $ck => $column) { foreach ($column as $component) { $tmp[0] = strtok($component->idxml, "/"); $tmp[1] = strtok("/"); $this->process["parses"][$this->iteration]["areas"]["content"]["tabs"][$tk]["components"][self::getComponentKey($tmp[1])] = array("name" => $tmp[1], "module" => $tmp[0], "column" => $ck, "refresh" => 0, "container" => "true", "parsable" => "true", "permissions" => "*", "priority" => 0, "params" => null); } } } else { $this->process["parses"][$this->iteration]["areas"]["content"]["tabs"][$tk]["components"] = array(); } } } } foreach ($this->process["parses"][$this->iteration]["areas"] as $area_type => $area) { if (!isset($area["tabs"])) { $area["tabs"][0] = array("attributes" => array(), "components" => $area["components"]); } foreach ($area["tabs"] as $k => $tab) { $z = 0; if ($area_type == "content" && $this->portalConfig) { $sizedata = $this->getPortalSizes($this->portalConfig->layoutType == afPortalStatePeer::TYPE_TABBED && $tab["attributes"]["layout"] != 0 ? $tab["attributes"] : $area["attributes"]); $this->portalConfig->content[$k]["portalLayoutType"] = $sizedata[0]; if (isset($tab["attributes"]["title"])) { $this->portalConfig->content[$k]["tabTitle"] = $tab["attributes"]["title"]; } // Create empty columns if (strstr($this->portalConfig->content[$k]["portalLayoutType"], ",")) { $tmpx = explode(",", $this->portalConfig->content[$k]["portalLayoutType"]); foreach ($tmpx as $x) { $this->portalConfig->content[$k]["portalColumns"][] = array(); } } } if (isset($tab['components']) && count($tab['components']) > 0) { foreach ($tab["components"] as $name => $component) { $this->currentUri = $component['module'] . "/" . $component['name']; $arg = 0; if (substr($name, 0, 4) != "tree") { if (isset($component["post"])) { $this->multisubmit = $component["post"]; } // Checking widget permissions if ($this->checkWidgetCredentials($component["module"], $component["name"]) === false) { continue; } //adds all the widgets by default to first column if ($area_type == "content" && !$this->portalStateObj) { if ($this->type !== self::WIZARD) { $idx = $component["column"]; if ($idx >= $sizedata[1]) { throw new XmlParserException("Invalid column reference!"); } } else { $idx = 0; } $this->portalConfig->content[$k]["portalColumns"][$idx][] = new stdClass(); $kx = count($this->portalConfig->content[$k]["portalColumns"][$idx]) - 1; $this->portalConfig->content[$k]["portalColumns"][$idx][$kx]->idxml = $component["module"] . "/" . $component["name"]; } $config_vars = afConfigUtils::getConfigVars($component['module'], $component['name'], $this->context->getRequest()); $this->vars[$component['module'] . "/" . $component['name']] = $config_vars; $attribute_holder->add($config_vars); $fileCU = new afConfigUtils($component['module']); $file = $fileCU->getConfigFilePath($component["name"] . ".xml", true); if (isset($component["params"])) { foreach ($component["params"] as $pname => $pvalue) { $attribute_holder->add(array($pname => $pvalue)); } } $this->readXmlDocument($file); $this->iteration++; $this->process["parses"][$this->iteration]["component"] = $name; $this->process["parses"][$this->iteration]["component_name"] = $component["name"]; $this->process["parses"][$this->iteration]["module"] = $component["module"]; $this->process["parses"][$this->iteration]["area"] = $area_type; $this->process["parses"][$this->iteration]["refresh"] = isset($component['refresh']) ? $component['refresh'] : false; if (($this->getCurrentView() == "edit" || $this->getCurrentView() == "show") && $this->fetch("//i:grouping")->length == 0) { $arg = 1; } $this->runParser($arg); } else { if ($area_type == "content" && !$this->portalStateObj) { if ($this->type !== self::WIZARD) { $idx = $component["column"]; if ($idx >= $sizedata[1]) { throw new XmlParserException("Invalid column reference!"); } } else { $idx = 0; } $idxml = "tree" . $z; $this->portalConfig->content[$k]["portalColumns"][$idx][] = new stdClass(); $kx = count($this->portalConfig->content[$k]["portalColumns"][$idx]) - 1; $this->portalConfig->content[$k]["portalColumns"][$idx][$kx]->idxml = $idxml; } $this->tree = new afExtjsTree(array('title' => $component["title"])); $this->tree_root = $this->tree->startRoot(array("title" => "Startroot")); $this->buildTree($component["rootnode"], 1); foreach (array_reverse($this->tree_item) as $level) { foreach ($level as $f) { $f->end(); } } $this->tree->endRoot($this->tree_root); $this->tree->end(); $this->extobjects[$idxml] = $this->tree; } } } } } if ($this->type == self::PAGE) { if (!$this->portalStateObj) { $this->portalStateObj = afPortalStatePeer::createOrUpdateState($this->portalConfig); } $layoutType = $this->portalStateObj->getLayoutType(); $portalLayoutType = $this->portalStateObj->getPortalLayoutType(); $this->portalContent = $this->portalStateObj->getContent(); $this->portalColumns = $this->portalStateObj->getColumns(); ksort($this->portalColumns); $this->portalColumnsSize = $this->portalStateObj->getColumnsSize(); $portalTools = new afExtjsTools(); if ($layoutType == afPortalStatePeer::TYPE_NORMAL) { $portalWidgets = $this->widgets; $portalTools->addItem(array('id' => 'gear', 'handler' => array('parameters' => 'e,target,portal', 'source' => "\r\n\t\t\t\t if(afApp.hasDesktop()){portal = portal.items.items[0].items.items[0];}\r\n\t\t\t\t \r\n\t\t\t\t\t\tvar layouts=[[100],[50,50],[25,75],[75,25],[33,33,33],[50,25,25],[25,50,25],[25,25,25,25],[40,20,20,20]]; \r\n\t\t\t\t\t\tvar menu=new Ext.menu.Menu({items:[\r\n\t\t\t\t\t\t\t{text: 'Layout Selector', handler:function(){\r\n\t\t\t\t\t\t\t\t\tportal.showLayoutSelector(target,'Layout Selector',layouts);\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_tile_horizontal.png' \r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Widget Selector', handler:function(){\r\n\t\t\t\t\t\t\t\t\tportal.showWidgetSelector(target,'Widget Selector');\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_side_boxes.png'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Reset to Default', handler:function(){\r\n\t\t\t\t\t\t\t\t\tnew Portals().reset(target,portal);\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_lightning.png'\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t ]});\t\t\t\t\t\t \r\n\t\t\t\t\t\tmenu.showAt(e.getXY());"))); } else { // TODO: Thise must be changed in 1165!! $newTabPortalWidgets = $this->filterWidgets(null, $this->portalContent, $this->widgets); $portalWidgets = null; $portalTools->addItem(array('id' => 'gear', 'handler' => array('parameters' => 'e,target,panel', 'source' => "\r\n\t\t\t\t if(afApp.hasDesktop()){panel = panel.items.items[0];}\r\n\t\t\t\t \r\n\t\t\t\t\t\tvar layouts=[[100],[50,50],[25,75],[75,25],[33,33,33],[50,25,25],[25,50,25],[25,25,25,25],[40,20,20,20]];\r\n\t\t\t\t\t\tvar tabpanel=panel.items.items[0];\r\n\t\t\t\t\t\tvar menu=new Ext.menu.Menu({items:[\r\n\t\t\t\t\t\t\t{text: 'Layout Selector', handler:function(){\r\n\t\t\t\t\t\t\t\t\ttabpanel.getActiveTab().items.items[0].showLayoutSelector(target,'Layout Selector for '+tabpanel.getActiveTab().title,layouts);\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_tile_horizontal.png' \r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Widget Selector', handler:function(){\r\n\t\t\t\t\t\t\t\t\ttabpanel.getActiveTab().items.items[0].showWidgetSelector(target,'Widget Selector for '+tabpanel.getActiveTab().title);\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_side_boxes.png'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Add New Tab', handler:function(){\r\n\t\t\t\t\t\t\t\t\tvar newTabPortalWidgets=" . json_encode($newTabPortalWidgets) . ";\r\n\t\t\t\t\t\t\t\t\tnew Portals().createNewTab(target,tabpanel,newTabPortalWidgets);\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_add.png'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Remove Tab', handler:function(){\r\n\t\t\t\t\t\t\t\t\tnew Portals().removeTab(target,tabpanel);\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_delete.png'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Change Title', handler:function(){\r\n\t\t\t\t\t\t\t\t\tnew Portals().changeTitle(target,tabpanel);\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_edit.png'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Reset to Default', handler:function(){\r\n\t\t\t\t\t\t\t\t\tnew Portals().reset(target,tabpanel.getActiveTab().items.items[0]);\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_lightning.png'\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t ]});\t\t\t\t\t\t \r\n\t\t\t\t\t\tmenu.showAt(e.getXY());"))); } $this->layout = new afExtjsPortalLayout(array('id' => 'center_panel', 'tools' => $portalTools, 'idxml' => $this->portalIdXml, 'layoutType' => $layoutType, 'portalLayoutType' => $portalLayoutType, 'portalWidgets' => $portalWidgets)); self::$masterLayout = $this->layout; } $this->postProcess(); }