diff --git a/data/templates/sidebar.block.linked.php b/data/templates/sidebar.block.linked.php
index 9e91f93..db0d087 100644
--- a/data/templates/sidebar.block.linked.php
+++ b/data/templates/sidebar.block.linked.php
@@ -1,4 +1,11 @@
getCurrentUserId();
-if ($logged_on_userid === false) {
- $logged_on_userid = NULL;
-}
-
-$explodedTags = array();
-if (strlen($currenttag)>0) {
- $explodedTags = explode('+', $currenttag);
-} else {
- if($summarizeLinkedTags == true) {
- $orphewTags = $tag2tagservice->getOrphewTags('>', $userid, 4, "nb");
- } else {
- $orphewTags = $tag2tagservice->getOrphewTags('>', $userid);
- }
-
- foreach($orphewTags as $orphewTag) {
- $explodedTags[] = $orphewTag['tag'];
- }
-}
-
+$editingMode = $logged_on_userid !== false;
?>
-
+
+
\ No newline at end of file
diff --git a/www/ajax/getadminlinkedtags.php b/www/ajax/getadminlinkedtags.php
index 1004f29..5f939a6 100644
--- a/www/ajax/getadminlinkedtags.php
+++ b/www/ajax/getadminlinkedtags.php
@@ -22,7 +22,16 @@
$httpContentType = 'application/json';
require_once '../www-header.php';
-function assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
+/**
+ * Creates and returns an array of tags for the jsTree ajax loader.
+ * If the tag is empty, the configured menu2 (admin) main tags are used.
+ *
+ * @param string $tag Tag name to fetch subtags for
+ * @param SemanticScuttle_Service_Tag2Tag $t2t Tag relation service
+ *
+ * @return array Array of tag data suitable for the jsTree ajax loader
+ */
+function assembleAdminTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
{
if ($tag == '') {
$linkedTags = $GLOBALS['menu2Tags'];
@@ -45,7 +54,8 @@ function assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
* Creates an jsTree json array for the given tag
*
* @param string $tag Tag name
- * @param boolean $hasChildren If the tag has subtags (children) or not
+ * @param boolean $hasChildren If the tag has subtags (children) or not.
+ * If unsure, set it to "true".
*
* @return array Array to be sent back to the browser as json
*/
@@ -74,7 +84,7 @@ function createTagArray($tag, $hasChildren = true)
$tag = isset($_GET['tag']) ? trim($_GET['tag']) : '';
-$tagData = assembleTagData(
+$tagData = assembleAdminTagData(
$tag,
SemanticScuttle_Service_Factory::get('Tag2Tag')
);
diff --git a/www/ajax/getlinkedtags.php b/www/ajax/getlinkedtags.php
index f412998..307ee26 100644
--- a/www/ajax/getlinkedtags.php
+++ b/www/ajax/getlinkedtags.php
@@ -1,64 +1,143 @@
+ * @author Christian Weiske
+ * @author Eric Dane
+ * @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';
-/* Service creation: only useful services are created */
-$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
-$bookmarkservice =SemanticScuttle_Service_Factory::get('Tag');
-$tagstatservice =SemanticScuttle_Service_Factory::get('TagStat');
+$tag = isset($_GET['tag']) ? $_GET['tag'] : null;
+$uId = isset($_GET['uId']) ? (int)$_GET['uId'] : 0;
+$loadParentTags = isset($_GET['parent']) ? (bool)$_GET['parent'] : false;
-/* Managing all possible inputs */
-isset($_GET['tag']) ? define('GET_TAG', $_GET['tag']): define('GET_TAG', '');
-isset($_GET['uId']) ? define('GET_UID', $_GET['uId']): define('GET_UID', '');
-
-
-function displayTag($tag, $uId) {
- $uId = ($uId==0)?NULL:$uId; // if user is nobody, NULL allows to look for every public tags
-
- $tag2tagservice =SemanticScuttle_Service_Factory::get('Tag2Tag');
- $output = '{ id:'.rand().', name:\''.$tag.'\'';
-
- $linkedTags = $tag2tagservice->getLinkedTags($tag, '>', $uId);
- if(count($linkedTags) > 0) {
- $output.= ', children: [';
- foreach($linkedTags as $linkedTag) {
- $output.= displayTag($linkedTag, $uId);
- }
- $output = substr($output, 0, -1); // remove final comma avoiding IE6 Dojo bug
- $output.= "]";
- }
-
- $output.= '},';
- return $output;
+$tags = explode(' ', trim($tag));
+if (count($tags) == 1 && $tags[0] == '') {
+ //no tags
+ $tags = array();
}
-?>
-{ label: 'name', identifier: 'id', items: [
-
-] }
+function assembleLinkedTagData(
+ $tags, $uId, $loadParentTags, SemanticScuttle_Service_Tag2Tag $t2t
+) {
+ $tagData = array();
+
+ if (count($tags) == 0) {
+ //no tags given -> show the 4 most used top-level tags
+ $orphewTags = $t2t->getOrphewTags('>', $uId, 4, 'nb');
+ #$orphewTags = $t2t->getOrphewTags('>', $uId);
+ foreach ($orphewTags as $orphewTag) {
+ $tags[] = $orphewTag['tag'];
+ }
+ $loadParentTags = true;
+ }
+
+ if ($loadParentTags) {
+ //find parent tags + append the selected tags as children afterwards
+ foreach ($tags as $tag) {
+ $parentTags = $t2t->getLinkedTags($tag, '>', $uId, true);
+ if (count($parentTags) > 0) {
+ foreach ($parentTags as $parentTag) {
+ $ta = createTagArray(
+ $parentTag, true, true, true
+ );
+ //FIXME: find out if there are subtags
+ $tac = createTagArray($tag, true);
+ $ta['children'][] = $tac;
+ $tagData[] = $ta;
+ }
+ } else {
+ //no parent tags -> display it normally
+ //FIXME: find out if there are subtags
+ $tagData[] = createTagArray($tag, true);
+ }
+ }
+ } else {
+ //just find the linked tags
+ foreach ($tags as $tag) {
+ $linkedTags = $t2t->getLinkedTags($tag, '>', $uId);
+ foreach ($linkedTags as $linkedTag) {
+ //FIXME: find out if there are subtags
+ $tagData[] = createTagArray($linkedTag, true);
+ }
+ }
+ }
+
+ return $tagData;
+}
+
+/**
+ * Creates an jsTree json array for the given tag
+ *
+ * @param string $tag Tag name
+ * @param boolean $hasChildren If the tag has subtags (children) or not.
+ * If unsure, set it to "true".
+ * @param boolean $isOpen If the tag has children: Is the tree node open
+ * or closed?
+ * @param boolean $autoParent If the tag is an automatically generated parent tag
+ *
+ * @return array Array to be sent back to the browser as json
+ */
+function createTagArray($tag, $hasChildren = true, $isOpen = false, $autoParent = false)
+{
+ if ($autoParent) {
+ $title = '(' . $tag . ')';
+ } else {
+ $title = $tag;
+ }
+
+ $ar = array(
+ 'data' => array(
+ // attributes
+ 'title' => $title,
+ 'attr' => array(
+ 'href' => createUrl('tags', $tag)
+ )
+ ),
+ // attributes
+ 'attr' => array(
+ 'rel' => $tag,//needed for identifying the tag in html
+ ),
+ );
+ if ($hasChildren) {
+ //jstree needs that to show the arrows
+ $ar['state'] = $isOpen ? 'open' : 'closed';
+ }
+ if ($autoParent) {
+ //FIXME: use css class
+ $ar['data']['attr']['style'] = 'color: #AAA';
+ }
+
+ return $ar;
+}
+
+
+$tagData = assembleLinkedTagData(
+ $tags, 0/*$uId*/, $loadParentTags,
+ SemanticScuttle_Service_Factory::get('Tag2Tag')
+);
+echo json_encode($tagData);
+?>
\ No newline at end of file