Bläddra i källkod

Crop improved on API, RSS, Comments and Page Titles when long names

pecesama 16 år sedan
förälder
incheckning
b060b0becb
4 ändrade filer med 34 tillägg och 44 borttagningar
  1. 14 17
      api.php
  2. 6 0
      classes/functions.php
  3. 8 16
      index.php
  4. 6 11
      rss.php

+ 14 - 17
api.php Visa fil

@@ -59,16 +59,16 @@ if(!defined('entry')) define('entry',true);
59 59
 			<posts start="<?php echo $start; ?>" total="<?php echo $total; ?>">
60 60
 <?php 
61 61
 			while($register = mysql_fetch_array($rs)) {
62
-				$desc = htmlspecialchars($register["description"]);
63
-				$url = $conf->urlGelato."/index.php?post=".$register["id_post"];
64
-				$formatedDate = gmdate("D, d M Y H:i:s", strtotime($register["date"])+transform_offset($conf->offsetTime));
62
+				$desc = trimString($register["description"]);				
63
+				$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"]) + transform_offset($conf->offsetTime));
65 66
 				
66 67
 				switch ($register["type"]) {
67 68
 					case "1":
68 69
 
69
-						$tit = ($register["title"]=="") ? $desc : $register["title"];
70
-?>
71
-						
70
+						$tit = (empty($register["title"])) ? $desc : strip_tags($register["title"]);
71
+?>						
72 72
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="regular" date="<?php echo $formatedDate;?>">
73 73
 							<regular-title><?php echo $tit;?></regular-title>
74 74
 							<regular-body><?php echo $desc;?></regular-body>
@@ -76,7 +76,7 @@ if(!defined('entry')) define('entry',true);
76 76
 <?php						
77 77
 						break;
78 78
 					case "2":
79
-						$tit = ($register["description"]=="") ? "Photo" : $desc;
79
+						$tit = (empty($register["description"])) ? "Photo" : $desc;
80 80
 ?>
81 81
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="photo" date="<?php echo $formatedDate;?>">
82 82
 <?php
@@ -91,12 +91,12 @@ if(!defined('entry')) define('entry',true);
91 91
 ?>
92 92
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="quote" date="<?php echo $formatedDate;?>">
93 93
 							<quote-text><?php echo $desc; ?></quote-text>
94
-							<quote-source><?php echo $register["title"]; ?></quote-source>
94
+							<quote-source><?php echo strip_tags($register["title"]); ?></quote-source>
95 95
 						</post>
96 96
 <?php
97 97
 						break;
98 98
 					case "4":
99
-						$tit = ($register["title"]=="") ? $register["url"] : $register["title"];
99
+						$tit = (empty($register["title"])) ? $register["url"] : strip_tags($register["title"]);
100 100
 ?>
101 101
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="link" date="<?php echo $formatedDate;?>">
102 102
                             <link-text><?php echo $tit; ?></link-text>
@@ -107,7 +107,7 @@ if(!defined('entry')) define('entry',true);
107 107
 					case "5":
108 108
 						$lines = explode("\n", $desc);
109 109
 						$line = $lines[0];
110
-						$tit = ($register["title"]=="") ? $line : $register["title"];
110
+						$tit = (empty($register["title"])) ? trimString($line) : $register["title"];
111 111
 						$desc = $tumble->formatConversation($desc);
112 112
 ?>
113 113
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="conversation" date="<?php echo $formatedDate;?>">
@@ -118,7 +118,7 @@ if(!defined('entry')) define('entry',true);
118 118
 <?php
119 119
 						break;
120 120
 					case "6":
121
-						$tit = ($register["description"]=="") ? "Video" : $desc;
121
+						$tit = (empty($register["description"])) ? "Video" : $desc;
122 122
 						$desc = $tumble->getVideoPlayer($register["url"]);
123 123
 ?>
124 124
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="video" date="<?php echo $formatedDate;?>">
@@ -130,7 +130,7 @@ if(!defined('entry')) define('entry',true);
130 130
 						break;
131 131
 
132 132
 					case "7":
133
-						$tit = ($register["description"]=="") ? "Audio" : $desc;
133
+						$tit = (empty($register["description"])) ? "Audio" : $desc;
134 134
 						$desc = $tumble->getMp3Player($register["url"]);
135 135
 ?>
136 136
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="audio" date="<?php echo $formatedDate;?>">
@@ -140,11 +140,8 @@ if(!defined('entry')) define('entry',true);
140 140
 <?php
141 141
 						break;
142 142
 
143
-				}
144
-				$url = $conf->urlGelato."/index.php/post/".$register["id_post"]."/";
145
-				$formatedDate = gmdate("D, d M Y H:i:s", strtotime($register["date"])+transform_offset($conf->offsetTime));
146
-			}		
147
- 
143
+				}				
144
+			} 
148 145
 ?>
149 146
 				</posts>
150 147
 <?php	

+ 6 - 0
classes/functions.php Visa fil

@@ -471,4 +471,10 @@ if(!defined('entry') || !entry) die('Not a valid page');
471 471
 		}
472 472
 		return $tmpStr;
473 473
 	}
474
+	
475
+	function trimString($string, $len = "") {
476
+		$string = strip_tags($string)
477
+		$len = (empty($len)) ? "50" : $len ;		
478
+		return ( strpos($string, " ", $len) ) ? substr_replace($string, "...", $len) : $string ;
479
+	}
474 480
 ?>

+ 8 - 16
index.php Visa fil

@@ -18,7 +18,7 @@ require_once('entry.php');
18 18
 global $user, $tumble, $conf;
19 19
 
20 20
 $theme = new themes;
21
-        // My approach to MVC
21
+        // Our first approach to MVC... ¿our second? visit http://www.flavorphp.com
22 22
 
23 23
         if(isset($_SERVER['PATH_INFO'])) $param_url = explode("/",$_SERVER['PATH_INFO']);
24 24
 
@@ -49,7 +49,7 @@ $theme = new themes;
49 49
         }
50 50
 
51 51
         $gelato_includes = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n";
52
-        $gelato_includes .= "\t<meta name=\"generator\" content=\"gelato  ".codeName()." (".version().")\" />\n";
52
+        $gelato_includes .= "\t<meta name=\"generator\" content=\"gelato ".codeName()." (".version().")\" />\n";
53 53
         $gelato_includes .= "\t<link rel=\"shortcut icon\" href=\"".$conf->urlGelato."/images/favicon.ico\" />\n";
54 54
         $gelato_includes .= "\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"".$conf->urlGelato.($conf->urlFriendly?"/rss/":"/rss.php")."\"/>\n";
55 55
         $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/themes/".$conf->template."/style.css\"/>\n";
@@ -64,11 +64,7 @@ $theme = new themes;
64 64
 			$register = $tumble->getPost($id_post);			
65 65
 			if (empty($register["title"])) {
66 66
 				if (!empty($register["description"])) {
67
-					if (strlen($register["description"]) > $page_title_len) {
68
-						$page_title_data = substr($register["description"], 0, $page_title_len)."...";
69
-					} else {
70
-						$page_title_data = $register["description"];
71
-					}
67
+					$page_title_data = trimString($register["description"], $page_title_len);
72 68
 				} else {
73 69
 					$page_title_data =  type2Text($register["type"]);
74 70
 				}
@@ -76,7 +72,7 @@ $theme = new themes;
76 72
 				$page_title_data = $register["title"];
77 73
 			}			
78 74
 			if (!empty($page_title_data)) {
79
-				$page_title .= $page_title_divisor.stripslashes(strip_tags($page_title_data));
75
+				$page_title .= $page_title_divisor.stripslashes($page_title_data);
80 76
 			}
81 77
 		}
82 78
 
@@ -278,15 +274,11 @@ $theme = new themes;
278 274
 					$user = new user();
279 275
 					$username = $user->getUserByID($register["id_user"]);
280 276
 
281
-					$row['User'] = $username["name"];
277
+					$row["User"] = $username["name"];
282 278
 					
283 279
 					if (empty($register["title"])) {
284 280
 						if (!empty($register["description"])) {
285
-							if (strlen($register["description"]) > 30) {
286
-								$postTitle = substr($register["description"], 0, 30)."...";
287
-							} else {
288
-								$postTitle = $register["description"];
289
-							}
281
+							$postTitle = trimString($register["description"]);
290 282
 						} else {
291 283
 							$postTitle =  type2Text($register["type"]);
292 284
 						}
@@ -294,8 +286,8 @@ $theme = new themes;
294 286
 						$postTitle = $register["title"];
295 287
 					}					
296 288
 
297
-					$row['Post_Title'] = strip_tags($postTitle);
298
-					$row['Comments_Number'] = $comment->countComments($register["id_post"]);
289
+					$row["Post_Title"] = $postTitle;
290
+					$row["Comments_Number"] = $comment->countComments($register["id_post"]);
299 291
 
300 292
 					$rows[] = $row;
301 293
 					$theme->set('rows',$rows);

+ 6 - 11
rss.php Visa fil

@@ -20,21 +20,18 @@ if(!defined('entry')) define('entry',true);
20 20
 	
21 21
 	
22 22
 	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
23
-?>
24
-	
23
+?>	
25 24
 	<rss version="2.0">
26 25
 	<channel>
27 26
 		<title><?php echo htmlspecialchars($conf->title);?></title>
28 27
 		<link><?php echo $conf->urlGelato;?></link>
29 28
 		<description><?php echo htmlspecialchars($conf->description);?></description>
30
-		<generator>gelato CMS</generator>
29
+		<generator>gelato CMS <?php echo codeName()." (".version().")"; ?></generator>        
31 30
 		<image>
32 31
 			<url><?php echo $conf->urlGelato;?>/images/information.png</url>
33 32
 			<title><?php echo htmlspecialchars($conf->description);?></title>
34 33
 			<link><?php echo $conf->urlGelato;?></link>
35 34
 		</image>
36
-
37
-
38 35
 <?php
39 36
 	$rs = $tumble->getPosts("20");
40 37
 	if ($tumble->contarRegistros()>0) {		
@@ -77,13 +74,11 @@ if(!defined('entry')) define('entry',true);
77 74
 					$desc = $tumble->getMp3Player($register["url"]);
78 75
 					break;
79 76
 			}
80
-			$tit = strip_tags($tit);
81
-			//$url = htmlspecialchars($url);
82
-			$strEnd=($conf->urlFriendly) ? "/" : "";
83
-			$url = $conf->urlGelato.($conf->urlFriendly?"/post/":"/index.php?post=").$register["id_post"].$strEnd;
84
-			$formatedDate = gmdate("r", strtotime($register["date"])+transform_offset($conf->offsetTime));
77
+			$tit = trimString($tit);
78
+			$strEnd = ($conf->urlFriendly) ? "/" : "";
79
+			$url = $conf->urlGelato.($conf->urlFriendly ? "/post/" : "/index.php?post=").$register["id_post"].$strEnd;
80
+			$formatedDate = gmdate("r", strtotime($register["date"]) + transform_offset($conf->offsetTime));
85 81
 ?>
86
-
87 82
 			<item>
88 83
 				<title><?php echo $tit;?></title>
89 84
 				<description><![CDATA[<?php echo $desc;?>]]></description>