functions.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * All helper functions can be found here
  4. *
  5. */
  6. /**
  7. * Remove the icon of a blog
  8. *
  9. * @param ElggBlog $blog The blog to remove the icon from
  10. *
  11. * @return bool
  12. */
  13. function blog_tools_remove_blog_icon(ElggBlog $blog) {
  14. $result = false;
  15. if (!empty($blog) && elgg_instanceof($blog, "object", "blog", "ElggBlog")) {
  16. if (!empty($blog->icontime)) {
  17. $icon_sizes = elgg_get_config("icon_sizes");
  18. if (!empty($icon_sizes)) {
  19. $fh = new ElggFile();
  20. $fh->owner_guid = $blog->getOwnerGUID();
  21. $prefix = "blogs/" . $blog->getGUID();
  22. foreach ($icon_sizes as $name => $info) {
  23. $fh->setFilename($prefix . $name . ".jpg");
  24. if ($fh->exists()) {
  25. $fh->delete();
  26. }
  27. }
  28. }
  29. unset($blog->icontime);
  30. $result = true;
  31. } else {
  32. $result = true;
  33. }
  34. }
  35. return $result;
  36. }
  37. /**
  38. * Check a plugin setting for the allowed use of advanced publication options
  39. *
  40. * @return bool
  41. */
  42. function blog_tools_use_advanced_publication_options() {
  43. static $result;
  44. if (!isset($result)) {
  45. $result = false;
  46. $setting = elgg_get_plugin_setting("advanced_publication", "blog_tools");
  47. if ($setting == "yes") {
  48. $result = true;
  49. }
  50. }
  51. return $result;
  52. }
  53. /**
  54. * Get related blogs to this blog
  55. *
  56. * @param ElggBlog $entity the blog to relate to
  57. * @param int $limit number of blogs to return
  58. *
  59. * @return bool|ElggBlog[]
  60. */
  61. function blog_tools_get_related_blogs(ElggBlog $entity, $limit = 4) {
  62. $result = false;
  63. $limit = sanitise_int($limit, false);
  64. if (!empty($entity) && elgg_instanceof($entity, "object", "blog")) {
  65. // transform to values
  66. $tag_values = $entity->tags;
  67. if (!empty($tag_values)) {
  68. if (!is_array($tag_values)) {
  69. $tag_values = array($tag_values);
  70. }
  71. // find blogs with these metadatavalues
  72. $options = array(
  73. "type" => "object",
  74. "subtype" => "blog",
  75. "metadata_name" => "tags",
  76. "metadata_values" => $tag_values,
  77. "wheres" => array("(e.guid <> " . $entity->getGUID() . ")"),
  78. "group_by" => "e.guid",
  79. "order_by" => "count(msn.id) DESC",
  80. "limit" => $limit
  81. );
  82. $result = elgg_get_entities_from_metadata($options);
  83. }
  84. }
  85. return $result;
  86. }