Пример #1
0
<?php

if (isset($threads_list) && sizeof($threads_list) > 0) {
    ?>

    <div class="threads_header">
        <span class="thread-logo"></span>
        <span id="threads_header-label">®Last_discussions®</span>
    </div>
    <div class="threads_list">
        <?php 
    $DTZ = new DateTimeZone('Europe/Paris');
    foreach ($threads_list as $thread) {
        if ($thread['studentOnly'] == '0' || $thread['studentOnly'] == '1' && !acl_has_moderated_album() || acl_is_admin()) {
            $editDate = get_lang() == 'fr' ? new DateTimeFrench($thread['lastEditDate'], $DTZ) : new DateTime($thread['lastEditDate'], $DTZ);
            $editDateVerbose = get_lang() == 'fr' ? $editDate->format('j F Y à H\\hi') : $editDate->format("F j, Y, g:i a");
            //@TODO go to real asset
            $meth_to_call = 'javascript:show_thread(\'' . $thread['albumName'] . '\', \'' . $thread['assetName'] . '\', \'' . $thread['timecode'] . '\', ' . $thread['id'] . ', \'\')';
            ?>
                <div class="item-thread">
                    <div onclick="<?php 
            echo $meth_to_call;
            ?>
">
                        <div class="item-thread-content" >
                                                            <?php 
            if ($thread['studentOnly'] == '1') {
                ?>
                                <img src="images/Generale/visibility-students.png" title="®Visibility_students®" class="visibility"/>
                                <?php 
            } else {
Пример #2
0
                    </label>
                    <div id="thread_description_wrapper">
                        <input type="text" name="description" tabindex='20' id="thread_desc_tinymce" required/>
                    </div>

                    <!-- Visibility field --> 
                    <input name="visibility" id="thread_visibility" type="checkbox" hidden/>
                    <br/>
                    <!-- Submit button -->
                    <div class="cancelButton" style="margin-left: 480px;">
                        <a class="button" tabindex='21' href="javascript: hide_thread_form(true);">®Cancel®</a>
                    </div>
                    <div class="submitButton">
                        <a class="button green2" tabindex='22' 
                        <?php 
if (!acl_has_moderated_album() || acl_is_admin()) {
    echo "data-reveal-id='modal_thread_visibility_choice'";
} else {
    echo "href='javascript:if(check_thread_form()) submit_thread_form()' ";
}
?>
                           >®Post_discussion®</a>
                    </div>
                </form>
            </div>
        </div>
        <div class="video_controls">
            <ul>
                <?php 
if ($playbackRate) {
    ?>
Пример #3
0
function thread_search($words, $fields, $albums, $asset = '')
{
    global $db_object;
    // set $relevancy to true if the result is aimed to be sorted by relevancy.
    // With $relevancy = false, as soon as a word is found in any of the fields,
    // we stop the search and check for the next discussion.
    // With $relevancy = true, we search for every words in every fields and
    // give a score to each discussion, according to certain rules.
    $relevancy = true;
    if (count($fields) <= 0) {
        return null;
    }
    if (count($albums) <= 0) {
        return null;
    }
    $albums_in_query = implode(',', array_fill(0, count($albums), '?'));
    $where_base = 'WHERE ' . 'albumName IN (' . $albums_in_query . ') ' . (isset($asset) && $asset != '' ? ' AND assetName LIKE ' . $db_object->quote("%{$asset}%") . ' ' : ' ') . (acl_has_moderated_album() && !acl_is_admin() ? ' AND studentOnly = 0 ' : ' ') . 'AND c.deleted = 0 ';
    if (in_array('title', $fields)) {
        // search in threads titles
        if (count($words) > 0) {
            $where = $where_base . 'AND ( ';
            foreach ($words as $index => $word) {
                if ($index > 0) {
                    $where .= ' OR ';
                }
                $where .= 'title LIKE ' . $db_object->quote("%" . $word . "%") . ' ';
            }
            $where .= ') ';
        }
        /*
         * SELECT DISTINCT ... FROM threads
         * WHERE albumName IN ( ' ... ' )  <-- selection of albums
         * AND assetName LIKE '%$asset%' <-- if $asset != ''
         * AND studentOnly == 0 <-- if user is a teacher
         * AND deleted != 1
         * AND (title LIKE '%$word[i]%' OR title LIKE '%word[i+1]%' ...)
         * GROUP BY albumName, assetName, id;
         */
        $stmt = 'SELECT DISTINCT id, title, message, timecode, albumName, assetName, assetTitle, studentOnly ' . 'FROM ' . db_gettable('threads') . ' c ' . $where . 'GROUP BY albumName, assetName, id';
        $prepared_stmt = $db_object->prepare($stmt);
        $prepared_stmt->execute($albums);
        $result_threads = $prepared_stmt->fetchAll(PDO::FETCH_ASSOC);
    }
    if (in_array('message', $fields)) {
        // search in threads messages and comments
        if (count($words) > 0) {
            $where = $where_base . 'AND ( ';
            foreach ($words as $index => $word) {
                if ($index > 0) {
                    $where .= ' OR ';
                }
                $where .= 'c.message LIKE ' . $db_object->quote("%" . $word . "%") . ' ';
            }
            $where .= ') ';
        }
        /*
         * SELECT DISTINCT ... FROM threads
         * WHERE albumName IN ( ' ... ' )  <-- selection of albums
         * AND assetName LIKE '%$asset%' <-- if $asset != ''
         * AND studentOnly == 0 <-- if user is a teacher
         * AND deleted != 1
         * AND (message LIKE '%$word[i]%' OR message LIKE '%word[i+1]%' ...)
         * GROUP BY albumName, assetName, id;
         */
        $stmt = 'SELECT DISTINCT id, title, message, timecode, albumName, assetName, assetTitle, studentOnly ' . 'FROM ' . db_gettable('threads') . ' c ' . $where . 'GROUP BY albumName, assetName, id';
        $prepared_stmt = $db_object->prepare($stmt);
        $prepared_stmt->execute($albums);
        $result_messages = $prepared_stmt->fetchAll(PDO::FETCH_ASSOC);
        /*
         * SELECT DISTINCT ... FROM comments c
         * JOIN threads t ON ...
         * WHERE albumName IN ( ' ... ' )  <-- selection of albums
         * AND assetName LIKE '%$asset%' <-- if $asset != ''
         * AND studentOnly == 0 <-- if user is a teacher
         * AND c.deleted != 1
         * AND (c.message LIKE '%$word[i]%' OR c.message LIKE '%word[i+1]%' ...)
         * AND t.deleted != 1
         * GROUP BY albumName, assetName, id;
         */
        $stmt = 'SELECT DISTINCT thread, title, c.message, t.message as thread_message, timecode, albumName, assetName, assetTitle, c.id, studentOnly ' . 'FROM ' . db_gettable('comments') . ' c ' . 'JOIN ' . db_gettable('threads') . ' t on c.thread = t.id ' . $where . ' AND t.deleted = 0 ' . 'GROUP BY albumName, assetName, t.id, c.id';
        $prepared_stmt = $db_object->prepare($stmt);
        $prepared_stmt->execute($albums);
        $result_comments = $prepared_stmt->fetchAll(PDO::FETCH_ASSOC);
    }
    // we have now 1/2/3 arrays (depending on fields 'title' and 'message')
    // $result_threads contains all threads where one of the words is in the title
    // $result_messages contains all threads where one of the words is in the message
    // $result_comments contains all the comments where one of the words is in the message
    $threads_array = array();
    // loop on threads that contain at least one word in the title
    foreach ($result_threads as $thread) {
        $score = 0;
        if ($relevancy) {
            foreach ($words as $word) {
                // search the word in the title
                $offset = stripos($thread['title'], $word);
                if ($offset !== false) {
                    // the word has been found, we increment the score
                    $last_index = $offset + strlen($word);
                    $score++;
                    // there is nothing before and/or after the word, we increment the score
                    if ($offset == 0) {
                        $score++;
                    }
                    if ($last_index == strlen($thread['title'])) {
                        $score++;
                    }
                    if ($offset > 0 && $thread['title'][$offset - 1] == ' ') {
                        $score++;
                    }
                    if ($last_index < strlen($thread['title']) && $thread['title'][$last_index] == ' ') {
                        $score++;
                    }
                    // There are multiple occurences of the word, we increment the score
                    $count = substr_count(strtoupper($thread['title']), strtoupper($word));
                    if ($count > 1) {
                        $score += ($count - 1) * 2;
                    }
                }
            }
            $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['score'] = $score;
        }
        $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['title'] = $thread['title'];
        $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['message'] = $thread['message'];
        $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['timecode'] = $thread['timecode'];
        $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['comments'] = array();
    }
    // loop on thread that contain at least one word in message
    foreach ($result_messages as $thread) {
        $score = 0;
        if ($relevancy) {
            foreach ($words as $word) {
                // search the word in the message
                $offset = stripos($thread['message'], $word);
                if ($offset !== false) {
                    // the word has been found, we increment the score
                    $last_index = $offset + strlen($word);
                    $score++;
                    // there is nothing before and/or after the word, we increment the score
                    if ($offset == 0) {
                        $score++;
                    }
                    if ($last_index == strlen($thread['message'])) {
                        $score++;
                    }
                    if ($offset > 0 && $thread['message'][$offset - 1] == ' ') {
                        $score++;
                    }
                    if ($last_index < strlen($thread['message']) && $thread['message'][$last_index] == ' ') {
                        $score++;
                    }
                    // There are multiple occurences of the word, we increment the score
                    $count = substr_count(strtoupper($thread['message']), strtoupper($word));
                    if ($count > 1) {
                        $score += ($count - 1) * 2;
                    }
                }
            }
        }
        if (isset($threads_array[$thread['albumName']][$thread['assetName']][$thread['id']])) {
            // updates the score of the thread
            if ($relevancy) {
                $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['score'] += $score;
            }
        } else {
            if ($relevancy) {
                $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['score'] = $score;
            }
            $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['title'] = $thread['title'];
            $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['message'] = $thread['message'];
            $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['timecode'] = $thread['timecode'];
            $threads_array[$thread['albumName']][$thread['assetName']][$thread['id']]['comments'] = array();
        }
    }
    // loop on comments that contain at least one word
    foreach ($result_comments as $thread_comment) {
        $score = 0;
        if ($relevancy) {
            foreach ($words as $word) {
                // search the word in the message
                $offset = stripos($thread_comment['message'], $word);
                if ($offset !== false) {
                    // the word has been found, we increment the score
                    $last_index = $offset + strlen($word);
                    $score++;
                    // there is nothing before and/or after the word, we increment the score
                    if ($offset == 0) {
                        $score++;
                    }
                    if ($last_index == strlen($thread_comment['message'])) {
                        $score++;
                    }
                    if ($offset > 0 && $thread_comment['message'][$offset - 1] == ' ') {
                        $score++;
                    }
                    if ($last_index < strlen($thread_comment['message']) && $thread_comment['message'][$last_index] == ' ') {
                        $score++;
                    }
                    // There are multiple occurences of the word, we increment the score
                    $count = substr_count(strtoupper($thread_comment['message']), strtoupper($word));
                    if ($count > 1) {
                        $score += ($count - 1) * 2;
                    }
                }
            }
        }
        // the thread is already in the list
        if (isset($threads_array[$thread_comment['albumName']][$thread_comment['assetName']][$thread_comment['thread']])) {
            // updates the score of the thread
            if ($relevancy) {
                $threads_array[$thread_comment['albumName']][$thread_comment['assetName']][$thread_comment['thread']]['score'] += $score;
            }
            $threads_array[$thread_comment['albumName']][$thread_comment['assetName']][$thread_comment['thread']]['comments'][$thread_comment['id']] = $thread_comment['message'];
        } else {
            if ($relevancy) {
                $threads_array[$thread_comment['albumName']][$thread_comment['assetName']][$thread_comment['thread']]['score'] = $score;
            }
            $threads_array[$thread_comment['albumName']][$thread_comment['assetName']][$thread_comment['thread']]['title'] = $thread_comment['title'];
            $threads_array[$thread_comment['albumName']][$thread_comment['assetName']][$thread_comment['thread']]['message'] = $thread_comment['thread_message'];
            $threads_array[$thread_comment['albumName']][$thread_comment['assetName']][$thread_comment['thread']]['timecode'] = $thread_comment['timecode'];
            $threads_array[$thread_comment['albumName']][$thread_comment['assetName']][$thread_comment['thread']]['comments'][$thread_comment['id']] = $thread_comment['message'];
        }
    }
    return $threads_array;
}