b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (Version 1.10) [ class tree: plugins ] [ index: plugins ] [ all elements ]

Class: code_highlight_plugin

Source Location: /blogs/plugins/code_highlight_plugin/_code_highlight.plugin.php

Class code_highlight_plugin

Inherited Properties, Constants, and Methods
Inherited Properties Inherited Methods Inherited Constants

Inherited From Plugin

Plugin::$long_desc
Plugin::$ping_service_name
Plugin::$ping_service_note
Plugin::$short_desc
Plugin::$sub_group

Inherited From Plugin

Plugin::Plugin()
Constructor.
Plugin::AdminAfterMenuInit()
Event handler: Gets invoked in /admin/_header.php for every backoffice page after the menu structure is build. You could use the $AdminUI object to modify it.
Plugin::AdminAfterPageFooter()
Event handler: Called right after displaying the admin page footer.
Plugin::AdminBeforeItemEditCreate()
Event handler: Called before a new item gets created (in the backoffice).
Plugin::AdminBeforeItemEditUpdate()
Event handler: Called before an existing item gets updated (in the backoffice).
Plugin::AdminBeginPayload()
Event handler: Gets invoked before the main payload in the backoffice.
Plugin::AdminDisplayEditorButton()
Event handler: Called when displaying editor buttons.
Plugin::AdminDisplayItemFormFieldset()
Event handler: Called at the end of the "Edit item" form.
Plugin::AdminDisplayToolbar()
Event handler: Called when displaying editor toolbars.
Plugin::AdminEndHtmlHead()
Event handler: Called when ending the admin html head section.
Plugin::AdminTabAction()
Event handler: Method that gets invoked when our tab is selected.
Plugin::AdminTabPayload()
Event handler: Gets invoked when our tab is selected and should get displayed.
Plugin::AdminToolAction()
Event handler: Called when handling actions for the "Tools" menu.
Plugin::AdminToolPayload()
Event handler: Called when displaying the block in the "Tools" menu.
Plugin::AfterCommentDelete()
Event handler: called at the end of deleting a comment from the database.
Plugin::AfterCommentFormInsert()
Event handler: Called when a comment form has been processed and the comment got inserted into DB.
Plugin::AfterCommentInsert()
Event handler: called at the end of inserting a comment into the database, which means it has been created.
Plugin::AfterCommentUpdate()
Event handler: called at the end of updating a comment in the database, which means that it has changed.
Plugin::AfterInstall()
Event handler: Called after the plugin has been installed.
Plugin::AfterItemDelete()
Event handler: called at the end of deleting an item/post from the database.
Plugin::AfterItemInsert()
Event handler: called at the end of inserting a item/post into the database, which means it has been created.
Plugin::AfterItemUpdate()
Event handler: called at the end of updating an item/post in the database, which means that it has been changed.
Plugin::AfterLoginAnonymousUser()
Event handler: Called at the end of the login procedure, if the user is anonymous ($current_User NOT set).
Plugin::AfterLoginRegisteredUser()
Event handler: Called at the end of the login procedure, if the $current_User is set and the user is therefor registered.
Plugin::AfterUserDelete()
Event handler: called at the end of deleting an user from the database.
Plugin::AfterUserInsert()
Event handler: called at the end of inserting an user account into the database, which means it has been created.
Plugin::AfterUserRegistration()
Event handler: Called when a new user has registered and got created.
Plugin::AfterUserUpdate()
Event handler: called at the end of updating an user account in the database, which means that it has been changed.
Plugin::AlternateAuthentication()
Event handler: called at the end of the login process, if the user did not try to login (by sending "login" and "pwd"), the session has no user attached or only "login" is given.
Plugin::AppendItemPreviewTransact()
Event handler: called when instantiating an Item for preview.
Plugin::AppendUserRegistrTransact()
Event handler: Called when a new user has registered, at the end of the DB transaction that created this user.
Plugin::are_events_available()
Check if the requested list of events is provided by any or one plugin.
Plugin::BeforeBlogDisplay()
Event handler: Called before a blog gets displayed (in _blog_main.inc.php).
Plugin::BeforeCommentFormInsert()
Event handler: Called before a comment gets inserted through the public comment form.
Plugin::BeforeDisable()
Event handler: Your plugin gets notified here, just before it gets disabled.
Plugin::BeforeEnable()
Event handler: Called when the admin tries to enable the plugin, changes its configuration/settings and after installation.
Plugin::BeforeInstall()
Event handler: Called before the plugin is going to be installed.
Plugin::BeforeTrackbackInsert()
Event handler: called before a trackback gets recorded.
Plugin::BeforeUninstall()
Event handler: Called before the plugin is going to be un-installed.
Plugin::BeforeUninstallPayload()
Event handler: Gets invoked to display the payload before uninstalling the plugin.
Plugin::CacheIsCollectingContent()
Event handler: gets asked for if we are generating cached content.
Plugin::CacheObjects()
Event handler: called to cache object data.
Plugin::CachePageContent()
Event handler: called to cache page content (get cached content or request caching).
Plugin::CaptchaPayload()
Event handler: general event to inject payload for a captcha test.
Plugin::CaptchaValidated()
Event handler: general event to validate a captcha which payload was added through CaptchaPayload().
Plugin::CaptchaValidatedCleanup()
Event handler: general event to be called after an action has been taken, which involved CaptchaPayload() and CaptchaValidated().
Plugin::CommentFormSent()
Event handler: Called before at the beginning, if a comment form gets sent (and received).
Plugin::debug_log()
Log a debug message.
Plugin::disable_event()
Disable an event.
Plugin::DisplayCommentFormButton()
Event handler: Called in the submit button section of the frontend comment form.
Plugin::DisplayCommentFormFieldset()
Event handler: Called at the end of the frontend comment form.
Plugin::DisplayCommentToolbar()
Event handler: Called when displaying editor toolbars.
Plugin::DisplayItemAsHtml()
Event handler: Called when displaying an item/post's content as HTML.
Plugin::DisplayItemAsText()
Event handler: Called when displaying an item/post's content as text.
Plugin::DisplayItemAsXml()
Event handler: Called when displaying an item/post's content as XML.
Plugin::DisplayLoginFormFieldset()
Event handler: Called at the end of the "Login" form.
Plugin::DisplayMessageFormButton()
Event handler: Called in the submit button section of the frontend message form.
Plugin::DisplayMessageFormFieldset()
Event handler: Called at the end of the frontend message form, which allows to send an email to a user/commentator.
Plugin::DisplayRegisterFormFieldset()
Event handler: Called at the end of the "Register as new user" form.
Plugin::DisplaySkin()
Event handler: Display a skin. Use Plugin::GetProvidedSkins() to return a list of names that you register.
Plugin::DisplayTrackbackAddr()
Event handler: called to display the URL that accepts trackbacks for an item.
Plugin::DisplayValidateAccountFormFieldset()
Event handler: Called at the end of the "Validate user account" form, which gets invoked if newusers_mustvalidate is enabled and the user has not been validated yet.
Plugin::enable_event()
Enable an event.
Plugin::ExecCronJob()
Execute/handle a cron job, which has been scheduled by the admin out of the list that the Plugin provides (see GetCronJobs()).
Plugin::FilterCommentAuthor()
Event handler: called to filter the comment's author name (blog name for trackbacks)
Plugin::FilterCommentAuthorUrl()
Event handler: called to filter the comment's author URL.
Plugin::FilterCommentContent()
Event handler: called to filter the comment's content
Plugin::FilterIpAddress()
Event handler: Called when an IP address gets displayed, typically in a protected area or for a privileged user, e.g. in the backoffice statistics menu.
Plugin::forget_events()
Call this to unregister all your events for the current request.
Plugin::GetCronJobs()
This method gets asked for a list of cronjobs that the plugin provides.
Plugin::GetDbLayout()
This method should return your DB schema, consisting of a list of CREATE TABLE queries.
Plugin::GetDefaultSettings()
Define here default settings that are then available in the backoffice.
Plugin::GetDefaultUserSettings()
Define here default user settings that are then available in the backoffice.
Plugin::GetDependencies()
Get the list of dependencies that the plugin has.
Plugin::GetExtraEvents()
This method gets asked when plugins get installed and allows you to return a list of extra events, which your plugin triggers itself (e.g. through $Plugins->trigger_event()).
Plugin::GetHtsrvMethods()
Override this method to define methods/functions that you want to make accessible through /htsrv/call_plugin.php, which allows you to call those methods by HTTP request.
Plugin::GetProvidedSkins()
Event handler: Gets asked about a list of skin names that the plugin handles.
Plugin::GetSpamKarmaForComment()
Event handler: Called to ask the plugin for the spam karma of a comment.
Plugin::get_class_id()
Get a string, unqiue for the plugin, usable in HTML form elements.
Plugin::get_edit_settings_link()
Get a link to edit the Plugin's settings (if the user has permission).
Plugin::get_help_file()
Get the help file for a Plugin ID. README.LOCALE.html will take precedence above the general (english) README.html.
Plugin::get_help_link()
Get a link to a help page (with icon).
Plugin::get_help_url()
Get the plugin's external help/website URL.
Plugin::get_htsrv_url()
Get the URL to call a plugin method through http. This links to the /htsrv/call_plugin.php file.
Plugin::get_plugin_url()
Get the absolute URL to the plugin's directory (where the plugins classfile is).
Plugin::get_README_link()
Plugin::get_sql_table()
Get canonical name for database tables a plugin uses, by adding an unique prefix for your plugin instance.
Plugin::ItemApplyAsRenderer()
Event handler: Does your Plugin want to apply as a renderer for the item?
Plugin::ItemCanComment()
Event handler: the plugin gets asked if an item can receive feedback/comments.
Plugin::ItemSendPing()
Event handler: send a ping about a new item.
Plugin::ItemViewsIncreased()
Event handler: Called when the view counter of an item got increased.
Plugin::LoginAttempt()
Event handler: called when a user attemps to login.
Plugin::Logout()
Event handler: called when a user logs out.
Plugin::MessageFormSent()
Event handler: Called when a message form has been submitted.
Plugin::MessageFormSentCleanup()
Event handler: Called after a message has been sent through the public email form.
Plugin::msg()
A simple wrapper around the $Messages object with a default catgory of 'note'.
Plugin::PluginInit()
Init the Plugin after it has been registered/instantiated.
Plugin::PluginSettingsEditAction()
Event handler: Called as action before displaying the "Edit plugin" form, which includes the display of the Plugin::Settings.
Plugin::PluginSettingsEditDisplayAfter()
Event handler: Called after the form to edit the Plugin::Settings has been displayed.
Plugin::PluginSettingsUpdateAction()
Event handler: Called as action just before updating the Plugin::Settings.
Plugin::PluginSettingsValidateSet()
Event handler: Called before displaying or setting a plugin's setting in the backoffice.
Plugin::PluginUserSettingsEditAction()
Event handler: Called as action before displaying the "Edit user" form, which includes the display of the Plugin::UserSettings.
Plugin::PluginUserSettingsEditDisplayAfter()
Event handler: Called after the form to edit the Plugin::UserSettings has been displayed.
Plugin::PluginUserSettingsUpdateAction()
Event handler: Called as action just before updating the Plugin::UserSettings.
Plugin::PluginUserSettingsValidateSet()
Event handler: Called before displaying or setting a plugin's user setting in the backoffice.
Plugin::PluginVersionChanged()
Event handler: Called when we detect a version change (in Plugins::register()).
Plugin::PrependItemInsertTransact()
Event handler: called at the beginning of inserting an item/post in the database.
Plugin::PrependItemUpdateTransact()
Event handler: called at the beginning of updating an item/post in the database.
Plugin::RegisterFormSent()
Event handler: Called when a "Register as new user" form has been submitted.
Plugin::register_menu_entry()
Register a tab (sub-menu) for the backoffice Tools menus.
Plugin::RenderItemAsHtml()
Event handler: Called when rendering item/post contents as HTML. (CACHED)
Plugin::RenderItemAsText()
Event handler: Called when rendering item/post contents other than XML or HTML.
Plugin::RenderItemAsXml()
Event handler: Called when rendering item/post contents as XML.
Plugin::SessionLoaded()
Event handler: Called after initializing plugins, DB, Settings, Hit, .. but quite early.
Plugin::session_delete()
Delete a value from the session data, using a unique prefix to the Plugin.
Plugin::session_get()
Get a data value for the session, using a unique prefix to the Plugin.
Plugin::session_set()
Set a data value for the session.
Plugin::set_status()
Set the status of the plugin.
Plugin::SkinBeginHtmlHead()
Event handler: Called at the beginning of the skin's HTML HEAD section.
Plugin::stop_propagation()
Stop propagation of the event to next plugins (with lower priority) in events that get triggered for a batch of Plugins.
Plugin::T_()
Translate a given string, in the Plugin's context.
Plugin::ValidateAccountFormSent()
Event handler: Called when a "Validate user account" form has been submitted.
Plugin::__get()
PHP5 overloading of get method to lazy-load (User)Settings.

[ Top ]
Property Summary
mixed   $apply_rendering  
mixed   $author  
mixed   $code  
mixed   $group  
mixed   $help_url  
mixed   $name  
mixed   $number_of_installs  
mixed   $priority  
mixed   $version  

[ Top ]
Method Summary
boolean   AdminDisplayToolbar()   Display a toolbar in admin
void   AdminEndHtmlHead()   Spits out the styles used
string   create_number()   Creates the SwipeFriendly line numbers
string   do_numbering()   Formats code ready for displaying With "SwipeFriendly" line numbers
void   FilterItemContents()   Filters out the custom tag that would not validate, PLUS escapes the actual code.
string   filter_codeblock_callback()   Formats code ready for the database
void   filter_codespan_callback()   Format codespan for display
string   format_to_edit()   Formats code ready for editing
array   GetDefaultSettings()   Get the settings that the plugin can use.
void   PluginInit()   Init
void   PluginVersionChanged()   Upgrade stuff for old style code posts
void   RenderItemAsHtml()   Perform rendering
void   RenderItemAsXml()   Perform rendering
string   render_codeblock_callback()   Formats codeblock ready for displaying
void   SkinBeginHtmlHead()   Spits out the styles used
string   tidy_code_output()   Tidys up a block of code ready for numbering
void   UnfilterItemContents()   Formats post contents ready for editing

[ Top ]
Properties
mixed   $apply_rendering = 'opt-out' [line 82]

Redefinition of:
Plugin::$apply_rendering
If this is a rendering plugin, when should rendering apply?

[ Top ]
mixed   $author = 'Astonish Me' [line 79]

Redefinition of:
Plugin::$author
Plugin author.

[ Top ]
mixed   $code = 'evo_code' [line 76]

Redefinition of:
Plugin::$code
Globally unique code for this plugin functionality. 32 chars. MUST BE SET.

[ Top ]
mixed   $group = 'rendering' [line 80]

Redefinition of:
Plugin::$group
Main group of the plugin.

[ Top ]
mixed   $help_url = 'http://b2evo.astonishme.co.uk/' [line 81]

Redefinition of:
Plugin::$help_url
URL for more info about the plugin, author and new versions.

[ Top ]
mixed   $name = 'Code highlight' [line 75]

Redefinition of:
Plugin::$name
Default plugin name as it will appear in lists.

[ Top ]
mixed   $number_of_installs = 1 [line 83]

Redefinition of:
Plugin::$number_of_installs
Number of allowed installs.

[ Top ]
mixed   $priority = 80 [line 77]

Redefinition of:
Plugin::$priority
Default priority.

[ Top ]
mixed   $version = '1.10-dev' [line 78]

Redefinition of:
Plugin::$version
Plugin version number (max 42 chars, so obscure CVS Revision keywords get handled).

[ Top ]
Methods
AdminDisplayToolbar  [line 149]

  boolean AdminDisplayToolbar( array &$params  )

Display a toolbar in admin

Parameters:
array   &$params:  Associative array of parameters

API Tags:
Return:  did we display a toolbar?


Redefinition of:
Plugin::AdminDisplayToolbar()
Event handler: Called when displaying editor toolbars.

[ Top ]
AdminEndHtmlHead  [line 394]

  void AdminEndHtmlHead( )

Spits out the styles used


API Tags:
See:  Plugin::AdminEndHtmlHead()


Redefinition of:
Plugin::AdminEndHtmlHead()
Event handler: Called when ending the admin html head section.

[ Top ]
create_number  [line 456]

  string create_number( integer $num  )

Creates the SwipeFriendly line numbers

Parameters:
integer   $num:  the line number to produce

API Tags:
Return:  the html for the line number


[ Top ]
do_numbering  [line 430]

  string do_numbering( string $code, [string $offset = 0], [string $type = 'code']  )

Formats code ready for displaying With "SwipeFriendly" line numbers

Parameters:
string   $code:  the code block to be wrapped up
string   $offset:  the attributes - currently only the starting line number
string   $type:  the code type ( code || php )

API Tags:
Return:  formatted code

Information Tags:
Todo:  

fp> no table should be needed. Also since we have odd/even coloring, word wrapping may be ok. yabs > unfortunately the tables are required to make the odd/even colouring and swipeable numbers work :(

an example : Danny uploaded a page to demo his colours of choice ( http://brendoman.com/dev/youtube.html ) if you scroll down to RenderItemAsHtml() you'll see it has 4 problems 1) some lines wrap - but they wrap underneath the line number 2) some lines don't wrap so they force a browser scrollbar ( although a scrollable div will cure this) 3) the lines that don't wrap lose their background colour once they become longer than the browser width ( a scrollable div has the same problem ) 4) If you try and copy/paste the code you also get the line numbers ( like every other code formatter that we've seen on the web that uses line numbers ... which is why most don't ;) )

compare that to the same section of code using this plugin ( http://cvs.astonishme.co.uk/index.php/2007/04/01/a_demo )

fp> almost all that can be fixed with proper CSS and will have the advantage of not adding extra space in front of the lines when copy/pasting. I'll work on it when I have time.

yabs> The operative word in that sentance is "almost" ;) ... I've removed the trailing spaces for all but empty lines ( required to "prop them open" ) ... I'd forgotten all about them :p


[ Top ]
FilterItemContents  [line 194]

  void FilterItemContents( &$params, mixed $params  )

Filters out the custom tag that would not validate, PLUS escapes the actual code.

Parameters:
mixed   $params: 
   &$params: 


[ Top ]
filter_codeblock_callback  [line 343]

  string filter_codeblock_callback( array $block  )

Formats code ready for the database

Parameters:
array   $block:  ( 2 - attributes, 3 - the code )

API Tags:
Return:  formatted code || empty


[ Top ]
filter_codespan_callback  [line 225]

  void filter_codespan_callback( $matches  )

Format codespan for display

This is a bit quick 'n dirty. We might want to unfilter this too. We might want to highlight this too (based on a lang attribute).

Parameters:
   $matches: 


[ Top ]
format_to_edit  [line 357]

  string format_to_edit( array $block  )

Formats code ready for editing

Parameters:
array   $block:  ( 1 - attributes, 2 - the code )

API Tags:
Return:  formatted code


[ Top ]
GetDefaultSettings  [line 129]

  array GetDefaultSettings( &$params  )

Get the settings that the plugin can use.

Those settings are transfered into a Settings member object of the plugin and can be edited in the backoffice (Settings / Plugins).

Parameters:
   &$params: 

API Tags:
See:  Plugin::PluginSettingsValidateSet()
See:  PluginSettings
See:  Plugin::GetDefaultSettings()


Redefinition of:
Plugin::GetDefaultSettings()
Define here default settings that are then available in the backoffice.

[ Top ]
PluginInit  [line 111]

  void PluginInit( &$params  )

Init

Parameters:
   &$params: 


Redefinition of:
Plugin::PluginInit()
Init the Plugin after it has been registered/instantiated.

[ Top ]
PluginVersionChanged  [line 476]

  void PluginVersionChanged( )

Upgrade stuff for old style code posts


API Tags:
See:  Plugin::PluginVersionChanged()


Redefinition of:
Plugin::PluginVersionChanged()
Event handler: Called when we detect a version change (in Plugins::register()).

[ Top ]
RenderItemAsHtml  [line 257]

  void RenderItemAsHtml( &$params  )

Perform rendering

Parameters:
   &$params: 

API Tags:
See:  Plugin::RenderItemAsHtml()


Redefinition of:
Plugin::RenderItemAsHtml()
Event handler: Called when rendering item/post contents as HTML. (CACHED)

[ Top ]
RenderItemAsXml  [line 276]

  void RenderItemAsXml( &$params  )

Perform rendering

Parameters:
   &$params: 

API Tags:
See:  Plugin::RenderItemAsXml() Note : Do we actually want to do this? - yabs


Redefinition of:
Plugin::RenderItemAsXml()
Event handler: Called when rendering item/post contents as XML.

[ Top ]
render_codeblock_callback  [line 508]

  string render_codeblock_callback( array $block  )

Formats codeblock ready for displaying

Each language is stored as a classfile This would allow new languages to be added more easily It would also allow Geshi to be used as the highlighter with no code changes ;)

Replaces both (current) highlighter functions

..... still requires some more thought though :p

Parameters:
array   $block:  ( 2 - attributes, 4 - the code )

API Tags:
Return:  formatted code


[ Top ]
SkinBeginHtmlHead  [line 368]

  void SkinBeginHtmlHead( )

Spits out the styles used


API Tags:
See:  Plugin::SkinBeginHtmlHead()


Redefinition of:
Plugin::SkinBeginHtmlHead()
Event handler: Called at the beginning of the skin's HTML HEAD section.

[ Top ]
tidy_code_output  [line 289]

  string tidy_code_output( string $block, [string $line_seperator = "\n"]  )

Tidys up a block of code ready for numbering

Parameters:
string   $block:  - the code to be tidied up
string   $line_seperator:  - the seperator between lines of code ( default \n )

API Tags:
Return:  - the tidied code


[ Top ]
UnfilterItemContents  [line 238]

  void UnfilterItemContents( &$params, mixed $params  )

Formats post contents ready for editing

Parameters:
mixed   $params: 
   &$params: 


[ Top ]

Documentation generated on Tue, 20 May 2008 01:38:44 +0200 by phpDocumentor 1.4.2