Browse Source

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

pecesama 16 years ago
parent
commit
b060b0becb
4 changed files with 34 additions and 44 deletions
  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 View File

59
 			<posts start="<?php echo $start; ?>" total="<?php echo $total; ?>">
59
 			<posts start="<?php echo $start; ?>" total="<?php echo $total; ?>">
60
 <?php 
60
 <?php 
61
 			while($register = mysql_fetch_array($rs)) {
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
 				switch ($register["type"]) {
67
 				switch ($register["type"]) {
67
 					case "1":
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
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="regular" date="<?php echo $formatedDate;?>">
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>
73
 							<regular-title><?php echo $tit;?></regular-title>
74
 							<regular-body><?php echo $desc;?></regular-body>
74
 							<regular-body><?php echo $desc;?></regular-body>
76
 <?php						
76
 <?php						
77
 						break;
77
 						break;
78
 					case "2":
78
 					case "2":
79
-						$tit = ($register["description"]=="") ? "Photo" : $desc;
79
+						$tit = (empty($register["description"])) ? "Photo" : $desc;
80
 ?>
80
 ?>
81
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="photo" date="<?php echo $formatedDate;?>">
81
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="photo" date="<?php echo $formatedDate;?>">
82
 <?php
82
 <?php
91
 ?>
91
 ?>
92
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="quote" date="<?php echo $formatedDate;?>">
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>
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
 						</post>
95
 						</post>
96
 <?php
96
 <?php
97
 						break;
97
 						break;
98
 					case "4":
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
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="link" date="<?php echo $formatedDate;?>">
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>
102
                             <link-text><?php echo $tit; ?></link-text>
107
 					case "5":
107
 					case "5":
108
 						$lines = explode("\n", $desc);
108
 						$lines = explode("\n", $desc);
109
 						$line = $lines[0];
109
 						$line = $lines[0];
110
-						$tit = ($register["title"]=="") ? $line : $register["title"];
110
+						$tit = (empty($register["title"])) ? trimString($line) : $register["title"];
111
 						$desc = $tumble->formatConversation($desc);
111
 						$desc = $tumble->formatConversation($desc);
112
 ?>
112
 ?>
113
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="conversation" date="<?php echo $formatedDate;?>">
113
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="conversation" date="<?php echo $formatedDate;?>">
118
 <?php
118
 <?php
119
 						break;
119
 						break;
120
 					case "6":
120
 					case "6":
121
-						$tit = ($register["description"]=="") ? "Video" : $desc;
121
+						$tit = (empty($register["description"])) ? "Video" : $desc;
122
 						$desc = $tumble->getVideoPlayer($register["url"]);
122
 						$desc = $tumble->getVideoPlayer($register["url"]);
123
 ?>
123
 ?>
124
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="video" date="<?php echo $formatedDate;?>">
124
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="video" date="<?php echo $formatedDate;?>">
130
 						break;
130
 						break;
131
 
131
 
132
 					case "7":
132
 					case "7":
133
-						$tit = ($register["description"]=="") ? "Audio" : $desc;
133
+						$tit = (empty($register["description"])) ? "Audio" : $desc;
134
 						$desc = $tumble->getMp3Player($register["url"]);
134
 						$desc = $tumble->getMp3Player($register["url"]);
135
 ?>
135
 ?>
136
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="audio" date="<?php echo $formatedDate;?>">
136
 						<post id="<?php echo $register["id_post"]; ?>" url="<?php echo $url;?>" type="audio" date="<?php echo $formatedDate;?>">
140
 <?php
140
 <?php
141
 						break;
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
 				</posts>
146
 				</posts>
150
 <?php	
147
 <?php	

+ 6 - 0
classes/functions.php View File

471
 		}
471
 		}
472
 		return $tmpStr;
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 View File

18
 global $user, $tumble, $conf;
18
 global $user, $tumble, $conf;
19
 
19
 
20
 $theme = new themes;
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
         if(isset($_SERVER['PATH_INFO'])) $param_url = explode("/",$_SERVER['PATH_INFO']);
23
         if(isset($_SERVER['PATH_INFO'])) $param_url = explode("/",$_SERVER['PATH_INFO']);
24
 
24
 
49
         }
49
         }
50
 
50
 
51
         $gelato_includes = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n";
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
         $gelato_includes .= "\t<link rel=\"shortcut icon\" href=\"".$conf->urlGelato."/images/favicon.ico\" />\n";
53
         $gelato_includes .= "\t<link rel=\"shortcut icon\" href=\"".$conf->urlGelato."/images/favicon.ico\" />\n";
54
         $gelato_includes .= "\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"".$conf->urlGelato.($conf->urlFriendly?"/rss/":"/rss.php")."\"/>\n";
54
         $gelato_includes .= "\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"".$conf->urlGelato.($conf->urlFriendly?"/rss/":"/rss.php")."\"/>\n";
55
         $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/themes/".$conf->template."/style.css\"/>\n";
55
         $gelato_includes .= "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"".$conf->urlGelato."/themes/".$conf->template."/style.css\"/>\n";
64
 			$register = $tumble->getPost($id_post);			
64
 			$register = $tumble->getPost($id_post);			
65
 			if (empty($register["title"])) {
65
 			if (empty($register["title"])) {
66
 				if (!empty($register["description"])) {
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
 				} else {
68
 				} else {
73
 					$page_title_data =  type2Text($register["type"]);
69
 					$page_title_data =  type2Text($register["type"]);
74
 				}
70
 				}
76
 				$page_title_data = $register["title"];
72
 				$page_title_data = $register["title"];
77
 			}			
73
 			}			
78
 			if (!empty($page_title_data)) {
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
 					$user = new user();
274
 					$user = new user();
279
 					$username = $user->getUserByID($register["id_user"]);
275
 					$username = $user->getUserByID($register["id_user"]);
280
 
276
 
281
-					$row['User'] = $username["name"];
277
+					$row["User"] = $username["name"];
282
 					
278
 					
283
 					if (empty($register["title"])) {
279
 					if (empty($register["title"])) {
284
 						if (!empty($register["description"])) {
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
 						} else {
282
 						} else {
291
 							$postTitle =  type2Text($register["type"]);
283
 							$postTitle =  type2Text($register["type"]);
292
 						}
284
 						}
294
 						$postTitle = $register["title"];
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
 					$rows[] = $row;
292
 					$rows[] = $row;
301
 					$theme->set('rows',$rows);
293
 					$theme->set('rows',$rows);

+ 6 - 11
rss.php View File

20
 	
20
 	
21
 	
21
 	
22
 	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
22
 	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
23
-?>
24
-	
23
+?>	
25
 	<rss version="2.0">
24
 	<rss version="2.0">
26
 	<channel>
25
 	<channel>
27
 		<title><?php echo htmlspecialchars($conf->title);?></title>
26
 		<title><?php echo htmlspecialchars($conf->title);?></title>
28
 		<link><?php echo $conf->urlGelato;?></link>
27
 		<link><?php echo $conf->urlGelato;?></link>
29
 		<description><?php echo htmlspecialchars($conf->description);?></description>
28
 		<description><?php echo htmlspecialchars($conf->description);?></description>
30
-		<generator>gelato CMS</generator>
29
+		<generator>gelato CMS <?php echo codeName()." (".version().")"; ?></generator>        
31
 		<image>
30
 		<image>
32
 			<url><?php echo $conf->urlGelato;?>/images/information.png</url>
31
 			<url><?php echo $conf->urlGelato;?>/images/information.png</url>
33
 			<title><?php echo htmlspecialchars($conf->description);?></title>
32
 			<title><?php echo htmlspecialchars($conf->description);?></title>
34
 			<link><?php echo $conf->urlGelato;?></link>
33
 			<link><?php echo $conf->urlGelato;?></link>
35
 		</image>
34
 		</image>
36
-
37
-
38
 <?php
35
 <?php
39
 	$rs = $tumble->getPosts("20");
36
 	$rs = $tumble->getPosts("20");
40
 	if ($tumble->contarRegistros()>0) {		
37
 	if ($tumble->contarRegistros()>0) {		
77
 					$desc = $tumble->getMp3Player($register["url"]);
74
 					$desc = $tumble->getMp3Player($register["url"]);
78
 					break;
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
 			<item>
82
 			<item>
88
 				<title><?php echo $tit;?></title>
83
 				<title><?php echo $tit;?></title>
89
 				<description><![CDATA[<?php echo $desc;?>]]></description>
84
 				<description><![CDATA[<?php echo $desc;?>]]></description>