Source Code Documentation


pro\s2member-pro\includes\menu-pages\import-export.inc.php


  1. <?php
  2. /**
  3. * Menu page for s2Member Pro (Import/Export page).
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * This WordPress® plugin (s2Member Pro) is comprised of two parts:
  10. *
  11. * o (1) Its PHP code is licensed under the GPL license, as is WordPress®.
  12. * You should have received a copy of the GNU General Public License,
  13. * along with this software. In the main directory, see: /licensing/
  14. * If not, see: {@link http://www.gnu.org/licenses/}.
  15. *
  16. * o (2) All other parts of (s2Member Pro); including, but not limited to:
  17. * the CSS code, some JavaScript code, images, and design;
  18. * are licensed according to the license purchased.
  19. * See: {@link http://www.s2member.com/prices/}
  20. *
  21. * Unless you have our prior written consent, you must NOT directly or indirectly license,
  22. * sub-license, sell, resell, or provide for free; part (2) of the s2Member Pro Module;
  23. * or make an offer to do any of these things. All of these things are strictly
  24. * prohibited with part (2) of the s2Member Pro Module.
  25. *
  26. * Your purchase of s2Member Pro includes free lifetime upgrades via s2Member.com
  27. * (i.e. new features, bug fixes, updates, improvements); along with full access
  28. * to our video tutorial library: {@link http://www.s2member.com/videos/}
  29. *
  30. * @package s2Member\Menu_Pages
  31. * @since 1.5
  32. */
  33. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  34. exit ("Do not access this file directly.");
  35.  
  36. if (!class_exists ("c_ws_plugin__s2member_pro_menu_page_import_export"))
  37. {
  38. /**
  39. * Menu page for s2Member Pro (Import/Export page).
  40. *
  41. * @package s2Member\Menu_Pages
  42. * @since 110531
  43. */
  44. class c_ws_plugin__s2member_pro_menu_page_import_export
  45. {
  46. public function __construct ()
  47. {
  48. echo '<div class="wrap ws-menu-page">' . "\n";
  49.  
  50. echo '<div id="icon-plugins" class="icon32"><br /></div>' . "\n";
  51. echo '<h2>s2Member® Pro (Import/Export Tools)</h2>' . "\n";
  52.  
  53. echo '<table class="ws-menu-page-table">' . "\n";
  54. echo '<tbody class="ws-menu-page-table-tbody">' . "\n";
  55. echo '<tr class="ws-menu-page-table-tr">' . "\n";
  56. echo '<td class="ws-menu-page-table-l">' . "\n";
  57.  
  58. if (is_multisite () && c_ws_plugin__s2member_utils_conds::is_multisite_farm () && !is_main_site ())
  59. {
  60. echo '<div class="ws-menu-page-group" title="User/Member CSV Importation"' . (($_POST["ws_plugin__s2member_pro_import_users"]) ? ' default-state="open"' : '') . '>' . "\n";
  61.  
  62. echo '<div class="ws-menu-page-section ws-plugin--s2member-pro-user-importation-section">' . "\n";
  63. echo '<h3>User/Member Importation (upload file / or direct input)</h3>' . "\n";
  64. echo '<p>Import files can be uploaded in CSV format, or you can copy/paste data into the form field provided. In either case, you MUST follow the examples given below. Please double-check your data before clicking the Import button. Make sure that all data fields are properly encapsulated by double-quotes, and separated by commas. You\'ll also need to make sure that all of your data fields are in the proper order, based on the examples given below. After importing Users/Members, you can inspect your work by going to: <code>WordPress® -› Users</code>.</p>' . "\n";
  65. echo '<p><em><strong>*No Email Notification*</strong> This import routine works silently. Users/Members will NOT be contacted by s2Member; that is, unless you have another plugin installed that conflicts with s2Member\'s ability to perform the Import properly. You should always test one or two accounts before importing a large number of Users all at once. If you want Users/Members to be contacted, you can add them manually, by going to <code>WordPress® -› Users -› Add New</code>, and selecting one of the s2Member Roles from the drop-down menu.</em></p>' . "\n";
  66. echo (version_compare(PHP_VERSION, "5.3", "<")) ? '<p><em><strong>*PHP v5.3+ recommended*</strong> In order for s2Member® to properly import CSV files containing escape sequences, PHP v5.3 or higher is required. While s2Member® may be able to parse import files in most cases, PHP v5.3 provides the best stability.</em></p>' . "\n" : '';
  67. echo '<p><em><strong class="ws-menu-page-hilite">*IMPORTANT NOTICE*</strong> s2Member\'s import format changed in s2Member Pro v130203+ (with respect to Custom Registration/Profile Fields only). If you are importing Custom Fields, please review <a href="http://www.s2member.com/kb/importing-updating-users/#custom-registration-profile-fields" target="_blank" rel="external nofollow x-link">this article</a> before you import new Users/Members or mass update any existing Users/Members. <strong>VERY important!</strong></em></p>' . "\n";
  68.  
  69. echo '<table class="form-table">' . "\n";
  70. echo '<tbody>' . "\n";
  71. echo '<tr>' . "\n";
  72.  
  73. echo '<td>' . "\n";
  74. echo '<form method="post" enctype="multipart/form-data" name="ws_plugin__s2member_pro_import_users_form" id="ws-plugin--s2member-pro-import-users-form">' . "\n";
  75. echo '<input type="hidden" name="ws_plugin__s2member_pro_import_users" id="ws-plugin--s2member-pro-import-users" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-pro-import-users")) . '" />' . "\n";
  76.  
  77. echo '<input type="file" name="ws_plugin__s2member_pro_import_users_file" id="ws-plugin--s2member-pro-import-users-file" />&nbsp;&nbsp;&nbsp;(up to 1000 lines per file)&nbsp;&nbsp;&nbsp;<input type="submit" class="button-primary" value="Import Now" /><br /><br />' . "\n";
  78. echo '<textarea name="ws_plugin__s2member_pro_import_users_direct_input" id="ws-plugin--s2member-pro-import-users-direct-input" rows="10" wrap="off" spellcheck="false" style="width:99%;">' . format_to_edit (trim (stripslashes ($_POST["ws_plugin__s2member_pro_import_users_direct_input"]))) . '</textarea><br />' . "\n";
  79.  
  80. echo 'One User/Member per line please. Here is a quick example:<br />' . "\n";
  81. echo '<code>"ID","Username","First Name","Last Name","Display Name","Email"</code>' . "\n";
  82.  
  83. echo '<div class="ws-menu-page-hr"></div>' . "\n";
  84.  
  85. echo 'If you fill the ID field, the Import routine will update an account matching the ID you specify (so long as the account ID does NOT belong to an Administrator, this is for security). When importing new Users/Members, you can leave the ID field empty Don\'t remove it, just leave it empty (i.e. <code>""</code>).<br /><br />'."\n";
  86.  
  87. echo 'Example: <code>"","Username","First Name","Last Name","Display Name","Email"</code><br /><br />' . "\n";
  88.  
  89. echo 'Additional extended information can also be included; even Custom Registration/Profile Fields:<br />' . "\n";
  90. echo '<code>"ID","Username","First Name","Last Name","Display Name","Email","Website","Level[0-9]+ or Role ID","Custom Capabilities","Registration Date (mm/dd/yyyy)","First Payment Date (mm/dd/yyyy)","Last Payment Date (mm/dd/yyyy)","Auto-EOT Date (mm/dd/yyyy)","Custom Value (starts w/domain)","Paid Subscr. ID","Paid Subscr. Gateway","Custom Field Value","Another Custom Field Value", ...</code><br /><br />' . "\n";
  91.  
  92. echo 'Here is a full example with all fields filled in, including extended details; and two Custom Field values:<br />' . "\n";
  93. echo '<code>"","johnsmith22","John","Smith","John Smith","john.smith@example.com","http://www.example.com/","2","music,videos","12/31/2000","01/10/2001","12/31/2020","12/31/2021","www.example.com|123.357.125.654","I-2342934SSER243","paypal","fishing,biking,computers","xx-large"</code><br /><br />' . "\n";
  94.  
  95. echo 'Here is a full example with some fields left empty:<br />' . "\n";
  96. echo '<code>"","johnsmith22","John","Smith","John Smith","john.smith@example.com","","s2member_level2","","","","","12/31/2021"</code>' . "\n";
  97.  
  98. echo '<div class="ws-menu-page-hr"></div>' . "\n";
  99.  
  100. echo '<em>* If you supply a Paid Subscr. Gateway, you must use one of these values: <code>paypal</code>, <code>alipay</code>, <code>authnet</code>, <code>ccbill</code>, <code>clickbank</code>, <code>google</code>.</em><br /><br />' . "\n";
  101.  
  102. echo '<em>* If you supply Custom Fields, your Custom Field values should be listed in alphabetical order, based on your Custom Field IDs (i.e. values listed in the order of your alphabetized Custom Field IDs). This is based on the Custom Field IDs you\'ve configured with s2Member. See: <code>s2Member -› General Options -› Registration/Profile Fields</code>. In the example above, you will see two Custom Field values (<code>... "fishing,biking,computers","xx-large"</code>). The first value comes first, because it maps to the Custom Field ID <code>interests</code>, and the second one comes last, because it maps to the Custom Field ID <code>t_shirt_size</code> (e.g. alphabetical order — based on the underlying Custom Field IDs that you\'re mapping this data to).</em><br /><br />'."\n";
  103. echo '<em>* If you have a Custom Field that contains an array of multiple values, you can import the array using PHP\'s <a href="http://php.net/manual/en/function.serialize.php" target="_blank" rel="external">serialize()</a> function. This allows you to convert the array into a string representation. s2Member will automatically unserialize the value during importation. If you have any trouble, please perform an export first. s2Member\'s export files are already formatted for easy re-importation. In other words, you can use them as a guideline for building your own import files.</em><br /><br />' . "\n";
  104.  
  105. echo '<em>* If you supply "First Payment Date", you have two options available. You can either supply a simple date in this format (mm/dd/yyyy), or you can import an array of First Payment Dates, in the form of Unix timestamps. s2Member has the ability to record and monitor First Payment Dates at each specific Membership Level. The array it expects, consists of the following: <code>array("level" => [timestamp of first payment date regardless of level], "level1" => [timestamp of first payment date at level #1], "level2" => [timestamp], "level3" => [timestamp], "level4" => [timestamp])</code>. Of course, if you decide to import an array with some of these timestamps, you will need to use PHP\'s <a href="http://php.net/manual/en/function.serialize.php" target="_blank" rel="external">serialize()</a> function to convert the array into a string representation. If you have any trouble, please perform an export first. s2Member\'s export files are already formatted for easy re-importation. In other words, you can use them as a guideline for building your own import files. By default, s2Member exports an array of timestamps.</em>' . "\n";
  106.  
  107. echo '</form>' . "\n";
  108. echo '</td>' . "\n";
  109.  
  110. echo '</tr>' . "\n";
  111. echo '</tbody>' . "\n";
  112. echo '</table>' . "\n";
  113. echo '</div>' . "\n";
  114.  
  115. echo '</div>' . "\n";
  116. }
  117. else // Otherwise, we use the standardized format for Importation.
  118. {
  119. echo '<div class="ws-menu-page-group" title="User/Member CSV Importation"' . ((isset ($_POST["ws_plugin__s2member_pro_import_users"])) ? ' default-state="open"' : '') . '>' . "\n";
  120.  
  121. echo '<div class="ws-menu-page-section ws-plugin--s2member-pro-user-importation-section">' . "\n";
  122. echo '<h3>User/Member Importation (upload file / or direct input)</h3>' . "\n";
  123. echo '<p>Import files can be uploaded in CSV format, or you can copy/paste data into the form field provided. In either case, you MUST follow the examples given below. Please double-check your data before clicking the Import button. Make sure that all data fields are properly encapsulated by double-quotes, and separated by commas. You\'ll also need to make sure that all of your data fields are in the proper order, based on the examples given below. After importing Users/Members, you can inspect your work by going to: <code>WordPress® -› Users</code>.</p>' . "\n";
  124. echo '<p><em><strong>*No Email Notification*</strong> This import routine works silently. Users/Members will NOT be contacted by s2Member; that is, unless you have another plugin installed that conflicts with s2Member\'s ability to perform the Import properly. You should always test one or two accounts before importing a large number of Users all at once. If you want Users/Members to be contacted, you can add them manually, by going to <code>WordPress® -› Users -› Add New</code>, and selecting one of the s2Member Roles from the drop-down menu.</em></p>' . "\n";
  125. echo (version_compare(PHP_VERSION, "5.3", "<")) ? '<p><em><strong>*PHP v5.3+ recommended*</strong> In order for s2Member® to properly import CSV files containing escape sequences, PHP v5.3 or higher is required. While s2Member® may be able to parse import files in most cases, PHP v5.3 provides the best stability.</em></p>' . "\n" : '';
  126. echo '<p><em><strong class="ws-menu-page-hilite">*IMPORTANT NOTICE*</strong> s2Member\'s import format changed in s2Member Pro v130203+ (with respect to Custom Registration/Profile Fields only). If you are importing Custom Fields, please review <a href="http://www.s2member.com/kb/importing-updating-users/#custom-registration-profile-fields" target="_blank" rel="external nofollow x-link">this article</a> before you import new Users/Members or mass update any existing Users/Members. <strong>VERY important!</strong></em></p>' . "\n";
  127.  
  128. echo '<table class="form-table">' . "\n";
  129. echo '<tbody>' . "\n";
  130. echo '<tr>' . "\n";
  131.  
  132. echo '<td>' . "\n";
  133. echo '<form method="post" enctype="multipart/form-data" name="ws_plugin__s2member_pro_import_users_form" id="ws-plugin--s2member-pro-import-users-form">' . "\n";
  134. echo '<input type="hidden" name="ws_plugin__s2member_pro_import_users" id="ws-plugin--s2member-pro-import-users" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-pro-import-users")) . '" />' . "\n";
  135.  
  136. echo '<input type="file" name="ws_plugin__s2member_pro_import_users_file" id="ws-plugin--s2member-pro-import-users-file" />&nbsp;&nbsp;&nbsp;(up to 1000 lines per file)&nbsp;&nbsp;&nbsp;<input type="submit" class="button-primary" value="Import Now" /><br /><br />' . "\n";
  137. echo '<textarea name="ws_plugin__s2member_pro_import_users_direct_input" id="ws-plugin--s2member-pro-import-users-direct-input" rows="10" wrap="off" spellcheck="false" style="width:99%;">' . format_to_edit (trim (stripslashes ($_POST["ws_plugin__s2member_pro_import_users_direct_input"]))) . '</textarea><br />' . "\n";
  138.  
  139. echo 'One User/Member per line please. Here is a quick example:<br />' . "\n";
  140. echo '<code>"ID","Username","Password","First Name","Last Name","Display Name","Email"</code><br /><br />' . "\n";
  141.  
  142. echo 'If you fill the ID field, the Import routine will update an account matching the ID you specify (so long as the account ID does NOT belong to an Administrator, this is for security). When importing new Users/Members, you can leave the ID field empty Don\'t remove it, just leave it empty (i.e. <code>""</code>).<br /><br />'."\n";
  143.  
  144. echo 'Example: <code>"","Username","First Name","Last Name","Display Name","Email"</code>' . "\n";
  145.  
  146. echo '<div class="ws-menu-page-hr"></div>' . "\n";
  147.  
  148. echo 'Additional extended information can also be included; even Custom Registration/Profile Fields:<br />' . "\n";
  149. echo 'Please see this KB article for more detailed instructions: <a href="http://www.s2member.com/kb/importing-updating-users/" target="_blank" rel="external nofollow x-link">Import (Or Mass Update Users)</a>' . "\n";
  150. echo '</form>' . "\n";
  151. echo '</td>' . "\n";
  152.  
  153. echo '</tr>' . "\n";
  154. echo '</tbody>' . "\n";
  155. echo '</table>' . "\n";
  156. echo '</div>' . "\n";
  157.  
  158. echo '</div>' . "\n";
  159. }
  160.  
  161. echo '<div class="ws-menu-page-group" title="User/Member CSV Exportation">' . "\n";
  162.  
  163. echo '<div class="ws-menu-page-section ws-plugin--s2member-pro-user-exportation-section">' . "\n";
  164. echo '<h3>User/Member Exportation (download CSV export files)</h3>' . "\n";
  165.  
  166. echo '<form method="post" name="ws_plugin__s2member_pro_export_users_form" id="ws-plugin--s2member-pro-export-users-form">' . "\n";
  167. echo '<input type="hidden" name="ws_plugin__s2member_pro_export_users" id="ws-plugin--s2member-pro-export-users" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-pro-export-users")) . '" />' . "\n";
  168.  
  169. echo '<table class="form-table">' . "\n";
  170. echo '<tbody>' . "\n";
  171. echo '<tr>' . "\n";
  172.  
  173. echo '<th>' . "\n";
  174. echo '<label for="ws-plugin--s2member-pro-export-users-format">' . "\n";
  175. echo 'CSV File Preference:' . "\n";
  176. echo '</label>' . "\n";
  177. echo '</th>' . "\n";
  178.  
  179. echo '</tr>' . "\n";
  180. echo '<tr>' . "\n";
  181.  
  182. echo '<td>' . "\n";
  183. echo '<select name="ws_plugin__s2member_pro_export_users_format" id="ws-plugin--s2member-pro-export-users-format">' . "\n";
  184. echo '<option value="" selected="selected">Default (CSV, perfectly formatted for easy re-importation)</option>' . "\n";
  185. echo '<option value="readable">Easy-Read (CSV w/ improved readability; CANNOT be re-imported)</option>' . "\n";
  186. echo '</select><br />' . "\n";
  187. echo '<em>Open CSV files with Notepad, MS Excel, or <a href="http://www.openoffice.org/" target="_blank" rel="external">OpenOffice</a> (recommended).</em>';
  188. echo '</td>' . "\n";
  189.  
  190. echo '</tr>' . "\n";
  191. echo '<tr>' . "\n";
  192.  
  193. echo '<th>' . "\n";
  194. echo '<label for="ws-plugin--s2member-pro-export-users-utf8-bom">' . "\n";
  195. echo 'Add UTF-8 BOM (Byte Order Marker)?' . "\n";
  196. echo '</label>' . "\n";
  197. echo '</th>' . "\n";
  198.  
  199. echo '</tr>' . "\n";
  200. echo '<tr>' . "\n";
  201.  
  202. echo '<td>' . "\n";
  203. echo '<select name="ws_plugin__s2member_pro_export_users_utf8_bom" id="ws-plugin--s2member-pro-export-users-utf8-bom">' . "\n";
  204. echo '<option value="0" selected="selected">Default (no, I will choose UTF-8 encoding when I open the file)</option>' . "\n";
  205. echo '<option value="1">Yes (add a UTF-8 Byte Order Marker so that UTF-8 encoding is always in use for this file)</option>' . "\n";
  206. echo '</select><br />' . "\n";
  207. echo '<em>If <code>Yes</code> — please open CSV files with <a href="http://www.openoffice.org/" target="_blank" rel="external">OpenOffice</a> (recommended).</em>';
  208. echo '</td>' . "\n";
  209.  
  210. echo '</tr>' . "\n";
  211. echo '<tr>' . "\n";
  212.  
  213. echo '<th>' . "\n";
  214. echo '<label for="ws-plugin--s2member-pro-export-users-start">' . "\n";
  215. echo 'CSV File Exportation:' . "\n";
  216. echo '</label>' . "\n";
  217. echo '</th>' . "\n";
  218.  
  219. echo '</tr>' . "\n";
  220. echo '<tr>' . "\n";
  221.  
  222. echo '<td>' . "\n";
  223. echo 'You have a total of ' . number_format (c_ws_plugin__s2member_utils_users::users_in_database ()) . ' User/Member rows in the database' . ((is_multisite ()) ? ' for this site' : '') . '.<br />' . "\n";
  224. echo 'You can export up to 1000 database rows in each file; starting from a particular row that you specify.<br />' . "\n";
  225. echo 'Export, starting with row#: <input type="text" autocomplete="off" name="ws_plugin__s2member_pro_export_users_start" id="ws-plugin--s2member-pro-export-users-start" style="width:100px;" value="1" /> <input type="submit" class="button-primary" value="Export Now" />' . "\n";
  226.  
  227. echo '<div class="ws-menu-page-hr"></div>' . "\n";
  228.  
  229. echo '<em>Please note. Export files do NOT contain Passwords. Passwords are stored by WordPress® with one-way encryption. In other words, it\'s not possible for s2Member to include them in the export file. However, this does NOT create a problem, because when/if you re-import existing Users/Members with the Password field empty, s2Member will simply keep the existing Password that is already on file. For further information, please read all Import instructions, regarding Passwords.</em>' . "\n";
  230. echo '</td>' . "\n";
  231.  
  232. echo '</tr>' . "\n";
  233. echo '</tbody>' . "\n";
  234. echo '</table>' . "\n";
  235.  
  236. echo '</form>' . "\n";
  237. echo '</div>' . "\n";
  238.  
  239. echo '</div>' . "\n";
  240.  
  241. echo '<div class="ws-menu-page-group" title="s2Member® Options (Import/Export)"' . ((isset ($_POST["ws_plugin__s2member_pro_import_ops"])) ? ' default-state="open"' : '') . '>' . "\n";
  242.  
  243. echo '<div class="ws-menu-page-section ws-plugin--s2member-pro-ops-importation-exportation-section">' . "\n";
  244.  
  245. echo '<h3 style="margin-bottom:5px;">s2Member® Options Export <small>(<a href="' . esc_attr (site_url ("/?ws_plugin__s2member_pro_export_ops=" . urlencode (wp_create_nonce ("ws-plugin--s2member-pro-export-ops")))) . '">download serialized export file</a>)</small></h3>' . "\n";
  246. echo '<p style="margin-top:5px;">This allows you to export your current s2Member® configuration, and then import it into another instance of WordPress®.' . "\n";
  247.  
  248. echo '<div class="ws-menu-page-hr"></div>' . "\n";
  249.  
  250. echo '<h3 style="margin-bottom:5px;">s2Member® Options Import <small>(upload your serialized export file)</small></h3>' . "\n";
  251. echo '<p style="margin-top:5px;">This allows you to import your s2Member® configuration export file, from another instance of WordPress®.' . "\n";
  252.  
  253. echo '<table class="form-table">' . "\n";
  254. echo '<tbody>' . "\n";
  255. echo '<tr>' . "\n";
  256.  
  257. echo '<td>' . "\n";
  258. echo '<form method="post" enctype="multipart/form-data" name="ws_plugin__s2member_pro_import_ops_form" id="ws-plugin--s2member-pro-import-ops-form">' . "\n";
  259. echo '<input type="hidden" name="ws_plugin__s2member_pro_import_ops" id="ws-plugin--s2member-pro-import-ops" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-pro-import-ops")) . '" />' . "\n";
  260. echo '<input type="file" name="ws_plugin__s2member_pro_import_ops_file" id="ws-plugin--s2member-pro-import-ops-file" />&nbsp;&nbsp;&nbsp;<input type="submit" class="button-primary" value="Import Now" />' . "\n";
  261. echo '</form>' . "\n";
  262. echo '</td>' . "\n";
  263.  
  264. echo '</tr>' . "\n";
  265. echo '</tbody>' . "\n";
  266. echo '</table>' . "\n";
  267.  
  268. echo '</div>' . "\n";
  269.  
  270. echo '</div>' . "\n";
  271.  
  272. echo '</td>' . "\n";
  273.  
  274. echo '<td class="ws-menu-page-table-r">' . "\n";
  275. c_ws_plugin__s2member_menu_pages_rs::display ();
  276. echo '</td>' . "\n";
  277.  
  278. echo '</tr>' . "\n";
  279. echo '</tbody>' . "\n";
  280. echo '</table>' . "\n";
  281.  
  282. echo '</div>' . "\n";
  283. }
  284. }
  285. }
  286.  
  287. new c_ws_plugin__s2member_pro_menu_page_import_export ();
  288. ?>

pro\s2member-pro\includes\menu-pages\import-export.inc.php

Source Code Documentation