浏览代码

Added api.xml

Victor De la Rocha 16 年前
父节点
当前提交
f35a98dc67
共有 2 个文件被更改,包括 116 次插入108 次删除
  1. 54 0
      admin/themes/admin/api.xml
  2. 62 108
      api.php

+ 54 - 0
admin/themes/admin/api.xml 查看文件

@@ -0,0 +1,54 @@
1
+{header Content-type: text/xml; charset=utf-8}
2
+<?xml version="1.0" encoding="UTF-8"?>
3
+	<gelato version="1.0">
4
+		<tumblelog name="{username}" timezone="{conf.offsetCity}" title="{conf.title}">
5
+			{conf.description}
6
+			<feeds>
7
+			{block $feeds as $feed}
8
+				<feed id="{$feed.id_feed}" url="{$feed.url}" import-type="{$feed.type}" next-update-in-seconds="{$feed.getNextUpdate}" title="{$feed.title}" error-text="{$feed.error_text}" />
9
+			{/block}
10
+			</feeds>
11
+		</tumblelog>	
12
+		<posts start="{start}" total="{total}">
13
+		{block $posts as $post}
14
+			{if $post.type=='post'}
15
+			<post id="{$post.id_post}" url="{$post.url}" type="regular" date="{$post.formatedDate}">
16
+				<regular-title>{$post.tit}</regular-title>
17
+				<regular-body>{$post.desc}</regular-body>
18
+			</post>
19
+			{elseif $post.type=='photo'}
20
+			<post id="{$post.id_post}" url="{$post.url}" type="photo" date="{$post.formatedDate}">
21
+				<photo-caption>{$post.tit}</photo-caption>
22
+				<photo-url>{$post.photoPath}</photo-url>
23
+			</post>
24
+			{elseif $post.type=='quote'}
25
+			<post id="{$post.id_post}" url="{$post.url}" type="quote" date="{$post.formatedDate}">
26
+				<quote-text>{$post.desc}</quote-text>
27
+				<quote-source>{$post.title}</quote-source>
28
+			</post>
29
+			{elseif $post.type=='url'}
30
+			<post id="{$post.id_post}" url="{$post.url}" type="link" date="{$post.formatedDate}">
31
+				<link-text>{$post.tit}</link-text>
32
+				<link-url>{$post.url}</link-url>
33
+			</post>
34
+			{elseif $post.type=='conversation'}
35
+			<post id="{$post.id_post}" url="{$post.url}" type="conversation" date="{$post.formatedDate}">
36
+				<conversation-title>{$post.tit}</conversation-title>
37
+				<conversation-text>{$post.desc}</conversation-text>
38
+				{$post.descAPIFormat}
39
+			</post>
40
+			{elseif $post.type=='video'}
41
+			<post id="{$post.id_post}" url="{$post.url}" type="video" date="{$post.formatedDate}">
42
+				<video-caption>{$post.tit}</video-caption>
43
+				<video-source>{$post.url}</video-source>
44
+				<video-player>{$post.desc}</video-player>                            
45
+			</post>
46
+			{elseif $post.type=='mp3'}
47
+			<post id="{$post.id_post}" url="{$post.url}" type="audio" date="{$post.formatedDate}">
48
+				<audio-caption>{$post.tit}</audio-caption>
49
+				<audio-player>{$post.desc}</audio-player>                            
50
+			</post>
51
+			{/if}
52
+		{/block}
53
+		</posts>
54
+	</gelato>

+ 62 - 108
api.php 查看文件

@@ -12,17 +12,14 @@ if(!defined('entry')) define('entry',true);
12 12
   =========================== */
13 13
 ?>
14 14
 <?php
15
-	header("Content-type: text/xml; charset=utf-8");
16 15
 	$isFeed = true;
17 16
 	
18 17
 	require('entry.php');
19 18
 	global $user, $conf, $tumble;
20 19
 	$f = new feeds();
21
-	
22
-	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
23
-?>
24
-	<gelato version="1.0">
25
-<?php	
20
+	
21
+	$theme = new themes;
22
+
26 23
 	if (isset($_GET["action"]) && $_GET["action"] == "read") {
27 24
 		if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; }
28 25
 		if (isset($_GET["total"])) { $total = $_GET["total"]; } else { $total = 20; }
@@ -30,122 +27,79 @@ if(!defined('entry')) define('entry',true);
30 27
 		if ($total > 50) { $total = 50; }
31 28
 		$user = new user();
32 29
 		$userData = $user->getUserByID(1);
33
-		$username = ($userData["name"] == "") ? "gelato" : $userData["name"];
34
-?>		
35
-		<tumblelog name="<?php echo $username;?>" timezone="<?php echo $conf->offsetCity;?>" title="<?php echo $conf->title;?>">
36
-<?php 	
37
-		echo "\n\t".$conf->description."\n";
38
-?>
39
-			<feeds>
40
-<?php
41
-				$actual_feeds = $f->getFeedList();
42
-				foreach($actual_feeds as $feed){
43
-					$error_text = ($feed["error"]>0) ? "false" : "true";
44
-?>
45
-					<feed id="<?php echo $feed["id_feed"];?>" url="<?php echo htmlspecialchars($feed["url"]);?>" import-type="<?php echo util::type2Text($feed["type"]);?>" next-update-in-seconds="<? echo $f->getNextUpdate($feed["id_feed"]);?>" title="<?php echo htmlspecialchars($feed["title"]);?>" error-text="<? echo $error_text;?>"/>
46
-<?php
47
-				}
48
-?>
49
-            </feeds>
50
-        </tumblelog>	
30
+		$username = ($userData["name"] == "") ? "gelato" : $userData["name"];
31
+
32
+		$theme->set("username",$username);
33
+		$theme->set("conf",array(
34
+			"offsetCity"=>$conf->offsetCity,
35
+			"title"=>$conf->title,
36
+			"description"=>$conf->description
37
+		));
38
+
39
+		$feeds = array();
		$actual_feeds = $f->getFeedList();
40
+		foreach($actual_feeds as $feed){
41
+			$error_text = ($feed["error"]>0) ? "false" : "true";
42
+			$feed['url'] = htmlspecialchars($feed['url']);
43
+			$feed['type'] = util::type2Text($feed['type']);
44
+			$feed['getNextUpdate'] = $f->getNextUpdate($feed['id_feed']);
45
+			$feed['title'] = htmlspecialchars($feed['title']);
46
+			$feed['error_text'] = $error_text;
47
+			$feeds[] = $feed;
48
+		}
49
+		
50
+		$theme->set("feeds",$feeds);
51 51
 
52
-<?php
53 52
 		if ($hasType) {
54 53
 			$postType = type2Number($_GET["type"]);
55 54
 		}
56 55
 		$rs = $tumble->getPosts($total, $start);
57
-		if ($db->contarRegistros()>0) {
58
-?>
59
-			<posts start="<?php echo $start; ?>" total="<?php echo $total; ?>">
60
-<?php 
61
-			while($register = mysql_fetch_array($rs)) {
62
-				$desc = util::trimString($register["description"]);				
56
+		if ($db->contarRegistros()>0) {
57
+			$theme->set("start",$start);
58
+			$theme->set("total",$total);
59
+
60
+			while($post = mysql_fetch_assoc($rs)){
61
+				$post['desc'] = util::trimString($post["description"]);				
63 62
 				$strEnd = ($conf->urlFriendly) ? "/" : "";
64
-				$url = $conf->urlGelato.($conf->urlFriendly ? "/post/" : "/index.php?post=").$register["id_post"].$strEnd;
65
-				$formatedDate = gmdate("D, d M Y H:i:s", strtotime($register["date"]) + util::transform_offset($conf->offsetTime));
66
-				
67
-				switch ($register["type"]) {
68
-					case "1":
63
+				$post['url'] = $conf->urlGelato.($conf->urlFriendly ? "/post/" : "/index.php?post=").$post["id_post"].$strEnd;
64
+				$post['formatedDate'] = gmdate("D, d M Y H:i:s", strtotime($post["date"]) + util::transform_offset($conf->offsetTime));
65
+				
66
+				$post['type'] = util::type2Text($post["type"]);
69 67
 
70
-						$tit = (empty($register["title"])) ? $desc : strip_tags($register["title"]);
71
-?>						
72
-						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="regular" date="<?php echo $formatedDate;?>">
73
-							<regular-title><?php echo $tit;?></regular-title>
74
-							<regular-body><?php echo $desc;?></regular-body>
75
-						</post>
76
-<?php						
68
+				switch ($post["type"]) {
69
+					case "post":
70
+						$post['tit'] = (empty($post["title"])) ? $desc : strip_tags($post["title"]);
77 71
 						break;
78
-					case "2":
79
-						$tit = (empty($register["description"])) ? "Photo" : $desc;
80
-?>
81
-						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="photo" date="<?php echo $formatedDate;?>">
82
-<?php
83
-							$photoPath = str_replace("../", $conf->urlGelato."/", $register["url"]);
84
-?>
85
-                            <photo-caption><?php echo stripslashes($tit);?></photo-caption>
86
-                            <photo-url><?php echo $photoPath;?></photo-url>                            
87
-                        </post>
88
-<?php
72
+					case "photo":
73
+						$post['photoPath'] = str_replace("../", $conf->urlGelato."/", $post["url"]);
74
+						$post['tit'] = stripslashes(((empty($post["description"])) ? "Photo" : $post['desc']));
89 75
 						break;
90
-					case "3":						
91
-?>
92
-						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="quote" date="<?php echo $formatedDate;?>">
93
-							<quote-text><?php echo $desc; ?></quote-text>
94
-							<quote-source><?php echo strip_tags($register["title"]); ?></quote-source>
95
-						</post>
96
-<?php
76
+					case "quote":
77
+						$post['title'] = strip_tags($post["title"]);
97 78
 						break;
98
-					case "4":
99
-						$tit = (empty($register["title"])) ? $register["url"] : strip_tags($register["title"]);
100
-?>
101
-						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="link" date="<?php echo $formatedDate;?>">
102
-                            <link-text><?php echo $tit; ?></link-text>
103
-                            <link-url><?php echo $register["url"]; ?></link-url>
104
-                        </post>
105
-<?php
79
+					case "url":
80
+						$post['tit'] = (empty($post["title"])) ? $post["url"] : strip_tags($post["title"]);
106 81
 						break;
107
-					case "5":
82
+					case "conversation":
108 83
 						$lines = explode("\n", $desc);
109 84
 						$line = $lines[0];
110
-						$tit = (empty($register["title"])) ? trimString($line) : $register["title"];
111
-						$desc = $tumble->formatConversation($desc);
112
-?>
113
-						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="conversation" date="<?php echo $formatedDate;?>">
114
-                            <conversation-title><?php echo $tit; ?></conversation-title>
115
-                            <conversation-text><?php echo $desc; ?></conversation-text>
116
-                            <?php echo $tumble->formatApiConversation($desc); ?>
117
-                        </post>
118
-<?php
85
+						$post['tit'] = (empty($post["title"])) ? trimString($line) : $post["title"];
86
+						$post['desc'] = $tumble->formatConversation($desc);
87
+						$post['descAPIFormat'] = $tumble->formatConversation($desc);
119 88
 						break;
120
-					case "6":
121
-						$tit = (empty($register["description"])) ? "Video" : $desc;
122
-						$desc = $tumble->getVideoPlayer($register["url"]);
123
-?>
124
-						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="video" date="<?php echo $formatedDate;?>">
125
-                            <video-caption><?php echo $tit; ?></video-caption>
126
-                            <video-source><?php echo $register["url"]; ?></video-source>
127
-                            <video-player><?php echo htmlspecialchars($desc); ?></video-player>                            
128
-                        </post>
129
-<?php
89
+					case "video":
90
+						$post['tit'] = (empty($post["description"])) ? "Video" : $desc;
91
+						$post['desc'] = htmlspecialchars($tumble->getVideoPlayer($post["url"]));
130 92
 						break;
131
-
132
-					case "7":
133
-						$tit = (empty($register["description"])) ? "Audio" : $desc;
134
-						$desc = $tumble->getMp3Player($register["url"]);
135
-?>
136
-						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="audio" date="<?php echo $formatedDate;?>">
137
-                            <audio-caption><?php echo $tit; ?></audio-caption>
138
-                            <audio-player><?php echo htmlspecialchars($desc); ?></audio-player>                            
139
-                        </post>
140
-<?php
93
+					case "mp3":
94
+						$post['tit'] = (empty($post["description"])) ? "Audio" : $desc;
95
+						$desc = htmlspecialchars($tumble->getMp3Player($post["url"]));
141 96
 						break;
142
-
143
-				}				
144
-			} 
145
-?>
146
-				</posts>
147
-<?php	
97
+				}				
98
+				$posts[] = $post;
99
+			}
100
+			$theme->set("posts",$posts);
148 101
 		}
149
-	}
150
-?>
151
-		</gelato>
102
+	}
103
+
104
+$theme->display(Absolute_Path.'admin/themes/admin/api.xml');
105
+?>