Example #1
0
function discussions_fetch($options)
{
    /*
    		if(644314 == $_SESSION['login']['id'])
    		{
    			echo '<h5>discussions_fetch(), $options:</h5>';
    			preint_r($options);
    		}
    */
    $options['include_deleted'] = isset($options['include_deleted']) ? $options['include_deleted'] : false;
    $options['order'] = is_array($options['order']) ? $options['order'] : array(array('field' => 'id', 'direction' => 'desc'));
    $options['limit'] = is_numeric($options['limit']) ? $options['limit'] : DISCUSSIONS_DEFAULT_LIMIT;
    $options['offset'] = is_numeric($options['offset']) ? $options['offset'] : 0;
    $options['filter'] = isset($options['filter']) ? is_array($options['filter']) ? $options['filter'] : array($options['filter']) : array();
    /*
    		//generate filterquality_min
    		unset($options['filter_ids']);
    		if(in_array('popular', $options['filter']))
    		{
    			//todo! Denna verkar inte alls fungera! Testa noga
    			//Följande filtrerar ut diskussioner med många inlägg senaste timmarna.
    			$factor = 1 - (date('G')%3)/8;  //todo! denna rad skall nog justeras mot slottiderna...
    			$today = date('Y-m-d');
    			$query = 'SELECT discussion_id FROM discussion_statistics WHERE date = "' . $today . 
    								'" AND slot = "' . discussions_slot_get() . '" ORDER BY posts + (posts_pre /"' . $factor . '")';
    			$result = mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
    			if($data = mysql_fetch_assoc($result))
    			{
    				$options['filter_ids'][] = $data['discussion_id'];
    			}
    		}
    		if(in_array('visited', $options['filter']))
    		{
    			//Only view discussions that have been visited before
    			if(login_checklogin())
    			{
    				$query = 'SELECT discussion_id FROM posts_read WHERE user_id = "' . $_SESSION['login']['id'] . '"';
    				$result = mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
    				while($data = mysql_fetch_assoc($result))
    				{
    					$options['filter_ids'][] = $data['discussion_id'];
    				}
    			}
    		}
    */
    if (isset($options['type'])) {
        $options['type'] = is_array($options['type']) ? $options['type'] : array($options['type']);
    }
    if (isset($options['tags'])) {
        $options['tags'] = is_array($options['tags']) ? $options['tags'] : array($options['tags']);
    }
    if (isset($options['id'])) {
        $options['id'] = is_array($options['id']) ? $options['id'] : array($options['id']);
    }
    if (isset($options['id_exclude'])) {
        $options['id_exclude'] = is_array($options['id_exclude']) ? $options['id_exclude'] : array($options['id_exclude']);
    }
    if (isset($options['handle'])) {
        $options['handle'] = is_array($options['handle']) ? $options['handle'] : array($options['handle']);
    }
    if (isset($options['parent_discussion'])) {
        $options['parent_discussion'] = is_array($options['parent_discussion']) ? $options['parent_discussion'] : array($options['parent_discussion']);
    }
    $select_posts_read = login_checklogin() ? ', pr.posts AS read_posts, (d.posts - pr.posts) AS unread_posts' : '';
    $from_posts_read = login_checklogin() ? ' LEFT JOIN posts_read AS pr ON (pr.user_id = "' . $_SESSION['login']['id'] . '" AND pr.discussion_id = d.id)' : '';
    $query = 'SELECT DISTINCT d.id, d.*' . $select_posts_read . ', p.timestamp AS last_post_timestamp, l.username AS author_username, t.label AS category_tag, t.handle AS category_handle';
    $query .= ' FROM discussions AS d' . $from_posts_read . ', posts AS p, login AS l, tags AS t';
    $query .= isset($options['tags']) ? ', tags AS ts, object_tags AS ot' : '';
    $query .= ' WHERE p.id = d.last_post AND l.id = d.author AND t.id = d.category_tag';
    $query .= $options['include_deleted'] ? '' : ' AND d.deleted = "0"';
    $query .= isset($options['time_min']) ? ' AND d.timestamp >= "' . $options['time_min'] . '"' : '';
    $query .= isset($options['time_max']) ? ' AND d.timestamp <= "' . $options['time_max'] . '"' : '';
    $query .= isset($options['quality_min']) ? ' AND d.quality_rank >= "' . $options['quality_min'] . '"' : '';
    $query .= isset($options['quality_max']) ? ' AND d.quality_rank <= "' . $options['quality_max'] . '"' : '';
    $query .= isset($options['author']) ? ' AND d.author = "' . $options['author'] . '"' : '';
    $query .= isset($options['type']) ? ' AND d.discussion_type IN("' . implode('", "', $options['type']) . '")' : '';
    $query .= isset($options['handle']) ? ' AND d.handle IN("' . implode('", "', $options['handle']) . '")' : '';
    $query .= isset($options['parent_discussion']) ? ' AND d.parent_discussion IN("' . implode('", "', $options['parent_discussion']) . '")' : '';
    $query .= isset($options['id']) ? ' AND d.id IN("' . implode('", "', $options['id']) . '")' : '';
    $query .= isset($options['id_exclude']) ? ' AND d.id NOT IN("' . implode('", "', $options['id_exclude']) . '")' : '';
    $query .= isset($options['filter_ids']) ? ' AND d.id IN("' . implode('", "', $options['filter_ids']) . '")' : '';
    $query .= isset($options['force_unread']) && login_checklogin() ? ' AND ((d.posts - pr.posts) > 0 OR pr.posts IS NULL) ' : '';
    $query .= isset($options['force_viewed']) && login_checklogin() ? ' AND (pr.posts > 0)' : '';
    $query .= isset($options['has_my_answer']) && login_checklogin() ? ' AND d.id in (SELECT DISTINCT discussion_id FROM posts WHERE author = ' . $_SESSION['login']['id'] . ')' . ' AND NOT d.author = ' . $_SESSION['login']['id'] : '';
    if (isset($options['admin_check'])) {
        $query .= ' AND ( (d.posts - d.posts_last_admin_check) > (pow(0.5, (d.quality_rank+1)*2)*120 ) OR d.posts_last_admin_check = 0 )';
    }
    if (isset($options['tags'])) {
        $query .= ' AND d.id = ot.reference_id AND ts.id = ot.tag_id AND ot.object_type = "discussion" AND';
        $query .= ' (ts.handle IN("' . implode('", "', $options['tags']) . '") OR ts.label IN("' . implode('", "', $options['tags']) . '"))';
    }
    if ($options['unread'] == 'force' && login_checklogin()) {
        $query .= ' AND (d.posts - pr.posts) > 0';
    } elseif ($opions['unread'] == 'exclude' && login_checklogin()) {
        $query .= ' AND (d.posts - pr.posts) < 1';
    }
    $query .= ' ORDER BY';
    for ($i = 0; $current = array_shift($options['order']); $i++) {
        $query .= $i != 0 ? ',' : '';
        $query .= ' ' . $current['field'] . ' ' . $current['direction'];
    }
    $query .= "\n";
    $query .= ' LIMIT ' . $options['offset'] . ', ' . $options['limit'];
    log_to_file('forum', LOGLEVEL_DEBUG, __FILE__, __LINE__, $query, '');
    /*
    		if(5 == $_SESSION['login']['userlevel'])
    		{
    			echo '<h3>fetch options: </h3>';
    			preint_r($options);
    			echo '<p>' . $query . '</p>';
    		}
    */
    /*
    		if(644314 == $_SESSION['login']['id'])
    		{
    			echo '<p>' . $query . '</p>';
    		}
    */
    $result = mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
    while ($data = mysql_fetch_assoc($result)) {
        $data['tags'] = tag_get_by_item('discussion', $data['id']);
        $data['title'] = strlen($data['title']) < 2 ? 'Diskussion utan rubrik' : $data['title'];
        $return[] = $data;
    }
    return $return;
}
Example #2
0
<?php

require '../include/core/common.php';
require PATHS_INCLUDE . 'libraries/forum.php';
// NOTE: if(false)! (This file is deprecated)
if (false) {
    if ($_GET['action'] == 'update_tags') {
        /* Remove all old tags */
        $tags = tag_get_by_item('discussion', $_GET['discussion_id']);
        foreach ($tags as $tag) {
            $tag_ids[] = $tag['tag_id'];
        }
        tag_remove($_GET['discussion_id'], 'discussion', $tag_ids);
        /* Set the new tags */
        $tags = explode(' ', str_replace(',', ' ', $_GET['tags']));
        foreach ($tags as $key => $tag) {
            $tags[$key] = trim($tag);
        }
        $tags = array_unique($tags);
        foreach ($tags as $tag_label) {
            $return = tag_exists($tag_label);
            if ($return['status'] == 'exists') {
                $set_tag_ids[] = array('tag_id' => $return['tag_id']);
            } else {
                $set_tag_ids[] = array('tag_id' => tag_create($taglabel));
            }
        }
        tag_set($_GET['discussion_id'], 'discussion', $set_tag_ids);
        // Äntligen kan vi börja sätta de nya taggarna
    }
}
Example #3
0
/**
* Draws the form where you can add or edit a film.
	$film	an array with all film data
*/
function films_admin_form_draw($film_type, $film = null, $options)
{
    rounded_corners_top();
    if (isset($film)) {
        //		preint_r($film);
        echo '<h1>Redigera film</h1>' . "\n";
    } else {
        echo '<h1>Lägg in en ny film</h1>' . "\n";
    }
    /*
    	echo '<h2>Ladda upp en filmfil:</h2>' . "\n";
    	echo '<form id="film_upload_form" method="post" target="film_upload_frame" action="/film/admin/film_upload_user.php">' . "\n";
    	echo '<input type="file" name="film_upload" />' . "\n";
    	echo '<input type="submit" class="button_80" value="Skicka" />' . "\n";
    	echo '</form>' . "\n";
    	echo '<iframe name="film_upload_frame" style="display: none;" ></iframe>' . "\n";
    */
    echo '<h2>eller klistra in länk till filmfilen:</h2>' . "\n";
    echo '<input type="text" name="fetch_link" id="film_fetch_link_input"/>' . "\n";
    echo '<button class="button_50" id="film_fetch_link_button">Skicka</button>' . "\n";
    if (isset($film)) {
        echo '<input type="checkbox" name="upload_new_file" id="upload_new_file" />' . "\n";
        echo '<label for="upload_new_file" >Uppdatera filmfilen</label>' . "\n";
    }
    echo '<div id="film_preview">' . "\n";
    echo '</div>' . "\n";
    echo '<form id="film_edit_form" method="post" action="/' . $film_type . '/admin/' . (isset($film) ? 'film_save.php' : 'film_new.php') . '" enctype="multipart/form-data">' . "\n";
    if (isset($film)) {
        echo '<input name="film_id" type="hidden" value="' . $film['id'] . '" />' . "\n";
    }
    echo '<h2>Titel</h2>' . "\n";
    echo '<input type="text" name="title" value="' . (isset($film) ? $film['title'] : '') . '" />' . "\n";
    echo '<h2>Filmtyp <strong>Byt absolut inte här, gå istället in på rätt sida!</strong></h2>' . "\n";
    $film_type = isset($film) ? $film['film_type'] : $film_type;
    echo '<input type="radio" name="film_type" value="flash" id="film_type_radio_flash" ' . ($film_type == 'flash' ? 'checked="on"' : '') . '/>' . "\n";
    echo '<label for="film_type_radio_flash">Flash</label>' . "\n";
    echo '<input type="radio" name="film_type" value="klipp" id="film_type_radio_klipp" ' . ($film_type == 'klipp' ? 'checked="on"' : '') . '/>' . "\n";
    echo '<label for="film_type_radio_klipp">Klipp</label>' . "\n";
    echo '<input type="radio" name="film_type" value="bilder" id="film_type_radio_bilder" ' . ($film_type == 'bilder' ? 'checked="on"' : '') . '/>' . "\n";
    echo '<label for="film_type_radio_bilder">Bild</label>' . "\n";
    echo '<h2>Kategori</h2>' . "\n";
    global $film_categories;
    global $film_type_categories;
    //	preint_r($film_categories);
    //	preint_r($film_type_categories[$film_type]);
    foreach ($film_type_categories[$film_type] as $category_id) {
        $categories[$category_id] = $film_categories[$category_id];
    }
    //	preint_r($categories);
    echo '<select name="film_category">' . "\n";
    foreach ($categories as $category_id => $category) {
        echo '<option value="' . $category_id . '"';
        if (isset($film) && $film['category_id'] == $category_id) {
            echo ' selected="selected"';
        }
        echo ' >' . $category['title'] . '</option>' . "\n";
    }
    echo '</select>' . "\n";
    echo '<h2>Övriga nyckelord (separerade med mellanslag)</h2>' . "\n";
    if (isset($film)) {
        unset($keywords);
        $tags = tag_get_by_item('film', $film['id']);
        foreach ($tags as $tag) {
            $keywords[] = $tag['label'];
        }
    }
    preint_r($keywords);
    echo '<textarea name="tags" rows="3" cols="60" >' . (isset($film) ? implode(' ', $keywords) : '') . '</textarea>' . "\n";
    echo '<h2>Bild (skalas och konverteras automagiskt)</h2>' . "\n";
    if (isset($film)) {
        echo '<img src="' . IMAGE_URL . '/film/' . $film['handle'] . '.png" />' . "\n";
    }
    echo '<input name="thumbnail" type="file" />' . "\n";
    echo '<h2>Release</h2>' . "\n";
    echo '<input type="text" name="release" value="' . date('Y-m-d H:i', isset($film) ? $film['release'] : schedule_release_get(array('type' => 'new_' . $film_type))) . '" />' . "\n";
    echo '<input type="checkbox" name="release_now" value="true" id="release_now_check" />' . "\n";
    echo '<label for="release_now_check">Släpp filmen direkt</label>' . "\n";
    echo '<h2>Specialkod</h2>' . "\n";
    echo '<input type="checkbox", value="true", id="chk_use_special_code" name="use_special_code" ' . (isset($film) && $film['use_special_code'] == 1 ? 'checked=checked' : '') . '/>' . "\n";
    echo '<label for="chk_use_special_code">Använd specialkod</label>' . "\n";
    echo '<textarea name="special_code" rows="5" cols="60" >' . (isset($film) ? stripslashes($film['html']) : '') . '</textarea>' . "\n";
    echo '<br />' . "\n";
    echo '<h2>Filmtrailer.se ID (rör ej om du inte vet vad detta är!)</h2>' . "\n";
    echo '<input type="text" name="trailer_id" value="' . $film['trailer_id'] . '" />' . "\n";
    echo '<input type="checkbox", value="delete" id="chk_film_delete" name="delete" />' . "\n";
    echo '<label for="chk_film_delete">Ta bort film</label>' . "\n";
    echo '<input class="button_50" type="submit" value="Spara" />' . "\n";
    echo '</form>' . "\n";
    rounded_corners_bottom();
}
Example #4
0
function posts_create($post, $options)
{
    /*
    		Required info: 
    			content
    			discussion_id
    			author
    		
    		Optional info:
    			timestamp
    */
    /*
    	$post['content'] = str_replace('(</p><p>)+', '</p><p>', $post['content']);
    	$post['content'] = str_replace('(<br />)+', '<br />', $post['content']);
    */
    if (forum_read_only_get($post['author'])) {
        echo 'Error: Användaren avstängd från forumet' . "\n";
        return false;
    }
    $post['content'] = trim($post['content']);
    $content = mysql_real_escape_string($post['content']);
    $quality_rank = text_quality_rank($post['content']);
    $spelling_grammar = text_quality_rank($post['content']);
    $post['timestamp'] = isset($post['timestamp']) ? $post['timestamp'] : time();
    $query = 'INSERT INTO posts (author, length, content, discussion_id, quality_rank, spelling_grammar, timestamp, no_smilies)';
    $query .= ' VALUES("' . $post['author'] . '", "' . strlen($post['content']) . '", "' . $post['content'] . '", "' . $post['discussion_id'];
    $query .= '", "' . $quality_rank . '", "' . $spelling_grammar . '", "' . $post['timestamp'] . '", "';
    $query .= (isset($post['no_smilies']) ? '1' : '0') . '")';
    mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
    $post_id = mysql_insert_id();
    /* Increase the post counter */
    $query = 'UPDATE discussions SET posts = posts + 1, last_post = "' . $post_id . '" WHERE id = "' . $post['discussion_id'] . '" LIMIT 1';
    mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
    if (isset($options['gb_recipient'])) {
        /* Update the "unread entries" in the remote users session */
        $query = 'SELECT session_id FROM login WHERE id = "' . $options['gb_recipient'] . '" LIMIT 1';
        $result = mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
        if (mysql_num_rows($result) == 1) {
            $data = mysql_fetch_assoc($result);
            if (strlen($data['session_id']) > 1) {
                $remote_session = session_load($data['session_id']);
                $remote_session['notices']['unread_gb_entries'] += 1;
                session_save($sessid_data['session_id'], $remote_session);
            }
        }
        /* If a private entry has been sent, set the appropriate flag */
        if ($options['private_gb'] == true) {
            $query = 'INSERT INTO flags (object_id, object_type, flag) VALUES("' . $post_id . '", "post", "private_gb")';
            mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
        }
    }
    //Parse to find answer tags
    foreach (preg_split('/\\n/', $content) as $line) {
        // find tags like: [svar:AmarsoLove=3245]
        // 					eller: [svar:Henrik]
        if (preg_match('/\\[svar:(\\w+)(=\\d+)?\\]/', $line, $matches)) {
            //Fetch user_id
            if (strtolower($matches[1]) != 'borttagen') {
                $query = 'SELECT id FROM login WHERE username = "******"';
                $result = mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
                if (mysql_num_rows($result) == 1) {
                    $data = mysql_fetch_assoc($result);
                    $receiver_id = $data['id'];
                    //Insert response notice
                    $query = 'INSERT INTO notices (user_id, post_id, type) VALUES ("' . $receiver_id . '", "' . $post_id . '", "response")';
                    mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
                }
            }
        }
    }
    //Send notices to all users listed in $options['notices']
    if (isset($options['notices'])) {
        foreach ($options['notices'] as $receiver) {
            if (strtolower($matches[1]) != 'borttagen') {
                //Fetch user_id
                $query = 'SELECT id FROM login WHERE username = "******"';
                $result = mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
                if (mysql_num_rows($result) == 1) {
                    $data = mysql_fetch_assoc($result);
                    $receiver_id = $data['id'];
                    //Insert response notice
                    $query = 'INSERT INTO notices (user_id, post_id, type) VALUES ("' . $receiver_id . '", "' . $post_id . '", "notice")';
                    log_to_file('forum', LOGLEVEL_DEBUG, __FILE__, __LINE__, 'notiser', $query);
                    mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
                }
            }
        }
    }
    //Update users quality rank
    //todo! This will require some thinking and adjustments in the future
    if (login_checklogin()) {
        $user_quality_rank = ($_SESSION['userinfo']['forum_quality_rank'] * 9 + $quality_rank) / 10;
        unset($data);
        $data['userinfo']['forum_quality_rank'] = $user_quality_rank;
        login_save_user_data($_SESSION['login']['id'], $data);
        session_merge($data);
        //Update discussion quality rank
        $query = 'SELECT quality_rank FROM posts WHERE discussion_id ="' . $post['discussion_id'] . '" ORDER BY id DESC LIMIT 30';
        $result = mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
        while ($data = mysql_fetch_assoc($result)) {
            $quality_ranks[] = $data['quality_rank'];
        }
        sort($quality_ranks);
        $discussion_quality_rank = $quality_ranks[floor(count($quality_ranks) / 2)];
        $query = 'UPDATE discussions SET quality_rank="' . $discussion_quality_rank . '" WHERE id = "' . $post['discussion_id'] . '"';
        mysql_query($query) or die(report_sql_error($query, __FILE__, __LINE__));
    }
    //Update discussion popularity
    $slot = floor(date('G') / 3);
    $slot_pre = $slot - 1;
    $date_pre = date('Y-m-d');
    if ($slot_pre < 0) {
        $slot_pre = 7;
        $date_pre = date('Y-m-d', strtotime('yesterday'));
    }
    $query_update = 'UPDATE discussion_statistics SET posts = posts + 1 WHERE discussion_id = "' . $post['discussion_id'] . '" AND date = "' . date('Y-m-d') . '" AND slot = "' . $slot . '"';
    $query_posts_pre = 'SELECT posts FROM discussion_statistics WHERE discussion_id = "' . $post['discussion_id'] . '" AND date = "' . $date_pre . '" AND slot = "' . $slot_pre . '" LIMIT 1';
    //	log_to_file('forum', LOGLEVEL_DEBUG, __FILE__, __LINE__, $post['discussion_id'] . ' ' . $slot . ' ' . $slot_pre, $query_posts_pre);
    // Update the popularity for the tags that the discussion has been tagged with.
    $tags = tag_get_by_item('discussion', $post['discussion_id']);
    foreach ($tags as $tag) {
        $query = 'UPDATE tags SET popularity = IF(popularity IS NULL, 0.05, popularity + 0.05) WHERE id = "' . $tag['tag_id'] . '" LIMIT 1';
        mysql_query($query) or die(report_sql_error($query));
    }
    $result = mysql_query($query_posts_pre);
    if ($data = mysql_fetch_assoc($result)) {
        //		log_to_file('forum', LOGLEVEL_DEBUG, __FILE__, __LINE__, $data['posts'], $query_posts_pre);
        $posts_pre = $data['posts'];
    }
    $query_insert = 'INSERT INTO discussion_statistics (discussion_id, date, slot, posts, posts_pre) VALUES ("' . $post['discussion_id'] . '", "' . date('Y-m-d') . '", "' . $slot . '", "1",' . ' "' . $posts_pre . '")';
    //	log_to_file('forum', LOGLEVEL_DEBUG, __FILE__, __LINE__, 'insert', $query_insert);
    if (mysql_query($query_insert)) {
        log_to_file('forum', LOGLEVEL_DEBUG, __FILE__, __LINE__, 'Vi körde insert!', $query_insert);
    } elseif (mysql_query($query_update)) {
        log_to_file('forum', LOGLEVEL_DEBUG, __FILE__, __LINE__, 'Vi körde update!', $query_update);
    } else {
        log_to_file('forum', LOGLEVEL_DEBUG, __FILE__, __LINE__, $query_update, $query_insert);
        exit;
    }
    $_SESSION['posts']['latest'][] = array('timestamp' => $time, 'hash' => md5($post['content']));
    return $post_id;
}