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 ($model->likes[$i]->profile->user_id == Yii::app()->user->id) {
39  $topLikes[] = LikeModule::t('You');
40  } else {
41  if (trim($model->likes[$i]->profile->firstname) != '' || trim($model->likes[$i]->profile->lastname) != '') {
42  $topLikes[] = $model->likes[$i]->profile->firstname . ' ' . $model->likes[$i]->profile->lastname;
43  } else {
44  $topLikes[] = LikeModule::t('Noname');
45  }
46  }
47  }
48 
49  echo implode(', ', $topLikes);
50  }
51  ?>
52  </span>
53 
54  <a href="javascript:;" class="and_others_container" id="and_others_container_<?php echo $model->content_id;?>"
55  style="display:<?php echo (count($model->likes) > $model->topLikesQty) ? '' : 'none'?>;">
56  <?php
57  if (count($model->likes) > $model->topLikesQty) {
58  echo LikeModule::t('and') . ' ' . ($model->likesQty - $model->topLikesQty) . ' ' . LikeModule::t('others like this');
59  }
60  ?>
61  </a>
62 
63  <div class="last_likes_overlay" id="last_likes_overlay_<?php echo $model->content_id;?>">
64  <?php if ($model->lastLikesQty > 0 && (count($model->likes) - $model->topLikesQty) > 0) { ?>
65  <?php
66  $lastLikes = array();
67  for ($i = $model->topLikesQty; $i < ($model->topLikesQty + $model->lastLikesQty) && $i < count($model->likes); $i++) {
68 
69  if (trim($model->likes[$i]->profile->firstname) != '' || trim($model->likes[$i]->profile->lastname) != '') {
70  $lastLikes[] = $model->likes[$i]->profile->firstname . ' ' . $model->likes[$i]->profile->lastname;
71  } else {
72  $lastLikes[] = LikeModule::t('Noname');
73  }
74  }
75 
76  if (count($model->likes) > ($model->topLikesQty + $model->lastLikesQty)) {
77  $lastLikes[] = LikeModule::t('And others...');
78  }
79 
80  echo implode('<br/>', $lastLikes);
81  }
82  ?>
83  </div>
84 </div>
85 <?php
86 if (!$this->isPreview) {
87  ?>
88 <script type="text/javascript">
89  $(document).ready(function () {
90  likeButton({
91  url:"<?php echo Yii::app()->createUrl('/like/like'); ?>",
92  contentId:"<?php echo $model->content_id;?>",
93  el:$('#like_href_<?php echo $model->content_id;?>'),
94  topLikesContainer:$('#top_likes_container_<?php echo $model->content_id;?>'),
95  andOthersContainer:$('#and_others_container_<?php echo $model->content_id;?>'),
96  lastLikesContainer:$('#last_likes_overlay_<?php echo $model->content_id;?>'),
97  hiddenFields: <?php echo CJSON::encode($request->enableCsrfValidation ? array($request->csrfTokenName => $request->getCsrfToken()) : array())?>
98  });
99 
100  toggleButton({
101  el:$('#and_others_container_<?php echo $model->content_id;?>'),
102  overlay:$('#last_likes_overlay_<?php echo $model->content_id;?>')
103  });
104  });
105 </script>
106 <?php
107 }
108 ?>