Announcement

Collapse
No announcement yet.

Create a custom PHP page in vB-CMS

Collapse
X
Collapse
  •  

  • Create a custom PHP page in vB-CMS

    What is this How-To about?

    Goal is to integrate a custom PHP page into the CMS with which - as far as I can tell - one can achieve most (or even all) things that were possible by creating a custom page for the old forums. This is not as easy as it could be, but it can be done. I will use the custom PHP-Widget for this.
    With the availibilty of the php content type in vB 4.0.4 this article has become deprecated.

    vB-Version

    This was written for vB 4.0.2.

    Step 1: Create Template

    First we'll create a template for the new page: AdminCP -> Styles & Templates -> Style Manager -> choose Style -> Dropdown: Add New Template

    • Title: my_cms_test
    • Template: As a minimum, the codebox only needs to contain the variable that contains the output of our PHP code. For our example, we'll fill it with the following code:


    HTML Code:
    This is a custom php page. 
    
    
    
    First URL parameter (a): 
    <vb:if condition="$output&#91;'a'&#93;">
        {vb:raw output.a}
    <vb:else />
        Not present.
    </vb:if>
    
    
    
    Second URL parameter (b): 
    <vb:if condition="$output&#91;'b'&#93;">
        {vb:raw output.b}
    <vb:else />
        Not present.
    </vb:if>
    Of course, like with all other templates in vB, you can have all kinds of html code and template conditionals in there.

    Step 2: Create Widget and configure

    Next we'll create a PHP-Widget: AdminCP -> vBulletin-CMS -> Widgets -> Create New Widget

    • Widget Type: PHP Direct Execution
    • Title: my_phppage_test


    Save, then configure the newly created widget.

    • In the main box, you enter your custom PHP code. Note that all output has to be done via variables, meaning: you can't use echo or print. You can use $output to save your output, which is handy, since this variable is auto-registered. Other variables are possible, but need to be registered in the usual way. Our example:


    PHP Code:
    // clean URL-parameters 
    // note how for a only text/numbers (NOHTML) 
    // and for b only numbers (UINT) are valid

    vB::$vbulletin->input->clean_array_gpc('g', array(
    'a' => TYPE_NOHTML,
    'b' => TYPE_UINT
    ));  

    // prepare variables for template use. 
    // Easiest way to do this in a widget is using $output,
    // since this is registered automatically. Of course, 
    // you can register other variables, if you like.

    $output['a'] = vB::$vbulletin->GPC['a'];
    $output['b'] = vB::$vbulletin->GPC['b']; 
    For Template Name we use the template we created in Step 1.

    Step 3: Create Layout

    You may already have a fitting layout, but if this is your first try, probably not: AdminCP -> Layout Manager -> Add New Layout

    • Titel: Your choice
    • Grid: I have used 1 Column + 240px Sidebar, but you are free to do what you want
    • The just created widget gets placed into the main area, under primary content area.
    • Then drop some widgets wherever you want them. Save.



    Step 4: Create a section for your page

    We create a Section to contain - or rather act as - our page. It is necessary to have a seperate section for every different php widget/page you create in this way: AdminCP -> CMS -> Section Manager -> Add New Section

    • enter a name
    • the other settings are not important atm (remember you need to publish your section sometimes, tho)



    Step 5: Go to the Frontend, to the section we just created, configure

    • Choose the layout we just crated in step 3.



    Step 6: Remove "There is no content in this section

    What's disturbing our nice php page now is the forced "There is no content in this section"-message. We'll get rid of this message in one last step - a step we'll hopefully can get rid of in the future (hint to devs )

    For this, we need to remember the Node-ID of our newly created section. That's the number that can be seen in every form of URL for the sections:
    Code:
    content.php?r=116-my-php
    content.php/116-my-php
    Then we go to AdminCP -> Styles & Templates -> Style Manager -> choose Style -> Template: vbcms_content_section_page

    In this template, look for:
    HTML Code:
        <vb:if condition="$no_results_phrase">
        <div class="fullwidth">
            <p class="cms_article_txt_content">
                {vb:raw no_results_phrase}
            </p>
        </div>
        </vb:if>
    Replace with:
    HTML Code:
        <vb:if condition="$nodeid != Node-ID">
        <vb:if condition="$no_results_phrase">
        <div class="fullwidth">
            <p class="cms_article_txt_content">
                {vb:raw no_results_phrase}
            </p>
        </div>
        </vb:if>
        </vb:if>
    where Node-ID is the number of the Node-ID we just found out above, in this case: 116

    If you want to have more than one custom php page, you may want to change the first line of the template edit to:
    HTML Code:
        <vb:if condition="!in_array($nodeid,array(Node-ID_1, Node-ID_2, Node-ID_3))">
    End: Test the page

    Who knows to read some PHP will already have figured out what the example code does - there's plenty of comment, after all. Anyway, by adding the parameters a and b to the URL you can test the example's functionality.

    Code:
    http://www.deinforum.de/content.php/113-php-test?a=parameterinhalt&b=123
    This leads to the following:

    More? Advanced stuff

    To get rid of the vB-CMS generated Headline, put the whole vbcms_content_section_page template into the conditional from step 6. Then you can control the Heading: move the relevant parts from the original template to your custom one and fill it with variables of your choice.

    The code for the headline is the following:

    HTML Code:
        <div class="title">
        <!-- section page title div -->
            <h1 class="header">
                <span>{vb:raw title}</span>
                <vb:if condition="$can_edit">
                    <a href="{vb:raw page_url}/edit" class="edit"><img class="editimage" src="{vb:raw vboptions.bburl}/{vb:stylevar imgdir_cms}/edit_small.png" alt="{vb:rawphrase edit}" /></a>
                </vb:if>
                <vb:if condition="$vboptions&#91;'externalrss'&#93;">
                    <a href="ajax.php?do=rss&amp;type=newcontent&amp;sectionid={vb:raw nodeid}&amp;days=120&amp;count=10"><img src="{vb:stylevar imgdir_misc}/rss_40b.png" alt="{vb:rawphrase rss_feed}" /></a>
                </vb:if>
            </h1>
        </div>
        <!-- closes section page title div -->
    In there are also the codes for the edit-Button and the RSS-Button. You should integrate the first one into your custom template to be able to edit the section, while the RSS-button is rather useless as far as I can see, since there's no primary content on the page - only our custom php widget.
    Attached Files
      Posting comments is disabled.

    About the Author

    Collapse

    cellarius Find out more about cellarius

    Article Tags

    Collapse

    advanced (5) affiliate (1) album (1) android (2) api (29) array (17) beginner (17) blog (4) bloginfo (1) calendar (2) cms (2) custom profile fields (1) forum (3) forums (4) Intermediate (7) iphone (3) mapi (30) methods (10) mobile (34) security (2) style (2) threads (4) tls (1) vb5howto (5) vBulletin (5)

    Latest Articles

    Collapse

    • Managing CMS Section and Content
      by Don Kuramura
      Here's a quick Visual Guide on how Manage Sections in the new CMS.

      1. Editing a Section: If you have permissions to manage a Section, as you hover over the Section title, a pencil icon will display.

      After clicking the pencil icon, you will be taken to the Section Edit page. Here's what you will see:

      2. Section Name:
      Enter the Section Name
      3. SEO URL Alias: This is the SEO Friendly URL. By default, if this is blank, the system will automatically copy the section title.
      4. Section Layout: For each section you can define an individual section layout.
      ...
      Tue 11th Mar '14, 2:04pm
    • How to Create a New Article
      by Don Kuramura
      Here's a quick visual guide on how to create a new article with the CMS.

      1. Create New Article Button: Navigate to the section you want the article to be published in. Click on the “Create a New Article” button. This will open an article form.


      2. Article Title: In the "Add/Edit Article" screen, enter the title of your article in the “Title” textbox.
      ...
      Tue 11th Mar '14, 2:04pm
    • Promoting Articles from the Forums
      by Don Kuramura
      One of the innovative new features on vBulletin 4.0 Publishing Suite is the cross-publishing "Promote to Article" functionality. In the spirit of promoting content discovery, we wanted to create features that will allow content to flow between Forums, Blogs, and Articles. For example, there might be a really popular post in the forums, but unfortunately it is buried inside page 13 of a thread. We will now have an option (if you have permissions) to “promote” a forum (or blog) post as a new artic...
      Tue 11th Mar '14, 2:04pm
    • Welcome to the new CMS. Read me first.
      by Don Kuramura
      Welcome to the new CMS. Here's a quick guide of the different areas of this page.

      1. Section Navigation Widget. This widget allows you to go to different sections. The "plus icon" means that this section has sub-sections. Clicking on the "plus icon" will display the sub-sections. ...
      Tue 11th Mar '14, 2:04pm
    • Recovering a hacked vBulletin Site
      by TheLastSuperman
      Symptoms

      Having your site hacked is something no owner wants to experience due to the fact it takes quite a bit of effort to fix, often times requiring payment to a experienced third-party when a owner feels inundated by the sheer amount of work required to troubleshoot and remedy the situation.
      • Site has been defaced - This is the most blatant form of hacking where your sites pages have been replaced with a very disruptive and sometimes rude message from the hacker themselves.
      ...
      Tue 12th Jun '12, 1:37am
    • Issues After Upgrading
      by TheLastSuperman
      If your running a completely default forum upgrading is a very simple process. Many sites however run third-party add-ons and even use a custom style therefor when things change between older and newer
      Thu 24th May '12, 12:02pm
    Working...
    X