예제 #1
0
 /**
  * Print the tag cloud and tagging link for an item
  * 
  * @param object TaggedItem $item
  * @param optional string $viewAction The action to use when clicking on a tag. 
  *							 Usually view or viewuser
  * @param optional array $styles An array of style-strings to use for various 
  *						levels of of tag occurrances.
  * @return string
  * @access public
  * @since 11/14/06
  * @static
  */
 static function getTagCloudForItem($item, $viewAction = 'view', $styles = null, $additionalParams = null)
 {
     ob_start();
     print "\n<div>";
     print TagAction::getTagCloud($item->getTags(), $viewAction, $styles, $additionalParams);
     print "\n\t<span> &nbsp; ";
     print "\n\t\t<a onclick=\"";
     print "this.viewAction = '" . $viewAction . "'; ";
     // register the styles with the tagger
     if (!is_array($styles)) {
         $styles = TagAction::getDefaultStyles();
     }
     print "this.styles = new Array(); ";
     foreach ($styles as $style) {
         $styleStrings = explode(";", $style);
         print "this.styles.push({";
         $started = false;
         foreach ($styleStrings as $styleString) {
             if (preg_match('/([a-z0-9\\-]+):\\s?([a-z0-9\\-\\s%]+)/i', $styleString, $matches)) {
                 // Reformat the style name for javascript
                 $styleName = trim($matches[1]);
                 $styleNameParts = explode('-', $styleName);
                 $styleName = $styleNameParts[0];
                 for ($i = 1; $i < count($styleNameParts); $i++) {
                     $styleName .= ucfirst($styleNameParts[$i]);
                 }
                 $styleValue = trim($matches[2]);
                 if ($started) {
                     print ", ";
                 }
                 print "'" . $styleName . "': '" . $styleValue . "'";
             }
         }
         print "}); ";
     }
     print "Tagger.run('" . $item->getIdString() . "', '" . $item->getSystem() . "', this, this.parentNode.parentNode";
     // Add Context parameters to the urls generated when re-writing the tag cloud.
     $harmoni = Harmoni::instance();
     $contextInfo = $harmoni->request->getContextInfo();
     if (count($contextInfo)) {
         print ", {";
         $params = array();
         foreach ($contextInfo as $info) {
             $params[] = $info->name . ": {value: '" . $info->value . "', namespace: '" . $info->namespace . "'}";
         }
         print implode(', ', $params);
         print "}";
     }
     print ");";
     print "\" title='" . _("Add Tags to this Item") . "'";
     print " style='font-weight: bold;'>";
     print _("+Tag") . "</a>";
     print "\n\t</span>";
     print "\n</div>";
     return ob_get_clean();
 }
    /**
     * Return the markup that represents the plugin.
     * Plugin writers should override this method with their own functionality
     * as needed.
     * 
     * @return string
     * @access public
     * @since 1/12/06
     */
    public function getMarkup()
    {
        ob_start();
        if ($this->getFieldValue('edit') && $this->canModify()) {
            $director = SiteDispatcher::getSiteDirector();
            $node = $director->getSiteComponentById($this->getId());
            $currentTarget = $this->getTargetNodeId();
            $node = $director->getSiteComponentById($this->getId());
            print "\n" . $this->formStartTagWithAction();
            $visitor = new UmbrellaVisitor();
            $node->acceptVisitor($visitor);
            print "<div>";
            print _('Chose a section or page:');
            print "<select name='" . $this->getFieldName('tagNode') . "'>";
            $this->writeUmbrellaSelect($visitor->getNodeData(), $currentTarget);
            print "</select>\n";
            print "<div class='tags_display_options'>" . _('Only tags from your selected section or page will be displayed') . "</div><br/>\n";
            print "<select name='" . $this->getFieldName('defaultSortMethod') . "'>";
            print "\n\t<option value='alpha' ";
            if ($this->readOption('defaultSortMethod') == 'alpha') {
                print "selected='selected'";
            }
            print ">" . _('sort tags alphabetically') . "</option>";
            print "\n\t<option value='freq' ";
            if ($this->readOption('defaultSortMethod') == 'freq') {
                print "selected='selected'";
            }
            print ">" . _('sort tags by frequency') . "</option>";
            print "</select>\n";
            print "<br/>";
            print "<select name='" . $this->getFieldName('defaultDisplayType') . "'>";
            print "\n\t<option value='cloud' ";
            if ($this->readOption('defaultDisplayType') == 'cloud') {
                print "selected='selected'";
            }
            print ">" . _('display as cloud') . "</option>";
            print "\n\t<option value='list' ";
            if ($this->readOption('defaultDisplayType') == 'list') {
                print "selected='selected'";
            }
            print ">" . _('display as list') . "</option>";
            print "</select>\n";
            print "<br/>";
            print "<select name='" . $this->getFieldName('defaultListLimit') . "'>";
            print "\n\t<option value='0' ";
            if ($this->readOption('defaultListLimit') == '0') {
                print "selected='selected'";
            }
            print ">" . _('in list show: all') . "</option>";
            for ($i = 5; $i < 25; $i = $i + 5) {
                print "\n\t<option value='{$i}' ";
                if (intval($this->readOption('defaultListLimit')) == $i) {
                    print "selected='selected'";
                }
                print ">" . str_replace('%1', $i, _('in list show: %1')) . "</option>";
            }
            for ($i = 25; $i <= 300; $i = $i + 25) {
                print "\n\t<option value='{$i}' ";
                if (intval($this->readOption('defaultListLimit')) == $i) {
                    print "selected='selected'";
                }
                print ">" . str_replace('%1', $i, _('in list show: %1')) . "</option>";
            }
            print "</select>\n";
            print "<br/>";
            print "<br/>";
            print "<input type='submit' value='Update' name='" . $this->getFieldName('submit') . "'>\n";
            print "\n\t<input type='button' value='" . _('Cancel') . "' onclick=" . $this->locationSendString() . "/>";
            print "</div>";
            print "</form>";
        } else {
            if ($this->canView()) {
                $items = array();
                $director = SiteDispatcher::getSiteDirector();
                $node = $director->getSiteComponentById($this->getTargetNodeId());
                $visitor = new TaggableItemVisitor();
                $items = $node->acceptVisitor($visitor);
                print "\n<div class='breadcrumbs' style='height: auto; margin-top: 1px; margin-bottom: 5px; border-bottom: 1px dotted; padding-bottom: 2px;'>";
                print str_replace('%1', $node->acceptVisitor(new BreadCrumbsVisitor($node)), _("Tags within: %1"));
                print "</div>";
                print "\n<div style='text-align: justify;' id='tag_cloud_container-" . $this->getId() . "'>";
                $tags = TagAction::getTagsFromItems($items);
                //SiteDispatcher::passthroughContext();
                print TagAction::getTagCloudDiv($tags, 'sitetag', TagAction::getDefaultStyles(), array(), array(null => array('node' => $this->getTargetNodeId())));
                //SiteDispatcher::forgetContext();
                ?>
 	
 	<script type="text/javascript">
 	// <![CDATA[
 	
 	var cloudParent = document.get_element_by_id('tag_cloud_container-<?php 
                print $this->getId();
                ?>
');
 	var clouds = document.get_elements_by_class('tag_cloud', cloudParent);
 	var cloud = TagCloud.forContainer(clouds[0]);
 	
 			<?php 
                if ($this->readOption('defaultListLimit') != 15) {
                    print "\n\tcloud.tagList.setLimit(" . $this->readOption('defaultListLimit') . ");";
                }
                if ($this->readOption('defaultSortMethod') == 'freq') {
                    print "\n\tcloud.orderFreq();";
                }
                if ($this->readOption('defaultDisplayType') == 'list') {
                    print "\n\tcloud.showList();";
                }
                ?>

 	// ]]>
 	</script>
 	
 			
 			<?php 
                print "</div>";
                if ($this->shouldShowControls()) {
                    print "\n<div style='text-align: right; white-space: nowrap;'>";
                    print "\n\t<a " . $this->href(array('edit' => 'true')) . ">" . _('edit') . "</a>";
                    print "\n</div>";
                }
                /* 	
                $visitor = new UmbrellaVisitor;
                $node->acceptVisitor($visitor);
                print "<br/><pre>";
                print_r($visitor->getNodeData());
                print "</pre><br/>\n";
                */
            }
        }
        return ob_get_clean();
    }