[geeklog-cvs] Geeklog-1.x/system lib-story.php, 1.119, 1.120 lib-webservices.php, 1.29, 1.30
Dirk Haun
dhaun at qs1489.pair.com
Fri Jan 4 13:36:33 EST 2008
Update of /cvsroot/geeklog/Geeklog-1.x/system
In directory qs1489.pair.com:/tmp/cvs-serv57928/system
Modified Files:
lib-story.php lib-webservices.php
Log Message:
If we have to create a new ID, try using the 'Slug:' header
Index: lib-webservices.php
===================================================================
RCS file: /cvsroot/geeklog/Geeklog-1.x/system/lib-webservices.php,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** lib-webservices.php 3 Jan 2008 16:22:00 -0000 1.29
--- lib-webservices.php 4 Jan 2008 18:36:31 -0000 1.30
***************
*** 173,176 ****
--- 173,183 ----
$args['gl_svc'] = true;
+ // provide convenient access to the 'Slug:' header, if available
+ if (isset($_SERVER['HTTP_SLUG'])) {
+ $args['slug'] = $_SERVER['HTTP_SLUG'];
+ } else {
+ $args['slug'] = '';
+ }
+
// Call PLG_invokeService here
$ret = PLG_invokeService($WS_PLUGIN, $action, $args, $out, $svc_msg);
***************
*** 823,826 ****
--- 830,871 ----
echo $WS_TEXT;
+ }
+
+ /*
+ * Create a new ID, preferrably from a provided 'Slug:' header
+ *
+ * @param string $slug Content of the 'Slug:' header
+ * @param int $max_length max. length of the created ID
+ * @return string new ID
+ *
+ * For more information on the 'Slug:' header, see RFC 5023, section 9.7
+ *
+ */
+ function WS_makeId($slug = '', $max_length = 40)
+ {
+ $sid = COM_makeSid();
+
+ if (strpos($slug, '%') !== false) {
+ // we'll end up removing most of the %-encoded characters anyway ...
+ $slug = '';
+ }
+
+ $slug = trim($slug);
+ if (!empty($slug)) {
+ // make it more ID-like
+ $slug = str_replace(' ', '-', $slug);
+ $slug = strtolower($slug);
+
+ $id = COM_sanitizeID($slug . '-' . $sid);
+ if (strlen($id) > $max_length) {
+ // 'slug-sid' would make for nicer IDs but if we have to shorten
+ // them, they're probably not unique any more. So swap order.
+ $id = $sid . '-' . $slug;
+ }
+ } else {
+ $id = $sid;
+ }
+
+ return substr(COM_sanitizeID($id), 0, $max_length);
}
Index: lib-story.php
===================================================================
RCS file: /cvsroot/geeklog/Geeklog-1.x/system/lib-story.php,v
retrieving revision 1.119
retrieving revision 1.120
diff -C2 -d -r1.119 -r1.120
*** lib-story.php 3 Jan 2008 20:01:57 -0000 1.119
--- lib-story.php 4 Jan 2008 18:36:31 -0000 1.120
***************
*** 1171,1175 ****
if (!$gl_edit) {
if (strlen($args['sid']) > STORY_MAX_ID_LENGTH) {
! $args['sid'] = COM_makeSid();
}
}
--- 1171,1175 ----
if (!$gl_edit) {
if (strlen($args['sid']) > STORY_MAX_ID_LENGTH) {
! $args['sid'] = WS_makeId($args['slug'], STORY_MAX_ID_LENGTH);
}
}
More information about the geeklog-cvs
mailing list