Ejemplo n.º 1
0
    $html_content = '<div class="list-group snippet-list">';
    foreach ($results as $row) {
        $html_content .= '<a href="view_snippet.php?id=' . $row['id'] . '" class="list-group-item"><span class="snippet-title">' . $row['name'] . '</span> <span class="label ' . get_category_color($row['category_tag']) . '">' . get_category_title($row['category_tag']) . '</span> &middot; <span class="created-date">updated ' . get_timeago($row['updated_time']) . '</span></a>';
    }
    $html_content .= '</div>';
} else {
    // empty cat
    $html_content = 'Oops.. you don\'t have any snippet saved here yet. Why not <a href="add_snippet.php">submit one</a>?';
}
$query2 = "SELECT * FROM " . DBTABLE_SNIPPETS . " WHERE user_id='" . $user_loggedin_id . "' AND visibility='private'";
$total_found2 = $db->num_rows($query2);
if ($total_found2 > 0) {
    $results2 = $db->get_results($query2);
    $html_content2 = '<div class="list-group snippet-list">';
    foreach ($results2 as $row2) {
        $html_content2 .= '<a href="view_snippet.php?id=' . $row2['id'] . '" class="list-group-item"><span class="snippet-title">' . $row2['name'] . '</span> <span class="label ' . get_category_color($row2['category_tag']) . '">' . get_category_title($row2['category_tag']) . '</span> &middot; <span class="created-date">updated ' . get_timeago($row2['updated_time']) . '</span></a>';
    }
    $html_content2 .= '</div>';
} else {
    // empty cat
    $html_content2 = 'Oops.. you don\'t have any snippet saved here yet. Why not <a href="add_snippet.php">submit one</a>?';
}
$query3 = "SELECT * FROM " . DBTABLE_SNIPPETS . " WHERE user_id='" . $user_loggedin_id . "'";
$total_found3 = $db->num_rows($query3);
$html_content3 = '<div class="alert alert-info" role="alert"><span class="label label-info">INFO</span> You have <strong>' . $total_found3 . '</strong> snippets in total; <em>' . $total_found . ' public snippets</em> and <em>' . $total_found2 . ' private snippets</em>.</div>';
?>

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
Ejemplo n.º 2
0
    $authenticated = true;
}
if (isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id'])) {
    $db = DB::getInstance();
    $snippet_id = $db->filter($_GET['id']);
    $query = "SELECT user_id, category_tag, name, visibility, description, snippet, created_time, updated_time, view_count FROM " . DBTABLE_SNIPPETS . " WHERE id='" . $snippet_id . "'";
    if ($db->num_rows($query) > 0) {
        list($user_id, $category_tag, $name, $visibility, $description, $snippet, $created_time, $updated_time, $view_count) = $db->get_row($query);
        if ($visibility == 'private' && $user_id != $user_loggedin_id) {
            // Visibility is private AND logged in user is not the owner of the snippet
            header('Location: 404.php?error=user_not_owner');
        } else {
            $snippet_user_id = $user_id;
            $snippet_name = $name;
            $snippet_cat = get_category_title($category_tag);
            $snippet_cat_color = get_category_color($category_tag);
            $snippet_desc = $description;
            if ($snippet_cat == 'plain-text') {
                $snippet_output = '<div id="plainOutput"><pre class="plain"><code>' . $snippet . '</code></pre></div>';
            } else {
                $snippet_output = '<div id="codeOutput"><pre class="highlighted"><code>' . $snippet . '</code></pre></div>';
            }
            $snippet_created_time = get_timeago($created_time);
            $snippet_updated_time = get_timeago($updated_time);
            $snippet_creator = get_username($user_id);
            $snippet_view_count = $view_count + 1;
            snippet_view_increment($snippet_id, $snippet_view_count);
        }
    } else {
        // ID not found
        header('Location: 404.php?error=id_not_found');
Ejemplo n.º 3
0
                        $html_content .= '<a href="view_snippet.php?id=' . $row['id'] . '" class="list-group-item"><span class="snippet-title">' . $row['name'] . '</span><span class="by-creator"> by <strong>' . get_username($row['user_id']) . '</strong></span> &middot; <span class="created-date">' . get_timeago($row['updated_time']) . '</span></a>';
                    }
                }
            }
            $html_content .= '</div>';
        } else {
            $html_content = '<div class="alert alert-warning" role="alert"><span class="label label-warning">OOPS..</span> No available snippet found under this category.</div>';
        }
    }
} else {
    // ID not numeric
    header('Location: 404.php?error=invalid_category');
    exit;
}
$category_title = get_category_title($snippet_cat);
$category_color = get_category_color($snippet_cat);
?>

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title><?php 
echo APP_NAME;
    } else {
        $html_content = '<div class="alert alert-warning" role="alert"><span class="label label-warning">OOPS..</span> No available snippet found.</div>';
    }
} else {
    // authenticated == true
    $query = "SELECT * FROM " . DBTABLE_SNIPPETS . " ORDER BY view_count DESC LIMIT 20";
    $total_found = $db->num_rows($query);
    if ($total_found > 0) {
        $results = $db->get_results($query);
        $html_content = '<div class="list-group snippet-list">';
        foreach ($results as $row) {
            if ($row['visibility'] == 'private' && $row['user_id'] == $user_loggedin_id) {
                $html_content .= '<a href="view_snippet.php?id=' . $row['id'] . '" class="list-group-item"><span class="snippet-title">' . $row['name'] . '</span> <span class="label ' . get_category_color($row['category_tag']) . '">' . get_category_title($row['category_tag']) . '</span> &middot; <span class="by-creator"> by <strong>' . get_username($row['user_id']) . '</strong></span> &middot; <span class="created-date">updated ' . get_timeago($row['updated_time']) . '</span> &middot; <span class="view-counter">' . $row['view_count'] . ' views</span><br><span class="private-snippet"><i class="fa fa-info-circle"></i> This is your private snippet. Only you can see this!</span></a>';
            } else {
                if ($row['visibility'] == 'public') {
                    $html_content .= '<a href="view_snippet.php?id=' . $row['id'] . '" class="list-group-item"><span class="snippet-title">' . $row['name'] . '</span> <span class="label ' . get_category_color($row['category_tag']) . '">' . get_category_title($row['category_tag']) . '</span> &middot; <span class="by-creator"> by <strong>' . get_username($row['user_id']) . '</strong></span> &middot; <span class="created-date">updated ' . get_timeago($row['updated_time']) . '</span> &middot; <span class="view-counter">' . $row['view_count'] . ' views</span></a>';
                }
            }
        }
        $html_content .= '</div>';
    } else {
        $html_content = '<div class="alert alert-warning" role="alert"><span class="label label-warning">OOPS..</span> No available snippet found.</div>';
    }
}
?>

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->