منتدى استراحات زايد

منتدى استراحات زايد (http://vb.ma7room.com/index.php)
-   منتدى أخبار المواقع والمنتديات العربية والأجنبية (http://vb.ma7room.com/forumdisplay.php?f=183)
-   -   Create a custom PHP page in vB-CMS (http://vb.ma7room.com/showthread.php?t=344791)

محروم.كوم 03-03-2010 02:00 AM

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.

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:raw output.a}

Not present.






Second URL parameter (b):

{vb:raw output.b}

Not present.

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:raw no_results_phrase}






Replace with:
HTML Code:




{vb:raw no_results_phrase}







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:

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/...erinhalt&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:



{vb:raw title}

<img class=span style="color:#0000FF""editimage"/span src=span style="color:#0000FF""{vb:raw vboptions.bburl}/{vb:stylevar imgdir_cms}/edit_small.png"/span alt=span style="color:#0000FF""{vb:rawphrase edit}"/span />


<img src=span style="color:#0000FF""{vb:stylevar imgdir_misc}/rss_40b.png"/span alt=span style="color:#0000FF""{vb:rawphrase rss_feed}"/span />







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 Images


الساعة الآن 08:17 PM

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.2 TranZ By Almuhajir


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227