/** * 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 true if the given action could be loaded with widget_load. * Wizards do not support that. They want to be displayed without menus. */ protected function isWidgetAction($actionInstance) { $module = $actionInstance->getModuleName(); $action = $actionInstance->getActionName(); $doc = afConfigUtils::getOptionalDoc($module, $action); if (!$doc) { return false; } $view = afDomAccess::wrap($doc, 'view', new afVarScope($actionInstance->getVarHolder()->getAll())); return $view->get('@type') !== 'wizard'; }
/** * Direct checking whether user has credential for module,action */ public static function actionHasCredential($module, $action) { $actionInstance = afConfigUtils::getActionInstance($module, $action); $user = sfContext::getInstance()->getUser(); if (!$actionInstance->isSecure()) { return true; } else { if (!$user->isAuthenticated()) { return false; } } $credentials = $actionInstance->getCredential(); /** * the action might not have any credentials set, so allow access */ if ($credentials == null) { return true; } else { if ($user->hasCredential($credentials)) { return true; } } }
<?php include dirname(__FILE__) . '/../bootstrap/dbunit.php'; $t = new lime_test(3, new lime_output_color()); $doc = afConfigUtils::getDoc('networkmonitor_snmp', 'editSnmpPackage'); $view = afDomAccess::wrap($doc, 'view'); $fields = $view->wrapAll('fields/field'); $t->is(count($fields), 3); $t->is(afEditView::getParams($fields[1], 'validator/param'), array('class' => 'SnmpPackage', 'column' => 'name', 'unique_error' => 'This name is already used. Please choose another one!')); $validators = json_decode('{"edit[name]":{"immValidatorUnique":{"params":{"class":"SnmpPackage","column":"name","unique_error":"This name is already used. Please choose another one!"}}},"edit[template]":{"immValidatorRequired":[]}}', true); $t->is(afEditView::getValidators($fields), $validators);
/** * 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; }
<?php include dirname(__FILE__) . '/../bootstrap/dbunit.php'; $t = new lime_test(9, new lime_output_color()); $doc = afConfigUtils::getDoc('server', 'listServer'); $view = afDomAccess::wrap($doc, 'view'); $t->is($view->get('datasource@type'), 'orm'); $t->is($view->get('datasource/method@name'), 'getAllServer'); $t->is($view->getBool('datasource/no_such_element'), false); $t->is($view->getBool('datasource/no_such_element', true), true); $columns = $view->wrapAll('fields/column'); $t->is(count($columns), 10); $t->is($columns[0]->get('@name'), 'name'); $t->is($columns[1]->get('@name'), 'is_enabled'); $t->is($columns[9]->get('@name'), 'c_i_a'); $actions = $view->wrapAll('actions/action'); $t->is(count($actions), 4);
/** * 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); }
protected function readWidgetConfig() { return afConfigUtils::getDoc($this->module, $this->action); }
<?php include dirname(__FILE__) . '/../bootstrap/dbunit.php'; $t = new lime_test(1, new lime_output_color()); $t->is(afConfigUtils::getPath('server', 'listServer'), '/usr/www/manager/apps/frontend/modules/server/config/listServer.xml');
<?php include dirname(__FILE__) . '/../bootstrap/dbunit.php'; $t = new lime_test(1, new lime_output_color()); $doc = afConfigUtils::getDoc('networkmonitor_snmp', 'listSnmpGroup'); $view = afDomAccess::wrap($doc, 'view'); $listView = new afListView($view); $t->is($listView->getSelectedColumns(), array('name', 'body', 'id'));
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(); }