/** * Edit * - Edit an RSS Item * * @param string $id * @param string $title * @param string $link * @param string $desc * @param array $other * @see Rss->add() above * @return bool */ public function edit($id, $title, $link, $desc = null, array $other = array()) { if ($this->isRemote) { throw new Rss_RemoteFeed(); } $channels = $this->feed->getElementsByTagName('channel'); if ($channels->length == 0) { throw new Rss_NoFeedInfo(); } // Get the item that we'll be editing $item = $this->feed->getElementById($id); if (is_null($item)) { $this->_log->message('RSS could not edit item "' . $id . '" as it does not exist', Log::L_INFO); throw new Rss_ItemNoExist('unable to edit item "' . $id . '" as it does not exist'); } // Save repeating code, get the foreach loop to handle them $other['title'] = $title; $other['link'] = $link; $other['guid'] = $link; $other['description'] = is_null($desc) ? null : $this->prepareDescription($desc, $link); $other = array_filter($other); // Update $this->items foreach ($other as $name => $value) { if (is_array($value)) { $value = $value['content']; } $this->items[$id][$name] = $value; } // Loop over all elements and update them foreach ($other as $key => $value) { $tmpNode = $item->getElementsByTagName($key)->item(0); // Remove the content of the node. Causes issues if you append straight off $tmpNode->nodeValue = ''; if (is_array($value)) { if (zula_needs_cdata($value['content'])) { // Replace any <![CDATA[ or ]]> with an encoded version so it doesn't cause issues. $val = str_replace(array('<![CDATA[', ']]>'), array('<![CDATA[', ']]>'), $value); $child = $this->feed->createCDATASection($value['content']); } else { $child = $this->feed->createTextNode($value['content']); } $element = $tmpNode->appendChild($child); // Unset the content so it isn't added again later unset($value['content']); // Set attributes for the element foreach ($value as $attr => $value) { $element->setAttribute($attr, $val); } } else { if (zula_needs_cdata($value)) { // Replace any <![CDATA[ or ]]> with an encoded version so it doesn't cause issues. $val = str_replace(array('<![CDATA[', ']]>'), array('<![CDATA[', ']]>'), $value); $tmpNode->appendChild($this->feed->createCDATASection($value)); } else { $tmpNode->appendChild($this->feed->createTextNode($value)); } } } Hooks::notifyAll('rss_item_edit', $this->name, $id, $title, $link, $desc, $other); return true; }
/** * Adds a new controller to the layout XML. The unique ID of the attached * cntrlr will be returned. * * @param string $sector * @param array $details * @param int $id * @return int */ public function addController($sector, array $details, $id = null) { $details = array('id' => $id ? $id : $this->makeCntrlrUid(), 'sector' => $sector, 'order' => isset($details['order']) ? $details['order'] : 0, 'mod' => isset($details['mod']) ? $details['mod'] : 'index', 'con' => isset($details['con']) ? $details['con'] : 'index', 'sec' => isset($details['sec']) ? $details['sec'] : 'index', 'config' => array_merge(array('displayTitle' => true, 'customTitle' => ''), isset($details['config']) ? $details['config'] : array())); // Create the new element with attributes $cntrlrElement = $this->dom->createElement('controller'); foreach (array('id', 'sector', 'order') as $attr) { $attrElement = $this->dom->createAttribute($attr); $attrElement->appendChild($this->dom->createTextNode($details[$attr])); $cntrlrElement->appendChild($attrElement); } // Add all of the elements for this controller. foreach (array('mod', 'con', 'sec', 'config') as $key) { $val = $details[$key]; $element = $this->dom->createElement($key); if (is_array($val)) { // Configuration values, currently only 1 level foreach ($val as $confKey => $confVal) { $confElement = $this->dom->createElement($confKey); $method = zula_needs_cdata($confVal) ? 'createCDATASection' : 'createTextNode'; $confElement->appendChild($this->dom->{$method}((string) $confVal)); $element->appendChild($confElement); } } else { $method = zula_needs_cdata($val) ? 'createCDATASection' : 'createTextNode'; $element->appendChild($this->dom->{$method}($val)); } $cntrlrElement->appendChild($element); } $this->dom->documentElement->appendChild($cntrlrElement); /** * Add ACL resource with default permissions (if needed), cleanup and return */ $resource = 'layout_controller_' . $details['id']; if (!$this->_acl->resourceExists($resource)) { $this->_acl->allow($resource, 'group_guest'); $this->_acl->allow($resource, 'group_root'); } $this->_cache->delete('layout_cntrlrs_' . $this->name); Hooks::notifyAll('layout_add_cntrlr', $details); return $details['id']; }