README 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. This directory holds import plugins for phpMyAdmin. Any new plugin should
  2. basically follow the structure presented here. Official plugins need to
  3. have str* messages with their definition in language files, but if you build
  4. some plugins for your use, you can directly use texts in plugin.
  5. <?php
  6. /* vim: set expandtab sw=4 ts=4 sts=4: */
  7. /**
  8. * [Name] import plugin for phpMyAdmin
  9. *
  10. * @package PhpMyAdmin-Import
  11. * @subpackage [Name]
  12. */
  13. if (! defined('PHPMYADMIN')) {
  14. exit;
  15. }
  16. /* Get the import interface */
  17. require_once 'libraries/plugins/ImportPlugin.class.php';
  18. /**
  19. * Handles the import for the [Name] format
  20. *
  21. * @package PhpMyAdmin-Import
  22. */
  23. class Import[Name] extends ImportPlugin
  24. {
  25. /**
  26. * optional - declare variables and descriptions
  27. *
  28. * @var type
  29. */
  30. private $_myOptionalVariable;
  31. /**
  32. * Constructor
  33. */
  34. public function __construct()
  35. {
  36. $this->setProperties();
  37. }
  38. /**
  39. * Sets the import plugin properties.
  40. * Called in the constructor.
  41. *
  42. * @return void
  43. */
  44. protected function setProperties()
  45. {
  46. // set properties
  47. $props = 'libraries/properties/';
  48. // include the main class for properties for the import plug-ins
  49. include_once "$props/plugins/ImportPluginProperties.class.php";
  50. // include the group properties classes
  51. include_once "$props/options/groups/OptionsPropertyRootGroup.class.php";
  52. include_once "$props/options/groups/OptionsPropertyMainGroup.class.php";
  53. // include the needed single property items
  54. include_once "$props/options/items/RadioPropertyItem.class.php";
  55. $importPluginProperties = new ImportPluginProperties();
  56. $importPluginProperties->setText('[name]'); // the name of your plug-in
  57. $importPluginProperties->setExtension('[ext]'); // extension this plug-in can handle
  58. $importPluginProperties->setOptionsText(__('Options'));
  59. // create the root group that will be the options field for
  60. // $importPluginProperties
  61. // this will be shown as "Format specific options"
  62. $importSpecificOptions = new OptionsPropertyRootGroup();
  63. $importSpecificOptions->setName("Format Specific Options");
  64. // general options main group
  65. $generalOptions = new OptionsPropertyMainGroup();
  66. $generalOptions->setName("general_opts");
  67. // optional :
  68. // create primary items and add them to the group
  69. // type - one of the classes listed in libraries/properties/options/items/
  70. // name - form element name
  71. // text - description in GUI
  72. // size - size of text element
  73. // len - maximal size of input
  74. // values - possible values of the item
  75. $leaf = new RadioPropertyItem();
  76. $leaf->setName("structure_or_data");
  77. $leaf->setValues(
  78. array(
  79. 'structure' => __('structure'),
  80. 'data' => __('data'),
  81. 'structure_and_data' => __('structure and data')
  82. )
  83. );
  84. $generalOptions->addProperty($leaf);
  85. // add the main group to the root group
  86. $importSpecificOptions->addProperty($generalOptions);
  87. // set the options for the import plugin property item
  88. $importPluginProperties->setOptions($importSpecificOptions);
  89. $this->properties = $importPluginProperties;
  90. }
  91. /**
  92. * This method is called when any PluginManager to which the observer
  93. * is attached calls PluginManager::notify()
  94. *
  95. * @param SplSubject $subject The PluginManager notifying the observer
  96. * of an update.
  97. *
  98. * @return void
  99. */
  100. public function update (SplSubject $subject)
  101. {
  102. }
  103. /**
  104. * Handles the whole import logic
  105. *
  106. * @return void
  107. */
  108. public function doImport()
  109. {
  110. // get globals (others are optional)
  111. global $error, $timeout_passed, $finished;
  112. $buffer = '';
  113. while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
  114. $data = PMA_importGetNextChunk();
  115. if ($data === false) {
  116. // subtract data we didn't handle yet and stop processing
  117. $offset -= strlen($buffer);
  118. break;
  119. } elseif ($data === true) {
  120. // Handle rest of buffer
  121. } else {
  122. // Append new data to buffer
  123. $buffer .= $data;
  124. }
  125. // PARSE $buffer here, post sql queries using:
  126. PMA_importRunQuery($sql, $verbose_sql_with_comments);
  127. } // End of import loop
  128. // Commit any possible data in buffers
  129. PMA_importRunQuery();
  130. }
  131. // optional:
  132. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  133. /**
  134. * Getter description
  135. *
  136. * @return type
  137. */
  138. private function _getMyOptionalVariable()
  139. {
  140. return $this->_myOptionalVariable;
  141. }
  142. /**
  143. * Setter description
  144. *
  145. * @param type $my_optional_variable description
  146. *
  147. * @return void
  148. */
  149. private function _setMyOptionalVariable($my_optional_variable)
  150. {
  151. $this->_myOptionalVariable = $my_optional_variable;
  152. }
  153. }
  154. ?>