Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
LikeWidget.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  */
10 
11 $request = Yii::app()->request;
12 ?>
13 <div class="like-widget" id="like_widget_<?php echo $model->content_id;?>">
14  <a name="lw<?php echo $model->content_id;?>"></a>
15  <?php
16  if (Yii::app()->user->isGuest) {
17  if (!$this->isPreview) {
18  echo CHtml::link('<span>' . LikeModule::t('Log in to Like') . '</span>', Yii::app()->createUrl('/like/like/login', array('return_url' => Yii::app()->request->getRequestUri() . '#lw' . $model->content_id)), array('class' => 'likebutton'));
19  } else {
20  echo CHtml::link('<span>' . LikeModule::t('Log in to Like') . '</span>', Yii::app()->createUrl(''), array('class' => 'likebutton'));
21  }
22  } else {
23  ?>
24  <?php if ($hasLiked) { ?>
25  <a href="javascript:;" class="likebutton like_href"
26  id="like_href_<?php echo $model->content_id;?>"><span><?php echo LikeModule::t('Unlike'); ?></span></a>
27  <?php } else { ?>
28  <a href="javascript:;" class="likebutton like_href"
29  id="like_href_<?php echo $model->content_id;?>"><span><?php echo LikeModule::t('Like'); ?></span></a>
30  <?php } ?>
31  <?php } ?>
32 
33  <span class="top_likes_container" id="top_likes_container_<?php echo $model->content_id;?>">
34  <?php
35  if ($model->topLikesQty > 0 && count($model->likes) > 0) {
36  $topLikes = array();
37  for ($i = 0; $i < $model->topLikesQty && $i < count($model->likes); $i++) {
38  if (isset($model->likes[$i]->profile)
39  && $model->likes[$i]->profile->user_id == Yii::app()->user->id) {
40  $topLikes[] = LikeModule::t('You');
41  } elseif (isset($model->likes[$i]->profile)
42  && ($name = trim($model->likes[$i]->profile->firstname.' '.$model->likes[$i]->profile->lastname))) {
43  $topLikes[] = $name;
44  } else {
45  $topLikes[] = LikeModule::t('Noname');
46  }
47  }
48  echo implode(', ', $topLikes);
49  }
50  ?>
51  </span>
52 
53  <a href="javascript:;" class="and_others_container" id="and_others_container_<?php echo $model->content_id;?>"
54  style="display:<?php echo (count($model->likes) > $model->topLikesQty) ? '' : 'none'?>;">
55  <?php
56  if (count($model->likes) > $model->topLikesQty) {
57  echo LikeModule::t('and') . ' ' . ($model->likesQty - $model->topLikesQty) . ' ' . LikeModule::t('others like this');
58  }
59  ?>
60  </a>
61 
62  <div class="last_likes_overlay" id="last_likes_overlay_<?php echo $model->content_id;?>">
63  <?php if ($model->lastLikesQty > 0 && (count($model->likes) - $model->topLikesQty) > 0) { ?>
64  <?php
65  $lastLikes = array();
66  for ($i = $model->topLikesQty; $i < ($model->topLikesQty + $model->lastLikesQty) && $i < count($model->likes); $i++) {
67  if (isset($model->likes[$i]->profile) && is_object($model->likes[$i]->profile) && is_object($model->likes[$i]->profile->firstname) && is_object($model->likes[$i]->profile->lastname)
68  && (trim($model->likes[$i]->profile->firstname) != '' && trim($model->likes[$i]->profile->lastname) != '')) {
69  $lastLikes[] = $model->likes[$i]->profile->firstname . ' ' . $model->likes[$i]->profile->lastname;
70  } else {
71  $lastLikes[] = LikeModule::t('Noname');
72  }
73  }
74 
75  if (count($model->likes) > ($model->topLikesQty + $model->lastLikesQty)) {
76  $lastLikes[] = LikeModule::t('And others...');
77  }
78 
79  echo implode('<br/>', $lastLikes);
80  }
81  ?>
82  </div>
83 </div>
84 <?php
85 if (!$this->isPreview) {
86  ?>
87 <script type="text/javascript">
88  $(document).ready(function () {
89  likeButton({
90  url:"<?php echo Yii::app()->createUrl('/like/like'); ?>",
91  contentId:"<?php echo $model->content_id;?>",
92  el:$('#like_href_<?php echo $model->content_id;?>'),
93  topLikesContainer:$('#top_likes_container_<?php echo $model->content_id;?>'),
94  andOthersContainer:$('#and_others_container_<?php echo $model->content_id;?>'),
95  lastLikesContainer:$('#last_likes_overlay_<?php echo $model->content_id;?>'),
96  hiddenFields: <?php echo CJSON::encode($request->enableCsrfValidation ? array($request->csrfTokenName => $request->getCsrfToken()) : array())?>
97  });
98 
99  toggleButton({
100  el:$('#and_others_container_<?php echo $model->content_id;?>'),
101  overlay:$('#last_likes_overlay_<?php echo $model->content_id;?>')
102  });
103  });
104 </script>
105 <?php
106 }
107 ?>