content.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. $widget = elgg_extract("entity", $vars);
  3. // get widget settings
  4. $count = (int) $widget->blog_count;
  5. if ($count < 1) {
  6. $count = 8;
  7. }
  8. // get view mode
  9. $view_mode = $widget->view_mode;
  10. // backup context and set
  11. switch($view_mode){
  12. case "slider":
  13. elgg_push_context("slider");
  14. break;
  15. case "preview":
  16. elgg_push_context("preview");
  17. break;
  18. case "simple":
  19. elgg_push_context("simple");
  20. break;
  21. default:
  22. elgg_push_context("listing");
  23. break;
  24. }
  25. $options = array(
  26. "type" => "object",
  27. "subtype" => "blog",
  28. "limit" => $count,
  29. "full_view" => false,
  30. "pagination" => false,
  31. "metadata_name_value_pairs" => array()
  32. );
  33. // only show published blogs to non admins
  34. if (!elgg_is_admin_logged_in()) {
  35. $options["metadata_name_value_pairs"][] = array(
  36. "name" => "status",
  37. "value" => "published"
  38. );
  39. }
  40. // limit to featured blogs?
  41. if ($widget->show_featured == "yes") {
  42. $options["metadata_name_value_pairs"][] = array(
  43. "name" => "featured",
  44. "value" => true
  45. );
  46. }
  47. $blogs = elgg_list_entities_from_metadata($options);
  48. if (!empty($blogs)) {
  49. if ($view_mode == "slider") {
  50. $blog_entities = elgg_get_entities_from_metadata($options);
  51. echo "<div id='blog_tools_widget_items_container_" . $widget->getGUID() . "' class='blog_tools_widget_items_container'>";
  52. echo $blogs;
  53. echo "</div>";
  54. echo "<div id='blog_tools_widget_items_navigator_" . $widget->getGUID() . "' class='elgg-widget-more blog_tools_widget_items_navigator'>";
  55. foreach ($blog_entities as $key => $blog) {
  56. echo "<span rel='" . $blog->getGUID() . "'>" . ($key + 1) . "</span>";
  57. }
  58. echo "</div>";
  59. ?>
  60. <script type="text/javascript">
  61. function rotateBlogItems<?php echo $widget->getGUID(); ?>(){
  62. if ($("#blog_tools_widget_items_navigator_<?php echo $widget->getGUID(); ?> .active").next().length === 0) {
  63. $("#blog_tools_widget_items_navigator_<?php echo $widget->getGUID(); ?>>span:first").click();
  64. } else {
  65. $("#blog_tools_widget_items_navigator_<?php echo $widget->getGUID(); ?> .active").next().click();
  66. }
  67. }
  68. $(document).ready(function(){
  69. $("#blog_tools_widget_items_navigator_<?php echo $widget->getGUID(); ?>>span:first").addClass("active");
  70. var active = $("#blog_tools_widget_items_navigator_<?php echo $widget->getGUID(); ?>>span:first").attr("rel");
  71. $("#blog_tools_widget_items_container_<?php echo $widget->getGUID(); ?> #elgg-object-" + active).show();
  72. $("#blog_tools_widget_items_navigator_<?php echo $widget->getGUID(); ?> span").click(function(){
  73. $("#blog_tools_widget_items_navigator_<?php echo $widget->getGUID(); ?> span.active").removeClass("active");
  74. $(this).addClass("active");
  75. $("#blog_tools_widget_items_container_<?php echo $widget->getGUID(); ?> .elgg-item").hide();
  76. var active = $(this).attr("rel");
  77. $("#blog_tools_widget_items_container_<?php echo $widget->getGUID(); ?> #elgg-object-" + active).show();
  78. });
  79. setInterval (rotateBlogItems<?php echo $widget->getGUID(); ?>, 10000);
  80. });
  81. </script>
  82. <?php
  83. } else {
  84. echo $blogs;
  85. }
  86. } else {
  87. echo elgg_echo("blog:noblogs");
  88. }
  89. // restore context
  90. elgg_pop_context();