getOne($sql, array($pageName)); return $id; } public static function getPageContent($pageID, $version = null){ global $cfg; $cmsDB = Database::getInstance($cfg['CMS']['dsn']); if(is_null($version)){ $sql = 'SELECT content FROM wikipages, cmsregions, cmscontent WHERE wikipages.regionid = cmsregions.regionid AND cmsregions.regionid = cmscontent.regionid AND wikipages.wikipageid = ? ORDER BY timestamp DESC LIMIT 1'; $content = $cmsDB->getOne($sql, array($pageID)); }else{ $sql = 'SELECT content FROM wikipages, cmsregions, cmscontent WHERE wikipages.regionid = cmsregions.regionid AND cmsregions.regionid = cmscontent.regionid AND cmscontent.contentid = ? AND wikipages.wikipageid = ? ORDER BY timestamp DESC'; $content = $cmsDB->getOne($sql, array($version, $pageID)); } return $content; } /** * Get the ID of the category specified by $categoryName * * @param string $categoryName The page name with underscores * @return int The ID of the category */ public static function getCategoryID($categoryName){ global $cfg; $wikiDB = Database::getInstance($cfg['TKWiki']['dsn']); $sql = 'SELECT categoryid FROM wikicategories WHERE name = ?'; $id = $wikiDB->getOne($sql, array($categoryName)); return $id; } /** * * Ensures that a page title contains only permitted characters. * * @return boolean True if the title is allowable, false if not */ public static function checkPageTitle($title){ return (strrpos($title, '¬') === false); } /** * Will return the region ID which $pageID uses * * @param int $pageID The page ID * @return int The region ID */ public static function getPageRegion($pageID){ global $cfg; $wikiDB = Database::getInstance($cfg['TKWiki']['dsn']); $sql = 'SELECT regionid FROM wikipages WHERE wikipageid = ?'; $regionID = $wikiDB->getOne($sql, array($pageID)); return $regionID; } /** * Get the realms to which a page or category belongs * * Note: This method caches results * * @param int $nodeID * @param boolean $isCategory Set to true if $nodeID specifies a category, false if it specifies a page * @return array An associative array with elements admin, edit and view. Each spcifies the relevant realm */ public static function getNodeSubRealmIDs($nodeID, $isCategory){ global $cfg; //See if the result has already been cached static $cache = array(); $bit = $isCategory ? '_1' : '_0'; if(isset($cache[$nodeID . $bit])){ return $cache[$nodeID . $bit]; //return the cached result if found } $db = Database::getInstance($cfg['Auth']['dsn']); if($isCategory){ $realmName = TKWikiUtils::getRealmNameFromCat($nodeID); }else{ $realmName = TKWikiUtils::getRealmNameFromPage($nodeID); } //Get the ID of the root realm (I.e. TKWiki) $sql = 'SELECT realmid, leftnum, rightnum FROM realms WHERE name = "TKWiki" AND parentID = 0'; $rootRealm = $db->getRow($sql); //Cache the left/right numbers AuthUtil::getRealmLeftRightNumbers($rootRealm['realmid'], $rootRealm['leftnum'], $rootRealm['rightnum']); //Get the view/edit/admin realms which are the children of the root TKWiki realm $sql = 'SELECT name, realmid, leftnum, rightnum FROM realms WHERE parentid = ? AND name IN ("Perm_View", "Perm_Edit", "Perm_Admin")'; $rootPermRealms = $db->getAll($sql, array($rootRealm['realmid'])); //Some sanity checking if(count($rootPermRealms) != 3){ throw new LoggedException("I did not get the expected (i.e. three) realms back from the SQL query (note: parentid={$rootRealm['realmid']}): $sql", 0, self::module, 'error'); } //While we have these realms with left/right numbers, load them into the cache foreach ($rootPermRealms as $r){ AuthUtil::getRealmLeftRightNumbers($r['realmid'], $r['leftnum'], $r['rightnum']); } //Now get all the realms under TKWiki which have the correct realm name //(as the name is guarenteed to be unique as it contains the page ID) $sql = 'SELECT realmid, leftnum, rightnum FROM realms WHERE leftnum > ? AND rightnum < ? AND name = ?'; $nodePermRealms = $db->getAll($sql, array($rootRealm['leftnum'], $rootRealm['rightnum'], $realmName)); //We can now determine which realm is the view/edit/admin realm by its left/right numbers $ids = array(); foreach ($nodePermRealms as $nodePermRealm){ foreach ($rootPermRealms as $rootPermRealm){ if($nodePermRealm['leftnum'] > $rootPermRealm['leftnum'] && $nodePermRealm['rightnum'] < $rootPermRealm['rightnum']){ switch ($rootPermRealm['name']){ case ('Perm_View'): $ids['view'] = $nodePermRealm['realmid']; break; case ('Perm_Edit'): $ids['edit'] = $nodePermRealm['realmid']; break; case ('Perm_Admin'): $ids['admin'] = $nodePermRealm['realmid']; break; } } } } //Check that $assocRealms contains Perm_View, Perm_Edit and Perm_Admin if(!isset($ids['view']) || !isset($ids['edit']) || !isset($ids['admin'])){ $pageOrCat = $isCategory ? 'category' : 'page'; throw new LoggedException("Could not find one or more of the permission realms for $pageOrCat with ID '$nodeID'.", 0, self::module, 'error'); } //Cache and return the array $cache[$nodeID . $bit] = $ids; return $cache[$nodeID . $bit]; } /** * Check the current user can view $pageID * * @param int $pageID The id of the page * @return boolean True/false if access is allowed/denied */ public static function userCanViewPage($pageID){ $auth = Auth::getInstance(); return TKWikiUtils::userCanXPage($pageID, 'view', $auth->getUserID()); } /** * Check the current user can edit $pageID * * @param int $pageID The id of the page * @return boolean True/false if access is allowed/denied */ public static function userCanEditPage($pageID){ $auth = Auth::getInstance(); return TKWikiUtils::userCanXPage($pageID, 'edit', $auth->getUserID()); } /** * Check the current user can admin $pageID * * @param int $pageID The id of the page * @return boolean True/false if access is allowed/denied */ public static function userCanAdminPage($pageID){ $auth = Auth::getInstance(); return TKWikiUtils::userCanXPage($pageID, 'admin', $auth->getUserID()); } /** * Check the current user can view $categoryID * * @param int $categoryID The id of the category * @return boolean True/false if access is allowed/denied */ public static function userCanViewCategory($categoryID){ $auth = Auth::getInstance(); return TKWikiUtils::userCanXCategory($categoryID, 'view', $auth->getUserID()); } /** * Check the current user can edit $categoryID * * @param int $categoryID The id of the category * @return boolean True/false if access is allowed/denied */ public static function userCanEditCategory($categoryID){ $auth = Auth::getInstance(); return TKWikiUtils::userCanXCategory($categoryID, 'edit', $auth->getUserID()); } /** * Check the current user can admin $categoryID * * @param int $categoryID The id of the category * @return boolean True/false if access is allowed/denied */ public static function userCanAdminCategory($categoryID){ $auth = Auth::getInstance(); return TKWikiUtils::userCanXCategory($categoryID, 'admin', $auth->getUserID()); } /** * Get the user's permissions for $pageID for access of type $accessType * * @param int $pageID * @param array $accessType The access type being queried (must be either: view, edit or admin) */ public static function userCanXPage($pageID, $accessType, $userID){ return TKWikiUtils::userCanXNode($pageID, $accessType, $userID, false); } public static function userCanXCategory($categoryID, $accessType, $userID){ return TKWikiUtils::userCanXNode($categoryID, $accessType, $userID, true); } /** * Get a user's permissions for a category * * @param int $categoryID * @param int $userID * @return array An array of boolean values with the elements view, edit and admin */ public static function getCategoryPermissions($categoryID, $userID){ $out['view'] = TKWikiUtils::userCanXCategory($categoryID, 'view', $userID); $out['edit'] = TKWikiUtils::userCanXCategory($categoryID, 'edit', $userID); $out['admin'] = TKWikiUtils::userCanXCategory($categoryID, 'admin', $userID); return $out; } /** * Checks that user $userID has permission to access $nodeID with the permissions $accessType * * @param int $nodeID The ID of the page or category * @param string $accessType Either view, edit, or admin * @param int $userID The ID of the user * @param boolean $isCategory True if $nodeID specifies a category, false if $realmID specifies a page * @return boolean */ protected static function userCanXNode($nodeID, $accessType, $userID, $isCategory){ global $cfg; $realms = self::getNodeSubRealmIDs($nodeID, $isCategory); $realmPath = AuthUtil::getRealmPath($realms[$accessType]); $out = AuthUtil::getDetailedUserrealmAccess($realmPath, $userID); return $out; } public static function getPageCategoryPath($pageID){ global $cfg; static $cache; if(isset($cache[$pageID])){ return $cache[$pageID]; } //Get the page's category $db = Database::getInstance($cfg['TKWiki']['dsn']); $sql = 'SELECT categoryid FROM wikipages WHERE wikipageid=?'; $iniCatID = $db->getOne($sql, array($pageID)); $sql = 'SELECT categoryid, name, parentid FROM wikicategories WHERE categoryid = ?'; $cats = array(); $parentID = $iniCatID; //include a safety counter incase the category tree is malformed $safetyCount = 20; while($parentID > 0 && $safetyCount > 0){ $safetyCount--; $catInfo = $db->getRow($sql, array($parentID)); $parentID = $catInfo['parentid']; unset($catInfo['parentid']); $cats[] = $catInfo; } if($safetyCount == 0){ throw new LoggedException("Could not determine the category path for page with id '$pageID', it seems the category tree is malformed", 0, self::module, 'error'); } $cache[$pageID] = array_reverse($cats); return $cache[$pageID]; } /** * Returns the ID of the category to which $pageID belongs * * @param in $pageID * @return int */ public static function getPageCategory($pageID){ global $cfg; $db = Database::getInstance($cfg['TKWiki']['dsn']); $sql = 'SELECT categoryid FROM wikipages WHERE wikipageid=?'; $catID = $db->getOne($sql, array($pageID)); return $catID; } public static function addPage($pageName, $content, $categoryID){ global $cfg; //Get database instances $dbTKWiki = Database::getInstance($cfg['TKWiki']['dsn']); $dbCMS = Database::getInstance($cfg['CMS']['dsn']); //Get instance of Auth $auth = Auth::getInstance(); //Start transactions $dbTKWiki->startTransaction(); $dbCMS->startTransaction(); $insertR = array('regionid' => '#id#', 'name' => $pageName, 'editrealm' => '8', 'viewrealm' => '8', 'inlinetoolbar' => 'TKWiki', 'windowtoolbar' => 'TKWiki'); $regionID = $dbCMS->insert("cmsregions", $insertR); $insertC = array('contentid' => '#id#', 'regionid' => $regionID, 'timestamp' => time(), 'content' => $content, 'userid' => $auth->getUserID()); $dbCMS->insert("cmscontent", $insertC); $insertP = array('wikipageid' => '#id#', 'name' => $pageName, 'regionid' => $regionID, 'categoryid' => $categoryID); $newPageID = $dbTKWiki->insert('wikipages', $insertP); //Enter the page in the realm tree $newPageName = TKWikiUtils::getRealmNameFromPage($newPageID); $catRealms = TKWikiUtils::getNodeSubRealmIDs($categoryID, true); AuthUtil::addRealm($catRealms['view'], $newPageName, array()); AuthUtil::addRealm($catRealms['edit'], $newPageName, array()); AuthUtil::addRealm($catRealms['admin'], $newPageName, array()); //Spider the page for searching TKWikiUtils::spiderPage(array($newPageID)); //Commit transactions $dbTKWiki->commit(); $dbCMS->commit(); return $newPageID; } public function addCategory($categoryName, $parentCategoryID){ global $cfg; $dbTKWiki = Database::getInstance($cfg['TKWiki']['dsn']); $dbTKWiki->startTransaction(); $sql = 'SELECT categoryid FROM wikicategories WHERE name = ? AND parentid = ?'; $exists = $dbTKWiki->getAll($sql, array($categoryName, $parentCategoryID)); if(count($exists) > 0){ throw new LoggedException('That category cannot be created because it already exists', 0, self::module, 'error'); } //Create the category in the wikicategories table $insert = array('categoryid' => '#id#', 'name' => $categoryName, 'parentid' => $parentCategoryID); $catID = $dbTKWiki->insert('wikicategories', $insert); //We need to find the realm ID of the parent realm $sql = 'SELECT realmid FROM realms WHERE name = ?'; $newRealmName = TKWikiUtils::getRealmNameFromCat($catID); $catRealms = self::getNodeSubRealmIDs($parentCategoryID, true); //Now create the sub realms Perm_View, Perm_Edit and Perm_Admin AuthUtil::addRealm($catRealms['view'], $newRealmName, array()); AuthUtil::addRealm($catRealms['edit'], $newRealmName, array()); AuthUtil::addRealm($catRealms['admin'], $newRealmName, array()); //Commit transactions $dbTKWiki->commit(); return $catID; } /** * Change the category for a page * * This method is quite intensive on the realms table as * three removals and three additions are done - totaling 3 deletes, * 3 inserts, and 12 updates. * * A note on $lazy: If you are quite sure that the page is not already in * the specified category then it is a good idea to set $lazy to * false as this will potentially save you a database query. * * @param int $pageID The ID of the page * @param int $categoryID The ID of the new category for the page * @param boolean $lazy If true, the change will not be performed if the page is alreay in the specified category * @return boolean True if the change was made, false if no change was necessary (which implies that $lazy was also set to true) */ function setPageCategory($pageID, $categoryID, $lazy = true){ global $cfg; $db = Database::getInstance($cfg['TKWiki']['dsn']); //If $lazy is set then check we actually need to do anything if($lazy){ $currentCategoryID = TKWikiUtils::getPageCategory($pageID); if($currentCategoryID == $categoryID){ return false; } } //Get the left/right numbers of the root TKWiki realm $sql = 'SELECT realmid, leftnum, rightnum FROM realms WHERE name = "TKWiki" AND parentID = 0'; $rootRealm = $db->getRow($sql); if(!is_array($rootRealm)){ throw new LoggedException("I failed to get the left/right numbers for the root TKWiki realms using the SQL: $sql", 0, self::module, 'error'); } //Cache the left/right numbers AuthUtil::getRealmLeftRightNumbers($rootRealm['realmid'], $rootRealm['leftnum'], $rootRealm['rightnum']); //Get a list of all the page's realms in the realm tree $pageRealmName = TKWikiUtils::getRealmNameFromPage($pageID); $sql = 'SELECT realmid FROM realms WHERE leftnum > ? AND rightnum < ? AND name = ?'; $pagesRealms = $db->getColumn($sql, 0, array($rootRealm['leftnum'], $rootRealm['rightnum'], $pageRealmName)); if(count($pagesRealms) != 3){ throw new LoggedException("I could not find the expected (i.e. three) number of realms for page with ID '$pageID'", 0, self::module, 'error'); } //Get the realm ID of the category the page is to be assigned to $categoryRealmIDs = TKWikiUtils::getNodeSubRealmIDs($categoryID, true); /* We now have all the information we need, so start editing the data... */ $db->startTransaction(); //Update the row in the wikipages table $update = array('categoryid' => $categoryID); $db->update('wikipages', $update, 'wikipageid = ' . $pageID); //Delete the old realms foreach ($pagesRealms as $realmID){ $deleted = AuthUtil::deleteRealm($realmID); if(!$deleted){ throw new LoggedException("I just tried to delete the realm with id '$realmID' but it failed, probably because the realm has kids. This should not happen because it is a page realm"); } } //Add the new realms AuthUtil::addRealm($categoryRealmIDs['view'], $pageRealmName, array()); AuthUtil::addRealm($categoryRealmIDs['edit'], $pageRealmName, array()); AuthUtil::addRealm($categoryRealmIDs['admin'], $pageRealmName, array()); $db->commit(); return true; } /** * Convert html char codes to their actual characters * * @author kevin_bro at hostedstuff dot com * @param string $string * @return html */ public static function unHTMLEntities($string) { $trans_tbl = get_html_translation_table (HTML_ENTITIES); $trans_tbl = array_flip ($trans_tbl); $ret = strtr ($string, $trans_tbl); return preg_replace('/&#(\d+);/me', "chr('\\1')",$ret); } public static function getRealmNameFromCat($categoryID){ $name = "Category_$categoryID"; return $name; } public static function getRealmNameFromPage($pageID){ $name = "Page_$pageID"; return $name; } public static function renderMath($mathText){ global $cfg; //$myObjRend = new objRend(); $out = strMath($mathText); return (count(split("\n", $out)) == 1); } /** * Get the name of the category specified by $categoryID * * @param int $categoryID * @return string The category name (with underscores) */ public static function getCategoryName($categoryID){ global $cfg; if($categoryID == 0){ return "Top Level Category"; } $db = Database::getInstance($cfg['TKWiki']['dsn']); $sql = 'SELECT name FROM wikicategories WHERE categoryid = ?'; return $db->getOne($sql, array($categoryID)); } /** * Get the name of the page specified by $pageID * * @param int $pageID * @return string The page name (with underscores) */ public static function getPageName($pageID){ global $cfg; $db = Database::getInstance($cfg['TKWiki']['dsn']); $sql = 'SELECT name FROM wikipages WHERE wikipageid = ?'; return $db->getOne($sql, array($pageID)); } /** * Determine if a user is allowed to search * * This method will determine if a user is allowed to search. This * is done based upon the settings specified by * $cfg['TKWiki']['searchUsers'] and $cfg['TKWiki']['searchGroups'] * * @param int $uid The user's id * @return boolean True if the user is allowed to search, false if not */ public static function userCanSearch($uid){ global $cfg; if($cfg['TKWiki']['searchUsers'] == '*'){ return true; } $username = AuthUtil::getUsername($uid); if(in_array($username, $cfg['TKWiki']['searchUsers'])){ return true; } $groups = AuthUtil::getGroupsListForUser($uid); foreach ($groups as $gid){ $groupname = AuthUtil::getGroupname($gid); if(in_array($groupname, $cfg['TKWiki']['searchGroups'])){ return true; } } return false; } /** * Determine if a page should be spidered * * This method will determine if a page should be spidered based on which * users and groups have access to it. The relevant lists of users * and groups can be found in $cfg['TKWiki']['spiderGroups'] and * $cfg['TKWiki']['spiderUsers'] respectively. * * @param int $pageID * @return boolean True if the page should be spidered, false otherwise */ protected static function shouldSpider($pageID){ global $cfg; $pageRealms = TKWikiUtils::getNodeSubRealmIDs($pageID, false); $viewRealm = $pageRealms['view']; foreach ($cfg['TKWiki']['spiderGroups'] as $group){ $gid = AuthUtil::getGroupID($group); $groupAccess = AuthUtil::getRecursiveGroupAccess($viewRealm, $gid); if($groupAccess == 'y'){ return true; } } foreach ($cfg['TKWiki']['spiderUsers'] as $user){ $uid = AuthUtil::getUserID($user); $userAccess = AuthUtil::getRecursiveUserAccess($viewRealm, $uid); if($userAccess == 'y'){ return true; } } return false; } /** * Spider a list of pages * * Use this method to update (or in the case of a new page, create) * the stored search information. * * @param array $pageIDs An array of page IDs to spider. An empty array will cause all pages to be spidered */ public static function spiderPage($pageIDs){ global $cfg; $TKWikiDB = Database::getInstance($cfg['TKWiki']['dsn']); $cmsDB = Database::getInstance($cfg['Auth']['dsn']); if(count($pageIDs) == 0){ //Get a list of page IDs. Dont get all the content now as it would //eat memory $pageIDs = $TKWikiDB->getColumn('SELECT wikipageid FROM wikipages'); } foreach ($pageIDs as $pid){ //Remove any existing word/page links before recreating them. //Doing this now also ensures that an existing page's spidering //data is removed from the database if its permissions have //changed in a way that causes shouldSpider() to return false. $TKWikiDB->delete('wordwikipagelink', "wikipageid = $pid"); //Check that the page should be spidered if(!TKWikiUtils::shouldSpider($pid)){ //If it should not, then skip this loop continue; } //Get the content for this page $regionID = TKWikiUtils::getPageRegion($pid); if(is_null($regionID)){ throw new LoggedException("The page with id '$pid' does not exist", 0, self::module , 'error'); } $content = $cmsDB->getOne('SELECT content FROM cmscontent WHERE regionid = ? ORDER BY timestamp DESC LIMIT 1', array($regionID)); if(is_null($content)){ throw new LoggedException("The page with id '$pid' has no content associated with it", 0, self::module , 'error'); } //Strip out html tags, html special codes, then split into words $content = strip_tags($content); $content = ereg_replace('/&\w;/', '', $content); $words = array(); preg_match_all("/(\b[\w+]+\b)/", $content, $words); foreach ($words[1] as $currentWord){ //Ignore words of 2 chars or less, or if it is in $cfg['TKWiki']['ignoreWords'] if(strlen($currentWord) <= 2 || in_array($currentWord, $cfg['TKWiki']['ignoreWords'])){ continue; } //See if the word exists $wordid = $TKWikiDB->getOne('SELECT wordid FROM words WHERE word = ?', array($currentWord)); //If the word does not exist, create it if(is_null($wordid)){ $insert = array('wordid' => '#id#', 'word' => $currentWord, 'soundex' => soundex($currentWord)); $wordid = $TKWikiDB->insert('words', $insert); } //We now have the id of the word (be it new or old). //Check if the word/page link exists. If it does, //incremenet the count, otherwise create it $linkid = $TKWikiDB->getOne('SELECT linkid FROM wordwikipagelink WHERE wordid = ? AND wikipageid = ?', array($wordid, $pid)); if(!is_null($linkid)){ $prep = $TKWikiDB->prepare('UPDATE wordwikipagelink SET count = count + 1 WHERE linkid = ?'); $TKWikiDB->execute($prep, array($linkid)); }else{ $insert = array('linkid' => '#id#', 'wordid' => $wordid, 'count' => 1, 'wikipageid' => $pid); $TKWikiDB->insert('wordwikipagelink', $insert); } } } } public static function diffText($orig, $final){ $diffObj = new Text_Diff('native', array(split("\n", $orig), split("\n", $final))); $changes = $diffObj->getDiff(); $out = array(); for($i=0; $iorig), count($changes[$i]->final)); if($changes[$i] instanceof Text_Diff_Op_add ){ $out[$i]['type'] = 'Add'; }else if ($changes[$i] instanceof Text_Diff_Op_change ){ $out[$i]['type'] = 'Change'; }else if ($changes[$i] instanceof Text_Diff_Op_copy ){ $out[$i]['type'] = 'Copy'; }else if ($changes[$i] instanceof Text_Diff_Op_delete ){ $out[$i]['type'] = 'Delete'; } if(is_array($changes[$i]->orig)){ foreach ($changes[$i]->orig as $k => $line){ if(strlen($line) == 0 || preg_match('/^[\s]*$/', $line)){ $out[$i]['orig'][$k] = "
\n"; }else{ $out[$i]['orig'][$k] = TKWikiUtils::htmlifyWhitespace(htmlspecialchars($line)) . "
\n"; } } }else{ $out[$i]['orig'] = $changes[$i]->orig; } if(is_array($changes[$i]->final)){ foreach ($changes[$i]->final as $k => $line){ if(strlen($line) == 0 || preg_match('/^[\s]*$/', $line)){ $out[$i]['final'][$k] = "
\n"; }else{ $out[$i]['final'][$k] = TKWikiUtils::htmlifyWhitespace(htmlspecialchars($line)) . "
\n"; } } }else{ $out[$i]['final'] = $changes[$i]->final; } } return $out; } /** * Converts whitespace to it's HTML code equivalent * @internal This method is taken from TextPasteUtils in the TextPaste module * @param unknown_type $text */ public static function htmlifyWhitespace($text){ $out = str_replace(' ', '  ', $text); $out = str_replace('  ', '  ', $out); $out = str_replace("\t", str_repeat(' ', 3), $out); return $out; } /** * Returns the UNIX timestamp on which the specified page version was created * * @param int $versionNumber The versions number as listed in the cmscontent table * @return mixed The integer timestamp if the version was found, false if the version was not found */ public static function getVersionTimestamp($pageVersion){ global $cfg; $db = Database::getInstance($cfg['CMS']['dsn']); $sql = 'SELECT timestamp FROM cmscontent WHERE contentid = ? LIMIT 1'; $timestamp = $db->getOne($sql, array($pageVersion)); if(is_null($timestamp)){ return false; }else{ return $timestamp; } } public static function checkFileExtension($fileName){ global $cfg; $ext = explode('.', strrev($fileName)); if(count($ext) == 1) { return false; //The file has no extension } $ext = strrev($ext[0]); if($ext == '') { return false; //The file ended with a '.' }//Users will not be allowed to upload files with the following extensions if(in_array($ext, $cfg['TKWiki']['bannedUploadExtensions'])){ return false; //The file has a banned extension (and this should have been caught at the client) } return true; //All tests passed, extension is ok } public static function getFileIconNameByExtension($fileExt){ global $cfg; foreach ($cfg['TKWiki']['iconMap'] as $class => $exts){ if(in_array(strtolower($fileExt), $exts)){ return $class; } } return 'file'; } public static function getFileRow($fileID){ global $cfg; $db = Database::getInstance($cfg['CMS']['dsn']); $sql = 'SELECT * FROM wikifiles WHERE fileid = ?'; $row = $db->getRow($sql, array($fileID)); return $row; } } ?>