PageRenderTime 67ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/system/expressionengine/models/comment_model.php

https://bitbucket.org/tdevonshire/hoolux
PHP | 146 lines | 72 code | 26 blank | 48 comment | 11 complexity | a19d807c926245ee169b5158ebfa032f MD5 | raw file
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2012, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Comment Model
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Core
  19. * @category Model
  20. * @author EllisLab Dev Team
  21. * @link http://ellislab.com
  22. */
  23. class Comment_model extends CI_Model {
  24. /**
  25. * Recount Stats for Comments
  26. *
  27. * Fetches the full data for comments
  28. *
  29. * @param array
  30. * @param array
  31. * @return array
  32. */
  33. public function recount_entry_comments($entry_ids)
  34. {
  35. foreach(array_unique($entry_ids) as $entry_id)
  36. {
  37. $query = $this->db->query("SELECT MAX(comment_date) AS max_date FROM exp_comments WHERE status = 'o' AND entry_id = '".$this->db->escape_str($entry_id)."'");
  38. $comment_date = ($query->num_rows() == 0 OR ! is_numeric($query->row('max_date') )) ? 0 : $query->row('max_date') ;
  39. $query = $this->db->query("SELECT COUNT(*) AS count FROM exp_comments WHERE entry_id = '".$this->db->escape_str($entry_id)."' AND status = 'o'");
  40. $this->db->query("UPDATE exp_channel_titles SET comment_total = '".($query->row('count') )."', recent_comment_date = '$comment_date' WHERE entry_id = '".$this->db->escape_str($entry_id)."'");
  41. }
  42. }
  43. // --------------------------------------------------------------------
  44. /**
  45. * Fetch Email Recipient Array
  46. *
  47. * @param array
  48. * @param array
  49. * @return array
  50. */
  51. public function fetch_email_recipients($entry_id, $subscriptions = array())
  52. {
  53. $recipients = array();
  54. $subscribed_members = array();
  55. $subscribed_emails = array();
  56. // No subscribers - skip!
  57. if (count($subscriptions))
  58. {
  59. // Do some work to figure out the user's name,
  60. // either based on their user id or on the comment
  61. // data (stored with their email)
  62. $subscription_map = array();
  63. foreach($subscriptions as $id => $row)
  64. {
  65. if ($row['member_id'])
  66. {
  67. $subscribed_members[] = $row['member_id'];
  68. $subscription_map[$row['member_id']] = $id;
  69. }
  70. else
  71. {
  72. $subscribed_emails[] = $row['email'];
  73. $subscription_map[$row['email']] = $id;
  74. }
  75. }
  76. if (count($subscribed_members))
  77. {
  78. $this->db->select('member_id, email, screen_name, smart_notifications');
  79. $this->db->where_in('member_id', $subscribed_members);
  80. $member_q = $this->db->get('members');
  81. if ($member_q->num_rows() > 0)
  82. {
  83. foreach ($member_q->result() as $row)
  84. {
  85. $sub_id = $subscription_map[$row->member_id];
  86. if ($row->smart_notifications == 'n' OR $subscriptions[$sub_id]['notification_sent'] == 'n')
  87. {
  88. $recipients[] = array($row->email, $sub_id, $row->screen_name);
  89. }
  90. }
  91. }
  92. }
  93. // Get all comments by these subscribers so we can grab their names
  94. if (count($subscribed_emails))
  95. {
  96. $this->db->select('DISTINCT(email), name, entry_id');
  97. $this->db->where('status', 'o');
  98. $this->db->where('entry_id', $entry_id);
  99. $this->db->where_in('email', $subscribed_emails);
  100. $comment_q = $this->db->get('comments');
  101. if ($comment_q->num_rows() > 0)
  102. {
  103. foreach ($comment_q->result() as $row)
  104. {
  105. $sub_id = $subscription_map[$row->email];
  106. $recipients[] = array($row->email, $sub_id, $row->name);
  107. }
  108. }
  109. }
  110. unset($subscription_map);
  111. }
  112. // Mark it as unread
  113. // if smart notifications are turned on, will
  114. // will prevent further emails from being sent
  115. $this->subscription->mark_as_unread(array($subscribed_members, $subscribed_emails), TRUE);
  116. return $recipients;
  117. }
  118. }
  119. /* End of file comment_model.php */
  120. /* Location: ./system/expressionengine/modules/comment/models/comment_model.php */