Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need assistance With PHP Coding

    Hello everyone, I'm currently coding for PHP forum, and am lost as to how to have an admin post be automatically sent to the front page under an announcement section, anyone have an suggestions as to how to accomplish this for a PHP amateur like myself? :D

    PS. I am using the latest version of PHPBB forum.

  • #2
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    Did you try asking in PHPBB support forum?

  • #3
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Well you should be able to get the data easily enough with a simple query i have no idea how PHPBB forums database is structured. Maybe you could structure of the relevant tables? Tell you what ill try install it on my PC and work out a query for you. I'm pretty bored anyway.
    You can not say you know how to do something, until you can teach it to someone else.

  • #4
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Well first off you need the table phpbb_acl_users. That stores an entry for admins. But I need to know which admin groups you want to fetch posts from for you announcments. Is it a specific group or is it just main site admin. Here is a list of groups

    ROLE_ADMIN_STANDARD ROLE_ADMIN_FORUM ROLE_ADMIN_USERGROUP ROLE_ADMIN_FULL ROLE_USER_FULL ROLE_USER_STANDARD ROLE_USER_LIMITED ROLE_USER_NOPM ROLE_USER_NOAVATAR ROLE_MOD_FULL ROLE_MOD_STANDARD ROLE_MOD_SIMPLE ROLE_MOD_QUEUE ROLE_FORUM_FULL ROLE_FORUM_STANDARD ROLE_FORUM_NOACCESS ROLE_FORUM_READONLY ROLE_FORUM_LIMITED ROLE_FORUM_BOT ROLE_FORUM_ONQUEUE ROLE_FORUM_POLLS ROLE_FORUM_LIMITED_POLLS

    maybe role ROLE_ADMIN_STANDARD and ROLE_ADMIN_FORUM and ROLE_ADMIN_FULL
    You can not say you know how to do something, until you can teach it to someone else.

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Just a main site admin is what I need to obtain the posts for.

  • #6
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Ok so the table phpbb_acl_users is what links the users to the the admin group they belong to I am User with User_ID 2 and the in the phpbb_acl_roles tables users with role_id 5 are ROLE_USER_FULL which seems a bit stupid. I should be ROLE_ADMIN_FULL surley :/
    Can you run this script for me on your server maybe make a file or put it at top of index.php somewhere

    PHP Code:
    <?php
    //Fill in the variable bellow
    $your_site_username=""// Put the username you use to log in to the site between speach marks here

    require_once('config.php');

    $conn mysql_connect($dbhost$dbuser$dbpasswd);

    if (!
    $conn) {
        echo 
    "Unable to connect to DB: " mysql_error();
        exit;
    }
      
    if (!
    mysql_select_db($dbname)) {
    }

    $sql "SELECT ".$table_prefix."users.user_id AS USERID, ".$table_prefix."acl_users.auth_role_id AS ROLE FROM ".$table_prefix."users, ".$table_prefix."acl_users WHERE ".$table_prefix."users.username='".$your_site_username."' AND ".$table_prefix."users.user_id=".$table_prefix."acl_users.user_id ";

    $result mysql_query($sql);



    $row mysql_fetch_assoc($result);

    echo 
    "Your user ID is :".$row['USERID']." and your acl role is: ".$row["ROLE"]."<br />";
    ?>
    P.S obvioulsy if your including it index no need to put the <?PHP and the ?> in there
    Last edited by timgolding; 03-23-2009 at 11:25 PM.
    You can not say you know how to do something, until you can teach it to someone else.

  • #7
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Sorry that had a few errors in originally ive fixed those now. Well let me know what is returns when you run the query i need to know what you acl_role to check its the same as mine. Mine returns

    Your user ID is :2 and your acl role is: 5
    You can not say you know how to do something, until you can teach it to someone else.

  • #8
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Well you went offline and didn't get back to me so don't know why I bothered really. But here's the code that works fine I have tested it. However you will need to fill in the three variables at the top of the code for it to work. Each variable has an explanation of what it is and what its used for. And you still need to run the script from my previous post to determine the acl_role_id for your user so you can fill that variable in here is the code
    PHP Code:
    <?php
    $your_ACL_role_id
    ="5"// Put the ACL_role_id returned form the previous script here or the ACL of the admins that you want to inlclude posts for. Fill in the space between speach marks
    $num_to_display="5"// The number of announcments to display, again fill in the space
    $allowed_chars_of_text="100"//The number of allowed chars in an announcment.

    require_once('config.php'); // prolley dont need this as your index will incluide this anyway.

    $conn mysql_connect($dbhost$dbuser$dbpasswd);

    if (!
    $conn) {
        echo 
    "Unable to connect to DB: " mysql_error();
        exit;
    }
      
    if (!
    mysql_select_db($dbname)) {
     die(
    "Could not connect to database:" .$dbname."<br />Error: ".mysql_error());
    }

    $sql "SELECT ".$table_prefix."posts.post_subject AS SUBJECT,
    "
    .$table_prefix."posts.post_text AS TEXT,
    "
    .$table_prefix."posts.post_time AS TIMESTAMP,
    "
    .$table_prefix."users.username AS USERNAME,
    "
    .$table_prefix."acl_users.auth_role_id
    FROM "
    .$table_prefix."posts, ".$table_prefix."users, ".$table_prefix."acl_users
    WHERE "
    .$table_prefix."posts.poster_id = ".$table_prefix."users.user_id 
    AND "
    .$table_prefix."users.user_id = ".$table_prefix."acl_users.user_id
    AND "
    .$table_prefix."acl_users.auth_role_id = '".$your_ACL_role_id."'
    LIMIT 0 , "
    .$num_to_display

    $result mysql_query($sql) or die ("Error in query: ".mysql_error());

    $announcements '<div id="announcements">';
    while(
    $row mysql_fetch_assoc($result)){
        
    $announcements .= '<span class="ann_subjects">'.$row['SUBJECT'].'</span><br />';
        
    $announcements .= '<span class="ann_text">'.truncate($row['TEXT'], $allowed_chars_of_text).'</span><br />';
        
    $announcements .= '<span class="ann_poster_text">Posted By '.$row["USERNAME"].' at '.date(DATE_RFC822$row['TIMESTAMP']).'</span><br /><br />';
    }
    $announcements .= '</div>';

    function 
    truncate($string$del) {
      
    $len strlen($string);
      if (
    $len $del) {
        
    $new substr($string,0,$del)."...";
        return 
    $new;
      }
      else return 
    $string;


    // Then you can echo $announcments any where in the code. with the following line
     
    echo $announcements;
    ?>
    Just stick it in where you want it to go. You would also need to style the output
    Heres the styles you should put in your active styles folder something like phpBB3\styles\prosilver\common.css
    Code:
    div#announcements
    {
    
    }
    
    span.ann_subjects
    {
    
    }
    
    span.ann_text
    {
    
    }
    
    span.ann_poster_text
    {
    
    }
    You can then style them how you like.
    Last edited by timgolding; 03-24-2009 at 01:54 AM.
    You can not say you know how to do something, until you can teach it to someone else.

  • Users who have thanked timgolding for this post:

    Abesh (03-24-2009)

  • #9
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Thanks I hope it works for you. If you have any problems implementing it let me know. Depending where you put the script some of the viriables may complain as to being undefined. e.g. $dbhost, $dbuser, $dbpasswd and dbname are declared when config.php is included but may be out of scope where you run the script. However having a quick look at there index file its apparent they use a class for all database querys. So you can probabaly ignor the connect codes completely and assume the that the database has been connected to. However then you got the problem of $table_prefix not being defined. One work around is changing
    PHP Code:
    require_once('config.php'); 
    for
    PHP Code:
    include('config.php'
    So these vars get redeclared. Then unset the dbpasswd var.
    PHP Code:
    unset($dbpasswd); 
    Final code

    PHP Code:
    $your_ACL_role_id="5"// Put the ACL_role_id returned form the previous script here or the ACL of the admins that you want to inlclude posts for. Fill in the space between speach marks
    $num_to_display="5"// The number of announcments to display, again fill in the space
    $allowed_chars_of_text="100"//The number of allowed chars in an announcment.

    include('config.php'); // re include it anyway so vars are in scope.

    $conn mysql_connect($dbhost$dbuser$dbpasswd);

    if (!
    $conn) {
        echo 
    "Unable to connect to DB: " mysql_error();
        exit;
    }
      
    if (!
    mysql_select_db($dbname)) {
     die(
    "Could not connect to database:" .$dbname."<br />Error: ".mysql_error());
    }

    $sql "SELECT ".$table_prefix."posts.post_subject AS SUBJECT,
    "
    .$table_prefix."posts.post_text AS TEXT,
    "
    .$table_prefix."posts.post_time AS TIMESTAMP,
    "
    .$table_prefix."users.username AS USERNAME,
    "
    .$table_prefix."acl_users.auth_role_id
    FROM "
    .$table_prefix."posts, ".$table_prefix."users, ".$table_prefix."acl_users
    WHERE "
    .$table_prefix."posts.poster_id = ".$table_prefix."users.user_id 
    AND "
    .$table_prefix."users.user_id = ".$table_prefix."acl_users.user_id
    AND "
    .$table_prefix."acl_users.auth_role_id = '".$your_ACL_role_id."'
    LIMIT 0 , "
    .$num_to_display

    $result mysql_query($sql) or die ("Error in query: ".mysql_error());

    $announcements '<div id="announcements">';
    while(
    $row mysql_fetch_assoc($result)){
        
    $announcements .= '<span class="ann_subjects">'.$row['SUBJECT'].'</span><br />';
        
    $announcements .= '<span class="ann_text">'.truncate($row['TEXT'], $allowed_chars_of_text).'</span><br />';
        
    $announcements .= '<span class="ann_poster_text">Posted By '.$row["USERNAME"].' at '.date(DATE_RFC822$row['TIMESTAMP']).'</span><br /><br />';
    }
    $announcements .= '</div>';

    function 
    truncate($string$del) {
      
    $len strlen($string);
      if (
    $len $del) {
        
    $new substr($string,0,$del)."...";
        return 
    $new;
      }
      else return 
    $string;


    // Then you can echo $announcments any where in the code. with the following line
     
    echo $announcements;

    unset(
    $dbpasswd); 
    Thats the easiest way round. Or you could try using there class to do the query. When i tested this script I made a file in the forum directory root and called it test.php to test the script but some things might need tweaking when you implement them into phpbb. For instance the path to config.php might change relative to where you are running the script from things like that. Best off to just try the script out and see what errors/ problems you get then tweak accordingly.
    Last edited by timgolding; 03-24-2009 at 12:15 PM.
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •