Very initial tagger stuff before I loose it.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 25 Jan 2009 21:21:18 +0000 (16:21 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 29 Jan 2009 22:39:52 +0000 (17:39 -0500)
kronolith/calendars/edit.php
kronolith/imple.php
kronolith/js/src/calendar-panel.js
kronolith/js/tagactions.js [new file with mode: 0755]
kronolith/lib/Forms/CreateCalendar.php [changed mode: 0644->0755]
kronolith/lib/Forms/EditCalendar.php
kronolith/lib/Imple/TagActions.php [new file with mode: 0644]
kronolith/lib/Tagger.php [new file with mode: 0644]
kronolith/templates/panel.inc

index 7ac53f3..dadbdca 100644 (file)
@@ -53,6 +53,8 @@ if ($form->validate($vars)) {
 
 $vars->set('name', $calendar->get('name'));
 $vars->set('description', $calendar->get('desc'));
+$tags = new Kronolith_Tagger();
+$vars->set('tags', implode(',', array_values($tags->getTags($calendar->getName(), 'calendar'))));
 $title = $form->getTitle();
 require KRONOLITH_TEMPLATES . '/common-header.inc';
 require KRONOLITH_TEMPLATES . '/menu.inc';
index 46b468d..f9b0245 100644 (file)
@@ -27,7 +27,6 @@ $imple = Kronolith_Imple::factory($impleName);
 if (!$imple) {
     exit;
 }
-
 $args = array();
 foreach ($path as $pair) {
     if (strpos($pair, '=') === false) {
index 408bd87..96fac0c 100644 (file)
@@ -13,6 +13,10 @@ function sbarToggle()
     new Ajax.Request(KronolithVar.pref_api_url, { parameters: { app: 'kronolith', pref: 'show_panel', value: pref_value } });
 }
 
+function removeTag(tagid)
+{
+       
+}
 document.observe('dom:loaded', function() {
     $$('#pageControlsInner .checkbox').invoke('observe', 'click', function() {
         Views.invalidate();
diff --git a/kronolith/js/tagactions.js b/kronolith/js/tagactions.js
new file mode 100755 (executable)
index 0000000..2963adc
--- /dev/null
@@ -0,0 +1,38 @@
+function addTag()
+{
+    if (!$('addtag').value.blank()) {
+        var params = new Object();
+        params.requestType="TagActions/action=add/gallery=" + tagActions.gallery + "/tags=" + $('addtag').value;
+        new Ajax.Updater({success:'tags'},
+                         tagActions.url,
+                         {
+                             method: 'post',
+                             parameters: params,
+                             onComplete: function() {$('addtag').value = "";}
+                         }
+        );
+    }
+
+    return true;
+}
+
+function removeTag(resource, type, tagid, endpoint)
+{
+    var params = new Object();
+    params.imple = "TagActions/action=remove/resource=" + resource + "/type=" + type + "/tags=" + tagid;
+    new Ajax.Updater({success:'tags-' + resource},
+                     endpoint,
+                     {
+                         method: 'post',
+                         parameters: params
+                     }
+    );
+    return true;
+}
+
+// Since onsubmit is never called when submitting programatically we
+// can use this function to add tags when we press enter on the tag form.
+function submitcheck()
+{
+    return !addTag();
+}
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index e00f705..b30db8a
@@ -32,7 +32,7 @@ class Kronolith_CreateCalendarForm extends Horde_Form {
 
         $this->addVariable(_("Name"), 'name', 'text', true);
         $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
-
+        $this->addVariable(_("Tags"), 'tags', 'text', false);
         $this->setButtons(array(_("Create")));
     }
 
@@ -45,6 +45,8 @@ class Kronolith_CreateCalendarForm extends Horde_Form {
         }
         $calendar->set('name', $this->_vars->get('name'));
         $calendar->set('desc', $this->_vars->get('description'));
+        $tagger = new Kronolith_Tagger();
+        $tagger->tag($calendar->getName(), explode(',', $this->_vars->get('tags')), 'calendar');
         return $GLOBALS['kronolith_shares']->addShare($calendar);
     }
 
index 94aefa2..03464e3 100644 (file)
@@ -39,7 +39,7 @@ class Kronolith_EditCalendarForm extends Horde_Form {
         $this->addHidden('', 'c', 'text', true);
         $this->addVariable(_("Name"), 'name', 'text', true);
         $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
-
+        $this->addVariable(_("Tags"), 'tags', 'text', false);
         $this->setButtons(array(_("Save")));
     }
 
@@ -49,7 +49,8 @@ class Kronolith_EditCalendarForm extends Horde_Form {
         $new_name = $this->_vars->get('name');
         $this->_calendar->set('name', $new_name);
         $this->_calendar->set('desc', $this->_vars->get('description'));
-
+        $tagger = new Kronolith_Tagger();
+        $tagger->tag($this->_calendar->getName(), explode(',', $this->_vars->get('tags')), 'calendar');
         if ($original_name != $new_name) {
             $result = $GLOBALS['kronolith_driver']->rename($original_name, $new_name);
             if (is_a($result, 'PEAR_Error')) {
diff --git a/kronolith/lib/Imple/TagActions.php b/kronolith/lib/Imple/TagActions.php
new file mode 100644 (file)
index 0000000..1156980
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ *
+ */
+class Kronolith_Imple_TagActions extends Kronolith_Imple
+{
+    public function attach()
+    {
+        // TODO: HACK! attach is called in the contructor which means that even
+        // if we are only handling the request, we try to attach().
+        if (count($this->_params) == 0) {
+            return;
+        }
+        Horde::addScriptFile('tagactions.js');
+        $dom_id = $this->_params['triggerId'];
+        $action = $this->_params['action'];
+        $content_id = $this->_params['resource'];
+        $content_type = $this->_params['type'];
+        $tag_id = $this->_params['tagId'];
+        $endpoint = Horde::url('imple.php', true);
+
+        if ($action == 'add') {
+            $js = "Event.observe('" . $dom_id . "', 'click', function(event) {addTag(); Event.stop(event)});";
+        } elseif ($action == 'delete') {
+            $js = "Event.observe('" . $dom_id . "', 'click', function(event) {removeTag('" . $content_id . "', '" . $content_type . "', " . $tag_id . ", '" . $endpoint . "'); Event.stop(event)});";
+        }
+        Kronolith::addInlineScript($js, 'window');
+    }
+
+    public function handle($args)
+    {
+        global $ansel_storage;
+
+        $request = $args['action'];
+        $content = array('id' => $args['resource'], 'type' => $args['type']);
+        $tags = $args['tags'];
+
+        /* Get the resource owner */
+        /* Perms checks */
+
+        switch ($request) {
+        case 'add':
+            break;
+        case 'remove':
+            $tagger = new Kronolith_Tagger();
+            //$tagger->
+
+
+            break;
+        }
+    }
+
+    private function _getTagHtml($tags, $hasEdit)
+    {
+    }
+
+}
diff --git a/kronolith/lib/Tagger.php b/kronolith/lib/Tagger.php
new file mode 100644 (file)
index 0000000..0795650
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+/**
+ * Kronolith interface to the Horde_Content tagger
+ *
+ *
+ */
+
+// Note:: Autoloading depends on there being a registry entry for content
+Horde_Autoloader::addClassPattern('/^Content_/',
+                                  $GLOBALS['registry']->get('fileroot', 'content') . '/lib/');
+
+class Kronolith_Tagger {
+
+    protected static $_type_ids = array();
+    protected static $_tagger;
+
+    public function __construct()
+    {
+        if (is_null(self::$_tagger)) {
+            // Set up the context for the tagger and related content classes
+            $GLOBALS['conf']['sql']['adapter'] = $GLOBALS['conf']['sql']['phptype'] == 'mysqli' ?
+                             'mysqli' :
+                             'pdo_' . $GLOBALS['conf']['sql']['phptype'];
+
+            Horde_Db::setAdapter(Horde_Db_Adapter::factory($GLOBALS['conf']['sql']));
+
+            $context = array('dbAdapter' => Horde_Db::getAdapter());
+            $user_mgr = new Content_Users_Manager($context);
+            $type_mgr = new Content_Types_Manager($context);
+
+            // Objects_Manager requires a Types_Manager
+            $context['typeManager'] = $type_mgr;
+            $object_mgr = new Content_Objects_Manager($context);
+
+            // Create the Content_Tagger
+            $context['userManager'] = $user_mgr;
+            $context['objectManager'] = $object_mgr;
+
+            self::$_tagger = new Content_Tagger($context);
+            $types = $type_mgr->ensureTypes(array('calendar', 'event'));
+            self::$_type_ids = array('calendar' => $types[0], 'event' => $types[1]);
+        }
+    }
+
+    /**
+     * Tag a kronolith object with any number of tags.
+     *
+     * @param string $localId       The identifier of the kronolith object.
+     * @param mixed $tags           Either a single tag string or an array of tags.
+     * @param string $content_type  The type of object we are tagging (event/calendar).
+     *
+     * @return void
+     */
+    public function tag($localId, $tags, $content_type = 'event')
+    {
+        self::$_tagger->tag(Auth::getAuth(),
+                   array('object' => $localId,
+                         'type' => self::$_type_ids[$content_type]),
+                   $tags);
+    }
+
+    /**
+     * Retrieve the tags on a given object(s)
+     */
+    public function getTags($localId, $type = 'event')
+    {
+        if (!is_array($localId)) {
+            $localId = array($localId);
+        }
+        $tags = array();
+        foreach ($localId as $id) {
+            $tags = $tags + self::$_tagger->getTags(array('objectId' => array('object' => $id, 'type' => $type)));
+        }
+var_dump($tags);
+        return $tags;
+    }
+
+    public function untag($localId, $tag, $content_type = 'event')
+    {
+        //self::$_tagger->
+    }
+
+    /**
+     * tag search - return all types of content we care about tagged with
+     * the passed in tags
+     *
+     * @param array $tags  An array of tag ids.
+     */
+    public function search($tags, $content_type = null)
+    {
+        $this->getObjects(array('tagId' => $tags, ''));
+    }
+
+}
index a9d353d..b717e3c 100644 (file)
@@ -16,6 +16,8 @@ foreach (Kronolith::listCalendars() as $id => $cal) {
         $shared_calendars[$id] = $cal;
     }
 }
+
+$tagger = new Kronolith_Tagger();
 ?>
 
 <div id="pageControls">
@@ -41,7 +43,21 @@ foreach (Kronolith::listCalendars() as $id => $cal) {
  <h4><?php echo _("My Calendars:") ?></h4>
  <ul id="mycalendars">
 <?php foreach ($my_calendars as $id => $cal): ?>
-  <li><label><input type="checkbox" class="checkbox" name="display_cal[]" value="<?php echo htmlspecialchars($id) ?>"<?php echo (in_array($id, $display_calendars) ? ' checked="checked"' : '') . ' /> ' . htmlspecialchars($cal->get('name')) ?></label> <?php echo $info_img ?></li>
+  <li><label><input type="checkbox" class="checkbox" name="display_cal[]" value="<?php echo htmlspecialchars($id) ?>"<?php echo (in_array($id, $display_calendars) ? ' checked="checked"' : '') . ' /> ' . htmlspecialchars($cal->get('name')) ?></label> <?php echo $info_img ?>
+   <ul class="panel-tags" id="tags-<?php echo $id?>" style="margin-left: 10px;">
+    <?php $tags = $tagger->getTags($id, 'calendar'); ?>
+    <?php foreach ($tags as $tag_id => $tag): ?>
+    <li><?php echo $tag . ($cal->hasPermission(Auth::getAuth(), PERMS_EDIT) ? '<a href="#" id="remove' . md5($id . $tag_id) . '">' . Horde::img('delete-small.png', _("Remove Tag"), '', $registry->getImageDir('horde')) . '</a>' : '') . '</li>'?>
+    <?php
+        Kronolith_Imple::factory('TagActions', array('triggerId' => 'remove' . md5($id . $tag_id),
+                                                              'action' => 'delete',
+                                                              'resource' => $id,
+                                                              'type' => 'calendar',
+                                                              'tagId' => $tag_id));
+    ?>
+    <?php endforeach;?>
+  </ul>
+  </li>
 <?php endforeach; ?>
  </ul>
 <?php endif; ?>