Jump to content

jimboppin

Members
  • Posts

    41
  • Joined

  • Last visited

Everything posted by jimboppin

  1. hi, im still trying to get my function to work.. i have done this so far its not working the way i want but im getting closer i just cant get it to work properly. function get_media($media_cat, $display_recent) { global $Parsedown, $media_id; if (!empty($media_id)) { if ($media_id == $media_cat) { $display_recent = null; } } $directory = MEDIA_BASEDIR.$media_cat.'/'; $files = array(); $files = glob($directory.'*.txt'); foreach ($files as $file) { $line = file($file); $date_time = $line[0]; $date_time = $Parsedown->text($date_time); uasort($files, function ($a, $b) { global $date_time; return strcmp ($a[$date_time], $b[$date_time]); }); $recent_content = array_slice($files, 0, $display_recent); foreach ($recent_content as $media) { $content = file_get_contents($media); $media_title = basename($media); $media_title = basename($media, '.txt'); thememediatop($media_title, $media_cat); echo $Parsedown->text($content); thememediabottom($date_time); } } } here is the txt file this is a example.. 02/03/2017 5:12pm everything from here on is content some content more content i think its got somthing to do with return strcmp ($a[$date_time], $b[$date_time]); because i get this error String offset cast occurred please help me with what i want here. thanks
  2. then i noticed it was wrong...
  3. heres what i did.. obviousley its wrong.
  4. i did try and implement this, but its not what im looking for.. i just need to read the date and time from the first line and use that line to order my files, i dont see the problem. im not here to argue ill just move on then.
  5. thanks i know its alot better to have a database but its alot more work when i can just make a little function to collect a text file and its contents, also the speed difference sql and txt files is just stupidly fast so for a site that dose not require users or admin i would much rather stick to this function. sorry to take 2 steps back, if you cant or dont want to help me thats fine i can seek help some where else, no affence. i just need to read the first line that will have a date format on it.. read it and arange by that date from the top line then output while ignoring the first line for content. thanks again.
  6. also tutorials and examples are out of date that i found...
  7. Hi, thankyou for reply, i do have sqli, i was on that track but i couldont work out how to get it secure when posting username and password etc i dont want my username or password sniffed out when its going thru to the script, i honestly would need help to get me going on somthing like that, i would need a secure basic sql login and then how to post to the database securley when adding data to it... this is what made me try and make it more simple because i live in notepad++ and filezilla it just made sence to me. im willing to learn if some one is willing to help me get going with it i can self teach the rest but security makes me on edge
  8. sorry i see how that works now, i was hopeing to be able to just upload a txt file no worries, and to do that the only thing i can think of is to put the date and time in the first line of the text file and then read the first line to sort by date first line being line[0] i know how to read the first line im just stuck how to use it in the uasort function thanks
  9. hi im trying to implement this to my code as i found out that if i backup my site then upload it all my news is reset and gets mixed up.. how do i format my txt file so this can read it and sort it out? i imagin somthing like this... date>27/02/2017 6:48pm anything after the above line is content some contentsome contentsomesome contentsome some contentsome contentsome some contentsome content some contentsome content some contentsome content some contentsome contentsome content heres the function... function get_media($media_cat, $display_recent) { global $Parsedown, $media_id; if (isset($media_id)) { if ($media_id == $media_cat) { $display_recent = null; } } $directory = MEDIA_BASEDIR.$media_cat.'/'; $files = array(); $files = glob($directory.'*.txt'); uasort($files, function ($a, $b) { return strcmp ($a['date'], $b['date']); }); $recent_content = array_slice($files, 0, $display_recent); foreach ($recent_content as $media => $fdata) { $content = file_get_contents($fdata); $media_title = basename($fdata); $media_title = basename($fdata, '.txt'); if (file_exists($fdata)) { $date_time = date ('F d Y H:i:s', filectime($fdata)); } THEMEMEDIATOP($media_title, $media_cat); echo $Parsedown->text($content); THEMEMEDIABOTTOM($date_time); } } thanks again
  10. i have this in my mainfile require_once INCLUDES_BASEDIR.'_parsedown.php'; $Parsedown = new Parsedown(); $Parsedown->setMarkupEscaped(true); and this is another update on my function to collect news or announcements etc function get_media($media_cat, $display_recent) { global $Parsedown; if (isset($_GET['id'])) { $media_id = htmlentities($_GET['id'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } if (isset($media_id)) { if ($media_id == $media_cat) { $display_recent = null; } } $media_dir = 'Media/'.$media_cat.'/'; $directory = PAGES_BASEDIR.$media_dir; $files = array(); $files = glob($directory.'*.txt'); usort($files, function($x, $y) { return filemtime($x) < filemtime($y); }); $recent_content = array_slice($files, 0, $display_recent); foreach ($recent_content as $media) { $content = file_get_contents($media); $media_title = basename($media); $media_title = basename($media, '.txt'); if (file_exists($media)) { $date_time = date ('F d Y H:i:s', filemtime($media)); } THEMEMEDIATOP($media_title); echo $Parsedown->text($content); THEMEMEDIABOTTOM($date_time); } } then i just add this into a page i want to show my content <?php get_media('News', 2);?> other then the permissions is this all ok now? i will look into the permissions thanks
  11. markdown is here i hope iv got it right function get_media($media_cat) { global $Parsedown; if (isset($_GET['id'])) { $media_id = htmlentities($_GET['id'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } if (isset($media_id)) { if ($media_id == $media_cat) { $media_dir = 'Media/'.$media_cat.'/'; $directory = PAGES_BASEDIR.$media_dir; $files = array(); $files = glob($directory.'*.txt'); usort($files, function($x, $y) { return filemtime($x) < filemtime($y); }); foreach ($files as $media) { $content = file_get_contents($media); $media_title = basename($media); $media_title = basename($media, '.txt'); if (file_exists($media)) { $date_time = date ('F d Y H:i:s', filemtime($media)); } THEMEMEDIATOP($media_title); echo $Parsedown->text($content); THEMEMEDIABOTTOM($date_time); } } } } also can you point me in the right direction for windows security regarding the files...
  12. there is a .htaccess file in all directories aswell denying all access the only place i found i cant use them is in my css directory
  13. hi, i have decided to change my files to html and changed the code, is this safe? function get_media($media_dir) { $directory = PAGES_BASEDIR.$media_dir; $files = array(); $files = glob($directory.'*.html'); usort($files, function($x, $y) { return filemtime($x) < filemtime($y); }); foreach ($files as $media) { $content = file_get_contents($media); $clean_content = htmlspecialchars($content, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); $clean_content = strip_tags($content, '<br><p><a><img><h1><h2><h3><h4>'); $media_title = basename($media); $media_title = basename($media, '.html'); if (file_exists($media)) { $date_time = date ('F d Y H:i:s', filemtime($media)); } THEMEMEDIATOP($media_title); echo $clean_content; THEMEMEDIABOTTOM($date_time); } } thanks
  14. cool, ill look into them thanks again.
  15. not realy, i didont look at it like that... i wanted to use a txt file just because there just articles that consist of <br /> etc nothing big... could i not whitelist some of these ? commonly used html tags? and the server im on is windows so im not sure how the file permissions work... i only see black blocks and xxx in filezilla rather then 755 etc..
  16. hi thankyou for the advice, its just a small project im working on, theres no edit or delete funtionality going into it... i have implemented what you suggested here function get_media($media_dir) { $directory = PAGES_BASEDIR.$media_dir; $files = array(); $files = glob($directory."*.txt"); usort($files, function($x, $y) { return filemtime($x) < filemtime($y); }); foreach ($files as $media) { $content = file_get_contents($media); $media_title = basename($media); $media_title = basename($media, ".txt"); if (file_exists($media)) { $date_time = date ("F d Y H:i:s", filemtime($media)); } THEMEMEDIATOP($media_title); echo htmlspecialchars($content, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); THEMEMEDIABOTTOM($date_time); } } but its showing up the html in the page now is there a way to auto apply the html so i can just create a text document from within windows and just upload it no worries... i changed this return filemtime($x) - filemtime($y); but it just changed it back to ABC and not last date modified... thanks
  17. hi, here is what i have managed to come up with and this is working. however is it valid and clean? function get_media($media_dir) { $directory = PAGES_BASEDIR.$media_dir; $files = array(); $files = glob($directory."*.txt"); usort($files, function($x, $y) { return filemtime($x) < filemtime($y); }); foreach ($files as $media) { $media_title = basename($media); $media_title = basename($media, ".txt"); if (file_exists($media)) { $date_time = date ("F d Y H:i:s", filemtime($media)); } THEMENEWSTOP($media_title); require_once $media; THEMENEWSBOTTOM($date_time); } } thanks
  18. ok cool ill do my best to try and put all that together and switch to glob, thankyou.
  19. hi there, im making a media page on my static site that has no database, i have managed to put this code together so that i can add text files into a directory and show all files content on a page.. my problem is i cant work out how to get it all in order, it seems that by default the order is alphabetical and i need it to be by the last modified date... any help would be great as im a bit stuck my function: function get_media($media_dir) { $directory = PAGES_BASEDIR.$media_dir; $dir = opendir($directory); while (($file = readdir($dir)) !== false) { $filename = $directory . $file; $type = filetype($filename); if ($type == 'file') { $contents = file_get_contents($filename); $items = explode('¬', $contents); $media_title = basename($filename); $media_title = basename($filename, ".txt"); if (file_exists($filename)) { $date_time = date ("F d Y H:i:s", filemtime($filename)); } foreach ($items as $media) { THEMENEWSTOP($media_title); echo ($media); THEMENEWSBOTTOM($date_time); } } } closedir($dir); } Thanks
  20. you said "WTF are these for?" like im suposed to know... cos your better you like to make yourself feel good laughing in your chair becouse some one else dosont know how to write code? witch is why im here to learn not be spoke to like a fool. im off. thankyou for the help to this point ill find my help else where.
  21. <?php // Directory Of Page_Include const INCLUDE_BASEDIR = __DIR__.'/page_include/'; // Directory Of Pages const PAGES_BASEDIR = __DIR__.'/pages/'; require_once INCLUDE_BASEDIR.'page_config.php'; if ($detect->isMobile()) { header('Location: mobile.php'); exit(0); } const PAGES = [ // Array Of Active Pages 'home', 'our_world', ]; if (!isset($_GET['page'])) { // Default Index Page require PAGES_BASEDIR.$DEFAULT_PAGE; } else if (in_array($_GET['page'], PAGES, true) && is_readable(PAGES_BASEDIR.$_GET['page'].'.php')) { // Displays The Called Link require PAGES_BASEDIR.$_GET['page'].'.php'; } else { http_response_code(404); // Display Error404 Page require PAGES_BASEDIR.$ERROR_404; } //END OF CONTENT require INCLUDE_BASEDIR.'page_footer.php'; ?> is this better? if (!isset($_GET[''.$LINK_NAME.''] ^ ^ | | +------------+-- WTF are these for? not for anything i was just playign with it to see what i can do.. LEARNING OVER HERE! wtf are you so rude for? arse. Jimbo.
  22. haha ok maybe not need to do that that... empty string? i dont understand? jimbo.
  23. i keep messing with it lol, how am i doing ??? <?php // Directory Of Page_Include const INCLUDE_BASEDIR = __DIR__.'/page_include/'; // Directory Of Pages const PAGES_BASEDIR = __DIR__.'/pages/'; $FILE_EXTENTION = '.php'; $ERROR_404 = 'Error404'.$FILE_EXTENTION.''; $DEFAULT_PAGE = 'home'.$FILE_EXTENTION.''; $LINK_NAME = 'page'; require_once INCLUDE_BASEDIR.'page_config'.$FILE_EXTENTION.''; if ($detect->isMobile()) { header('Location: mobile'.$FILE_EXTENTION.''); exit(0); } const PAGES = [ // Array Of Active Pages 'home', ]; if (!isset($_GET[''.$LINK_NAME.''])) { // Default Index Page require PAGES_BASEDIR.$DEFAULT_PAGE; } else if (in_array($_GET[''.$LINK_NAME.''], PAGES, true) && is_readable(PAGES_BASEDIR.$_GET[''.$LINK_NAME.''].''.$FILE_EXTENTION.'')) { // Displays The Called Link require PAGES_BASEDIR.$_GET[''.$LINK_NAME.''].''.$FILE_EXTENTION.''; } else { http_response_code(404); // Display Error404 Page require PAGES_BASEDIR.$ERROR_404; } //END OF CONTENT require INCLUDE_BASEDIR.'page_footer'.$FILE_EXTENTION.''; ?> Jimbo
  24. is my code ready for best answer ? Its works perfect for me i just want it to be clean so people can use it... Jimbo.
×
×
  • 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.