/**
  * 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 static final function clearRetVal()
 {
     self::$ret = array();
 }
 public function readXmlDocument($path = null, $security = false, $uri = false)
 {
     $page = false;
     if (!$uri) {
         $action = sfContext::getInstance()->getActionName();
         $module = sfContext::getInstance()->getModuleName();
     } else {
         $module = strtok($uri, "/");
         $action = strtok("/");
     }
     if ($path === null) {
         $pathCU = new afConfigUtils($module);
         $path = $pathCU->getConfigFilePath($action . '.xml', true);
         if (strstr($path, "page")) {
             $page = true;
         }
     }
     $hash = sha1_file($path);
     $obj = afValidatorCachePeer::inCache($path);
     if (!$obj || $obj->getSignature() != $hash) {
         $doc = new XmlValidator($path, $security, false, false, $page ? $this->context->getModuleName() . "/" . $this->context->getActionName() : null);
         $doc->validateXmlDocument();
         $this->document = $doc->getXmlDocument();
         $this->validator = $doc;
     } else {
         $this->document = new DOMDocument();
         $this->document->load($path);
     }
     parent::setNamespace($security);
     parent::setXmlDocument($this->document);
     parent::setXpath();
     XmlBaseElementParser::clearRetVal();
 }
 public static function parse($node, $parent, $key = null)
 {
     $type = self::$parser->get($node, "type");
     $name = self::$parser->get($parent, "name");
     $process = self::$parser->getProcess();
     $iteration = self::$parser->getIteration();
     $default = self::$parser->fetch("./i:default|./i:static", $node);
     $defvalue = $selected = "";
     if ($default->length) {
         $default = $default->item(0);
         $kname = self::$parser->name($default, true);
         $children = self::$parser->fetch("./i:node", $default);
         if ($children->length) {
             parent::parseNodes($children, $defvalue, $selected);
             if ($selected) {
                 self::add("fields/" . $name . "/value/" . $kname . "/selected", $selected);
             }
         } else {
             $defvalue = self::$parser->get($default);
         }
         self::add("fields/" . $name . "/value/" . $kname . "/value", $defvalue);
     }
     if (self::$parser->find($node, "source")) {
         self::add("fields/" . $name . "/value/type", "1");
         self::add("fields/" . $name . "/value/class", $process["parses"][$iteration]["datasource"]["class"]);
         self::add("fields/" . $name . "/value/method", self::$parser->get(self::$parser->getnode("source", $node), "name"));
     } else {
         if (self::$parser->find($node, "item")) {
             self::add("fields/" . $name . "/value/type", "3");
             $nodes = self::$parser->fetch("./i:item", $node);
             $it = new nodeListIterator($nodes, PAIRS);
             $ls = $it->getList();
             $ls_arr = array();
             foreach ($ls as $node) {
                 $ls_arr[$node->getAttribute("value")] = $node->nodeValue;
             }
             $it->setList($ls);
             self::add("fields/" . $name . "/value/default/value", $ls_arr);
             //$it->setAttribute("value");
             //self::add("fields/".$name."/value/items",$it);
         } else {
             if ($node) {
                 $class = self::$parser->get(self::$parser->getnode("class", $node));
                 if ($class) {
                     self::add("fields/" . $name . "/value/type", "2");
                     self::add("fields/" . $name . "/value/class", $class);
                     $method = self::$parser->getnode("method", $node);
                     if ($method) {
                         self::add("fields/" . $name . "/value/method/name", self::$parser->get($method, "name"));
                         $nodes = self::$parser->fetch("./i:param", $method);
                         $it = new nodeListIterator($nodes);
                         if ($it->getListLength() > 0) {
                             self::parseValues($it);
                             $it->rewind();
                             //$it->setMode(VALUES);
                         }
                         $i = 0;
                         foreach ($it as $v) {
                             $val = self::$parser->get($v);
                             if (!property_exists($v, "non_convertable") && substr($val, 0, 1) == "[") {
                                 $val = explode(",", preg_replace("/[\\[\\]]+/", "", $val));
                             }
                             self::add("fields/" . $name . "/value/method/params/" . $i, $val);
                             $i++;
                         }
                     }
                 } else {
                     if ($type == 'orm') {
                         // falling back to class defined in datasource node with guessed getter method name
                         self::add("fields/" . $name . "/value/type", "1");
                         self::add("fields/" . $name . "/value/class", $process["parses"][$iteration]["datasource"]["class"]);
                         $nameParts = explode('[', $name);
                         $nameParts = array_reverse($nameParts);
                         $originalName = str_replace(']', '', $nameParts[0]);
                         $originalNameGetterMethod = 'get' . sfInflector::camelize($originalName);
                         self::add("fields/" . $name . "/value/method", $originalNameGetterMethod);
                     }
                 }
             }
         }
     }
     return true;
 }
 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;
     }
 }