txp/plugin-cheat

Create your textpattern plugins with "Inspired Plugin Composer":http://inspired.kiev.ua/txp/ied_plugin_composer!


h2. Register tag (publish-side plugin)

p. @function txp_mytag ($atts, $thing)@
@{@
@return "By calling <txp:txp_mytag /> tag I see this";@
@}@

p. @extract(lAtts(array('param' => false), $atts));@ // to get the value of the attribute

p. @parse ($thing);@ // _to get text enclosed in the tag, which will be parsed according to the settings of the article, i.e. textiled or not, etc._



h2. Register admin page (admin-side plugin)

p. @if('admin' == @txpinterface) {@
@add_privs('txp_my_admin_page','1,2,3,4');@ // Allow only "userlevels":http://forum.textpattern.com/viewtopic.php?id=9881 1,2,3,4 acess to this plugin.
@register_tab('extensions', 'txp_my_admin_page', "my page name");@ // Add tab for the 'txp_my_admin_page' event under extensions tab ( possible: content, presentation, admin, extensions).
@register_callback("txp_my_function", "txp_my_admin_page");@ // event txp_my_admin_page will be handled by txp_my_function function
@}@
 
p. @function txp_my_function ($event, $step)@
@{@
@pagetop('My title', 'my message');@
@echo 'hello world';@
@}@












h2. Cookbook


p. @include_plugin('txp_plugin')@ // to include another plugin
@&#64;register_callback($func, $event, $step=, $pre=0)@ // get your function executed on existed events "more info":http://textpattern.net/wiki/index.php?title=Plugin_Development_Topics

p. @global $textarray;@
@$textarray = array_merge(array('txp_my_message' => 'My Message'), $textarray);@ // to register a message in localization array

p. @include_once txpath.'/lib/classTextile.php'; $textileThis = new Textile();@
@$textileThis->TextileThis('I want this to be textiled');@

p. @has_privs('article.edit')@ // check if the current user on the admin side has privileges to edit articles (as an example). See "the table of priveleges":http://forum.textpattern.com/viewtopic.php?id=9881


h2. "txplib_misc":http://www.avinnovators.com/txpref/nav.html?textpattern/lib/txplib_misc.php.source.html

@gTxt('txp_my_message')@ // returns localized message

p. @gps($thing)@ // _checks GET and POST for a named variable, or creates it blank_
@gpsa($array)@ // performs gps() on an array of variable names
@ps($thing)@ // checks POST for a named variable, or creates it blank
@psa($array)@ // performs ps on an array of variable names
@psas($array)@ // same as above, but does strip_tags on post values
@stripPost()@ // returns $_POST striplashed if needed
@serverSet($thing)@ // Get a var from $_SERVER global array, or create it
@pcs($thing)@ //    Get a var from POST or COOKIE; if not, create it
@cs($thing)@ //    Get a var from COOKIE; if not, create it


h2. txplib_html, txplib_forms

p. @tag($content, $tag, $atts='')@ // <notextile><$tag $atts>$content</$tag></notextile>

p. @form( startTable('thetable')@ // "form()":http://www.avinnovators.com/txpref/nav.html?textpattern/lib/txplib_forms.php.source.html#l149 "startTable($type,$align='',$class='',$p='')":http://www.avinnovators.com/txpref/textpattern/lib/txplib_html.php.source.html#l146
@.  tr( td( fInput('text','name','value','class','title','this.select()','20','2') ) )@
@.  tr( td( fInput('submit','',gTxt('save'),'publish') ) )@
@.  endTable()@
@.  sInput('mystep')@
@.  eInput('myevent')@
@.  hInput('name','value'));@ // will output:

p. @<form action="index.php" method="post">@
@<table cellpadding="3" cellspacing="0" border="0" id="thetable" align="center">@
@<tr><td><input type="text" name="name" value="value" size="20" title="title" onclick="this.select()" tabindex="2" /></td></tr>@
@<tr><td><input type="submit" name="" value="Save" /></td></tr>@
@</table>@
@<input type="hidden" name="step" value="mystep" />@
@<input type="hidden" name="event" value="myevent" />@
@<input type="hidden" name="name" value="value" />@
@</form>@



















h2. Some of the globals

p. @$GLOBALS['thisarticle']['url_title']@
@$GLOBALS['thisarticle']['thisid'];@
@$GLOBALS['prefs']['path_from_root']@
@$GLOBALS['prefs']['siteurl']@

p. more info
"TXP globals @ rise.lewander.com":http://rise.lewander.com/textpattern/94/txp-global-variables : "$thisarticle":http://rise.lewander.com/textpattern/99/txp-global-variable-thisarticle "$prefs":http://rise.lewander.com/textpattern/96/txp-global-variable-prefs "$pretext":http://rise.lewander.com/textpattern/97/txp-global-variable-pretext "$thispage":http://rise.lewander.com/textpattern/100/txp-global-variable-thispage  
"TXP globals @ focusontheclouds":http://www.focusontheclouds.com/home/articles/72/accessing-global-variables-in-textpattern









h2. Database related


p. @fetch('Body', 'textpattern', 'ID', $id)@ // _return value of Body column in textpattern table where ID=$id_


p. @safe_insert  (@
@"textpattern",@
@"Title = '$my_title', Body = '$my_body', Body_html = '$my_body',@
@Excerpt = '', Excerpt_html = '',@
@Image = '',  Keywords = '', Status  = '4', Posted = now(),@
@LastMod = now(),  AuthorID = '$txp_user',@
@Section = 'category', Category1 = '', Category2 = '',@
@textile_body = '1', textile_excerpt = '1', Annotate = '', override_form   = '',@
@url_title = '$my_url_title',  AnnotateInvite  = '',@
@custom_1 = '',  custom_2 = '',  custom_3 = '',  custom_4 = '',  custom_5 = '',@
@custom_6 = '',  custom_7 = '',  custom_8 = '',  custom_9 = '',  custom_10 = '',@
@uid = '".md5(uniqid(rand(),true))."',  feed_time = curdate()" );@
@mysql_insert_id();@ // PHP function that returns the ID generated from the last INSERT operation

p. fields in "textpattern" table: _ID, Posted, AuthorID, LastMod, LastModID, Title, Title_html, Body, Body_html, Excerpt, Excerpt_html, Image, Category1, Category2, Annotate, AnnotateInvite, comments_count, Status, textile_body, textile_excerpt, Section, override_form, Keywords, url_title, custom_1, custom_2, custom_3, custom_4, custom_5, custom_6, custom_7, custom_8, custom_9, custom_10, uid, feed_time_

p. txp_category
txp_css
txp_discuss
txp_discuss_ipban
txp_discuss_nonce
txp_file
txp_form
txp_image
txp_lang
txp_link
txp_log
txp_page
txp_plugin
txp_prefs
txp_priv
txp_section
txp_users

h2. Reference

p. "List of all functions in the Textpattern source code":http://www.avinnovators.com/txpref/nav.html?_functions/index.html

p. "Plugin developer resources":http://forum.textpattern.com/viewtopic.php?id=9881
"The TextBook: Plugin Development Topics":http://textpattern.net/wiki/index.php?title=Plugin_Development_Topics