Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Simple and tiny blog - WIP
New on LowEndTalk? Please Register and read our Community Rules.

Simple and tiny blog - WIP

netomxnetomx Moderator
edited April 2012 in General

Hello. @Daniel gave me an idea of a simple blog. So, I was thinking about it, what about any webserver+PHP? No MySQL, No SQLite. So I started... this is what I got so far:

<?php
include('header.php');
exec("ls posts/*.txt", $output);
if (!$output)
echo "No posts, yet!"; //o incluir un php con una informacion de nuevo blog
else
{
echo "<div style='width:600px;'>";
for ($x=0; $x<4; $x++){
if (count($output)<=$x)
break; //if there's less posts than the post per pages, it will stop
include($output[$x]);
echo "<br>";
} //fin del FOR
} //fin del ELSE
//include("footer.php");
?>

What's missing?
-The "older posts" link. I will update it later on.
-Print the date. don't know if get it via filemtime() or manually print it on the post.
-Basic admin. Get posts, previews, delete, edit, new post (using the NicEdit).

what do you think? Any ideas?

Thanked by 3OneTwo Steve81 seikan

Comments

  • Nice one. Go ahead and make a nice more robust system!!

  • VPNshVPNsh Member, Host Rep

    Copy @sleddog - Blite is lovely (y)

  • raindog308raindog308 Administrator

    While looking for this...

    http://stevehanov.ca/blog/index.php?id=49 ("A complete blogging system in 1900 lines of php")

    ...I found this:

    https://github.com/sadasant/b ("A blog with 100 lines of not so obfuscated code using PHP, JSON, Markdown, Facebook Meta Tags and Disquss.")

    Thanked by 1Steve81
  • @raindog308 said: https://github.com/sadasant/b ("A blog with 100 lines of not so obfuscated code using PHP, JSON, Markdown, Facebook Meta Tags and Disquss.")

    O-M-F-G

  • Exactly, that's pretty impressive. It's just dark as hell.

  • There's also this.

  • debugdebug Member
    edited April 2012

    Pretty good. Use PHP's glob function instead of exec to list the files (Theres another way, but off my head I can not remember).

  • netomxnetomx Moderator

    @debug said: Pretty good. Use PHP's glob function instead of exec to list the files (Theres another way, but off my head I can not remember).

    I also did a quick one, loosely based on yours. Feel free to use it for ideas. It offers a "little" bit more functionality (and served as a way for me to wake up :P)

    https://gist.github.com/2364240

    (Also not tested, I'm using a hotel's wifi and I cant be bothered to install an apache-php install. Way too slow)

    Lol, it is like mine! thanks 4 the idea of glob, I will research... it will help to make it portable

  • debugdebug Member

    @netomx said: Lol, it is like mine! thanks 4 the idea of glob, I will research... it will help to make it portable

    I jumped the gun on glob way too early. Your better off using DirectoryIterator. Here's an example code (thanks stackoverflow! http://stackoverflow.com/questions/7642191/php-directoryiterator-sort-files-by-date )

    $files = array();
    $dir = new DirectoryIterator('.');
    foreach ($dir as $fileinfo) {     
       $files[$fileinfo->getMTime()] = $fileinfo->getFilename();
    }
    
    ksort($files);
    

    Just change the arg passed to the DirectoryIterator to the directory. Then it will be sorted w/ ksort, based on the modified time.

  • netomxnetomx Moderator

    @debug said: I jumped the gun on glob way too early.

    Why? glob seems fine. I have updated the code, and made the new post page too :) I will fix the "older posts" tomorrow, and some template thing and publish it :)

    I like it, sooo f*cking simple, using just php+text files

  • twaintwain Member

    @netomx said: What's missing?
    -The "older posts" link. I will update it later on.
    -Print the date. don't know if get it via filemtime() or manually print it on the post.
    -Basic admin. Get posts, previews, delete, edit, new post (using the NicEdit).

    You could just use this for the admin part; to edit, post new etc.

    https://github.com/rocktronica/OneFileCMS

  • You should ideally load the content before you load the header, so you can load the blog post into the page name?

  • exussumexussum Member
    edited April 2012

    You can remove that if statement being run each loop by something like

    $ppp=4;
    for ($x=0; $x<min($ppp,count($output)); $x++){

    Which only counts the number of text files once. and takes $ppp out (posts per page)

    When you add pages you can multiply the needed parts for the loop to work

    maybe similar to

    for ($x=($pageno-1)$ppp; $x<min($pageno$ppp,count($output)); $x++){

    where $pageno is >1 ?

    not sure why the times astrix sign is not showing between both $pageno and $ppp there should be one

  • netomxnetomx Moderator
    edited April 2012

    @twain said: You could just use this for the admin part; to edit, post new etc.

    https://github.com/rocktronica/OneFileCMS

    Thank you, I'll check it, although I want to finish what I started :) I had made the new post one.

    @Daniel said: You should ideally load the content before you load the header, so you can load the blog post into the page name?

    I was thinking about that, making the first line of the post as the page name. Maybe when I finish the basic things. I have made the post show (changed a little bit the code), and make new post, allso basic, but working :). Then, I'm gonna implement CSS.

    @exussum said: $ppp=4;

    for ($x=0; $x<min($ppp,count($output)); $x++){

    Which only counts the number of text files once. and takes $ppp out (posts per page)

    When you add pages you can multiply the needed parts for the loop to work

    maybe similar to

    for ($x=($pageno-1)$ppp; $x<min($pageno$ppp,count($output)); $x++){
    where $pageno is >1 ?

    It's too early for me to process your information, but it seems that the add pages is what I am trying to achieve. The $ppp is the next thing I'm gonna make, maybe even taking out some things into a config.php file. Look at this code now:

    <?php
    include('header.php');
    date_default_timezone_set("America/Monterrey");
    $output = glob("posts/*.txt");
    if (!$output)
    echo "No posts, yet!"; //o redireccionar los resultados a un archivo de nuevo
    else {
    echo "<div id='posts' style='width:650px;'>";
    $numeropost = count($output);
    for ($x=$numeropost-1; $x>$numeropost-6; $x--){
    if ($x<0)
    break; //if there's less posts than the post per pages, it will stop
    echo date("d/m/o H:i ",filemtime($output[$x]))."<br>";
    include($output[$x]);
    echo "
    "; } //fin del FOR if ($x>=0) //aqui, en vez de esto, deberia de dividir el post donde se quedó, entre //el total, para saber en que página va, y mandarlo en el index. echo "< a href='index.php?p=' >Ver posts mas viejos< / a >"; } //fin del ELSE //include("footer.php"); ?>
  • netomxnetomx Moderator

    btw, this is my new posts php, is there any problem with it? (code injection)

    <?php
    if (isset($_POST["texto"])) {
    $output = glob("posts/*.txt");
    if (!$output)
    $numero=0;
    else
    $numero=count($output);
    if (file_put_contents("posts/".$numero.".txt", $_POST["texto"]))
    echo "Escrito archivo ".$numero.".txt<br>";
    else
    echo "Error al escribir archivo
    "; } ?> bkLib.onDomLoaded(nicEditors.allTextAreas); " method="post">
  • debugdebug Member

    @netomx said: Why? glob seems fine.

    Depends on how you name your files. If you name then by ids (like 1, 2, 3), then its fine. However, if it's by name, you'll want to use the code I posted to sort by the file modified time.

  • netomxnetomx Moderator

    @debug said: Depends on how you name your files. If you name then by ids (like 1, 2, 3), then its fine. However, if it's by name, you'll want to use the code I posted to sort by the file modified time.

    Yeap, they are just numbers, so it is fine :)

  • @netomx said: It's too early for me to process your information, but it seems that the add pages is what I am trying to achieve

    Your if statement gets run and checked when it doesnt need to, Have as as the for argument and it wont run extra times when it doesnt need to. Ive just tested it and it works well could do a minimum function containing the amount of pages, so if a number too high is entered it just shows the last page (so page 999999 would show page 2 assuming 4 per page and 6 entries)

  • netomxnetomx Moderator

    @exussum said: Your if statement gets run and checked when it doesnt need to, Have as as the for argument and it wont run extra times when it doesnt need to. Ive just tested it and it works well could do a minimum function containing the amount of pages, so if a number too high is entered it just shows the last page (so page 999999 would show page 2 assuming 4 per page and 6 entries)

    Now I get it! with the min() function, sorry, it was too late (10am) and on the work, but my mind was closed hahaha. I will implement it later on :) btw I think that I had covered the basic things:

    index.php

    <?php
    include('header.php');
    $ppp=5; //posts per page
    date_default_timezone_set("America/Monterrey");
    $output = glob("posts/*.txt");
    if (!$output)
    echo "No posts, yet!"; //o redireccionar los resultados a un archivo de nuevo
    else {
    echo "<div id='posts' style='width:650px;'>";
    if (isset($_GET['p']))
    $numeropost = $_GET['p']+1;
    else
    $numeropost = count($output);
    for ($x=$numeropost-1; $x>$numeropost-$ppp-1; $x--){
    if ($x<0)
    break; //if there's less posts than the post per pages, it will stop
    echo date("d/m/o H:i ",filemtime($output[$x]))."<br>";
    include($output[$x]);
    echo "
    "; } //fin del FOR if ($x>=0) //aqui, en vez de esto, deberia de dividir el post donde se quedó, entre //el total, para saber en que página va, y mandarlo en el index. echo "< a href='index.php?p=".$x."' >Ver posts mas viejos< / a >"; } //fin del ELSE //include("footer.php"); ?>
  • @netomx open a github account or host the code somewhere dude.

  • netomxnetomx Moderator

    @OneTwo said: @netomx open a github account or host the code somewhere dude.

    i will, when the time comes

  • netomxnetomx Moderator

    btw, this is what I achieved: http://backup2.neto.mx/blog/

    btw, the borders are just to know if it is well-formatted. I will finish admin today and start the design process, cleaning the style things and use CSS.

Sign In or Register to comment.