-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextbrokerPlugin.php
876 lines (754 loc) · 27.3 KB
/
TextbrokerPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
<?php
/**
This file is part of the Textbroker WordPress-Plugin.
The Textbroker WordPress-Plugin is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
The Textbroker WordPress Plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Textbroker WordPress Plugin. If not, see http://www.gnu.org/licenses/.
*/
require_once('PluginStandards.php');
require_once('PluginStandardsInterface.php');
require_once(dirname(__FILE__) . '/textbroker-PHP5-Client/Textbroker.php');
require_once(dirname(__FILE__) . '/textbroker-PHP5-Client/TextbrokerBudgetCheck.php');
require_once(dirname(__FILE__) . '/textbroker-PHP5-Client/TextbrokerBudgetOrder.php');
require_once(dirname(__FILE__) . '/textbroker-PHP5-Client/TextbrokerBudgetOrderChange.php');
require_once(dirname(__FILE__) . '/textbroker-PHP5-Client/TextbrokerBudgetProofreading.php');
/**
*
* @package Textbroker WordPress-Plugin
* @author Fabio Bacigalupo <info1@open-haus.de>
* @copyright Fabio Bacigalupo 2012
* @version $Revision: 2.6 $
* @since PHP5.2.12
*/
class TextbrokerPlugin extends PluginStandards implements PluginStandardsInterface {
/**
* Prefix to differentiate capabilities
*
*/
const PREFIX_CAPABILITY = 'manage_textbrokerplugin_';
/**
* Internally used name
*
*/
const IDENTIFIER = 'textbroker';
/**
* Option name
*
*/
const IDENTIFIER_BUDGETS = 'textbroker-budgets';
/**
* Option name
*
*/
const IDENTIFIER_ORDERS = 'textbroker-orders';
/**
* Option name
*
*/
const IDENTIFIER_PROOFREADING = 'textbroker-proofreading';
/**
* Name of plugin
*
*/
const PLUGIN_NAME = 'Textbroker-WordPress-Plugin';
const PARAM_BUDGET = 'budget';
const PARAM_BUDGET_ID = 'budget_id';
const PARAM_BUDGET_NAME = 'budget_name';
const PARAM_BUDGET_ORDER_ID = 'budget_order_id';
const PARAM_ORDER = 'order';
const PARAM_ORDER_ID = 'order_id';
const PARAM_ORDER_COMMENT = 'order_comment';
const PARAM_ORDER_RATING = 'order_review';
const PARAM_ORDER_TITLE = 'order_title';
const PARAM_PUBLISH_TYPE = 'type';
const PARAM_COMMENT = 'comment';
const PARAM_TEAM_ID = 'team_id';
const PARAM_TEAM_NAME = 'team_name';
const PARAM_FORCE = 'force';
const PARAM_PROOFREADING_ID = 'proofreading_id_created';
const PARAM_PROOFREADING_DATE = 'proofreading_created';
const PARAM_PROOFREADING_TITLE = 'proofreading_title';
const PUBLISH_TYPE_PAGE = 'page';
const PUBLISH_TYPE_POST = 'post';
const USE_PROOFREAD = 'use_proofread';
const ACTION_BUDGET_INFO_ADD = '1001';
const ACTION_BUDGET_INFO_INSERT = '1002';
const ACTION_BUDGET_INFO_EDIT = '1003';
const ACTION_BUDGET_INFO_UPDATE = '1004';
const ACTION_BUDGET_INFO_LIST = '1005';
const ACTION_BUDGET_INFO_DELETE = '1006';
const ACTION_ORDER_ADD = '2001';
const ACTION_ORDER_INSERT = '2002';
const ACTION_ORDER_GETSTATUS = '2003';
const ACTION_ORDER_DELETE = '2004';
const ACTION_ORDER_ACCEPT = '2005';
const ACTION_ORDER_PREVIEW = '2006';
const ACTION_ORDER_REVISE = '2007';
const ACTION_ORDER_PUBLISH = '2008';
const ACTION_ORDER_REMOVE = '2009';
const ACTION_ORDER_REJECT = '2010';
const ACTION_ORDER_EDIT = '2011';
const ACTION_ORDER_UPDATE = '2012';
const ACTION_TEAMORDER_ADD = '3001';
const ACTION_TEAMORDER_INSERT = '3002';
const ACTION_TEAMORDER_UPDATE = '3003';
const ACTION_PROOFREAD_ADD = '4001';
const ACTION_PROOFREAD_INSERT = '4002';
const ACTION_PROOFREAD_GETSTATUS= '4003';
const ACTION_PROOFREAD_DELETE = '4004';
const ACTION_PROOFREAD_ACCEPT = '4005';
const ACTION_PROOFREAD_PREVIEW = '4006';
const ACTION_PROOFREAD_REVISE = '4007';
const ACTION_PROOFREAD_PICKUP = '4008';
const ACTION_PROOFREAD_REJECT = '4009';
/**
* Simple version number
* Raise this if e.g. stylesheet has changed
*
* @var float
* @see loadScripts()
*/
const PLUGIN_VERSION = 2.6;
/**
* List of available services
*
* @var array
*/
protected static $aServices = array(
#'Check',
'Order',
);
/**
* List of locations textbroker offer its services
*
* @var array
*/
private static $aLocations = array(
'us',
'de',
'fr',
'uk',
'nl',
'es',
);
/**
* Singleton
*
* @return obj
*/
public static function &singleton() {
static $instance;
if (!isset($instance)) {
$class = __CLASS__;
$instance = new $class;
}
return $instance;
}
/**
* Constructor
*
*/
function __construct() {
parent::__construct();
}
/**
* Load templates and JavaScript files
*
*/
public function loadScripts() {
$stylesheet = $this->getPluginPath() . '/css/' . self::getIdentifier() . '-admin.css';
wp_enqueue_style(self::getIdentifier() . '-admin', $stylesheet, false, self::getVersion(), 'all');
parent::loadScripts();
}
/**
* This acts as controller
*
*/
public function process() {
$showBudgetInformation = true;
try {
switch ( $_REQUEST['_wpnonce'] ) {
case wp_create_nonce(self::ACTION_BUDGET_INFO_ADD) :
$this->showBudgetInformationEntryForm(array(), false, true);
$showBudgetInformation = false;
break;
case wp_create_nonce(self::ACTION_BUDGET_INFO_INSERT) :
$this->saveBudget($_REQUEST[self::PARAM_BUDGET]);
$this->showMessage(__('Budget information saved successfully', self::getIdentifier()), self::HINT_SUCCESS, true);
break;
case wp_create_nonce(self::ACTION_BUDGET_INFO_EDIT) :
$this->showBudgetInformationEntryForm($this->getBudget($_REQUEST[self::PARAM_BUDGET_ID]), true, true);
$showBudgetInformation = false;
break;
case wp_create_nonce(self::ACTION_BUDGET_INFO_UPDATE) :
$this->saveBudget($_REQUEST[self::PARAM_BUDGET], true);
$this->showMessage(__('Budget information updated successfully', self::getIdentifier()), self::HINT_SUCCESS, true);
break;
case wp_create_nonce(self::ACTION_BUDGET_INFO_DELETE) :
$this->deleteBudget($_REQUEST[self::PARAM_BUDGET_ID]);
$this->showMessage(__('Budget information deleted successfully', self::getIdentifier()), self::HINT_SUCCESS, true);
break;
case wp_create_nonce(self::ACTION_BUDGET_INFO_LIST) :
$this->showBudgetDetails($this->getBudgetDetails($_REQUEST[self::PARAM_BUDGET_ID]), true);
$showBudgetInformation = false;
break;
}
} catch (TextbrokerBudgetInsertException $e) {
$this->showMessage(__($e->getMessage(), self::getIdentifier()), self::HINT_ERROR, true);
$this->showBudgetInformationEntryForm(@$_REQUEST[self::PARAM_BUDGET], false, true);
$showBudgetInformation = false;
} catch (TextbrokerBudgetUpdateException $e) {
$this->showMessage(__($e->getMessage(), self::getIdentifier()), self::HINT_ERROR, true);
$this->showBudgetInformationEntryForm($_REQUEST[self::PARAM_BUDGET], true, true);
$showBudgetInformation = false;
} catch (TextbrokerBudgetException $e) {
$this->showMessage(__($e->getMessage(), self::getIdentifier()), self::HINT_ERROR, true);
} catch (Exception $e) {
$this->showMessage($e->getMessage(), self::HINT_ERROR, true);
}
if ($showBudgetInformation) {
$this->showBudgetInformation($this->getBudgets(), true);
$this->showTeamInformation($this->getBudgets(), true);
$this->showBudgetInformationAddButton(true);
}
}
/**
*
*
* @return array
*/
public function getServices() {
return self::$aServices;
}
/**
*
*
* @return string
*/
public function getIdentifier() {
return self::IDENTIFIER;
}
/**
*
*
* @return string
*/
public function getName() {
return self::PLUGIN_NAME;
}
/**
*
*
* @return float
*/
public function getVersion() {
return self::PLUGIN_VERSION;
}
/**
*
*
* @return string
*/
public function getCapabilityPrefix() {
return self::PREFIX_CAPABILITY;
}
/**
*
*
* @return array
*/
public function getLocations() {
$aLocations = array();
$aLocations = self::$aLocations;
if (file_exists(dirname(__FILE__) . '/TextbrokerLocations.php')) {
require(dirname(__FILE__) . '/TextbrokerLocations.php');
$aLocations = array_merge($aLocations, TextbrokerLocations::getLocations());
}
return $aLocations;
}
/**
*
*
* @param int $budgetId
* @return array
* @throws TextbrokerBudgetException
*/
public function getBudget($budgetId) {
$aBudgets = $this->getOption(self::IDENTIFIER_BUDGETS);
if(!isset($aBudgets[$budgetId])) {
throw new TextbrokerBudgetException('ERROR: Failed getting budget');
}
return $aBudgets[$budgetId];
}
/******************************************************************************************************************************************************************************
* Private processing stuff
******************************************************************************************************************************************************************************/
/**
* Save the information as an option
*
* @param array $aBudget
* @param bool $isUpdate
* @throws TextbrokerBudgetInsertException|TextbrokerBudgetUpdateException
*/
private function saveBudget(array $aBudget, $isUpdate = false) {
try {
if (!isset($aBudget['id']) || empty($aBudget['id'])) {
throw new Exception("ERROR: Budget id is missing");
} elseif (!is_numeric($aBudget['id'])) {
throw new Exception("ERROR: Budget id is invalid");
}
if (!isset($aBudget['key']) || empty($aBudget['key'])) {
throw new Exception("ERROR: Budget key is missing");
}
if (!isset($aBudget['password']) || empty($aBudget['password'])) {
throw new Exception("ERROR: Budget password is missing");
}
$aBudget['name'] = TextbrokerBudgetCheck::singleton($aBudget['key'], $aBudget['id'], $aBudget['password'], $aBudget['location'])->getName();
if (!$aBudget['name'] || empty($aBudget['name'])) {
throw new Exception("ERROR: Budget information is incorrect");
}
$aBudgets = $this->getBudgets();
$aBudgets[$aBudget['id']] = $aBudget;
$this->setOption(self::IDENTIFIER_BUDGETS, $aBudgets);
} catch (Exception $e) {
if ($isUpdate) {
throw new TextbrokerBudgetUpdateException($e->getMessage());
} else {
throw new TextbrokerBudgetInsertException($e->getMessage());
}
}
}
/**
*
* @param int $budgetId
* @throws TextbrokerBudgetException
*/
private function deleteBudget($budgetId) {
try {
$aBudgets = $this->getBudgets();
unset($aBudgets[$budgetId]);
$this->setOption(self::IDENTIFIER_BUDGETS, $aBudgets);
} catch (Exception $e) {
throw new TextbrokerBudgetException($e->getMessage());
}
}
/**
*
*
* @return array
*/
public function getBudgets() {
$aBudgets = $this->getOption(self::IDENTIFIER_BUDGETS);
if(!is_array($aBudgets)) {
return array();
}
return $aBudgets;
}
/**
*
*
* @return array
*/
private function getTeams($budgetId) {
$aBudget = $this->getBudget($budgetId);
$oBudgetOrder = TextbrokerBudgetOrder::singleton($aBudget['key'], $aBudget['id'], $aBudget['password'], $aBudget['location']);
$aTeams = $oBudgetOrder->getTeams();
if(!is_array($aTeams)) {
return array();
}
return $aTeams;
}
/**
*
*
* @param int $budgetId
* @return array
*/
private function getBudgetDetails($budgetId) {
$aBudget = $this->getBudget($budgetId);
$oBudgetOrder = TextbrokerBudgetCheck::singleton($aBudget['key'], $aBudget['id'], $aBudget['password'], $aBudget['location']);
$aUsage = $oBudgetOrder->getUsage();
if (is_array($aUsage) && count($aUsage) > 0) {
$aBudget += $aUsage;
}
$aBudget += $oBudgetOrder->isInSandbox();
$aBudget += $oBudgetOrder->getActualPeriodData();
return $aBudget;
}
/**
* Get formatted date
*
* @param string $location
* @param string $timestamp
* @return string
*/
protected function getDate($location, $timestamp = null) {
if (is_null($timestamp)) {
$timestamp = time();
}
if ($location == 'de') {
return date('d.m.Y', $timestamp);
} else {
return date('m/d/Y', $timestamp);
}
}
/******************************************************************************************************************************************************************************
* HTML forms
******************************************************************************************************************************************************************************/
public function getHeader($display = false) {
parent::getHeader(plugins_url(self::getName() . '/images/logo.gif'), $display);
}
/**
*
* @param bool $display
* @return void | string
*/
public function showBudgetInformationAddButton($display = false) {
$str = '
<p class="submit">
<a href="%s" class="button right">%s</a>
</p>
';
$args = array(
attribute_escape(add_query_arg('_wpnonce', wp_create_nonce(self::ACTION_BUDGET_INFO_ADD))),
__('Enter budget information', self::getIdentifier()),
);
if ($display) {
vprintf($str, $args);
} else {
return vsprintf($str, $args);
}
}
/**
*
* @param bool $display
* @return void | string
*/
public function showBudgetInformationEntryForm(array $aBudget = array(), $update = false, $display = false) {
$str = '
<div class="left half">
<form method="post" action="%s" class="tb">
<fieldset>
<label for="budget-id">%s</label>
<input type="text" name="budget[id]" value="%s" id="budget-id" %s />
<label for="budget-key">%s</label>
<input type="text" name="budget[key]" value="%s" id="budget-key" %s />
<label for="budget-password">%s</label>
<input type="password" name="budget[password]" value="%s" id="budget-password" />
<label for="budget-location">%s</label>
<select name="budget[location]" id="budget-location">
%s
</select>
<p class="submit">
<input type="submit" name="do" value="%s" class="button" />
</p>
</fieldset>
</form>
</div>
<div class="right half">
<p>
%s
</p>
</div>
';
$args = array(
$update ? attribute_escape(add_query_arg('_wpnonce', wp_create_nonce(self::ACTION_BUDGET_INFO_UPDATE))) : attribute_escape(add_query_arg('_wpnonce', wp_create_nonce(self::ACTION_BUDGET_INFO_INSERT))),
$update ? __('Budget id', self::getIdentifier()) : __('Enter budget id', self::getIdentifier()),
@$aBudget['id'],
$update ? 'readonly="readonly"' : '',
$update ? __('Budget key', self::getIdentifier()) : __('Enter budget key', self::getIdentifier()),
@$aBudget['key'],
$update ? 'readonly="readonly"' : '',
__('Enter budget password', self::getIdentifier()),
@$aBudget['password'],
__('Service location', self::getIdentifier()),
$this->showLocation(@$aBudget['location']),
$update ? __('Update budget information', self::getIdentifier()) : __('Save budget information', self::getIdentifier()),
__('You find your budget information on the Textbroker website.', self::getIdentifier()),
);
if ($display) {
vprintf($str, $args);
} else {
return vsprintf($str, $args);
}
}
/**
*
*
* @param array $aBudgets
* @param bool $display
* @return string | void
*/
public function showBudgetInformation(array $aBudgets, $display = false) {
$str = '
<h4>%s</h4>
<div>
<ul>
%s
</ul>
</div>
<div class="clear"></div>
';
$args = array(
__('Budgets', self::getIdentifier()),
$this->showBudgets($aBudgets),
);
if ($display) {
vprintf($str, $args);
} else {
return vsprintf($str, $args);
}
}
/**
*
*
* @param array $aBudgets
* @param bool $display
* @return string | void
*/
public function showTeamInformation(array $aBudgets, $display = false) {
$str = '
<h4>%s</h4>
<div>
<ul>
%s
</ul>
</div>
<div class="clear"></div>
';
$args = array(
__('Teams', self::getIdentifier()),
$this->showTeams($aBudgets)
);
if ($display) {
vprintf($str, $args);
} else {
return vsprintf($str, $args);
}
}
/**
*
*
* @param array $aBudgets
* @return string
*/
private function showBudgets(array $aBudgets) {
$str = null;
if (count($aBudgets) > 0) {
foreach ($aBudgets as $aBudget) {
$str .= sprintf('
<li class="clear">
<ul class="tb-budgets">
<li><img src="%s" alt="%s" /> <a href="%s&%s" title="%s: %s - %s">%s</a></li>
<li><a href="%s" class="button">%s</a></li>
</ul>
</li>
',
plugins_url(self::getName() . '/images/' . $aBudget['location'] . '.gif'),
__('Service: ' . $aBudget['location'], self::getIdentifier()),
attribute_escape(add_query_arg('_wpnonce', wp_create_nonce(self::ACTION_BUDGET_INFO_LIST))),
self::PARAM_BUDGET_ID . '=' . $aBudget['id'],
__('Budget', self::getIdentifier()),
$aBudget['id'],
__('List budget details', self::getIdentifier()),
$aBudget['name'],
get_option('siteurl') . '/wp-admin/admin.php?page=' . self::getName() . '/lib/TextbrokerOrder.php&_wpnonce=' . wp_create_nonce(self::ACTION_ORDER_ADD) . '&' . self::PARAM_BUDGET_ID . '=' . $aBudget['id'] . '&' . self::PARAM_BUDGET_NAME . '=' . $aBudget['name'],
__('Add order', self::getIdentifier())
);
}
} else {
$str = sprintf('<li>%s</li>', __('No budgets', self::getIdentifier()));
}
return $str;
}
/**
* Build options for location selector
*
* @param string $selected
* @return string
*/
private function showLocation($selected) {
$str = '';
foreach ($this->getLocations() as $location) {
$str .= sprintf('<option value="%s" %s>%s</option>', $location, ($location == $selected) ? 'selected="selected"' : '', __('Service: ' . $location, self::getIdentifier()));
}
return $str;
}
/**
*
*
* @param array $aBudgets
* @return string
*/
private function showTeams(array $aBudgets) {
$str = null;
if (count($aBudgets) > 0) {
$aBudget = array_shift($aBudgets);
$aTeams = $this->getTeams($aBudget['id']);
$str .= sprintf('
<li class="clear">
<ul class="tb-budgets">
<li>
<form action="%s" method="post">
<input type="hidden" name="%s" value="%s" />
<select name="%s">%s</select>
<input value="%s" type="submit">
</form>
</li>
</ul>
</li>
',
get_option('siteurl') . '/wp-admin/admin.php?page=' . self::getName() . '/lib/TextbrokerOrder.php&_wpnonce=' . wp_create_nonce(self::ACTION_TEAMORDER_ADD),
self::PARAM_BUDGET_ID,
$aBudget['id'],
self::PARAM_TEAM_ID,
$this->buildTeams($aTeams),
__('Create team order', self::getIdentifier())
);
}
return $str;
}
/**
* Build options for teams
*
* @param array $aTeams
* @return string
*/
private function buildTeams(array $aTeams) {
$str = '';
try {
foreach ($aTeams as $aTeam) {
$str .= sprintf('<option value="%s">%s %s %s/%s</option>', $aTeam['team_id'], $aTeam['team_name'], $aTeam['team_price_per_word']/100, __('Local currency', self::getIdentifier()), __('Word', self::getIdentifier()));
}
} catch (TextbrokerBudgetOrderException $e) {
$str .= sprintf('<option value="">%s</option>', __("ERROR: " . $e->getMessage(), self::getIdentifier()));
}
return $str;
}
/**
*
*
* @param array $aBudget
* @param bool $display
* @return string | void
*/
private function showBudgetDetails(array $aBudget, $display = false) {
$str = '
<h4>%s „%s“ <a href="%s&%s" class="button">%s</a></h4>
<dl class="tb-list">
<dt>%s:</dt> <dd>%s</dd>
<dt>%s:</dt> <dd>%s</dd>
<dt>%s:</dt> <dd>%s</dd>
</dl>
<table class="widefat">
<thead>
<tr>
<th>%s</th>
<th>%s</th>
<th>%s</th>
<th>%s</th>
<th>%s</th>
<th>%s</th>
</tr>
</thead>
<tbody>
<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>
</tbody>
</table>
<p class="submit">
<a href="%s&%s" class="button">%s</a>
</p>
';
$args = array(
__('Budget', self::getIdentifier()),
$aBudget['name'],
attribute_escape(add_query_arg('_wpnonce', wp_create_nonce(self::ACTION_BUDGET_INFO_EDIT))), self::PARAM_BUDGET_ID . '=' . $aBudget['id'],
__('Edit', self::getIdentifier()),
__('Budget id', self::getIdentifier()),
$aBudget['id'],
__('Budget key', self::getIdentifier()),
$aBudget['key'],
__('Status', self::getIdentifier()),
$aBudget['sandbox'] ? __('Sandbox', self::getIdentifier()) : __('Live', self::getIdentifier()),
__('Period start', self::getIdentifier()),
__('Period end', self::getIdentifier()),
__('Budget max', self::getIdentifier()),
__('Budget left', self::getIdentifier()),
__('Budget locked', self::getIdentifier()),
__('Budget used', self::getIdentifier()),
$this->getDate($aBudget['location'], $aBudget['start']),
$this->getDate($aBudget['location'], $aBudget['end']),
$aBudget['max'],
$aBudget['left'],
$aBudget['locked'],
$aBudget['usage'],
attribute_escape(add_query_arg('_wpnonce', wp_create_nonce(self::ACTION_BUDGET_INFO_DELETE))), self::PARAM_BUDGET_ID . '=' . $aBudget['id'],
__('Delete', self::getIdentifier()),
);
if ($display) {
vprintf($str, $args);
} else {
return vsprintf($str, $args);
}
}
/**
* Set the name the option list is saved as in WordPress internally
*/
function setOptionsName() {
$this->optionsName .= self::IDENTIFIER;
}
}
/**
*
* @package Textbroker WordPress-Plugin
* @author Fabio Bacigalupo <info1@open-haus.de>
* @copyright Fabio Bacigalupo 2010
* @version $Revision: 1 $
* @since PHP 5.2
*/
class TextbrokerBudgetException extends Exception {
public function __construct($message, $code = 0) {
parent::__construct($message, $code);
}
}
/**
*
* @package Textbroker WordPress-Plugin
* @author Fabio Bacigalupo <info1@open-haus.de>
* @copyright Fabio Bacigalupo 2010
* @version $Revision: 1 $
* @since PHP 5.2
*/
class TextbrokerBudgetUpdateException extends TextbrokerBudgetException {
public function __construct($message, $code = 0) {
parent::__construct($message, $code);
}
}
/**
*
* @package Textbroker WordPress-Plugin
* @author Fabio Bacigalupo <info1@open-haus.de>
* @copyright Fabio Bacigalupo 2010
* @version $Revision: 1 $
* @since PHP 5.2
*/
class TextbrokerBudgetInsertException extends TextbrokerBudgetException {
public function __construct($message, $code = 0) {
parent::__construct($message, $code);
}
}
?>