/** * Get a html representation of a NodeSettings object * @param joppa\model\NodeSettings $nodesettings * @return string html representation of the NodeSettings object */ private function getHtmlFromNodeSettings(NodeSettings $nodeSettings) { $inheritedSettings = $nodeSettings->getInheritedNodeSettings(); if ($inheritedSettings) { $arrayInheritedSettings = $inheritedSettings->getArray(true, true); } else { $arrayInheritedSettings = array(); } $arraySettings = $nodeSettings->getArray(); $settings = Structure::merge($arrayInheritedSettings, $arraySettings); ksort($settings); $html = ''; foreach ($settings as $key => $setting) { $value = $setting->getIniString(true); if ($setting->inherit) { $value = substr($value, 1); } if (isset($arraySettings[$key])) { $html .= '<strong>' . $value . '</strong>'; } else { $html .= $value; } $html .= "<br />\n"; } return $html; }
public function testMerge() { $array1 = array('key1' => 'value1', 'key2' => 'value2'); $array2 = array('key1' => 'value2', 'key3' => 'value3'); $array3 = array('key1' => 'value2', 'key2' => 'value2', 'key3' => 'value3'); $array = Structure::merge($array1, $array2); $this->assertEquals($array3, $array); }
/** * Add a empty value to the option * @param string $value label of the option * @param string $key key of the option * @return null */ public function addEmpty($value = '---', $key = 0) { $model = ModelManager::getInstance()->getModel(CountryModel::NAME); $country = $model->createData(false); $country->id = $key; $country->name = $value; $this->options = Structure::merge(array('---' => array($key => $country)), $this->options); }
/** * Get the routes from the Joppa system combined with the routes from the fallback router * @return array Array with the route as key and a Route object as value */ public function getRoutes() { $model = ModelManager::getInstance()->getModel(NodeModel::NAME); $routes = $model->getNodeRoutes(); foreach ($routes as $route) { $routes[$route] = new Route($route, self::FRONTEND_CONTROLLER); } return Structure::merge(parent::getRoutes(), $routes); }
/** * Reads the routes from the data source * @return array Array with Route instances */ protected function readRoutes() { $routes = array(); $files = array_reverse(Zibo::getInstance()->getFiles(self::PATH_FILE)); foreach ($files as $file) { $fileRoutes = $this->readRoutesFromFile($file); $routes = Structure::merge($routes, $fileRoutes); } return $routes; }
/** * Read all the models in the Zibo file system structure * @param boolean $onlyInModules Set to true to only read in the modules directory * @return array Array with Model instances */ public function readModelsFromIncludePaths($onlyInModules = false) { $models = array(); $includePaths = array_reverse(Zibo::getInstance()->getIncludePaths()); if ($onlyInModules) { array_pop($includePaths); array_shift($includePaths); } foreach ($includePaths as $includePath) { $pathModels = $this->readModelsFromPath(new File($includePath)); $models = Structure::merge($models, $pathModels); } return $models; }
protected function applyPagination() { $this->countRows = count($this->parents) + count($this->values); $this->values = Structure::merge($this->parents, $this->values); if (!$this->pageRows) { return; } $this->paginationPages = ceil($this->countRows / $this->pageRows); if ($this->page > $this->pages || $this->page < 1) { $this->page = 1; } $offset = ($this->page - 1) * $this->pageRows; $this->values = array_slice($this->values, $offset, $this->pageRows, true); }
/** * Render a subview for this view * * All the styles and scripts of the subview will be added to the main view * * @param zibo\core\View $view the view to render * @return string The output of the view */ protected function renderView(View $view) { $renderedView = $view->render(true); if (!$view instanceof HtmlView) { return $renderedView; } $this->meta = Structure::merge($this->meta, $view->getMeta()); $this->styles = Structure::merge($this->styles, $view->getStyles()); $this->scripts = Structure::merge($this->scripts, $view->getJavascripts()); $this->inlineScripts = Structure::merge($this->inlineScripts, $view->getInlineJavascripts()); return $renderedView; }
/** * Gets the log for a data object * @param string $modelName Name of the data model * @param integer $id Primary key of the data * @param integer $version If provided, the log of this version will be retrieved, else all logs * @param string $locale * @return array Array with LogData objects */ public function getLog($modelName, $id, $version = null, $locale = null) { $logs = $this->getChanges($modelName, $id, $version, $locale); $logs = array_reverse($logs); $versions = array(); foreach ($logs as $log) { $id = $log->dateAdded; if (!$log->changes && $log->dataModel != $modelName) { continue; } if ($log->dataModel != $modelName) { if (!isset($versions[$id])) { if (isset($versions[$id - 1])) { $versions[$id - 1]->changes = Structure::merge($versions[$id - 1]->changes, $log->changes); continue; } else { $versions[$id] = $log; } } } elseif (!isset($versions[$id])) { $versions[$id] = $log; continue; } if ($versions[$id]->dataModel != $modelName && $log->dataModel == $modelName) { $versions[$id]->dataModel = $modelName; $versions[$id]->dataId = $log->dataId; $versions[$id]->dataVersion = $log->dataVersion; } $versions[$id]->changes = Structure::merge($versions[$id]->changes, $log->changes); } foreach ($versions as $id => $version) { $changes = $version->changes; foreach ($changes as $index => $change) { if ($change->fieldName == VersionField::NAME || $change->fieldName == LocalizedModel::FIELD_LOCALE || $change->fieldName == LocalizedModel::FIELD_DATA) { unset($changes[$index]); } } $version->changes = $changes; $versions[$id] = $version; } return array_reverse($versions); }
/** * Parses a hierarchic array into a simple array * @param array $configuration Hierarchic array with configuration values to simplify * @param string $prefix Prefix for the keys of the configuration array (needed for recursive calls) * @return array Simplified configuration */ private function parseConfigurationArray(array $configuration, $prefix = null) { $result = array(); if ($prefix) { $prefix .= Config::TOKEN_SEPARATOR; } foreach ($configuration as $key => $value) { $prefixedKey = $prefix . $key; if (is_array($value)) { $result = Structure::merge($result, $this->parseConfigurationArray($value, $prefixedKey)); } else { $result[$prefixedKey] = $value; } } return $result; }
/** * Get the names of all the sections in the configuration * @return array Array with the names of all the ini files in the configuration directory, withouth the extension */ public function getAllSections() { $sections = array(); $includePaths = $this->browser->getIncludePaths(); foreach ($includePaths as $includePath) { $path = new File($includePath, Zibo::DIRECTORY_CONFIG); $sections = Structure::merge($sections, $this->getDirectorySections($path)); } $path = new File($this->getEnvironmentPath()); $sections = Structure::merge($sections, $this->getDirectorySections($path)); return $sections; }
/** * Gets the array of actions to include * @return array */ public function getInclude() { return Structure::getKeyArray($this->getValue(self::FIELD_INCLUDE)); }
/** * Get the value of this field from the request * @param string $name name of the request variable * @return mixed value of this field from the request */ protected function getRequestValue($name = null) { if ($name == null) { $name = $this->name; } $request = new Structure($_REQUEST); return $request->get($name); }
/** * Get an array with the settings of this object * @param boolean $includeInheritedSettings true to include the inherited settings in the array * @param boolean $onlyInheritSettings true to include only settings which inherit to lower levels * @return array Array with the setting key as key and a NodeSetting instance as value */ public function getArray($includeInheritedSettings = false, $inheritedSettingRequired = false) { $array = $this->settings; if ($inheritedSettingRequired) { foreach ($array as $key => $nodeSetting) { if (!$nodeSetting->inherit) { unset($array[$key]); } } } $inheritedSettings = $this->getInheritedNodeSettings(); if (!$includeInheritedSettings || $inheritedSettings == null) { return $array; } $inheritedArray = $inheritedSettings->getArray($includeInheritedSettings, $inheritedSettingRequired); return Structure::merge($inheritedArray, $array); }
/** * Create an array with the node hierarchy. Usefull for an options field. * @param array $tree array with Node objects * @param string $prefix prefix for the node names * @return array Array with the node id as key and the node name as value */ public function createListFromNodeTree(array $tree, $separator = '/', $prefix = '') { $list = array(); foreach ($tree as $node) { $newPrefix = $prefix . $separator . $node->name; $list[$node->id] = $newPrefix; if ($node->children) { $children = $this->createListFromNodeTree($node->children, $separator, $newPrefix); $list = Structure::merge($list, $children); } } return $list; }
/** * Gets all the files needed for the provided CSS file. This will extract the imports from the CSS. * @param zibo\core\Zibo $zibo Instance of Zibo * @param zibo\library\filesystem\File $file CSS source file * @return array Array with the path of the file as key and the File object as value */ private function getFilesFromStyle(Zibo $zibo, File $file) { $source = $file->read(); $source = preg_replace(CSSMin::REGEX_COMMENT, '', $source); $files = array(); $parent = $file->getParent(); $lines = explode("\n", $source); foreach ($lines as $line) { $line = trim($line); if (empty($line)) { continue; } if (!preg_match(CSSMin::REGEX_IMPORT, $line)) { break; } $importFileName = $this->getFileNameFromImportLine($line); $importFile = $zibo->getRelativeFile(new File($parent, $importFileName)); $importFile = $zibo->getFile($importFile); if (!$importFile) { continue; } $styleFiles = $this->getFilesFromStyle($zibo, $importFile); $files = Structure::merge($files, $styleFiles); } $files[$file->getPath()] = $file; return $files; }
/** * Parses the provided part and subparts * @param resource $stream The stream of the connection with the server * @param integer $id The internal id of the message * @param integer $partId The internal id of the part * @param object $part The part to parse * @return array Array with MimePart objects extracted from the part */ private function parseMessagePart($stream, $id, $partId, $part) { $parts = array(); $body = imap_fetchbody($stream, $id, $partId); if ($part->type != 0) { // part is not text $filename = null; if (isset($part->dparameters)) { $filename = $this->parser->getPartFilename($part->dparameters); } if (empty($filename) && isset($part->parameters)) { $filename = $this->parser->getPartFilename($part->parameters); } if (!empty($filename)) { $mimeType = $this->parser->getPartMimeType($part); $encoding = $this->parser->getPartEncoding($part); $parts[$filename] = new MimePart($body, $mimeType, null, $encoding); } } else { // part is text $textPartId = $partId; if (!isset($parts[Message::PART_BODY])) { $textPartId = Message::PART_BODY; } elseif (!isset($parts[Message::PART_ALTERNATIVE])) { if ($parts[Message::PART_BODY]->getMimeType() === 'text/html') { $textPartId = Message::PART_ALTERNATIVE; } else { $textPartId = Message::PART_BODY; $parts[Message::PART_ALTERNATIVE] = $parts[Message::PART_BODY]; unset($parts[Message::PART_BODY]); } } $mimeType = $this->parser->getPartMimeType($part); $encoding = $this->parser->getPartEncoding($part); $parts[$textPartId] = new MimePart($body, $mimeType, null, $encoding); } // if subparts... recurse into function and parse them too! if (isset($part->parts) && count($part->parts)) { foreach ($part->parts as $subPartId => $subPart) { $subParts = $this->parseMessagePart($stream, $id, $partId . '.' . ($subPartId + 1), $subPart); $parts = Structure::merge($parts, $subParts); } } return $parts; }
/** * Updates the module model with the installed modules * @return null */ private function readModules() { $modules = array(); $path = new File(Zibo::DIRECTORY_MODULES); $files = $path->read(); foreach ($files as $file) { // skip hidden files if (strncmp($file->getName(), '.', 1) === 0) { continue; } $fileModules = $this->getModulesFromPath($file); $modules = Structure::merge($modules, $fileModules); } $this->model->addModules($modules); }