Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 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();
 }