| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,110 @@ |
| 1 |
+<html> |
|
| 2 |
+ |
|
| 3 |
+<head> |
|
| 4 |
+<meta http-equiv="Content-Language" content="en-us"> |
|
| 5 |
+<meta name="GENERATOR" content="Microsoft FrontPage 5.0"> |
|
| 6 |
+<meta name="ProgId" content="FrontPage.Editor.Document"> |
|
| 7 |
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> |
|
| 8 |
+<title>Creating Blocks</title> |
|
| 9 |
+</head> |
|
| 10 |
+ |
|
| 11 |
+<body> |
|
| 12 |
+ |
|
| 13 |
+<h2 align="center">Creating Blocks</h2> |
|
| 14 |
+<p>For those that want to create their own blocks to share with others or just |
|
| 15 |
+ tweak the ones included already, here's the basics. There are two files |
|
| 16 |
+ needed for each block: blockname.php an init.php. Technically, if you |
|
| 17 |
+ added the block manually, you wouldn't need the init.php file. It is only |
|
| 18 |
+ used when the block is first initialized, and can be deleted afterward. |
|
| 19 |
+ Though I would suggest keeping a backup somewhere, just in case.</p> |
|
| 20 |
+<p>The init.php file is very simple composed simply of a mysql statement that |
|
| 21 |
+ adds the block tot he database. As in the example below.</p> |
|
| 22 |
+<p><?php<br> |
|
| 23 |
+ dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_blocks(`block_name`, |
|
| 24 |
+ `block_title`, `block_status`, `block_file`, `block_variables`) VALUES('categories',
|
|
| 25 |
+ 'Main Categories', '0', 'categories/categories.php', '');");<br> |
|
| 26 |
+ ?></p> |
|
| 27 |
+<p>This also shows the basic parameters needed for a block: name, title, status, |
|
| 28 |
+ file, and variables. The title can be an empty string if you don't need |
|
| 29 |
+ a title for that particular block. If the block doesn't need any variables, |
|
| 30 |
+ that too can be left empty. The file should be a subfolder/file of the blocks |
|
| 31 |
+ folder for the sake of consistency. The status should generally start off as |
|
| 32 |
+ 0 for inactive. There are 3 status options for blocks: </p> |
|
| 33 |
+<div align="center"> |
|
| 34 |
+ <center> |
|
| 35 |
+ <table border="1" cellpadding="5" cellspacing="0" |
|
| 36 |
+ style="border-collapse: collapse" bordercolor="#111111"> |
|
| 37 |
+ <tr> |
|
| 38 |
+ <th colspan="2">Status</th> |
|
| 39 |
+ <th> Associated .tpl file</th> |
|
| 40 |
+ <th>Appears</th> |
|
| 41 |
+ </tr> |
|
| 42 |
+ <tr> |
|
| 43 |
+ <td>0</td> |
|
| 44 |
+ <td>Inactive</td> |
|
| 45 |
+ <td>The block is off. </td> |
|
| 46 |
+ <td>nowhere</td> |
|
| 47 |
+ </tr> |
|
| 48 |
+ <tr> |
|
| 49 |
+ <td>1</td> |
|
| 50 |
+ <td>Active</td> |
|
| 51 |
+ <td>The block is on.</td> |
|
| 52 |
+ <td>anywhere</td> |
|
| 53 |
+ </tr> |
|
| 54 |
+ <tr> |
|
| 55 |
+ <td>2</td> |
|
| 56 |
+ <td>Index only</td> |
|
| 57 |
+ <td>index page only.</td> |
|
| 58 |
+ <td>anywhere on the index page.</td> |
|
| 59 |
+ </tr> |
|
| 60 |
+ </table> |
|
| 61 |
+ </center> |
|
| 62 |
+</div> |
|
| 63 |
+<p> </p> |
|
| 64 |
+<p>Any default configuration you want for the block can be included in the init.php |
|
| 65 |
+ as well. The variables are an array encoded using PHP's serialize function. |
|
| 66 |
+ For instance, the categories block currently has two options: one column and |
|
| 67 |
+ multiple columns. The default is a single column lists. If I were |
|
| 68 |
+ to change the init file as follows, the default would then become a multiple |
|
| 69 |
+ column list.</p> |
|
| 70 |
+<p><?php<br> |
|
| 71 |
+ dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_blocks(`block_name`, |
|
| 72 |
+ `block_title`, `block_status`, `block_file`, `block_variables`) VALUES('categories',
|
|
| 73 |
+ 'Main Categories', '0', 'categories/categories.php', '".serialize(array("columns" |
|
| 74 |
+ => "1"))."');");<br> |
|
| 75 |
+ ?></p> |
|
| 76 |
+<p> When you change any of the settings for the blocks from the admin panel the |
|
| 77 |
+ information stored in the database about the block is updated.</p> |
|
| 78 |
+<p>The block.php file creates the content that is placed inside the {blockname_content}
|
|
| 79 |
+variable. This content is placed inside a variable $content which is then |
|
| 80 |
+assigned to {blockname_content} So a very simple example of a block would
|
|
| 81 |
+be:</p> |
|
| 82 |
+<p><?php<br> |
|
| 83 |
+$content = "Hello World!";<br> |
|
| 84 |
+?></p> |
|
| 85 |
+<p>There are two other optional files. The first is an admin file which |
|
| 86 |
+will be called from the admin panel to make changes to the settings in the |
|
| 87 |
+block. Creating one of those is for another day. </p> |
|
| 88 |
+<p>The second file (or multiple files) is a language file that defines any text |
|
| 89 |
+you use in your block. These files take the same format as the main |
|
| 90 |
+language file in the languages folder and are named similarly. So for |
|
| 91 |
+instance, an English language file would be named en.php. For Spanish, it |
|
| 92 |
+would be es.php. </p> |
|
| 93 |
+<p>Most often, you might need to define some wording for your admin.php file. |
|
| 94 |
+If you need to add a language file, use the following code in either admin.php |
|
| 95 |
+or blockname.php</p> |
|
| 96 |
+<p>if(file_exists("blocks/categories/{$language}.php")) include_once("blocks/categories/{$language}.php");</p>
|
|
| 97 |
+<p>The if(...) isn't technically necessary, but it will prevent errors if the |
|
| 98 |
+ file ends up missing. For instance, the site's language is set to Russian, |
|
| 99 |
+ but the block doesn't have a Russian translation. You might also want |
|
| 100 |
+ to include an else statement to load a default language file you have created |
|
| 101 |
+ if the site's chosen language is missing.</p> |
|
| 102 |
+<p>if(file_exists("blocks/categories/{$language}.php")) include_once("blocks/categories/{$language}.php");<br>
|
|
| 103 |
+ else include_once("blocks/categories/en.php");</p> |
|
| 104 |
+<p>To keep your block files secure from hackers you are strongly encouraged to |
|
| 105 |
+ include this line at the top of each file just under the <?php</p> |
|
| 106 |
+<p>if(!defined("_CHARSET")) exit( );</p> |
|
| 107 |
+<p> </p> |
|
| 108 |
+</body> |
|
| 109 |
+ |
|
| 110 |
+</html> |
|
| 0 | 111 |
\ No newline at end of file |