public function actionLike()
 {
     $user_id = Yii::app()->user->id;
     if (Yii::app()->request->isAjaxRequest && !empty($user_id)) {
         $tbl = Yii::app()->getRequest()->getPost('_tbl');
         $item_id = Yii::app()->getRequest()->getPost('_item_id');
         $hash = md5($tbl . $item_id . $user_id);
         $likesObj = Likes::model()->find('hash=:_hash', array(':_hash' => $hash));
         if (empty($likesObj->id)) {
             $likesObj = new Likes();
             $likesObj->tbl = $tbl;
             $likesObj->item_id = $item_id;
             $likesObj->user_id = $user_id;
             $likesObj->hash = $hash;
             $likesObj->save();
             Yii::app()->db->createCommand("UPDATE {$tbl} SET likes=likes+1 WHERE id=" . intval($item_id))->execute();
             echo json_encode(array('status' => 'ok', 'data' => 'like'));
         } else {
             $likesObj->delete();
             Yii::app()->db->createCommand("UPDATE {$tbl} SET likes=likes-1 WHERE id=" . intval($item_id))->execute();
             echo json_encode(array('status' => 'ok', 'data' => 'unlike'));
         }
     } else {
         throw new CException('Not Found', 404);
     }
 }
Example #2
0
 public static function getUserAttributes($comments, $session_user)
 {
     foreach ($comments as $comment) {
         $comment->username = User::getUsernameById($comment->user_id);
         $comment->likecount = Likes::countLike($comment->id);
         $comment->is_author = $comment->isAuthor($session_user);
         $comment->is_liked = Likes::isLiked($comment->id, $session_user);
     }
 }
Example #3
0
 public function like()
 {
     if (Input::has("post_id")) {
         $post_id = explode("_", Input::get("post_id"));
         //Find if user already liked the post
         if (Likes::where("post_id", $post_id[1])->where("user_id", "1")->count() > 0) {
             Likes::where("post_id", $post_id[1])->where("user_id", "1")->delete();
             return Response::json(array("result" => "1", "isunlike" => "0", "text" => "Like"));
         } else {
             $like = new Likes();
             //We are using hardcoded user id for now , in production change
             //it to Sentry::getId() if using Sentry for authentication
             $like->user_id = "1";
             $like->post_id = $post_id[1];
             $like->save();
             return Response::json(array("result" => "1", "isunlike" => "1", "text" => "unlike"));
         }
         return Response::json(array("result" => "1", "isunlike" => "1", "text" => "unlike"));
     } else {
         //No post id no access sorry
         return Response::json(array("result" => "0"));
     }
 }
Example #4
0
 public function action_like()
 {
     if (Auth::guest()) {
         return;
     }
     $imageID = Input::get('imageid');
     $userID = Auth::user()->id;
     Likes::add($imageID, $userID);
     Images::incrementLikes($imageID);
     if (Request::ajax()) {
         return Response::json(array('success' => true));
     } else {
         return Redirect::to('home');
     }
 }
 public function like()
 {
     $thread_id = Param::get('thread_id');
     $comment_id = Param::get('comment_id');
     $process = Param::get('process');
     $user_id = get_authenticated_user_id($_SESSION['userid']);
     switch ($process) {
         case self::METHOD_LIKE:
             Likes::setLike($comment_id, $user_id);
             break;
         case self::METHOD_UNLIKE:
             Likes::unsetLike($comment_id, $user_id);
             break;
         default:
             redirect(NOT_FOUND_PAGE);
     }
     redirect(VIEW_COMMENT_PAGE, array('thread_id' => $thread_id));
 }
Example #6
0
 /**
  * Display the specified resource.
  *
  * @param  int  $itemId
  * @param string $key
  * @return Response
  */
 public function show($itemId, $key)
 {
     //
     $retVal = array('status' => 'ERR', 'msg' => 'Invalid Session');
     try {
         $user = \Member::where('session_key', '=', $key)->exists();
         if (!$user) {
             return Response::json($retVal);
         }
         $like = \Likes::where('itemid', '=', $itemId)->get();
         if ($like->count() > 0) {
             $retVal = array('status' => 'OK', 'count' => $like->count(), 'itemid' => $itemId, 'itemtype' => $like[0]->itemtype);
         } else {
             $retVal = array('status' => 'ERR', 'msg' => 'beyond your imagination :)');
         }
         return Response::json($retVal);
     } catch (ModelNotFoundException $e) {
     }
 }
Example #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLikes()
 {
     return $this->hasMany(Likes::className(), ['FK_service_id' => 'id']);
 }
 function get_comment($comment_id, $context)
 {
     global $blog_id;
     $comment = get_comment($comment_id);
     if (!$comment || is_wp_error($comment)) {
         return new WP_Error('unknown_comment', 'Unknown comment', 404);
     }
     $types = array('', 'comment', 'pingback', 'trackback');
     if (!in_array($comment->comment_type, $types)) {
         return new WP_Error('unknown_comment', 'Unknown comment', 404);
     }
     $post = get_post($comment->comment_post_ID);
     if (!$post || is_wp_error($post)) {
         return new WP_Error('unknown_post', 'Unknown post', 404);
     }
     $status = wp_get_comment_status($comment->comment_ID);
     // Permissions
     switch ($context) {
         case 'edit':
             if (!current_user_can('edit_comment', $comment->comment_ID)) {
                 return new WP_Error('unauthorized', 'User cannot edit comment', 403);
             }
             $GLOBALS['post'] = $post;
             $comment = get_comment_to_edit($comment->comment_ID);
             foreach (array('comment_author', 'comment_author_email', 'comment_author_url') as $field) {
                 $comment->{$field} = htmlspecialchars_decode($comment->{$field}, ENT_QUOTES);
             }
             break;
         case 'display':
             if ('approved' !== $status) {
                 $current_user_id = get_current_user_id();
                 $user_can_read_coment = false;
                 if ($current_user_id && $comment->user_id && $current_user_id == $comment->user_id) {
                     $user_can_read_coment = true;
                 } elseif ($comment->comment_author_email && $comment->comment_author && isset($this->api->token_details['user']) && isset($this->api->token_details['user']['user_email']) && $this->api->token_details['user']['user_email'] === $comment->comment_author_email && $this->api->token_details['user']['display_name'] === $comment->comment_author) {
                     $user_can_read_coment = true;
                 } else {
                     $user_can_read_coment = current_user_can('edit_comment', $comment->comment_ID);
                 }
                 if (!$user_can_read_coment) {
                     return new WP_Error('unauthorized', 'User cannot read unapproved comment', 403);
                 }
             }
             $GLOBALS['post'] = $post;
             setup_postdata($post);
             break;
         default:
             return new WP_Error('invalid_context', 'Invalid API CONTEXT', 400);
     }
     $can_view = $this->user_can_view_post($post->ID);
     if (!$can_view || is_wp_error($can_view)) {
         return $can_view;
     }
     $GLOBALS['comment'] = $comment;
     $response = array();
     foreach (array_keys($this->comment_object_format) as $key) {
         switch ($key) {
             case 'ID':
                 // explicitly cast all output
                 $response[$key] = (int) $comment->comment_ID;
                 break;
             case 'post':
                 $response[$key] = (object) array('ID' => (int) $post->ID, 'title' => (string) get_the_title($post->ID), 'type' => (string) $post->post_type, 'link' => (string) $this->links->get_post_link($this->api->get_blog_id_for_output(), $post->ID));
                 break;
             case 'author':
                 $response[$key] = (object) $this->get_author($comment, 'edit' === $context && current_user_can('edit_comment', $comment->comment_ID));
                 break;
             case 'date':
                 $response[$key] = (string) $this->format_date($comment->comment_date_gmt, $comment->comment_date);
                 break;
             case 'URL':
                 $response[$key] = (string) esc_url_raw(get_comment_link($comment->comment_ID));
                 break;
             case 'short_URL':
                 // @todo - pagination
                 $response[$key] = (string) esc_url_raw(wp_get_shortlink($post->ID) . "%23comment-{$comment->comment_ID}");
                 break;
             case 'content':
                 if ('display' === $context) {
                     ob_start();
                     comment_text();
                     $response[$key] = (string) ob_get_clean();
                 } else {
                     $response[$key] = (string) $comment->comment_content;
                 }
                 break;
             case 'status':
                 $response[$key] = (string) $status;
                 break;
             case 'parent':
                 // (object|false)
                 if ($comment->comment_parent) {
                     $parent = get_comment($comment->comment_parent);
                     $response[$key] = (object) array('ID' => (int) $parent->comment_ID, 'type' => (string) ($parent->comment_type ? $parent->comment_type : 'comment'), 'link' => (string) $this->links->get_comment_link($blog_id, $parent->comment_ID));
                 } else {
                     $response[$key] = false;
                 }
                 break;
             case 'type':
                 $response[$key] = (string) ($comment->comment_type ? $comment->comment_type : 'comment');
                 break;
             case 'like_count':
                 if (defined('IS_WPCOM') && IS_WPCOM) {
                     $response[$key] = (int) $this->api->comment_like_count($blog_id, $post->ID, $comment->comment_ID);
                 }
                 break;
             case 'i_like':
                 if (defined('IS_WPCOM') && IS_WPCOM) {
                     $response[$key] = (bool) Likes::comment_like_current_user_likes($blog_id, $comment->comment_ID);
                 }
                 break;
             case 'meta':
                 $response[$key] = (object) array('links' => (object) array('self' => (string) $this->links->get_comment_link($this->api->get_blog_id_for_output(), $comment->comment_ID), 'help' => (string) $this->links->get_comment_link($this->api->get_blog_id_for_output(), $comment->comment_ID, 'help'), 'site' => (string) $this->links->get_site_link($this->api->get_blog_id_for_output()), 'post' => (string) $this->links->get_post_link($this->api->get_blog_id_for_output(), $comment->comment_post_ID), 'replies' => (string) $this->links->get_comment_link($this->api->get_blog_id_for_output(), $comment->comment_ID, 'replies/'), 'likes' => (string) $this->links->get_comment_link($this->api->get_blog_id_for_output(), $comment->comment_ID, 'likes/')));
                 break;
         }
     }
     unset($GLOBALS['comment'], $GLOBALS['post']);
     return $response;
 }
Example #9
0
{
	CIBlockPriceTools::setRatioMinPrice($arResult, true);
}

if (!empty($arResult['DISPLAY_PROPERTIES']))
{
	foreach ($arResult['DISPLAY_PROPERTIES'] as $propKey => $arDispProp)
	{
		if ('F' == $arDispProp['PROPERTY_TYPE'])
			unset($arResult['DISPLAY_PROPERTIES'][$propKey]);
	}
}

$arResult['SKU_PROPS'] = $arSKUPropList;
$arResult['DEFAULT_PICTURE'] = $arEmptyPreview;

$arResult['wish']['isWished'] = CIBlockElement::GetList(false, array(
	'IBLOCK_ID' => 23,
	'ACTIVE' => 'Y',
	'PROPERTY_OBJECT' => $arResult['ID']
	), false, false, array('ID'))->SelectedRowsCount();

CBitrixComponent::includeComponentClass("component.model:likes");
$objElement = new CIBlockElement;
$likes = new Likes(1);

$arResult['likes']['already_liked'] = $likes->isLikedByCurrent($arResult['ID']);
$arResult['likes']['value'] = $likes->count($arResult['ID']);


?>
Example #10
0
File: like.php Project: ASDAFF/mp
<?php

require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php";
CModule::IncludeModule('iblock');
CBitrixComponent::includeComponentClass("component.model:likes");
$objElement = new CIBlockElement();
$likes = new Likes($_POST['ib']);
$like = $likes->isLikedByCurrent($_POST['element']);
if (false === $like) {
    $result['plus'] = true;
    $hash = md5($_SERVER['REMOTE_ADDR']);
    $x = $objElement->Add(array('IBLOCK_ID' => 17, 'NAME' => 'Like', 'ACTIVE' => 'Y', 'PROPERTY_VALUES' => array('IP' => $_SERVER['REMOTE_ADDR'], 'HASH' => $hash, 'OBJECT_ID' => $_POST['element'], 'IBLOCK_ID' => $_POST['ib'], 'USER' => $USER->GetId())));
    \setcookie('muchmore-blog-like', $hash);
} else {
    $result['plus'] = false;
    $objElement->Delete($like);
    unset($_COOKIE['muchmore-blog-like']);
}
$result['val'] = $likes->count($_POST['element']);
echo json_encode($result);
Example #11
0
File: API.php Project: writyfy/app
                     $likes = new Likes($r['ID']);
                     $array1['Likes'] = $likes->getLikes();
                     $rows[] = $array1;
                 }
                 print json_encode($rows);
             }
             break;
         default:
             $user = new CurrentUser();
             if (isset($_COOKIE['ID']) && $user->isLoggedIn()) {
                 $mysql_connection = mysqli_connect($DBurl, $DBusername, $DBpassword, $DBname);
                 $result = mysqli_query($mysql_connection, "SELECT * FROM books WHERE UserID = '" . mysqli_real_escape_string($mysql_connection, $_COOKIE['ID']) . "' ORDER BY RAND()");
                 $rows = array();
                 while ($r = mysqli_fetch_array($result)) {
                     $array1 = $r;
                     $likes = new Likes($r['ID']);
                     $array1['Likes'] = $likes->getLikes();
                     $rows[] = $array1;
                 }
                 print json_encode($rows);
             }
             break;
     }
 } else {
     if (is_numeric($data2)) {
         $mysql_connection = mysqli_connect($DBurl, $DBusername, $DBpassword, $DBname);
         $result = mysqli_query($mysql_connection, "SELECT * FROM books WHERE UserID = '" . mysqli_real_escape_string($mysql_connection, $data2) . "' ORDER BY RAND()");
         $rows = array();
         while ($r = mysqli_fetch_array($result)) {
             $rows[] = $r;
         }