Jelajahi Sumber

Sync API comment and small fixes. Templates for API documentation

seavenois 10 tahun lalu
induk
melakukan
8a76dfe748

+ 8 - 0
www/.htaccess

@@ -1,3 +1,5 @@
+#RewriteMap lc int:tolower
+
 ErrorDocument 403     /error/403.php
 ErrorDocument 404     /error/404.php
 ErrorDocument 500     /error/500.php
@@ -12,6 +14,8 @@ AddHandler php5-cgi .xml
 # </FilesMatch>
 Options +FollowSymlinks
 RewriteEngine on
+CheckSpelling on
+
 
 RewriteRule ^sitemap.xml$ /sitemap.php [NC]
 RewriteRule ^imgmap.xml$ /sitemap-image.php [NC]
@@ -44,6 +48,10 @@ RewriteRule ^galeria/([A-Z\-a-z0-9{3,}]+)/$ /galeria/album.php?perm=$1 [NC]
 RewriteRule ^galeria/([A-Z\-a-z0-9{3,}]+)/([A-Z\-a-z0-9{3,}]+)$ /galeria/photo.php?album=$2&perm=$1 [NC]
 RewriteRule ^galeria/([A-Z\-a-z0-9{3,}]+)/([A-Z\-a-z0-9{3,}]+)/$ /galeria/photo.php?album=$2&perm=$1 [NC]
 
+#API redirections
+#TODO: This changes the url in the browser
+RewriteRule ^API/V([{0-9}]+)/help/([A-Z\-a-z0-9{3,}]+)$ /API/V$1/help/$2.php [NC,QSA,L]
+RewriteRule ^API/V([{0-9}]+)/help/([A-Z\-a-z0-9{3,}]+)/$ /API/V$1/help/$2.php [L,NC]
 
 # BEGIN Cache-Control Headers
 <IfModule mod_expires.c>

+ 56 - 0
www/API/v1/help/comment.php

@@ -0,0 +1,56 @@
+<?php 
+	$http_host = $_SERVER['HTTP_HOST']; 
+	$v = 1;
+?>
+
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
+		<meta charset="utf-8"/>
+		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
+		<title>Gasteizko Margolariak API v<?php echo($v); ?> Documentation</title>
+		<link rel="shortcut icon" href="<?php echo "http://$http_host/img/logo/favicon.ico";?>">
+		<!-- CSS files -->
+		<style>
+			<?php 
+				include("../../../css/ui.css"); 
+				include("../../../css/index.css");
+			?>
+		</style>
+		<!-- CSS for mobile version -->
+		<style media="(max-width : 990px)">
+			<?php 
+				include("../../../css/m/ui.css"); 
+				include("../../../css/m/index.css");
+			?>
+		</style>
+		<!-- Script files -->
+		<script type="text/javascript">
+			<?php include("../../../script/ui.js"); ?>
+		</script>
+		<!-- Meta tags -->
+		<link rel="canonical" href="<?php echo "http://$http_host/API/help/V$v"; ?>"/>
+		<link rel="author" href="<?php echo "http://$http_host"; ?>"/>
+		<link rel="publisher" href="<?php echo "http://$http_host"; ?>"/>
+		<meta name="description" content="<?php echo $lng['index_description'];?>"/>
+		<meta property="og:title" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation"/>
+		<meta property="og:url" content="<?php echo "http://$http_host/API/help/V$v"; ?>"/>
+		<meta property="og:description" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation - Index page"/>
+		<meta property="og:image" content="<?php echo "http://$http_host/img/logo/logo-api.png";?>"/>
+		<meta property="og:site_name" content="Gasteizko Margolariak"/>
+		<meta property="og:type" content="website"/>
+		<meta property="og:locale" content="en"/>
+		<meta name="twitter:card" content="summary"/>
+		<meta name="twitter:title" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation""/>
+		<meta name="twitter:description" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation - Index page"/>
+		<meta name="twitter:image" content="<?php echo "http://$http_host/img/logo/logo-api.png";?>"/>
+		<meta name="twitter:url" content="<?php echo "http://$http_host/API/help/V$v"; ?>"/>
+		<meta name="robots" content="index follow"/>
+	</head>
+	<body>
+		<?php include("toolbar.php"); ?>
+		<div id="content">
+		</div>
+	</body>
+</body>

+ 56 - 1
www/API/v1/help/index.php

@@ -1 +1,56 @@
- 
+<?php 
+	$http_host = $_SERVER['HTTP_HOST']; 
+	$v = 1;
+?>
+
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
+		<meta charset="utf-8"/>
+		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
+		<title>Gasteizko Margolariak API v<?php echo($v); ?> Documentation</title>
+		<link rel="shortcut icon" href="<?php echo "http://$http_host/img/logo/favicon.ico";?>">
+		<!-- CSS files -->
+		<style>
+			<?php 
+				include("../../../css/ui.css"); 
+				include("../../../css/index.css");
+			?>
+		</style>
+		<!-- CSS for mobile version -->
+		<style media="(max-width : 990px)">
+			<?php 
+				include("../../../css/m/ui.css"); 
+				include("../../../css/m/index.css");
+			?>
+		</style>
+		<!-- Script files -->
+		<script type="text/javascript">
+			<?php include("../../../script/ui.js"); ?>
+		</script>
+		<!-- Meta tags -->
+		<link rel="canonical" href="<?php echo "http://$http_host/API/help/V$v"; ?>"/>
+		<link rel="author" href="<?php echo "http://$http_host"; ?>"/>
+		<link rel="publisher" href="<?php echo "http://$http_host"; ?>"/>
+		<meta name="description" content="<?php echo $lng['index_description'];?>"/>
+		<meta property="og:title" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation"/>
+		<meta property="og:url" content="<?php echo "http://$http_host/API/help/V$v"; ?>"/>
+		<meta property="og:description" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation - Index page"/>
+		<meta property="og:image" content="<?php echo "http://$http_host/img/logo/logo-api.png";?>"/>
+		<meta property="og:site_name" content="Gasteizko Margolariak"/>
+		<meta property="og:type" content="website"/>
+		<meta property="og:locale" content="en"/>
+		<meta name="twitter:card" content="summary"/>
+		<meta name="twitter:title" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation""/>
+		<meta name="twitter:description" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation - Index page"/>
+		<meta name="twitter:image" content="<?php echo "http://$http_host/img/logo/logo-api.png";?>"/>
+		<meta name="twitter:url" content="<?php echo "http://$http_host/API/help/V$v"; ?>"/>
+		<meta name="robots" content="index follow"/>
+	</head>
+	<body>
+		<?php include("toolbar.php"); ?>
+		<div id="content">
+		</div>
+	</body>
+</body>

+ 56 - 0
www/API/v1/help/sync.php

@@ -0,0 +1,56 @@
+<?php 
+	$http_host = $_SERVER['HTTP_HOST']; 
+	$v = 1;
+?>
+
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
+		<meta charset="utf-8"/>
+		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
+		<title>Gasteizko Margolariak API v<?php echo($v); ?> Documentation</title>
+		<link rel="shortcut icon" href="<?php echo "http://$http_host/img/logo/favicon.ico";?>">
+		<!-- CSS files -->
+		<style>
+			<?php 
+				include("../../../css/ui.css"); 
+				include("../../../css/index.css");
+			?>
+		</style>
+		<!-- CSS for mobile version -->
+		<style media="(max-width : 990px)">
+			<?php 
+				include("../../../css/m/ui.css"); 
+				include("../../../css/m/index.css");
+			?>
+		</style>
+		<!-- Script files -->
+		<script type="text/javascript">
+			<?php include("../../../script/ui.js"); ?>
+		</script>
+		<!-- Meta tags -->
+		<link rel="canonical" href="<?php echo "http://$http_host/API/help/V$v"; ?>"/>
+		<link rel="author" href="<?php echo "http://$http_host"; ?>"/>
+		<link rel="publisher" href="<?php echo "http://$http_host"; ?>"/>
+		<meta name="description" content="<?php echo $lng['index_description'];?>"/>
+		<meta property="og:title" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation"/>
+		<meta property="og:url" content="<?php echo "http://$http_host/API/help/V$v"; ?>"/>
+		<meta property="og:description" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation - Index page"/>
+		<meta property="og:image" content="<?php echo "http://$http_host/img/logo/logo-api.png";?>"/>
+		<meta property="og:site_name" content="Gasteizko Margolariak"/>
+		<meta property="og:type" content="website"/>
+		<meta property="og:locale" content="en"/>
+		<meta name="twitter:card" content="summary"/>
+		<meta name="twitter:title" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation""/>
+		<meta name="twitter:description" content="Gasteizko Margolariak API v<?php echo($v); ?> Documentation - Index page"/>
+		<meta name="twitter:image" content="<?php echo "http://$http_host/img/logo/logo-api.png";?>"/>
+		<meta name="twitter:url" content="<?php echo "http://$http_host/API/help/V$v"; ?>"/>
+		<meta name="robots" content="index follow"/>
+	</head>
+	<body>
+		<?php include("toolbar.php"); ?>
+		<div id="content">
+		</div>
+	</body>
+</body>

+ 27 - 0
www/API/v1/help/toolbar.php

@@ -0,0 +1,27 @@
+ <div id="header" class="desktop">
+	<div id="header_content">
+		<img src="/img/logo/logo-api.png"/>
+		<div id="header_menu">
+			<table>
+				<tr>
+					<td><a href="http://<?php echo($http_host . "API/help/V$v/"); ?>">API documentation</a></td>
+					<td><a href="http://<?php echo($http_host . "API/help/V$v/sync/"); ?>">Sync</a></td>
+					<td><a href="http://<?php echo($http_host . "API/help/V$v/comment/"); ?>">Comment</a></td>
+					<td><a href="http://<?php echo($http_host); ?>/">Main page</a></td>
+				</tr>
+			</table>
+		</div>
+	</div>
+</div>
+<div id="header_m" class="mobile">
+	<img src="/img/logo/logo-api.png" onClick='toggleMobileMenu();' id='mobile_logo'/>
+	<div id="header_menu_m">
+		<div id='header_m_title' onClick='openMobileMenu();' class='pointer'><span><img src='http://<?php echo $http_host; ?>/img/misc/slid-menu.png'/>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $cur_section; ?></span></div>
+		<div class='header_m_link'><a href="http://<?php echo($http_host . "API/help/V$v/"); ?>">API documentation</a></div>
+		<div class='header_m_link'><a href="http://<?php echo($http_host . "API/help/V$v/sync/"); ?>">Sync</a></div>
+		<div class='header_m_link'><a href="http://<?php echo($http_host . "API/help/V$v/comment/"); ?>">Comment</a></div>
+		<div class='header_m_link'><a href="http://<?php echo($http_host); ?>/">Main page</a></div>
+		<div id='header_m_slider' onClick='closeMobileMenu();' class='pointer'><span><img src='http://<?php echo $http_host; ?>/img/misc/slid-top.png'/></span></div>
+	</div><br/><br/>
+</div>
+

+ 35 - 3
www/API/v1/sync.php

@@ -21,6 +21,10 @@
 	//Default action
 	define('DEF_ACTION', ACTION_SYNC);
 	
+	//Output keys
+	define('KEY_VERSION', 'version');
+	define('KEY_DATA', 'data');
+	
 	//$_GET valid parameters
 	define('GET_CLIENT', 'client');
 	define('GET_USER', 'user');
@@ -74,7 +78,7 @@
 	}	
 	
 	/****************************************************
-	* Echoes the version of one or more of the sections *
+	* Gives the version of one or more of the sections  *
 	* of the database, or the global section.           * 
 	*                                                   *
 	* @params:                                          *
@@ -102,6 +106,23 @@
 		}
 	}
 	
+	/****************************************************
+	* Gives the version of every section of the db.     *
+	*                                                   *
+	* @params:                                          *
+	*    con: (MySQL server connection) RO mode enough. *
+	* @return: (Assoc. array): The versions of the db.  *
+ 	****************************************************/
+	function get_all_versions($con){
+		$v = array();
+		$v[] = [SEC_ALL => get_version($con, SEC_ALL)];
+		$v[] = [SEC_BLOG => get_version($con, SEC_BLOG)];
+		$v[] = [SEC_ACTIVITIES => get_version($con, SEC_ACTIVITIES)];
+		$v[] = [SEC_GALLERY => get_version($con, SEC_GALLERY)];
+		$v[] = [SEC_LABLANCA => get_version($con, SEC_LABLANCA)];
+		return $v;
+	}
+	
 	/****************************************************
 	* Prepares the info of the database or a portion of *
 	* it in the selected format.                        * 
@@ -138,13 +159,24 @@
 				return;
 		}
 		
+		$v = array();
+		if ($section == SEC_ALL){
+			$v = get_all_versions($con);
+		}
+		else{
+			$v[] = [ $section => get_version($con, $section) ];
+		}
+		
 		switch ($format){
 			case FOR_JSON:
 				$db = array();
 				foreach($tables as $table){
 					$db[] = [ $table => get_table($con, $table, $format) ];
 				}
-				return(json_encode($db));
+				$data = array();
+				$data[] = [ KEY_VERSION => $v ];
+				$data[] = [ KEY_DATA => $db];
+				return(json_encode($data));
 				break;
 		}
 		
@@ -276,7 +308,7 @@
 		$user = '';
 	}
 	if (strlen($action) < 1){
-		$action = DEF_ACTION
+		$action = DEF_ACTION;
 	}
 	if ($action != ACTION_SYNC && $action != ACTION_VERSION){
 		//Bad request

TEMPAT SAMPAH
www/img/logo/logo-api.png