function printTermsRecursive($terms, $level = 0)
 {
     foreach ($terms as $term) {
         if ($this->selected == null || !wpdreams_in_array_r($term->term_id, $this->selected)) {
             echo '<li class="ui-state-default termlevel-' . $level . '" term_id="' . $term->term_id . '" taxonomy="' . $term->taxonomy . '">' . $term->name . '</li>';
         }
         if (is_array($term->children) && count($term->children) > 0) {
             $this->printTermsRecursive($term->children, $level + 1);
         }
     }
 }
        function getType()
        {
            parent::getType();
            $this->processData();
            $this->types = $this->getAllTaxonomies();
            echo "\r\n      <div class='wpdreamsTaxonomySelect'>\r\n        <fieldset>\r\n\r\n          <legend>" . $this->label . "</legend>";
            echo '<div class="sortablecontainer" id="sortablecontainer' . self::$_instancenumber . '">
                  <div class="arrow-all-left"></div>
                  <div class="arrow-all-right"></div>
            <p>Available taxonomies</p>
            <ul id="sortable' . self::$_instancenumber . '" class="connectedSortable">';
            if ($this->types != null && is_array($this->types)) {
                foreach ($this->types as $tax) {
                    $custom_post_type = "";
                    if ($tax->object_type != null && $tax->object_type[0] != null) {
                        $custom_post_type = $tax->object_type[0] . " - ";
                    }
                    if ($this->selected == null || !wpdreams_in_array_r($tax->name, $this->selected)) {
                        echo '<li class="ui-state-default" taxonomy="' . $tax->name . '">' . $custom_post_type . $tax->labels->name . '</li>';
                    }
                }
            }
            echo "</ul></div>";
            echo '<div class="sortablecontainer"><p>Drag here the taxonomies you want to <b>' . $this->otype . '</b>!</p><ul id="sortable_conn' . self::$_instancenumber . '" class="connectedSortable">';
            if ($this->selected != null && is_array($this->selected)) {
                foreach ($this->selected as $_tax) {
                    $tax = get_taxonomy($_tax);
                    $custom_post_type = "";
                    if ($tax->object_type != null && $tax->object_type[0] != null) {
                        $custom_post_type = $tax->object_type[0] . " - ";
                    }
                    echo '<li class="ui-state-default" taxonomy="' . $tax->name . '">' . $custom_post_type . $tax->labels->name . '</li>';
                }
            }
            echo "</ul></div>";
            echo "\r\n         <input isparam=1 type='hidden' value='" . $this->data["value"] . "' name='" . $this->name . "'>\r\n         <input type='hidden' value='wpdreamsTaxonomySelect' name='classname-" . $this->name . "'>";
            ?>
            <script type='text/javascript'>
                (function ($) {
                    $(document).ready(function () {
                        var selector = "#sortable<?php 
            echo self::$_instancenumber;
            ?>
, #sortable_conn<?php 
            echo self::$_instancenumber;
            ?>
";
                        $(selector).sortable({
                            connectWith: ".connectedSortable"
                        }, {
                            update: function (event, ui) {
                            }
                        }).disableSelection();
                        $(selector).on('sortupdate', function(event, ui) {
                            if (typeof(ui)!='undefined')
                                parent = $(ui.item).parent();
                            else
                                parent = $(event.target);
                            while (!parent.hasClass('wpdreamsTaxonomySelect')) {
                                parent = $(parent).parent();
                            }
                            var items = $('ul[id*=sortable_conn] li', parent);
                            var hidden = $('input[name="<?php 
            echo $this->name;
            ?>
"]', parent);
                            var val = "";
                            items.each(function () {
                                val += "|" + $(this).attr('taxonomy');
                            });
                            val = val.substring(1);
                            hidden.val(val);
                        });
                        $("#sortablecontainer<?php 
            echo self::$_instancenumber;
            ?>
 .arrow-all-left").click(function(){
                            $("#sortable_conn<?php 
            echo self::$_instancenumber;
            ?>
 li")
                                .detach().appendTo("#sortable<?php 
            echo self::$_instancenumber;
            ?>
");
                            $(selector).trigger("sortupdate");
                        });
                        $("#sortablecontainer<?php 
            echo self::$_instancenumber;
            ?>
 .arrow-all-right").click(function(){
                            $("#sortable<?php 
            echo self::$_instancenumber;
            ?>
 li")
                                .detach().appendTo("#sortable_conn<?php 
            echo self::$_instancenumber;
            ?>
");
                            $(selector).trigger("sortupdate");
                        });
                    });
                }(jQuery));
            </script>
            <?php 
            echo "\r\n        </fieldset>\r\n      </div>";
        }
Example #3
0
 function wpdreams_in_array_r($needle, $haystack, $strict = false)
 {
     foreach ($haystack as $item) {
         if (($strict ? $item === $needle : $item == $needle) || is_array($item) && wpdreams_in_array_r($needle, $item, $strict)) {
             return true;
         }
     }
     return false;
 }
        function getType()
        {
            parent::getType();
            $this->processData();
            $this->types = $this->getAllTerms();
            echo "\n      <div class='wpdreamsCustomTaxonomyTerm'>\n        <fieldset>                               \n          <div style='margin:15px 30px;text-align: left;'>\n          <label>Select the taxonomy: </label>\n          <select name='" . $this->name . "_taxonomies' id='" . $this->name . "_taxonomies'> ";
            foreach ($this->types as $taxonomy => $v) {
                //foreach ($terms as $term) {
                $tax = get_taxonomy($taxonomy);
                $custom_post_type = "";
                if ($tax->object_type != null && $tax->object_type[0] != null) {
                    $custom_post_type = $tax->object_type[0] . " - ";
                }
                echo "<option  value='" . $taxonomy . "' taxonomy='" . $taxonomy . "'>" . $custom_post_type . $tax->labels->name . "</option>";
                //}
            }
            echo "</select>\n          </div>\n          <legend>" . $this->label . "</legend>";
            echo '<div class="sortablecontainer"><p>Available terms for the selected taxonomy</p><ul id="sortable' . self::$_instancenumber . '" class="connectedSortable">';
            if ($this->types != null && is_array($this->types)) {
                foreach ($this->types as $kk => $vv) {
                    foreach ($vv as $k => $term) {
                        if ($this->selected == null || !wpdreams_in_array_r($term->term_id, $this->selected)) {
                            echo '<li class="ui-state-default" term_id="' . $term->term_id . '" taxonomy="' . $term->taxonomy . '">' . $term->name . '</li>';
                        }
                    }
                }
            }
            echo "</ul></div>";
            echo '<div class="sortablecontainer"><p>Drag here the terms you want to <b>' . $this->otype . '</b>!</p><ul id="sortable_conn' . self::$_instancenumber . '" class="connectedSortable">';
            if ($this->selected != null && is_array($this->selected)) {
                foreach ($this->selected as $k => $v) {
                    $term = get_term($v[0], $v[1]);
                    //print_r($term);
                    echo '<li class="ui-state-default" term_id="' . $term->term_id . '" taxonomy="' . $term->taxonomy . '">' . $term->name . '</li>';
                }
            }
            echo "</ul></div>";
            echo "\n         <input isparam=1 type='hidden' value='" . $this->data["value"] . "' name='" . $this->name . "'>";
            ?>
         <script type='text/javascript'>
          (function($) {
            $(document).ready(function() { 
              $( "#sortable<?php 
            echo self::$_instancenumber;
            ?>
, #sortable_conn<?php 
            echo self::$_instancenumber;
            ?>
" ).sortable({
                  connectWith: ".connectedSortable"
              }, {
                update: function(event, ui) {
                  parent = $(ui.item).parent();
                  while(!parent.hasClass('wpdreamsCustomTaxonomyTerm')) {
                    parent=$(parent).parent();
                  }
                  var items = $('ul[id*=sortable_conn] li',parent);
                  var hidden = $('input[name=<?php 
            echo $this->name;
            ?>
]', parent);
                  var val = "";
                  items.each(function(){
                     val+= "|"+$(this).attr('term_id') + "-" + $(this).attr('taxonomy');
                  });
                  val = val.substring(1);
                  hidden.val(val);
                }
              }).disableSelection();
              $("#<?php 
            echo $this->name;
            ?>
_taxonomies").change(function(){
                 var taxonomy = $(this).val();
                 $("li", "#sortable<?php 
            echo self::$_instancenumber;
            ?>
").css('display', 'none');
                 $("li[taxonomy="+taxonomy+"]", "#sortable<?php 
            echo self::$_instancenumber;
            ?>
").css('display', 'block');
              });
              $("#<?php 
            echo $this->name;
            ?>
_taxonomies").change();
            });
          }(jQuery));
         </script>
      <?php 
            echo "\n        </fieldset>\n      </div>";
        }