public static function selector($langXml) { // create lang selector $langSelector = new simpleXmlElement("<lang_selector/>"); if ($langXml) { foreach ($langXml as $entry) { $langCode = $entry->getName(); //echoall($langCode); $countryCode = OLIVLang::defaultCountry($langCode); // make current language bigger $id = "oliv_lang_flag"; if ($langCode == status::lang()) { $id = "oliv_lang_flag_selected"; } //get string for url title language name $title = OLIVText::_("change_language", $langCode); $title .= " - " . OLIVText::_($langCode, $langCode); // full language name // create flag image // $img = new simpleXmlElement("<img url='" . status::url() . "' urllang='" . $langCode . "' urltitle='{$title}' src='oliv_flag' id='{$id}' lang='" . $countryCode . "' />"); $img = new simpleXmlElement("<selector><a href='current()' title='{$title}' lang='" . $langCode . "'/><img id='{$id}' lang='" . $countryCode . "'>oliv_flag</img></selector>"); // insert image olivxml_insert($langSelector, $img, "ALL"); } //echoall($langSelector->asXML()); return $langSelector; } }
public static function __callStatic($method, $options) { $content = $options[0]; $tag = $options[1]; $type = $options[2]; switch ($type) { // call text search case 'search': // merge result with status::set() $searchString = argv::search(); $result = textPlugin::search(); if ($result) { // get translation of pages $pages = $result->XPath("./result"); // insert text snippets with highlighted searchString foreach ($pages as $page) { $moduleName = (string) $page->type; $name = (string) $page->name; $value = (string) $page->value; $article = OLIVModule::load_xml("", $moduleName . "/" . "content/", $name . ".xml"); if ($article) { $texts = $article->XPath("//text"); foreach ($texts as $text) { // highlight seachstring if ($highlighted = OLIVText::highlight((string) $text, $searchString, "highlight", 25)) { $page->summary = $highlighted; // add language $page->lang = (string) $text['lang']; } } // insert page name olivxml_insert($page->pagename, OLIVRoute::getName((string) $page->page)); } } olivxml_insert($content, $result); } break; // call renderer // call renderer case 'render': textPlugin::render($content); break; } }
public function process($page) { $content = $page->structure(); if ($content) { $lang = status::lang(); $default_lang = system::OLIV_DEFAULT_LANG(); $texts = $content->XPath("//*/*[text]"); // translate all texts for ($i = 0; $i < count($texts); $i++) { $text = OLIVText::xml($texts[$i]); // set correct language in node if (is_array($texts)) { if (array_key_exists($i, $texts)) { if ($texts[$i]->text) { unset($texts[$i]->text); $texts[$i]->text = $text; } } } } } //echoall($content); }
public static function load_xml($header, $path, $name, $root = "") { $filePath = system::OLIV_MODULE_PATH(); // use module name from header if ($header) { $filePath .= (string) $header->name . "/"; } $filePath .= $path; //TODO // load system file if (strtolower($root) == "system") { if (olivfile_exists($filePath . $name)) { return olivxml_load_file($filePath . $name); } } else { if (sessionfile_exists($filePath . $name)) { $xml = sessionxml_load_file($filePath . $name); // if access defined and write access -> enable editing if ($xml->access->getName()) { // read access -> display if (!OLIVRight::r($xml->access)) { $xmlName = $xml->getName(); return new simpleXmlElement("<{$xmlName}/>"); } elseif (OLIVRight::w($xml->access)) { OLIVText::writeSource($xml, $filePath . $name); } } //TODO write imagesource // OLIVImage::writeSource($xml,$filePath); return $xml; } else { OLIVError::warning("module.php::load_xml - {$root}{$filePath}{$name} not found"); } } }
public function draw() { $display = ""; $o = "<ul id='" . $this->context->attributes()->name . "' class='contextMenu'>"; // create ouput string from xml foreach ($this->context as $entry) { // disable entry if ($display = (string) $entry->attributes()->display) { $display = " " . $display; } // set entry to url or status::url if (($url = (string) $entry->attributes()->url) == "#CURRENT") { $url = status::url(); } // set val if ($val = (string) $this->context->attributes()->value) { } else { $val = (string) $this->context->attributes()->name; } // set parameters $class = (string) $entry->attributes()->class; $cmd = (string) $entry->attributes()->cmd; $command = OLIVText::_($cmd); $text = OLIVText::_($entry->getName()); $o .= "<li class='{$class}{$display}'>"; $o .= "<a href='#{$cmd};{$command};" . OLIVRoute::url("", array("url" => $url)) . ";{$val}'>{$text}</a>"; $o .= "</li>"; } $o .= "</ul>"; // output to display echo $o; }
public static function getGroupName($user) { $groups = OLIVUser::getGroup($user); $groupArray = array(); foreach ($groups as $entry) { $groupId = $entry->getName(); array_push($groupArray, OLIVText::xml($entry->name)); } return implode(", ", $groupArray); }
public static function tagEditString($tag, $value, $options) { $content = $options['template']; $source = $content->attributes()->source; //echoall($options); $retArray = imgRender::tagString($tag, $value, $options); // set link if permission granted && source found if (OLIVRight::x($content) and $source) { $retArray['link']['url'] = status::url(); $retArray['link']['val'] = OLIVText::_("edit"); $retArray['link']['lang'] = status::lang(); $retArray['value'] = "edit"; } return $retArray; }
public static function highlight($text, $searchString, $class, $overhang = 0) { // parse string without accesnts and lowercase for searchstring $stringArray = array(); $textArray = explode(" ", $text); $retArray = array(); $pattern = "~{$searchString}~"; $string = strtolower(OLIVText::remove_accents((string) $text)); preg_match_all($pattern, $string, $matches, PREG_OFFSET_CAPTURE); // split the string $start = 0; $offset = 0; if ($matches) { if (count($matches[0])) { return $text; //TODO solve the problem with the utf8 chars /* foreach ($matches[0] as $match) { $delimitor = ""; // insert part from previous start $length = $match[1] - $start; if ($overhang) { if ($length > $overhang) { // text longer than 2 times the overhang // cut away the rest if ($length > 2*$overhang) { array_push($stringArray,$delimitor . substr((string)$text,$start,$overhang) . "... "); $start = $match[1] - $overhang; $length = $overhang; $delimitor = " ..."; } } } if ($length) array_push($stringArray,$delimitor . substr((string)$text,$start,$length)); // insert hightlighted searchstring $length = strlen($searchString); $start = $match[1]; if ($length) array_push($stringArray,"{span class='$class'}" . substr((string)$text,$start,$length) . "{/span}"); $start = $start + $length; }*/ } else { return FALSE; } // rest of text longer than overhang // cut away the rest /* $length = strlen($text) - $start; if ($overhang) { if ($length > $overhang) { $length = $overhang; $delimitor = "..."; } } array_push($stringArray,substr((string)$text,$start,$length) . $delimitor); return implode("",$stringArray);*/ } }
public function init($session) { // ------------------------------------------------------------------------------ // set session if ($session) { system::set('OLIV_SESSION', $session . "/"); } else { die("***FATAL ERROR: init.php - no session defined"); } // core path for multisession defined if (!system::OLIV_CORE_PATH()) { die("Core path not defined"); } // ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------ // load basic system methods OLIVCore::loadScript("library/init.php"); if (!system::OLIVENV()) { die("Environment not set"); } // ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------ // load system language if (!system::OLIVTEXT()) { die("INIT: OLIVTEXT not found"); } OLIVText::load(system::OLIV_LANGUAGE_PATH(), system::OLIV_CORE_TEXT()); // ------------------------------------------------------------------------------ // initialice main components // ------------------------------------------------------------------------------ // connect to database // $this->daba = new OLIVDatabase($this->coreXml->_("core.database")); // initialise router $this->route = new OLIVRoute(); // initialise html $this->html = new OLIVHtml(); // load module metadata $this->module = new OLIVModule(); // load plugin metadata $this->plugin = new OLIVPlugin(); // load site template $this->template = new OLIVTemplate(system::OLIV_TEMPLATE_PATH() . system::OLIV_TEMPLATE() . "/", system::OLIV_TEMPLATE()); // initialise page $this->page = new OLIVPage(); // initialise preprocessor $this->processor = new OLIVProcessor(); // initialise renderer $this->render = new OLIVRender(); // ------------------------------------------------------------------------------ // set core status // ------------------------------------------------------------------------------ // extract command and value if (status::val()) { // extract cmd and param $cmdArray = explode("/", cut_slash(status::val())); // TODO define commands in system section ??? // search for command and retranslate if (count($cmdArray)) { $cmd = OLIVText::getId($cmdArray[0]); status::set('command', $cmd); // save command } // if command found, extract command from val if (count($cmdArray) > 1 and $cmd) { array_shift($cmdArray); // remove command from val status::set('val', implode("/", $cmdArray)); // save val } } // ------------------------------------------------------------------------------ // initialize clipboard // get content from clipboard parameter if ($clipboard = argv::clipboard()) { OLIVClipboard::_($clipboard); } // get clipboard from cut/copy command $command = status::command(); if ($command) { OLIVClipboard::$command(status::val()); } }
public function insertText($text, $url = "", $lang = "") { // remove punctuation marks in text $text = preg_replace("![\\.\\,\\;\\:\\(\\)\\[\\]\\{\\}\\-\\_\\/]!", " ", strtolower($text)); // extract words $wordArray = explode(" ", $text); $wordArray = array_unique($wordArray); foreach ($wordArray as $word) { // $word = strtolower(Normalizer::normalize($word,Normalizer::FORM_C)); $word = strtolower($word); //TODO replace all special characters with root $specialChar = array("ä", "ö"); $replaceChar = array(); $word = OLIVText::remove_accents($word); // $this->insertWord($word,$word); $suffArray = $this->makeSuffArray($word); foreach ($suffArray as $suffix) { $this->insertWord($suffix, status::url() . ":" . $url . ":{$lang}:{$word}", $lang); } } global $_INDEX; //echoall($_INDEX); // write index to disk $path = session_path(""); $name = "index.idx"; if (file_exists($path)) { $fh = fopen($path . $name, "w"); if ($fh) { fwrite($fh, $_INDEX->asXML()); fclose($fh); } else { OLIVError::fire("index.php - no write permission"); } } else { OLIVError::fire("index.php - directory {$path} don't exist"); } }
private function parse($menus, $menuName, $templateName, $access, $url, $level = 0) { $menu = $menus->{$menuName}; $active = FALSE; if ($menu) { // get name of menu $menuName = $menu->getName(); $menuXml = new simpleXmlElement("<menu></menu>"); // open path to actice menu $this->openPath($menus, $url); //------------------------------------------------------------------------------ // loop over menu entries foreach ($menu->children() as $entry) { $visible = FALSE; $subMenuVisible = $entry['visible']; if ($subMenuVisible) { $entry->visible = "visible"; } //------------------------------------------------------------------------------ // display item if read permission if (OLIVRight::r($entry) and OLIVRight::r($menu)) { $internUrl = ""; $menuItemName = $entry->getName(); //------------------------------------------------------------------------------ // is intern link if (!$entry->url) { // look for module link $mod = (string) $entry["mod"]; $page = (string) $entry["page"]; $name = $entry->getName(); if ($mod and $page) { olivxml_insert($entry, OLIVModule::getContentFriendlyName($mod, $name), "ALL"); olivxml_insert($entry, OLIVModule::getContentName($mod, $name), "ALL"); olivxml_insert($entry, OLIVModule::getContentTitle($mod, $name), "ALL"); $internUrl = "href():" . $page; $entry->url = $internUrl; // echoall($internUrl); } else { // create correct url $internUrl = $name; $entry->url = $internUrl; $urlName = OLIVText::xml(OLIVRoute::getPageName(status::lang(), $internUrl)); // expand url with val if ($val = (string) $entry['val']) { $valArray = OLIVModule::parse_param_string($val); /* if (array_key_exists("mod",$valArray) and array_key_exists("content",$valArray)) { $contentName = OLIVModule::getContentName($valArray['mod'],$valArray['content']); olivxml_insert($entry->val,OLIVModule::getContentFriendlyName($valArray['mod'],$valArray['content'])); $contentTitle = OLIVModule::getContentTitle($valArray['mod'],$valArray['content']); olivxml_insert($entry->title,$contentTitle); olivxml_insert($entry->name,$contentName); }*/ } else { olivxml_insert($entry, OLIVRoute::getTitle($internUrl), "ALL"); olivxml_insert($entry, OLIVRoute::getPageName(status::lang(), $internUrl), "ALL"); } } } //------------------------------------------------------------------------------ // set display class //------------------------------------------------------------------------------ // aktive / inactive if ($internUrl == $url) { $visible = $url; $entry->status = "active"; $entry->class = "{$templateName} menu_{$templateName}_active"; } else { $entry->class = "{$templateName} menu_{$templateName}_inactive"; } // submenu level if ($level) { $entry->class = "menu{$level}_" . $entry->class; } else { $entry->class = "menu_" . $entry->class; } //------------------------------------------------------------------------------ // remove link if no x permission // check for menu_item, menu and page permissions // set display class to disabled $pageXAccess = (string) $access->x; $menuXAccess = OLIVRight::x($menu); if (!(OLIVRight::x($entry) and $menuXAccess and $pageXAccess)) { $entry->url = ""; $entry->class = "menu_{$templateName}_disabled"; } // get submenu name $subName = (string) $entry['submenu']; if ($subName) { $entry->submenu = $subName; } // create menu_item xml $menu_item = new simpleXmlElement("<menu_item_{$templateName}></menu_item_{$templateName}>"); olivxml_insert($menu_item, $entry); // insert menu_item into new menu structure olivxml_insert($menuXml, $menu_item, "ALL"); //------------------------------------------------------------------------------ // look if aktive menu is in submenu // display sub menus if ($subName and $visible or $subMenuVisible) { // call menu recursive $subMenu = $this->parse($menus, $subName, $templateName, $access, $url, $level + 1); olivxml_insert($menuXml, $subMenu); } } } //echoall($menuXml); return $menuXml; } // else // OLIVError::fire("menu::parse - no menu defined"); }
public function scan($lang) { $path = system::OLIV_PAGE_PATH() . "page.xml"; if (sessionfile_exists($path)) { $pageXml = sessionxml_load_file($path); status::set("pages", $pageXml->define); status::set("pagestructure", $pageXml->structure); OLIVText::writeSource(status::pages(), $path); } else { OLIVError::fire("page::scan - page.xml not found -> rescan"); } }
private function create() { $structure = $this->content->structure; $content = $this->content->content; if ($content) { foreach ($content->children() as $entry) { $name = $entry->getName(); // insert translated text in attibutes // text tag with leading $ $tempName = "\$" . $name; $nodes = $structure->XPath("//*[@* = '{$tempName}']"); foreach ($nodes as $node) { $text = OLIVText::xml($entry); foreach ($node->attributes() as $key => $value) { if ((string) $value == $tempName) { $node[$key] = $text; } } } // insert content at name attribute $nodes = $structure->XPath("//*[@name = '{$name}']"); foreach ($nodes as $node) { // insert text into node olivxml_insert($node, $entry); } } } //echoall($this->content->structure); }