Jump to content

ShoeLace1291

Members
  • Posts

    401
  • Joined

  • Last visited

Contact Methods

  • Website URL
    http://forum.lensereflex.com

Profile Information

  • Gender
    Not Telling

ShoeLace1291's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. I am trying to modify a class that I found that is a Steam API class. I want it to work with codeigniter. I keep getting call to a member function on a non-object error when I call the getProfileData function. Not sure why it's happening. Here is the code: The library: <?php // Disable XML warnings to avoid problems when SteamCommunity is down libxml_use_internal_errors(true); // Use SteamUtility to fetch URLs and other stuff require_once 'SteamUtility.php'; /** * SteamUser - Representation of any Steam user profile * * @category SteamAPI * @copyright Copyright (c) 2012 Matt Ryder (www.mattryder.co.uk) * @license GPLv2 License * @version v1.3 * @link https://github.com/MattRyder/SteamAPI/blob/master/steam/SteamUser.php * @since Class available since v1.0 */ class SteamUser { private $userID; private $vanityURL; private $apiKey; public $info; /** * Constructor * @param mixed $id User's steamID or vanityURL * @param string $apiKey API key for http://steamcommunity.com/dev/ */ /** * GetProfileData * - Accesses Steam Profile XML and parses the data */ function __construct($params){ $userId = $params['userId']; $this->CI =& get_instance(); $this->CI->load->config('steam'); if(empty($userId)) { echo "Error: No Steam ID or URL given!", PHP_EOL; return NULL; } if(is_numeric($userId)) { $this->userID = $userId; } else { $this->vanityURL = strtolower($userId); } $this->apiKey = $this->CI->config->item('api_key'); } function getProfileData() { $info = array(); //Set Base URL for the query: if(empty($this->vanityURL)) { $base = "http://steamcommunity.com/profiles/{$this->userId}/?xml=1"; } else { $base = "http://steamcommunity.com/id/{$this->vanityURL}/?xml=1"; } try { $content = SteamUtility::fetchURL($base); if ($content) { $parsedData = new SimpleXMLElement($content); } else { return null; } } catch (Exception $e) { //echo "Whoops! Something went wrong!\n\nException Info:\n" . $e . "\n\n"; return null; } if(!empty($parsedData)) { $info['steamID64'] = (string)$parsedData->steamID64; $info['steamID'] = (string)$parsedData->steamID; $info['stateMessage'] = (string)$parsedData->stateMessage; $info['visibilityState'] = (int)$parsedData->visibilityState; $info['privacyState'] = (string)$parsedData->privacyState; $info['avatarIcon'] = (string)$parsedData->avatarIcon; $info['avatarMedium'] = (string)$parsedData->avatarMedium; $info['avatarFull'] = (string)$parsedData->avatarFull; $info['vacBanned'] = (int)$parsedData->vacBanned; $info['tradeBanState'] = (string)$parsedData->tradeBanState; $info['isLimitedAccount'] = (string)$parsedData->isLimitedAccount; $info['onlineState'] = (string)$parsedData->onlineState; $info['inGameServerIP'] = (string)$parsedData->inGameServerIP; //If their account is public, get that info: if($info['privacyState'] == "public") { $info['customURL'] = (string)$parsedData->customURL; $info['memberSince'] = (string)$parsedData->memberSince; $info['steamRating'] = (float)$parsedData->steamRating; $info['hoursPlayed2Wk'] = (float)$parsedData->hoursPlayed2Wk; $info['headline'] = (string)$parsedData->headline; $info['location'] = (string)$parsedData->location; $info['realname'] = (string)$parsedData->realname; $info['summary'] = (string)$parsedData->summary; } //If they're in a game, grab that info: if($info['onlineState'] == "in-game") { $info['inGameInfo']['inGameInfo'] = array(); $info['inGameInfo']["gameName"] = (string)$parsedData->inGameInfo->gameName; $info['inGameInfo']["gameLink"] = (string)$parsedData->inGameInfo->gameLink; $info['inGameInfo']["gameIcon"] = (string)$parsedData->inGameInfo->gameIcon; $info['inGameInfo']["gameLogo"] = (string)$parsedData->inGameInfo->gameLogo; $info['inGameInfo']["gameLogoSmall"] = (string)$parsedData->inGameInfo->gameLogoSmall; } //Get their most played video games: if(!empty($parsedData->mostPlayedGames)) { $info['mostPlayedGames'] = array(); $i = 0; foreach ($parsedData->mostPlayedGames->mostPlayedGame as $mostPlayedGame) { $info['mostPlayedGames'][$i] = new stdClass(); $info['mostPlayedGames'][$i]['gameName'] = (string)$mostPlayedGame->gameName; $info['mostPlayedGames'][$i]['gameLink'] = (string)$mostPlayedGame->gameLink; $info['mostPlayedGames'][$i]['gameIcon'] = (string)$mostPlayedGame->gameIcon; $info['mostPlayedGames'][$i]['gameLogo'] = (string)$mostPlayedGame->gameLogo; $info['mostPlayedGames'][$i]['gameLogoSmall'] = (string)$mostPlayedGame->gameLogoSmall; $info['mostPlayedGames'][$i]['hoursPlayed'] = (string)$mostPlayedGame->hoursPlayed; $info['mostPlayedGames'][$i]['hoursOnRecord'] = (string)$mostPlayedGame->hoursOnRecord; $info['mostPlayedGames'][$i]['statsName'] = (string)$mostPlayedGame->statsName; $i++; } } //Any weblinks listed in their profile: if(!empty($parsedData->weblinks)) { $this['weblinks'] = array(); $i = 0; foreach ($parsedData->weblinks->weblink as $weblink) { $info['weblinks'][$i]['title'] = (string)$weblink->title; $info['weblinks'][$i]['link'] = (string)$weblink->link; $i++; } } //And grab any subscribed groups: if(!empty($parsedData->groups)) { $this->groups = array(); $i = 0; foreach ($parsedData->groups->group as $group) { $info['groups'][$i] = array(); $info['groups'][$i]['groupID64'] = (string)$group->groupID64; $info['groups'][$i]['groupName'] = (string)$group->groupName; $info['groups'][$i]['groupURL'] = (string)$group->groupURL; $info['groups'][$i]['headline'] = (string)$group->headline; $info['groups'][$i]['summary'] = (string)$group->summary; $info['groups'][$i]['avatarIcon'] = (string)$group->avatarIcon; $info['groups'][$i]['avatarMedium'] = (string)$group->avatarMedium; $info['groups'][$i]['avatarFull'] = (string)$group->avatarFull; $info['groups'][$i]['memberCount'] = (string)$group->memberCount; $info['groups'][$i]['membersInChat'] = (string)$group->membersInChat; $info['groups'][$i]['membersInGame'] = (string)$group->membersInGame; $info['groups'][$i]['membersOnline'] = (string)$group->membersOnline; $i++; } } } return $info; } The model where I call the library: function retrieve($member_id = 0, $page = 1, $limit = 10){ $info = array(); $this->db->select('memberId AS id, facebookId, steamId, userName, emailAddress, dateJoined, dateBorn') ->from('members') ->where('memberId', $member_id) ->limit(1); if($query = $this->db->get()){ if($query->num_rows() > 0){ $member = $query->row_array(); var_dump($member); $info = $member; if($member['steamId'] != ''){ $this->load->library('SteamUser', array('userId' => $member['steamId'])); $steam = $this->SteamUser->getProfileData(); $info['steam'] = array( 'id' => $member['steamId'], 'avatar' => $steam['avatarIcon'] ); } } } $this->info = $info; }
  2. I've been googling for about the last 3 hours now looking for a decent extension to CodeIgniter's template parser class that adds the use of conditional statements. I can't really seem to find anything. Would anybody have any suggestions of one that would help me do something like this: {if:is_admin} show an admin link {/if}
  3. I am in the process of developing my personal website. There will not be any member accounts, but I will still need to have an admin panel so that I can manage my content. I will be the only person using the admin panel. Without using a database table to store it, what would be the most secure way to store a single admin password that I can use to login to my admin panel?
  4. I have already set up a class that I can use to log errors in CodeIgniter. I am now looking for a way to automatically log database errors in CI to a file in the application/logs folder. I've thought of maybe just chaining a log function to the get or query methods in the DB class that would use my logger class, but the problem is that they are in two different files. I'm not really sure where I should put the function. Has anyone done anything like this? Are there some better ways that this could be done?
  5. I am developing an article system with PHP. I have a table for articles and a table for article categories. There are two levels of categories: plain old categories, and subcategories. Articles can have a category id of either regular categories or of a subcategory. I would like to get all articles in a category and if that category has subcategories under it, the articles from those subcategories as well. And then order the articles by their id. This is the query I have so far, but it obviously only gets articles in the parent category and not from the parent categories' subcategories. SELECT article_id, category_id FROM articles WHERE category_id = 1 ORDER BY article_id DESC LIMIT 10 CREATE TABLE IF NOT EXISTS `articles` ( `article_id` int(15) NOT NULL AUTO_INCREMENT, `author_id` int(15) NOT NULL, `category_id` int(15) NOT NULL, `modification_id` int(15) NOT NULL, `title` varchar(125) NOT NULL, `content` text NOT NULL, `date_posted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `status` tinyint(1) NOT NULL, `attachment_id` int(15) NOT NULL, PRIMARY KEY (`article_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `article_categories` ( `category_id` int(15) NOT NULL AUTO_INCREMENT, `parent_id` int(15) NOT NULL, `title` varchar(50) NOT NULL, `description` text NOT NULL, `attachment_id` text NOT NULL, `enable_comments` tinyint(1) NOT NULL, `enable_ratings` tinyint(1) NOT NULL, PRIMARY KEY (`category_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Thanks in advance.
  6. I am trying to write my custom bb code parser in PHP. In my img tags, I want to be able to allow users to add optional parameters(width, height, and align). The combinations of attributes may be different between tags... for instance, some tags may only have the align attribute, others may have only width and height, others may have all three, or none of them. So basically my regex should match img tags with either width, height, or align as attributes... either numerical characters or the strings left, right, middle, top or bottom as the values, equal(=) symbol in between the attribute and the value, and spaces. This is the regex: ^\[img(((width|height|align)=(([0-9]+)|(left|right|middle|top|bottom)) )+)\](.*?)\[\/img\]$This is the test string: [img width=100 height=100 align=right]thelinktotheimage[/img] http://regex101.com/r/uT1lU2 Thanks in advance.
  7. I removed the inside quote tag and it seems to work now! Thanks!
  8. Your suggestion worked for one-level quotes, but the nested quotes are working almost the same way as before. The post body of the quote tag appears once per quote tag, but the whole quote tag(at the nested level) appears twice. Any ideas? [quote message_id=10] [quote message_id=9] [/quote] [/quote]
  9. Ok, I wasn't sure what exactly to title this thread since it could be any number of factors causing this problem.... Anyway, I am trying to write a script for my custom CodeIgniter-powered forum that parses bbcodes... I almost have it working completely, except for one tiny problem... The content of the quote tags is being parsed twice... I cannot figure out why this is happening. The header displays absolutely fine, it's just the content of the quote(or body) is doubled. It could be the preg_replace_call_back, or just my poor coding structure... but I can't figure it out. This is my result: My String Helper: <?php function parse_bb($str){ $CI =& get_instance(); $str = nl2br($str); $str = strip_slashes($str); $find = array( "'\[b\](.*?)\[/b\]'is", "'\[i\](.*?)\[/i\]'is", "'\[u\](.*?)\[/u\]'is", "'\[s\](.*?)\[/s\]'is", "'\[img\](.*?)\[\/img\]'is", "'\[url\](.*?)\[/url\]'i", "'\[url=(.*?)\](.*?)\[/url\]'i", "'\[link\](.*?)\[/link\]'i", "'\[link=(.*?)\](.*?)\[/link\]'i", "'\[h1\](.*?)\[\/h1\]'is", "'\[h2\](.*?)\[\/h2\]'is", "'\[h3\](.*?)\[\/h3\]'is", "'\[ul\](.*?)\[\/ul\]'is", "'\[li\](.*?)\[\/li\]'is", "'\[p\](.*?)\[\/p\]'is" //"'(\[quote (thread_id|message_id)=([0-9]+)\](.*?)\[\/quote\])e'" ); $replace = array( '<strong>\1</strong>', '<em>\1</em>', '<u>\1</u>', '<s>\1</s>', '<img src="\1" \1alt="User Image" />', anchor('\1'), //'<a href="\1">\1</a>', anchor('\1', '\2'), //'<a href="\1">\2</a>', '<a href="\1">\1</a>', '<a href="\1">\2</a>', '<h1>\1</h1>', '<h2>\1</h2>', '<h3>\1</h3>', '<ul>\1</ul>', '<li>\1</li>', '<p>\1</p>' //parse_quote('\2', '\3') ); $str = preg_replace($find, $replace, $str); //var_dump($matches); $str = preg_replace_callback("^(\[quote (thread_id|message_id)=([0-9]+)\])^", 'parse_quote', $str); $str = preg_replace("^\[\/quote\]^", "\n</div>", $str); return $str; } function parse_quote($matches){ $post_type = $matches[2]; $post_id = $matches[3]; $CI =& get_instance(); if($post_type == "thread_id"){ $CI->load->model('forums/thread'); $CI->thread->get_info($post_id); if($CI->thread->error == NULL){ $thread = $CI->thread->info; $str = " <div class=\"quote\"> <div class=\"heading\"> <h1>Posted by ".$thread['author']['display_name']." about ".$thread['date_posted']." ago.</h1> </div> <div class=\"body\"> ".$thread['content_parsed']." </div> "; } else { show_error($CI->thread->error); } } else if($post_type == "message_id"){ $CI->load->model('forums/message'); $CI->message->get_info($post_id); if($CI->message->error == NULL){ $message = $CI->message->info; $str = " <div class=\"quote\"> <div class=\"heading\"> <h1>Posted by ".$message['author']['display_name']." about ".$message['date_posted']." ago.</h1> </div> <div class=\"body\"> ".$message['content_parsed']." </div> "; } } return $str; } Model thread->get_info() function get_info($thread_id){ $this->db->select('board_id, thread_id, author_id, title, content, UNIX_TIMESTAMP(date_posted) AS date_posted, views, status, type'); $this->db->from('forum_threads'); $this->db->where('thread_id', $thread_id); $this->db->limit(1); if($query_thread = $this->db->get()){ if($query_thread->num_rows() > 0){ $thread = $query_thread->row_array(); $this->member->get_info($thread['author_id']); $author = $this->member->info; $update = ''; /* Get the total number of replies to this thread, excluding the first message. */ $total_replies = 0; $this->db->select('thread_id, message_id'); $this->db->from('forum_messages'); $this->db->where('thread_id', $thread['thread_id']); if($query_replies = $this->db->get()){ $total_replies = $query_replies->num_rows(); } $thread_update = ""; /*Get the info of the thread's last message... */ $this->db->select('thread_id, message_id, author_id, date_posted, date_modified'); $this->db->from('forum_messages'); $this->db->where('thread_id', $thread['thread_id']); $this->db->order_by('message_id', 'desc'); $this->db->limit(1); if($query_last_msg = $this->db->get()){ if($query_last_msg->num_rows() > 0){ $last_msg = $query_last_msg->row_array(); $this->member->get_info($last_msg['author_id']); $author = $this->member->info; if($last_msg['date_modified'] == NULL){ $update_time = $last_msg['date_posted']; } else { $update_time = $last_msg['date_modified']; } $thread_update = $author['member_profile'].' posted about '.timespan(strtotime($update_time), time()).' ago.'; } } $has_new_posts = FALSE; /* Determine whether or not there are new messages in this thread for the current user... */ $this->db->select('mark_id, thread_id, member_id, UNIX_TIMESTAMP(date_marked) AS date_marked'); $this->db->from('forum_thread_marks'); $this->db->where('thread_id', $thread['thread_id']); $this->db->where('member_id', $this->user['id']); $this->db->order_by('date_marked', 'desc'); $this->db->limit(1); if($query_mark = $this->db->get()){ if($query_mark->num_rows() > 0){ $mark = $query_mark->row_array(); $this->db->select('message_id, thread_id, UNIX_TIMESTAMP(date_posted) AS date_posted'); $this->db->from('forum_messages'); $this->db->where('thread_id', $thread['thread_id']); $this->db->where('date_posted > '.$mark['date_marked']); if($query_new = $this->db->get()){ if($query_new->num_rows() > 0){ $has_new_posts = TRUE; } } } } /* Put it all together and we get... the array of information! */ $info = array( 'id' => $thread['thread_id'], 'title' => $thread['title'], 'author' => $author, 'content' => $thread['content'], 'content_parsed' => parse_bb($thread['content']), 'date_posted' => timespan(strtotime($thread['date_posted']), time()), 'board_id' => $thread['board_id'], 'status' => $thread['status'], 'update' => $thread_update, 'reply_count' => $total_replies, 'view_count' => $thread['views'], 'uri' => 'forums/threads/'.url_title($thread['title']).'/'.$thread['thread_id'], 'actions' => $this->actions($thread['thread_id']), 'has_new_posts' => $has_new_posts ); } else { $this->error = "The thread you have requested no longer exists in the database."; } } else { $this->error = "An error occurred while attempting to retrieve the data of the requested thread: ".$this->db->_error_message(); } $this->info = $info; }Model message->get_info() function get_info($message_id){ $this->db->select('message_id, thread_id, author_id, modifier_id, content, date_posted, date_modified'); $this->db->where('message_id', $message_id); $this->db->limit(1); if($query = $this->db->get('forum_messages')){ if($query->num_rows() > 0){ $message = $query->row_array(); $this->member->get_info($message['author_id']); $author = $this->member->info; $info = array( 'id' => $message['message_id'], 'thread_id' => $message['thread_id'], 'author' => $author, 'content' => $message['content'], 'content_parsed' => parse_bb($message['content']), 'date_posted' => timespan(strtotime($message['date_posted']), time()), 'actions' => $this->actions($message['message_id']) ); if($message['modifier_id'] == NULL){ $last_modified = ''; } else { $this->member->get_info($message['modifier_id']); $modifier = $this->member->info; $modification = array( 'by' => $modifier, 'date' => $message['date_modified'] ); } $this->info = $info; } else { $this->error = "The message you are attempting to retrieve does not exist in the database."; } } else { $this->error = $this->db->_error_message(); } }
  10. Hello, all! I am trying to write my own private messaging chat script for my website. I would like the "Inbox" to display the "conversations" with other users, but only by the last message of the conversation. I found a thread on stackoverflow and used a query suggested on that page. The query doesn't find any rows. http://stackoverflow.com/questions/10520246/mysql-query-to-group-messages-into-a-conversation-and-show-the-first-in-the-inbo $query_convos = " SELECT m1.message_id, m1.author_id, m1.recipient_id, m1.content, UNIX_TIMESTAMP(m1.date_sent) FROM private_messages AS m1 WHERE m1.date_sent = ( SELECT max(m1.date_sent) FROM private_messages AS m2 WHERE m1.author_id = m2.author_id AND m1.recipient_id = m2.recipient_id AND (author_id = ".$this->user['id']." OR recipient_id = ".$this->user['id'].") ) GROUP BY m1.author_id, m1.recipient_id ORDER BY m1.message_id DESC LIMIT 10 ";
  11. I am developing a PHP application that will have a member login and profile system. I have created a table for storing member's experience(exp) for certain actions. For example, if they create a new forum thread, add a comment to an article, etc, they will earn a certain amount of exp. I have found a formula that will calculate the member's exp level. I need to find their progress percentage based on the exp required for the next level. For example, if they are level 1 with 75 exp and it takes 100 exp to level up to 2, then they are 75% of the way to level 2. What this formula I need should do is find out the total exp needed for the next level. I can get the percentage from there. Below is the formula I currently am using. Any help is greatly appreciated! $experience = 18714; $level = pow(($experience / 1000), ( 7 / 10)); $level = floor($level); echo $experience; // Would output '7' PS: Any input on adjusting the $level formula to make it harder or easier to level up is welcome!
  12. I am working on developing a custom forum with codeigniter. I am almost completely finished with it, however, the only problem I am running into is parsing a bbcode quote tag. I use two different arrays to supply to the preg_replace function that will replace the bbcodes with html. The function I have written successfully replaces the
  13. Thank you, kicken! Your query worked absolutely beautifully!
  14. Will changing date_posted to DATETIME or TIMESTAMP work with a unix timestamp? E.G. what's produced with php's time() function.
  15. I am trying to create a custom forum with CodeIgniter. I have 3 primary tables in this scenario: boards, threads, and messages. I want to get all the threads in the board that a user is viewing. If I use a plain old select query with ORDER BY thread_id DESC, all that does is obviously orders them by when they were posted in descending order. I want to order the threads by when their last message was posted. For example, if a user posts a thread called "Thread A", and after that a user posts "Thread B", in the original query would display Thread B followed by Thread A. But if someone posts a reply to Thread A before a reply is posted to Thread B, then Thread A should be at the top. I hope this makes sense. Below is the query I am currently working with. $query = " SELECT t.board_id, t.thread_id FROM forum_threads AS t LEFT JOIN ( SELECT m.thread_id, m.message_id FROM forum_messages AS m WHERE m.thread_id = t.thread_id ORDER BY m.message_id DESC LIMIT 1 ) AS q ON m.thread_id = t.thread_id WHERE t.board_id = ".$board_id." ORDER BY q.date_posted DESC LIMIT ".$starting.", ".$this->user['results_per_page']; This is returning the error Unknown column 't.thread_id' in 'where clause' CREATE TABLE IF NOT EXISTS `forum_messages` ( `message_id` int(15) NOT NULL AUTO_INCREMENT, `thread_id` int(15) NOT NULL, `author_id` int(15) NOT NULL, `content` text NOT NULL, `date_posted` text NOT NULL, PRIMARY KEY (`message_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `forum_threads` ( `thread_id` int(15) NOT NULL AUTO_INCREMENT, `board_id` int(15) NOT NULL, `author_id` int(15) NOT NULL, `title` text NOT NULL, `date_posted` text NOT NULL, `views` int(15) NOT NULL, PRIMARY KEY (`thread_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `forum_boards` ( `board_id` int(15) NOT NULL AUTO_INCREMENT, `category_id` int(15) NOT NULL, `position` tinyint(1) NOT NULL, `title` text NOT NULL, `description` text NOT NULL, `status` tinyint(1) NOT NULL, PRIMARY KEY (`board_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; I have been trying to find a solution to this problem for the last week or so... It has been really frustrating to find it. Any help would be greatly appreciated!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.