public static function store($name, $data) { /* Input data structure: implementation: other plugin_name description: ** Equivalent of plugin info function here ** body: input: use|ignore default: body content to use params: token_name: input: token_name, default uses same name above default: value to use if missing encoding: none|html|url - default to none params: ; Use input parameter directly token_name: default value ; Custom input parameter replacement token_name: pattern: body content to use params: token_name: input: token_name, default uses same name above default: value to use if missing encoding: none|html|url - default to none */ if (empty($name)) { return; } $name = TikiLib::strtolower($name); $data['plugin_name'] = $name; $prefName = "pluginalias_{$name}"; $tikilib = TikiLib::lib('tiki'); $tikilib->set_preference($prefName, serialize($data)); global $prefs; $list = array(); if (isset($prefs['pluginaliaslist'])) { $list = unserialize($prefs['pluginaliaslist']); } if (!in_array($name, $list)) { $list[] = $name; $tikilib->set_preference('pluginaliaslist', serialize($list)); } foreach (glob('temp/cache/wikiplugin_*') as $file) { unlink($file); } $cachelib = TikiLib::lib('cache'); $cachelib->invalidate('plugindesc'); }
/** * Return a blog by its title * * @param string $blogTitle * @return array or false if no blog is found */ function get_blog_by_title($blogTitle) { // Avoiding select by name so as to avoid SQL injection problems. $query = "select `title`, `blogId` from `tiki_blogs`"; $result = $this->fetchAll($query); if (!empty($result)) { foreach ($result as $res) { if (TikiLib::strtolower($res['title']) == TikiLib::strtolower($blogTitle)) { return $this->get_blog($res['blogId']); } } } return false; }
function getValue() { return TikiLib::strtolower($this->value); }
/** * @param $type * @param $old * @param $new */ protected function rename_object($type, $old, $new, $user = '') { global $prefs; // comments $this->table('tiki_comments')->updateMultiple(array('object' => $new), array('object' => $old, 'objectType' => $type)); // Move email notifications $oldId = str_replace($type, ' ', '') . $old; $newId = str_replace($type, ' ', '') . $new; $this->table('tiki_user_watches')->updateMultiple(array('object' => $newId), array('object' => $oldId)); $this->table('tiki_group_watches')->updateMultiple(array('object' => $newId), array('object' => $oldId)); // theme_control_objects(objId,name) $oldId = md5($type . $old); $newId = md5($type . $new); $this->table('tiki_theme_control_objects')->updateMultiple(array('objId' => $newId, 'name' => $new), array('objId' => $oldId)); // polls if ($prefs['feature_polls'] == 'y') { $query = "update `tiki_polls` tp inner join `tiki_poll_objects` tpo on tp.`pollId` = tpo.`pollId` inner join `tiki_objects` tob on tpo.`catObjectId` = tob.`objectId` set tp.`title`=? where tp.`title`=? and tob.`type` = ?"; $this->query($query, array($new, $old, $type)); } // Move custom permissions $oldId = md5($type . TikiLib::strtolower($old)); $newId = md5($type . TikiLib::strtolower($new)); $this->table('users_objectpermissions')->updateMultiple(array('objectId' => $newId), array('objectId' => $oldId, 'objectType' => $type)); // Logs if ($prefs['feature_actionlog'] == 'y') { $logslib = TikiLib::lib('logs'); $logslib->add_action('Renamed', $new, 'wiki page', 'old=' . $old . '&new=' . $new, $user, '', '', '', '', array(array('rename' => $old))); $logslib->rename($type, $old, $new); } // Attributes $this->table('tiki_object_attributes')->updateMultiple(array('itemId' => $new), array('itemId' => $old, 'type' => $type)); $this->table('tiki_object_relations')->updateMultiple(array('source_itemId' => $new), array('source_itemId' => $old, 'source_type' => $type)); $this->table('tiki_object_relations')->updateMultiple(array('target_itemId' => $new), array('target_itemId' => $old, 'target_type' => $type)); $menulib = TikiLib::lib('menu'); $menulib->rename_wiki_page($old, $new); }
function object_has_one_permission($objectId, $objectType) { $objectId = md5($objectType . TikiLib::strtolower($objectId)); if (!isset($this->userobjectperm_cache) || !is_array($this->userobjectperm_cache) || !isset($this->userobjectperm_cache[$objectId])) { // i think, we really dont need the "and `objectType`=?" because the objectId should be unique due to the md5() $query = 'select count(*) from `users_objectpermissions` where `objectId`=? and `objectType`=?'; $this->userobjectperm_cache[$objectId]= $this->getOne($query, array($objectId, $objectType)); } return $this->userobjectperm_cache[$objectId]; }
$likepages = $wikilib->get_like_pages($page); if ($prefs['feature_wiki_pagealias'] == 'y' && count($referencedPages) == 1) { $newPage = $referencedPages[0]; } else { if ($prefs['feature_wiki_1like_redirection'] == 'y' && count($likepages) == 1) { $newPage = $likepages[0]; } } /* if we have exactly one match, redirect to it */ if (isset($newPage) && !$isUserPage) { $url = $wikilib->sefurl($newPage); // Process prefix alias with itemId append for pretty tracker pages $prefixes = explode(',', $prefs['wiki_prefixalias_tokens']); foreach ($prefixes as $p) { $p = trim($p); if (strlen($p) > 0 && TikiLib::strtolower(substr($page, 0, strlen($p))) == TikiLib::strtolower($p)) { $suffix = trim(substr($page, strlen($p))); if (!ctype_digit($suffix) && $suffix) { // allow escaped numerics as text $suffix = stripslashes($suffix); global $semanticlib; if (!is_object($semanticlib)) { require_once 'lib/wiki/semanticlib.php'; } $items = $semanticlib->getItemsFromTracker($newPage, $suffix); if (count($items) > 1) { $msg = tra('There is more than one item in the tracker with this title'); foreach ($items as $i) { $msg .= '<br /><a href="tiki-index.php?page=' . urlencode($newPage) . '&itemId=' . $i . '">' . $i . '</a>'; } $smarty->assign('msg', $msg);
/** * normalize_tag * * This is a utility function used to take a raw tag and convert it to normalized form. * Normalized form is essentially lowercased alphanumeric characters only, * with no spaces or special characters. * * Customize the normalized valid chars with your own set of special characters * in regex format within the option 'normalized_valid_chars'. It acts as a filter * to let a customized set of characters through. * * After the filter is applied, the function also lowercases the characters using strtolower * in the current locale. * * The default for normalized_valid_chars is a-zA-Z0-9, or english alphanumeric. * * @param tag string An individual tag in raw form that should be normalized. * * @return string Returns the tag in normalized form. */ function normalize_tag($tag) { if (!empty($this->_normalized_valid_chars) && $this->_normalized_valid_chars != '*') { $normalized_valid_chars = $this->_normalized_valid_chars; $tag = preg_replace("/[^{$normalized_valid_chars}]/", '', $tag); } return $this->_normalize_in_lowercase ? TikiLib::strtolower($tag, 'UTF-8') : $tag; }
private function cleanObject($name) { return TikiLib::strtolower(trim($name)); }
function findWikiPage() { global $prefs; $tikilib = TikiLib::lib('tiki'); $page_info = $tikilib->get_page_info($this->namespace . $this->namespaceSeparator . $this->page, false); if ($page_info === false) { $page_info = $tikilib->get_page_info($this->page, false); $this->setDescription($this->renderPageName()); } if ($page_info !== false) { return $page_info; } // If page does not exist directly, attempt to find an alias if ($prefs['feature_wiki_pagealias'] == 'y') { $semanticlib = TikiLib::lib('semantic'); $toPage = $this->page; $tokens = explode(',', $prefs['wiki_pagealias_tokens']); $prefixes = explode(',', $prefs["wiki_prefixalias_tokens"]); foreach ($prefixes as $p) { $p = trim($p); if (strlen($p) > 0 && TikiLib::strtolower(substr($this->page, 0, strlen($p))) == TikiLib::strtolower($p)) { $toPage = $p; $tokens = 'prefixalias'; } } $links = $semanticlib->getLinksUsing($tokens, array('toPage' => $toPage)); if (count($links) > 1) { // There are multiple aliases for this page. Need to disambiguate. // // When feature_likePages is set, trying to display the alias itself will // display an error page with the list of aliased pages in the "like pages" section. // This allows the user to pick the appropriate alias. // So, leave the $pageName to the alias. // // If feature_likePages is not set, then the user will only see that the page does not // exist. So it's better to just pick the first one. // if ($prefs['feature_likePages'] == 'y' || $tokens == 'prefixalias') { // Even if there is more then one match, if prefix is being redirected then better // to fail than to show possibly wrong page return true; } else { // If feature_likePages is NOT set, then trying to display the first one is fine // $pageName is by ref so it does get replaced $pageName = $links[0]['fromPage']; return $tikilib->get_page_info($this->page, true); } } elseif (count($links)) { // there is exactly one match if ($prefs['feature_wiki_1like_redirection'] == 'y') { return true; } else { $this->page = $links[0]['fromPage']; return $tikilib->get_page_info($this->page, true); } } } }
function run($data, $params) { global $prefs, $page_regex; // Grab and handle our Tiki parameters... extract($params, EXTR_SKIP); if (!isset($ignore)) { $ignore = ''; } if (!isset($splitby)) { $splitby = '+'; } if (!isset($skipext)) { $skipext = false; } if (!isset($debug)) { $debug = false; } if (!isset($collect)) { $collect = 'from'; } if (!isset($table)) { $table = 'sep'; } if (!isset($level)) { $level = ''; } // for regexes and external wiki details, see tikilib.php if ($level == 'strict') { $level_reg = '([A-Za-z0-9_])([\.: A-Za-z0-9_\-])*([A-Za-z0-9_])'; } elseif ($level == 'full') { $level_reg = '([A-Za-z0-9_]|[\x80-\xFF])([\.: A-Za-z0-9_\-]|[\x80-\xFF])*([A-Za-z0-9_]|[\x80-\xFF])'; } elseif ($level == 'complete') { $level_reg = '([^|\(\)])([^|\(\)](?!\)\)))*?([^|\(\)])'; } elseif (($level == 'custom') && ($data != '')) { if (preg_ispreg($data)) { // custom regular expression $level_reg = $data; } elseif ($debug == 2) { echo $data . ': ' . tra('non-valid custom regex') . '<br />'; } } else { // default $level_reg = $page_regex; } // define the separator if ($table == 'br') { $break = '<br />'; } elseif ($table == 'co') { $break = tra(', '); } else { $break = 'sep'; } // get array of fromPages to be ignored $ignorepages = explode($splitby, $ignore); // Currently we only look in wiki pages. // Wiki links in articles, blogs, etc are ignored. $query = 'select distinct tl.`toPage`, tl.`fromPage` from `tiki_links` tl'; $query .= ' left join `tiki_pages` tp on (tl.`toPage` = tp.`pageName`)'; $categories = $this->get_jail(); if ($categories) $query .= ' inner join `tiki_objects` as tob on (tob.`itemId`= tl.`fromPage` and tob.`type`= ?) inner join `tiki_category_objects` as tc on (tc.`catObjectId`=tob.`objectId` and tc.`categId` IN(' . implode(', ', array_fill(0, count($categories), '?')) . '))'; $query .= ' where tp.`pageName` is null'; $result = $this->query($query, $categories ? array_merge(array('wiki page'), $categories) : array()); $tmp = array(); while ($row = $result->fetchRow()) { foreach ($ignorepages as $ipage) { // test whether a substring ignores this page, ignore case if (fnmatch(TikiLib::strtolower($ipage), TikiLib::strtolower($row['fromPage'])) === true) { if ($debug == 2) { // the "hardcore case" echo $row['toPage'] . ' [from: ' . $row['fromPage'] . ']: ' . tra('ignored') . '<br />'; } elseif ($debug) { // add this page to the table $tmp[] = array($row['toPage'], $row['fromPage'], 'ignored'); } continue 2; // no need to test other ignorepages or toPages } } // foreach ignorepage // if toPage contains colon, and exloding yields two parts => external Wiki if (($skipext) && (strstr($row['toPage'], ':') !== false)) { $parts = explode(':', $row['toPage']); if (count($parts) == 2) { if ($debug == 2) { echo $row['toPage'] . ' [from: ' . $row['fromPage'] . ']: ' . tra('External Wiki') . '<br />'; } elseif ($debug) { $tmp[] = array($row['toPage'], $row['fromPage'], 'External Wiki'); } continue; } } // $skipext $dashWikiWord = preg_match("/^(?<=[ \n\t\r\,\;]|^)([A-Z][a-z0-9_\-\x80-\xFF]+[A-Z][a-z0-9_\-\x80-\xFF]+[A-Za-z0-9\-_\x80-\xFF]*)(?=$|[ \n\t\r\,\;\.])$/", $row['toPage']); $WikiWord = preg_match("/^(?<=[ \n\t\r\,\;]|^)([A-Z][a-z0-9\x80-\xFF]+[A-Z][a-z0-9\x80-\xFF]+[A-Za-z0-9\x80-\xFF]*)(?=$|[ \n\t\r\,\;\.])$/", $row['toPage']); // test whether toPage is a valid wiki page under current syntax if ($dashWikiWord && !$WikiWord) { // a Dashed-WikiWord, can we allow this? if (($prefs['feature_wikiwords'] != 'y') || ($prefs['feature_wikiwords_usedash'] != 'y')) { $tmp = debug_print($row, $debug, tra('dash-WikiWord')); continue; } } elseif ($WikiWord) { // a WikiWord, can we allow this? if ($prefs['feature_wikiwords'] != 'y') { $tmp = debug_print($row, $debug, tra('WikiWord')); continue; } } else { // no WikiWord, we can now filter with the level parameter if (!preg_match("/^($level_reg)$/", $row['toPage'])) { $tmp = debug_print($row, $debug, tra('not in level')); continue; } } // dashWikiWord, WikiWord, normal link if (!$debug) { // a normal, valid WantedPage: $tmp[] = array($row['toPage'], $row['fromPage']); } elseif ($debug == 2) { debug_print($row, $debug, tra('valid')); } // in simple debug mode, valid links are ignored } // while (each entry in tiki_links is handled) unset($result); // free memory if ($debug == 2) { return(tra('End of debug output.')); } $out = array(); $linkin = (!$debug) ? '((' : '~np~'; // this is how toPages are handled $linkout = (!$debug) ? '))' : '~/np~'; foreach ($tmp as $row) { // row[toPage, fromPage, reason] if ($debug) { // modified rejected toPages with reason $row[0] = '<em>' . tra($row[2]) . '</em>: ' . $row[0]; } $row[0] = $linkin . $row[0] . $linkout; // toPages $row[1] = '((' . $row[1] . '))'; // fromPages // two identical keys may exist, they can either be displayed // each in its own table row, or be collected in one cell, separated by // either comma or <br /> if ($collect == 'from') { if ($break == 'sep') { // toPages separated in each row, there might be duplicates!!! $out[] = array($row[0], $row[1]); } elseif (!array_key_exists($row[0], $out)) { // multiple fromPages (for one toPage) might be in one row, this is the first $out[$row[0]] = $row[1]; } else { // multiple fromPages might be in one row, this is a follow-up $out[$row[0]] = $out[$row[0]].$break.$row[1]; } } else { // $collect == to if ($break == 'sep') { // fromPages separated in each row, there might be duplicates!!! $out[] = array($row[1], $row[0]); } elseif (!array_key_exists($row[1], $out)) { // multiple toPages (for one fromPage) might be in one row, this is the first $out[$row[1]] = $row[0]; } else { // multiple toPages might be in one row, this is a follow-up $out[$row[1]] = $out[$row[1]] . $break . $row[0]; } } } // foreach (received row) is handled unset($tmp); // free memory // sort the entries if ($break == 'sep') { sort($out); } else { ksort($out); } $headerwant = tra('Wanted Page'); $headerref = tra('Referenced By Page'); $rowbreak = "\n"; $endtable = '||'; if ($prefs['feature_wiki_tables'] != 'new') { $rowbreak = ' || '; $endtable = ''; } $sOutput = '||' . ' __'; if ($collect == 'from') { $sOutput .= $headerwant . '__ | __' . $headerref . '__ ' . $rowbreak; if ($break == 'sep') { foreach ($out as $link) { $sOutput .= $link[0] . ' | ' . $link[1] . $rowbreak; } } else { foreach ($out as $to => $from) { $sOutput .= $to . ' | ' . $from . $rowbreak; } } } else { // $collect == 'to' $sOutput .= $headerref . '__ | __' . $headerwant . '__ ' . $rowbreak; if ($break == 'sep') { foreach ($out as $link) { $sOutput .= $link[0] . ' | ' . $link[1] . $rowbreak; } } else { foreach ($out as $from => $to) { $sOutput .= $from . ' | ' . $to . $rowbreak; } } } $sOutput .= $endtable; return $sOutput; } // run()
if ($userlib->object_has_one_permission($p['pageName'], 'wiki page')) { $p['perms_active'] = 'y'; } else { $p['perms_active'] = 'n'; } } $smarty->assign_by_ref('listpages', $listpages['data']); $smarty->assign_by_ref('cant', $listpages['cant']); ask_ticket('list-pages'); include_once 'tiki-section_options.php'; // disallow robots to index page: $smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW'); // Exact match and single result, go to page directly if (count($listpages['data']) == 1) { $result = reset($listpages['data']); if (TikiLib::strtolower($find) == TikiLib::strtolower($result['pageName'])) { require_once 'lib/wiki/wikilib.php'; header('Location: ' . $wikilib->sefurl($result['pageName'], '', $all_langs)); exit; } } if ($access->is_serializable_request()) { if (isset($_REQUEST['listonly']) && ($prefs['feature_jquery'] == 'y' && $prefs['feature_jquery_autocomplete'] == 'y')) { $pages = array(); foreach ($listpages['data'] as $page) { $pages[] = $page['pageName']; } $access->output_serialized($pages); } else { $pages = array(); require_once 'lib/wiki/wikilib.php';
/** * @param $objectType * @param $objectId */ function __construct($objectType, $objectId) { global $Tiki_ShareObject__groups; $this->objectHash = md5($objectType . TikiLib::strtolower($objectId)); $this->objectType = $objectType; $this->objectId = $objectId; $this->loadedPermission = array(); $this->validGroups = array(); if ($Tiki_ShareObject__groups == null) { $this->loadGroups(); } }
function getAliasContaining($query, $exact_match = false, $in_lang = NULL) { global $tikilib, $prefs; $orig_query = $query; if (!$exact_match) { $query = "%{$query}%"; } $mid = "((`target_type` = 'wiki page' AND `target_itemId` LIKE ?)"; $bindvars = array($query); $prefixes = explode(',', $prefs["wiki_prefixalias_tokens"]); $haveprefixes = false; foreach ($prefixes as $p) { $p = trim($p); if (strlen($p) > 0 && TikiLib::strtolower(substr($query, 0, strlen($p))) == TikiLib::strtolower($p)) { $mid .= " OR ( `target_type` = 'wiki page' AND `target_itemId` LIKE ?)"; $bindvars[] = "{$p}%"; $haveprefixes = true; } } $mid .= ") AND ( `relation` = 'tiki.link.alias' "; if ($haveprefixes) { $mid .= " OR `relation` = 'tiki.link.prefixalias' "; } $mid .= ")"; $querystring = "SELECT `source_itemId` `fromPage`, `target_itemId` `toPage` FROM `tiki_object_relations` WHERE {$mid}"; $aliases = $tikilib->fetchAll($querystring, $bindvars); $aliases = $this->onlyKeepAliasesFromPageInLanguage($in_lang, $aliases); return $aliases; }
/** * Return the page names for a page alias, if any. * * Unfortunately there is no mechanism to prevent two * different pages from sharing the same alias and that is * why this method return an array of page names instead of a * page name string. * * @param string $alias * @return array page names */ public function get_pages_by_alias($alias) { global $prefs; $semanticlib = TikiLib::lib('semantic'); $pages = array(); if ($prefs['feature_wiki_pagealias'] == 'n' && empty($prefs["wiki_prefixalias_tokens"])) { return $pages; } $toPage = $alias; $tokens = explode(',', $prefs['wiki_pagealias_tokens']); $prefixes = explode(',', $prefs["wiki_prefixalias_tokens"]); foreach ($prefixes as $p) { $p = trim($p); if (strlen($p) > 0 && TikiLib::strtolower(substr($alias, 0, strlen($p))) == TikiLib::strtolower($p)) { $toPage = $p; $tokens = 'prefixalias'; } } $links = $semanticlib->getLinksUsing($tokens, array('toPage' => $toPage)); if (count($links) > 0) { foreach ($links as $row) { $pages[] = $row['fromPage']; } } return $pages; }