Jump to content

ShoeLace1291

Members
  • Posts

    401
  • Joined

  • Last visited

Everything posted by ShoeLace1291

  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!
  16. A more clarifying statement: http://www.php.net/manual/en/session.examples.basic.php
  17. I was tired of having to type out the same code over and over to report mysql errors while indicating where they occur. So I decided to write my own function to handle the errors. However, it doesn't seem to be working properly. function DbQuery($query, $file, $line){ if($execute = mysql_query($query)){ return $execute; } else { return ' <p>You have an error in a mysql query.</p> <p>File: '.$file.'</p> <p>Line: '.$line.'</p> <p>Query: '.$query.'</p> '; } } I tested it out with this bit of code. When everything is ok with the query itself, the function works perfectly. If there is a syntax error, I get a php error saying that mysql_num_rows expects parameter 1 to be resource... which I know why, but I can't figure out how to skip that part, and go right to my custom error. $query = DbQuery(" SELECT member_id, email_address, recieve_member_emails, recieve_admin_emails FROM ".DB_PREFIX."members WHERE member_id = ".$mbr['id']." LIM 1", __FILE__, __LINE__); if(mysql_num_rows($query) > 0){ $member = mysql_fetch_assoc($query); var_dump($member); } Thank you for your time.
  18. I recently had to reinstall my WAMP server. So to back up my stuff, I first copied my www folder. Then, I stupidly copied the actual database files from wamp/bin/mysql/data/databasename instead of just creating an sql file with phpmyadmin. When I go to the database in phpmyadmin, it doesn't show any tables, but all of the .fm files are there in the appropriate folders. Is there a way to tell phpmyadmin or mysql or whatever that these files need to be associated with their databases?
  19. So I've been using virtual hosts with Apache in WAMP for the past couple of weeks. I would like to know how to make these vHosts show up on the WAMP server homepage. You know; where it says "Tools" and lists phpinfo and phpmyadmin, then "Your Projects" below that, but then there is always that blank list of vHosts. Anyone know how to make your vHosts appear there? I have tried setting the ServerAlias argument in the httpd-vhosts.conf file, but that doesn't work at all. Any ideas?
  20. So, I am trying to write a script that routes URI's to the appropriate file. I am not using classes, only files(source) and functions(action). I've had a bunch of trouble with getting this to work, and I can't seem to figure out the problem. Basically, I want to route the first segment to a source file if it is a valid source. If a second segment exists and is a valid action(function), then that function will be loaded. So say I have a source file called members.source.php and there is a function called register in it. A user will have to access the uri http://localhost/mya...embers/register to access that page. or myapp/members would be directed to the "_default" action(function). myapp/members/SomeCoolMember would redirect to members.source.php with the viewprofile action(function). I hope you understand what I am trying to get at here. For whatever reason, the variable "source" is not being defined. Here's what I have as my index.php file. $uri_segments = $_SERVER['REQUEST_URI']; $uri_segments = str_replace('/Base%20Command/', '', $uri_segments); if(strlen($uri_segments) == 0){ $uri_segments = array(); } else { $uri_segments = explode('/', $uri_segments); } if(count($uri_segments) > 0){ foreach($uri_segments as $key => $segment){ if(!preg_match('^[a-z0-9_-]^', $segment)){ die('Could not accept provied URI string... the string contains invalid characters.<br>'.$segment); } else { if(validSource($segment) && empty($source)){ $source = $segment; } else if(validDirectory($segment) && empty($source)){ $source = $segment; } else if(isset($source) && empty($action)){ if(validFunction($segment)){ $action = $segment; } else { die('404 Error: Page not found. 001'); } } } } } else { $source = 'index'; $action = '_default'; } function validSource($sourceName){ if(file_exists(DOC_ROOT.'/sources/'.$sourceName)){ return TRUE; } else { return FALSE; } } function validDirectory($dirName){ if(is_dir(DOC_ROOT.'/sources/'.$dirName)){ return TRUE; } else { return FALSE; } } function validFunction($fnc){ if(function_exists($fnc)){ return TRUE; } else { return FALSE; } }
  21. I am trying to write a script that writes url's to the correct "source" file. Basically, I want to write a script that works kind of like CodeIgniter's URI routing class, but not as complex. I want to find what class and what method to use, but instead of classes and methods, I am using just files and functions. For example: forums/threads/some-cool-thread/2051 would route to sources/forums/threads.source.php with a couple of extra segments. another example: members/register would route to sources/members.php with the register function since members is a file within the sources directory and not a directory in itself. For some reason, I am having a bunch of trouble with coming up with the logic for what I want to do. If someone could maybe layout a flow chart or something just to give me an idea, that would be wonderful!
  22. I am trying to give my users the ability to share one of my articles on their facebook page, but I am having a few problems. I don't believe that the problem lies within my app, because it works perfectly in the example... there's just something wrong with my code. The getLoginUrl variable as an anchor just takes me back to the same exact page within my site, but it still tells me i'm not logged in. It never redirects me. This is the code I have so far: function facebook($article_id){ $config = array( 'appId' => '276870792431073', 'secret' => '8d49eee575413fb9a8063d22f65dbf6a' ); $this->load->library('facebook', $config); $user = $this->facebook->getUser(); if ($user) { try { // Proceed knowing you have a logged in user who's authenticated. $user_profile = $this->facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); $user = null; } } if($user){ $article = $this->article->fetch_article($article_id); $config = array( 'message' => 'I just read an '.anchor('articles/'.url_title($article['title']).'/'.$article_id, 'article').' on '.anchor('', 'TrackTheOutbreak.com').'!', ); $this->facebook->api('/me/feed', 'post', $config); } else { $data['MESSAGE_TITLE'] = 'Authentication Error'; $data['MESSAGE_TEXT'] = 'You must be logged into an existing Facebook account to use this feature. Click '.anchor($this->facebook->getLoginUrl(), 'here').' to login.'; $this->parser->parse('error_body.tpl', $data); } }
  23. This is what my tables actually look like: CREATE TABLE `articles` ( `article_id` int(15) NOT NULL AUTO_INCREMENT, `parent_id` int(15) NOT NULL, `author_id` int(15) NOT NULL, `title` text NOT NULL, `content` text NOT NULL, `date_posted` text NOT NULL, `views` int(15) NOT NULL, `preview` text NOT NULL, `status` tinyint(1) NOT NULL, `modified_date` text NOT NULL, PRIMARY KEY (`article_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `article_tags` ( `tag_id` int(15) NOT NULL AUTO_INCREMENT, `article_id` int(15) NOT NULL, `keyword` varchar(250) NOT NULL, PRIMARY KEY (`tag_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; This is the query I have written so far, and it does not work... SELECT A2.article_id, count(A2.article_id) AS matches FROM article_tags AS A1 JOIN article_tags ON (A1.keyword = A2.keyword AND A1.article_id != A2.article_id) JOIN articles ON (A2.article_id = A.article_id) AS A WHERE A1.article_id = 1 GROUP BY A2.article_id ORDER BY matches DESC LIMIT 5
  24. So, I have a database with a table called artcles, and also a table called article tags. When a user views an article, I want to query up to five articles that have tags similar to the one that is being viewed. Here are my two tables: table: articles - article_id // Primary, unique, auto increment - title - content table: article_tags - tag_id // Primary, unique, auto increment - article_id //Relational to the above table - keyword I've tried writing my own queries, but they never seem to work. I would like to use joins in the query instead of resorting to using CSV's and LIKE. Any help would be 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.