librefm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Librefm-commits] [1273] Copy fixes to stable branch.


From: Toby Inkster
Subject: [Librefm-commits] [1273] Copy fixes to stable branch.
Date: Thu, 07 May 2009 10:21:22 +0000

Revision: 1273
          http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1273
Author:   tobyink
Date:     2009-05-07 10:21:21 +0000 (Thu, 07 May 2009)
Log Message:
-----------
Copy fixes to stable branch.

Modified Paths:
--------------
    branches/stable/nixtape/data/Group.php
    branches/stable/nixtape/edit_group.php

Modified: branches/stable/nixtape/data/Group.php
===================================================================
--- branches/stable/nixtape/data/Group.php      2009-05-07 10:03:33 UTC (rev 
1272)
+++ branches/stable/nixtape/data/Group.php      2009-05-07 10:21:21 UTC (rev 
1273)
@@ -75,42 +75,76 @@
                        $this->users        = array();
 
                        if (! preg_match('/\:/', $this->id))
-                               $this->id = $base.'/group/' . 
urlencode($this->name) . '#group';
+                               $this->id = $base.'/group/' . 
rawurlencode($this->name) . '#group';
                }               
        }
-       
+
+       /**
+        * Create a new nixtape group.
+        *
+        * @param string $name the name of the group (used to generate its URL).
+        * @param object $owner a User object representing the person who owns 
this group.
+        * @return object a Group object on success, a PEAR_Error object 
otherwise.
+        * @author tobyink
+        */
        static function create ($name, $owner)
        {
                global $mdb2;
+
+               if (!preg_match('/^[A-Za-z0-9][A-Za-z0-9_\.-]*[A-Za-z0-9]$/', 
$name))
+               {
+                       return (new PEAR_Error('Group names should only contain 
letters, numbers, hyphens, underscores and full stops (a.k.a. dots/periods), 
must be at least two characters long, and can\'t start or end with 
punctuation.'));
+               }
+
+               if (in_array(strtolower($name), array('new', 'search')))
+               {
+                       return (new PEAR_Error("Not allowed to create a group 
called '$name' (reserved word)!"));
+               }
                
-               // Should check to make sure no existing group with same name 
(case-insensitive).
+               // Check to make sure no existing group with same name 
(case-insensitive).
+               $q = sprintf('SELECT groupname FROM Groups WHERE 
LOWER(groupname)=LOWER(%s)'
+                               , $mdb2->quote($name, 'text'));
+               $res = $mdb2->query($q);
+               if (PEAR::isError($res))
+               {
+                       return $res;
+               }
+               elseif ($res->numRows())
+               {
+                       $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
+                       $existing = $row['groupname'];
+                       return (new PEAR_Error(
+                                       ($existing == $name) ?
+                                       "There is already a group called 
'$existing'." :
+                                       "The name '$name' it too similar to 
existing group '$existing'"
+                               ));
+               }
                
-               $q = sprintf("INSERT INTO Groups (groupname, owner, created, 
modified) VALUES (%s, %s, %d, %d)"
+               // Create new group
+               $q = sprintf('INSERT INTO Groups (groupname, owner, created, 
modified) VALUES (%s, %s, %d, %d)'
                                , $mdb2->quote($name, 'text')
                                , $mdb2->quote($owner->name, 'text')
                                , time()
                                , time());
                $res = $mdb2->query($q);
-               
-               if(PEAR::isError($res)) {
-                       header("Content-Type: text/plain");
-                       print_r($res);
-                       exit;
+               if (PEAR::isError($res))
+               {
+                       return $res;
                }
 
-               $q = sprintf("INSERT INTO Group_Members (groupname, member, 
joined) VALUES (%s, %s, %d)"
+               // Group owner must be a member of the group
+               $q = sprintf('INSERT INTO Group_Members (groupname, member, 
joined) VALUES (%s, %s, %d)'
                                , $mdb2->quote($name, 'text')
                                , $mdb2->quote($owner->name, 'text')
                                , time());
                $res = $mdb2->query($q);
-               
-               if(PEAR::isError($res)) {
-                       header("Content-Type: text/plain");
-                       print_r($res);
-                       exit;
+               if (PEAR::isError($res))
+               {
+                       return $res;
                }
 
-               return 1;
+               // Return the newly created group. Callers should check the 
return value.
+               return (new Group($name));
        }
        
        static function groupList ($user=false)
@@ -205,9 +239,9 @@
        function getURLAction ($action) {
                $url = $this->getURL();
                if (strstr($url, '?'))
-                       return $url . '&action=' . urlencode($action);
+                       return $url . '&action=' . rawurlencode($action);
                else
-                       return $url . '?action=' . urlencode($action);
+                       return $url . '?action=' . rawurlencode($action);
        }
        
        function getUsers () {

Modified: branches/stable/nixtape/edit_group.php
===================================================================
--- branches/stable/nixtape/edit_group.php      2009-05-07 10:03:33 UTC (rev 
1272)
+++ branches/stable/nixtape/edit_group.php      2009-05-07 10:21:21 UTC (rev 
1273)
@@ -37,14 +37,25 @@
 {
        if ($_REQUEST['new'])
        {
-               Group::create($_REQUEST['new'], $this_user);
-               header("Location: 
{$base_url}/edit_group.php?group=".$_REQUEST['new']);
-               exit;
+               $result = Group::create($_REQUEST['new'], $this_user);
+
+               if ($result instanceof Group)
+               {
+                       header("Location: 
{$base_url}/edit_group.php?group=".$_REQUEST['new']);
+                       exit();
+               }
+               elseif (PEAR::isError($result))
+               {
+                       $smarty->assign('error', 'Error!');
+                       $smarty->assign('details', $result->getMessage());
+                       $smarty->display('error.tpl');
+                       die();
+               }
        }
        else
        {
                $smarty->assign('newform', true);
-               $aTagCloud = TagCloud::GenerateTagCloud('Scrobbles', 'artist');
+               $aTagCloud = TagCloud::GenerateTagCloud('Free_Scrobbles', 
'artist');
                if (!PEAR::isError ($aTagCloud))
                {
                        $smarty->assign('tagcloud', $aTagCloud);
@@ -132,7 +143,7 @@
        # And display the page.
        $smarty->assign('errors', $errors);
        $smarty->assign('newform', false);
-       $aTagCloud = TagCloud::GenerateTagCloud('Scrobbles', 'artist');
+       $aTagCloud = TagCloud::GenerateTagCloud('Free_Scrobbles', 'artist');
        if (!PEAR::isError ($aTagCloud))
        {
                $smarty->assign('tagcloud', $aTagCloud);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]