make linkedtags sidebar tree menu work with jquery/jstree now
This commit is contained in:
parent
aaf293b18d
commit
22e46a9b45
3 changed files with 193 additions and 145 deletions
|
@ -1,4 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
/*
|
||||||
|
* Used in:
|
||||||
|
* - populartags.php
|
||||||
|
* - bookmarks.php
|
||||||
|
* - alltags.php
|
||||||
|
* - tags.php
|
||||||
|
*/
|
||||||
/* Service creation: only useful services are created */
|
/* Service creation: only useful services are created */
|
||||||
$tag2tagservice =SemanticScuttle_Service_Factory::get('Tag2Tag');
|
$tag2tagservice =SemanticScuttle_Service_Factory::get('Tag2Tag');
|
||||||
|
|
||||||
|
@ -8,98 +15,50 @@ require_once('sidebar.linkedtags.inc.php');
|
||||||
$user = isset($user)?$user:'';
|
$user = isset($user)?$user:'';
|
||||||
$userid = isset($userid)?$userid:0;
|
$userid = isset($userid)?$userid:0;
|
||||||
$currenttag = isset($currenttag)?$currenttag:'';
|
$currenttag = isset($currenttag)?$currenttag:'';
|
||||||
$summarizeLinkedTags = isset($summarizeLinkedTags)?$summarizeLinkedTags:false;
|
//$summarizeLinkedTags = isset($summarizeLinkedTags)?$summarizeLinkedTags:false;
|
||||||
|
|
||||||
|
|
||||||
$logged_on_userid = $userservice->getCurrentUserId();
|
$logged_on_userid = $userservice->getCurrentUserId();
|
||||||
if ($logged_on_userid === false) {
|
$editingMode = $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'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
<h2><?php echo T_('Linked Tags'); ?></h2>
|
||||||
|
<div id="related">
|
||||||
<?php
|
<?php
|
||||||
if(($logged_on_userid != null) && ($userid === $logged_on_userid)) {
|
|
||||||
$editingMode = true;
|
|
||||||
} else {
|
|
||||||
$editingMode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->includeTemplate("dojo.inc");
|
|
||||||
?>
|
|
||||||
|
|
||||||
<?php if(count($explodedTags)>0 || $editingMode):?>
|
|
||||||
|
|
||||||
<h2><?php
|
|
||||||
|
|
||||||
|
|
||||||
echo T_('Linked Tags').' ';
|
|
||||||
//if($userid != null) {
|
|
||||||
$cUser = $userservice->getUser($userid);
|
|
||||||
//echo '<small><a href="'.createURL('alltags', $cUser['username']).'">('.T_('all tags').')</a></small>';
|
|
||||||
//}
|
|
||||||
?></h2>
|
|
||||||
<?php //endif?>
|
|
||||||
|
|
||||||
<div id="related"> <?php
|
|
||||||
if ($editingMode) {
|
if ($editingMode) {
|
||||||
echo '<p style="margin-bottom: 13px;text-align:center;">';
|
echo '<p style="margin-bottom: 13px;text-align:center;">';
|
||||||
echo ' (<a href="'. createURL('tag2tagadd','') .'" rel="tag">'.T_('Add new link').'</a>) ';
|
echo ' (<a href="'. createURL('tag2tagadd','') .'" rel="tag">'.T_('Add new link').'</a>) ';
|
||||||
echo ' (<a href="'. createURL('tag2tagdelete','') .'" rel="tag">'.T_('Delete link').'</a>)';
|
echo ' (<a href="'. createURL('tag2tagdelete','') .'" rel="tag">'.T_('Delete link').'</a>)';
|
||||||
echo '</p>';
|
echo '</p>';
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
if(strlen($user)==0) {
|
<script type="text/javascript" src="<?php echo ROOT ?>js/jquery-1.4.2.js"></script>
|
||||||
$cat_url = createURL('tags', '%2$s');
|
<script type="text/javascript" src="<?php echo ROOT ?>js/jquery.jstree.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
jQuery("#related")
|
||||||
|
.jstree({
|
||||||
|
"themes" : {
|
||||||
|
"theme": "default",
|
||||||
|
"dots": false,
|
||||||
|
"icons": true,
|
||||||
|
"url": '<?php echo ROOT ?>js/themes/default/style.css'
|
||||||
|
},
|
||||||
|
"json_data" : {
|
||||||
|
"ajax" : {
|
||||||
|
"url": function(node) {
|
||||||
|
//-1 is root
|
||||||
|
parent = "";
|
||||||
|
if (node == -1 ) {
|
||||||
|
node = <?php echo json_encode($currenttag); ?>;
|
||||||
|
parent = "&parent=true";
|
||||||
|
} else if (node.attr('rel')) {
|
||||||
|
node = node.attr('rel');
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
return "<?php echo ROOT ?>ajax/getlinkedtags.php?tag=" + node + parent;
|
||||||
$stopList = array();
|
|
||||||
foreach($explodedTags as $explodedTag) {
|
|
||||||
if(!in_array($explodedTag, $stopList)) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// fathers tag
|
|
||||||
$fatherTags = $tag2tagservice->getLinkedTags($explodedTag, '>', $userid, true);
|
|
||||||
if(count($fatherTags)>0) {
|
|
||||||
foreach($fatherTags as $fatherTag) {
|
|
||||||
echo '<a href="'. sprintf($cat_url, filter($user, 'url'), filter($fatherTag, 'url')) .'" rel="tag">('. filter($fatherTag) .')</a> ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
},
|
||||||
$displayLinkedTags = displayLinkedTags($explodedTag, '>', $userid, $cat_url, $user, $editingMode, null, 1);
|
plugins : [ "themes", "json_data"]
|
||||||
echo $displayLinkedTags['output'];
|
});
|
||||||
if(is_array($displayLinkedTags['stopList'])) {
|
</script>
|
||||||
$stopList = array_merge($stopList, $displayLinkedTags['stopList']);
|
</div>
|
||||||
}*/
|
|
||||||
echo '<div dojoType="dojo.data.ItemFileReadStore" url="'.ROOT.'ajax/getlinkedtags.php?tag='.filter($explodedTag, 'url').'&uId='.$userid.'" jsid="linkedTagStore" ></div>';
|
|
||||||
echo '<div dojoType="dijit.Tree" store="linkedTagStore" labelAttr="name" >';
|
|
||||||
echo '<script type="dojo/method" event="onClick" args="item">';
|
|
||||||
$returnUrl = sprintf($cat_url, filter($user, 'url'), filter('', 'url'));
|
|
||||||
echo 'window.location = "'.$returnUrl.'"+item.name';
|
|
||||||
echo '</script>';
|
|
||||||
echo '<script type="dojo/method" event="getLabelClass" args="item">';
|
|
||||||
echo 'return \'treeTag\';';
|
|
||||||
echo '</script>';
|
|
||||||
echo '</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
?> </div>
|
|
||||||
|
|
||||||
<?php endif?>
|
|
|
@ -22,7 +22,16 @@
|
||||||
$httpContentType = 'application/json';
|
$httpContentType = 'application/json';
|
||||||
require_once '../www-header.php';
|
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 == '') {
|
if ($tag == '') {
|
||||||
$linkedTags = $GLOBALS['menu2Tags'];
|
$linkedTags = $GLOBALS['menu2Tags'];
|
||||||
|
@ -45,7 +54,8 @@ function assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
|
||||||
* Creates an jsTree json array for the given tag
|
* Creates an jsTree json array for the given tag
|
||||||
*
|
*
|
||||||
* @param string $tag Tag name
|
* @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
|
* @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']) : '';
|
$tag = isset($_GET['tag']) ? trim($_GET['tag']) : '';
|
||||||
$tagData = assembleTagData(
|
$tagData = assembleAdminTagData(
|
||||||
$tag,
|
$tag,
|
||||||
SemanticScuttle_Service_Factory::get('Tag2Tag')
|
SemanticScuttle_Service_Factory::get('Tag2Tag')
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,64 +1,143 @@
|
||||||
<?php
|
<?php
|
||||||
/***************************************************************************
|
/**
|
||||||
Copyright (C) 2004 - 2006 Scuttle project
|
* Returns a list of tags linked to the given one,
|
||||||
http://sourceforge.net/projects/scuttle/
|
* suitable for jsTree consumption.
|
||||||
http://scuttle.org/
|
*
|
||||||
|
* Accepted GET parameters:
|
||||||
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
|
* @param string $tag Tag for which the children tags shall be returned
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
* Multiple tags (separated with space or "+") are
|
||||||
(at your option) any later version.
|
* supported.
|
||||||
|
* If no tag is given, all top-level tags are loaded.
|
||||||
This program is distributed in the hope that it will be useful,
|
* @param integer $uId User ID to fetch the tags for
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* @param boolean $parent Load parent tags
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
*
|
||||||
GNU General Public License for more details.
|
* SemanticScuttle - your social bookmark manager.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU General Public License
|
* PHP version 5.
|
||||||
along with this program; if not, write to the Free Software
|
*
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* @category Bookmarking
|
||||||
***************************************************************************/
|
* @package SemanticScuttle
|
||||||
|
* @subpackage Templates
|
||||||
/* Return a json file with list of linked tags */
|
* @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 = 'application/json';
|
||||||
|
#$httpContentType = 'text/plain';
|
||||||
require_once '../www-header.php';
|
require_once '../www-header.php';
|
||||||
|
|
||||||
/* Service creation: only useful services are created */
|
$tag = isset($_GET['tag']) ? $_GET['tag'] : null;
|
||||||
$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
|
$uId = isset($_GET['uId']) ? (int)$_GET['uId'] : 0;
|
||||||
$bookmarkservice =SemanticScuttle_Service_Factory::get('Tag');
|
$loadParentTags = isset($_GET['parent']) ? (bool)$_GET['parent'] : false;
|
||||||
$tagstatservice =SemanticScuttle_Service_Factory::get('TagStat');
|
|
||||||
|
|
||||||
/* Managing all possible inputs */
|
$tags = explode(' ', trim($tag));
|
||||||
isset($_GET['tag']) ? define('GET_TAG', $_GET['tag']): define('GET_TAG', '');
|
if (count($tags) == 1 && $tags[0] == '') {
|
||||||
isset($_GET['uId']) ? define('GET_UID', $_GET['uId']): define('GET_UID', '');
|
//no tags
|
||||||
|
$tags = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function displayTag($tag, $uId) {
|
function assembleLinkedTagData(
|
||||||
$uId = ($uId==0)?NULL:$uId; // if user is nobody, NULL allows to look for every public tags
|
$tags, $uId, $loadParentTags, SemanticScuttle_Service_Tag2Tag $t2t
|
||||||
|
) {
|
||||||
|
$tagData = array();
|
||||||
|
|
||||||
$tag2tagservice =SemanticScuttle_Service_Factory::get('Tag2Tag');
|
if (count($tags) == 0) {
|
||||||
$output = '{ id:'.rand().', name:\''.$tag.'\'';
|
//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;
|
||||||
|
}
|
||||||
|
|
||||||
$linkedTags = $tag2tagservice->getLinkedTags($tag, '>', $uId);
|
if ($loadParentTags) {
|
||||||
if(count($linkedTags) > 0) {
|
//find parent tags + append the selected tags as children afterwards
|
||||||
$output.= ', children: [';
|
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) {
|
foreach ($linkedTags as $linkedTag) {
|
||||||
$output.= displayTag($linkedTag, $uId);
|
//FIXME: find out if there are subtags
|
||||||
|
$tagData[] = createTagArray($linkedTag, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$output = substr($output, 0, -1); // remove final comma avoiding IE6 Dojo bug
|
|
||||||
$output.= "]";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$output.= '},';
|
return $tagData;
|
||||||
return $output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(
|
||||||
|
//<a> attributes
|
||||||
|
'title' => $title,
|
||||||
|
'attr' => array(
|
||||||
|
'href' => createUrl('tags', $tag)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
//<li> 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);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
{ label: 'name', identifier: 'id', items: [
|
|
||||||
<?php
|
|
||||||
$json = displayTag(GET_TAG, intval(GET_UID));
|
|
||||||
$json = substr($json, 0, -1); // remove final comma avoiding IE6 Dojo bug
|
|
||||||
echo $json;
|
|
||||||
?>
|
|
||||||
] }
|
|
||||||
|
|
Loading…
Reference in a new issue