function repButtons($member, $data = array())
 {
     $IPBHTML = "";
     if (IPSLib::locationHasHooks('skin_global_other', $this->_funcHooks['repButtons'])) {
         $count_fbe0dd9307850715511aba5ed44b249a = is_array($this->functionData['repButtons']) ? count($this->functionData['repButtons']) : 0;
         $this->functionData['repButtons'][$count_fbe0dd9307850715511aba5ed44b249a]['member'] = $member;
         $this->functionData['repButtons'][$count_fbe0dd9307850715511aba5ed44b249a]['data'] = $data;
     }
     // Apps can set the key empty to disable, but this will allow all apps to use the popup to show who repped
     if (!isset($data['jsCallback'])) {
         $data['jsCallback'] = "ipb.global.repPopUp( this, {$data['primaryId']}, '{$data['app']}', '{$data['type']}' );";
     }
     $repClickable = ($this->memberData['gbw_view_reps'] and $data['jsCallback']) ? 'onclick="' . $data['jsCallback'] . '"' : '';
     $this->templateVars['repClickable'] = "";
     $this->__default__templateVars['repClickable'] = "";
     if ($this->memberData['gbw_view_reps']) {
         $this->templateVars['repClickable'] = " clickable";
     } else {
         $this->templateVars['repClickable'] = $this->__default__templateVars['repClickable'];
     }
     $IPBHTML .= "" . ($this->settings['reputation_enabled'] ? "" . (!($this->settings['reputation_protected_groups'] && in_array($member['member_group_id'], explode(',', $this->settings['reputation_protected_groups']))) ? "" . ($this->settings['reputation_point_types'] == 'like' ? "<div class='ipsLikeBar right clearfix' id='{$data['domCountId']}'>\n                                <ul class='ipsList_inline'>\n                                        " . ((!isset($data['hide_text']) or !$data['hide_text']) ? "<li id=\"{$data['domLikeStripId']}\" class='ipsLikeBar_info' " . (!$data['likeFormatted'] ? "style=\"display:none\"" : "") . ">\n                                                        {$data['likeFormatted']}\n                                                </li>" : "") . "\n                                        " . (IPSMember::canGiveRep($data, $member) !== false && $this->memberData['member_id'] ? "<li " . (IPSMember::canRepUp($data, $member) === false ? "style=\"display:none\"" : "") . ">\n                                                        <a class='ipsLikeButton ipsLikeButton_enabled rep_up' href='{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}' title='{$this->lang->words['do_like_up']}'>{$this->lang->words['like_this']}</a>\n                                                </li>\n                                                <li " . (IPSMember::canRepDown($data, $member) === false ? "style=\"display:none\"" : "") . ">\n                                                        <a class='ipsLikeButton ipsLikeButton_disabled rep_down' href='{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=-1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}' title='{$this->lang->words['do_like_down']}'>{$this->lang->words['unlike_this']}</a>\n                                                </li>" : "") . "\n                                </ul>\n                        </div>" : "<div class='rep_bar clearfix " . (!$data['position'] || $data['position'] == 'right' ? "right" : "") . "' id='{$data['domCountId']}'>\n                                                                \n                                        " . (IPSMember::canGiveRep($data, $member) !== false && $this->memberData['member_id'] ? "\n<div class=\"orate-btns\">\n                                               <span>\n                                                        <a href='{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}' class='rep_up' title='{$this->lang->words['reputation_up']}' >" . $this->registry->getClass('output')->getReplacement("rep_up") . "</a>\n                                                        <a href='{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=-1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}' class='rep_down' title='{$this->lang->words['reputation_down']}' >" . $this->registry->getClass('output')->getReplacement("rep_down") . "</a>\n                                                </span>\n                                                </div>\n                                       " : "") . "\n\n                                        " . ($this->settings['reputation_point_types'] != 'like' ? "" . ($data['rep_points'] == 0 ? "\n                                                        <span class='reputation2 zero2 rep_show" . $this->templateVars["repClickable"] . "' title='{$this->lang->words['reputation']}' {$repClickable}>\n                                                " : "") . "\n                                                " . ($data['rep_points'] > 0 ? "\n                                                        <span class='reputation2 positive2 rep_show" . $this->templateVars["repClickable"] . "' title='{$this->lang->words['reputation']}' {$repClickable}>\n                                                " : "") . "\n                                                " . ($data['rep_points'] < 0 ? "\n                                                        <span class='reputation2 negative2 rep_show" . $this->templateVars["repClickable"] . "' title='{$this->lang->words['reputation']}' {$repClickable}>\n                                                " : "") . "\n                                                       " . intval($data['rep_points']) . "\n                                                        </span>" : "") . "\n</div>") . "" : "") . "" : "") . "\n<script type='text/javascript'>\n        ipb.global.registerReputation( '{$data['domCountId']}', { domLikeStripId: '{$data['domLikeStripId']}', app: '{$data['app']}', type: '{$data['type']}', typeid: '{$data['primaryId']}' }, parseInt('{$data['rep_points']}') );\n</script>";
     return $IPBHTML;
 }
 function repButtons($member, $data = array())
 {
     $IPBHTML = "";
     if (IPSLib::locationHasHooks('skin_global_other', $this->_funcHooks['repButtons'])) {
         $count_8e591a6dcb26abac222befba44cac8db = is_array($this->functionData['repButtons']) ? count($this->functionData['repButtons']) : 0;
         $this->functionData['repButtons'][$count_8e591a6dcb26abac222befba44cac8db]['member'] = $member;
         $this->functionData['repButtons'][$count_8e591a6dcb26abac222befba44cac8db]['data'] = $data;
     }
     $IPBHTML .= "" . ($this->settings['reputation_enabled'] ? "" . (!($this->settings['reputation_protected_groups'] && in_array($member['member_group_id'], explode(',', $this->settings['reputation_protected_groups']))) ? "" . ($this->settings['reputation_point_types'] == 'like' ? "<ul class='ipsList_inline post_rep'>\n\t\t\t\t<li " . (IPSMember::canRepUp($data, $member) === false ? "style=\"display:none\"" : "") . " >\n\t\t\t\t\t<a class='ipsLikeButton ipsLikeButton_enabled rep_up' href='{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}' title='{$this->lang->words['reputation_up']}'>{$this->lang->words['like_this']}</a>\n\t\t\t\t</li>\n\t\t\t\t<li " . (IPSMember::canRepDown($data, $member) === false ? "style=\"display:none\"" : "") . " >\n\t\t\t\t\t<a class='ipsLikeButton ipsLikeButton_disabled rep_down'  href='{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=-1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}' title='{$this->lang->words['reputation_down']}'>{$this->lang->words['unlike_this']}</a>\n\t\t\t\t</li>\n\t\t\t</ul>" : "<ul class='ipsList_inline post_rep'>\n\t\t\t\t" . (IPSMember::canGiveRep($data, $member) !== false ? "<li " . (IPSMember::canRepUp($data, $member) === false ? "style=\"display:none\"" : "") . ">\n\t\t\t\t\t\t<a href='{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}' class='rep_up' title='{$this->lang->words['reputation_up']}'>" . $this->registry->getClass('output')->getReplacement("rep_up") . "</a>\n\t\t\t\t\t</li>\n\t\t\t\t\t<li " . (IPSMember::canRepDown($data, $member) === false ? "style=\"display:none\"" : "") . ">\n\t\t\t\t\t\t<a href='{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=-1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}' class='rep_down' title='{$this->lang->words['reputation_down']}'>" . $this->registry->getClass('output')->getReplacement("rep_down") . "</a>\n\t\t\t\t\t</li>" : "") . "\n\t\t\t</ul>") . "" : "") . "" : "") . "";
     return $IPBHTML;
 }
 /**
  * Adds a rating to the index
  *
  * @return	@e void
  */
 protected function _doRating()
 {
     /* INIT */
     $app = $this->request['app_rate'];
     $type = $this->request['type'];
     $type_id = intval($this->request['type_id']);
     $rating = intval($this->request['rating']);
     /* Check */
     if (!$app || !$type || !$type_id || !$rating) {
         $this->returnString($this->lang->words['ajax_incomplete_data']);
     }
     /* Get the rep library */
     $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . 'sources/classes/class_reputation_cache.php', 'classReputationCache');
     $repCache = new $classToLoad();
     /* Add the rating */
     if ($repCache->addRate($type, $type_id, $rating, '', 0, $app) !== false) {
         $formatted = $repCache->getLikeFormatted(array('id' => $type_id, 'app' => $app, 'type' => $type));
         $current = $repCache->getCurrentMemberRating(array('id' => $type_id, 'app' => $app, 'type' => $type, 'memberId' => $this->memberData['member_id']));
         $rating = $repCache->getCurrentRating(array('id' => $type_id, 'app' => $app, 'type' => $type));
         $this->returnJsonArray(array('status' => 'ok', 'rating' => $rating, 'likeData' => $formatted, 'canRepUp' => IPSMember::canRepUp($current, $this->memberData), 'canRepDown' => IPSMember::canRepDown($current, $this->memberData)));
     } else {
         if ($repCache->error_message) {
             $this->returnJsonError($repCache->error_message);
         }
         $this->returnString('done');
     }
 }
 function repButtons($member, $data = array())
 {
     $IPBHTML = "";
     if (IPSLib::locationHasHooks('skin_global_other', $this->_funcHooks['repButtons'])) {
         $count_13530034eaab611754789dc47e2536e3 = is_array($this->functionData['repButtons']) ? count($this->functionData['repButtons']) : 0;
         $this->functionData['repButtons'][$count_13530034eaab611754789dc47e2536e3]['member'] = $member;
         $this->functionData['repButtons'][$count_13530034eaab611754789dc47e2536e3]['data'] = $data;
     }
     $IPBHTML .= "" . ((!($this->settings['reputation_protected_groups'] && in_array($member['member_group_id'], explode(',', $this->settings['reputation_protected_groups']))) and $this->memberData['member_id']) ? "" . ($this->settings['reputation_point_types'] == 'like' ? "" . (IPSMember::canGiveRep($data, $member) !== false ? "" . (IPSMember::canRepUp($data, $member) !== false ? "\n\t\t\t\t<likeURL><![CDATA[{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}]]></likeURL>\n\t\t\t" : "") . "" : "") . "" : "" . (IPSMember::canGiveRep($data, $member) !== false ? "\n\t\t\t<repupURL><![CDATA[{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}]]></repupURL>\n\t\t" : "") . "\n\t\t" . (IPSMember::canRepDown($data, $member) !== false ? "\n\t\t\t<repDownURL><![CDATA[{$this->settings['base_url']}app=core&amp;module=global&amp;section=reputation&amp;do=add_rating&amp;app_rate={$data['app']}&amp;type={$data['type']}&amp;type_id={$data['primaryId']}&amp;rating=-1&amp;secure_key={$this->member->form_hash}&amp;post_return={$data['primaryId']}]]></repDownURL>\n\t\t" : "") . "") . "" : "") . "";
     return $IPBHTML;
 }
 /**
  * Adds a rating to the index and updates caches
  *
  * @access	public
  * @param	string		$type		Type of content, ex; Post
  * @param	integer		$type_id	ID of the type, ex: pid
  * @param	integer		$rating		Either 1 or -1
  * @param	string		$message	Message associated with this rating
  * @param	integer		$member_id	Id of the owner of the content being rated
  * @param	string		[$app]		App for this content, by default the current application
  * @todo 	[Future] Move forum notifications to an onRep memberSync callback
  * @return	bool
  */
 public function addRate($type, $type_id, $rating, $message = '', $member_id = 0, $app = '')
 {
     $this->registry->getClass('class_localization')->loadLanguageFile(array('public_global'), 'core');
     /* Online? */
     if (!$this->rep_system_on) {
         $this->error_message = $this->lang->words['reputation_offline'];
         return false;
     }
     /* INIT */
     $app = $app ? $app : ipsRegistry::$current_application;
     $rating = intval($rating);
     if (!$this->memberData['member_id']) {
         $this->error_message = $this->lang->words['reputation_guest'];
         return false;
     }
     if ($rating != -1 && $rating != 1) {
         $this->error_message = $this->lang->words['reputation_invalid'];
         return false;
     }
     /* Does the rep item exist? */
     if (!$this->likeItemExists($app, $type, $type_id)) {
         /* See ticket #845557 - item may not exist when not in LIKE mode. Need to add functionalty so each app can return boolean if item exists in native tables */
         //$this->error_message = $this->lang->words['reputation_invalid'];
         //return false;
     }
     /* Check for existing rating */
     $currentRating = $this->getCurrentMemberRating(array('app' => $app, 'type' => $type, 'id' => $type_id, 'memberId' => $this->memberData['member_id']));
     /* Check the point types */
     if ($rating == -1 && IPSMember::canRepDown($currentRating, $this->memberData) === false) {
         $this->error_message = $this->lang->words['reputation_invalid'];
         return false;
     }
     if ($rating == 1 && IPSMember::canRepUp($currentRating, $this->memberData) === false) {
         $this->error_message = $this->lang->words['reputation_invalid'];
         return false;
     }
     /* Day Cutoff */
     $day_cutoff = time() - 86400;
     /* Check Max Positive Votes */
     if ($rating == 1) {
         if (intval($this->memberData['g_rep_max_positive']) === 0) {
             $this->error_message = $this->lang->words['reputation_quota_pos'];
             return false;
         }
         $total = $this->DB->buildAndFetch(array('select' => 'count(*) as votes', 'from' => 'reputation_index', 'where' => 'member_id=' . $this->memberData['member_id'] . ' AND rep_rating=1 AND rep_date > ' . $day_cutoff));
         if ($total['votes'] >= $this->memberData['g_rep_max_positive']) {
             $this->error_message = $this->lang->words['reputation_quota_pos'];
             return false;
         }
     }
     /* Check Max Negative Votes if not like mode */
     if ($rating == -1 and !$this->isLikeMode()) {
         if (intval($this->memberData['g_rep_max_negative']) === 0) {
             $this->error_message = $this->lang->words['reputation_quota_neg'];
             return false;
         }
         $total = $this->DB->buildAndFetch(array('select' => 'count(*) as votes', 'from' => 'reputation_index', 'where' => 'member_id=' . $this->memberData['member_id'] . ' AND rep_rating=-1 AND rep_date > ' . $day_cutoff));
         if ($total['votes'] >= $this->memberData['g_rep_max_negative']) {
             $this->error_message = $this->lang->words['reputation_quota_neg'];
             return false;
         }
     }
     /* If no member id was passed in, we have to query it using the config file */
     if (!$member_id) {
         /* Reputation Config */
         if (is_file(IPSLib::getAppDir($app) . '/extensions/reputation.php')) {
             $rep_author_config = array();
             require IPSLib::getAppDir($app) . '/extensions/reputation.php';
             /*maybeLibHook*/
         } else {
             $this->error_message = $this->lang->words['reputation_config'];
             return false;
         }
         if (!$rep_author_config[$type]['column'] || !$rep_author_config[$type]['table']) {
             $this->error_message = $this->lang->words['reputation_config'];
             return false;
         }
         $_col = $rep_author_config[$type]['id_field'] ? $rep_author_config[$type]['id_field'] : $type;
         /* Query the content author */
         $content_author = $this->DB->buildAndFetch(array('select' => "{$rep_author_config[$type]['column']} as id", 'from' => $rep_author_config[$type]['table'], 'where' => "{$_col}={$type_id}"));
         $member_id = $content_author['id'];
     }
     if (!ipsRegistry::$settings['reputation_can_self_vote'] && $member_id == $this->memberData['member_id']) {
         $this->error_message = $this->lang->words['reputation_yourown'];
         return false;
     }
     /* Query the member group */
     if (ipsRegistry::$settings['reputation_protected_groups']) {
         $member_group = $this->DB->buildAndFetch(array('select' => 'member_group_id', 'from' => 'members', 'where' => "member_id={$member_id}"));
         if (in_array($member_group['member_group_id'], explode(',', ipsRegistry::$settings['reputation_protected_groups']))) {
             $this->error_message = $this->lang->words['reputation_protected'];
             return false;
         }
     }
     /* Build the insert array */
     $db_insert = array('member_id' => $this->memberData['member_id'], 'app' => $app, 'type' => $type, 'type_id' => $type_id, 'rep_date' => time(), 'rep_msg' => $message, 'rep_rating' => $rating);
     /* Insert */
     if ($currentRating) {
         if ($rating == -1 && $this->isLikeMode()) {
             $this->DB->delete('reputation_index', "app='{$app}' AND type='{$type}' AND type_id={$type_id} AND member_id=" . $this->memberData['member_id']);
         }
     } else {
         $this->DB->replace('reputation_index', $db_insert, array('app', 'type', 'type_id', 'member_id'));
     }
     /* Update cache */
     $this->updateCache($app, $type, $type_id);
     /* Get authors current rep */
     $author_points = $this->DB->buildAndFetch(array('select' => 'pp_reputation_points', 'from' => 'profile_portal', 'where' => "pp_member_id=" . intval($member_id)));
     /* Figure out new rep */
     if ($currentRating['rep_rating'] == -1) {
         $author_points['pp_reputation_points'] += 1;
     } else {
         if ($currentRating['rep_rating'] == 1) {
             $author_points['pp_reputation_points'] -= 1;
         }
     }
     /* now add on new rating if we're not like mode-ing */
     if (!$this->isLikeMode() || empty($currentRating['rep_rating']) && $this->isLikeMode()) {
         $author_points['pp_reputation_points'] += $rating;
     }
     $this->DB->update('profile_portal', array('pp_reputation_points' => $author_points['pp_reputation_points']), "pp_member_id={$member_id}");
     /* Notification */
     if ($rating == 1 && $this->isLikeMode() && $app == 'forums' && $type == 'pid') {
         /* Check for class_forums */
         if (!$this->registry->isClassLoaded('class_forums')) {
             $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('forums') . "/sources/classes/forums/class_forums.php", 'class_forums', 'forums');
             $this->registry->setClass('class_forums', new $classToLoad($this->registry));
             $this->registry->strip_invisible = 0;
             $this->registry->class_forums->forumsInit();
         }
         $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . '/sources/classes/member/notifications.php', 'notifications');
         $notifyLibrary = new $classToLoad($this->registry);
         if (!$this->registry->isClassLoaded('topics')) {
             $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('forums') . "/sources/classes/topics.php", 'app_forums_classes_topics', 'forums');
             $this->registry->setClass('topics', new $classToLoad($this->registry));
         }
         $post = $this->registry->getClass('topics')->getPostById($type_id);
         /* Set topic data */
         $this->registry->getClass('topics')->setTopicData($post);
         /* Quick check */
         if (!$post['author_id'] or $post['author_id'] == $this->memberData['member_id']) {
             return true;
         }
         $_toMember = IPSMember::load($post['author_id']);
         /* Set language */
         $_toMember['language'] = $_toMember['language'] == "" ? IPSLib::getDefaultLanguage() : $_toMember['language'];
         /* Quick permission check */
         if ($this->registry->getClass('topics')->canView() !== true) {
             return true;
         }
         $url = $this->registry->output->buildSEOUrl("showtopic={$post['topic_id']}&amp;view=findpost&amp;p={$post['pid']}", "publicNoSession", $post['title_seo'], 'showtopic');
         IPSText::getTextClass('email')->getTemplate("new_likes", $_toMember['language']);
         IPSText::getTextClass('email')->buildMessage(array('MEMBER_NAME' => $this->memberData['members_display_name'], 'SHORT_POST' => IPSText::truncate(IPSText::getTextClass('bbcode')->stripAllTags($post['post']), 300), 'URL' => $url));
         IPSText::getTextClass('email')->subject = sprintf(IPSText::getTextClass('email')->subject, $this->registry->output->buildSEOUrl('showuser='******'member_id'], 'publicNoSession', $this->memberData['members_seo_name'], 'showuser'), $this->memberData['members_display_name'], $url, $this->registry->output->buildSEOUrl("showtopic={$post['topic_id']}", "publicNoSession", $post['title_seo'], 'showtopic'), IPSText::truncate($post['topic_title'], 30));
         $notifyLibrary->setMember($_toMember);
         $notifyLibrary->setFrom($this->memberData);
         $notifyLibrary->setNotificationKey('new_likes');
         $notifyLibrary->setNotificationUrl($url);
         $notifyLibrary->setNotificationText(IPSText::getTextClass('email')->message);
         $notifyLibrary->setNotificationTitle(IPSText::getTextClass('email')->subject);
         try {
             $notifyLibrary->sendNotification();
         } catch (Exception $e) {
         }
     }
     return true;
 }