PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/php/lib/function.mtsubcatsrecurse.php

http://github.com/openmelody/melody
PHP | 61 lines | 39 code | 9 blank | 13 comment | 3 complexity | dd3fba4e189840d1613cdd089931e42f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, LGPL-2.1
  1. <?php
  2. # Movable Type (r) Open Source (C) 2001-2010 Six Apart, Ltd.
  3. # This program is distributed under the terms of the
  4. # GNU General Public License, version 2.
  5. #
  6. # $Id$
  7. function smarty_function_mtsubcatsrecurse($args, &$ctx) {
  8. $localvars = array('subCatsDepth', 'category', 'subCatIsFirst', 'subCatIsLast', 'subFolderHead', 'subFolderFoot');
  9. $fn = $ctx->stash('subCatTokens');
  10. #if (!method_exists($ctx,$fn)) {
  11. # return $ctx->error("Called SubCatsRecurse outside of SubCategories tag!");
  12. #}
  13. $cat = $ctx->stash('category');
  14. # Get the depth info
  15. $max_depth = $args['max_depth'];
  16. $depth = $ctx->stash('subCatsDepth') or 0;
  17. # Get the sorting info
  18. $sort_method = $ctx->stash('subCatsSortMethod');
  19. $sort_order = $ctx->stash('subCatsSortOrder');
  20. # Get the class info
  21. $class = 'category';
  22. if (isset($args['class'])) {
  23. $class = $args['class'];
  24. }
  25. $cats =& $ctx->mt->db->fetch_categories(array('blog_id' => $ctx->stash('blog_id'), 'category_id' => $cat['category_id'], 'children' => 1, 'show_empty' => 1, 'class' => $class));
  26. #$cats = sort_cats($ctx, $sort_method, $sort_order, $child_cats);
  27. if (!$cats) {
  28. return ''; #$ctx->error("No sub categories!");
  29. }
  30. $count = 0;
  31. $res = '';
  32. require_once("function.mtsetvar.php");
  33. $ctx->localize($localvars);
  34. $ctx->stash('subCatsDepth', $depth + 1);
  35. while ($c = array_shift($cats)) {
  36. smarty_function_mtsetvar(array('name' => '__depth__', 'value' => ($depth + 1)), $ctx);
  37. $ctx->stash('category', $c);
  38. $ctx->stash('subCatIsFirst', !$count);
  39. $ctx->stash('subCatIsLast', !count($cats));
  40. $ctx->stash('subFolderHead', !$count);
  41. $ctx->stash('subFolderFoot', !count($cats));
  42. ob_start();
  43. $fn($ctx, array());
  44. #call_user_method($fn, $ctx, $ctx, array());
  45. $res .= ob_get_contents();
  46. ob_end_clean();
  47. $count++;
  48. }
  49. $ctx->restore($localvars);
  50. return $res;
  51. }
  52. ?>