Пример #1
0
 function action_toggle($input)
 {
     global $user, $tikilib, $prefs, $artlib;
     if (!$user) {
         throw new Services_Exception(tr('Must be authenticated'), 403);
     }
     $type = $input->type->none();
     $object = $input->object->none();
     $target = $input->target->int();
     if (!$type || !$object) {
         throw new Services_Exception(tr('Invalid input'), 400);
     }
     $relationlib = TikiLib::lib('relation');
     $relations = $this->action_list($input);
     if ($target) {
         if (!in_array("{$type}:{$object}", $relations) && ($relationId = $relationlib->add_relation('tiki.user.favorite', 'user', $user, $type, $object))) {
             $relations[$relationId] = "{$type}:{$object}";
             TikiLib::lib('tiki')->refresh_index($type, $object);
         }
     } else {
         foreach ($relations as $id => $key) {
             if ($key === "{$type}:{$object}") {
                 $relationlib->remove_relation($id);
                 unset($relations[$id]);
                 TikiLib::lib('tiki')->refresh_index($type, $object);
             }
         }
     }
     if ($prefs['feature_score'] == 'y' && $target) {
         if ($type == 'forum post') {
             require_once 'lib/comments/commentslib.php';
             $commentslib = new Comments();
             $forum_id = $commentslib->get_comment_forum_id($object);
             $forum_info = $commentslib->get_forum($forum_id);
             $thread_info = $commentslib->get_comment($object, null, $forum_info);
             $item_user = $thread_info['userName'];
         } elseif ($type == 'article') {
             require_once 'lib/articles/artlib.php';
             $artlib = new ArtLib();
             $res = $artlib->get_article($object);
             $item_user = $res['author'];
         }
         $tikilib->score_event($user, 'item_favorited', "{$type}:{$object}");
         $tikilib->score_event($item_user, 'item_is_favorited', "{$user}:{$type}:{$object}");
     }
     return array('list' => $relations);
 }
Пример #2
0
function smarty_function_rating($params, $smarty)
{
    global $prefs, $ratinglib;
    require_once 'lib/rating/ratinglib.php';
    if (!isset($params['type'], $params['id'])) {
        return tra('No object information provided for rating.');
    }
    $type = $params['type'];
    $id = $params['id'];
    if (isset($params['changemandated']) && $params['changemandated'] == 'y') {
        $changemandated = true;
        // needed to fix multiple submission problem in comments
    } else {
        $changemandated = false;
    }
    if (isset($_REQUEST['rating_value'][$type][$id], $_REQUEST['rating_prev'][$type][$id])) {
        $value = $_REQUEST['rating_value'][$type][$id];
        $prev = $_REQUEST['rating_prev'][$type][$id];
        if ((!$changemandated || $value != $prev) && $ratinglib->record_vote($type, $id, $value)) {
            // Handle type-specific actions
            if ($type == 'comment') {
                global $user;
                require_once 'lib/comments/commentslib.php';
                if ($user) {
                    $commentslib = new Comments();
                    $commentslib->vote_comment($id, $user, $value);
                }
            } elseif ($type == 'article') {
                global $artlib, $user;
                require_once 'lib/articles/artlib.php';
                if ($user) {
                    $artlib->vote_comment($id, $user, $value);
                }
            }
            if ($prefs['feature_score'] == 'y' && $id) {
                global $tikilib;
                if ($type == 'comment') {
                    $forum_id = $commentslib->get_comment_forum_id($id);
                    $forum_info = $commentslib->get_forum($forum_id);
                    $thread_info = $commentslib->get_comment($id, null, $forum_info);
                    $item_user = $thread_info['userName'];
                } elseif ($type == 'article') {
                    require_once 'lib/articles/artlib.php';
                    $artlib = new ArtLib();
                    $res = $artlib->get_article($id);
                    $item_user = $res['author'];
                }
                if ($value == '1') {
                    $tikilib->score_event($item_user, 'item_is_rated', "{$user}:{$type}:{$id}");
                } elseif ($value == '2') {
                    $tikilib->score_event($item_user, 'item_is_unrated', "{$user}:{$type}:{$id}");
                }
            }
        } elseif ($value != $prev) {
            return tra('An error occurred.');
        }
    }
    $vote = $ratinglib->get_vote($type, $id);
    $options = $ratinglib->get_options($type, $id);
    if ($prefs['rating_smileys'] == 'y') {
        $smiles = $ratinglib->get_options_smiles($type, $id);
        $smarty->assign('rating_smiles', $smiles);
    }
    $smarty->assign('rating_type', $type);
    $smarty->assign('rating_id', $id);
    $smarty->assign('rating_options', $options);
    $smarty->assign('current_rating', $vote);
    return $smarty->fetch('rating.tpl');
}