commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / packages / PHP / Beautifier / Filter / phpBB.filter.php
1 <?php
2 /**
3 * Filter the code to make it compatible with phpBB Coding Standards
4 *
5 * PHP version 5
6 *
7 * LICENSE: This source file is subject to version 3.0 of the PHP license
8 * that is available through the world-wide-web at the following URI:
9 * http://www.php.net/license/3_0.txt. If you did not receive a copy of
10 * the PHP License and are unable to obtain it through the web, please
11 * send a note to license@php.net so we can mail you a copy immediately.
12 * @category PHP
13 * @package PHP_Beautifier
14 * @subpackage Filter
15 * @author Jim Wigginton <terrafrost@php.net>
16 * @copyright 2008 Jim Wigginton
17 * @link http://pear.php.net/package/PHP_Beautifier
18 * @license http://www.gnu.org/licenses/lgpl.html LGPL
19 * @version CVS: $Id:$
20 */
21 /**
22 * Require PEAR_Config
23 */
24 require_once ('PEAR/Config.php');
25 /**
26 * Filter the code to make it compatible with phpBB Coding Standards
27 *
28 * Among other differences from the PEAR Coding Standards, the phpBB coding standards use BSD style indenting.
29 *
30 * @category PHP
31 * @package PHP_Beautifier
32 * @subpackage Filter
33 * @author Jim Wigginton <terrafrost@php.net>
34 * @copyright 2008 Jim Wigginton
35 * @link http://pear.php.net/package/PHP_Beautifier
36 * @license http://www.gnu.org/licenses/lgpl.html LGPL
37 * @version Release: 0.0.1
38 */
39 class PHP_Beautifier_Filter_phpBB extends PHP_Beautifier_Filter
40 {
41 protected $sDescription = 'Filter the code to make it compatible with phpBB Coding Standards';
42 private $iNestedIfs = 0;
43 public function __construct(PHP_Beautifier $oBeaut, $aSettings = array())
44 {
45 parent::__construct($oBeaut, $aSettings);
46 $oBeaut->setIndentChar("\t");
47 $oBeaut->setIndentNumber(1);
48 $oBeaut->setNewLine(PHP_EOL);
49 }
50 function t_open_brace($sTag)
51 {
52 $this->oBeaut->addNewLineIndent();
53 $this->oBeaut->add($sTag);
54 $this->oBeaut->incIndent();
55 $this->oBeaut->addNewLineIndent();
56 }
57 function t_close_brace($sTag)
58 {
59 if ($this->oBeaut->getMode('string_index') or $this->oBeaut->getMode('double_quote')) {
60 $this->oBeaut->add($sTag);
61 } else {
62 $this->oBeaut->removeWhitespace();
63 $this->oBeaut->decIndent();
64 $this->oBeaut->addNewLineIndent();
65 $this->oBeaut->add($sTag);
66 $this->oBeaut->addNewLineIndent();
67 }
68 }
69 function t_else($sTag)
70 {
71 $this->oBeaut->add($sTag);
72 if (!$this->oBeaut->isNextTokenContent('{')) {
73 $this->oBeaut->addNewLineIndent();
74 $this->oBeaut->add('{');
75 $this->oBeaut->incIndent();
76 $this->oBeaut->addNewLineIndent();
77 $this->iNestedIfs++;
78 }
79 }
80 function t_semi_colon($sTag)
81 {
82 $this->oBeaut->removeWhitespace();
83 $this->oBeaut->add($sTag);
84 if ($this->oBeaut->getControlParenthesis() != T_FOR) {
85 if ($this->iNestedIfs > 0) {
86 $this->oBeaut->decIndent();
87 $this->oBeaut->addNewLineIndent();
88 $this->oBeaut->add('}');
89 $this->iNestedIfs--;
90 }
91 $this->oBeaut->addNewLineIndent();
92 }
93 }
94 function preProcess()
95 {
96 $this->iNestedIfs = 0;
97 }
98 }
99 ?>