This directory holds import plugins for phpMyAdmin. Any new plugin should
basically follow the structure presented here. Official plugins need to
have str* messages with their definition in language files, but if you build
some plugins for your use, you can directly use texts in plugin.
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* [Name] import plugin for phpMyAdmin
*
* @package PhpMyAdmin-Import
* @subpackage [Name]
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/* Get the import interface */
require_once "libraries/plugins/ImportPlugin.class.php";
/**
* Handles the import for the [Name] format
*
* @package PhpMyAdmin-Import
*/
class Import[Name] extends ImportPlugin
{
/**
* optional - declare variables and descriptions
*
* @var type
*/
private $_myOptionalVariable;
/**
* Constructor
*/
public function __construct()
{
$this->setProperties();
}
/**
* Sets the import plugin properties.
* Called in the constructor.
*
* @return void
*/
protected function setProperties()
{
// optional - get globals
// set properties
$this->properties = array( // set name of your plugin
'text' => __('[Name]'), // text to be displayed as choice
'extension' => '[ext]', // extension this plugin can handle
'options' => array(), // array of options
'options_text' => __('Options')
);
// optional :
// type - bool or text, or begin/end group_subgroup
// name - form element name
// text - description in GUI
// size - size of text element (optional)
// len - maximal size of input (optional)
$this->properties['options'] = array(
array(
'type' => 'begin_group',
'name' => 'general_opts'
),
[..],
array(
'type' => 'end_group'
)
);
}
/**
* This method is called when any PluginManager to which the observer
* is attached calls PluginManager::notify()
*
* @param SplSubject $subject The PluginManager notifying the observer
* of an update.
*
* @return void
*/
public function update (SplSubject $subject)
{
}
/**
* Handles the whole import logic
*
* @return void
*/
public function doImport()
{
// get globals (others are optional)
global $error, $timeout_passed, $finished;
$buffer = '';
while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
$data = PMA_importGetNextChunk();
if ($data === false) {
// subtract data we didn't handle yet and stop processing
$offset -= strlen($buffer);
break;
} elseif ($data === true) {
// Handle rest of buffer
} else {
// Append new data to buffer
$buffer .= $data;
}
// PARSE $buffer here, post sql queries using:
PMA_importRunQuery($sql, $verbose_sql_with_comments);
} // End of import loop
// Commit any possible data in buffers
PMA_importRunQuery();
}
// optional:
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
/**
* Getter description
*
* @return type
*/
private function _getMyOptionalVariable()
{
return $this->_myOptionalVariable;
}
/**
* Setter description
*
* @param type $my_optional_variable description
*
* @return void
*/
private function _setMyOptionalVariable($my_optional_variable)
{
$this->_myOptionalVariable = $my_optional_variable;
}
}
?>