示例#1
0
文件: user.php 项目: redroot/URIKA
    function ulist()
    {
        $q_vars = get_url_vars();
        $base = base_url();
        // sort vars
        $limit = 10;
        $search = isset($q_vars->search) ? $q_vars->search : "";
        $offset = isset($q_vars->page) ? ($q_vars->page - 1) * $limit : 0;
        $order_by = isset($q_vars->order_by) ? $q_vars->order_by : "";
        $order_dir = isset($q_vars->order_dir) ? strtoupper($q_vars->order_dir) : "";
        // following vars, using the same one, let model handle it
        if (isset($q_vars->following)) {
            $following = "following_" . $q_vars->following;
        } else {
            if (isset($q_vars->followed_by)) {
                $following = "followedby_" . $q_vars->followed_by;
            } else {
                $following = "";
            }
        }
        $users = $this->user_model->getUsers($search, $offset, $limit, $following, $order_by, $order_dir);
        $table_html = "";
        if (isset($q_vars->usernotfound)) {
            $table_html .= '
				<p class="error" style="margin-bottom: 10px;">
					User <strong>' . $q_vars->usernotfound . '</strong> not found. Try searching again
				</p>
			';
        }
        // handle user feedback
        $filters_html = "";
        // no applicable q_vars
        $no_list = array("page", "usernotfound", "user_search");
        // Set up filters at the top
        if ($search != "" || isset($q_vars->following) || isset($q_vars->followed_by)) {
            $filters_html = '<ul class="search_filters user_search_filters">';
            if ($search != "") {
                $filters_html .= '<li><a href="' . $base . 'user/ulist/' . queryStringDrop("search", $no_list) . '"class="remove_filter" title="Remove this filter"><span class="hide">Remove</span></a> 
							Search results for <strong>' . $search . '</strong></li>';
            }
            if (isset($q_vars->following)) {
                $filters_html .= '<li><a href="' . $base . 'user/ulist/' . queryStringDrop("following", $no_list) . '" class="remove_filter" title="Remove this filter"><span class="hide">Remove</span></a> Showing users following <strong>' . $q_vars->following . '</strong></li>';
            }
            if (isset($q_vars->followed_by)) {
                $filters_html .= '<li><a href="' . $base . 'user/ulist/' . queryStringDrop("followed_by", $no_list) . '" class="remove_filter" title="Remove this filter"><span class="hide">Remove</span></a> Showing users followed by <strong>' . $q_vars->followed_by . '</strong></li>';
            }
            $filters_html .= '</ul>';
        }
        // now output the table
        $query_count = count($users["result"]);
        if ($users != false) {
            // work out page results text
            $showing = "";
            // so we can control what appears in the same conditional
            $show_next = true;
            $show_prev = false;
            // if a page is set
            if (isset($q_vars->page)) {
                $show_prev = true;
                $current_start = $limit * ($q_vars->page - 1) + 1;
                // determine end
                if ($limit * $q_vars->page < $users["total"]) {
                    // if there are more on the next page
                    $current_end = $limit * $q_vars->page;
                    $show_next = true;
                } else {
                    // else we dont need a previ button
                    $current_end = $users["total"];
                    $show_next = false;
                }
            } else {
                // now page, so determine when the end should say
                $current_start = 1;
                if ($users["total"] >= $limit) {
                    $current_end = $limit;
                } else {
                    $current_end = $users["total"];
                }
            }
            $showing = '<p class="showing_count">Showing <strong>' . $current_start . '</strong> - <strong>' . $current_end . '</strong> of <strong>' . $users["total"] . '</strong> user results</p>';
            $table_html .= '<table class="user_list_table">
			<tr class="top">
				<th class="username_col"><span style="color: #777;">Username</span></th>
			';
            // now we sort out the order by function
            if ($q_vars == null) {
                $table_html .= '
				<th><a href="' . $base . 'user/ulist/?order_by=images_count&amp;order_dir=DESC" title="Order by Image uploads">Uploads</a></th>
				<th><a href="' . $base . 'user/ulist/?order_by=following_count&amp;order_dir=DESC" title="Order by Following">Following</a></th>
				<th><a href="' . $base . 'user/ulist/?order_by=followed_count&amp;order_dir=DESC" title="Order by Image uploads">Followers</a></th>
				';
            } else {
                // first we do if for if there are q_vars by nothing to do with order_by
                if (!isset($q_vars->order_by)) {
                    // reset all filters an page
                    $no_list[] = "page";
                    $current_query = queryStringDrop(null, $no_list);
                    // detect the existing query
                    if ($current_query == "") {
                        $current_query .= "?";
                    } else {
                        $current_query .= "&";
                    }
                    $table_html .= '
					<th><a href="' . $base . 'user/ulist/' . $current_query . 'order_by=images_count&order_dir=DESC" title="Order by Image uploads">Uploads</a></th>
					<th><a href="' . $base . 'user/ulist/' . $current_query . 'order_by=following_count&order_dir=DESC" title="Order by Following">Following</a></th>
					<th><a href="' . $base . 'user/ulist/' . $current_query . 'order_by=followed_count&order_dir=DESC" title="Order by Image uploads">Followers</a></th>
					';
                    unset($no_list["page"]);
                } else {
                    // now we have to do with each case
                    // easiest thing is too go through each and test each one
                    // also, temp set $no_list to contain order_by and order_dir
                    // so we can set these ourselves safely
                    $no_list[] = "order_by";
                    $no_list[] = "order_dir";
                    $current_query = queryStringDrop(null, $no_list);
                    // quick check something is left in the query
                    // and append something accordinly
                    if ($current_query == "") {
                        $current_query = "?";
                    } else {
                        $current_query .= "&";
                    }
                    // set some class vars so we can just throw everything together at the end
                    $sort_classes = array("", "", "");
                    $sort_directions = array("DESC", "DESC", "DESC");
                    if ($q_vars->order_by == "images_count") {
                        $sort_classes[0] = "sort";
                        if ($q_vars->order_dir == "DESC") {
                            $sort_directions[0] = "ASC";
                        }
                    } else {
                        if ($q_vars->order_by == "following_count") {
                            $sort_classes[1] = "sort";
                            if ($q_vars->order_dir == "DESC") {
                                $sort_directions[1] = "ASC";
                            }
                        } else {
                            if ($q_vars->order_by == "followed_count") {
                                $sort_classes[2] = "sort";
                                if ($q_vars->order_dir == "DESC") {
                                    $sort_directions[2] = "ASC";
                                }
                            }
                        }
                    }
                    $table_html .= '
					<th class="' . $sort_classes[0] . '"><a href="' . $base . 'user/ulist/' . $current_query . 'order_by=images_count&order_dir=' . $sort_directions[0] . '" title="Order by Image uploads">Uploads</a></th>
					<th class="' . $sort_classes[1] . '"><a href="' . $base . 'user/ulist/' . $current_query . 'order_by=following_count&order_dir=' . $sort_directions[1] . '" title="Order by Following">Following</a></th>
					<th class="' . $sort_classes[2] . '"><a href="' . $base . 'user/ulist/' . $current_query . 'order_by=followed_count&order_dir=' . $sort_directions[2] . '" title="Order by Followed By">Followers</a></th>
					';
                    // now unset the no_list stuff
                    unset($no_list[count($no_list) - 1]);
                    unset($no_list[count($no_list) - 1]);
                }
            }
            $table_html .= '
			</tr>
			';
            for ($i = 0; $i < $query_count; $i++) {
                if ($i % 2 == 1) {
                    $class = "odd";
                } else {
                    $class = "even";
                }
                $img = getUserProfileURL($users["result"][$i]->u_profile_id, $users["result"][$i]->u_email);
                $table_html .= '<tr class="' . $class . '">
					<th class="username_col"><a href="' . $base . 'user/u/' . $users["result"][$i]->u_username . '/" title="View \'' . $users["result"][$i]->u_username . '\'s profile"><img src="' . $img . '" alt="user profile image" width="30px" height="30px" />' . $users["result"][$i]->u_username . ' <em>  - joined ' . date('F j, Y', strtotime($users["result"][$i]->u_date_joined)) . '</em></a></th>
					<td class="userlist_images">' . $users["result"][$i]->images_count . '</td>
					<td class="userlist_following"><a href="' . $base . 'user/ulist/?followed_by=' . $users["result"][$i]->u_username . '" title="See all users followed by ' . $users["result"][$i]->u_username . '">' . $users["result"][$i]->following_count . '</a></td>
					<td class="userlist_followers"><a href="' . $base . 'user/ulist/?following=' . $users["result"][$i]->u_username . '" title="See all users following by ' . $users["result"][$i]->u_username . '">' . $users["result"][$i]->followed_count . '</a></td>
				</tr>';
            }
            $table_html .= '</table>';
            $table_html .= '
			<div class="pagination_buttons">
			';
            if ($show_prev) {
                $table_html .= '<a class="pagination" href="' . $base . 'user/ulist/' . queryStringDrop(null, $no_list, -1) . '"  title="View previous page of results">< Previous</a>';
            }
            if ($show_next && $users["total"] > $limit) {
                $table_html .= '<a class="pagination"  href="' . $base . 'user/ulist/' . queryStringDrop(null, $no_list, 1) . '"  title="Viewnext page of results">Next ></a>';
            }
            $table_html .= '
			</div>
			';
        } else {
            // no results
            $table_html .= '<p class="error">No results found for these parameters</p>';
        }
        // determine some extra stuff
        // like appending existing URLs onto the search
        // query
        if ($q_vars != null) {
            $extra_params = "";
            $search_text = "Search All Users";
            if (isset($q_vars->following)) {
                $extra_params = '<input type="hidden" name="following" value="' . $q_vars->following . '" />';
                $search_text = "Search Results";
            } else {
                if (isset($q_vars->followed_by)) {
                    $extra_params = '<input type="hidden" name="followed_by" value="' . $q_vars->followed_by . '" />';
                    $search_text = "Search Results";
                }
            }
        } else {
            $search_text = "Search All Users";
            $extra_params = "";
        }
        $data = array("table_html" => $table_html, "search_text" => $search_text, "extra_params" => $extra_params, "filters_html" => $filters_html, "search" => $search);
        //now render templates
        $this->template->write("title", "User Listing");
        $this->template->write_view("content", "user/user_list", $data, TRUE);
        $this->template->render();
    }
示例#2
0
文件: browse.php 项目: redroot/URIKA
    function index()
    {
        //query vars
        $q_vars = get_url_vars();
        $base = base_url();
        // set search vars
        $order_by = isset($q_vars->sort) ? $q_vars->sort : "datetime";
        $order_dir = isset($q_vars->sort_dir) ? strtoupper($q_vars->sort_dir) : "DESC";
        $per_page = 20;
        $offset = isset($q_vars->page) ? ($q_vars->page - 1) * $per_page : 0;
        $current_page = isset($q_vars->page) ? $q_vars->page : 1;
        $search_val = isset($q_vars->search) ? str_replace("+", " ", $q_vars->search) : "";
        $tag_val = isset($q_vars->tag) ? str_replace("+", " ", $q_vars->tag) : "";
        $type = isset($q_vars->type) ? $q_vars->type : "both";
        $results = $this->general_model->searchAll($tag_val, $search_val, $type, $offset, $per_page, $order_by, $order_dir);
        if ($results == false) {
            $total = 0;
            $count_string = 0;
            $show_prev = false;
            $show_next = false;
        } else {
            // calculate offset and info
            $total = $results["total"];
            $count = count($results["results"]);
            // work out page results text
            // so we can control what appears in the same conditional
            $show_next = true;
            $show_prev = false;
            // if a page is set
            if (isset($q_vars->page)) {
                $show_prev = true;
                $current_start = $per_page * ($q_vars->page - 1) + 1;
                // determine end
                if ($per_page * $q_vars->page < $total) {
                    // if there are more on the next page
                    $current_end = $per_page * $q_vars->page;
                    $show_next = true;
                } else {
                    // else we dont need a previ button
                    $current_end = $total;
                    $show_next = false;
                }
            } else {
                // now page, so determine when the end should say
                $current_start = 1;
                if ($total >= $per_page) {
                    $current_end = $per_page;
                } else {
                    $current_end = $total;
                    $show_next = false;
                }
            }
            $count_string = $current_start . ' - ' . $current_end;
        }
        // query html
        // same as batave, x of y records, filter info
        $results_info = "";
        // count
        $results_info .= 'Showing <strong>' . $count_string . '</strong> of <strong>' . $total . '</strong> results';
        if ($tag_val != "") {
            $results_info .= '. Filtering for tags containing <strong>' . $tag_val . '</strong>';
        }
        if ($search_val != "") {
            $results_info .= '. Filtering for search term <strong>' . $search_val . '</strong>';
        }
        // now reassign results
        $results = $results["results"];
        if ($total > 0 && isset($results[0])) {
            $out = '<ul class="uploadList">';
            for ($i = 0; $i < $per_page; $i++) {
                if (isset($results[$i]->image_id)) {
                    //parse Image
                    $data = array("thumb_url" => $results[$i]->i_thumb_url, "title" => $results[$i]->i_title, "url" => $base . 'image/view/' . $results[$i]->image_id . '/' . slugify($results[$i]->i_title) . '/', "user_url" => $base . 'user/u/' . $results[$i]->u_username . '/', "username" => $results[$i]->u_username, "views" => $results[$i]->i_views, "overlay" => $base . 'assets/images/layout/uploadListOverlay.gif');
                    $out .= $this->load->view("components/uploadListLi", $data, true);
                } else {
                    if (isset($results[$i]->moodboard_id)) {
                        // parse Moodboard
                        $data = array("thumb_url" => $results[$i]->m_thumb_url, "title" => $results[$i]->m_title, "url" => $base . 'moodboard/view/' . $results[$i]->moodboard_id . '/' . slugify($results[$i]->m_title) . '/', "user_url" => $base . 'user/u/' . $results[$i]->u_username . '/', "username" => $results[$i]->u_username, "views" => $results[$i]->m_views, "overlay" => $base . 'assets/images/layout/mbListOverlay.gif');
                        $out .= $this->load->view("components/mbListLi", $data, true);
                    } else {
                        if (isset($results[$i]->row_id)) {
                            // this is from the UNION sql so we have to be a bit smarter here
                            if ($results[$i]->type == "image") {
                                $row_url = $base . 'image/view/' . $results[$i]->row_id . '/' . slugify($results[$i]->row_title) . '/';
                                $overlay = $base . 'assets/images/layout/uploadListOverlay.gif';
                                $view = "components/uploadListLi";
                            } else {
                                $row_url = $base . 'moodboard/view/' . $results[$i]->row_id . '/' . slugify($results[$i]->row_title) . '/';
                                $overlay = $base . 'assets/images/layout/mbListOverlay.gif';
                                $view = "components/mbListLi";
                            }
                            // parse object
                            // parse Moodboard
                            $data = array("thumb_url" => $results[$i]->row_thumb_url, "title" => $results[$i]->row_title, "url" => $row_url, "user_url" => $base . 'user/u/' . $results[$i]->u_username . '/', "username" => $results[$i]->u_username, "views" => $results[$i]->views, "overlay" => $overlay);
                            $out .= $this->load->view($view, $data, true);
                        }
                    }
                }
            }
            $out .= '</ul>';
        } else {
            $out = '<p class="error">No results for this criteria</p>';
        }
        // pagination links
        $no_list = array('page', 'browse_search');
        $out .= '
		<div class="pagination_buttons clear">
		';
        if ($show_prev) {
            $out .= '<a class="pagination" href="' . $base . 'browse/' . queryStringDrop(null, $no_list, -1) . '"  title="View previous page of results">< Previous</a>';
        }
        if ($show_next && $total > $per_page) {
            $out .= '<a class="pagination"  href="' . $base . 'browse/' . queryStringDrop(null, $no_list, 1) . '"  title="Viewnext page of results">Next ></a>';
        }
        $out .= '
		</div>
		';
        // now render
        $data = array("list_html" => $out, "search" => $search_val, "tag" => $tag_val, "type" => $type, "order_by" => $order_by, "results_info" => $results_info);
        $this->template->write("title", "Browsing");
        $this->template->write_view("content", "browse/browse_default", $data);
        $this->template->render();
    }