]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
make the admin tag menu behave correctly now and show only arrows on nodes that have...
authorChristian Weiske <cweiske@cweiske.de>
Fri, 1 Oct 2010 19:34:11 +0000 (21:34 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 1 Oct 2010 19:34:11 +0000 (21:34 +0200)
www/ajax/getadminlinkedtags.php

index a08045a7f88a4821cc01e6390199076726aba9be..5581c43e17a9cb88f3851848f1b8bdd9e36dcda9 100644 (file)
@@ -1,31 +1,27 @@
 <?php
-/***************************************************************************
- Copyright (C) 2004 - 2006 Scuttle project
- http://sourceforge.net/projects/scuttle/
- http://scuttle.org/
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- ***************************************************************************/
-
-/* Return a json file with list of linked tags */
+/**
+ * Returns a list of tags managed by the admins, in json format
+ * suitable for jsTree consumption.
+ *
+ * @param string $tag Tag for which the children tags shall be returned
+ *
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category    Bookmarking
+ * @package     SemanticScuttle
+ * @subcategory Templates
+ * @author      Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author      Christian Weiske <cweiske@cweiske.de>
+ * @author      Eric Dane <ericdane@users.sourceforge.net>
+ * @license     GPL http://www.gnu.org/licenses/gpl.html
+ * @link        http://sourceforge.net/projects/semanticscuttle
+ */
+
 $httpContentType = 'application/json';
-$httpContentType='text/plain';
 require_once '../www-header.php';
 
-$tag = isset($_GET['tag']) ? trim($_GET['tag']) : '';
-
 function assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
 {
     if ($tag == '') {
@@ -36,27 +32,34 @@ function assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
 
     $tagData = array();
     foreach ($linkedTags as $tag) {
-        $tagData[] = createTagArray($tag);
+        //FIXME: the hasChildren code is nasty, because it causes too many
+        // queries onto the database
+        $hasChildren = 0 < count($t2t->getAdminLinkedTags($tag, '>'));
+        $tagData[] = createTagArray($tag, $hasChildren);
     }
 
        return $tagData;
 }
 
-function createTagArray($tag)
+function createTagArray($tag, $hasChildren = true)
 {
-    return array(
+    $ar = array(
         'data' => $tag,
         'attr' => array('rel' => $tag),
-        //'children' => array('foo', 'bar'),
-        'state' => 'closed'
     );
+    if ($hasChildren) {
+        //jstree needs that to show the arrows
+        $ar['state'] = 'closed';
+    }
+
+    return $ar;
 }
 
 
+$tag     = isset($_GET['tag']) ? trim($_GET['tag']) : '';
 $tagData = assembleTagData(
     $tag,
     SemanticScuttle_Service_Factory::get('Tag2Tag')
 );
-//$json = substr($json, 0, -1); // remove final comma avoiding IE6 Dojo bug
 echo json_encode($tagData);
 ?>
\ No newline at end of file