Completed
Push — prado-3.3 ( f4da81...5dd4b5 )
by Fabio
09:03
created
framework/PradoBase.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@
 block discarded – undo
18 18
 if(!defined('PRADO_DIR'))
19 19
 	define('PRADO_DIR',dirname(__FILE__));
20 20
 /**
21
- * Defines the default permission for writable directories and files
22
- */
21
+	 * Defines the default permission for writable directories and files
22
+	 */
23 23
 if(!defined('PRADO_CHMOD'))
24 24
 	define('PRADO_CHMOD',0777);
25 25
 
Please login to merge, or discard this patch.
framework/Web/UI/ActiveControls/TActiveDataGrid.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 	}
69 69
 
70 70
 	/**
71
-	* Creates a new callback control, sets the adapter to
72
-	* TActiveControlAdapter.
73
-	*/
71
+	 * Creates a new callback control, sets the adapter to
72
+	 * TActiveControlAdapter.
73
+	 */
74 74
 	public function __construct() {
75 75
 		parent::__construct();
76 76
 		$this->setAdapter(new TActiveControlAdapter($this));
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @param string $value container tag
112 112
 	 */
113 113
 	public function setSurroundingTag($value) {
114
-    $this->_surroundingTag=TPropertyValue::ensureString($value);
114
+	$this->_surroundingTag=TPropertyValue::ensureString($value);
115 115
 	}
116 116
 
117 117
 	/**
Please login to merge, or discard this patch.
framework/Web/UI/WebControls/TCheckBoxList.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
 	{
405 405
 	  if ($needSpan=$this->getSpanNeeded())
406 406
 	  {
407
-	    $writer->addAttribute('id', $this->getClientId());
408
-	    $writer->renderBeginTag('span');
407
+		$writer->addAttribute('id', $this->getClientId());
408
+		$writer->renderBeginTag('span');
409 409
 	  }
410 410
 		if($this->getItemCount()>0)
411 411
 		{
@@ -463,14 +463,14 @@  discard block
 block discarded – undo
463 463
 	 */
464 464
 	public function getIsValid()
465 465
 	{
466
-	    return $this->_isValid;
466
+		return $this->_isValid;
467 467
 	}
468 468
 	/**
469 469
 	 * @param bool wether this control is valid.
470 470
 	 */
471 471
 	public function setIsValid($value)
472 472
 	{
473
-	    $this->_isValid=TPropertyValue::ensureBoolean($value);
473
+		$this->_isValid=TPropertyValue::ensureBoolean($value);
474 474
 	}
475 475
 
476 476
 	/**
Please login to merge, or discard this patch.
framework/Web/UI/WebControls/TReCaptcha2Validator.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -29,82 +29,82 @@
 block discarded – undo
29 29
 
30 30
 class TReCaptcha2Validator extends TBaseValidator
31 31
 {
32
-    protected $_isvalid = null;
32
+	protected $_isvalid = null;
33 33
 
34
-    protected function getClientClassName()
35
-    {
36
-        return 'Prado.WebUI.TReCaptcha2Validator';
37
-    }
38
-    public function getEnableClientScript()
39
-    {
40
-        return true;
41
-    }
42
-    protected function getCaptchaControl()
43
-    {
44
-        $control = $this->getValidationTarget();
45
-        if (!$control)
46
-            throw new Exception('No target control specified for TReCaptcha2Validator');
47
-        if (!($control instanceof TReCaptcha2))
48
-            throw new Exception('TReCaptcha2Validator only works with TReCaptcha2 controls');
49
-        return $control;
50
-    }
51
-    public function getClientScriptOptions()
52
-    {
53
-        $options = parent::getClientScriptOptions();
54
-        $options['ResponseFieldName'] = $this->getCaptchaControl()->getResponseFieldName();
55
-        return $options;
56
-    }
57
-    /**
58
-     * This method overrides the parent's implementation.
59
-     * The validation succeeds if the input control has the same value
60
-     * as the one displayed in the corresponding RECAPTCHA control.
61
-     *
62
-     * @return boolean whether the validation succeeds
63
-     */
64
-    protected function evaluateIsValid()
65
-    {
66
-        // check validity only once (if trying to evaulate multiple times, all redundant checks would fail)
67
-        if (is_null($this->_isvalid))
68
-        {
69
-            $control = $this->getCaptchaControl();
70
-            $this->_isvalid = $control->validate();
71
-        }
72
-        return ($this->_isvalid==true);
73
-    }
74
-    public function onPreRender($param)
75
-    {
76
-        parent::onPreRender($param);
34
+	protected function getClientClassName()
35
+	{
36
+		return 'Prado.WebUI.TReCaptcha2Validator';
37
+	}
38
+	public function getEnableClientScript()
39
+	{
40
+		return true;
41
+	}
42
+	protected function getCaptchaControl()
43
+	{
44
+		$control = $this->getValidationTarget();
45
+		if (!$control)
46
+			throw new Exception('No target control specified for TReCaptcha2Validator');
47
+		if (!($control instanceof TReCaptcha2))
48
+			throw new Exception('TReCaptcha2Validator only works with TReCaptcha2 controls');
49
+		return $control;
50
+	}
51
+	public function getClientScriptOptions()
52
+	{
53
+		$options = parent::getClientScriptOptions();
54
+		$options['ResponseFieldName'] = $this->getCaptchaControl()->getResponseFieldName();
55
+		return $options;
56
+	}
57
+	/**
58
+	 * This method overrides the parent's implementation.
59
+	 * The validation succeeds if the input control has the same value
60
+	 * as the one displayed in the corresponding RECAPTCHA control.
61
+	 *
62
+	 * @return boolean whether the validation succeeds
63
+	 */
64
+	protected function evaluateIsValid()
65
+	{
66
+		// check validity only once (if trying to evaulate multiple times, all redundant checks would fail)
67
+		if (is_null($this->_isvalid))
68
+		{
69
+			$control = $this->getCaptchaControl();
70
+			$this->_isvalid = $control->validate();
71
+		}
72
+		return ($this->_isvalid==true);
73
+	}
74
+	public function onPreRender($param)
75
+	{
76
+		parent::onPreRender($param);
77 77
 
78
-        $cs = $this->Page->getClientScript();
79
-        $cs->registerPradoScript('validator');
78
+		$cs = $this->Page->getClientScript();
79
+		$cs->registerPradoScript('validator');
80 80
 
81
-        // communicate validation status to the client side
82
-        $value = $this->_isvalid===false ? '0' : '1';
83
-        $cs->registerHiddenField($this->getClientID().'_1',$value);
81
+		// communicate validation status to the client side
82
+		$value = $this->_isvalid===false ? '0' : '1';
83
+		$cs->registerHiddenField($this->getClientID().'_1',$value);
84 84
 
85
-        // update validator display
86
-        if ($control = $this->getValidationTarget())
87
-        {
88
-            $fn = 'captchaUpdateValidatorStatus_'.$this->getClientID();
85
+		// update validator display
86
+		if ($control = $this->getValidationTarget())
87
+		{
88
+			$fn = 'captchaUpdateValidatorStatus_'.$this->getClientID();
89 89
 
90
-            $cs->registerEndScript($this->getClientID().'::validate', implode(' ',array(
91
-                // this function will be used to update the validator
92
-                'function '.$fn.'(valid)',
93
-                '{',
94
-                '  jQuery('.TJavaScript::quoteString('#'.$this->getClientID().'_1').').val(valid);',
95
-                '  Prado.Validation.validateControl('.TJavaScript::quoteString($control->ClientID).'); ',
96
-                '}',
97
-                '',
98
-                // update the validator to the result if we're in a callback 
99
-                // (if we're in initial rendering or a postback then the result will be rendered directly to the page html anyway)
100
-                $this->Page->IsCallback ? $fn.'('.$value.');' : '',
101
-                '',
102
-                // install event handler that clears the validation error when user changes the captcha response field
103
-                'jQuery("#'.$control->getClientID().'").on("change", '.TJavaScript::quoteString('#'.$control->getResponseFieldName()).', function() { ',
104
-                    $fn.'("1");',
105
-                '});',
106
-            )));
107
-        }
108
-    }
90
+			$cs->registerEndScript($this->getClientID().'::validate', implode(' ',array(
91
+				// this function will be used to update the validator
92
+				'function '.$fn.'(valid)',
93
+				'{',
94
+				'  jQuery('.TJavaScript::quoteString('#'.$this->getClientID().'_1').').val(valid);',
95
+				'  Prado.Validation.validateControl('.TJavaScript::quoteString($control->ClientID).'); ',
96
+				'}',
97
+				'',
98
+				// update the validator to the result if we're in a callback 
99
+				// (if we're in initial rendering or a postback then the result will be rendered directly to the page html anyway)
100
+				$this->Page->IsCallback ? $fn.'('.$value.');' : '',
101
+				'',
102
+				// install event handler that clears the validation error when user changes the captcha response field
103
+				'jQuery("#'.$control->getClientID().'").on("change", '.TJavaScript::quoteString('#'.$control->getResponseFieldName()).', function() { ',
104
+					$fn.'("1");',
105
+				'});',
106
+			)));
107
+		}
108
+	}
109 109
 }
110 110
 
Please login to merge, or discard this patch.
framework/Web/UI/WebControls/TReCaptcha2.php 1 patch
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -55,310 +55,310 @@
 block discarded – undo
55 55
 
56 56
 class TReCaptcha2 extends TActivePanel implements ICallbackEventHandler, IValidatable
57 57
 {
58
-    const ChallengeFieldName = 'g-recaptcha-response';
59
-    private $_widgetId=0;
60
-    private $_isValid=true;
58
+	const ChallengeFieldName = 'g-recaptcha-response';
59
+	private $_widgetId=0;
60
+	private $_isValid=true;
61 61
 
62
-    public function __construct()
63
-    {
64
-        parent::__construct();
65
-        $this->setAdapter(new TActiveControlAdapter($this));
66
-    }
67
-    public function getActiveControl()
68
-    {
69
-        return $this->getAdapter()->getBaseActiveControl();
70
-    }
71
-    public function getClientSide()
72
-    {
73
-        return $this->getAdapter()->getBaseActiveControl()->getClientSide();
74
-    }
75
-    public function getClientClassName()
76
-    {
77
-        return 'Prado.WebUI.TReCaptcha2';
78
-    }
79
-    public function getTagName()
80
-    {
81
-        return 'div';
82
-    }
83
-    /**
84
-     * Returns true if this control validated successfully. 
85
-     * Defaults to true.
86
-     * @return bool wether this control validated successfully.
87
-     */
88
-    public function getIsValid()
89
-    {
90
-        return $this->_isValid;
91
-    }
92
-    /**
93
-     * @param bool wether this control is valid.
94
-     */
95
-    public function setIsValid($value)
96
-    {
97
-        $this->_isValid=TPropertyValue::ensureBoolean($value);
98
-    }
99
-    public function getValidationPropertyValue()
100
-    {
101
-        return $this->Request[$this->getResponseFieldName()];
102
-    }
103
-    public function getResponseFieldName()
104
-    {
105
-        $captchas = $this->Page->findControlsByType('TReCaptcha2');
106
-        $cont = 0;
107
-        $responseFieldName = self::ChallengeFieldName;
108
-        foreach ($captchas as $captcha)
109
-        {
110
-            if ($this->getClientID() == $captcha->ClientID)
111
-            {
112
-                $responseFieldName .= ($cont > 0) ? '-'.$cont : '';
113
-            }
114
-            $cont++;
115
-        }
116
-        return $responseFieldName;
117
-    }
118
-    /**
119
-     * Returns your site key. 
120
-     * @return string.
121
-     */
122
-    public function getSiteKey()
123
-    {
124
-        return $this->getViewState('SiteKey');
125
-    }
126
-    /**
127
-     * @param string your site key.
128
-     */
129
-    public function setSiteKey($value)
130
-    {
131
-        $this->setViewState('SiteKey', TPropertyValue::ensureString($value));
132
-    }
133
-    /**
134
-     * Returns your secret key. 
135
-     * @return string.
136
-     */
137
-    public function getSecretKey()
138
-    {
139
-        return $this->getViewState('SecretKey');
140
-    }
141
-    /**
142
-     * @param string your secret key.
143
-     */
144
-    public function setSecretKey($value)
145
-    {
146
-        $this->setViewState('SecretKey', TPropertyValue::ensureString($value));
147
-    }
148
-    /**
149
-     * Returns your language.
150
-     * @return string.
151
-     */
152
-    public function getLanguage()
153
-    {
154
-        return $this->getViewState('Language', 'en');
155
-    }
156
-    /**
157
-     * @param string your language.
158
-     */
159
-    public function setLanguage($value)
160
-    {
161
-        $this->setViewState('Language', TPropertyValue::ensureString($value), 'en');
162
-    }
163
-    /**
164
-     * Returns the color theme of the widget. 
165
-     * @return string.
166
-     */
167
-    public function getTheme()
168
-    {
169
-        return $this->getViewState('Theme', 'light');
170
-    }
171
-    /**
172
-     * The color theme of the widget.
173
-     * Default: light
174
-     * @param string the color theme of the widget.
175
-     */
176
-    public function setTheme($value)
177
-    {
178
-        $this->setViewState('Theme', TPropertyValue::ensureString($value), 'light');
179
-    }
180
-    /**
181
-     * Returns the type of CAPTCHA to serve.
182
-     * @return string.
183
-     */
184
-    public function getType()
185
-    {
186
-        return $this->getViewState('Type', 'image');
187
-    }
188
-    /**
189
-     * The type of CAPTCHA to serve.
190
-     * Default: image
191
-     * @param string the type of CAPTCHA to serve.
192
-     */
193
-    public function setType($value)
194
-    {
195
-        $this->setViewState('Type', TPropertyValue::ensureString($value), 'image');
196
-    }
197
-    /**
198
-     * Returns the size of the widget.
199
-     * @return string.
200
-     */
201
-    public function getSize()
202
-    {
203
-        return $this->getViewState('Size', 'normal');
204
-    }
205
-    /**
206
-     * The size of the widget.
207
-     * Default: normal
208
-     * @param string the size of the widget.
209
-     */
210
-    public function setSize($value)
211
-    {
212
-        $this->setViewState('Size', TPropertyValue::ensureString($value), 'normal');
213
-    }
214
-    /**
215
-     * Returns the tabindex of the widget and challenge.
216
-     * If other elements in your page use tabindex, it should be set to make user navigation easier.
217
-     * @return string.
218
-     */
219
-    public function getTabIndex()
220
-    {
221
-        return $this->getViewState('TabIndex', 0);
222
-    }
223
-    /**
224
-     * The tabindex of the widget and challenge.
225
-     * If other elements in your page use tabindex, it should be set to make user navigation easier.
226
-     * Default: 0
227
-     * @param string the tabindex of the widget and challenge.
228
-     */
229
-    public function setTabIndex($value)
230
-    {
231
-        $this->setViewState('TabIndex', TPropertyValue::ensureInteger($value), 0);
232
-    }
233
-    /**
234
-     * Resets the reCAPTCHA widget.
235
-     * Optional widget ID, defaults to the first widget created if unspecified.
236
-     */
237
-    public function reset()
238
-    {
239
-        $this->Page->CallbackClient->callClientFunction('grecaptcha.reset',array(array($this->WidgetId)));
240
-    }
241
-    /**
242
-     * Gets the response for the reCAPTCHA widget.
243
-     */
244
-    public function getResponse()
245
-    {
246
-        return $this->getViewState('Response', '');
247
-    }
248
-    public function setResponse($value)
249
-    {
250
-        $this->setViewState('Response', TPropertyValue::ensureString($value), '');
251
-    }
252
-    public function getWidgetId()
253
-    {
254
-        return $this->getViewState('WidgetId', 0);
255
-    }
256
-    public function setWidgetId($value)
257
-    {
258
-        $this->setViewState('WidgetId', TPropertyValue::ensureInteger($value), 0);
259
-    }
260
-    protected function getClientOptions()
261
-    {
262
-        $options['ID'] = $this->getClientID();
263
-        $options['EventTarget'] = $this->getUniqueID();
264
-        $options['FormID'] = $this->Page->getForm()->getClientID();
265
-        $options['onCallback'] = $this->hasEventHandler('OnCallback');
266
-        $options['onCallbackExpired'] = $this->hasEventHandler('OnCallbackExpired');
267
-        $options['options']['sitekey'] = $this->getSiteKey();
268
-        if ($theme = $this->getTheme()) $options['options']['theme'] = $theme;
269
-        if ($type = $this->getType()) $options['options']['type'] = $type;
270
-        if ($size = $this->getSize()) $options['options']['size'] = $size;
271
-        if ($tabIndex = $this->getTabIndex()) $options['options']['tabindex'] = $tabIndex;
62
+	public function __construct()
63
+	{
64
+		parent::__construct();
65
+		$this->setAdapter(new TActiveControlAdapter($this));
66
+	}
67
+	public function getActiveControl()
68
+	{
69
+		return $this->getAdapter()->getBaseActiveControl();
70
+	}
71
+	public function getClientSide()
72
+	{
73
+		return $this->getAdapter()->getBaseActiveControl()->getClientSide();
74
+	}
75
+	public function getClientClassName()
76
+	{
77
+		return 'Prado.WebUI.TReCaptcha2';
78
+	}
79
+	public function getTagName()
80
+	{
81
+		return 'div';
82
+	}
83
+	/**
84
+	 * Returns true if this control validated successfully. 
85
+	 * Defaults to true.
86
+	 * @return bool wether this control validated successfully.
87
+	 */
88
+	public function getIsValid()
89
+	{
90
+		return $this->_isValid;
91
+	}
92
+	/**
93
+	 * @param bool wether this control is valid.
94
+	 */
95
+	public function setIsValid($value)
96
+	{
97
+		$this->_isValid=TPropertyValue::ensureBoolean($value);
98
+	}
99
+	public function getValidationPropertyValue()
100
+	{
101
+		return $this->Request[$this->getResponseFieldName()];
102
+	}
103
+	public function getResponseFieldName()
104
+	{
105
+		$captchas = $this->Page->findControlsByType('TReCaptcha2');
106
+		$cont = 0;
107
+		$responseFieldName = self::ChallengeFieldName;
108
+		foreach ($captchas as $captcha)
109
+		{
110
+			if ($this->getClientID() == $captcha->ClientID)
111
+			{
112
+				$responseFieldName .= ($cont > 0) ? '-'.$cont : '';
113
+			}
114
+			$cont++;
115
+		}
116
+		return $responseFieldName;
117
+	}
118
+	/**
119
+	 * Returns your site key. 
120
+	 * @return string.
121
+	 */
122
+	public function getSiteKey()
123
+	{
124
+		return $this->getViewState('SiteKey');
125
+	}
126
+	/**
127
+	 * @param string your site key.
128
+	 */
129
+	public function setSiteKey($value)
130
+	{
131
+		$this->setViewState('SiteKey', TPropertyValue::ensureString($value));
132
+	}
133
+	/**
134
+	 * Returns your secret key. 
135
+	 * @return string.
136
+	 */
137
+	public function getSecretKey()
138
+	{
139
+		return $this->getViewState('SecretKey');
140
+	}
141
+	/**
142
+	 * @param string your secret key.
143
+	 */
144
+	public function setSecretKey($value)
145
+	{
146
+		$this->setViewState('SecretKey', TPropertyValue::ensureString($value));
147
+	}
148
+	/**
149
+	 * Returns your language.
150
+	 * @return string.
151
+	 */
152
+	public function getLanguage()
153
+	{
154
+		return $this->getViewState('Language', 'en');
155
+	}
156
+	/**
157
+	 * @param string your language.
158
+	 */
159
+	public function setLanguage($value)
160
+	{
161
+		$this->setViewState('Language', TPropertyValue::ensureString($value), 'en');
162
+	}
163
+	/**
164
+	 * Returns the color theme of the widget. 
165
+	 * @return string.
166
+	 */
167
+	public function getTheme()
168
+	{
169
+		return $this->getViewState('Theme', 'light');
170
+	}
171
+	/**
172
+	 * The color theme of the widget.
173
+	 * Default: light
174
+	 * @param string the color theme of the widget.
175
+	 */
176
+	public function setTheme($value)
177
+	{
178
+		$this->setViewState('Theme', TPropertyValue::ensureString($value), 'light');
179
+	}
180
+	/**
181
+	 * Returns the type of CAPTCHA to serve.
182
+	 * @return string.
183
+	 */
184
+	public function getType()
185
+	{
186
+		return $this->getViewState('Type', 'image');
187
+	}
188
+	/**
189
+	 * The type of CAPTCHA to serve.
190
+	 * Default: image
191
+	 * @param string the type of CAPTCHA to serve.
192
+	 */
193
+	public function setType($value)
194
+	{
195
+		$this->setViewState('Type', TPropertyValue::ensureString($value), 'image');
196
+	}
197
+	/**
198
+	 * Returns the size of the widget.
199
+	 * @return string.
200
+	 */
201
+	public function getSize()
202
+	{
203
+		return $this->getViewState('Size', 'normal');
204
+	}
205
+	/**
206
+	 * The size of the widget.
207
+	 * Default: normal
208
+	 * @param string the size of the widget.
209
+	 */
210
+	public function setSize($value)
211
+	{
212
+		$this->setViewState('Size', TPropertyValue::ensureString($value), 'normal');
213
+	}
214
+	/**
215
+	 * Returns the tabindex of the widget and challenge.
216
+	 * If other elements in your page use tabindex, it should be set to make user navigation easier.
217
+	 * @return string.
218
+	 */
219
+	public function getTabIndex()
220
+	{
221
+		return $this->getViewState('TabIndex', 0);
222
+	}
223
+	/**
224
+	 * The tabindex of the widget and challenge.
225
+	 * If other elements in your page use tabindex, it should be set to make user navigation easier.
226
+	 * Default: 0
227
+	 * @param string the tabindex of the widget and challenge.
228
+	 */
229
+	public function setTabIndex($value)
230
+	{
231
+		$this->setViewState('TabIndex', TPropertyValue::ensureInteger($value), 0);
232
+	}
233
+	/**
234
+	 * Resets the reCAPTCHA widget.
235
+	 * Optional widget ID, defaults to the first widget created if unspecified.
236
+	 */
237
+	public function reset()
238
+	{
239
+		$this->Page->CallbackClient->callClientFunction('grecaptcha.reset',array(array($this->WidgetId)));
240
+	}
241
+	/**
242
+	 * Gets the response for the reCAPTCHA widget.
243
+	 */
244
+	public function getResponse()
245
+	{
246
+		return $this->getViewState('Response', '');
247
+	}
248
+	public function setResponse($value)
249
+	{
250
+		$this->setViewState('Response', TPropertyValue::ensureString($value), '');
251
+	}
252
+	public function getWidgetId()
253
+	{
254
+		return $this->getViewState('WidgetId', 0);
255
+	}
256
+	public function setWidgetId($value)
257
+	{
258
+		$this->setViewState('WidgetId', TPropertyValue::ensureInteger($value), 0);
259
+	}
260
+	protected function getClientOptions()
261
+	{
262
+		$options['ID'] = $this->getClientID();
263
+		$options['EventTarget'] = $this->getUniqueID();
264
+		$options['FormID'] = $this->Page->getForm()->getClientID();
265
+		$options['onCallback'] = $this->hasEventHandler('OnCallback');
266
+		$options['onCallbackExpired'] = $this->hasEventHandler('OnCallbackExpired');
267
+		$options['options']['sitekey'] = $this->getSiteKey();
268
+		if ($theme = $this->getTheme()) $options['options']['theme'] = $theme;
269
+		if ($type = $this->getType()) $options['options']['type'] = $type;
270
+		if ($size = $this->getSize()) $options['options']['size'] = $size;
271
+		if ($tabIndex = $this->getTabIndex()) $options['options']['tabindex'] = $tabIndex;
272 272
 
273
-        return $options;
274
-    }
275
-    protected function registerClientScript()
276
-    {
277
-        $id         = $this->getClientID();
278
-        $options    = TJavaScript::encode($this->getClientOptions());
279
-        $className  = $this->getClientClassName();
280
-        $cs         = $this->Page->ClientScript;
281
-        $code       = "new $className($options);";
273
+		return $options;
274
+	}
275
+	protected function registerClientScript()
276
+	{
277
+		$id         = $this->getClientID();
278
+		$options    = TJavaScript::encode($this->getClientOptions());
279
+		$className  = $this->getClientClassName();
280
+		$cs         = $this->Page->ClientScript;
281
+		$code       = "new $className($options);";
282 282
 
283
-        $cs->registerPradoScript('ajax');
284
-        $cs->registerEndScript("grecaptcha:$id", $code);
285
-    }
286
-    public function validate()
287
-    {
288
-        $value = $this->getValidationPropertyValue();
289
-        if($value === null || empty($value))
290
-            return false;
283
+		$cs->registerPradoScript('ajax');
284
+		$cs->registerEndScript("grecaptcha:$id", $code);
285
+	}
286
+	public function validate()
287
+	{
288
+		$value = $this->getValidationPropertyValue();
289
+		if($value === null || empty($value))
290
+			return false;
291 291
 
292
-        return true;
293
-    }
294
-    /**
295
-     * Checks for API keys
296
-     * @param mixed event parameter
297
-     */
298
-    public function onPreRender($param)
299
-    {
300
-        parent::onPreRender($param);
292
+		return true;
293
+	}
294
+	/**
295
+	 * Checks for API keys
296
+	 * @param mixed event parameter
297
+	 */
298
+	public function onPreRender($param)
299
+	{
300
+		parent::onPreRender($param);
301 301
 
302
-        if("" == $this->getSiteKey())
303
-            throw new TConfigurationException('recaptcha_publickey_unknown');
304
-        if("" == $this->getSecretKey())
305
-            throw new TConfigurationException('recaptcha_privatekey_unknown');
302
+		if("" == $this->getSiteKey())
303
+			throw new TConfigurationException('recaptcha_publickey_unknown');
304
+		if("" == $this->getSecretKey())
305
+			throw new TConfigurationException('recaptcha_privatekey_unknown');
306 306
 
307
-        // need to register captcha fields so they will be sent postback
308
-        $this->Page->registerRequiresPostData($this->getResponseFieldName());
309
-        $this->Page->ClientScript->registerHeadScriptFile('grecaptcha2', 'https://www.google.com/recaptcha/api.js?onload=TReCaptcha2_onloadCallback&render=explicit&hl=' . $this->getLanguage());
310
-    }
311
-    protected function addAttributesToRender($writer)
312
-    {
313
-        $writer->addAttribute('id',$this->getClientID());
314
-        parent::addAttributesToRender($writer);
315
-    }
316
-    public function raiseCallbackEvent($param)
317
-    {
318
-        $params = $param->getCallbackParameter();
319
-        if ($params instanceof stdClass)
320
-        {
321
-            $callback = property_exists($params, 'onCallback');
322
-            $callbackExpired = property_exists($params, 'onCallbackExpired');
307
+		// need to register captcha fields so they will be sent postback
308
+		$this->Page->registerRequiresPostData($this->getResponseFieldName());
309
+		$this->Page->ClientScript->registerHeadScriptFile('grecaptcha2', 'https://www.google.com/recaptcha/api.js?onload=TReCaptcha2_onloadCallback&render=explicit&hl=' . $this->getLanguage());
310
+	}
311
+	protected function addAttributesToRender($writer)
312
+	{
313
+		$writer->addAttribute('id',$this->getClientID());
314
+		parent::addAttributesToRender($writer);
315
+	}
316
+	public function raiseCallbackEvent($param)
317
+	{
318
+		$params = $param->getCallbackParameter();
319
+		if ($params instanceof stdClass)
320
+		{
321
+			$callback = property_exists($params, 'onCallback');
322
+			$callbackExpired = property_exists($params, 'onCallbackExpired');
323 323
 
324
-            if ($callback)
325
-            {
326
-                $this->WidgetId = $params->widgetId;
327
-                $this->Response = $params->response;
328
-                $this->Page->CallbackClient->jQuery($params->responseField, 'text',array($params->response));
324
+			if ($callback)
325
+			{
326
+				$this->WidgetId = $params->widgetId;
327
+				$this->Response = $params->response;
328
+				$this->Page->CallbackClient->jQuery($params->responseField, 'text',array($params->response));
329 329
 
330
-                if ($params->onCallback)
331
-                {
332
-                    $this->onCallback($param);
333
-                }
334
-            }
330
+				if ($params->onCallback)
331
+				{
332
+					$this->onCallback($param);
333
+				}
334
+			}
335 335
 
336
-            if ($callbackExpired)
337
-            {
338
-                $this->Response = '';
339
-                $this->reset();
336
+			if ($callbackExpired)
337
+			{
338
+				$this->Response = '';
339
+				$this->reset();
340 340
 
341
-                if ($params->onCallbackExpired)
342
-                {
343
-                    $this->onCallbackExpired($param);
344
-                }
345
-            }
346
-        }
347
-    }
341
+				if ($params->onCallbackExpired)
342
+				{
343
+					$this->onCallbackExpired($param);
344
+				}
345
+			}
346
+		}
347
+	}
348 348
 
349
-    public function onCallback($param)
350
-    {
351
-        $this->raiseEvent('OnCallback', $this, $param);
352
-    }
349
+	public function onCallback($param)
350
+	{
351
+		$this->raiseEvent('OnCallback', $this, $param);
352
+	}
353 353
 
354
-    public function onCallbackExpired($param)
355
-    {
356
-        $this->raiseEvent('OnCallbackExpired', $this, $param);
357
-    }
354
+	public function onCallbackExpired($param)
355
+	{
356
+		$this->raiseEvent('OnCallbackExpired', $this, $param);
357
+	}
358 358
 
359
-    public function render($writer)
360
-    {
361
-        $this->registerClientScript();
362
-        parent::render($writer);
363
-    }
359
+	public function render($writer)
360
+	{
361
+		$this->registerClientScript();
362
+		parent::render($writer);
363
+	}
364 364
 }
Please login to merge, or discard this patch.
framework/I18N/core/TCache_Lite.php 1 patch
Indentation   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -46,575 +46,575 @@
 block discarded – undo
46 46
 class TCache_Lite
47 47
 {
48 48
 
49
-    // --- Private properties ---
50
-
51
-    /**
52
-    * Directory where to put the cache files
53
-    * (make sure to add a trailing slash)
54
-    *
55
-    * @var string $_cacheDir
56
-    */
57
-    protected $_cacheDir = '/tmp/';
58
-
59
-    /**
60
-    * Enable / disable caching
61
-    *
62
-    * (can be very usefull for the debug of cached scripts)
63
-    *
64
-    * @var boolean $_caching
65
-    */
66
-    protected $_caching = true;
67
-
68
-    /**
69
-    * Cache lifetime (in seconds)
70
-    *
71
-    * @var int $_lifeTime
72
-    */
73
-    protected $_lifeTime = 3600;
74
-
75
-    /**
76
-    * Enable / disable fileLocking
77
-    *
78
-    * (can avoid cache corruption under bad circumstances)
79
-    *
80
-    * @var boolean $_fileLocking
81
-    */
82
-    protected $_fileLocking = true;
83
-
84
-    /**
85
-    * Timestamp of the last valid cache
86
-    *
87
-    * @var int $_refreshTime
88
-    */
89
-    protected $_refreshTime;
90
-
91
-    /**
92
-    * File name (with path)
93
-    *
94
-    * @var string $_file
95
-    */
96
-    protected $_file;
97
-
98
-    /**
99
-    * Enable / disable write control (the cache is read just after writing
100
-    * to detect corrupt entries)
101
-    *
102
-    * Enable write control will lightly slow the cache writing but not the
103
-    * cache reading. Write control can detect some corrupt cache files but
104
-    * maybe it's not a perfect control
105
-    *
106
-    * @var boolean $_writeControl
107
-    */
108
-    protected $_writeControl = true;
109
-
110
-    /**
111
-    * Enable / disable read control
112
-    *
113
-    * If enabled, a control key is embeded in cache file and this key is
114
-    * compared with the one calculated after the reading.
115
-    *
116
-    * @var boolean $_writeControl
117
-    */
118
-    protected $_readControl = true;
119
-
120
-    /**
121
-    * Type of read control (only if read control is enabled)
122
-    *
123
-    * Available values are :
124
-    * 'md5' for a md5 hash control (best but slowest)
125
-    * 'crc32' for a crc32 hash control (lightly less safe but faster,
126
-    * better choice)
127
-    * 'strlen' for a length only test (fastest)
128
-    *
129
-    * @var boolean $_readControlType
130
-    */
131
-    protected $_readControlType = 'crc32';
132
-
133
-    /**
134
-    * Current cache id
135
-    *
136
-    * @var string $_id
137
-    */
138
-    protected $_id;
139
-
140
-    /**
141
-    * Current cache group
142
-    *
143
-    * @var string $_group
144
-    */
145
-    protected $_group;
146
-
147
-    /**
148
-    * Enable / Disable "Memory Caching"
149
-    *
150
-    * NB : There is no lifetime for memory caching !
151
-    *
152
-    * @var boolean $_memoryCaching
153
-    */
154
-    protected $_memoryCaching = false;
155
-
156
-    /**
157
-    * Enable / Disable "Only Memory Caching"
158
-    * (be carefull, memory caching is "beta quality")
159
-    *
160
-    * @var boolean $_onlyMemoryCaching
161
-    */
162
-    protected $_onlyMemoryCaching = false;
163
-
164
-    /**
165
-    * Memory caching array
166
-    *
167
-    * @var array $_memoryCachingArray
168
-    */
169
-    protected $_memoryCachingArray = array();
170
-
171
-    /**
172
-    * Memory caching counter
173
-    *
174
-    * @var int $memoryCachingCounter
175
-    */
176
-    protected $_memoryCachingCounter = 0;
177
-
178
-    /**
179
-    * Memory caching limit
180
-    *
181
-    * @var int $memoryCachingLimit
182
-    */
183
-    protected $_memoryCachingLimit = 1000;
184
-
185
-    /**
186
-    * File Name protection
187
-    *
188
-    * if set to true, you can use any cache id or group name
189
-    * if set to false, it can be faster but cache ids and group names
190
-    * will be used directly in cache file names so be carefull with
191
-    * special characters...
192
-    *
193
-    * @var boolean $fileNameProtection
194
-    */
195
-    protected $_fileNameProtection = true;
196
-
197
-    /**
198
-    * Enable / disable automatic serialization
199
-    *
200
-    * it can be used to save directly datas which aren't strings
201
-    * (but it's slower)
202
-    *
203
-    * @var boolean $_serialize
204
-    */
205
-    protected $_automaticSerialization = false;
206
-
207
-    // --- Public methods ---
208
-
209
-    /**
210
-    * Constructor
211
-    *
212
-    * $options is an assoc. Available options are :
213
-    * $options = array(
214
-    * 'cacheDir' => directory where to put the cache files (string),
215
-    * 'caching' => enable / disable caching (boolean),
216
-    * 'lifeTime' => cache lifetime in seconds (int),
217
-    * 'fileLocking' => enable / disable fileLocking (boolean),
218
-    * 'writeControl' => enable / disable write control (boolean),
219
-    * 'readControl' => enable / disable read control (boolean),
220
-    * 'readControlType' => type of read control 'crc32', 'md5', 'strlen',
221
-    * 'memoryCaching' => enable / disable memory caching (boolean),
222
-    * 'onlyMemoryCaching' => enable / disable only memory caching (boolean),
223
-    * 'memoryCachingLimit' => max nbr of records in memory caching (int),
224
-    * 'fileNameProtection' => enable / disable file name protection (boolean),
225
-    * 'automaticSerialization' => enable / disable serialization (boolean)
226
-    * );
227
-    *
228
-    * @param array $options options
229
-    * @access public
230
-    */
231
-    function __construct($options = array(null))
232
-    {
233
-        $availableOptions = array(	'automaticSerialization',
234
-        							'fileNameProtection',
235
-        							'memoryCaching',
236
-        							'onlyMemoryCaching',
237
-        							'memoryCachingLimit',
238
-        							'cacheDir',
239
-        							'caching',
240
-        							'lifeTime',
241
-        							'fileLocking',
242
-        							'writeControl',
243
-        							'readControl',
244
-        							'readControlType');
245
-        foreach($options as $key => $value) {
246
-            if(in_array($key, $availableOptions)) {
247
-                $property = '_'.$key;
248
-                $this->$property = $value;
249
-            }
250
-        }
251
-        $this->_refreshTime = time() - $this->_lifeTime;
49
+	// --- Private properties ---
50
+
51
+	/**
52
+	 * Directory where to put the cache files
53
+	 * (make sure to add a trailing slash)
54
+	 *
55
+	 * @var string $_cacheDir
56
+	 */
57
+	protected $_cacheDir = '/tmp/';
58
+
59
+	/**
60
+	 * Enable / disable caching
61
+	 *
62
+	 * (can be very usefull for the debug of cached scripts)
63
+	 *
64
+	 * @var boolean $_caching
65
+	 */
66
+	protected $_caching = true;
67
+
68
+	/**
69
+	 * Cache lifetime (in seconds)
70
+	 *
71
+	 * @var int $_lifeTime
72
+	 */
73
+	protected $_lifeTime = 3600;
74
+
75
+	/**
76
+	 * Enable / disable fileLocking
77
+	 *
78
+	 * (can avoid cache corruption under bad circumstances)
79
+	 *
80
+	 * @var boolean $_fileLocking
81
+	 */
82
+	protected $_fileLocking = true;
83
+
84
+	/**
85
+	 * Timestamp of the last valid cache
86
+	 *
87
+	 * @var int $_refreshTime
88
+	 */
89
+	protected $_refreshTime;
90
+
91
+	/**
92
+	 * File name (with path)
93
+	 *
94
+	 * @var string $_file
95
+	 */
96
+	protected $_file;
97
+
98
+	/**
99
+	 * Enable / disable write control (the cache is read just after writing
100
+	 * to detect corrupt entries)
101
+	 *
102
+	 * Enable write control will lightly slow the cache writing but not the
103
+	 * cache reading. Write control can detect some corrupt cache files but
104
+	 * maybe it's not a perfect control
105
+	 *
106
+	 * @var boolean $_writeControl
107
+	 */
108
+	protected $_writeControl = true;
109
+
110
+	/**
111
+	 * Enable / disable read control
112
+	 *
113
+	 * If enabled, a control key is embeded in cache file and this key is
114
+	 * compared with the one calculated after the reading.
115
+	 *
116
+	 * @var boolean $_writeControl
117
+	 */
118
+	protected $_readControl = true;
119
+
120
+	/**
121
+	 * Type of read control (only if read control is enabled)
122
+	 *
123
+	 * Available values are :
124
+	 * 'md5' for a md5 hash control (best but slowest)
125
+	 * 'crc32' for a crc32 hash control (lightly less safe but faster,
126
+	 * better choice)
127
+	 * 'strlen' for a length only test (fastest)
128
+	 *
129
+	 * @var boolean $_readControlType
130
+	 */
131
+	protected $_readControlType = 'crc32';
132
+
133
+	/**
134
+	 * Current cache id
135
+	 *
136
+	 * @var string $_id
137
+	 */
138
+	protected $_id;
139
+
140
+	/**
141
+	 * Current cache group
142
+	 *
143
+	 * @var string $_group
144
+	 */
145
+	protected $_group;
146
+
147
+	/**
148
+	 * Enable / Disable "Memory Caching"
149
+	 *
150
+	 * NB : There is no lifetime for memory caching !
151
+	 *
152
+	 * @var boolean $_memoryCaching
153
+	 */
154
+	protected $_memoryCaching = false;
155
+
156
+	/**
157
+	 * Enable / Disable "Only Memory Caching"
158
+	 * (be carefull, memory caching is "beta quality")
159
+	 *
160
+	 * @var boolean $_onlyMemoryCaching
161
+	 */
162
+	protected $_onlyMemoryCaching = false;
163
+
164
+	/**
165
+	 * Memory caching array
166
+	 *
167
+	 * @var array $_memoryCachingArray
168
+	 */
169
+	protected $_memoryCachingArray = array();
170
+
171
+	/**
172
+	 * Memory caching counter
173
+	 *
174
+	 * @var int $memoryCachingCounter
175
+	 */
176
+	protected $_memoryCachingCounter = 0;
177
+
178
+	/**
179
+	 * Memory caching limit
180
+	 *
181
+	 * @var int $memoryCachingLimit
182
+	 */
183
+	protected $_memoryCachingLimit = 1000;
184
+
185
+	/**
186
+	 * File Name protection
187
+	 *
188
+	 * if set to true, you can use any cache id or group name
189
+	 * if set to false, it can be faster but cache ids and group names
190
+	 * will be used directly in cache file names so be carefull with
191
+	 * special characters...
192
+	 *
193
+	 * @var boolean $fileNameProtection
194
+	 */
195
+	protected $_fileNameProtection = true;
196
+
197
+	/**
198
+	 * Enable / disable automatic serialization
199
+	 *
200
+	 * it can be used to save directly datas which aren't strings
201
+	 * (but it's slower)
202
+	 *
203
+	 * @var boolean $_serialize
204
+	 */
205
+	protected $_automaticSerialization = false;
206
+
207
+	// --- Public methods ---
208
+
209
+	/**
210
+	 * Constructor
211
+	 *
212
+	 * $options is an assoc. Available options are :
213
+	 * $options = array(
214
+	 * 'cacheDir' => directory where to put the cache files (string),
215
+	 * 'caching' => enable / disable caching (boolean),
216
+	 * 'lifeTime' => cache lifetime in seconds (int),
217
+	 * 'fileLocking' => enable / disable fileLocking (boolean),
218
+	 * 'writeControl' => enable / disable write control (boolean),
219
+	 * 'readControl' => enable / disable read control (boolean),
220
+	 * 'readControlType' => type of read control 'crc32', 'md5', 'strlen',
221
+	 * 'memoryCaching' => enable / disable memory caching (boolean),
222
+	 * 'onlyMemoryCaching' => enable / disable only memory caching (boolean),
223
+	 * 'memoryCachingLimit' => max nbr of records in memory caching (int),
224
+	 * 'fileNameProtection' => enable / disable file name protection (boolean),
225
+	 * 'automaticSerialization' => enable / disable serialization (boolean)
226
+	 * );
227
+	 *
228
+	 * @param array $options options
229
+	 * @access public
230
+	 */
231
+	function __construct($options = array(null))
232
+	{
233
+		$availableOptions = array(	'automaticSerialization',
234
+									'fileNameProtection',
235
+									'memoryCaching',
236
+									'onlyMemoryCaching',
237
+									'memoryCachingLimit',
238
+									'cacheDir',
239
+									'caching',
240
+									'lifeTime',
241
+									'fileLocking',
242
+									'writeControl',
243
+									'readControl',
244
+									'readControlType');
245
+		foreach($options as $key => $value) {
246
+			if(in_array($key, $availableOptions)) {
247
+				$property = '_'.$key;
248
+				$this->$property = $value;
249
+			}
250
+		}
251
+		$this->_refreshTime = time() - $this->_lifeTime;
252 252
 	}
253 253
 
254
-    /**
255
-    * Test if a cache is available and (if yes) return it
256
-    *
257
-    * @param string $id cache id
258
-    * @param string $group name of the cache group
259
-    * @param boolean $doNotTestCacheValidity if set to true, the cache
260
-    * validity won't be tested
261
-    * @return string data of the cache (or false if no cache available)
262
-    * @access public
263
-    */
264
-    function get($id, $group = 'default', $doNotTestCacheValidity = false)
265
-    {
266
-        $this->_id = $id;
267
-        $this->_group = $group;
268
-        $data = false;
269
-        if ($this->_caching) {
270
-            $this->_setFileName($id, $group);
271
-            if ($this->_memoryCaching) {
272
-                if (isset($this->_memoryCachingArray[$this->_file])) {
273
-                    if ($this->_automaticSerialization) {
274
-                        return unserialize(
275
-                        			$this->_memoryCachingArray[$this->_file]);
276
-                    } else {
277
-                        return $this->_memoryCachingArray[$this->_file];
278
-                    }
279
-                } else {
280
-                    if ($this->_onlyMemoryCaching) {
281
-                        return false;
282
-                    }
283
-                }
284
-            }
285
-            if ($doNotTestCacheValidity) {
286
-                if (file_exists($this->_file)) {
287
-                    $data = $this->_read();
288
-                }
289
-            } else {
290
-                if (@filemtime($this->_file) > $this->_refreshTime) {
291
-                    $data = $this->_read();
292
-                }
293
-            }
294
-            if (($data) and ($this->_memoryCaching)) {
295
-                $this->_memoryCacheAdd($this->_file, $data);
296
-            }
297
-            if ($this->_automaticSerialization && is_string($data)) {
298
-                $data = unserialize($data);
299
-            }
300
-            return $data;
301
-        }
302
-        return false;
303
-    }
304
-
305
-    /**
306
-    * Save some data in a cache file
307
-    *
308
-    * @param string $data data to put in cache (can be another type than strings
309
-    * if automaticSerialization is on)
310
-    * @param string $id cache id
311
-    * @param string $group name of the cache group
312
-    * @return boolean true if no problem
313
-    * @access public
314
-    */
315
-    function save($data, $id = null, $group = 'default')
316
-    {
317
-        if ($this->_caching) {
318
-            if ($this->_automaticSerialization) {
319
-                $data = serialize($data);
320
-            }
321
-            if (isset($id)) {
322
-                $this->_setFileName($id, $group);
323
-            }
324
-            if ($this->_memoryCaching) {
325
-                $this->_memoryCacheAdd($this->_file, $data);
326
-                if ($this->_onlyMemoryCaching) {
327
-                    return true;
328
-                }
329
-            }
330
-            if ($this->_writeControl) {
331
-                if (!$this->_writeAndControl($data)) {
332
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
333
-                    return false;
334
-                } else {
335
-                    return true;
336
-                }
337
-            } else {
338
-                return $this->_write($data);
339
-            }
340
-        }
341
-        return false;
342
-    }
343
-
344
-    /**
345
-    * Remove a cache file
346
-    *
347
-    * @param string $id cache id
348
-    * @param string $group name of the cache group
349
-    * @return boolean true if no problem
350
-    * @access public
351
-    */
352
-    function remove($id, $group = 'default')
353
-    {
354
-        $this->_setFileName($id, $group);
355
-        if (!@unlink($this->_file)) {
356
-            $this->raiseError('TCache_Lite : Unable to remove cache !', -3);
357
-            return false;
358
-        }
359
-        return true;
360
-    }
361
-
362
-    /**
363
-    * Clean the cache
364
-    *
365
-    * if no group is specified all cache files will be destroyed
366
-    * else only cache files of the specified group will be destroyed
367
-    *
368
-    * @param string $group name of the cache group
369
-    * @return boolean true if no problem
370
-    * @access public
371
-    */
372
-    function clean($group = false)
373
-    {
374
-        if ($this->_fileNameProtection) {
375
-            $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
376
-        } else {
377
-            $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
378
-        }
379
-        if ($this->_memoryCaching) {
380
-            while (list($key, $value) = each($this->_memoryCaching)) {
381
-                if (strpos($key, $motif, 0)) {
382
-                    unset($this->_memoryCaching[$key]);
383
-                    $this->_memoryCachingCounter =
384
-                    		$this->_memoryCachingCounter - 1;
385
-                }
386
-            }
387
-            if ($this->_onlyMemoryCaching) {
388
-                return true;
389
-            }
390
-        }
391
-        if (!($dh = opendir($this->_cacheDir))) {
392
-            $this->raiseError('TCache_Lite : Unable to open cache directory !');
393
-            return false;
394
-        }
395
-        while ($file = readdir($dh)) {
396
-            if (($file != '.') && ($file != '..')) {
397
-                $file = $this->_cacheDir . $file;
398
-                if (is_file($file)) {
399
-                    if (strpos($file, $motif, 0)) {
400
-                        if (!@unlink($file)) {
401
-             $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
402
-                            return false;
403
-                        }
404
-                    }
405
-                }
406
-            }
407
-        }
408
-        return true;
409
-    }
410
-
411
-	    /**
412
-    * Set a new life time
413
-    *
414
-    * @param int $newLifeTime new life time (in seconds)
415
-    * @access public
416
-    */
417
-    function setLifeTime($newLifeTime)
418
-    {
419
-        $this->_lifeTime = $newLifeTime;
420
-        $this->_refreshTime = time() - $newLifeTime;
421
-    }
422
-
423
-    /**
424
-    *
425
-    * @access public
426
-    */
427
-    function saveMemoryCachingState($id, $group = 'default')
428
-    {
429
-        if ($this->_caching) {
430
-            $array = array(
431
-                'counter' => $this->_memoryCachingCounter,
432
-                'array' => $this->_memoryCachingState
433
-            );
434
-            $data = serialize($array);
435
-            $this->save($data, $id, $group);
436
-        }
437
-    }
438
-
439
-    /**
440
-    *
441
-    * @access public
442
-    */
443
-    function getMemoryCachingState($id, $group = 'default',
444
-    								$doNotTestCacheValidity = false)
445
-    {
446
-        if ($this->_caching) {
447
-            if ($data = $this->get($id, $group, $doNotTestCacheValidity))
448
-            {
449
-                $array = unserialize($data);
450
-                $this->_memoryCachingCounter = $array['counter'];
451
-                $this->_memoryCachingArray = $array['array'];
452
-            }
453
-        }
454
-    }
455
-
456
-    /**
457
-    * Return the cache last modification time
458
-    *
459
-    * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !
460
-    *
461
-    * @return int last modification time
462
-    */
463
-    function lastModified() {
464
-        return filemtime($this->cache->_file);
465
-    }
466
-
467
-    /**
468
-    * Trigger a PEAR error
469
-    *
470
-    * To improve performances, the PEAR.php file is included dynamically.
471
-    * The file is so included only when an error is triggered. So, in most
472
-    * cases, the file isn't included and perfs are much better.
473
-    *
474
-    * @param string $msg error message
475
-    * @param int $code error code
476
-    * @access public
477
-    */
478
-    function raiseError($msg, $code)
479
-    {
480
-       throw new Exception($msg);
481
-    }
482
-
483
-    // --- Private methods ---
484
-
485
-    /**
486
-    *
487
-    * @access private
488
-    */
489
-    function _memoryCacheAdd($id, $data)
490
-    {
491
-        $this->_memoryCachingArray[$this->_file] = $data;
492
-        if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
493
-            list($key, $value) = each($this->_memoryCachingArray);
494
-            unset($this->_memoryCachingArray[$key]);
495
-        } else {
496
-            $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
497
-        }
498
-    }
499
-
500
-    /**
501
-    * Make a file name (with path)
502
-    *
503
-    * @param string $id cache id
504
-    * @param string $group name of the group
505
-    * @access private
506
-    */
507
-    function _setFileName($id, $group)
508
-    {
509
-        if ($this->_fileNameProtection) {
510
-            $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
511
-            						.md5($id));
512
-        } else {
513
-            $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
514
-        }
515
-    }
516
-
517
-    function getCacheFile()
518
-    {
519
-    	return $this->_file;
520
-    }
521
-
522
-    /**
523
-    * Read the cache file and return the content
524
-    *
525
-    * @return string content of the cache file
526
-    * @access private
527
-    */
528
-    function _read()
529
-    {
530
-        $fp = @fopen($this->_file, "rb");
531
-        if ($this->_fileLocking) @flock($fp, LOCK_SH);
532
-        if ($fp) {
533
-        	// because the filesize can be cached by PHP itself...
534
-            clearstatcache();
535
-            $length = @filesize($this->_file);
536
-            if ($this->_readControl) {
537
-                $hashControl = @fread($fp, 32);
538
-                $length = $length - 32;
539
-            }
540
-            $data = @fread($fp, $length);
541
-            if ($this->_fileLocking) @flock($fp, LOCK_UN);
542
-            @fclose($fp);
543
-            if ($this->_readControl) {
544
-                $hashData = $this->_hash($data, $this->_readControlType);
545
-                if ($hashData != $hashControl) {
546
-                    @touch($this->_file, time() - 2*abs($this->_lifeTime));
547
-                    return false;
548
-                }
549
-            }
550
-            return $data;
551
-        }
552
-        $this->raiseError('Cache_Lite : Unable to read cache !', -2);
553
-        return false;
554
-    }
555
-
556
-    /**
557
-    * Write the given data in the cache file
558
-    *
559
-    * @param string $data data to put in cache
560
-    * @return boolean true if ok
561
-    * @access private
562
-    */
563
-    function _write($data)
564
-    {
565
-        $fp = @fopen($this->_file, "wb");
566
-        if ($fp) {
567
-            if ($this->_fileLocking) @flock($fp, LOCK_EX);
568
-            if ($this->_readControl) {
569
-                @fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
570
-            }
571
-            $len = strlen($data);
572
-            @fwrite($fp, $data, $len);
573
-            if ($this->_fileLocking) @flock($fp, LOCK_UN);
574
-            @fclose($fp);
575
-            return true;
576
-        }
577
-        $this->raiseError('Cache_Lite : Unable to write cache !', -1);
578
-        return false;
579
-    }
580
-
581
-    /**
582
-    * Write the given data in the cache file and control it just after to avoid
583
-    * corrupted cache entries
584
-    *
585
-    * @param string $data data to put in cache
586
-    * @return boolean true if the test is ok
587
-    * @access private
588
-    */
589
-    function _writeAndControl($data)
590
-    {
591
-        $this->_write($data);
592
-        $dataRead = $this->_read($data);
593
-        return ($dataRead==$data);
594
-    }
595
-
596
-    /**
597
-    * Make a control key with the string containing datas
598
-    *
599
-    * @param string $data data
600
-    * @param string $controlType type of control 'md5', 'crc32' or 'strlen'
601
-    * @return string control key
602
-    * @access private
603
-    */
604
-    function _hash($data, $controlType)
605
-    {
606
-        switch ($controlType) {
607
-        case 'md5':
608
-            return md5($data);
609
-        case 'crc32':
610
-            return sprintf('% 32d', crc32($data));
611
-        case 'strlen':
612
-            return sprintf('% 32d', strlen($data));
613
-        default:
614
-            $this->raiseError('Unknown controlType ! '.
615
-            '(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
616
-        }
617
-    }
254
+	/**
255
+	 * Test if a cache is available and (if yes) return it
256
+	 *
257
+	 * @param string $id cache id
258
+	 * @param string $group name of the cache group
259
+	 * @param boolean $doNotTestCacheValidity if set to true, the cache
260
+	 * validity won't be tested
261
+	 * @return string data of the cache (or false if no cache available)
262
+	 * @access public
263
+	 */
264
+	function get($id, $group = 'default', $doNotTestCacheValidity = false)
265
+	{
266
+		$this->_id = $id;
267
+		$this->_group = $group;
268
+		$data = false;
269
+		if ($this->_caching) {
270
+			$this->_setFileName($id, $group);
271
+			if ($this->_memoryCaching) {
272
+				if (isset($this->_memoryCachingArray[$this->_file])) {
273
+					if ($this->_automaticSerialization) {
274
+						return unserialize(
275
+									$this->_memoryCachingArray[$this->_file]);
276
+					} else {
277
+						return $this->_memoryCachingArray[$this->_file];
278
+					}
279
+				} else {
280
+					if ($this->_onlyMemoryCaching) {
281
+						return false;
282
+					}
283
+				}
284
+			}
285
+			if ($doNotTestCacheValidity) {
286
+				if (file_exists($this->_file)) {
287
+					$data = $this->_read();
288
+				}
289
+			} else {
290
+				if (@filemtime($this->_file) > $this->_refreshTime) {
291
+					$data = $this->_read();
292
+				}
293
+			}
294
+			if (($data) and ($this->_memoryCaching)) {
295
+				$this->_memoryCacheAdd($this->_file, $data);
296
+			}
297
+			if ($this->_automaticSerialization && is_string($data)) {
298
+				$data = unserialize($data);
299
+			}
300
+			return $data;
301
+		}
302
+		return false;
303
+	}
304
+
305
+	/**
306
+	 * Save some data in a cache file
307
+	 *
308
+	 * @param string $data data to put in cache (can be another type than strings
309
+	 * if automaticSerialization is on)
310
+	 * @param string $id cache id
311
+	 * @param string $group name of the cache group
312
+	 * @return boolean true if no problem
313
+	 * @access public
314
+	 */
315
+	function save($data, $id = null, $group = 'default')
316
+	{
317
+		if ($this->_caching) {
318
+			if ($this->_automaticSerialization) {
319
+				$data = serialize($data);
320
+			}
321
+			if (isset($id)) {
322
+				$this->_setFileName($id, $group);
323
+			}
324
+			if ($this->_memoryCaching) {
325
+				$this->_memoryCacheAdd($this->_file, $data);
326
+				if ($this->_onlyMemoryCaching) {
327
+					return true;
328
+				}
329
+			}
330
+			if ($this->_writeControl) {
331
+				if (!$this->_writeAndControl($data)) {
332
+					@touch($this->_file, time() - 2*abs($this->_lifeTime));
333
+					return false;
334
+				} else {
335
+					return true;
336
+				}
337
+			} else {
338
+				return $this->_write($data);
339
+			}
340
+		}
341
+		return false;
342
+	}
343
+
344
+	/**
345
+	 * Remove a cache file
346
+	 *
347
+	 * @param string $id cache id
348
+	 * @param string $group name of the cache group
349
+	 * @return boolean true if no problem
350
+	 * @access public
351
+	 */
352
+	function remove($id, $group = 'default')
353
+	{
354
+		$this->_setFileName($id, $group);
355
+		if (!@unlink($this->_file)) {
356
+			$this->raiseError('TCache_Lite : Unable to remove cache !', -3);
357
+			return false;
358
+		}
359
+		return true;
360
+	}
361
+
362
+	/**
363
+	 * Clean the cache
364
+	 *
365
+	 * if no group is specified all cache files will be destroyed
366
+	 * else only cache files of the specified group will be destroyed
367
+	 *
368
+	 * @param string $group name of the cache group
369
+	 * @return boolean true if no problem
370
+	 * @access public
371
+	 */
372
+	function clean($group = false)
373
+	{
374
+		if ($this->_fileNameProtection) {
375
+			$motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
376
+		} else {
377
+			$motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
378
+		}
379
+		if ($this->_memoryCaching) {
380
+			while (list($key, $value) = each($this->_memoryCaching)) {
381
+				if (strpos($key, $motif, 0)) {
382
+					unset($this->_memoryCaching[$key]);
383
+					$this->_memoryCachingCounter =
384
+							$this->_memoryCachingCounter - 1;
385
+				}
386
+			}
387
+			if ($this->_onlyMemoryCaching) {
388
+				return true;
389
+			}
390
+		}
391
+		if (!($dh = opendir($this->_cacheDir))) {
392
+			$this->raiseError('TCache_Lite : Unable to open cache directory !');
393
+			return false;
394
+		}
395
+		while ($file = readdir($dh)) {
396
+			if (($file != '.') && ($file != '..')) {
397
+				$file = $this->_cacheDir . $file;
398
+				if (is_file($file)) {
399
+					if (strpos($file, $motif, 0)) {
400
+						if (!@unlink($file)) {
401
+			 $this->raiseError('Cache_Lite : Unable to remove cache !', -3);
402
+							return false;
403
+						}
404
+					}
405
+				}
406
+			}
407
+		}
408
+		return true;
409
+	}
410
+
411
+		/**
412
+		 * Set a new life time
413
+		 *
414
+		 * @param int $newLifeTime new life time (in seconds)
415
+		 * @access public
416
+		 */
417
+	function setLifeTime($newLifeTime)
418
+	{
419
+		$this->_lifeTime = $newLifeTime;
420
+		$this->_refreshTime = time() - $newLifeTime;
421
+	}
422
+
423
+	/**
424
+	 *
425
+	 * @access public
426
+	 */
427
+	function saveMemoryCachingState($id, $group = 'default')
428
+	{
429
+		if ($this->_caching) {
430
+			$array = array(
431
+				'counter' => $this->_memoryCachingCounter,
432
+				'array' => $this->_memoryCachingState
433
+			);
434
+			$data = serialize($array);
435
+			$this->save($data, $id, $group);
436
+		}
437
+	}
438
+
439
+	/**
440
+	 *
441
+	 * @access public
442
+	 */
443
+	function getMemoryCachingState($id, $group = 'default',
444
+									$doNotTestCacheValidity = false)
445
+	{
446
+		if ($this->_caching) {
447
+			if ($data = $this->get($id, $group, $doNotTestCacheValidity))
448
+			{
449
+				$array = unserialize($data);
450
+				$this->_memoryCachingCounter = $array['counter'];
451
+				$this->_memoryCachingArray = $array['array'];
452
+			}
453
+		}
454
+	}
455
+
456
+	/**
457
+	 * Return the cache last modification time
458
+	 *
459
+	 * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY !
460
+	 *
461
+	 * @return int last modification time
462
+	 */
463
+	function lastModified() {
464
+		return filemtime($this->cache->_file);
465
+	}
466
+
467
+	/**
468
+	 * Trigger a PEAR error
469
+	 *
470
+	 * To improve performances, the PEAR.php file is included dynamically.
471
+	 * The file is so included only when an error is triggered. So, in most
472
+	 * cases, the file isn't included and perfs are much better.
473
+	 *
474
+	 * @param string $msg error message
475
+	 * @param int $code error code
476
+	 * @access public
477
+	 */
478
+	function raiseError($msg, $code)
479
+	{
480
+	   throw new Exception($msg);
481
+	}
482
+
483
+	// --- Private methods ---
484
+
485
+	/**
486
+	 *
487
+	 * @access private
488
+	 */
489
+	function _memoryCacheAdd($id, $data)
490
+	{
491
+		$this->_memoryCachingArray[$this->_file] = $data;
492
+		if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
493
+			list($key, $value) = each($this->_memoryCachingArray);
494
+			unset($this->_memoryCachingArray[$key]);
495
+		} else {
496
+			$this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
497
+		}
498
+	}
499
+
500
+	/**
501
+	 * Make a file name (with path)
502
+	 *
503
+	 * @param string $id cache id
504
+	 * @param string $group name of the group
505
+	 * @access private
506
+	 */
507
+	function _setFileName($id, $group)
508
+	{
509
+		if ($this->_fileNameProtection) {
510
+			$this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'
511
+									.md5($id));
512
+		} else {
513
+			$this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id;
514
+		}
515
+	}
516
+
517
+	function getCacheFile()
518
+	{
519
+		return $this->_file;
520
+	}
521
+
522
+	/**
523
+	 * Read the cache file and return the content
524
+	 *
525
+	 * @return string content of the cache file
526
+	 * @access private
527
+	 */
528
+	function _read()
529
+	{
530
+		$fp = @fopen($this->_file, "rb");
531
+		if ($this->_fileLocking) @flock($fp, LOCK_SH);
532
+		if ($fp) {
533
+			// because the filesize can be cached by PHP itself...
534
+			clearstatcache();
535
+			$length = @filesize($this->_file);
536
+			if ($this->_readControl) {
537
+				$hashControl = @fread($fp, 32);
538
+				$length = $length - 32;
539
+			}
540
+			$data = @fread($fp, $length);
541
+			if ($this->_fileLocking) @flock($fp, LOCK_UN);
542
+			@fclose($fp);
543
+			if ($this->_readControl) {
544
+				$hashData = $this->_hash($data, $this->_readControlType);
545
+				if ($hashData != $hashControl) {
546
+					@touch($this->_file, time() - 2*abs($this->_lifeTime));
547
+					return false;
548
+				}
549
+			}
550
+			return $data;
551
+		}
552
+		$this->raiseError('Cache_Lite : Unable to read cache !', -2);
553
+		return false;
554
+	}
555
+
556
+	/**
557
+	 * Write the given data in the cache file
558
+	 *
559
+	 * @param string $data data to put in cache
560
+	 * @return boolean true if ok
561
+	 * @access private
562
+	 */
563
+	function _write($data)
564
+	{
565
+		$fp = @fopen($this->_file, "wb");
566
+		if ($fp) {
567
+			if ($this->_fileLocking) @flock($fp, LOCK_EX);
568
+			if ($this->_readControl) {
569
+				@fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
570
+			}
571
+			$len = strlen($data);
572
+			@fwrite($fp, $data, $len);
573
+			if ($this->_fileLocking) @flock($fp, LOCK_UN);
574
+			@fclose($fp);
575
+			return true;
576
+		}
577
+		$this->raiseError('Cache_Lite : Unable to write cache !', -1);
578
+		return false;
579
+	}
580
+
581
+	/**
582
+	 * Write the given data in the cache file and control it just after to avoid
583
+	 * corrupted cache entries
584
+	 *
585
+	 * @param string $data data to put in cache
586
+	 * @return boolean true if the test is ok
587
+	 * @access private
588
+	 */
589
+	function _writeAndControl($data)
590
+	{
591
+		$this->_write($data);
592
+		$dataRead = $this->_read($data);
593
+		return ($dataRead==$data);
594
+	}
595
+
596
+	/**
597
+	 * Make a control key with the string containing datas
598
+	 *
599
+	 * @param string $data data
600
+	 * @param string $controlType type of control 'md5', 'crc32' or 'strlen'
601
+	 * @return string control key
602
+	 * @access private
603
+	 */
604
+	function _hash($data, $controlType)
605
+	{
606
+		switch ($controlType) {
607
+		case 'md5':
608
+			return md5($data);
609
+		case 'crc32':
610
+			return sprintf('% 32d', crc32($data));
611
+		case 'strlen':
612
+			return sprintf('% 32d', strlen($data));
613
+		default:
614
+			$this->raiseError('Unknown controlType ! '.
615
+			'(available values are only \'md5\', \'crc32\', \'strlen\')', -5);
616
+		}
617
+	}
618 618
 
619 619
 }
620 620
 
Please login to merge, or discard this patch.
framework/I18N/core/MessageSource.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -109,15 +109,15 @@
 block discarded – undo
109 109
 	/**
110 110
 	 * Factory method to instantiate a new MessageSource depending on the
111 111
 	 * source type. The allowed source types are 'XLIFF', 'gettext' and
112
-     * 'Database'. The source parameter depends on the source type. 
113
-     * For 'gettext' and 'XLIFF', 'source' should point to the directory 
114
-     * where the messages are stored. 
115
-     * For 'Database', 'source' must be a valid connection id.
116
-     * If a deprecated 'SQLite' type is used, 'source' must contain
117
-     * a valid DSN.
112
+	 * 'Database'. The source parameter depends on the source type. 
113
+	 * For 'gettext' and 'XLIFF', 'source' should point to the directory 
114
+	 * where the messages are stored. 
115
+	 * For 'Database', 'source' must be a valid connection id.
116
+	 * If a deprecated 'SQLite' type is used, 'source' must contain
117
+	 * a valid DSN.
118 118
 	 *
119
- 	 * Custom message source are possible by supplying the a filename parameter
120
- 	 * in the factory method.
119
+	 * Custom message source are possible by supplying the a filename parameter
120
+	 * in the factory method.
121 121
 	 * 
122 122
 	 * @param string the message source type.
123 123
 	 * @param string the location of the resource or the ConnectionID.
Please login to merge, or discard this patch.
framework/I18N/core/Gettext/PO.php 1 patch
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -51,110 +51,110 @@
 block discarded – undo
51 51
  */
52 52
 class TGettext_PO extends TGettext
53 53
 {
54
-    /**
55
-     * Constructor
56
-     *
57
-     * @access  public
58
-     * @return  object      File_Gettext_PO
59
-     * @param   string      path to GNU PO file
60
-     */
61
-    function __construct($file = '')
62
-    {
63
-        $this->file = $file;
64
-    }
54
+	/**
55
+	 * Constructor
56
+	 *
57
+	 * @access  public
58
+	 * @return  object      File_Gettext_PO
59
+	 * @param   string      path to GNU PO file
60
+	 */
61
+	function __construct($file = '')
62
+	{
63
+		$this->file = $file;
64
+	}
65 65
 
66
-    /**
67
-     * Load PO file
68
-     *
69
-     * @access  public
70
-     * @return  mixed   Returns true on success or PEAR_Error on failure.
71
-     * @param   string  $file
72
-     */
73
-    function load($file = null)
74
-    {
75
-        if (!isset($file)) {
76
-            $file = $this->file;
77
-        }
66
+	/**
67
+	 * Load PO file
68
+	 *
69
+	 * @access  public
70
+	 * @return  mixed   Returns true on success or PEAR_Error on failure.
71
+	 * @param   string  $file
72
+	 */
73
+	function load($file = null)
74
+	{
75
+		if (!isset($file)) {
76
+			$file = $this->file;
77
+		}
78 78
 
79
-        // load file
80
-        if (!$contents = @file($file)) {
81
-            return false;
82
-        }
83
-        $contents = implode('', $contents);
79
+		// load file
80
+		if (!$contents = @file($file)) {
81
+			return false;
82
+		}
83
+		$contents = implode('', $contents);
84 84
 
85
-        // match all msgid/msgstr entries
86
-        $matched = preg_match_all(
87
-            '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' .
88
-            '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/',
89
-            $contents, $matches
90
-        );
91
-        unset($contents);
85
+		// match all msgid/msgstr entries
86
+		$matched = preg_match_all(
87
+			'/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' .
88
+			'(msgstr\s+("([^"]|\\\\")*?"\s*)+)/',
89
+			$contents, $matches
90
+		);
91
+		unset($contents);
92 92
 
93
-        if (!$matched) {
94
-            return false;
95
-        }
93
+		if (!$matched) {
94
+			return false;
95
+		}
96 96
 
97
-        // get all msgids and msgtrs
98
-        for ($i = 0; $i < $matched; $i++) {
99
-            $msgid = preg_replace(
100
-                '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]);
101
-            $msgstr= preg_replace(
102
-                '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]);
103
-            $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr);
104
-        }
97
+		// get all msgids and msgtrs
98
+		for ($i = 0; $i < $matched; $i++) {
99
+			$msgid = preg_replace(
100
+				'/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]);
101
+			$msgstr= preg_replace(
102
+				'/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]);
103
+			$this->strings[parent::prepare($msgid)] = parent::prepare($msgstr);
104
+		}
105 105
 
106
-        // check for meta info
107
-        if (isset($this->strings[''])) {
108
-            $this->meta = parent::meta2array($this->strings['']);
109
-            unset($this->strings['']);
110
-        }
106
+		// check for meta info
107
+		if (isset($this->strings[''])) {
108
+			$this->meta = parent::meta2array($this->strings['']);
109
+			unset($this->strings['']);
110
+		}
111 111
 
112
-        return true;
113
-    }
112
+		return true;
113
+	}
114 114
 
115
-    /**
116
-     * Save PO file
117
-     *
118
-     * @access  public
119
-     * @return  mixed   Returns true on success or PEAR_Error on failure.
120
-     * @param   string  $file
121
-     */
122
-    function save($file = null)
123
-    {
124
-        if (!isset($file)) {
125
-            $file = $this->file;
126
-        }
115
+	/**
116
+	 * Save PO file
117
+	 *
118
+	 * @access  public
119
+	 * @return  mixed   Returns true on success or PEAR_Error on failure.
120
+	 * @param   string  $file
121
+	 */
122
+	function save($file = null)
123
+	{
124
+		if (!isset($file)) {
125
+			$file = $this->file;
126
+		}
127 127
 
128
-        // open PO file
129
-        if (!is_resource($fh = @fopen($file, 'w'))) {
130
-            return false;
131
-        }
128
+		// open PO file
129
+		if (!is_resource($fh = @fopen($file, 'w'))) {
130
+			return false;
131
+		}
132 132
 
133
-        // lock PO file exclusively
134
-        if (!flock($fh, LOCK_EX)) {
135
-            fclose($fh);
136
-            return false;
137
-        }
138
-        // write meta info
139
-        if (count($this->meta)) {
140
-            $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n";
141
-            foreach ($this->meta as $k => $v) {
142
-                $meta .= '"' . $k . ': ' . $v . '\n"' . "\n";
143
-            }
144
-            fwrite($fh, $meta . "\n");
145
-        }
146
-        // write strings
147
-        foreach ($this->strings as $o => $t) {
148
-            fwrite($fh,
149
-                'msgid "'  . parent::prepare($o, true) . '"' . "\n" .
150
-                'msgstr "' . parent::prepare($t, true) . '"' . "\n\n"
151
-            );
152
-        }
133
+		// lock PO file exclusively
134
+		if (!flock($fh, LOCK_EX)) {
135
+			fclose($fh);
136
+			return false;
137
+		}
138
+		// write meta info
139
+		if (count($this->meta)) {
140
+			$meta = 'msgid ""' . "\nmsgstr " . '""' . "\n";
141
+			foreach ($this->meta as $k => $v) {
142
+				$meta .= '"' . $k . ': ' . $v . '\n"' . "\n";
143
+			}
144
+			fwrite($fh, $meta . "\n");
145
+		}
146
+		// write strings
147
+		foreach ($this->strings as $o => $t) {
148
+			fwrite($fh,
149
+				'msgid "'  . parent::prepare($o, true) . '"' . "\n" .
150
+				'msgstr "' . parent::prepare($t, true) . '"' . "\n\n"
151
+			);
152
+		}
153 153
 
154
-        //done
155
-        @flock($fh, LOCK_UN);
156
-        @fclose($fh);
157
-        chmod($file,PRADO_CHMOD);
158
-        return true;
159
-    }
154
+		//done
155
+		@flock($fh, LOCK_UN);
156
+		@fclose($fh);
157
+		chmod($file,PRADO_CHMOD);
158
+		return true;
159
+	}
160 160
 }
Please login to merge, or discard this patch.
framework/I18N/core/Gettext/MO.php 1 patch
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -52,304 +52,304 @@
 block discarded – undo
52 52
  */
53 53
 class TGettext_MO extends TGettext
54 54
 {
55
-    /**
56
-     * file handle
57
-     *
58
-     * @access  private
59
-     * @var     resource
60
-     */
61
-    protected $_handle = null;
62
-
63
-    /**
64
-     * big endianess
65
-     *
66
-     * Whether to write with big endian byte order.
67
-     *
68
-     * @access  public
69
-     * @var     bool
70
-     */
71
-    protected $writeBigEndian = false;
72
-
73
-    /**
74
-     * Constructor
75
-     *
76
-     * @access  public
77
-     * @return  object      File_Gettext_MO
78
-     * @param   string      $file   path to GNU MO file
79
-     */
80
-    function __construct($file = '')
81
-    {
82
-        $this->file = $file;
83
-    }
84
-
85
-    /**
86
-     * _read
87
-     *
88
-     * @access  private
89
-     * @return  mixed
90
-     * @param   int     $bytes
91
-     */
92
-    function _read($bytes = 1)
93
-    {
94
-        if (0 < $bytes = abs($bytes)) {
95
-            return fread($this->_handle, $bytes);
96
-        }
97
-        return null;
98
-    }
99
-
100
-    /**
101
-     * _readInt
102
-     *
103
-     * @access  private
104
-     * @return  int
105
-     * @param   bool    $bigendian
106
-     */
107
-    function _readInt($bigendian = false)
108
-    {
55
+	/**
56
+	 * file handle
57
+	 *
58
+	 * @access  private
59
+	 * @var     resource
60
+	 */
61
+	protected $_handle = null;
62
+
63
+	/**
64
+	 * big endianess
65
+	 *
66
+	 * Whether to write with big endian byte order.
67
+	 *
68
+	 * @access  public
69
+	 * @var     bool
70
+	 */
71
+	protected $writeBigEndian = false;
72
+
73
+	/**
74
+	 * Constructor
75
+	 *
76
+	 * @access  public
77
+	 * @return  object      File_Gettext_MO
78
+	 * @param   string      $file   path to GNU MO file
79
+	 */
80
+	function __construct($file = '')
81
+	{
82
+		$this->file = $file;
83
+	}
84
+
85
+	/**
86
+	 * _read
87
+	 *
88
+	 * @access  private
89
+	 * @return  mixed
90
+	 * @param   int     $bytes
91
+	 */
92
+	function _read($bytes = 1)
93
+	{
94
+		if (0 < $bytes = abs($bytes)) {
95
+			return fread($this->_handle, $bytes);
96
+		}
97
+		return null;
98
+	}
99
+
100
+	/**
101
+	 * _readInt
102
+	 *
103
+	 * @access  private
104
+	 * @return  int
105
+	 * @param   bool    $bigendian
106
+	 */
107
+	function _readInt($bigendian = false)
108
+	{
109 109
 		//unpack returns a reference????
110 110
 		$unpacked = unpack($bigendian ? 'N' : 'V', $this->_read(4));
111
-        return array_shift($unpacked);
112
-    }
113
-
114
-    /**
115
-     * _writeInt
116
-     *
117
-     * @access  private
118
-     * @return  int
119
-     * @param   int     $int
120
-     */
121
-    function _writeInt($int)
122
-    {
123
-        return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int));
124
-    }
125
-
126
-    /**
127
-     * _write
128
-     *
129
-     * @access  private
130
-     * @return  int
131
-     * @param   string  $data
132
-     */
133
-    function _write($data)
134
-    {
135
-        return fwrite($this->_handle, $data);
136
-    }
137
-
138
-    /**
139
-     * _writeStr
140
-     *
141
-     * @access  private
142
-     * @return  int
143
-     * @param   string  $string
144
-     */
145
-    function _writeStr($string)
146
-    {
147
-        return $this->_write($string . "\0");
148
-    }
149
-
150
-    /**
151
-     * _readStr
152
-     *
153
-     * @access  private
154
-     * @return  string
155
-     * @param   array   $params     associative array with offset and length
156
-     *                              of the string
157
-     */
158
-    function _readStr($params)
159
-    {
160
-        fseek($this->_handle, $params['offset']);
161
-        return $this->_read($params['length']);
162
-    }
163
-
164
-    /**
165
-     * Load MO file
166
-     *
167
-     * @access   public
168
-     * @return   mixed   Returns true on success or PEAR_Error on failure.
169
-     * @param    string  $file
170
-     */
171
-    function load($file = null)
172
-    {
173
-        if (!isset($file)) {
174
-            $file = $this->file;
175
-        }
176
-
177
-        // open MO file
178
-        if (!is_resource($this->_handle = @fopen($file, 'rb'))) {
179
-            return false;
180
-        }
181
-        // lock MO file shared
182
-        if (!@flock($this->_handle, LOCK_SH)) {
183
-            @fclose($this->_handle);
184
-            return false;
185
-        }
186
-
187
-        // read (part of) magic number from MO file header and define endianess
111
+		return array_shift($unpacked);
112
+	}
113
+
114
+	/**
115
+	 * _writeInt
116
+	 *
117
+	 * @access  private
118
+	 * @return  int
119
+	 * @param   int     $int
120
+	 */
121
+	function _writeInt($int)
122
+	{
123
+		return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int));
124
+	}
125
+
126
+	/**
127
+	 * _write
128
+	 *
129
+	 * @access  private
130
+	 * @return  int
131
+	 * @param   string  $data
132
+	 */
133
+	function _write($data)
134
+	{
135
+		return fwrite($this->_handle, $data);
136
+	}
137
+
138
+	/**
139
+	 * _writeStr
140
+	 *
141
+	 * @access  private
142
+	 * @return  int
143
+	 * @param   string  $string
144
+	 */
145
+	function _writeStr($string)
146
+	{
147
+		return $this->_write($string . "\0");
148
+	}
149
+
150
+	/**
151
+	 * _readStr
152
+	 *
153
+	 * @access  private
154
+	 * @return  string
155
+	 * @param   array   $params     associative array with offset and length
156
+	 *                              of the string
157
+	 */
158
+	function _readStr($params)
159
+	{
160
+		fseek($this->_handle, $params['offset']);
161
+		return $this->_read($params['length']);
162
+	}
163
+
164
+	/**
165
+	 * Load MO file
166
+	 *
167
+	 * @access   public
168
+	 * @return   mixed   Returns true on success or PEAR_Error on failure.
169
+	 * @param    string  $file
170
+	 */
171
+	function load($file = null)
172
+	{
173
+		if (!isset($file)) {
174
+			$file = $this->file;
175
+		}
176
+
177
+		// open MO file
178
+		if (!is_resource($this->_handle = @fopen($file, 'rb'))) {
179
+			return false;
180
+		}
181
+		// lock MO file shared
182
+		if (!@flock($this->_handle, LOCK_SH)) {
183
+			@fclose($this->_handle);
184
+			return false;
185
+		}
186
+
187
+		// read (part of) magic number from MO file header and define endianess
188 188
 
189 189
 		//unpack returns a reference????
190 190
 		$unpacked = unpack('c', $this->_read(4));
191
-        switch ($magic = array_shift($unpacked))
192
-        {
193
-            case -34:
194
-                $be = false;
195
-            break;
196
-
197
-            case -107:
198
-                $be = true;
199
-            break;
200
-
201
-            default:
202
-                return false;
203
-        }
204
-
205
-        // check file format revision - we currently only support 0
206
-        if (0 !== ($_rev = $this->_readInt($be))) {
207
-            return false;
208
-        }
209
-
210
-        // count of strings in this file
211
-        $count = $this->_readInt($be);
212
-
213
-        // offset of hashing table of the msgids
214
-        $offset_original = $this->_readInt($be);
215
-        // offset of hashing table of the msgstrs
216
-        $offset_translat = $this->_readInt($be);
217
-
218
-        // move to msgid hash table
219
-        fseek($this->_handle, $offset_original);
220
-        // read lengths and offsets of msgids
221
-        $original = array();
222
-        for ($i = 0; $i < $count; $i++) {
223
-            $original[$i] = array(
224
-                'length' => $this->_readInt($be),
225
-                'offset' => $this->_readInt($be)
226
-            );
227
-        }
228
-
229
-        // move to msgstr hash table
230
-        fseek($this->_handle, $offset_translat);
231
-        // read lengths and offsets of msgstrs
232
-        $translat = array();
233
-        for ($i = 0; $i < $count; $i++) {
234
-            $translat[$i] = array(
235
-                'length' => $this->_readInt($be),
236
-                'offset' => $this->_readInt($be)
237
-            );
238
-        }
239
-
240
-        // read all
241
-        for ($i = 0; $i < $count; $i++) {
242
-            $this->strings[$this->_readStr($original[$i])] =
243
-                $this->_readStr($translat[$i]);
244
-        }
245
-
246
-        // done
247
-        @flock($this->_handle, LOCK_UN);
248
-        @fclose($this->_handle);
249
-        $this->_handle = null;
250
-
251
-        // check for meta info
252
-        if (isset($this->strings[''])) {
253
-            $this->meta = parent::meta2array($this->strings['']);
254
-            unset($this->strings['']);
255
-        }
256
-
257
-        return true;
258
-    }
259
-
260
-    /**
261
-     * Save MO file
262
-     *
263
-     * @access  public
264
-     * @return  mixed   Returns true on success or PEAR_Error on failure.
265
-     * @param   string  $file
266
-     */
267
-    function save($file = null)
268
-    {
269
-        if (!isset($file)) {
270
-            $file = $this->file;
271
-        }
272
-
273
-        // open MO file
274
-        if (!is_resource($this->_handle = @fopen($file, 'wb'))) {
275
-            return false;
276
-        }
277
-        // lock MO file exclusively
278
-        if (!@flock($this->_handle, LOCK_EX)) {
279
-            @fclose($this->_handle);
280
-            return false;
281
-        }
282
-
283
-        // write magic number
284
-        if ($this->writeBigEndian) {
285
-            $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde));
286
-        } else {
287
-            $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95));
288
-        }
289
-
290
-        // write file format revision
291
-        $this->_writeInt(0);
292
-
293
-        $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0));
294
-        // write count of strings
295
-        $this->_writeInt($count);
296
-
297
-        $offset = 28;
298
-        // write offset of orig. strings hash table
299
-        $this->_writeInt($offset);
300
-
301
-        $offset += ($count * 8);
302
-        // write offset transl. strings hash table
303
-        $this->_writeInt($offset);
304
-
305
-        // write size of hash table (we currently ommit the hash table)
306
-        $this->_writeInt(0);
307
-
308
-        $offset += ($count * 8);
309
-        // write offset of hash table
310
-        $this->_writeInt($offset);
311
-
312
-        // unshift meta info
313
-        if ($this->meta) {
314
-            $meta = '';
315
-            foreach ($this->meta as $key => $val) {
316
-                $meta .= $key . ': ' . $val . "\n";
317
-            }
318
-            $strings = array('' => $meta) + $this->strings;
319
-        } else {
320
-            $strings = $this->strings;
321
-        }
322
-
323
-        // write offsets for original strings
324
-        foreach (array_keys($strings) as $o) {
325
-            $len = strlen($o);
326
-            $this->_writeInt($len);
327
-            $this->_writeInt($offset);
328
-            $offset += $len + 1;
329
-        }
330
-
331
-        // write offsets for translated strings
332
-        foreach ($strings as $t) {
333
-            $len = strlen($t);
334
-            $this->_writeInt($len);
335
-            $this->_writeInt($offset);
336
-            $offset += $len + 1;
337
-        }
338
-
339
-        // write original strings
340
-        foreach (array_keys($strings) as $o) {
341
-            $this->_writeStr($o);
342
-        }
343
-
344
-        // write translated strings
345
-        foreach ($strings as $t) {
346
-            $this->_writeStr($t);
347
-        }
348
-
349
-        // done
350
-        @flock($this->_handle, LOCK_UN);
351
-        @fclose($this->_handle);
352
-        chmod($file,PRADO_CHMOD);
353
-        return true;
354
-    }
191
+		switch ($magic = array_shift($unpacked))
192
+		{
193
+			case -34:
194
+				$be = false;
195
+			break;
196
+
197
+			case -107:
198
+				$be = true;
199
+			break;
200
+
201
+			default:
202
+				return false;
203
+		}
204
+
205
+		// check file format revision - we currently only support 0
206
+		if (0 !== ($_rev = $this->_readInt($be))) {
207
+			return false;
208
+		}
209
+
210
+		// count of strings in this file
211
+		$count = $this->_readInt($be);
212
+
213
+		// offset of hashing table of the msgids
214
+		$offset_original = $this->_readInt($be);
215
+		// offset of hashing table of the msgstrs
216
+		$offset_translat = $this->_readInt($be);
217
+
218
+		// move to msgid hash table
219
+		fseek($this->_handle, $offset_original);
220
+		// read lengths and offsets of msgids
221
+		$original = array();
222
+		for ($i = 0; $i < $count; $i++) {
223
+			$original[$i] = array(
224
+				'length' => $this->_readInt($be),
225
+				'offset' => $this->_readInt($be)
226
+			);
227
+		}
228
+
229
+		// move to msgstr hash table
230
+		fseek($this->_handle, $offset_translat);
231
+		// read lengths and offsets of msgstrs
232
+		$translat = array();
233
+		for ($i = 0; $i < $count; $i++) {
234
+			$translat[$i] = array(
235
+				'length' => $this->_readInt($be),
236
+				'offset' => $this->_readInt($be)
237
+			);
238
+		}
239
+
240
+		// read all
241
+		for ($i = 0; $i < $count; $i++) {
242
+			$this->strings[$this->_readStr($original[$i])] =
243
+				$this->_readStr($translat[$i]);
244
+		}
245
+
246
+		// done
247
+		@flock($this->_handle, LOCK_UN);
248
+		@fclose($this->_handle);
249
+		$this->_handle = null;
250
+
251
+		// check for meta info
252
+		if (isset($this->strings[''])) {
253
+			$this->meta = parent::meta2array($this->strings['']);
254
+			unset($this->strings['']);
255
+		}
256
+
257
+		return true;
258
+	}
259
+
260
+	/**
261
+	 * Save MO file
262
+	 *
263
+	 * @access  public
264
+	 * @return  mixed   Returns true on success or PEAR_Error on failure.
265
+	 * @param   string  $file
266
+	 */
267
+	function save($file = null)
268
+	{
269
+		if (!isset($file)) {
270
+			$file = $this->file;
271
+		}
272
+
273
+		// open MO file
274
+		if (!is_resource($this->_handle = @fopen($file, 'wb'))) {
275
+			return false;
276
+		}
277
+		// lock MO file exclusively
278
+		if (!@flock($this->_handle, LOCK_EX)) {
279
+			@fclose($this->_handle);
280
+			return false;
281
+		}
282
+
283
+		// write magic number
284
+		if ($this->writeBigEndian) {
285
+			$this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde));
286
+		} else {
287
+			$this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95));
288
+		}
289
+
290
+		// write file format revision
291
+		$this->_writeInt(0);
292
+
293
+		$count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0));
294
+		// write count of strings
295
+		$this->_writeInt($count);
296
+
297
+		$offset = 28;
298
+		// write offset of orig. strings hash table
299
+		$this->_writeInt($offset);
300
+
301
+		$offset += ($count * 8);
302
+		// write offset transl. strings hash table
303
+		$this->_writeInt($offset);
304
+
305
+		// write size of hash table (we currently ommit the hash table)
306
+		$this->_writeInt(0);
307
+
308
+		$offset += ($count * 8);
309
+		// write offset of hash table
310
+		$this->_writeInt($offset);
311
+
312
+		// unshift meta info
313
+		if ($this->meta) {
314
+			$meta = '';
315
+			foreach ($this->meta as $key => $val) {
316
+				$meta .= $key . ': ' . $val . "\n";
317
+			}
318
+			$strings = array('' => $meta) + $this->strings;
319
+		} else {
320
+			$strings = $this->strings;
321
+		}
322
+
323
+		// write offsets for original strings
324
+		foreach (array_keys($strings) as $o) {
325
+			$len = strlen($o);
326
+			$this->_writeInt($len);
327
+			$this->_writeInt($offset);
328
+			$offset += $len + 1;
329
+		}
330
+
331
+		// write offsets for translated strings
332
+		foreach ($strings as $t) {
333
+			$len = strlen($t);
334
+			$this->_writeInt($len);
335
+			$this->_writeInt($offset);
336
+			$offset += $len + 1;
337
+		}
338
+
339
+		// write original strings
340
+		foreach (array_keys($strings) as $o) {
341
+			$this->_writeStr($o);
342
+		}
343
+
344
+		// write translated strings
345
+		foreach ($strings as $t) {
346
+			$this->_writeStr($t);
347
+		}
348
+
349
+		// done
350
+		@flock($this->_handle, LOCK_UN);
351
+		@fclose($this->_handle);
352
+		chmod($file,PRADO_CHMOD);
353
+		return true;
354
+	}
355 355
 }
Please login to merge, or discard this patch.