Issues (292)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

lib/Dwoo/Plugins/Blocks/PluginSection.php (11 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Copyright (c) 2013-2016
4
 *
5
 * @category  Library
6
 * @package   Dwoo\Plugins\Blocks
7
 * @author    Jordi Boggiano <[email protected]>
8
 * @author    David Sanchez <[email protected]>
9
 * @copyright 2008-2013 Jordi Boggiano
10
 * @copyright 2013-2016 David Sanchez
11
 * @license   http://dwoo.org/LICENSE Modified BSD License
12
 * @version   1.3.0
13
 * @date      2016-09-19
14
 * @link      http://dwoo.org/
15
 */
16
17
namespace Dwoo\Plugins\Blocks;
18
19
use Dwoo\Compiler;
20
use Dwoo\IElseable;
21
use Dwoo\Block\Plugin as BlockPlugin;
22
use Dwoo\ICompilable\Block as ICompilableBlock;
23
24
/**
25
 * Compatibility plugin for smarty templates, do not use otherwise, this is deprecated.
26
 * This software is provided 'as-is', without any express or implied warranty.
27
 * In no event will the authors be held liable for any damages arising from the use of this software.
28
 */
29
class PluginSection extends BlockPlugin implements ICompilableBlock, IElseable
30
{
31
    public static $cnt = 0;
32
33
    /**
34
     * @param      $name
35
     * @param      $loop
36
     * @param null $start
37
     * @param null $step
38
     * @param null $max
39
     * @param bool $show
40
     */
41
    public function init($name, $loop, $start = null, $step = null, $max = null, $show = true)
0 ignored issues
show
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $loop is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $start is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $step is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $max is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $show is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
    }
44
45
    /**
46
     * @param Compiler $compiler
47
     * @param array    $params
48
     * @param string   $prepend
49
     * @param string   $append
50
     * @param string   $type
51
     *
52
     * @return string
53
     */
54
    public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
55
    {
56
        return '';
57
    }
58
59
    /**
60
     * @param Compiler $compiler
61
     * @param array    $params
62
     * @param string   $prepend
63
     * @param string   $append
64
     * @param string   $content
65
     *
66
     * @return string
67
     */
68
    public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
69
    {
70
        $output = Compiler::PHP_OPEN;
71
        $params = $compiler->getCompiledParams($params);
72
73
        // assigns params
74
        $loop  = $params['loop'];
75
        $start = $params['start'];
76
        $max   = $params['max'];
77
        $name  = $params['name'];
78
        $step  = $params['step'];
79
        $show  = $params['show'];
80
81
        // gets unique id
82
        $cnt = self::$cnt ++;
83
84
        $output .= '$this->globals[\'section\'][' . $name . '] = array();' . "\n" . '$_section' . $cnt . ' =& $this->globals[\'section\'][' . $name . '];' . "\n";
85
86 View Code Duplication
        if ($loop !== 'null') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
            $output .= '$_section' . $cnt . '[\'loop\'] = is_array($tmp = ' . $loop . ') ? count($tmp) : max(0, (int) $tmp);' . "\n";
88
        } else {
89
            $output .= '$_section' . $cnt . '[\'loop\'] = 1;' . "\n";
90
        }
91
92 View Code Duplication
        if ($show !== 'null') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
            $output .= '$_section' . $cnt . '[\'show\'] = ' . $show . ";\n";
94
        } else {
95
            $output .= '$_section' . $cnt . '[\'show\'] = true;' . "\n";
96
        }
97
98 View Code Duplication
        if ($name !== 'null') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
            $output .= '$_section' . $cnt . '[\'name\'] = ' . $name . ";\n";
100
        } else {
101
            $output .= '$_section' . $cnt . '[\'name\'] = true;' . "\n";
102
        }
103
104
        if ($max !== 'null') {
105
            $output .= '$_section' . $cnt . '[\'max\'] = (int)' . $max . ";\n" . 'if($_section' . $cnt . '[\'max\'] < 0) { $_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\']; }' . "\n";
106
        } else {
107
            $output .= '$_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
108
        }
109
110 View Code Duplication
        if ($step !== 'null') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
            $output .= '$_section' . $cnt . '[\'step\'] = (int)' . $step . ' == 0 ? 1 : (int) ' . $step . ";\n";
112
        } else {
113
            $output .= '$_section' . $cnt . '[\'step\'] = 1;' . "\n";
114
        }
115
116
        if ($start !== 'null') {
117
            $output .= '$_section' . $cnt . '[\'start\'] = (int)' . $start . ";\n";
118
        } else {
119
            $output .= '$_section' . $cnt . '[\'start\'] = $_section' . $cnt . '[\'step\'] > 0 ? 0 : $_section' . $cnt . '[\'loop\'] - 1;' . "\n" . 'if ($_section' . $cnt . '[\'start\'] < 0) { $_section' . $cnt . '[\'start\'] = max($_section' . $cnt . '[\'step\'] > 0 ? 0 : -1, $_section' . $cnt . '[\'loop\'] + $_section' . $cnt . '[\'start\']); } ' . "\n" . 'else { $_section' . $cnt . '[\'start\'] = min($_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] : $_section' . $cnt . '[\'loop\'] -1); }' . "\n";
120
        }
121
122
        /*		if ($usesAny) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
123
                    $output .= "\n".'$this->globals["section"]['.$name.'] = array'."\n(";
124
                    if ($usesIndex) $output .="\n\t".'"index"		=> 0,';
125
                    if ($usesIteration) $output .="\n\t".'"iteration"		=> 1,';
126
                    if ($usesFirst) $output .="\n\t".'"first"		=> null,';
127
                    if ($usesLast) $output .="\n\t".'"last"		=> null,';
128
                    if ($usesShow) $output .="\n\t".'"show"		=> ($this->isArray($_for'.$cnt.'_from, true)) || (is_numeric($_for'.$cnt.'_from) && $_for'.$cnt.'_from != $_for'.$cnt.'_to),';
129
                    if ($usesTotal) $output .="\n\t".'"total"		=> $this->isArray($_for'.$cnt.'_from) ? $this->count($_for'.$cnt.'_from) - $_for'.$cnt.'_skip : (is_numeric($_for'.$cnt.'_from) ? abs(($_for'.$cnt.'_to + 1 - $_for'.$cnt.'_from)/$_for'.$cnt.'_step) : 0),';
130
                    $out.="\n);\n".'$_section'.$cnt.'[\'glob\'] =& $this->globals["section"]['.$name.'];'."\n\n";
131
                }
132
        */
133
134
        $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
135
        if ($start === 'null' && $step === 'null' && $max === 'null') {
136
            $output .= '	$_section' . $cnt . '[\'total\'] = $_section' . $cnt . '[\'loop\'];' . "\n";
137
        } else {
138
            $output .= '	$_section' . $cnt . '[\'total\'] = min(ceil(($_section' . $cnt . '[\'step\'] > 0 ? $_section' . $cnt . '[\'loop\'] - $_section' . $cnt . '[\'start\'] : $_section' . $cnt . '[\'start\'] + 1) / abs($_section' . $cnt . '[\'step\'])), $_section' . $cnt . '[\'max\']);' . "\n";
139
        }
140
        $output .= '	if ($_section' . $cnt . '[\'total\'] == 0) {' . "\n" . '		$_section' . $cnt . '[\'show\'] = false;' . "\n" . '	}' . "\n" . '} else {' . "\n" . '	$_section' . $cnt . '[\'total\'] = 0;' . "\n}\n";
141
        $output .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n";
142
        $output .= "\t" . 'for ($this->scope[' . $name . '] = $_section' . $cnt . '[\'start\'], $_section' . $cnt . '[\'iteration\'] = 1; ' . '$_section' . $cnt . '[\'iteration\'] <= $_section' . $cnt . '[\'total\']; ' . '$this->scope[' . $name . '] += $_section' . $cnt . '[\'step\'], $_section' . $cnt . '[\'iteration\']++) {' . "\n";
143
        $output .= "\t\t" . '$_section' . $cnt . '[\'rownum\'] = $_section' . $cnt . '[\'iteration\'];' . "\n";
144
        $output .= "\t\t" . '$_section' . $cnt . '[\'index_prev\'] = $this->scope[' . $name . '] - $_section' . $cnt . '[\'step\'];' . "\n";
145
        $output .= "\t\t" . '$_section' . $cnt . '[\'index_next\'] = $this->scope[' . $name . '] + $_section' . $cnt . '[\'step\'];' . "\n";
146
        $output .= "\t\t" . '$_section' . $cnt . '[\'first\']      = ($_section' . $cnt . '[\'iteration\'] == 1);' . "\n";
147
        $output .= "\t\t" . '$_section' . $cnt . '[\'last\']       = ($_section' . $cnt . '[\'iteration\'] == $_section' . $cnt . '[\'total\']);' . "\n";
148
149
        $output .= Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN;
150
151
        $output .= "\n\t}\n} " . Compiler::PHP_CLOSE;
152
153
        if (isset($params['hasElse'])) {
154
            $output .= $params['hasElse'];
155
        }
156
157
        return $output;
158
    }
159
}
160