svn: /web/doc-editor/trunk/ index.php php/RepositoryFetcher.php

From: Date: Thu, 30 Dec 2010 00:10:09 +0000
Subject: svn: /web/doc-editor/trunk/ index.php php/RepositoryFetcher.php
Groups: php.doc.web 
Request: Send a blank email to doc-web+get-1918@lists.php.net to get a copy of this message
yannick Thu, 30 Dec 2010 00:10:09 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=306838 Log: Better support for the permlink. Don't allow blank & 'function' ID. Start by searching a page with this exact ID and fallback to a page containing this ID Changed paths: U web/doc-editor/trunk/index.php U web/doc-editor/trunk/php/RepositoryFetcher.php Modified: web/doc-editor/trunk/index.php =================================================================== --- web/doc-editor/trunk/index.php 2010-12-29 20:58:46 UTC (rev 306837) +++ web/doc-editor/trunk/index.php 2010-12-30 00:10:09 UTC (rev 306838) @@ -9,26 +9,33 @@ // Perm link management if (isset($_REQUEST['perm'])) { - require_once dirname(__FILE__) . '/php/ProjectManager.php'; - require_once dirname(__FILE__) . '/php/RepositoryFetcher.php'; + $perm = trim($_REQUEST['perm'], '/ '); + + if( substr($perm, -4) == '.php' ) + { + require_once dirname(__FILE__) . '/php/ProjectManager.php'; + require_once dirname(__FILE__) . '/php/RepositoryFetcher.php'; - $_project = $_REQUEST['project']; + $_project = $_REQUEST['project']; - // Set the project - ProjectManager::getInstance()->setProject($_project); + // Set the project + ProjectManager::getInstance()->setProject($_project); - $_p = explode('/', trim($_REQUEST['perm'], '/')); - $_lang = array_shift($_p); - $_file = array_pop($_p); + $_p = explode('/', $perm); + $_lang = array_shift($_p); + $_file = array_pop($_p); - $_id = explode('.', $_file); - array_pop($_id); - $xmlid = implode('.', $_id); + $_id = explode('.', $_file); + array_pop($_id); + $xmlid = implode('.', $_id); - $r = RepositoryFetcher::getInstance()->getFileByXmlID($_lang, $xmlid); + $r = RepositoryFetcher::getInstance()->getFileByXmlID($_lang, $xmlid); - if (false == is_null($r)) { - $jsVar = 'var directAccess = {"lang":"'.$r->lang.'", "path":"'.$r->path.'", "name":"'.$r->name.'", "project":"'.$_project.'"};'; + if ( $r ) { + $jsVar = 'var directAccess = {"lang":"'.$r->lang.'", "path":"'.$r->path.'", "name":"'.$r->name.'", "project":"'.$_project.'"};'; + } else { + $jsVar = 'var directAccess = false;'; + } } else { $jsVar = 'var directAccess = false;'; } Modified: web/doc-editor/trunk/php/RepositoryFetcher.php =================================================================== --- web/doc-editor/trunk/php/RepositoryFetcher.php 2010-12-29 20:58:46 UTC (rev 306837) +++ web/doc-editor/trunk/php/RepositoryFetcher.php 2010-12-30 00:10:09 UTC (rev 306838) @@ -1033,12 +1033,60 @@ */ public function getFileByXmlID($lang, $id) { + $db = DBConnection::getInstance(); $project = AccountManager::getInstance()->project; - $s = "SELECT lang, path, name FROM files - WHERE project='$project' AND lang = '$lang' AND xmlid LIKE '%$id%'"; - $r = DBConnection::getInstance()->query($s); - return $r->fetch_object(); + // If user forget ".php" at this end of the permlink, this is "function" how is search into DB. + // We don't allow it, neither blank ID + if( $id == 'function' || empty($id) ) { + return false; + } + + // We start by searching file witch only this ID + $s = sprintf( + 'SELECT + lang, path, name + FROM + files + WHERE + project="%s" AND + lang = "%s" AND + xmlid = "%s"', + $project, + $lang, + $id + ); + $r = $db->query($s); + $nb = $r->num_rows; + + if( $nb >= 1 ) { + return $r->fetch_object(); + } else { + + // We now search file which contain this ID + $s = sprintf( + 'SELECT + lang, path, name + FROM + files + WHERE + project="%s" AND + lang = "%s" AND + xmlid LIKE "%%%s%%"', + $project, + $lang, + $id + ); + $r = $db->query($s); + $nb = $r->num_rows; + + if( $nb == 0 ) { + return false; + } else { + return $r->fetch_object(); + } + + } } /**

« previous php.doc.web (#1918) next »