From cb1d41054b26c46c75f746a7d8e5bc28f32664f0 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Fri, 1 Oct 2010 18:21:33 +0200
Subject: make adminlinkedtags (menu2Tags) finally work with jquery
---
www/ajax/getadminlinkedtags.php | 62 ++++++++++++++++++++---------------------
1 file changed, 30 insertions(+), 32 deletions(-)
(limited to 'www/ajax')
diff --git a/www/ajax/getadminlinkedtags.php b/www/ajax/getadminlinkedtags.php
index 6646c50..a08045a 100644
--- a/www/ajax/getadminlinkedtags.php
+++ b/www/ajax/getadminlinkedtags.php
@@ -21,44 +21,42 @@
/* Return a json file with list of linked tags */
$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']) ? trim($_GET['tag']) : '';
-/* 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 assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
+{
+ if ($tag == '') {
+ $linkedTags = $GLOBALS['menu2Tags'];
+ } else {
+ $linkedTags = $t2t->getAdminLinkedTags($tag, '>');
+ }
+ $tagData = array();
+ foreach ($linkedTags as $tag) {
+ $tagData[] = createTagArray($tag);
+ }
-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->getAdminLinkedTags($tag, '>');
- 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.= "]";
- }
+ return $tagData;
+}
- $output.= '},';
- return $output;
+function createTagArray($tag)
+{
+ return array(
+ 'data' => $tag,
+ 'attr' => array('rel' => $tag),
+ //'children' => array('foo', 'bar'),
+ 'state' => 'closed'
+ );
}
-?>
-{ label: 'name', identifier: 'id', items: [
-
-] }
+$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
--
cgit v1.2.3
From bd92516e6fac1970770fbddec612f3d8da30fb3f Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Fri, 1 Oct 2010 21:34:11 +0200
Subject: make the admin tag menu behave correctly now and show only arrows on
nodes that have children
---
www/ajax/getadminlinkedtags.php | 63 +++++++++++++++++++++--------------------
1 file changed, 33 insertions(+), 30 deletions(-)
(limited to 'www/ajax')
diff --git a/www/ajax/getadminlinkedtags.php b/www/ajax/getadminlinkedtags.php
index a08045a..5581c43 100644
--- a/www/ajax/getadminlinkedtags.php
+++ b/www/ajax/getadminlinkedtags.php
@@ -1,31 +1,27 @@
+ * @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';
-$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
--
cgit v1.2.3
From b812deefa1ab85c542c13dc97432ca2fe90958f1 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Thu, 7 Oct 2010 18:59:27 +0200
Subject: give admin tags a link href :)
---
src/SemanticScuttle/constants.php | 4 +++-
www/ajax/getadminlinkedtags.php | 21 +++++++++++++++++++--
2 files changed, 22 insertions(+), 3 deletions(-)
(limited to 'www/ajax')
diff --git a/src/SemanticScuttle/constants.php b/src/SemanticScuttle/constants.php
index 95c4384..aebc059 100644
--- a/src/SemanticScuttle/constants.php
+++ b/src/SemanticScuttle/constants.php
@@ -17,7 +17,9 @@ if (!isset($GLOBALS['root'])) {
$rootTmp = '/';
foreach ($pieces as $piece) {
//we eliminate possible sscuttle subfolders (like gsearch for example)
- if ($piece != '' && !strstr($piece, '.php') && $piece != 'gsearch') {
+ if ($piece != '' && !strstr($piece, '.php')
+ && $piece != 'gsearch' && $piece != 'ajax'
+ ) {
$rootTmp .= $piece .'/';
}
}
diff --git a/www/ajax/getadminlinkedtags.php b/www/ajax/getadminlinkedtags.php
index 5581c43..1004f29 100644
--- a/www/ajax/getadminlinkedtags.php
+++ b/www/ajax/getadminlinkedtags.php
@@ -41,11 +41,28 @@ function assembleTagData($tag, SemanticScuttle_Service_Tag2Tag $t2t)
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
+ *
+ * @return array Array to be sent back to the browser as json
+ */
function createTagArray($tag, $hasChildren = true)
{
$ar = array(
- 'data' => $tag,
- 'attr' => array('rel' => $tag),
+ 'data' => array(
+ // attributes
+ 'title' => $tag,
+ '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
--
cgit v1.2.3
From 22e46a9b45810bae480aea72b16680d715a57ff4 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Sat, 9 Oct 2010 10:20:14 +0200
Subject: make linkedtags sidebar tree menu work with jquery/jstree now
---
data/templates/sidebar.block.linked.php | 131 ++++++++---------------
www/ajax/getadminlinkedtags.php | 16 ++-
www/ajax/getlinkedtags.php | 179 +++++++++++++++++++++++---------
3 files changed, 187 insertions(+), 139 deletions(-)
(limited to 'www/ajax')
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';
- 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.
+$tag = isset($_GET['tag']) ? $_GET['tag'] : null;
+$uId = isset($_GET['uId']) ? (int)$_GET['uId'] : 0;
+$loadParentTags = isset($_GET['parent']) ? (bool)$_GET['parent'] : false;
- 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.
+$tags = explode(' ', trim($tag));
+if (count($tags) == 1 && $tags[0] == '') {
+ //no tags
+ $tags = array();
+}
- 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 */
-$httpContentType = 'application/json';
-require_once '../www-header.php';
+function assembleLinkedTagData(
+ $tags, $uId, $loadParentTags, SemanticScuttle_Service_Tag2Tag $t2t
+) {
+ $tagData = array();
-/* 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');
+ 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;
+ }
-/* 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', '');
+ 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;
+}
-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.'\'';
+/**
+ * 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;
+ }
- $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.= "]";
- }
+ $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';
+ }
- $output.= '},';
- return $output;
+ return $ar;
}
-?>
-{ label: 'name', identifier: 'id', items: [
-
-] }
+$tagData = assembleLinkedTagData(
+ $tags, 0/*$uId*/, $loadParentTags,
+ SemanticScuttle_Service_Factory::get('Tag2Tag')
+);
+echo json_encode($tagData);
+?>
\ No newline at end of file
--
cgit v1.2.3
From 6bf4e76495b03ccec29fb4d9262ac871dd10a221 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Sat, 9 Oct 2010 13:03:55 +0200
Subject: make add/del tag nav links work again
---
data/templates/sidebar.block.linked.php | 3 ++-
www/ajax/getlinkedtags.php | 1 -
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'www/ajax')
diff --git a/data/templates/sidebar.block.linked.php b/data/templates/sidebar.block.linked.php
index 54e9260..ac864dc 100644
--- a/data/templates/sidebar.block.linked.php
+++ b/data/templates/sidebar.block.linked.php
@@ -30,10 +30,11 @@ if ($editingMode) {
echo '
';
}
?>
+
-
includeTemplate('dynamictags.inc');
@@ -204,5 +199,5 @@ else if (false)
includeTemplate($GLOBALS['bottom_include']);
+$this->includeTemplate($GLOBALS['bottom_include']);
?>
diff --git a/www/ajax/getcontacttags.php b/www/ajax/getcontacttags.php
index 89d6a3a..5f1edb3 100644
--- a/www/ajax/getcontacttags.php
+++ b/www/ajax/getcontacttags.php
@@ -27,18 +27,20 @@ require_once '../www-header.php';
$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
$bookmarkservice =SemanticScuttle_Service_Factory::get('Tag');
+$listTags = $b2tservice->getContactTags(
+ $userservice->getCurrentUserId(), 1000, $userservice->getCurrentUserId()
+);
+$tags = array();
+foreach($listTags as $t) {
+ $tags[] = array(
+ 'caption' => $t['tag'],
+ 'value' => $t['tag'],
+ );
+}
+
+echo json_encode($tags);
?>
-{identifier:"tag",
-items: [
-getContactTags($userservice->getCurrentUserId(), 1000, $userservice->getCurrentUserId());
- foreach($listTags as $t) {
- echo "{tag: \"".$t['tag']."\"},";
- }
-?>
-]}
-
diff --git a/www/bookmarks.php b/www/bookmarks.php
index 5241481..0753c16 100644
--- a/www/bookmarks.php
+++ b/www/bookmarks.php
@@ -41,7 +41,6 @@ isset($_POST['address']) ? define('POST_ADDRESS', $_POST['address']): define('PO
isset($_POST['description']) ? define('POST_DESCRIPTION', $_POST['description']): define('POST_DESCRIPTION', '');
isset($_POST['privateNote']) ? define('POST_PRIVATENOTE', $_POST['privateNote']): define('POST_PRIVATENOTE', '');
isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', '');
-isset($_POST['tags']) ? define('POST_TAGS', $_POST['tags']): define('POST_TAGS', '');
isset($_POST['referrer']) ? define('POST_REFERRER', $_POST['referrer']): define('POST_REFERRER', '');
isset($_GET['popup']) ? define('GET_POPUP', $_GET['popup']): define('GET_POPUP', '');
@@ -50,6 +49,10 @@ isset($_POST['popup']) ? define('POST_POPUP', $_POST['popup']): define('POST_POP
isset($_GET['page']) ? define('GET_PAGE', $_GET['page']): define('GET_PAGE', 0);
isset($_GET['sort']) ? define('GET_SORT', $_GET['sort']): define('GET_SORT', '');
+if (!isset($_POST['tags'])) {
+ $_POST['tags'] = array();
+}
+//echo '' . var_export($_POST, true) . '
';die();
if ((GET_ACTION == "add") && !$userservice->isLoggedOn()) {
@@ -143,7 +146,7 @@ if ($userservice->isLoggedOn() && POST_SUBMITTED != '') {
$description = trim(POST_DESCRIPTION);
$privateNote = trim(POST_PRIVATENOTE);
$status = intval(POST_STATUS);
- $categories = trim(POST_TAGS);
+ $categories = trim(implode(',', $_POST['tags']));
$saved = true;
if ($bookmarkservice->addBookmark($address, $title, $description, $privateNote, $status, $categories)) {
if (POST_POPUP != '') {
@@ -184,10 +187,10 @@ if ($templatename == 'editbookmark.tpl') {
'bAddress' => stripslashes(POST_ADDRESS),
'bDescription' => stripslashes(POST_DESCRIPTION),
'bPrivateNote' => stripslashes(POST_PRIVATENOTE),
- 'tags' => (POST_TAGS ? explode(',', stripslashes(POST_TAGS)) : array()),
+ 'tags' => ($_POST['tags'] ? $_POST['tags'] : array()),
'bStatus' => 0,
);
- $tplVars['tags'] = POST_TAGS;
+ $tplVars['tags'] = $_POST['tags'];
} else {
if(GET_COPYOF != '') { //copy from bookmarks page
$tplVars['row'] = $bookmarkservice->getBookmark(intval(GET_COPYOF), true);
--
cgit v1.2.3
From 6d49b0622df0ea44975e99b585781f55fe9ac671 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Fri, 25 Mar 2011 19:26:42 +0100
Subject: begin modifying ajax/getcontacttags
---
data/templates/editbookmark.tpl.php | 5 +++
www/ajax/getcontacttags.php | 69 +++++++++++++++++++------------------
2 files changed, 40 insertions(+), 34 deletions(-)
(limited to 'www/ajax')
diff --git a/data/templates/editbookmark.tpl.php b/data/templates/editbookmark.tpl.php
index 727ee1a..6ce10b3 100644
--- a/data/templates/editbookmark.tpl.php
+++ b/data/templates/editbookmark.tpl.php
@@ -150,6 +150,11 @@ jQuery(document).ready(function() {
$.ui.autocomplete.filter(
availableTags, extractLast(request.term)
)
+ /*
+ $.getJSON( "search.php", {
+ term: extractLast( request.term )
+ }, response );
+ */
);
},
diff --git a/www/ajax/getcontacttags.php b/www/ajax/getcontacttags.php
index 5f1edb3..1377fea 100644
--- a/www/ajax/getcontacttags.php
+++ b/www/ajax/getcontacttags.php
@@ -1,46 +1,47 @@
+ * @author Christian Weiske
+ * @author Eric Dane
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
-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 tags according to current user and sort by popularity*/
$httpContentType = 'application/json';
require_once '../www-header.php';
-/* Service creation: only useful services are created */
-$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
-$bookmarkservice =SemanticScuttle_Service_Factory::get('Tag');
+$limit = 30;
+$beginsWith = null;
+$currentUserId = $userservice->getCurrentUserId();
+
+if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
+ $limit = (int)$_GET['limit'];
+}
+if (isset($_GET['beginsWith']) && strlen(trim($_GET['beginsWith']))) {
+ $beginsWith = trim($_GET['beginsWith']);
+}
-$listTags = $b2tservice->getContactTags(
- $userservice->getCurrentUserId(), 1000, $userservice->getCurrentUserId()
+$listTags = SemanticScuttle_Service_Factory::get('Bookmark2Tag')->getContactTags(
+ $currentUserId, $limit, $currentUserId, $beginsWith
);
$tags = array();
-foreach($listTags as $t) {
- $tags[] = array(
- 'caption' => $t['tag'],
- 'value' => $t['tag'],
- );
+foreach ($listTags as $t) {
+ $tags[] = $t['tag'];
}
echo json_encode($tags);
?>
-
-
-
-
--
cgit v1.2.3
From 78654369e918126c137b5aa4ba709a7bc0a27b43 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Sat, 26 Mar 2011 11:54:47 +0100
Subject: test for beginsWith parameter and a bugfix :)
---
tests/ajax/GetContactTagsTest.php | 17 +++++++++++++++++
www/ajax/getcontacttags.php | 2 +-
2 files changed, 18 insertions(+), 1 deletion(-)
(limited to 'www/ajax')
diff --git a/tests/ajax/GetContactTagsTest.php b/tests/ajax/GetContactTagsTest.php
index 757dce9..6e40444 100644
--- a/tests/ajax/GetContactTagsTest.php
+++ b/tests/ajax/GetContactTagsTest.php
@@ -71,6 +71,23 @@ class ajax_GetContactTagsTest extends TestBaseApi
$this->assertContains('public2', $data);
$this->assertContains('user2tag', $data);
}
+
+ public function testParameterBeginsWith()
+ {
+ list($req, $uId) = $this->getLoggedInRequest('?beginsWith=bar');
+ $this->addBookmark($uId, null, 0, array('foobar', 'barmann'));
+
+ $res = $req->send();
+ $this->assertEquals(200, $res->getStatus());
+ $this->assertEquals(
+ 'application/json; charset=utf-8',
+ $res->getHeader('content-type')
+ );
+ $data = json_decode($res->getBody());
+ $this->assertInternalType('array', $data);
+ $this->assertEquals(1, count($data));
+ $this->assertContains('barmann', $data);
+ }
}
diff --git a/www/ajax/getcontacttags.php b/www/ajax/getcontacttags.php
index 1377fea..d353226 100644
--- a/www/ajax/getcontacttags.php
+++ b/www/ajax/getcontacttags.php
@@ -36,7 +36,7 @@ if (isset($_GET['beginsWith']) && strlen(trim($_GET['beginsWith']))) {
}
$listTags = SemanticScuttle_Service_Factory::get('Bookmark2Tag')->getContactTags(
- $currentUserId, $limit, $currentUserId, $beginsWith
+ $currentUserId, $limit, $currentUserId, null, $beginsWith
);
$tags = array();
foreach ($listTags as $t) {
--
cgit v1.2.3
From a1545004f2a96597165e4d9b970229137dd156e3 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Sat, 26 Mar 2011 17:04:21 +0100
Subject: rewrite ajax/getadmintags.php
---
www/ajax/getadmintags.php | 81 ++++++++++++++++++++++++-----------------------
1 file changed, 42 insertions(+), 39 deletions(-)
(limited to 'www/ajax')
diff --git a/www/ajax/getadmintags.php b/www/ajax/getadmintags.php
index ffd20bb..2f13060 100644
--- a/www/ajax/getadmintags.php
+++ b/www/ajax/getadmintags.php
@@ -1,44 +1,47 @@
+ * @author Christian Weiske
+ * @author Eric Dane
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
-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 tags according to current user and sort by popularity*/
$httpContentType = 'application/json';
require_once '../www-header.php';
-/* Service creation: only useful services are created */
-$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
-$bookmarkservice =SemanticScuttle_Service_Factory::get('Tag');
-
-?>
-
-{identifier:"tag",
-items: [
-getAdminTags(1000, $userservice->getCurrentUserId());
- foreach($listTags as $t) {
- echo "{tag: \"".$t['tag']."\"},";
- }
-?>
-]}
-
-
-
-
+$limit = 30;
+$beginsWith = null;
+$currentUserId = $userservice->getCurrentUserId();
+
+if (isset($_GET['limit']) && is_numeric($_GET['limit'])) {
+ $limit = (int)$_GET['limit'];
+}
+if (isset($_GET['beginsWith']) && strlen(trim($_GET['beginsWith']))) {
+ $beginsWith = trim($_GET['beginsWith']);
+}
+
+$listTags = SemanticScuttle_Service_Factory::get('Bookmark2Tag')->getAdminTags(
+ $limit, $currentUserId, null, $beginsWith
+);
+$tags = array();
+foreach ($listTags as $t) {
+ $tags[] = $t['tag'];
+}
+
+echo json_encode($tags);
+?>
\ No newline at end of file
--
cgit v1.2.3