aboutsummaryrefslogtreecommitdiff
path: root/www/ajax
diff options
context:
space:
mode:
Diffstat (limited to 'www/ajax')
-rw-r--r--www/ajax/getadminlinkedtags.php92
-rw-r--r--www/ajax/getadmintags.php47
-rw-r--r--www/ajax/getcontacttags.php47
-rw-r--r--www/ajax/getlinkedtags.php141
-rw-r--r--www/ajax/gettags.php44
5 files changed, 371 insertions, 0 deletions
diff --git a/www/ajax/getadminlinkedtags.php b/www/ajax/getadminlinkedtags.php
new file mode 100644
index 0000000..5f939a6
--- /dev/null
+++ b/www/ajax/getadminlinkedtags.php
@@ -0,0 +1,92 @@
+<?php
+/**
+ * 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';
+require_once '../www-header.php';
+
+/**
+ * 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'];
+ } else {
+ $linkedTags = $t2t->getAdminLinkedTags($tag, '>');
+ }
+
+ $tagData = array();
+ foreach ($linkedTags as $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;
+}
+
+/**
+ * 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".
+ *
+ * @return array Array to be sent back to the browser as json
+ */
+function createTagArray($tag, $hasChildren = true)
+{
+ $ar = array(
+ 'data' => array(
+ //<a> attributes
+ 'title' => $tag,
+ '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'] = 'closed';
+ }
+
+ return $ar;
+}
+
+
+$tag = isset($_GET['tag']) ? trim($_GET['tag']) : '';
+$tagData = assembleAdminTagData(
+ $tag,
+ SemanticScuttle_Service_Factory::get('Tag2Tag')
+);
+echo json_encode($tagData);
+?> \ No newline at end of file
diff --git a/www/ajax/getadmintags.php b/www/ajax/getadmintags.php
new file mode 100644
index 0000000..2f13060
--- /dev/null
+++ b/www/ajax/getadmintags.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Return a json file with list of public tags used by admins and sorted
+ * by popularity.
+ *
+ * The following GET parameters are accepted:
+ * @param string $beginsWith The tag name shall start with that string.
+ * No default.
+ * @param integer $limit Number of tags to return. Defaults to 1000
+ *
+ * Part of SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @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';
+require_once '../www-header.php';
+
+$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
diff --git a/www/ajax/getcontacttags.php b/www/ajax/getcontacttags.php
new file mode 100644
index 0000000..d353226
--- /dev/null
+++ b/www/ajax/getcontacttags.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Return a json file with list of tags according to current user
+ * and sorted by popularity.
+ *
+ * The following GET parameters are accepted:
+ * @param string $beginsWith The tag name shall start with that string.
+ * No default.
+ * @param integer $limit Number of tags to return. Defaults to 1000
+ *
+ * Part of SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @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';
+require_once '../www-header.php';
+
+$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')->getContactTags(
+ $currentUserId, $limit, $currentUserId, null, $beginsWith
+);
+$tags = array();
+foreach ($listTags as $t) {
+ $tags[] = $t['tag'];
+}
+
+echo json_encode($tags);
+?>
diff --git a/www/ajax/getlinkedtags.php b/www/ajax/getlinkedtags.php
new file mode 100644
index 0000000..9bb3b1f
--- /dev/null
+++ b/www/ajax/getlinkedtags.php
@@ -0,0 +1,141 @@
+<?php
+/**
+ * Returns a list of tags linked to the given one(s),
+ * suitable for jsTree consumption.
+ *
+ * Accepted GET parameters:
+ *
+ * @param string $tag Tag for which the children tags shall be returned
+ * Multiple tags (separated with comma) are supported.
+ * If no tag is given, all top-level tags are loaded.
+ * @param integer $uId User ID to fetch the tags for
+ * @param boolean $parent Load parent tags
+ *
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @subpackage 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';
+require_once '../www-header.php';
+
+$tag = isset($_GET['tag']) ? $_GET['tag'] : null;
+$uId = isset($_GET['uId']) ? (int)$_GET['uId'] : 0;
+$loadParentTags = isset($_GET['parent']) ? (bool)$_GET['parent'] : false;
+
+$tags = explode(',', trim($tag));
+if (count($tags) == 1 && $tags[0] == '') {
+ //no tags
+ $tags = array();
+}
+
+
+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(
+ //<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);
+?> \ No newline at end of file
diff --git a/www/ajax/gettags.php b/www/ajax/gettags.php
new file mode 100644
index 0000000..cb73720
--- /dev/null
+++ b/www/ajax/gettags.php
@@ -0,0 +1,44 @@
+<?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 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: [
+<?php
+ $listTags = $b2tservice->getPopularTags($userservice->getCurrentUserId(), 1000, $userservice->getCurrentUserId());
+ foreach($listTags as $t) {
+ echo "{tag: \"".$t['tag']."\"},";
+ }
+?>
+]}
+
+
+
+