Lingotek Translation - Version 1.2.3

Version Description

(2016-8-24) =

  • Fixed a bug that prevented the removal of target languages from the Dashboard
  • Updated code for compatibility with Polylang version 2.0
  • Fixed CSS conflict with other plugins
Download this release

Release Info

Developer erichie
Plugin Icon 128x128 Lingotek Translation
Version 1.2.3
Comparing to
See all releases

Code changes from version 1.2.2 to 1.2.3

Files changed (85) hide show
  1. admin/actions.php +0 -0
  2. admin/admin.php +24 -1
  3. admin/content-table.php +0 -0
  4. admin/custom-fields-table.php +0 -0
  5. admin/filters-columns.php +0 -0
  6. admin/filters-media.php +0 -0
  7. admin/filters-post.php +2 -2
  8. admin/filters-term.php +0 -0
  9. admin/import.php +44 -0
  10. admin/import/FormatConverter.php +237 -0
  11. admin/import/StandardImportObject.php +95 -0
  12. admin/import/import-table.php +523 -0
  13. admin/import/view-content.php +139 -0
  14. admin/import/view-settings.php +91 -0
  15. admin/manage/view-content.php +0 -0
  16. admin/manage/view-custom-fields.php +0 -0
  17. admin/manage/view-edit-profile.php +0 -0
  18. admin/manage/view-profiles.php +0 -0
  19. admin/manage/view-string-groups.php +0 -0
  20. admin/manage/view-strings.php +0 -0
  21. admin/post-actions.php +0 -0
  22. admin/profiles-table.php +0 -0
  23. admin/settings.php +0 -0
  24. admin/settings/connect-account.php +0 -0
  25. admin/settings/view-account.php +0 -0
  26. admin/settings/view-defaults.php +0 -0
  27. admin/settings/view-preferences.php +17 -0
  28. admin/settings/view-utilities.php +0 -0
  29. admin/string-actions.php +0 -0
  30. admin/strings-table.php +0 -0
  31. admin/table-string.php +44 -1
  32. admin/term-actions.php +0 -0
  33. admin/tutorial/content.php +0 -0
  34. admin/tutorial/credits.php +0 -0
  35. admin/tutorial/faq.php +0 -0
  36. admin/tutorial/features.php +0 -0
  37. admin/tutorial/img/add-languages.png +0 -0
  38. admin/tutorial/img/add-page.png +0 -0
  39. admin/tutorial/img/add-page2.png +0 -0
  40. admin/tutorial/img/automatic-translation.gif +0 -0
  41. admin/tutorial/img/automatic-translation.png +0 -0
  42. admin/tutorial/img/check-status.png +0 -0
  43. admin/tutorial/img/content-types.png +0 -0
  44. admin/tutorial/img/dashboard.png +0 -0
  45. admin/tutorial/img/polylang-compatible.png +0 -0
  46. admin/tutorial/img/pro-translation.png +0 -0
  47. admin/tutorial/img/professional-translation.png +0 -0
  48. admin/tutorial/img/ready-to-upload.png +0 -0
  49. admin/tutorial/img/request-translations.png +0 -0
  50. admin/tutorial/img/translation-profiles.png +0 -0
  51. admin/tutorial/img/translation-services.png +0 -0
  52. admin/tutorial/img/translations-downloaded.png +0 -0
  53. admin/tutorial/img/translations-ready-for-download.png +0 -0
  54. admin/tutorial/img/translations-underway.png +0 -0
  55. admin/tutorial/img/workbench-full.png +0 -0
  56. admin/tutorial/img/workbench.png +0 -0
  57. admin/utilities.php +0 -0
  58. admin/view-dashboard.php +0 -0
  59. admin/view-manage.php +0 -0
  60. admin/view-network.php +0 -0
  61. admin/view-tutorial.php +0 -0
  62. admin/wp-import.php +3 -3
  63. css/admin.css +1 -2
  64. img/lingotek-chevrons-blue.png +0 -0
  65. img/lingotek-icon.png +0 -0
  66. img/lingotek-white.png +0 -0
  67. include/api.php +70 -38
  68. include/callback.php +0 -0
  69. include/dashboard.php +15 -4
  70. include/group-post.php +0 -0
  71. include/group-string.php +0 -0
  72. include/group-term.php +0 -0
  73. include/group.php +1 -1
  74. include/http.php +0 -0
  75. include/model.php +0 -0
  76. include/plugins-compat.php +0 -0
  77. include/pointer.php +0 -0
  78. js/defaults.js +0 -0
  79. js/progress.js +0 -0
  80. js/updater.js +0 -0
  81. languages/wp-lingotek-fr_FR.mo +0 -0
  82. languages/wp-lingotek-fr_FR.po +0 -0
  83. lingotek.php +2 -2
  84. readme.txt +8 -2
  85. uninstall.php +0 -0
admin/actions.php CHANGED
File without changes
admin/admin.php CHANGED
@@ -214,12 +214,16 @@ class Lingotek_Admin {
214
  array($this, 'display_dashboard_page'), 'dashicons-translation'
215
  );
216
 
 
217
  add_submenu_page($this->plugin_slug, __('Translation Dashboard', 'lingotek-translation'), __('Dashboard', 'lingotek-translation'), 'manage_options', $this->plugin_slug, array($this, 'display_dashboard_page'));
218
  add_submenu_page($this->plugin_slug, __('Translation Management', 'lingotek-translation'), __('Manage', 'lingotek-translation'), 'manage_options', $this->plugin_slug . '_manage', array($this, 'display_manage_page'));
219
  add_submenu_page($this->plugin_slug, __('Translation Settings', 'lingotek-translation'), __('Settings', 'lingotek-translation'), 'manage_options', $this->plugin_slug . '_settings', array($this, 'display_settings_page'));
220
  add_submenu_page($this->plugin_slug, __('Lingotek Tutorial', 'lingotek-translation'), __('Tutorial', 'lingotek-translation'), 'manage_options', $this->plugin_slug . '_tutorial', array($this, 'display_tutorial_page'));
221
- }
222
 
 
 
 
 
223
  /*
224
  * displays the settings page
225
  *
@@ -622,4 +626,23 @@ class Lingotek_Admin {
622
  }
623
  }
624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
  }
214
  array($this, 'display_dashboard_page'), 'dashicons-translation'
215
  );
216
 
217
+
218
  add_submenu_page($this->plugin_slug, __('Translation Dashboard', 'lingotek-translation'), __('Dashboard', 'lingotek-translation'), 'manage_options', $this->plugin_slug, array($this, 'display_dashboard_page'));
219
  add_submenu_page($this->plugin_slug, __('Translation Management', 'lingotek-translation'), __('Manage', 'lingotek-translation'), 'manage_options', $this->plugin_slug . '_manage', array($this, 'display_manage_page'));
220
  add_submenu_page($this->plugin_slug, __('Translation Settings', 'lingotek-translation'), __('Settings', 'lingotek-translation'), 'manage_options', $this->plugin_slug . '_settings', array($this, 'display_settings_page'));
221
  add_submenu_page($this->plugin_slug, __('Lingotek Tutorial', 'lingotek-translation'), __('Tutorial', 'lingotek-translation'), 'manage_options', $this->plugin_slug . '_tutorial', array($this, 'display_tutorial_page'));
 
222
 
223
+ $selected_options = Lingotek_Model::get_prefs();
224
+ if (isset($selected_options['import_enabled']) && $selected_options['import_enabled']['enabled'] == '1'){
225
+ add_submenu_page($this->plugin_slug, __('Lingotek Import', 'lingotek-translation'), __('Import', 'lingotek-translation'), 'manage_options', $this->plugin_slug . '_import', array($this, 'display_import_page')); }
226
+ }
227
  /*
228
  * displays the settings page
229
  *
626
  }
627
  }
628
 
629
+ public function display_import_page() {
630
+ if (self::has_token_details()) {
631
+ // $client = new Lingotek_API();
632
+ // $docs = $client->get_documents(array('limit'=>5000));
633
+ // //$community_id = get_option('lingotek_community');
634
+ // $communities = $client->get_communities();
635
+ // var_dump($communities->entities);
636
+ // die();
637
+ // $projects = $client->get_projects($community_id)->entities;
638
+ // var_dump($projects);
639
+ // die();
640
+ settings_errors();
641
+ include(LINGOTEK_ADMIN_INC) . '/import.php';
642
+ }
643
+ else {
644
+ $this->display_settings_page();
645
+ }
646
+ }
647
+
648
  }
admin/content-table.php CHANGED
File without changes
admin/custom-fields-table.php CHANGED
File without changes
admin/filters-columns.php CHANGED
File without changes
admin/filters-media.php CHANGED
File without changes
admin/filters-post.php CHANGED
@@ -41,12 +41,12 @@ class Lingotek_Filters_Post extends PLL_Admin_Filters_Post {
41
  *
42
  * @since 0.1
43
  */
44
- public function add_meta_boxes($post_type) {
45
  global $post_ID;
46
  if ($this->model->is_translated_post_type($post_type)) {
47
  $document = $this->lgtm->get_group('post', $post_ID);
48
  if (empty($document->source)) {
49
- parent::add_meta_boxes($post_type);
50
  }
51
  else {
52
  add_action( 'edit_form_top', array( &$this, 'edit_form_top' ) );
41
  *
42
  * @since 0.1
43
  */
44
+ public function add_meta_boxes($post_type, $post = null) {
45
  global $post_ID;
46
  if ($this->model->is_translated_post_type($post_type)) {
47
  $document = $this->lgtm->get_group('post', $post_ID);
48
  if (empty($document->source)) {
49
+ parent::add_meta_boxes($post_type, $document);
50
  }
51
  else {
52
  add_action( 'edit_form_top', array( &$this, 'edit_form_top' ) );
admin/filters-term.php CHANGED
File without changes
admin/import.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <h2><?php _e('Import', 'wp-lingotek'); ?></h2>
3
+ <p class="description"><?php printf(__('Import your posts from another wordpress blog through Lingotek', 'wp-lingotek'), 'admin.php?page=wp-lingotek_import'); ?></p>
4
+
5
+
6
+ <?php
7
+ $menu_items = array(
8
+ 'content' => __('Content', 'wp-lingotek'),
9
+ 'settings' => __('Settings', 'wp-lingotek')
10
+ );
11
+ ?>
12
+
13
+ <h3 class="nav-tab-wrapper">
14
+ <?php
15
+ $menu_item_index = 0;
16
+ foreach ($menu_items as $menu_item_key => $menu_item_label) {
17
+ $use_as_default = ($menu_item_index === 0 && !isset($_GET['sm'])) ? TRUE : FALSE;
18
+ $alias = NULL;
19
+ // custom sub sub-menus
20
+ if(isset($_GET['sm']) && $_GET['sm'] == "edit-profile") {
21
+ $alias = "profiles";
22
+ }
23
+ ?>
24
+
25
+ <a class="nav-tab <?php if ($use_as_default || (isset($_GET['sm']) && $_GET['sm'] == $menu_item_key) || $alias == $menu_item_key): ?> nav-tab-active<?php endif; ?>"
26
+ href="admin.php?page=<?php echo $_GET['page']; ?>&amp;sm=<?php echo $menu_item_key; ?>"><?php echo $menu_item_label; ?></a>
27
+ <?php
28
+ $menu_item_index++;
29
+ }
30
+ ?>
31
+ </h3>
32
+
33
+ <?php
34
+ settings_errors();
35
+ $submenu = isset($_GET['sm']) ? $_GET['sm'] : 'content';
36
+ $dir = dirname(__FILE__) . '/import/';
37
+ $filename = $dir . 'view-' . $submenu . ".php";
38
+ if (file_exists($filename))
39
+ include $filename;
40
+ else
41
+ echo "TO-DO: create <i>" . 'import/view-' . $submenu . ".php</i>";
42
+ ?>
43
+
44
+ </div>
admin/import/FormatConverter.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'StandardImportObject.php';
4
+
5
+ /**
6
+ *This class exists to convert other content (e.g. JSON--Drupal 7, Drupal 8, Middleware--
7
+ *HTML, XML, Text, Plaintext) into content compatible with WP
8
+ *
9
+ *@author Unkown
10
+ *@uses StandardImportObject.php|StandardImportObject
11
+ *@return StandardImportObject returns an object that is in the format and has the
12
+ *content to be imported into WordPress
13
+ *
14
+ */
15
+ class FormatConverter
16
+ { /**
17
+ *The document that is used to determine information about the import. It is
18
+ *the source document that can be accessed.
19
+ */
20
+ private $source_doc;
21
+ /**
22
+ *The content is the bulk of the information without format, source, etc. This
23
+ *is what is converted into the title and body of the wp import.
24
+ */
25
+ private $content;
26
+ /**
27
+ *The format is the format of the source upload document so that it can be handled
28
+ *by the right conversion function (e.g. JSON, HTML, TXT, etc.)
29
+ */
30
+ private $format;
31
+
32
+ /**
33
+ *Constructor
34
+ *Sets up the FormatConverter object so it can be converted
35
+ *
36
+ *@author Unkown
37
+ *
38
+ *@param object $source_doc The document that needs to be converted and then imported
39
+ *@param string $content The content portion of the document -- This is what becomes
40
+ * the body of the WP post/page
41
+ *@param string $format The format of the file. The extension of the document
42
+ * is used to choose the right function to convert to standard
43
+ *@return void This builds an object that is then converted to wp import
44
+ */
45
+ function __construct($source_doc, $content, $format)
46
+ {
47
+ $this->source_doc = $source_doc;
48
+ $this->content = $content;
49
+ $this->format = $format;
50
+ }
51
+
52
+
53
+ /**
54
+ *This function determines which converter function is needed. If there is not
55
+ *a converter function for the selected document then it defaults to
56
+ *JSON (in the else statement) and attempts the conversion with the assumption
57
+ *of working with a JSON file.
58
+ *
59
+ *@author Unkown
60
+ *@return StandardImportObject $importObject An object that can be imported into WP
61
+ */
62
+ public function convert_to_standard(){
63
+ if (method_exists($this, $this->format.'_to_standard')){
64
+ $importObject = call_user_func(array($this, $this->format.'_to_standard'), $this->source_doc, $this->content);
65
+ return $importObject;
66
+ }
67
+ else {
68
+ $importObject = call_user_func(array($this,'json_to_standard'), $this->source_doc, $this->content);
69
+ return $importObject;
70
+ }
71
+ }
72
+
73
+
74
+ /**
75
+ *Converts source JSON into a StandardImportObject that can be imported into WP
76
+ *@author Unkown
77
+ *@param object $source_doc source document
78
+ *@param string $content JSON string that is then parsed to get the relevant
79
+ *information for the title and body
80
+ *@return StandardImportObject That can be imported into WP
81
+ */
82
+ public function json_to_standard($source_doc, $content){
83
+
84
+ /**
85
+ *These string replaces are to make it so that we can access the json objects
86
+ *with these titles. They were being imported with @ before the key and that
87
+ *made them inaccessible. This is specific to Middleware json strings.
88
+ *@author Matt Smith and TJ Murphy
89
+ */
90
+ $content = str_replace('"@title"','"title"',$content);
91
+ $content = str_replace('"@type"','"type"',$content);
92
+
93
+ $decoded_json = json_decode($content);
94
+
95
+ $content = __('We could not parse the data from this document.
96
+ Are you sure that it is in a recognizable format, such as JSON, XML, HTML, or plain text?', 'wp-lingotek');
97
+ $title = __('No title found', 'wp-lingotek');
98
+ $error = false;
99
+
100
+
101
+ /**
102
+ *An if statement to check for the different json patterns to find the content
103
+ *that will be the body of the WP imported post/page
104
+ *@author Unkown and TJ Murphy
105
+ *@return string $content is set -- if nothing matches then $content remains
106
+ *with a warning
107
+ *@see $content
108
+ */
109
+ if (isset($decoded_json->post->post_content)){ // Drupal 7
110
+ $content = $decoded_json->post->post_content;
111
+ }
112
+ else if (isset($decoded_json->body[0]->value)){ // Drupal 8
113
+ $content = $decoded_json->body[0]->value;
114
+ }
115
+ else if (isset($decoded_json->args->description)){
116
+ $content = $decoded_json->args->description;
117
+ }
118
+ else if (isset($decoded_json->content->body)){ // Middleware - MindTouch
119
+ $content = $decoded_json->content->body;
120
+ }
121
+ else if (isset($decoded_json->body)){ // Middleware - Zendesk and HubSpot
122
+ $content = $decoded_json->body;
123
+ }
124
+ else if (isset($decoded_json->email_body)){ // Middleware - Email HubSpot
125
+ $content = $decoded_json->email_body;
126
+ }
127
+ else if (isset($decoded_json->post_summary)){ // Middleware
128
+ $content = $decoded_json->post_summary;
129
+ }
130
+ else if (isset($decoded_json->description)){ // Middleware
131
+ $content = $decoded_json->description;
132
+ }
133
+ else {
134
+ $error = true;
135
+ }
136
+
137
+ /**
138
+ *An if statement to check for the different json patterns to find the title
139
+ *that will be the title of the WP imported post/page
140
+ *@author Unkown and TJ Murphy
141
+ *@return string $title is set -- if nothing matches then $error is set to TRUE
142
+ *@see $title
143
+ */
144
+ if (isset($decoded_json->title[0]->value)){ // Drupal 8
145
+ $title = $decoded_json->title[0]->value;
146
+ }
147
+ else if (isset($decoded_json->post->post_title)){ // Drupal 7
148
+ $title = $decoded_json->post->post_title;
149
+ }
150
+ else if (isset($decoded_json->content->title)){ // Middleware - MindTouch
151
+ $title = $decoded_json->content->title;
152
+ }
153
+ else if (isset($decoded_json->title)){ // Middleware - Zendesk and HubSpot
154
+ $title = $decoded_json->title;
155
+ }
156
+ else if (isset($decoded_json->name)){ // Middleware - Email HubSpot
157
+ $title = $decoded_json->name;
158
+ }
159
+ else {
160
+ $error = true;
161
+ }
162
+
163
+ return new StandardImportObject($title, $content, $error);
164
+ }
165
+
166
+ /**
167
+ *Converts source XML into a StandardImportObject that can be imported into WP
168
+ *@author Unkown
169
+ *@param object $source_doc source document
170
+ *@param string $xml_string XML string that is then parsed to get the relevant
171
+ *information for the title and body
172
+ *@return StandardImportObject That can be imported into WP
173
+ */
174
+ public function xml_to_standard($source_doc, $xml_string){
175
+ $content = __('We could not parse the data from this document.
176
+ Are you sure that it is in a recognizable format, such as JSON, XML, HTML, or plain text?', 'wp-lingotek');
177
+ $title = __('No title found', 'wp-lingotek');
178
+ $error_message_xml = __('Failed to load XML', 'wp-lingotek');
179
+ $error = false;
180
+ $xml = new SimpleXMLElement($xml_string);
181
+ if ($xml === false){
182
+ echo $error_message_xml;
183
+ $error = true;
184
+ }
185
+
186
+ $found_content = (array) $xml->xpath('//element');
187
+ if ($found_content){
188
+ $content = (string) $found_content[0];
189
+ $title = (string) $source_doc->properties->title;
190
+ }
191
+ else {
192
+ $error = true;
193
+ }
194
+
195
+ return new StandardImportObject($title, $content, $error);
196
+ }
197
+
198
+ /**
199
+ *Converts source TXT into a StandardImportObject that can be imported into WP
200
+ *@author Unkown
201
+ *@param object $source_doc source document
202
+ *@param string $content TXT string that is then parsed to get the relevant
203
+ *information for the title and body
204
+ *@return StandardImportObject That can be imported into WP
205
+ */
206
+ public function txt_to_standard($source_doc, $content){
207
+ $title = $source_doc->properties->title;
208
+ return new StandardImportObject($title, $content);
209
+ }
210
+
211
+ /**
212
+ *Converts source PLAINTEXT into a StandardImportObject that can be imported into WP
213
+ *@author Unkown
214
+ *@param object $source_doc source document
215
+ *@param string $content PLAINTEXT string that is then parsed to get the relevant
216
+ *information for the title and body
217
+ *@return StandardImportObject That can be imported into WP
218
+ */
219
+ public function plaintext_to_standard($source_doc, $content){
220
+ $title = $source_doc->properties->title;
221
+ return new StandardImportObject($title, $content);
222
+ }
223
+
224
+ /**
225
+ *Converts source HTML into a StandardImportObject that can be imported into WP
226
+ *@author Unkown
227
+ *@param object $source_doc source document
228
+ *@param string $content HTML string that is then parsed to get the relevant
229
+ *information for the title and body
230
+ *@return StandardImportObject That can be imported into WP
231
+ */
232
+ public function html_to_standard($source_doc, $content){
233
+ $title = $source_doc->properties->title;
234
+ return new StandardImportObject($title, $content);
235
+ }
236
+ }
237
+ ?>
admin/import/StandardImportObject.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Used to hold all important information about a post or page to be imported
5
+ *@author Unknown
6
+ */
7
+ class StandardImportObject
8
+ {
9
+ private $title;
10
+ private $content;
11
+ private $error;
12
+
13
+ /**
14
+ *Constructor
15
+ *@author Unknown
16
+ *@param string $title This is what will become the title of the post/page
17
+ *when the document is imported into WP
18
+ *@param string $content This is what will become the body of the post/page
19
+ *when the document is imported into WP
20
+ *@param bool $error captures if there was an error in preparing the document
21
+ *@return void just sets the variables
22
+ */
23
+ function __construct($title, $content, $error = false)
24
+ {
25
+ $this->title = $title;
26
+ $this->content = $content;
27
+ $this->error = $error;
28
+ }
29
+
30
+ /**
31
+ *Gets the title of the object
32
+ *@author Unknown
33
+ *@return string $this->title
34
+ */
35
+ public function getTitle()
36
+ {
37
+ return $this->title;
38
+ }
39
+
40
+ /**
41
+ *Sets the title of the object
42
+ *@author Unknown
43
+ *@param string $title What the title of the import should be
44
+ *@return self
45
+ */
46
+ public function setTitle($title)
47
+ {
48
+ $this->title = $title;
49
+ return $this;
50
+ }
51
+
52
+ /**
53
+ *Gets the Content of the object
54
+ *@author Unknown
55
+ *@return string $this->content
56
+ */
57
+ public function getContent()
58
+ {
59
+ return $this->content;
60
+ }
61
+
62
+ /**
63
+ *Sets the content of the object
64
+ *@author Unknown
65
+ *@param string $content What the body of the import should be
66
+ *@return self
67
+ */
68
+ public function setContent($content)
69
+ {
70
+ $this->content = $content;
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ *Sets the error for the object
76
+ *@author Unknown
77
+ *@param bool $trueOrFalse TRUE means there was an error, FALSE means there
78
+ *was not.
79
+ *@return void
80
+ */
81
+ public function setError($trueOrFalse){
82
+ $this->error = $trueOrFalse;
83
+ }
84
+
85
+ /**
86
+ *Checks to see if the object has an error.
87
+ *@author Unknown
88
+ *@return bool $this->error
89
+ */
90
+ public function hasError(){
91
+ return $this->error;
92
+ }
93
+
94
+ }
95
+ ?>
admin/import/import-table.php ADDED
@@ -0,0 +1,523 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!class_exists('WP_List_Table')) {
4
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); // since WP 3.1
5
+ }
6
+
7
+ /**
8
+ *Requires and evaluates the FormatConverter.php before continuing. If it is not
9
+ *found then a fatal error is thrown
10
+ *@author Unkown
11
+ *@link http://php.net/manual/en/function.include.php
12
+ *@see FormatConverter.php
13
+ *
14
+ */
15
+ require_once 'FormatConverter.php';
16
+ settings_errors();
17
+
18
+ /**
19
+ *$client is an API call for the client logged in. This gives the end-user the ability
20
+ *to manipulate their documents
21
+ *@uses wp-lingotek/include/api.php/Lingotek_API
22
+ *@deprecated since 24 May 2016 This was making an extra API call and making load
23
+ *time very slow.
24
+ */
25
+ //$client = new Lingotek_API();
26
+ //$docs = $client->get_documents(array('limit'=>5000));
27
+ //$communities = $client->get_communities();
28
+
29
+
30
+ /**
31
+ *This class is used to prepare the import table that is displayed when users go
32
+ *to the import tab.
33
+ *@author Unkown
34
+ *
35
+ */
36
+ class Lingotek_Import_Table extends WP_List_Table {
37
+
38
+ var $client = null;
39
+ var $doc_data = array();
40
+ var $projects = array();
41
+ var $import_status = null;
42
+ var $supported_extentions = array('json', 'xml');
43
+ var $document_count = 0;
44
+ /**
45
+ *Used to mark the number of successful imports on a bulk import
46
+ *@author TJ Murphy
47
+ */
48
+ var $import_success_count = 0;
49
+ /**
50
+ *Used to mark the number of failed imports on a bulk import
51
+ *@author TJ Murphy
52
+ */
53
+ var $import_failure_count = 0;
54
+ /**
55
+ *Used to gather the doc ids for documents that did not import as expected
56
+ *@author TJ Murphy
57
+ */
58
+ var $unsuccessful_imports = array();
59
+
60
+ /**
61
+ *Constructor
62
+ *@author Unkown and TJ Murphy
63
+ *@uses wp-lingotek/include/api.php/Lingotek_API
64
+ *@see Lingotek_Import_Table::get_docs()
65
+ *@see Lingotek_Import_Table::format_docs()
66
+ */
67
+ function __construct() {
68
+ $this->client = new Lingotek_API();
69
+
70
+ $this->projects = $this->get_projects($this->client->get_communities());
71
+ $this->document_count = $this->client->get_document_count();
72
+ /**
73
+ *Sets $import_success_count to ZERO
74
+ *@author TJ Murphy
75
+ */
76
+ $this->import_success_count = 0;
77
+ /**
78
+ *Sets $import_failure_count to ZERO
79
+ *@author TJ Murphy
80
+ */
81
+ $this->import_failure_count = 0;
82
+ /**
83
+ *Sets $unsuccessful_imports to a blank array
84
+ *@author TJ Murphy
85
+ */
86
+ $this->unsuccessful_imports = array();
87
+ /**
88
+ *This will get ALL docs for the client
89
+ *@author TJ Murphy
90
+ *@see Lingotek_Import_Table::get_docs()
91
+ *@see Lingotek_Import_Table::format_docs()
92
+ */
93
+ $docs = $this->get_docs($this->client, $this->document_count);
94
+ $this->doc_data = $this->format_docs($docs);
95
+
96
+ global $status, $page;
97
+ parent::__construct(array(
98
+ 'singular' => 'post',
99
+ 'plural' => 'posts',
100
+ 'ajax' => false
101
+ ));
102
+ }
103
+ /**
104
+ *This function is to access the count of successful imports. It is used for both
105
+ *bulk and single imports. This is used for a few checks and a few messages that
106
+ *get displayed to the end-user after imports occur
107
+ *
108
+ *@author TJ Murphy
109
+ *@uses Lingotek_Import_Table::$import_success_count
110
+ *@return void
111
+ *
112
+ */
113
+ function add_one_import_success_count(){
114
+ $this->import_success_count++;
115
+ }
116
+
117
+ /**
118
+ *This function is to add the doc ids of the failed imports to an array so that
119
+ *they can be displayed to the end-user. This just gives them more information
120
+ *about the errors they may encounter. It also handles the counts for failed imports.
121
+ *
122
+ *@author TJ Murphy
123
+ *@param string $doc_id
124
+ *@return void
125
+ */
126
+ function add_doc_id_to_unsuccessful_imports($doc_id){
127
+ array_push($this->unsuccessful_imports,$doc_id);
128
+ $this->import_failure_count++;
129
+ }
130
+
131
+ /**
132
+ *This function is to list the captured doc ids in a string separated by commas
133
+ *so it can be displayed for the end-user in a message.
134
+ *
135
+ *@author TJ Murphy
136
+ *@uses Lingotek_Import_Table::$unsuccessful_imports
137
+ *@return string $unsuccessful_imports_string this creates an HTML string that
138
+ *creates an unordered list of doc ids that failed to import
139
+ */
140
+ function to_string_unsuccessful_imports(){
141
+ $unsuccessful_imports_string = '<div><ul>';
142
+ foreach ($this->unsuccessful_imports as $doc_id){
143
+ $unsuccessful_imports_string = $unsuccessful_imports_string.'<li>'.(string)$doc_id.'</li>';
144
+ }
145
+ $unsuccessful_imports_string = $unsuccessful_imports_string.'</ul></div>';
146
+ return $unsuccessful_imports_string;
147
+ }
148
+
149
+ /**
150
+ *Calls the API to get all the projects from the TMS and show them for the end-user
151
+ *@author Unkown
152
+ *@uses wp-lingotek/include/api.php/Lingotek_API::get_projects()
153
+ *@param $communitites
154
+ *@return array $new_projects an array of projects with key/value of (project id, project title)
155
+ */
156
+ function get_projects($communities){
157
+ $new_projects = array();
158
+ foreach ($communities->entities as $community){
159
+ $projects = $this->client->get_projects($community->properties->id)->entities;
160
+ foreach ($projects as $project){
161
+ $new_projects[$project->properties->id] = $project->properties->title;
162
+ }
163
+ }
164
+
165
+ return $new_projects;
166
+ }
167
+
168
+ /**
169
+ *Get a list of projects or use id to get the corresponding project
170
+ *extract doc data and insert into correct structure for rendering
171
+ *@author Unkown
172
+ *@uses Lingotek_Import_Table::get_option()
173
+ *@param object $docs list of files that need to be properly formatted to show
174
+ *in the table
175
+ *@return array $result an array of properly formatted objects to be put into
176
+ *the table
177
+ */
178
+ function format_docs($docs) {
179
+ $result = array();
180
+ $count = 1;
181
+ $resources = get_option('lingotek_community_resources');
182
+ $projectInfoArray = $resources['projects'];
183
+
184
+ foreach ($docs as $doc) {
185
+ /**
186
+ *Convert date from unix time and properly format it
187
+ *@author Unkown
188
+ */
189
+ $unix_upload_time = $doc->properties->upload_date / 1000;
190
+ $upload_date_str = gmdate("m/j/Y", $unix_upload_time);
191
+
192
+ $project_name = $doc->properties->project_id;
193
+ if (array_key_exists($doc->properties->project_id, $this->projects)){
194
+ $project_name = $this->projects[$doc->properties->project_id];
195
+ }
196
+
197
+ $doc_properties = array('ID' => $count, 'title' => $doc->properties->title, 'extension' => $doc->properties->extension,
198
+ 'locale' => "<a title=". $doc->entities[0]->properties->language.">".$doc->entities[0]->properties->code.'</a>',
199
+ 'upload_date' => $upload_date_str, 'project_name'=> $project_name, 'id' => $doc->properties->id);
200
+ $result[] = $doc_properties;
201
+ $count++;
202
+ }
203
+ return $result;
204
+ }
205
+
206
+ /**
207
+ *This function makes a query to get the documents
208
+ *@author Unkown
209
+ *@uses wp-lingotek/include/api.php/Lingotek_API::get_documents()
210
+ *@param Lingotek_API $client used to make the API calls to get the docs
211
+ *@param int $per_page default = 10 limits the query to 10 results
212
+ *@param int $page_number default = 1 helps to determine the offset
213
+ *(so we get the right x amount of documents presented on the current page)
214
+ *@return array $docs list of documents returned from the API call get_documents()
215
+ */
216
+ function get_docs($client, $per_page = 10, $page_number = 1){
217
+
218
+ $limit = $per_page;
219
+ $docs = $client->get_documents(array('limit'=>$limit, 'offset'=>(($page_number - 1) * $per_page )));
220
+ return $docs;
221
+ }
222
+
223
+ /**
224
+ * Gets the columns for the table to be displayed properly
225
+ *@author Unkown
226
+ *@return array $columns the appropriate columns i18n ready
227
+ */
228
+ function get_columns() {
229
+ $columns = array(
230
+ 'cb' => '<input type="checkbox" />',
231
+ 'title' => __('Title', 'wp-lingotek'),
232
+ 'extension'=> __('Extension', 'wp-lingotek'),
233
+ 'locale' => __('Locale', 'wp-lingotek'),
234
+ 'upload_date' => __('Upload Date', 'wp-lingotek'),
235
+ 'project_name' => __('Project Name', 'wp-lingotek'),
236
+ 'id' => __('ID', 'wp-lingotek'),
237
+ );
238
+ return $columns;
239
+ }
240
+
241
+ /**
242
+ *This function prepares all the items to be displayed. It calls the get_columns()
243
+ *and other supporting funcitons.
244
+ *@author Unkown and TJ Murphy
245
+ *@uses Lingotek_Import_Table::get_columns()
246
+ *@uses Lingotek_Import_Table::process_actions()
247
+ *@uses Lingotek_Import_Table::get_sortable_columns()
248
+ *@uses Lingotek_Import_Table::usort_reorder()
249
+ *@see wp-admin/includes/class-wp-list-table.php/WP_List_Table::get_items_per_page()
250
+ *@see wp-admin/includes/class-wp-list-table.php/WP_List_Table::get_pagenum()
251
+ *@see wp-admin/includes/class-wp-list-table.php/WP_List_Table::set_pagination_args()
252
+ *@return void This just sets some variables within the object
253
+ */
254
+ function prepare_items() {
255
+
256
+ /**
257
+ *Constant to define how many items per page will show up.
258
+ *@author TJ Murphy
259
+ */
260
+ define('ITEMS_PER_PAGE', 10);
261
+
262
+ $columns = $this->get_columns();
263
+ $this->process_actions();
264
+ $hidden = array();
265
+
266
+ $sortable = $this->get_sortable_columns();
267
+ $this->_column_headers = array($columns, $hidden, $sortable);
268
+
269
+ /**
270
+ *Sets the total_items (total number of documents calculated by us) and
271
+ *the per_page (how many documents appear on a page dtermined by us)
272
+ *@see wp-admin/includes/class-wp-list-table.php/WP_List_Table::set_pagination_args()
273
+ */
274
+ $this->set_pagination_args( [
275
+ 'total_items' => $this->document_count,
276
+ 'per_page' => ITEMS_PER_PAGE
277
+ ] );
278
+
279
+ usort($this->doc_data, array(&$this, 'usort_reorder'));
280
+
281
+ /**
282
+ *This slices the documents for the client and only shows the appropriate number
283
+ *of documents based on the constant ITEMS_PER_PAGE. array_slice takes three
284
+ *parameters ($array, $offset, $length)
285
+ *@author TJ Murphy
286
+ *@link http://php.net/manual/en/function.array-slice.php
287
+ */
288
+ $this->items = array_slice($this->doc_data,((ITEMS_PER_PAGE*$this->get_pagenum())-ITEMS_PER_PAGE),ITEMS_PER_PAGE);
289
+ }
290
+
291
+ /**
292
+ *This sets the column default. The default for the switch statement shows the
293
+ *whole array for troubleshooting purposes
294
+ *@author Unkown
295
+ *@param array $item
296
+ *@param string $column_name
297
+ *@return string $item[$column_name]
298
+ */
299
+ function column_default($item, $column_name) {
300
+ switch ($column_name) {
301
+ case 'title':
302
+ case 'extension':
303
+ case 'locale':
304
+ case 'upload_date':
305
+ case 'project_name':
306
+ case 'id':
307
+ return $item[$column_name];
308
+ default:
309
+ return print_r($item, true);
310
+ }
311
+ }
312
+
313
+ /**
314
+ *Gets the sortable columns and returns the list
315
+ *@author Unkown
316
+ *@return array $sortable_columns
317
+ */
318
+ function get_sortable_columns() {
319
+ $sortable_columns = array(
320
+ 'title' => array('title', false),
321
+ 'extension'=>array('extension', false),
322
+ 'locale' => array('locale', false),
323
+ 'upload_date' => array('upload_date', false),
324
+ 'project_name' => array('project_name', false),
325
+ 'id' => array('id', false)
326
+ );
327
+ return $sortable_columns;
328
+ }
329
+
330
+ /**
331
+ *Sorts the documents by one of the columns. The default sort is with the Title
332
+ *and ascending order. The date sort has its own method to sort, but all other
333
+ *columns are sorted the same way.
334
+ *@author Unknown
335
+ *@return int $result direction of sort
336
+ *@todo it would be great to make the query that gets the documents do an Order By
337
+ *and then this would not even be necessary. It appears this is a limitation in
338
+ *the API.
339
+ */
340
+ function usort_reorder($a, $b) {
341
+ $orderby = (!empty($_GET['orderby']) ) ? $_GET['orderby'] : 'title';
342
+ $order = (!empty($_GET['order']) ) ? $_GET['order'] : 'asc';
343
+ $result = 0;
344
+ if ($orderby == 'upload_date'){
345
+ $date_a = strtotime($a['upload_date']);
346
+ $date_b = strtotime($b['upload_date']);
347
+ $result = $date_a - $date_b;
348
+ }
349
+ else {
350
+ $result = strcmp($a[$orderby], $b[$orderby]);
351
+ }
352
+
353
+ return ( $order === 'asc' ) ? $result : -$result;
354
+ }
355
+
356
+ /**
357
+ *Sets the column Title to have the right information in that column. This includes
358
+ *the popup link to import the file.
359
+ *@author Unknown
360
+ *@see wp-lingotek/admin/string-actions.php/Lingotek_String_actions::row_actions()
361
+ *@return string to be put in the column when displayed
362
+ */
363
+ function column_title($item) {
364
+ $actions = array(
365
+ 'import' => sprintf('<a href="?page=%s&action=%s&post=%s&count=%s&paged=%s">Import</a>',
366
+ $_REQUEST['page'], 'import', $item['id'], $this->importedCount, $this->get_pagenum()),
367
+ );
368
+ return sprintf('%1$s %2$s', $item['title'], $this->row_actions($actions));
369
+ }
370
+
371
+ /**
372
+ *This just gets the actions that are available for bulk actions
373
+ *@author Unknown
374
+ *@return array $actions available actions to be done on a bulk level
375
+ */
376
+ function get_bulk_actions() {
377
+ $actions = array(
378
+ 'import' => 'Import'
379
+ );
380
+ return $actions;
381
+ }
382
+
383
+ /**
384
+ *This function processes any actions (currently the only action is import).
385
+ *This includes bulk imports and individual imports. Then it sets the import as
386
+ *successful or unsuccessful.
387
+ *@author Unknown
388
+ *@uses Lingotek_Import_Table::add_one_import_success_count()
389
+ *@uses Lingotek_Import_Table::add_doc_id_to_unsuccessful_imports()
390
+ *@uses Lingotek_Import_Table::import()
391
+ *@uses Lingotek_Import_Table::$import_success_count
392
+ *@uses Lingotek_Import_Table::$import_status
393
+ *@return void this just sets certain variables in the object.
394
+ */
395
+ public function process_actions() {
396
+ $result = null;
397
+ if( 'import' === $this->current_action() ) {
398
+ if (isset($_POST['post'])){ // bulk action
399
+ foreach($_POST['post'] as $doc_id){
400
+ $result = $this->import($doc_id);
401
+ if ($result != 0){
402
+ $this->add_one_import_success_count();
403
+ }
404
+ else {
405
+ $this->add_doc_id_to_unsuccessful_imports($doc_id);
406
+ }
407
+ }
408
+ }
409
+ else {
410
+ if (isset($_GET['action']) && $_GET['action'] == 'import'){ //single action
411
+ $doc_id = $_GET['post'];
412
+ $result = $this->import($doc_id);
413
+ if ($result != 0){
414
+ $this->add_one_import_success_count();
415
+ }
416
+ else {
417
+ $this->add_doc_id_to_unsuccessful_imports($doc_id);
418
+ }
419
+ }
420
+ }
421
+
422
+ /**
423
+ *This checks the import_success_count to determine if the import status
424
+ *wassuccessful or not. It used to just check if the $result was 0 or not.
425
+ *This led to the last bulk import to determine the import status. Now if
426
+ *any imports are successful it will mark the import status as successful.
427
+ *@author TJ Murphy
428
+ *@uses Lingotek_Import_Table::$import_success_count
429
+ *@uses Lingotek_Import_Table::$import_status
430
+ */
431
+ if ($this->import_success_count > 0){
432
+ $this->import_status = 'success';
433
+ }
434
+ else {
435
+ $this->import_status = 'failure';
436
+ }
437
+ }
438
+ }
439
+
440
+ /**
441
+ *This converts the many objects and strings that are documents into a format
442
+ *that can be imported into WP. If $post_status is not set it gets set to draft.
443
+ *If the $post_type is not set then it gets set to post.
444
+ *@author Unknown
445
+ *@uses wp-lingotek/admin/import/StandardImportObject.php/StandardImportObject
446
+ *@uses wp-lingotek/admin/import/StandardImportObject.php/StandardImportObject::getTitle()
447
+ *@uses wp-lingotek/admin/import/StandardImportObject.php/StandardImportObject::getContent()
448
+ *@see wp-admin/includes/class-wp-screen.php/WP_Screen::get_option()
449
+ *@link https://developer.wordpress.org/reference/functions/wp_insert_post/
450
+ *@param StandardImportObject $object a document that needs to be converted to
451
+ *a standard object that can be imported into WP
452
+ *@return int|bool $result 0 or 1 to show if it was successful or not
453
+ */
454
+ public function import_standard_object(StandardImportObject $object){
455
+ if ($object->hasError()){
456
+ return 0;
457
+ }
458
+
459
+ $post_status = get_option('lingotek_import_prefs')['import_post_status'];
460
+ $post_type = get_option('lingotek_import_prefs')['import_type'];
461
+ if (!isset($post_status) ){
462
+ $post_status = 'draft';
463
+ }
464
+ if (!isset($post_type) ){
465
+ $post_type = 'post';
466
+ }
467
+
468
+ $post_to_import = array(
469
+ 'post_title' => $object->getTitle(),
470
+ 'post_content' => $object->getContent(),
471
+ 'post_status' => $post_status, // draft, published, etc.
472
+ 'post_type' => $post_type, // page or post?
473
+ 'post_category' => array(8,39)
474
+ );
475
+ /**
476
+ *@link https://developer.wordpress.org/reference/functions/wp_insert_post/
477
+ */
478
+ $result = wp_insert_post( $post_to_import );
479
+ return $result;
480
+ }
481
+
482
+ /**
483
+ *This function makes the API calls that send a query and get the documents
484
+ *@author Unknown
485
+ *@uses Lingotek_Import_Table::$client
486
+ *@uses wp-lingotek/admin/import/FormatConverter.php/FormatConverter
487
+ *@uses wp-lingotek/admin/import/FormatConverter.php/FormatConverter::convert_to_standard()
488
+ *@uses wp-lingotek/admin/import/FormatConverter.php/FormatConverter::import_standard_object()
489
+ */
490
+ public function import($doc_id){
491
+
492
+ $source_doc = $this->client->get_document($doc_id);
493
+
494
+ $content =$this->client->get_document_content($doc_id);
495
+ if ($content == null){
496
+ $content == __('There is no content to display', 'wp-lingotek');
497
+ }
498
+
499
+ $format = $source_doc->properties->extension;
500
+ $formatConverter = new FormatConverter($source_doc, $content, $format);
501
+ $importObject = $formatConverter->convert_to_standard();
502
+ $response = $this->import_standard_object($importObject);
503
+ return $response;
504
+ }
505
+
506
+ /**
507
+ *Prints the Column Checkbox
508
+ *@author Unknown
509
+ *@return string the HTML necessary to show the Checkbox
510
+ */
511
+ function column_cb($item) {
512
+ return sprintf('<input type="checkbox" name="post[]" value="%s" />', $item['id']);
513
+ }
514
+
515
+ /**
516
+ *This gets the import status
517
+ *@author Unknown
518
+ *@return string $this->import_status
519
+ */
520
+ function get_import_status(){
521
+ return $this->import_status;
522
+ }
523
+ }
admin/import/view-content.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *This file actually prepares the content to be viewed and calls the other files
4
+ *as needed so that everything appears as expected.
5
+ *@author Unknown
6
+ */
7
+
8
+
9
+ include_once 'import-table.php';
10
+
11
+ $profile = Lingotek_Model::get_profile('string', $this->pllm->get_language($this->pllm->options['default_lang']));
12
+
13
+ /**
14
+ *Tests to see if the profile is disabled or not.
15
+ *@author Unknown
16
+ */
17
+ if ('disabled' == $profile['profile']) {
18
+ printf('<div class="error" style="border-left: 4px solid #ffba00;"><p>%s</p></div>',
19
+ sprintf(__('The strings translation is disabled in %sContent Type Configuration%s.', 'wp-lingotek'),
20
+ '<a href="' . admin_url('admin.php?page=wp-lingotek_settings&sm=content') . '">',
21
+ '</a>'
22
+ )
23
+ );
24
+ }
25
+ else {
26
+ $table = new Lingotek_Import_Table();
27
+
28
+ $table->prepare_items();
29
+ //Gets the import type (post or page)
30
+ $post_type = get_option('lingotek_import_prefs')['import_type'];
31
+ $plural_or_singular = '';
32
+
33
+ /**
34
+ *This tests to see if the import was successful. If it was it runs the subsequent
35
+ *code.
36
+ *@author Unknown
37
+ */
38
+ if ($table->get_import_status() == 'success'){
39
+ $importedCount = 0;
40
+
41
+ /**
42
+ *Gets the import count based on if it is POST (Bulk import) or GET (indiviudal import)
43
+ *@author Unknown
44
+ */
45
+ if (isset($_POST['post'])){ // used for bulk import
46
+ $importedCount = count($_POST['post']);
47
+ }
48
+ else if (isset($_GET['post'])){ // used for single import
49
+ $importedCount = count($_GET['post']);
50
+ }
51
+
52
+ /**
53
+ *This is to show the correct syntax in the message saying the import was Successful
54
+ *or not. It was always showing post even if it was imported as a page. Now it
55
+ *will show page if imported as page and post if imported as a post.
56
+ *
57
+ *@author TJ Murphy
58
+ *@uses Lingotek_Import_Table::$import_success_count
59
+ *
60
+ */
61
+ if ($post_type == 'page'){
62
+ $plural_or_singular = sprintf( _n( 'Successfully imported %1$s of %2$s page', 'Successfully imported %1$s of %2$s pages', $table->import_success_count, 'wp-lingotek' ), $table->import_success_count, $importedCount );
63
+ }
64
+ else {
65
+ $plural_or_singular = sprintf( _n( 'Successfully imported %1$s of %2$s post', 'Successfully imported %1$s of %2$s posts', $table->import_success_count, 'wp-lingotek' ), $table->import_success_count, $importedCount );
66
+ }
67
+
68
+ add_settings_error($this->plugin_slug . '_import', '', $plural_or_singular, 'updated');
69
+
70
+ /**
71
+ *If not all the imports were successful this if statement adds a settings error
72
+ *that lists the ids of the documents that did not import
73
+ *
74
+ *@author TJ Murphy
75
+ *@uses Lingotek_Import_Table::$import_success_count
76
+ *@uses Lingotek_Import_Table::$import_failure_count
77
+ *@uses Lingotek_Import_Table::to_string_unsuccessful_imports()
78
+ *
79
+ */
80
+ if ($table->import_success_count != $importedCount){
81
+ $document_plurality = sprintf(_n( 'The following document did not import: %s', 'The following documents did not import: %s', $table->import_failure_count, 'wp-lingotek' ), $table->to_string_unsuccessful_imports());
82
+ add_settings_error($this->plugin_slug . '_import', '',$document_plurality, 'error');
83
+ }
84
+ }
85
+
86
+ else if ($table->get_import_status() == 'failure'){
87
+ /**
88
+ *This determines if any files were attempted to be imported. If Zero were even
89
+ *attempted then it shows a message relating that. If >0 were attempted and 0
90
+ *passed then it displays an error message saying all imports failed.
91
+ *
92
+ *@author TJ Murphy
93
+ *@uses Lingotek_Import_Table::import_success_count
94
+ *@uses Lingotek_Import_Table::import_failure_count
95
+ *
96
+ */
97
+ if ($table->import_success_count == $importedCount && $table->import_failure_count == $importedCount && $importedCount == 0){
98
+ add_settings_error(
99
+ $this->plugin_slug . '_import',
100
+ '',
101
+ __('No files were selected to import. Please check the desired documents to import.','wp-lingotek'),
102
+ 'error'
103
+ );
104
+ }
105
+ else {
106
+ $file_plurality = sprintf( _n( 'There was an error importing your file. We currently only support Wordpress, Drupal, HTML, and Text files.',
107
+ 'There was an error importing your files. We currently only support Wordpress, Drupal, HTML, and Text files.',
108
+ $table->import_failure_count,
109
+ 'wp-lingotek' ),
110
+ $table->import_failure_count );
111
+ add_settings_error(
112
+ $this->plugin_slug . '_import',
113
+ '',
114
+ $file_plurality,
115
+ 'error'
116
+ );
117
+ }
118
+
119
+ }
120
+ settings_errors();
121
+
122
+ $order = (!empty($_GET['order']) ) ? $_GET['order'] : 'asc';
123
+ $orderby = (!empty($_GET['orderby']) ) ? '&orderby='.$_GET['orderby'].'&order='.$order : '';
124
+
125
+ ?>
126
+
127
+ <?php
128
+ /**
129
+ *This creates the starting form tag for the import page and sets the page and
130
+ *action parameters.
131
+ *@author Unknown
132
+ */
133
+ echo sprintf('<form id="lingotek-import" method="post" action="admin.php?page=lingotek-translation_import&action=bulk_import'.(string)$orderby.'"');
134
+ /**
135
+ *@see wp-admin/includes/class-wp-list-table.php/WP_List_Table::display()
136
+ */
137
+ $table->display(); ?>
138
+ </form><?php
139
+ }
admin/import/view-settings.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ *Sets all of the setting details so they can appropriately be presented.
6
+ *@author Unknown
7
+ *@var array
8
+ */
9
+ $setting_details = array(
10
+ 'import_post_status' => array(
11
+ 'type' => 'dropdown',
12
+ 'label' => __('Import documents as', 'wp-lingotek'),
13
+ 'description' => __('The post status for newly imported documents', 'wp-lingotek'),
14
+ 'values' => array(
15
+ 'draft' => __('Draft', 'wp-lingotek'),
16
+ 'pending' => __('Pending Review', 'wp-lingotek'),
17
+ 'publish' => __('Published', 'wp-lingotek'),
18
+ 'private' => __('Privately Published', 'wp-lingotek'),
19
+ )),
20
+ 'import_type' => array(
21
+ 'type' => 'dropdown',
22
+ 'label' => __('Format', 'wp-lingotek'),
23
+ 'description' => __('In which format would you like your imports to be?', 'wp-lingotek'),
24
+ 'values' => array(
25
+ 'page' => __('Page', 'wp-lingotek'),
26
+ 'post' => __('Post', 'wp-lingotek'),
27
+ )),
28
+ );
29
+
30
+
31
+ $page_key = $this->plugin_slug . '_import&sm=settings';
32
+
33
+ /**
34
+ *Sets the options
35
+ *@author Unknown
36
+ */
37
+ if (!empty($_POST)) {
38
+ $options = array();
39
+ foreach ($setting_details as $key => $setting) {
40
+ if (isset($_POST[$key])) {
41
+ $options[$key] = $_POST[$key];
42
+ }
43
+ else {
44
+ $options[$key] = null;
45
+ }
46
+ }
47
+
48
+
49
+ update_option('lingotek_import_prefs', $options);
50
+
51
+ add_settings_error('lingotek_prefs', 'prefs', __('Your preferences were successfully updated.', 'wp-lingotek'), 'updated');
52
+ settings_errors();
53
+ }
54
+ $selected_options = get_option('lingotek_import_prefs');
55
+ ?>
56
+
57
+ <h3><?php _e('Settings', 'wp-lingotek'); ?></h3>
58
+
59
+ <form id="lingotek-settings" method="post" action="admin.php?page=<?php echo $page_key; ?>" class="validate">
60
+ <?php wp_nonce_field($page_key, '_wpnonce_' . $page_key); ?>
61
+
62
+ <table class="form-table"><?php foreach ($setting_details as $key => $setting) { ?>
63
+
64
+ <tr>
65
+ <th scope="row"><label for="<?php echo $key; ?>"><?php echo $setting['label'] ?></label></th>
66
+ <td>
67
+ <?php if ($setting['type'] == 'dropdown') { ?>
68
+ <select name="<?php echo $key ?>" id="<?php echo $key ?>">
69
+ <?php
70
+ foreach ($setting['values'] as $id => $title) {
71
+ echo "\n\t" . '<option value="' . esc_attr($id) . '" ' . selected($selected_options[$key], $id) . '>' . $title . '</option>';
72
+ }
73
+ ?>
74
+ </select>
75
+ <?php } else if ($setting['type'] == 'checkboxes') {
76
+ echo '<ul class="pref-statuses">';
77
+ foreach ($setting['values'] as $id => $title) {
78
+ $cb_name = $key.'['.esc_attr($id) . ']';
79
+ $checked = checked('1', (isset($selected_options[$key][$id]) && $selected_options[$key][$id]), false);
80
+ echo '<li><input type="checkbox" id="'.$cb_name.'" name="'.$cb_name.'" value="1" ' . $checked. '><label for="'.$cb_name.'">' . $title . '</label></li>';
81
+ }
82
+ echo '</ul>';
83
+ } ?>
84
+ <p class="description">
85
+ <?php echo $setting['description']; ?>
86
+ </p>
87
+ </tr><?php } ?>
88
+ </table>
89
+
90
+ <?php submit_button(__('Save Changes', 'wp-lingotek'), 'primary', 'submit', false); ?>
91
+ </form>
admin/manage/view-content.php CHANGED
File without changes
admin/manage/view-custom-fields.php CHANGED
File without changes
admin/manage/view-edit-profile.php CHANGED
File without changes
admin/manage/view-profiles.php CHANGED
File without changes
admin/manage/view-string-groups.php CHANGED
File without changes
admin/manage/view-strings.php CHANGED
File without changes
admin/post-actions.php CHANGED
File without changes
admin/profiles-table.php CHANGED
File without changes
admin/settings.php CHANGED
File without changes
admin/settings/connect-account.php CHANGED
File without changes
admin/settings/view-account.php CHANGED
File without changes
admin/settings/view-defaults.php CHANGED
File without changes
admin/settings/view-preferences.php CHANGED
@@ -33,6 +33,13 @@ $setting_details = array(
33
  'delete' => __('Delete documents from Lingotek TMS when disassociating.', 'lingotek-translation'),
34
  )
35
  ),
 
 
 
 
 
 
 
36
  );
37
 
38
  $page_key = $this->plugin_slug . '_settings&sm=preferences';
@@ -53,6 +60,16 @@ if (!empty($_POST)) {
53
  add_settings_error('lingotek_prefs', 'prefs', __('Your preferences were successfully updated.', 'lingotek-translation'), 'updated');
54
  settings_errors();
55
  }
 
 
 
 
 
 
 
 
 
 
56
 
57
  $selected_options = Lingotek_Model::get_prefs();
58
 
33
  'delete' => __('Delete documents from Lingotek TMS when disassociating.', 'lingotek-translation'),
34
  )
35
  ),
36
+ 'import_enabled' => array(
37
+ 'type' => 'checkboxes',
38
+ 'label' => __('Import', 'wp-lingotek'),
39
+ 'description' => __('When checked, an "Import" submenu will appear.', 'wp-lingotek'),
40
+ 'values' => array(
41
+ 'enabled' => __('Enable importing from Lingotek Content Cloud. (beta)', 'wp-lingotek')
42
+ )),
43
  );
44
 
45
  $page_key = $this->plugin_slug . '_settings&sm=preferences';
60
  add_settings_error('lingotek_prefs', 'prefs', __('Your preferences were successfully updated.', 'lingotek-translation'), 'updated');
61
  settings_errors();
62
  }
63
+ // else {
64
+ // $selected_options = Lingotek_Model::get_prefs();
65
+ //
66
+ // $options = array();
67
+ // if (!isset($selected_options['import_enabled'])){
68
+ // $options['import_enabled'] = 'enabled';
69
+ // }
70
+ //
71
+ // update_option('lingotek_prefs', $options);
72
+ // }
73
 
74
  $selected_options = Lingotek_Model::get_prefs();
75
 
admin/settings/view-utilities.php CHANGED
File without changes
admin/string-actions.php CHANGED
File without changes
admin/strings-table.php CHANGED
File without changes
admin/table-string.php CHANGED
@@ -23,9 +23,52 @@ class Lingotek_Table_String extends PLL_Table_String {
23
  $out .= sprintf('<div class="translation"><label for="%1$s-%2$s">%3$s</label>'.$input_type.'</div>'."\n",
24
  esc_attr($key),
25
  esc_attr($item['row']),
26
- esc_html($this->languages[$key]),
27
  format_to_edit($translation)); // don't interpret special chars
28
  }
29
  return $out;
30
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
23
  $out .= sprintf('<div class="translation"><label for="%1$s-%2$s">%3$s</label>'.$input_type.'</div>'."\n",
24
  esc_attr($key),
25
  esc_attr($item['row']),
26
+ esc_html($this->languages['languages'][$key]),
27
  format_to_edit($translation)); // don't interpret special chars
28
  }
29
  return $out;
30
  }
31
+
32
+ function prepare_items($data = null) {
33
+ $listlanguages = $GLOBALS['polylang']->model->get_languages_list();
34
+ // $data = $this->strings;
35
+
36
+ // Filter for search string
37
+ $s = empty( $_GET['s'] ) ? '' : wp_unslash( $_GET['s'] );
38
+ foreach ( $data as $key => $row ) {
39
+ if ( ( -1 !== $this->selected_group && $row['context'] !== $this->selected_group ) || ( ! empty( $s ) && stripos( $row['name'], $s ) === false && stripos( $row['string'], $s ) === false ) ) {
40
+ unset( $data[ $key ] );
41
+ }
42
+ }
43
+
44
+ // Load translations
45
+ foreach ($listlanguages as $language) {
46
+ // filters by language if requested
47
+ if (($lg = get_user_meta(get_current_user_id(), 'pll_filter_content', true)) && $language->slug != $lg)
48
+ continue;
49
+
50
+ $mo = new PLL_MO();
51
+ $mo->import_from_db($language);
52
+ foreach ($data as $key=>$row) {
53
+ $data[$key]['translations'][$language->slug] = $mo->translate($row['string']);
54
+ $data[$key]['row'] = $key; // store the row number for convenience
55
+ }
56
+ }
57
+
58
+ $per_page = $this->get_items_per_page( 'pll_strings_per_page' );
59
+ $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() );
60
+
61
+ if ( ! empty( $_GET['orderby'] ) ) { // No sort by default
62
+ usort( $data, array( $this, 'usort_reorder' ) );
63
+ }
64
+
65
+ $total_items = count( $data );
66
+ $this->items = array_slice( $data, ( $this->get_pagenum() - 1 ) * $per_page, $per_page );
67
+
68
+ $this->set_pagination_args( array(
69
+ 'total_items' => $total_items,
70
+ 'per_page' => $per_page,
71
+ 'total_pages' => ceil( $total_items / $per_page ),
72
+ ) );
73
+ }
74
  }
admin/term-actions.php CHANGED
File without changes
admin/tutorial/content.php CHANGED
File without changes
admin/tutorial/credits.php CHANGED
File without changes
admin/tutorial/faq.php CHANGED
File without changes
admin/tutorial/features.php CHANGED
File without changes
admin/tutorial/img/add-languages.png CHANGED
File without changes
admin/tutorial/img/add-page.png CHANGED
File without changes
admin/tutorial/img/add-page2.png CHANGED
File without changes
admin/tutorial/img/automatic-translation.gif CHANGED
File without changes
admin/tutorial/img/automatic-translation.png CHANGED
File without changes
admin/tutorial/img/check-status.png CHANGED
File without changes
admin/tutorial/img/content-types.png CHANGED
File without changes
admin/tutorial/img/dashboard.png CHANGED
File without changes
admin/tutorial/img/polylang-compatible.png CHANGED
File without changes
admin/tutorial/img/pro-translation.png CHANGED
File without changes
admin/tutorial/img/professional-translation.png CHANGED
File without changes
admin/tutorial/img/ready-to-upload.png CHANGED
File without changes
admin/tutorial/img/request-translations.png CHANGED
File without changes
admin/tutorial/img/translation-profiles.png CHANGED
File without changes
admin/tutorial/img/translation-services.png CHANGED
File without changes
admin/tutorial/img/translations-downloaded.png CHANGED
File without changes
admin/tutorial/img/translations-ready-for-download.png CHANGED
File without changes
admin/tutorial/img/translations-underway.png CHANGED
File without changes
admin/tutorial/img/workbench-full.png CHANGED
File without changes
admin/tutorial/img/workbench.png CHANGED
File without changes
admin/utilities.php CHANGED
File without changes
admin/view-dashboard.php CHANGED
File without changes
admin/view-manage.php CHANGED
File without changes
admin/view-network.php CHANGED
File without changes
admin/view-tutorial.php CHANGED
File without changes
admin/wp-import.php CHANGED
@@ -1,13 +1,13 @@
1
  <?php
2
 
3
- /*
4
  * Fires before WordPress Importer to remove Lingotek metadata so Lingotek can track posts correctly
5
  *
6
  * @since 1.0.6
7
  */
8
  class Lingotek_WP_Import extends PLL_WP_Import {
9
 
10
- /*
11
  * Removes post_translations metadata if no translations exist so it doesn't get put in the database by WP_Import
12
  *
13
  * @since 1.0.6
@@ -28,4 +28,4 @@ class Lingotek_WP_Import extends PLL_WP_Import {
28
  }
29
  }
30
 
31
- ?>
1
  <?php
2
 
3
+ /**
4
  * Fires before WordPress Importer to remove Lingotek metadata so Lingotek can track posts correctly
5
  *
6
  * @since 1.0.6
7
  */
8
  class Lingotek_WP_Import extends PLL_WP_Import {
9
 
10
+ /**
11
  * Removes post_translations metadata if no translations exist so it doesn't get put in the database by WP_Import
12
  *
13
  * @since 1.0.6
28
  }
29
  }
30
 
31
+ ?>
css/admin.css CHANGED
@@ -20,7 +20,6 @@
20
  font-weight: 700;
21
  }
22
  .ui-dialog button {
23
- position:absolute;
24
  right: 0;
25
  top: 0;
26
  float: right;
@@ -94,4 +93,4 @@ a.dashicons {
94
 
95
  #utility_delete_documents {
96
  margin-left: 20px;
97
- }
20
  font-weight: 700;
21
  }
22
  .ui-dialog button {
 
23
  right: 0;
24
  top: 0;
25
  float: right;
93
 
94
  #utility_delete_documents {
95
  margin-left: 20px;
96
+ }
img/lingotek-chevrons-blue.png CHANGED
File without changes
img/lingotek-icon.png CHANGED
File without changes
img/lingotek-white.png CHANGED
File without changes
include/api.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  require_once('http.php');
4
 
5
- /*
6
  * manages communication with Lingotek TMS
7
  * uses Lingotek API V5
8
  *
@@ -17,7 +17,7 @@ class Lingotek_API extends Lingotek_HTTP {
17
  const SANDBOX_URL = "https://cms.lingotek.com";
18
  const CLIENT_ID = "780966c9-f9c8-4691-96e2-c0aaf47f62ff";// Lingotek App ID
19
 
20
- /*
21
  * constructor
22
  *
23
  * @since 0.1
@@ -52,7 +52,7 @@ class Lingotek_API extends Lingotek_HTTP {
52
  return $this->api_url;
53
  }
54
 
55
- /*
56
  * updates the projet callback
57
  *
58
  * @since 0.2
@@ -65,7 +65,7 @@ class Lingotek_API extends Lingotek_HTTP {
65
  return !is_wp_error($response) && 204 == wp_remote_retrieve_response_code($response);
66
  }
67
 
68
- /*
69
  * creates a new project
70
  *
71
  * @since 0.2
@@ -90,7 +90,7 @@ class Lingotek_API extends Lingotek_HTTP {
90
  }
91
  }
92
 
93
- /*
94
  * uploads a document
95
  *
96
  * @since 0.1
@@ -129,7 +129,7 @@ class Lingotek_API extends Lingotek_HTTP {
129
  return false;
130
  }
131
 
132
- /*
133
  * modifies a document
134
  *
135
  * @since 0.1
@@ -165,7 +165,7 @@ class Lingotek_API extends Lingotek_HTTP {
165
  return !is_wp_error($response) && 202 == wp_remote_retrieve_response_code($response);
166
  }
167
 
168
- /*
169
  * deletes a document
170
  *
171
  * @since 0.1
@@ -186,12 +186,13 @@ class Lingotek_API extends Lingotek_HTTP {
186
  return !is_wp_error($response) && (204 == wp_remote_retrieve_response_code($response) || 202 == wp_remote_retrieve_response_code($response));
187
  }
188
 
189
- /*
190
- * get documents ids
 
191
  *
192
  * @since 0.1
193
  */
194
- public function get_documents($args = array()) {
195
  $response = $this->get(add_query_arg($args, $this->api_url . '/document'));
196
  $ids = array();
197
 
@@ -205,40 +206,71 @@ class Lingotek_API extends Lingotek_HTTP {
205
  return $ids;
206
  }
207
 
208
- /*
209
- * check if a document is existing
 
 
 
 
 
 
 
 
 
 
 
 
210
  *
211
  * @since 0.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  *
213
- * @param string $id document id
214
- * @return bool
215
  */
216
- public function document_exists($doc_id, $wp_id = null) {
217
  $response = $this->get($this->api_url . '/document/' . $doc_id);
218
 
219
- if ($wp_id) {
220
- $arr = get_option('lingotek_log_errors');
221
-
222
- if (200 == wp_remote_retrieve_response_code($response)) {
223
- if (isset($arr[$wp_id])) {
224
- unset($arr[$wp_id] );
225
- }
226
- }
227
- else if (is_wp_error($response)) {
228
- $arr[$wp_id]['wp_error'] = __('Make sure you have internet connectivity', 'lingotek-translation');
229
- }
230
- else if (400 == wp_remote_retrieve_response_code($response)) {
231
- $arr[$wp_id]['document_exists'] = sprintf(
232
- __('There was an error updating the translations status for WordPress item %1$s', 'lingotek-translation'), $wp_id
233
- );
234
- }
235
- update_option('lingotek_log_errors', $arr);
236
  }
237
 
238
- return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  }
240
 
241
- /*
242
  * check translations status of a document
243
  *
244
  * @since 0.1
@@ -277,7 +309,7 @@ class Lingotek_API extends Lingotek_HTTP {
277
  return empty($translations) ? array() : $translations;
278
  }
279
 
280
- /*
281
  * requests a new translation of a document
282
  *
283
  * @since 0.1
@@ -319,7 +351,7 @@ class Lingotek_API extends Lingotek_HTTP {
319
  return !is_wp_error($response) && 201 == wp_remote_retrieve_response_code($response);
320
  }
321
 
322
- /*
323
  * get a translation
324
  *
325
  * @since 0.1
@@ -358,7 +390,7 @@ class Lingotek_API extends Lingotek_HTTP {
358
  return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response) ? wp_remote_retrieve_body($response) : false;
359
  }
360
 
361
- /*
362
  * deletes a translation
363
  *
364
  * @since 0.1
@@ -379,7 +411,7 @@ class Lingotek_API extends Lingotek_HTTP {
379
  // FIXME send a response
380
  }
381
 
382
- /*
383
  * get connect account url
384
  *
385
  * @param string $redirect_uri the location where to redirect to after account has been connected
2
 
3
  require_once('http.php');
4
 
5
+ /**
6
  * manages communication with Lingotek TMS
7
  * uses Lingotek API V5
8
  *
17
  const SANDBOX_URL = "https://cms.lingotek.com";
18
  const CLIENT_ID = "780966c9-f9c8-4691-96e2-c0aaf47f62ff";// Lingotek App ID
19
 
20
+ /**
21
  * constructor
22
  *
23
  * @since 0.1
52
  return $this->api_url;
53
  }
54
 
55
+ /**
56
  * updates the projet callback
57
  *
58
  * @since 0.2
65
  return !is_wp_error($response) && 204 == wp_remote_retrieve_response_code($response);
66
  }
67
 
68
+ /**
69
  * creates a new project
70
  *
71
  * @since 0.2
90
  }
91
  }
92
 
93
+ /**
94
  * uploads a document
95
  *
96
  * @since 0.1
129
  return false;
130
  }
131
 
132
+ /**
133
  * modifies a document
134
  *
135
  * @since 0.1
165
  return !is_wp_error($response) && 202 == wp_remote_retrieve_response_code($response);
166
  }
167
 
168
+ /**
169
  * deletes a document
170
  *
171
  * @since 0.1
186
  return !is_wp_error($response) && (204 == wp_remote_retrieve_response_code($response) || 202 == wp_remote_retrieve_response_code($response));
187
  }
188
 
189
+
190
+ /**
191
+ * get all documents ids
192
  *
193
  * @since 0.1
194
  */
195
+ public function get_document_ids($args = array()) {
196
  $response = $this->get(add_query_arg($args, $this->api_url . '/document'));
197
  $ids = array();
198
 
206
  return $ids;
207
  }
208
 
209
+ public function get_document_count($args = array()) {
210
+ $response = $this->get(add_query_arg($args, $this->api_url . '/document'));
211
+ $docs = array();
212
+
213
+ if (!is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response)) {
214
+ $response = json_decode(wp_remote_retrieve_body($response));
215
+ return $response->properties->total;
216
+ }
217
+
218
+ return null;
219
+ }
220
+
221
+ /**
222
+ * get all documents
223
  *
224
  * @since 0.1
225
+ */
226
+ public function get_documents($args = array()) {
227
+ $response = $this->get(add_query_arg($args, $this->api_url . '/document'));
228
+ $docs = array();
229
+
230
+ if (!is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response)) {
231
+ $documents = json_decode(wp_remote_retrieve_body($response));
232
+ foreach ($documents->entities as $doc) {
233
+ $docs[] = $doc;
234
+ }
235
+ }
236
+
237
+ return $docs;
238
+ }
239
+
240
+ /**
241
+ * get document by id
242
  *
243
+ * @since 0.1
 
244
  */
245
+ public function get_document($doc_id) {
246
  $response = $this->get($this->api_url . '/document/' . $doc_id);
247
 
248
+ if (!is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response)) {
249
+ $document = json_decode(wp_remote_retrieve_body($response));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  }
251
 
252
+ return $document;
253
+ }
254
+
255
+
256
+ /**
257
+ * get specific document content
258
+ *
259
+ * @since 0.1
260
+ *
261
+ * @param string $id document id
262
+ * @return string
263
+ */
264
+ public function get_document_content($doc_id) {
265
+ $response = $this->get($this->api_url . '/document/' . $doc_id . '/content');
266
+
267
+ if (!is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response)) {
268
+ $content = wp_remote_retrieve_body( $response );
269
+ }
270
+ return $content;
271
  }
272
 
273
+ /**
274
  * check translations status of a document
275
  *
276
  * @since 0.1
309
  return empty($translations) ? array() : $translations;
310
  }
311
 
312
+ /**
313
  * requests a new translation of a document
314
  *
315
  * @since 0.1
351
  return !is_wp_error($response) && 201 == wp_remote_retrieve_response_code($response);
352
  }
353
 
354
+ /**
355
  * get a translation
356
  *
357
  * @since 0.1
390
  return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response) ? wp_remote_retrieve_body($response) : false;
391
  }
392
 
393
+ /**
394
  * deletes a translation
395
  *
396
  * @since 0.1
411
  // FIXME send a response
412
  }
413
 
414
+ /**
415
  * get connect account url
416
  *
417
  * @param string $redirect_uri the location where to redirect to after account has been connected
include/callback.php CHANGED
File without changes
include/dashboard.php CHANGED
@@ -91,8 +91,10 @@ class Lingotek_Dashboard {
91
  $strings = $lingotek_model->get_strings();
92
  foreach ($strings as $string) {
93
  $group = $lingotek_model->get_group('string', $string['context']);
94
- unset($group->translations[$lang->locale]);
95
- $group->save();
 
 
96
  }
97
 
98
  $response = array (
@@ -306,8 +308,17 @@ class Lingotek_Dashboard {
306
  static public function has_language_content($language) {
307
  // posts
308
  $objects = get_objects_in_term($language->term_id, 'language');
309
- if (!empty($objects))
310
- return true;
 
 
 
 
 
 
 
 
 
311
 
312
  // terms, only the default category is accepted
313
  $objects = get_objects_in_term($language->tl_term_id, 'term_language');
91
  $strings = $lingotek_model->get_strings();
92
  foreach ($strings as $string) {
93
  $group = $lingotek_model->get_group('string', $string['context']);
94
+ if ($group) {
95
+ unset($group->translations[$lang->locale]);
96
+ $group->save();
97
+ }
98
  }
99
 
100
  $response = array (
308
  static public function has_language_content($language) {
309
  // posts
310
  $objects = get_objects_in_term($language->term_id, 'language');
311
+ if (!empty($objects)) {
312
+ foreach ($objects as $key => $object) {
313
+ $post = get_post($object);
314
+ if ($post->post_status == 'auto-draft') {
315
+ unset($objects[$key]);
316
+ }
317
+ }
318
+ if (!empty($objects)) {
319
+ return true;
320
+ }
321
+ }
322
 
323
  // terms, only the default category is accepted
324
  $objects = get_objects_in_term($language->tl_term_id, 'term_language');
include/group-post.php CHANGED
File without changes
include/group-string.php CHANGED
File without changes
include/group-term.php CHANGED
File without changes
include/group.php CHANGED
@@ -152,7 +152,7 @@ abstract class Lingotek_Group {
152
  public function source_status() {
153
  $client = new Lingotek_API();
154
 
155
- if ('importing' == $this->status && $client->document_exists($this->document_id, $this->source)){
156
  $this->status = 'current';
157
  $this->save();
158
  }
152
  public function source_status() {
153
  $client = new Lingotek_API();
154
 
155
+ if ('importing' == $this->status /*&& $client->document_exists($this->document_id, $this->source)*/){
156
  $this->status = 'current';
157
  $this->save();
158
  }
include/http.php CHANGED
File without changes
include/model.php CHANGED
File without changes
include/plugins-compat.php CHANGED
File without changes
include/pointer.php CHANGED
File without changes
js/defaults.js CHANGED
File without changes
js/progress.js CHANGED
File without changes
js/updater.js CHANGED
File without changes
languages/wp-lingotek-fr_FR.mo CHANGED
File without changes
languages/wp-lingotek-fr_FR.po CHANGED
File without changes
lingotek.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin name: Lingotek Translation
4
  Plugin URI: http://lingotek.com/wordpress#utm_source=wpadmin&utm_medium=plugin&utm_campaign=wplingotektranslationplugin
5
- Version: 1.2.2
6
  Author: Lingotek and Frédéric Demarle
7
  Author uri: http://lingotek.com
8
  Description: Lingotek offers convenient cloud-based localization and translation.
@@ -15,7 +15,7 @@ GitHub Plugin URI: https://github.com/lingotek/lingotek-translation
15
  if (!function_exists('add_action'))
16
  exit();
17
 
18
- define('LINGOTEK_VERSION', '1.2.2'); // plugin version (should match above meta)
19
  define('LINGOTEK_MIN_PLL_VERSION', '1.8');
20
  define('LINGOTEK_BASENAME', plugin_basename(__FILE__)); // plugin name as known by WP
21
  define('LINGOTEK_PLUGIN_SLUG', 'lingotek-translation');// plugin slug (should match above meta: Text Domain)
2
  /*
3
  Plugin name: Lingotek Translation
4
  Plugin URI: http://lingotek.com/wordpress#utm_source=wpadmin&utm_medium=plugin&utm_campaign=wplingotektranslationplugin
5
+ Version: 1.2.3
6
  Author: Lingotek and Frédéric Demarle
7
  Author uri: http://lingotek.com
8
  Description: Lingotek offers convenient cloud-based localization and translation.
15
  if (!function_exists('add_action'))
16
  exit();
17
 
18
+ define('LINGOTEK_VERSION', '1.2.3'); // plugin version (should match above meta)
19
  define('LINGOTEK_MIN_PLL_VERSION', '1.8');
20
  define('LINGOTEK_BASENAME', plugin_basename(__FILE__)); // plugin name as known by WP
21
  define('LINGOTEK_PLUGIN_SLUG', 'lingotek-translation');// plugin slug (should match above meta: Text Domain)
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: chouby, smithworx, erichie
3
  Donate link: http://lingotek.com/
4
  Tags: automation, bilingual, international, language, Lingotek, localization, multilanguage, multilingual, translate, translation
5
  Requires at least: 3.8
6
- Tested up to: 4.5
7
- Stable tag: 1.2.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -122,6 +122,12 @@ For more, visit the [Lingotek documentation site](https://lingotek.atlassian.net
122
 
123
  == Changelog ==
124
 
 
 
 
 
 
 
125
  = 1.2.2 (2016-7-8) =
126
 
127
  * Fixed a bug that prevented translation of content into Japanese
3
  Donate link: http://lingotek.com/
4
  Tags: automation, bilingual, international, language, Lingotek, localization, multilanguage, multilingual, translate, translation
5
  Requires at least: 3.8
6
+ Tested up to: 4.6
7
+ Stable tag: 1.2.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
122
 
123
  == Changelog ==
124
 
125
+ = 1.2.3 (2016-8-24) =
126
+
127
+ * Fixed a bug that prevented the removal of target languages from the Dashboard
128
+ * Updated code for compatibility with Polylang version 2.0
129
+ * Fixed CSS conflict with other plugins
130
+
131
  = 1.2.2 (2016-7-8) =
132
 
133
  * Fixed a bug that prevented translation of content into Japanese
uninstall.php CHANGED
File without changes