function handleCookies() { // if no session lets check for cookies if (!isLoggedIn()) { if (isset($_COOKIE["urika_userlogin"]) == true && isset($_COOKIE["urika_login_tried"]) == false) { $CI =& get_instance(); $CI->load->model("user_model"); $query = $CI->user_model->getUser($_COOKIE["urika_userlogin"], "u_username"); if ($query) { // now verify secret before creating session $row = $query->row(); if (isset($_COOKIE["urika_usersecret"]) && md5($row->u_username . $row->u_password) == $_COOKIE["urika_usersecret"]) { // win lets make a session $data = array('username' => $row->u_username, 'user_id' => $row->user_id, 'is_logged_in' => true, 'image_url' => getUserProfileURL($row->u_profile_id, $row->u_email)); $CI->session->set_userdata($data); } else { // no luck setcookie("urika_login_tried", $_COOKIE["urika_userlogin"]); } } else { // no match, so et a cookie so we don't try over and over again setcookie("urika_login_tried", $_COOKIE["urika_userlogin"]); } } } }
function view($id, $name = null) { $mb = $this->moodboard_model->getMoodboard($id); if ($mb !== false) { $mb = $mb->row(); if ($name !== slugify($mb->m_title)) { // redirect to right version redirect('moodboard/view/' . $mb->moodboard_id . '/' . slugify($mb->m_title) . '/', 'location'); } $base = base_url(); $this->load->model("user_model"); $user = $this->user_model->getUser($mb->m_user_id); $user = $user->row(); $profile_url = getUserProfileURL($user->u_profile_id, $user->u_email); $this->load->model("favourite_model"); $datetime = date("F j, Y", strtotime($mb->m_datetime)); // get page $page = isset($q_vars->comment_page) == true ? $q_vars->comment_page : 1; // sort tags out $tags = explode(',', $mb->m_tags); $tags_html = "<strong>Tags:</strong> "; $count = count($tags); for ($i = 0; $i < $count; $i++) { if ($tags[$i] != "") { $tags_html .= '<a class="tag_link" href="' . $base . 'browse/?tag=' . str_replace(" ", "+", $tags[$i]) . '" title="Search by this tag">' . $tags[$i] . '</a>'; } } $controlsHTML = array(); if (isLoggedIn() == true) { // determine if this user is the owner of this image if ($this->session->userdata("user_id") == $mb->m_user_id) { $controlsHTML["editLink"] = $base . "moodboard/edit/" . $mb->moodboard_id . "/"; $controlsHTML["deleteLink"] = $base . "moodboard/delete/" . $mb->moodboard_id . "/"; } else { if ($this->favourite_model->favouriteExists($this->session->userdata("user_id"), $mb->moodboard_id, "moodboard") == false) { $controlsHTML["favlink"] = '<li><span class="fav_link" id="ajax_fav" onclick="addFavourite(' . $mb->moodboard_id . ');" >Add to Favourites</span></li>'; } else { $controlsHTML["favlink"] = '<li><span class="fav_link" >Favourited!</span></li>'; } } // now increment views $update_data = array("m_views" => $mb->m_views + 1); $this->moodboard_model->updateMoodboard($update_data, $mb->moodboard_id); } // comments + favourites $this->load->model("comment_model"); $comments = $this->comment_model->getComments($mb->moodboard_id, $page, "moodboard"); $comments_html = "<p class='nocomments'>No Comments</p>"; $comments_count = 0; $comments_total = $this->comment_model->getCommentsCount($mb->moodboard_id, "moodboard"); $user_profile_url = ""; if (isLoggedIn() == true) { $signedin = $this->user_model->getUser($this->session->userdata("user_id")); $signedin = $signedin->row(); $user_profile_url = getUserProfileURL($signedin->u_profile_id, $signedin->u_email); } $comments_buttons = ""; if (is_array($comments)) { $comments_html = ""; $comments_count = count($comments); for ($i = 0; $i < $comments_count; $i++) { $comment_data = array("profile_url" => getUserProfileURL($comments[$i]->u_profile_id, $comments[$i]->u_email), "user_url" => $base . "user/u/" . $comments[$i]->u_username . "/", "username" => $comments[$i]->u_username, "comment_id" => $comments[$i]->comment_id, "date_uploader" => date("F j, Y, G:i", strtotime($comments[$i]->c_datetime)), "comment_text" => html_entity_decode($comments[$i]->c_content), "classes" => "", "showdelete" => "false"); // set delete link think if ($comments[$i]->c_poster_id == $this->session->userdata("user_id")) { $comment_data["showdelete"] = "true"; } // get classes if ($i % 2 == 1) { $comment_data["classes"] = "even"; } else { $comment_data["classes"] = "odd"; } // uploader comment if ($comments[$i]->user_id == $comments[$i]->c_subject_user_id) { $comment_data["classes"] .= " uploader_comment"; $comment_data["date_uploader"] .= " <span>- uploader comment</span>"; } $comments_html .= $this->load->view("components/commentDiv", $comment_data, true); } // now add prev/next buttons if ($comments_total > 10) { $prev_class = $page == 1 ? "hide" : ""; $comments_buttons = ' <div class="pagination_buttons comments_buttons"> <span id="current_comment_page" class="hide">' . $page . '</span> <input type="button" class="pagination ' . $prev_class . '" onclick="commentsNav(\'moodboard\',' . $mb->moodboard_id . ',-1,' . $comments_total . ')"; name="comments_prev" id="comments_prev" value="< Newer" /> <input type="button" class="pagination" onclick="commentsNav(\'moodboard\',' . $mb->moodboard_id . ',1,' . $comments_total . ')"; name="comments_next" id="comments_next" value="Older >" /> <span class="loading hide"> </span> </div> '; } } // favourites $favourites = $this->favourite_model->getFavourites($mb->moodboard_id, "moodboard"); $favs_html = "No Favourites"; $favs_count = 0; if (is_array($favourites)) { $favs_count = count($favourites); $favs_html = "<ul id='imageFavsList' class='wideUserList'>"; for ($i = 0; $i < $favs_count; $i++) { $urow = $favourites[$i]; $fimage_url = getUserProfileURL($urow->u_profile_id, $urow->u_email); $base = base_url(); $profilelink = $base . 'user/u/' . $urow->u_username; $lidata = array("user_id" => $urow->user_id, "profile_link" => $profilelink, "profile_img" => $fimage_url, "username" => $urow->u_username); $favs_html .= $this->load->view("components/smallUserListLi", $lidata, true); } $favs_html .= "</ul>"; } // sort data out and insert into the view $data = array("mb_url" => $mb->m_full_url, "mb_title" => $mb->m_title, "mb_desc" => $mb->m_description, "mb_favourites" => 0, "mb_views" => $mb->m_views, "mb_datetime" => $datetime, "mb_tags_html" => $tags_html, "mb_id" => $mb->moodboard_id, "mb_user_id" => $mb->m_user_id, "username" => $user->u_username, "profile_url" => $profile_url, "base_url" => $base, "controlsHTML" => $controlsHTML, "favs_html" => $favs_html, "favs_count" => $favs_count, "comments_html" => $comments_html, "comments_buttons" => $comments_buttons, "comments_count" => $comments_total, "signedin_profile_url" => $user_profile_url); $this->template->write("title", $mb->m_title . ", created by " . $user->u_username); $this->template->add_js("assets/js/image.js"); $this->template->add_js("assets/js/ajax.js"); $this->template->add_js("assets/js/tabs.js"); $this->template->write_view("content", "moodboard/view", $data, TRUE); $this->template->render(); } else { $data = array("errorTitle" => "Moodboard not found", "content" => "The moodboard with the id '" . $id . "' was not found."); $this->template->write_view("content", "general/error", $data, TRUE); //now render templates $this->template->render(); } }
function notices() { loggedInSection(); $this->load->model("notice_model"); $notices = $this->notice_model->getUserNotices($this->session->userdata("user_id")); $user = $this->user_model->getUser($this->session->userdata("user_id"))->row(); $show_buttons = false; if ($notices == false) { $content = '<div class="borderbox">You have no notices yet. Get into the community and get noticed!</div>'; } else { $show_buttons = true; $content = '<ul class="notice_list">'; $ids_list = ''; // loop through notices foreach ($notices as $notice) { $class = 'notice_' . $notice->n_type; $read_link_text = 'Mark as Unread'; $ids_list .= $notice->notice_id . '+'; if ($notice->n_new == 1) { $class .= ' notice_new'; $read_link_text = 'Mark as Read'; } $controls = '<a href="#" class="toggle_read_link" onclick="toggleNoticeRead(' . $notice->notice_id . ');" title="toggle mark as read">' . $read_link_text . '</a> | <a href="#" onclick="deleteNotice(' . $notice->notice_id . ')" title="delete this notice">Delete Notice</a>'; $content .= '<li id="notice_' . $notice->notice_id . '" class="' . $class . '">' . $notice->n_html . ' <p class="notice_controls">' . $controls . '</p></li>'; } $content .= '</ul><input type="hidden" id="notice_ids_list" name="notice_ids_list" value="' . substr($ids_list, 0, -1) . '" />'; } $data = array("username" => $user->u_username, "image_url" => getUserProfileURL($user->u_profile_id, $user->u_email), "notices_html" => $content, "show_buttons" => $show_buttons); $this->template->write("title", "Your notices"); $this->template->add_js("assets/js/account.js"); $this->template->add_js("assets/js/ajax.js"); $this->template->write_view("content", "user/notices", $data); //now render templates $this->template->render(); }
function add() { loggedInSection(); // urika_helper.php if (isAjaxRequest()) { $last_comment = $this->comment_model->getLastUserCommentTime($_POST["user_id"]); $out = ""; // check last comment time if ($last_comment != false) { // check time $time_diff = time() - $last_comment; if ($time_diff < 120) { $out = json_encode(array("result" => "toosoon")); } } if ($out == "") { $insert_array = array("c_poster_id" => $this->input->xss_clean($_POST["user_id"]), "c_subject_id" => $this->input->xss_clean($_POST["subject_id"]), "c_subject_user_id" => $this->input->xss_clean($_POST["sub_user_id"]), "c_type" => $this->input->xss_clean($_POST["type"]), "c_content" => htmlentities(nl2br($this->input->xss_clean($_POST["text"]))), "c_privacy" => 0); $insert = $this->comment_model->createNewComment($insert_array); if ($insert != false) { $base = base_url(); // get comment user details $this->load->model("user_model"); $user = $this->user_model->getUser($this->input->xss_clean($_POST["user_id"])); $user = $user->row(); $isUploader = "false"; if ($_POST["user_id"] == $this->input->xss_clean($_POST["sub_user_id"])) { $isUploader = "true"; } $profile_url = getUserProfileURL($user->u_profile_id, $user->u_email); $json = array("result" => "true", "user_url" => $base . "user/u/" . $user->u_username . "/", "profile_url" => $profile_url, "datetime" => date("F j, Y, G:i"), "username" => $user->u_username, "is_uploader" => $isUploader, "comment_id" => $insert["id"]); /* Notice insert no notice if you did it on your thing */ // check for upload_comments in notice format string $createNotice = true; $subject_user = $this->user_model->getUser($this->input->xss_clean($_POST["sub_user_id"]))->row(); if ($_POST["type"] == "image") { if (strpos($subject_user->u_notice_format, "upload_comments") === FALSE) { $createNotice = false; } } else { if ($_POST["type"] == "moodboard") { if (strpos($subject_user->u_notice_format, "mb_comments") === FALSE) { $createNotice = false; } } } if ($isUploader == "false" && $createNotice == true) { $notice_insert = array("n_object_user_id" => $this->input->xss_clean($_POST["sub_user_id"]), "n_object_id" => $this->input->xss_clean($_POST["subject_id"]), "n_object_type" => $this->input->xss_clean($_POST["type"]), "n_action_user_id" => $this->input->xss_clean($_POST["user_id"]), "n_type" => "comment", "n_new" => 1, "n_html" => ""); // now html $notice_html = '<span class="notice_date">' . $json["datetime"] . '</span> - <a href="' . $json["user_url"] . '" title="' . $json["username"] . '\'s profile">' . $json["username"] . '</a> commented on your '; if ($_POST["type"] == "image") { $this->load->model("image_model"); $image = $this->image_model->getImage($_POST["subject_id"])->row(); $n_url = $base . 'image/view/' . $_POST["subject_id"] . '/' . slugify($image->i_title) . '/#comment_' . $insert["id"]; $notice_html .= 'upload <a href="' . $n_url . '" title="View comment on this image">' . $_POST["subject_name"] . '</a>'; } else { if ($_POST["type"] == "moodboard") { $this->load->model("moodboard_model"); $mb = $this->moodboard_model->getMoodboard($_POST["subject_id"])->row(); $n_url = $base . 'moodboard/view/' . $_POST["subject_id"] . '/' . slugify($mb->m_title) . '/#comment_' . $insert["id"]; $notice_html .= 'moodboard <a href="' . $n_url . '" title="View comment on this moodboard">' . $_POST["subject_name"] . '</a>'; } } $notice_insert["n_html"] = $notice_html; $this->load->model("notice_model"); $this->notice_model->createNewNotice($notice_insert); } /* End notice insert */ $out = json_encode($json); } else { $out = json_encode(array("result" => "false")); } } echo $out; } else { $data = array("errorTitle" => "Request Denied", "content" => "An error has occurred: you cannot access this page from the browser."); $this->template->write_view("content", "general/error", $data, TRUE); //now render templates $this->template->render(); } }
/** AJAX browse super function, used to grab image results follow results, and comments results etc but in an a straight upload return form Params are part of the post var, the type of results determines by the url parameter @param type : type of results to grab */ function ajaxresults($type = null) { if (isAjaxRequest()) { if ($type != null) { $allowedTypes = array("images", "moodboards", "comments"); $this->input->xss_clean($_POST); // check it actually exists if (in_array(strtolower($type), $allowedTypes)) { $result_html = ""; $result; $base = base_url(); // some universal or multiplue use variables $search_term = $tag = ""; $page = 1; $per_page = 20; $base = base_url(); // now process the post terms if (isset($_POST["search"]) && $_POST["search"] != "") { $search_term = trim($_POST["search"]); } if (isset($_POST["tag"]) && $_POST["tag"] != "") { $tag = trim($_POST["tag"]); } if (isset($_POST["page"]) && $_POST["page"] != "") { $page = $_POST["page"]; } if (isset($_POST["per_page"]) && $_POST["per_page"] != "") { $per_page = $_POST["per_page"]; } // set offset $offset = (int) ($page * $per_page); if (strtolower($type) == "images") { /* 1) Images search Handles: Order by Date Order by Views User's uploads User's favs Follow feed Tag Search term */ $order_by = ""; $order_dir = ""; if (isset($_POST["order_by"]) && $_POST["order_by"] == "") { $order_by = trim($_POST["order_by"]); } // Now determine which functions to run if (isset($_POST["user_id"]) && !isset($_POST["user_favs"])) { // this means we are looking at user uploads $this->load->model("user_model"); $results = $this->user_model->getUserImages($_POST["user_id"], $per_page * ($page - 1)); // generate user lis from results } else { if (isset($_POST["user_favs"])) { // this means we are looking at favurites $this->load->model("user_model"); $results = $this->user_model->getUserFavs($_POST["user_id"], $per_page * ($page - 1)); } } // now process results into upload list li if ($results["count"] != false) { $out = ""; for ($i = 0; $i < $results["count"]; $i++) { $irow = $results["result"][$i]; if (!isset($irow->f_type)) { // load li through view $data = array("thumb_url" => $irow->i_thumb_url, "title" => $irow->i_title, "url" => $base . 'image/view/' . $irow->image_id . '/' . slugify($irow->i_title) . '/', "user_url" => $base . 'user/u/' . $irow->u_username . '/', "username" => $irow->u_username, "views" => $irow->i_views, "overlay" => $base . 'assets/images/layout/uploadListOverlay.gif'); $out .= $this->load->view("components/uploadListLi", $data, true); } else { if ($irow->f_type == "image") { // load li through view $data = array("thumb_url" => $irow->i_thumb_url, "title" => $irow->i_title, "url" => $base . 'image/view/' . $irow->image_id . '/' . slugify($irow->i_title) . '/', "user_url" => $base . 'user/u/' . $irow->u_username . '/', "username" => $irow->u_username, "views" => $irow->i_views, "overlay" => $base . 'assets/images/layout/uploadListOverlay.gif'); $out .= $this->load->view("components/uploadListLi", $data, true); } else { if ($irow->f_type == "moodboard") { // load li through view $data = array("thumb_url" => $irow->m_thumb_url, "title" => $irow->m_title, "url" => $base . 'moodboard/view/' . $irow->moodboard_id . '/' . slugify($irow->m_title) . '/', "user_url" => $base . 'user/u/' . $irow->u_username . '/', "username" => $irow->u_username, "views" => $irow->m_views, "overlay" => $base . 'assets/images/layout/mbListOverlay.gif'); $out .= $this->load->view("components/mbListLi", $data, true); } } } } } else { $out = "no_more"; } $return_html = $out; } else { if (strtolower($type) == "moodboards") { /* Moodboards search - simple pagination for user page */ if (isset($_POST["user_id"])) { // this means we are looking at user uploads $this->load->model("user_model"); $results = $this->user_model->getUserMoodboards($_POST["user_id"], $per_page * ($page - 1)); if ($results["count"] != 0) { $out = ""; for ($i = 0; $i < $results["count"]; $i++) { $mrow = $results["result"][$i]; // load li through view $data = array("thumb_url" => $mrow->m_thumb_url, "title" => $mrow->m_title, "url" => $base . 'moodboard/view/' . $mrow->moodboard_id . '/' . slugify($mrow->m_title) . '/', "user_url" => $base . 'user/u/' . $mrow->u_username . '/', "username" => $mrow->u_username, "views" => $mrow->m_views, "overlay" => $base . 'assets/images/layout/mbListOverlay.gif'); $out .= $this->load->view("components/mbListLi", $data, true); } $return_html = $out; } else { $return_html = "no_more"; } } else { $return_html = "false"; } } else { if (strtolower($type) == "comments") { $this->load->model("comment_model"); // simply, simply need to return an offset $comments = $this->comment_model->getComments($_POST["subject_id"], $page, $_POST["comment_type"]); if (is_array($comments)) { $comments_html = ""; $comments_count = count($comments); for ($i = 0; $i < $comments_count; $i++) { $comment_data = array("profile_url" => getUserProfileURL($comments[$i]->u_profile_id, $comments[$i]->u_email), "user_url" => $base . "user/u/" . $comments[$i]->u_username . "/", "username" => $comments[$i]->u_username, "comment_id" => $comments[$i]->comment_id, "date_uploader" => date("F j, Y, G:i", strtotime($comments[$i]->c_datetime)), "comment_text" => html_entity_decode($comments[$i]->c_content), "classes" => "", "showdelete" => "false"); // set delete link think if ($comments[$i]->c_poster_id == $this->session->userdata("user_id")) { $comment_data["showdelete"] = "true"; } // get classes if ($i % 2 == 1) { $comment_data["classes"] = "even"; } else { $comment_data["classes"] = "odd"; } // uploader comment if ($comments[$i]->user_id == $comments[$i]->c_subject_user_id) { $comment_data["classes"] .= " uploader_comment"; $comment_data["date_uploader"] .= " <span>- uploader comment</span>"; } $comments_html .= $this->load->view("components/commentDiv", $comment_data, true); } $return_html = $comments_html; } else { // no more comments $return_html = "no_more"; } } else { } } } echo $return_html; } else { echo "false"; } } else { echo "false"; } } else { redirect('', 'location'); } }
function view($id, $name = null) { $collection = $this->collection_model->getCollection($id); if ($collection != false) { $collection = $collection->row(); if ($name !== slugify($collection->col_name)) { // redirect to right version redirect('collection/view/' . $collection->collection_id . '/' . slugify($collection->col_name) . '/', 'location'); } $images = $this->collection_model->getCollectionImages($id); $base = base_url(); $q_vars = get_url_vars(); // image string if ($images != false) { $image_count = count($images); } else { $image_count = 0; } $col_images_string = "Contains "; if ($image_count == 1) { $col_images_string .= "1 Image"; } else { $col_images_string .= $image_count . " Images"; } $col_images_string .= '<span class="sep">|</span> Last Updated ' . date("F j, Y, G:i", strtotime($collection->col_updated)); //mages if ($image_count > 0) { $images_html = '<ul class="uploadList">'; for ($i = 0; $i < $image_count; $i++) { $irow = $images[$i]; // load li through view $data = array("thumb_url" => $irow->i_thumb_url, "title" => $irow->i_title, "url" => $base . 'image/view/' . $irow->image_id . '/' . slugify($irow->i_title) . '/', "user_url" => $base . 'user/u/' . $irow->u_username . '/', "username" => $irow->u_username, "views" => $irow->i_views, "overlay" => $base . 'assets/images/layout/uploadListOverlay.gif'); $images_html .= $this->load->view("components/uploadListLi", $data, true); } $images_html .= '</ul>'; } else { if ($collection->col_user_id == $this->session->userdata("user_id")) { $base = base_url(); $images_html = ' <p class="borderbox"> <img class="right" src="' . $base . 'assets/images/content/add_fav_col_small.jpg" alt="new add to collection button" width="120" height="62" /> <strong>Welcome to your new collection!</strong>. You can use the <strong>Add to Collection</strong> button on any upload to add it to a collection. This button appears under the Add to Favourites button on any upload, including your own. <br/> <br/> For information, see the <a href="' . $base . 'page/faq/" title="FAQ section">FAQ section</a> <span class="clear"> </span> </p> '; } else { $images_html = "No images have been added to this collection."; } } // message start $message = ""; if (isset($q_vars->saved)) { $message = "saved"; } // controls start $controls_html = ""; if ($this->session->userdata("user_id") == $collection->col_user_id) { $controls_html = ' <ul class="collection_controls"> <li><a class="edit_link" href="' . $base . 'collection/edit/' . $collection->collection_id . '/">Edit Collection</a></li> <li><a class="delete_link" href="' . $base . 'collection/delete/' . $collection->collection_id . '/">Delete Collection</a></li> <li><a class="moodboard_link" href="' . $base . 'moodboard/add/' . $collection->collection_id . '/col/">Create Moodboard</a></li> </ul> <div class="clear"> </div> '; } $view_data = array("col_title" => $collection->col_name, "username" => $collection->u_username, "profile_url" => getUserProfileURL($collection->u_profile_id, $collection->u_email), "col_images_string" => $col_images_string, "images_html" => $images_html, "message" => $message, "controls_html" => $controls_html); // render templates $this->template->write("title", "Collection: " . $collection->col_name); $this->template->write_view("content", "collections/view", $view_data, TRUE); //now render templates $this->template->render(); } else { $data = array("errorTitle" => "Collection Not Found", "content" => "An error has occurred: the collection with the id <strong>" . $id . "</strong> could not be found. It may have been deleted."); $this->template->write_view("content", "general/error", $data, TRUE); //now render templates $this->template->render(); } }
/** Viewing an image page **/ function view($id = null, $name = null) { $q_vars = get_url_vars(); if ($id == null || !is_numeric($id)) { redirect('', 'location'); } else { $image = $this->image_model->getImage($id); if ($image == false) { $data = array("errorTitle" => "Image wasn't found", "content" => "The image with the id " . $id . " was not found, it may not exist or has been deleted"); $this->template->write_view("content", "general/error", $data, TRUE); //now render templates $this->template->render(); } else { if ($name != null && $name !== slugify($image->row()->i_title)) { // redirect to right version $image = $image->row(); redirect('image/view/' . $image->image_id . '/' . slugify($image->i_title) . "/", 'location'); } else { $image = $image->row(); $base = base_url(); $this->load->model("user_model"); $user = $this->user_model->getUser($image->i_user_id); $user = $user->row(); $profile_url = getUserProfileURL($user->u_profile_id, $user->u_email); $this->load->model("favourite_model"); $datetime = date("F j, Y", strtotime($image->i_datetime)); // get page $page = isset($q_vars->comment_page) == true ? $q_vars->comment_page : 1; // sort tags out $tags = explode(',', $image->i_tags); $tags_html = "<strong>Tags:</strong> "; $count = count($tags); for ($i = 0; $i < $count; $i++) { if ($tags[$i] != "") { $tags_html .= '<a class="tag_link" href="' . $base . 'browse/?tag=' . str_replace(" ", "+", $tags[$i]) . '" title="Search by this tag">' . $tags[$i] . '</a>'; } } // now handle edit and delete link $controlsHTML = array(); if (isLoggedIn() == true) { // determine if this user is the owner of this image if ($this->session->userdata("user_id") == $image->i_user_id) { $controlsHTML["editLink"] = $base . "image/edit/" . $image->image_id . "/"; $controlsHTML["deleteLink"] = $base . "image/delete/" . $image->image_id . "/"; } else { if ($this->favourite_model->favouriteExists($this->session->userdata("user_id"), $image->image_id) == false) { $controlsHTML["favlink"] = '<li><span class="fav_link" id="ajax_fav" onclick="addFavourite(' . $image->image_id . ',\'image\');" >Add to Favourites</span></li>'; } else { $controlsHTML["favlink"] = '<li><span class="fav_link" >Favourited!</span></li>'; } $this->load->model("flag_model"); if ($this->flag_model->flagExists($this->session->userdata("user_id"), $image->image_id) == false) { $controlsHTML["flagLink"] = '<li><span class="flag_link" id="ajax_flag" onclick="addFlagPopUp(' . $image->image_id . ');" >Flag This Upload</span></li>'; } else { $controlsHTML["flagLink"] = '<li><span class="flag_link" >Flagged!</span></li>'; } } $collections = $this->user_model->getUserCollections($this->session->userdata("user_id")); // add collections link $controlsHTML["collectionsLink"] = '<li><span class="collections_link" onclick="addToCollectionPopUp(' . $image->image_id . ')">Add to Collection</span></li>'; // now the collections bit, two hidden spans holding collection ids that this // image isnt in $available_cols_json = "{"; $current_id = 0; // use this to make sure indexing works if ($collections["count"] > 0) { for ($k = 0; $k < $collections["count"]; $k++) { $ex = explode(",", $collections["result"][$k]->col_string); if (!in_array($image->image_id, $ex)) { if ($available_cols_json != "{") { $available_cols_json .= ','; } $available_cols_json .= '"' . $current_id . '":{"name":"' . $collections["result"][$k]->col_name . '","id":"' . $collections["result"][$k]->collection_id . '"}'; $current_id++; } } } $available_cols_json .= "}"; if ($available_cols_json == "{}") { $available_cols_json = 'empty'; } $controlsHTML["collectionsLink"] .= '<input type="hidden" id="userColsJSON" value=\'' . $available_cols_json . '\' />'; // now increment views $update_data = array("i_views" => $image->i_views + 1); $this->image_model->updateImage($update_data, $image->image_id); } // now comments and favourites // comments $this->load->model("comment_model"); $comments = $this->comment_model->getComments($image->image_id, $page); $comments_html = "<p class='nocomments'>No Comments</p>"; $comments_count = 0; $comments_total = $this->comment_model->getCommentsCount($image->image_id); $user_profile_url = ""; if (isLoggedIn() == true) { $signedin = $this->user_model->getUser($this->session->userdata("user_id")); $signedin = $signedin->row(); $user_profile_url = getUserProfileURL($signedin->u_profile_id, $signedin->u_email); } $comments_buttons = ""; if (is_array($comments)) { $comments_html = ""; $comments_count = count($comments); for ($i = 0; $i < $comments_count; $i++) { $comment_data = array("profile_url" => getUserProfileURL($comments[$i]->u_profile_id, $comments[$i]->u_email), "user_url" => $base . "user/u/" . $comments[$i]->u_username . "/", "username" => $comments[$i]->u_username, "comment_id" => $comments[$i]->comment_id, "date_uploader" => date("F j, Y, G:i", strtotime($comments[$i]->c_datetime)), "comment_text" => html_entity_decode($comments[$i]->c_content), "classes" => "", "showdelete" => "false"); // set delete link think if ($comments[$i]->c_poster_id == $this->session->userdata("user_id")) { $comment_data["showdelete"] = "true"; } // get classes if ($i % 2 == 1) { $comment_data["classes"] = "even"; } else { $comment_data["classes"] = "odd"; } // uploader comment if ($comments[$i]->user_id == $comments[$i]->c_subject_user_id) { $comment_data["classes"] .= " uploader_comment"; $comment_data["date_uploader"] .= " <span>- uploader comment</span>"; } $comments_html .= $this->load->view("components/commentDiv", $comment_data, true); } // now add prev/next buttons if ($comments_total > 10) { $prev_class = $page == 1 ? "hide" : ""; $comments_buttons = ' <div class="pagination_buttons comments_buttons"> <span id="current_comment_page" class="hide">' . $page . '</span> <input type="button" class="pagination ' . $prev_class . '" onclick="commentsNav(\'image\',' . $image->image_id . ',-1,' . $comments_total . ')"; name="comments_prev" id="comments_prev" value="< Newer" /> <input type="button" class="pagination" onclick="commentsNav(\'image\',' . $image->image_id . ',1,' . $comments_total . ')"; name="comments_next" id="comments_next" value="Older >" /> <span class="loading hide"> </span> </div> '; } } // favourites $favourites = $this->favourite_model->getFavourites($image->image_id); $favs_html = "No Favourites"; $favs_count = 0; if (is_array($favourites)) { $favs_count = count($favourites); $favs_html = "<ul id='imageFavsList' class='wideUserList'>"; for ($i = 0; $i < $favs_count; $i++) { $urow = $favourites[$i]; $fimage_url = getUserProfileURL($urow->u_profile_id, $urow->u_email); $base = base_url(); $profilelink = $base . 'user/u/' . $urow->u_username; $lidata = array("user_id" => $urow->user_id, "profile_link" => $profilelink, "profile_img" => $fimage_url, "username" => $urow->u_username); $favs_html .= $this->load->view("components/smallUserListLi", $lidata, true); } $favs_html .= "</ul>"; } $data = array("image_url" => $image->i_full_url, "image_title" => $image->i_title, "image_desc" => $image->i_description, "image_favourites" => 0, "image_views" => $image->i_views, "image_dims" => str_replace("X", " X ", $image->i_size), "image_datetime" => $datetime, "image_tags_html" => $tags_html, "image_website" => $image->i_website, "image_id" => $image->image_id, "image_user_id" => $image->i_user_id, "username" => $user->u_username, "profile_url" => $profile_url, "base_url" => $base, "controlsHTML" => $controlsHTML, "favs_html" => $favs_html, "favs_count" => $favs_count, "comments_html" => $comments_html, "comments_buttons" => $comments_buttons, "comments_count" => $comments_total, "signedin_profile_url" => $user_profile_url); $this->template->write("title", $image->i_title . ", uploaded by " . $user->u_username); $this->template->add_js("assets/js/image.js"); $this->template->add_js("assets/js/ajax.js"); $this->template->add_js("assets/js/tabs.js"); $this->template->write_view("content", "image/view", $data, TRUE); $this->template->render(); } } //increment image views } }
function _parseUserRow($user) { $base = base_url(); $result = array("user_id" => $user->user_id, "username" => $user->u_username, "profile_link" => $base . 'user/u/' . $user->u_username . '/', "avatar_src" => getUserProfileURL($user->u_profile_id, $user->u_email), "upload_count" => isset($user->u_image_count) ? $user->u_image_count : "", "moodboard_count" => isset($user->u_mb_count) ? $user->u_mb_count : "", "favourite_count" => isset($user->u_favs) ? $user->u_favs : ""); return $result; }