GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#2022)
by
unknown
07:50
created

documentModel::getDocumentPage()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 50
Code Lines 24

Duplication

Lines 21
Ratio 42 %

Importance

Changes 0
Metric Value
cc 7
eloc 24
nc 6
nop 2
dl 21
loc 50
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * documentModel class
5
 * model class of the module document
6
 *
7
 * @author NAVER ([email protected])
8
 * @package /modules/document
9
 * @version 0.1
10
 */
11
class documentModel extends document
12
{
13
	/**
14
	 * Initialization
15
	 * @return void
16
	 */
17
	function init()
18
	{
19
	}
20
21
	/**
22
	 * document checked the permissions on the session values
23
	 * @param int $document_srl
24
	 * @return void
25
	 */
26
	function isGranted($document_srl)
27
	{
28
		return $_SESSION['own_document'][$document_srl];
29
	}
30
31
	/**
32
	 * Return document extra information from database
33
	 * @param array $documentSrls
34
	 * @return object
35
	 */
36
	function getDocumentExtraVarsFromDB($documentSrls)
37
	{
38
		if(!is_array($documentSrls) || count($documentSrls) == 0)
39
		{
40
			return new Object(-1, 'msg_invalid_request');
41
		}
42
43
		$args = new stdClass();
44
		$args->document_srl = $documentSrls;
45
		$output = executeQueryArray('document.getDocumentExtraVars', $args);
46
		return $output;
47
	}
48
49
	/**
50
	 * Extra variables for each article will not be processed bulk select and apply the macro city
51
	 * @return void
52
	 */
53
	function setToAllDocumentExtraVars()
54
	{
55
		static $checked_documents = array();
56
		$_document_list = &$GLOBALS['XE_DOCUMENT_LIST'];
57
58
		// XE XE_DOCUMENT_LIST all documents that the object referred to the global variable settings
59
		if(count($_document_list) <= 0) return;
60
61
		// Find all called the document object variable has been set extension
62
		$document_srls = array();
63
		foreach($_document_list as $key => $val)
64
		{
65
			if(!$val->document_srl || $checked_documents[$val->document_srl]) continue;
66
			$checked_documents[$val->document_srl] = true;
67
			$document_srls[] = $val->document_srl;
68
		}
69
		// If the document number, return detected
70
		if(!count($document_srls)) return;
71
		// Expand variables mijijeongdoen article about a current visitor to the extension of the language code, the search variable
72
		//$obj->document_srl = implode(',',$document_srls);
73
		$output = $this->getDocumentExtraVarsFromDB($document_srls);
74
		if($output->toBool() && $output->data)
75
		{
76
			foreach($output->data as $key => $val)
77
			{
78
				if(!isset($val->value)) continue;
79
				if(!$extra_vars[$val->module_srl][$val->document_srl][$val->var_idx][0]) $extra_vars[$val->module_srl][$val->document_srl][$val->var_idx][0] = trim($val->value);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$extra_vars was never initialized. Although not strictly required by PHP, it is generally a good practice to add $extra_vars = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The variable $extra_vars does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
80
				$extra_vars[$val->document_srl][$val->var_idx][$val->lang_code] = trim($val->value);
81
			}
82
		}
83
84
		$user_lang_code = Context::getLangType();
85
		for($i=0,$c=count($document_srls);$i<$c;$i++)
86
		{
87
			$document_srl = $document_srls[$i];
88
			unset($vars);
89
90
			if(!$_document_list[$document_srl] || !is_object($_document_list[$document_srl]) || !$_document_list[$document_srl]->isExists()) continue;
91
			$module_srl = $_document_list[$document_srl]->get('module_srl');
92
			$extra_keys = $this->getExtraKeys($module_srl);
93
			$vars = $extra_vars[$document_srl];
94
			$document_lang_code = $_document_list[$document_srl]->get('lang_code');
95
			// Expand the variable processing
96
			if(count($extra_keys))
97
			{
98
				foreach($extra_keys as $idx => $key)
99
				{
100
					$extra_keys[$idx] = clone($key);
101
					$val = $vars[$idx];
102
					if(isset($val[$user_lang_code])) $v = $val[$user_lang_code];
103
					else if(isset($val[$document_lang_code])) $v = $val[$document_lang_code];
104
					else if(isset($val[0])) $v = $val[0];
105
					else $v = null;
106
					$extra_keys[$idx]->value = $v;
107
				}
108
			}
109
110
			unset($evars);
111
			$evars = new ExtraVar($module_srl);
112
			$evars->setExtraVarKeys($extra_keys);
113
			// Title Processing
114
			if($vars[-1][$user_lang_code]) $_document_list[$document_srl]->add('title',$vars[-1][$user_lang_code]);
115
			// Information processing
116
			if($vars[-2][$user_lang_code]) $_document_list[$document_srl]->add('content',$vars[-2][$user_lang_code]);
117
118
			if($vars[-1][$user_lang_code] || $vars[-2][$user_lang_code])
119
			{
120
				unset($checked_documents[$document_srl]);
121
			}
122
123
			$GLOBALS['XE_EXTRA_VARS'][$document_srl] = $evars->getExtraVars();
124
		}
125
	}
126
127
	/**
128
	 * Import Document
129
	 * @param int $document_srl
130
	 * @param bool $is_admin
131
	 * @param bool $load_extra_vars
132
	 * @param array $columnList
133
	 * @return documentItem
134
	 */
135
	function getDocument($document_srl=0, $is_admin = false, $load_extra_vars=true, $columnList = array())
136
	{
137
		if(!$document_srl) return new documentItem();
138
139
		if(!$GLOBALS['XE_DOCUMENT_LIST'][$document_srl])
140
		{
141
			$oDocument = new documentItem($document_srl, $load_extra_vars, $columnList);
142
			$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
143
			if($load_extra_vars) $this->setToAllDocumentExtraVars();
144
		}
145
		if($is_admin) $GLOBALS['XE_DOCUMENT_LIST'][$document_srl]->setGrant();
146
147
		return $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
148
	}
149
150
	/**
151
	 * Bringing multiple documents (or paging)
152
	 * @param array|string $document_srls
153
	 * @param bool $is_admin
154
	 * @param bool $load_extra_vars
155
	 * @param array $columnList
156
	 * @return array value type is documentItem
157
	 */
158
	function getDocuments($document_srls, $is_admin = false, $load_extra_vars=true, $columnList = array())
159
	{
160
		if(is_array($document_srls))
161
		{
162
			$list_count = count($document_srls);
163
			$document_srls = implode(',',$document_srls);
164
		}
165
		else
166
		{
167
			$list_count = 1;
168
		}
169
		$args = new stdClass();
170
		$args->document_srls = $document_srls;
171
		$args->list_count = $list_count;
172
		$args->order_type = 'asc';
173
174
		$output = executeQuery('document.getDocuments', $args, $columnList);
175
		$document_list = $output->data;
176
		if(!$document_list) return;
177
		if(!is_array($document_list)) $document_list = array($document_list);
178
179
		$document_count = count($document_list);
0 ignored issues
show
Unused Code introduced by
$document_count is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
180 View Code Duplication
		foreach($document_list as $key => $attribute)
181
		{
182
			$document_srl = $attribute->document_srl;
183
			if(!$document_srl) continue;
184
185
			if(!$GLOBALS['XE_DOCUMENT_LIST'][$document_srl])
186
			{
187
				$oDocument = null;
0 ignored issues
show
Unused Code introduced by
$oDocument is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
188
				$oDocument = new documentItem();
189
				$oDocument->setAttribute($attribute, false);
190
				if($is_admin) $oDocument->setGrant();
191
				$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
192
			}
193
194
			$result[$attribute->document_srl] = $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
195
		}
196
197
		if($load_extra_vars) $this->setToAllDocumentExtraVars();
198
199
		$output = null;
200
		if(count($result))
201
		{
202
			foreach($result as $document_srl => $val)
0 ignored issues
show
Bug introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
203
			{
204
				$output[$document_srl] = $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
205
			}
206
		}
207
208
		return $output;
209
	}
210
211
	/**
212
	 * Module_srl value, bringing the list of documents
213
	 * @param object $obj
214
	 * @param bool $except_notice
215
	 * @param bool $load_extra_vars
216
	 * @param array $columnList
217
	 * @return Object
218
	 */
219
	function getDocumentList($obj, $except_notice = false, $load_extra_vars=true, $columnList = array())
220
	{
221
		$sort_check = $this->_setSortIndex($obj, $load_extra_vars);
222
		$obj->sort_index = $sort_check->sort_index;
223
		$obj->isExtraVars = $sort_check->isExtraVars;
224
		unset($obj->use_alternate_output);
225
		$obj->columnList = $columnList;
226
		// Call trigger (before)
227
		// This trigger can be used to set an alternative output using a different search method
228
		$output = ModuleHandler::triggerCall('document.getDocumentList', 'before', $obj);
229
		if($output instanceof Object && !$output->toBool())
230
		{
231
			return $output;
232
		}
233
234
		// If an alternate output is set, use it instead of running the default queries
235
		$use_alternate_output = (isset($obj->use_alternate_output) && $obj->use_alternate_output instanceof Object);
236
		if (!$use_alternate_output)
237
		{
238
			$this->_setSearchOption($obj, $args, $query_id, $use_division);
239
		}
240
241
		if ($use_alternate_output)
242
		{
243
			$output = $obj->use_alternate_output;
244
			unset($obj->use_alternate_output);
245
		}
246
		elseif ($sort_check->isExtraVars && substr_count($obj->search_target,'extra_vars'))
247
		{
248
			$query_id = 'document.getDocumentListWithinExtraVarsExtraSort';
249
			$args->sort_index = str_replace('documents.','',$args->sort_index);
0 ignored issues
show
Bug introduced by
The variable $args does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
250
			$output = executeQueryArray($query_id, $args);
251
		}
252
		elseif ($sort_check->isExtraVars)
253
		{
254
			$output = executeQueryArray($query_id, $args);
0 ignored issues
show
Bug introduced by
The variable $query_id does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
255
		}
256
		else
257
		{
258
			// document.getDocumentList query execution
259
			// Query_id if you have a group by clause getDocumentListWithinTag getDocumentListWithinComment or used again to perform the query because
260
			$groupByQuery = array('document.getDocumentListWithinComment' => 1, 'document.getDocumentListWithinTag' => 1, 'document.getDocumentListWithinExtraVars' => 1);
261
			if(isset($groupByQuery[$query_id]))
262
			{
263
				$group_args = clone($args);
264
				$group_args->sort_index = 'documents.'.$args->sort_index;
265
				$output = executeQueryArray($query_id, $group_args);
266
				if(!$output->toBool()||!count($output->data)) return $output;
267
268
				foreach($output->data as $key => $val)
269
				{
270
					if($val->document_srl) $target_srls[] = $val->document_srl;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$target_srls was never initialized. Although not strictly required by PHP, it is generally a good practice to add $target_srls = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
271
				}
272
273
				$page_navigation = $output->page_navigation;
274
				$keys = array_keys($output->data);
275
				$virtual_number = $keys[0];
276
277
				$target_args = new stdClass();
278
				$target_args->document_srls = implode(',',$target_srls);
0 ignored issues
show
Bug introduced by
The variable $target_srls does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
279
				$target_args->list_order = $args->sort_index;
280
				$target_args->order_type = $args->order_type;
281
				$target_args->list_count = $args->list_count;
282
				$target_args->page = 1;
283
				$output = executeQueryArray('document.getDocuments', $target_args);
284
				$output->page_navigation = $page_navigation;
285
				$output->total_count = $page_navigation->total_count;
286
				$output->total_page = $page_navigation->total_page;
287
				$output->page = $page_navigation->cur_page;
288
			}
289
			else
290
			{
291
				$output = executeQueryArray($query_id, $args, $columnList);
292
			}
293
		}
294
		// Return if no result or an error occurs
295
		if(!$output->toBool()||!count($output->data)) return $output;
296
		$idx = 0;
0 ignored issues
show
Unused Code introduced by
$idx is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
297
		$data = $output->data;
298
		unset($output->data);
299
300
		if(!isset($virtual_number))
301
		{
302
			$keys = array_keys($data);
303
			$virtual_number = $keys[0];
304
		}
305
306
		if($except_notice)
307
		{
308
			foreach($data as $key => $attribute)
309
			{
310
				if($attribute->is_notice == 'Y') $virtual_number --;
311
			}
312
		}
313
314
		foreach($data as $key => $attribute)
315
		{
316
			if($except_notice && $attribute->is_notice == 'Y') continue;
317
			$document_srl = $attribute->document_srl;
318
			if(!$GLOBALS['XE_DOCUMENT_LIST'][$document_srl])
319
			{
320
				$oDocument = null;
0 ignored issues
show
Unused Code introduced by
$oDocument is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
321
				$oDocument = new documentItem();
322
				$oDocument->setAttribute($attribute, false);
323
				if($is_admin) $oDocument->setGrant();
0 ignored issues
show
Bug introduced by
The variable $is_admin does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
324
				$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
325
			}
326
327
			$output->data[$virtual_number] = $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
328
			$virtual_number--;
329
		}
330
331
		if($load_extra_vars) $this->setToAllDocumentExtraVars();
332
333
		if(count($output->data))
334
		{
335
			foreach($output->data as $number => $document)
336
			{
337
				$output->data[$number] = $GLOBALS['XE_DOCUMENT_LIST'][$document->document_srl];
338
			}
339
		}
340
341
		// Call trigger (after)
342
		// This trigger can be used to modify search results
343
		ModuleHandler::triggerCall('document.getDocumentList', 'after', $output);
344
		return $output;
345
	}
346
347
	/**
348
	 * Module_srl value, bringing the document's gongjisa Port
349
	 * @param object $obj
350
	 * @param array $columnList
351
	 * @return object|void
352
	 */
353
	function getNoticeList($obj, $columnList = array())
354
	{
355
		$args = new stdClass();
356
		$args->module_srl = $obj->module_srl;
357
		$args->category_srl= $obj->category_srl;
358
		$output = executeQueryArray('document.getNoticeList', $args, $columnList);
359
		if(!$output->toBool()||!$output->data) return;
360
361 View Code Duplication
		foreach($output->data as $key => $val)
362
		{
363
			$document_srl = $val->document_srl;
364
			if(!$document_srl) continue;
365
366
			if(!$GLOBALS['XE_DOCUMENT_LIST'][$document_srl])
367
			{
368
				$oDocument = null;
0 ignored issues
show
Unused Code introduced by
$oDocument is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
369
				$oDocument = new documentItem();
370
				$oDocument->setAttribute($val, false);
371
				$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
372
			}
373
			$result->data[$document_srl] = $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
0 ignored issues
show
Bug introduced by
The variable $result does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
374
		}
375
		$this->setToAllDocumentExtraVars();
376
377
		foreach($result->data as $document_srl => $val)
378
		{
379
			$result->data[$document_srl] = $GLOBALS['XE_DOCUMENT_LIST'][$document_srl];
380
		}
381
382
		return $result;
383
	}
384
385
	/**
386
	 * Function to retrieve the key values of the extended variable document
387
	 * $Form_include: writing articles whether to add the necessary extensions of the variable input form
388
	 * @param int $module_srl
389
	 * @return array
390
	 */
391
	function getExtraKeys($module_srl)
392
	{
393
		if(!isset($GLOBALS['XE_EXTRA_KEYS'][$module_srl]))
394
		{
395
			$keys = false;
396
			$oCacheHandler = CacheHandler::getInstance('object', null, true);
397
			if($oCacheHandler->isSupport())
398
			{
399
				$object_key = 'module_document_extra_keys:' . $module_srl;
400
				$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
401
				$keys = $oCacheHandler->get($cache_key);
402
			}
403
404
			$oExtraVar = ExtraVar::getInstance($module_srl);
405
406
			if($keys === false)
407
			{
408
				$obj = new stdClass();
409
				$obj->module_srl = $module_srl;
410
				$obj->sort_index = 'var_idx';
411
				$obj->order = 'asc';
412
				$output = executeQueryArray('document.getDocumentExtraKeys', $obj);
413
414
				// correcting index order
415
				$isFixed = FALSE;
416
				if(is_array($output->data))
417
				{
418
					$prevIdx = 0;
419
					foreach($output->data as $no => $value)
420
					{
421
						// case first
422
						if($prevIdx == 0 && $value->idx != 1)
423
						{
424
							$args = new stdClass();
425
							$args->module_srl = $module_srl;
426
							$args->var_idx = $value->idx;
427
							$args->new_idx = 1;
428
							executeQuery('document.updateDocumentExtraKeyIdx', $args);
429
							executeQuery('document.updateDocumentExtraVarIdx', $args);
430
							$prevIdx = 1;
431
							$isFixed = TRUE;
432
							continue;
433
						}
434
435
						// case others
436
						if($prevIdx > 0 && $prevIdx + 1 != $value->idx)
437
						{
438
							$args = new stdClass();
439
							$args->module_srl = $module_srl;
440
							$args->var_idx = $value->idx;
441
							$args->new_idx = $prevIdx + 1;
442
							executeQuery('document.updateDocumentExtraKeyIdx', $args);
443
							executeQuery('document.updateDocumentExtraVarIdx', $args);
444
							$prevIdx += 1;
445
							$isFixed = TRUE;
446
							continue;
447
						}
448
449
						$prevIdx = $value->idx;
450
					}
451
				}
452
453
				if($isFixed)
454
				{
455
					$output = executeQueryArray('document.getDocumentExtraKeys', $obj);
456
				}
457
458
				$oExtraVar->setExtraVarKeys($output->data);
459
				$keys = $oExtraVar->getExtraVars();
460
				if(!$keys) $keys = array();
0 ignored issues
show
Bug Best Practice introduced by
The expression $keys of type ExtraItem[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
461
462
				if($oCacheHandler->isSupport())
463
				{
464
					$oCacheHandler->put($cache_key, $keys);
0 ignored issues
show
Bug introduced by
The variable $cache_key does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
465
				}
466
			}
467
468
469
			$GLOBALS['XE_EXTRA_KEYS'][$module_srl] = $keys;
470
		}
471
472
		return $GLOBALS['XE_EXTRA_KEYS'][$module_srl];
473
	}
474
475
	/**
476
	 * A particular document to get the value of the extra variable function
477
	 * @param int $module_srl
478
	 * @param int $document_srl
479
	 * @return array
480
	 */
481
	function getExtraVars($module_srl, $document_srl)
0 ignored issues
show
Unused Code introduced by
The parameter $module_srl 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...
482
	{
483
		if(!isset($GLOBALS['XE_EXTRA_VARS'][$document_srl]))
484
		{
485
			// Extended to extract the values of variables set
486
			$oDocument = $this->getDocument($document_srl, false);
487
			$GLOBALS['XE_DOCUMENT_LIST'][$document_srl] = $oDocument;
488
			$this->setToAllDocumentExtraVars();
489
		}
490
		if(is_array($GLOBALS['XE_EXTRA_VARS'][$document_srl])) ksort($GLOBALS['XE_EXTRA_VARS'][$document_srl]);
491
		return $GLOBALS['XE_EXTRA_VARS'][$document_srl];
492
	}
493
494
	/**
495
	 * Show pop-up menu of the selected posts
496
	 * Printing, scrap, recommendations and negative, reported the Add Features
497
	 * @return void
498
	 */
499
	function getDocumentMenu()
500
	{
501
		// Post number and the current login information requested Wanted
502
		$document_srl = Context::get('target_srl');
503
		$mid = Context::get('cur_mid');
0 ignored issues
show
Unused Code introduced by
$mid is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
504
		$logged_info = Context::get('logged_info');
505
		$act = Context::get('cur_act');
0 ignored issues
show
Unused Code introduced by
$act is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
506
		// to menu_list "pyosihalgeul, target, url" put into an array
507
		$menu_list = array();
508
		// call trigger
509
		ModuleHandler::triggerCall('document.getDocumentMenu', 'before', $menu_list);
0 ignored issues
show
Documentation introduced by
$menu_list is of type array, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
510
511
		$oDocumentController = getController('document');
512
		// Members must be a possible feature
513
		if($logged_info->member_srl)
514
		{
515
			$oDocumentModel = getModel('document');
516
			$columnList = array('document_srl', 'module_srl', 'member_srl', 'ipaddress');
517
			$oDocument = $oDocumentModel->getDocument($document_srl, false, false, $columnList);
518
			$module_srl = $oDocument->get('module_srl');
519
			$member_srl = $oDocument->get('member_srl');
520
			if(!$module_srl) return new Object(-1, 'msg_invalid_request');
521
522
			$oModuleModel = getModel('module');
523
			$document_config = $oModuleModel->getModulePartConfig('document',$module_srl);
524 View Code Duplication
			if($document_config->use_vote_up!='N' && $member_srl!=$logged_info->member_srl)
525
			{
526
				// Add a Referral Button
527
				$url = sprintf("doCallModuleAction('document','procDocumentVoteUp','%s')", $document_srl);
528
				$oDocumentController->addDocumentPopupMenu($url,'cmd_vote','','javascript');
529
			}
530
531 View Code Duplication
			if($document_config->use_vote_down!='N' && $member_srl!=$logged_info->member_srl)
532
			{
533
				// Add button to negative
534
				$url= sprintf("doCallModuleAction('document','procDocumentVoteDown','%s')", $document_srl);
535
				$oDocumentController->addDocumentPopupMenu($url,'cmd_vote_down','','javascript');
536
			}
537
538
			// Adding Report
539
			$url = sprintf("doCallModuleAction('document','procDocumentDeclare','%s')", $document_srl);
540
			$oDocumentController->addDocumentPopupMenu($url,'cmd_declare','','javascript');
541
542
			// Add Bookmark button
543
			$url = sprintf("doCallModuleAction('member','procMemberScrapDocument','%s')", $document_srl);
544
			$oDocumentController->addDocumentPopupMenu($url,'cmd_scrap','','javascript');
545
		}
546
		// Add print button
547
		$url = getUrl('','module','document','act','dispDocumentPrint','document_srl',$document_srl);
548
		$oDocumentController->addDocumentPopupMenu($url,'cmd_print','','printDocument');
549
		// Call a trigger (after)
550
		ModuleHandler::triggerCall('document.getDocumentMenu', 'after', $menu_list);
551 View Code Duplication
		if($this->grant->manager)
0 ignored issues
show
Bug introduced by
The property grant does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
552
		{
553
			$str_confirm = Context::getLang('confirm_move');
554
			$url = sprintf("if(!confirm('%s')) return; var params = new Array(); params['document_srl']='%s'; params['mid']=current_mid;params['cur_url']=current_url; exec_xml('document', 'procDocumentAdminMoveToTrash', params)", $str_confirm, $document_srl);
555
			$oDocumentController->addDocumentPopupMenu($url,'cmd_trash','','javascript');
556
		}
557
558
		// If you are managing to find posts by ip
559 View Code Duplication
		if($logged_info->is_admin == 'Y')
560
		{
561
			$oDocumentModel = getModel('document');
562
			$oDocument = $oDocumentModel->getDocument($document_srl);	//before setting document recycle
563
564
			if($oDocument->isExists())
565
			{
566
				// Find a post equivalent to ip address
567
				$url = getUrl('','module','admin','act','dispDocumentAdminList','search_target','ipaddress','search_keyword',$oDocument->getIpAddress());
568
				$oDocumentController->addDocumentPopupMenu($url,'cmd_search_by_ipaddress',$icon_path,'TraceByIpaddress');
0 ignored issues
show
Bug introduced by
The variable $icon_path does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
569
570
				$url = sprintf("var params = new Array(); params['ipaddress_list']='%s'; exec_xml('spamfilter', 'procSpamfilterAdminInsertDeniedIP', params, completeCallModuleAction)", $oDocument->getIpAddress());
571
				$oDocumentController->addDocumentPopupMenu($url,'cmd_add_ip_to_spamfilter','','javascript');
572
			}
573
		}
574
		// Changing the language of pop-up menu
575
		$menus = Context::get('document_popup_menu_list');
576
		$menus_count = count($menus);
577 View Code Duplication
		for($i=0;$i<$menus_count;$i++)
578
		{
579
			$menus[$i]->str = Context::getLang($menus[$i]->str);
580
		}
581
		// Wanted to finally clean pop-up menu list
582
		$this->add('menus', $menus);
583
	}
584
585
	/**
586
	 * The total number of documents that are bringing
587
	 * @param int $module_srl
588
	 * @param object $search_obj
589
	 * @return int
590
	 */
591
	function getDocumentCount($module_srl, $search_obj = NULL)
592
	{
593
		if(is_null($search_obj)) $search_obj = new stdClass();
594
		$search_obj->module_srl = $module_srl;
595
596
		$output = executeQuery('document.getDocumentCount', $search_obj);
597
		// Return total number of
598
		$total_count = $output->data->count;
599
		return (int)$total_count;
600
	}
601
602
	/**
603
	 * the total number of documents that are bringing
604
	 * @param object $search_obj
605
	 * @return array
606
	 */
607
	function getDocumentCountByGroupStatus($search_obj = NULL)
608
	{
609
		$output = executeQuery('document.getDocumentCountByGroupStatus', $search_obj);
610
		if(!$output->toBool()) return array();
611
612
		return $output->data;
613
	}
614
615
	function getDocumentExtraVarsCount($module_srl, $search_obj = NULL)
616
	{
617
		// Additional search options
618
		$args->module_srl = $module_srl;
0 ignored issues
show
Bug introduced by
The variable $args does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
619
620
		$args->category_srl = $search_obj->category_srl;
621
		$args->var_idx = $search_obj->s_var_idx;
622
		$args->var_eid = $search_obj->s_var_eid;
623
		$args->var_value = $search_obj->s_var_value;
624
		$args->var_lang_code = Context::getLangType();
625
626
		$output = executeQuery('document.getDocumentExtraVarsCount', $args);
627
		// Return total number of
628
		$total_count = $output->data->count;
629
		return (int)$total_count;
630
	}
631
632
	/**
633
	 * Import page of the document, module_srl Without throughout ..
634
	 * @param documentItem $oDocument
635
	 * @param object $opt
636
	 * @return int
637
	 */
638
	function getDocumentPage($oDocument, $opt)
639
	{
640
		$sort_check = $this->_setSortIndex($opt, TRUE);
641
		$opt->sort_index = $sort_check->sort_index;
642
		$opt->isExtraVars = $sort_check->isExtraVars;
643
644
		$this->_setSearchOption($opt, $args, $query_id, $use_division);
645
646
		if($sort_check->isExtraVars)
647
		{
648
			return 1;
649
		}
650
		else
651
		{
652
			if($sort_check->sort_index === 'list_order' || $sort_check->sort_index === 'update_order')
653
			{
654 View Code Duplication
				if($args->order_type === 'desc')
655
				{
656
					$args->{'rev_' . $sort_check->sort_index} = $oDocument->get($sort_check->sort_index);
657
				}
658
				else
659
				{
660
					$args->{$sort_check->sort_index} = $oDocument->get($sort_check->sort_index);
661
				}
662
			}
663 View Code Duplication
			elseif($sort_check->sort_index === 'regdate')
664
			{
665
666
				if($args->order_type === 'asc')
667
				{
668
					$args->{'rev_' . $sort_check->sort_index} = $oDocument->get($sort_check->sort_index);
669
				}
670
				else
671
				{
672
					$args->{$sort_check->sort_index} = $oDocument->get($sort_check->sort_index);
673
				}
674
675
			}
676
			else
677
			{
678
				return 1;
679
			}
680
		}
681
682
		// Guhanhu total number of the article search page
683
		$output = executeQuery($query_id . 'Page', $args);
684
		$count = $output->data->count;
685
		$page = (int)(($count-1)/$opt->list_count)+1;
686
		return $page;
687
	}
688
689
	/**
690
	 * Imported Category of information
691
	 * @param int $category_srl
692
	 * @param array $columnList
693
	 * @return object
694
	 */
695
	function getCategory($category_srl, $columnList = array())
696
	{
697
		$args =new stdClass();
698
		$args->category_srl = $category_srl;
699
		$output = executeQuery('document.getCategory', $args, $columnList);
700
701
		$node = $output->data;
702
		if(!$node) return;
703
704
		if($node->group_srls)
705
		{
706
			$group_srls = explode(',',$node->group_srls);
707
			unset($node->group_srls);
708
			$node->group_srls = $group_srls;
709
		}
710
		else
711
		{
712
			unset($node->group_srls);
713
			$node->group_srls = array();
714
		}
715
		return $node;
716
	}
717
718
	/**
719
	 * Check whether the child has a specific category
720
	 * @param int $category_srl
721
	 * @return bool
722
	 */
723
	function getCategoryChlidCount($category_srl)
724
	{
725
		$args = new stdClass();
726
		$args->category_srl = $category_srl;
727
		$output = executeQuery('document.getChildCategoryCount',$args);
728
		if($output->data->count > 0) return true;
729
		return false;
730
	}
731
732
	/**
733
	 * Bringing the Categories list the specific module
734
	 * Speed and variety of categories, considering the situation created by the php script to include a list of the must, in principle, to use
735
	 * @param int $module_srl
736
	 * @param array $columnList
737
	 * @return array
738
	 */
739
	function getCategoryList($module_srl, $columnList = array())
740
	{
741
		// Category of the target module file swollen
742
		$filename = sprintf("%sfiles/cache/document_category/%s.php", _XE_PATH_, $module_srl);
743
		// If the target file to the cache file regeneration category
744
		if(!file_exists($filename))
745
		{
746
			$oDocumentController = getController('document');
747
			if(!$oDocumentController->makeCategoryFile($module_srl)) return array();
748
		}
749
750
		include($filename);
751
752
		// Cleanup of category
753
		$document_category = array();
754
		$this->_arrangeCategory($document_category, $menu->list, 0);
0 ignored issues
show
Bug introduced by
The variable $menu does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
755
		return $document_category;
756
	}
757
758
	/**
759
	 * Category within a primary method to change the array type
760
	 * @param array $document_category
761
	 * @param array $list
762
	 * @param int $depth
763
	 * @return void
764
	 */
765
	function _arrangeCategory(&$document_category, $list, $depth)
766
	{
767
		if(!count($list)) return;
768
		$idx = 0;
769
		$list_order = array();
770
		foreach($list as $key => $val)
771
		{
772
			$obj = new stdClass;
773
			$obj->mid = $val['mid'];
774
			$obj->module_srl = $val['module_srl'];
775
			$obj->category_srl = $val['category_srl'];
776
			$obj->parent_srl = $val['parent_srl'];
777
			$obj->title = $obj->text = $val['text'];
778
			$obj->description = $val['description'];
779
			$obj->expand = $val['expand']=='Y'?true:false;
780
			$obj->color = $val['color'];
781
			$obj->document_count = $val['document_count'];
782
			$obj->depth = $depth;
783
			$obj->child_count = 0;
784
			$obj->childs = array();
785
			$obj->grant = $val['grant'];
786
787
			if(Context::get('mid') == $obj->mid && Context::get('category') == $obj->category_srl) $selected = true;
788
			else $selected = false;
789
790
			$obj->selected = $selected;
791
792
			$list_order[$idx++] = $obj->category_srl;
793
			// If you have a parent category of child nodes apply data
794
			if($obj->parent_srl)
795
			{
796
				$parent_srl = $obj->parent_srl;
797
				$document_count = $obj->document_count;
798
				$expand = $obj->expand;
799
				if($selected) $expand = true;
800
801
				while($parent_srl)
802
				{
803
					$document_category[$parent_srl]->document_count += $document_count;
804
					$document_category[$parent_srl]->childs[] = $obj->category_srl;
805
					$document_category[$parent_srl]->child_count = count($document_category[$parent_srl]->childs);
806
					if($expand) $document_category[$parent_srl]->expand = $expand;
807
808
					$parent_srl = $document_category[$parent_srl]->parent_srl;
809
				}
810
			}
811
812
			$document_category[$key] = $obj;
813
814
			if(count($val['list'])) $this->_arrangeCategory($document_category, $val['list'], $depth+1);
815
		}
816
		$document_category[$list_order[0]]->first = true;
817
		$document_category[$list_order[count($list_order)-1]]->last = true;
818
	}
819
820
	/**
821
	 * Wanted number of documents belonging to category
822
	 * @param int $module_srl
823
	 * @param int $category_srl
824
	 * @return int
825
	 */
826
	function getCategoryDocumentCount($module_srl, $category_srl)
827
	{
828
		$args = new stdClass;
829
		$args->module_srl = $module_srl;
830
		$args->category_srl = $category_srl;
831
		$output = executeQuery('document.getCategoryDocumentCount', $args);
832
		return (int)$output->data->count;
833
	}
834
835
	/**
836
	 * Xml cache file of the document category return information
837
	 * @param int $module_srl
838
	 * @return string
839
	 */
840 View Code Duplication
	function getCategoryXmlFile($module_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
841
	{
842
		$xml_file = sprintf('files/cache/document_category/%s.xml.php',$module_srl);
843
		if(!file_exists($xml_file))
844
		{
845
			$oDocumentController = getController('document');
846
			$oDocumentController->makeCategoryFile($module_srl);
847
		}
848
		return $xml_file;
849
	}
850
851
	/**
852
	 * Php cache files in the document category return information
853
	 * @param int $module_srl
854
	 * @return string
855
	 */
856 View Code Duplication
	function getCategoryPhpFile($module_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
857
	{
858
		$php_file = sprintf('files/cache/document_category/%s.php',$module_srl);
859
		if(!file_exists($php_file))
860
		{
861
			$oDocumentController = getController('document');
862
			$oDocumentController->makeCategoryFile($module_srl);
863
		}
864
		return $php_file;
865
	}
866
867
	/**
868
	 * Imported post monthly archive status
869
	 * @param object $obj
870
	 * @return object
871
	 */
872 View Code Duplication
	function getMonthlyArchivedList($obj)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
873
	{
874
		if($obj->mid)
875
		{
876
			$oModuleModel = getModel('module');
877
			$obj->module_srl = $oModuleModel->getModuleSrlByMid($obj->mid);
878
			unset($obj->mid);
879
		}
880
		// Module_srl passed the array may be a check whether the array
881
		$args = new stdClass;
882
		if(is_array($obj->module_srl)) $args->module_srl = implode(',', $obj->module_srl);
883
		else $args->module_srl = $obj->module_srl;
884
885
		$output = executeQuery('document.getMonthlyArchivedList', $args);
886
		if(!$output->toBool()||!$output->data) return $output;
887
888
		if(!is_array($output->data)) $output->data = array($output->data);
889
890
		return $output;
891
	}
892
893
	/**
894
	 * Bringing a month on the status of the daily posts
895
	 * @param object $obj
896
	 * @return object
897
	 */
898 View Code Duplication
	function getDailyArchivedList($obj)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
899
	{
900
		if($obj->mid)
901
		{
902
			$oModuleModel = getModel('module');
903
			$obj->module_srl = $oModuleModel->getModuleSrlByMid($obj->mid);
904
			unset($obj->mid);
905
		}
906
		// Module_srl passed the array may be a check whether the array
907
		$args = new stdClass;
908
		if(is_array($obj->module_srl)) $args->module_srl = implode(',', $obj->module_srl);
909
		else $args->module_srl = $obj->module_srl;
910
		$args->regdate = $obj->regdate;
911
912
		$output = executeQuery('document.getDailyArchivedList', $args);
913
		if(!$output->toBool()) return $output;
914
915
		if(!is_array($output->data)) $output->data = array($output->data);
916
917
		return $output;
918
	}
919
920
	/**
921
	 * Get a list for a particular module
922
	 * @return void|Object
923
	 */
924
	function getDocumentCategories()
925
	{
926
		if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted');
927
		$module_srl = Context::get('module_srl');
928
		$categories= $this->getCategoryList($module_srl);
929
		$lang = Context::get('lang');
930
		// No additional category
931
		$output = "0,0,{$lang->none_category}\n";
932
		if($categories)
0 ignored issues
show
Bug Best Practice introduced by
The expression $categories of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
933
		{
934
			foreach($categories as $category_srl => $category)
935
			{
936
				$output .= sprintf("%d,%d,%s\n",$category_srl, $category->depth,$category->title);
937
			}
938
		}
939
		$this->add('categories', $output);
940
	}
941
942
	/**
943
	 * Wanted to set document information
944
	 * @return object
945
	 */
946
	function getDocumentConfig()
947
	{
948
		if(!$GLOBALS['__document_config__'])
949
		{
950
			$oModuleModel = getModel('module');
951
			$config = $oModuleModel->getModuleConfig('document');
952
953
			if(!$config) $config = new stdClass();
954
			if(!$config->thumbnail_type) $config->thumbnail_type = 'crop';
955
			$GLOBALS['__document_config__'] = $config;
956
		}
957
		return $GLOBALS['__document_config__'];
958
	}
959
960
	/**
961
	 * Common:: Module extensions of variable management
962
	 * Expansion parameter management module in the document module instance, when using all the modules available
963
	 * @param int $module_srl
964
	 * @return string
965
	 */
966
	function getExtraVarsHTML($module_srl)
967
	{
968
		// Bringing existing extra_keys
969
		$extra_keys = $this->getExtraKeys($module_srl);
970
		Context::set('extra_keys', $extra_keys);
0 ignored issues
show
Documentation introduced by
$extra_keys is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
971
		$security = new Security();
972
		$security->encodeHTML('extra_keys..');
973
974
		// Get information of module_grants
975
		$oTemplate = &TemplateHandler::getInstance();
976
		return $oTemplate->compile($this->module_path.'tpl', 'extra_keys');
977
	}
978
979
	/**
980
	 * Common:: Category parameter management module
981
	 * @param int $module_srl
982
	 * @return string
983
	 */
984
	function getCategoryHTML($module_srl)
985
	{
986
		$category_xml_file = $this->getCategoryXmlFile($module_srl);
987
988
		Context::set('category_xml_file', $category_xml_file);
989
990
		Context::loadJavascriptPlugin('ui.tree');
991
992
		// Get a list of member groups
993
		$oMemberModel = getModel('member');
994
		$group_list = $oMemberModel->getGroups($module_info->site_srl);
0 ignored issues
show
Bug introduced by
The variable $module_info does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
995
		Context::set('group_list', $group_list);
996
997
		$security = new Security();
998
		$security->encodeHTML('group_list..title');
999
1000
		// Get information of module_grants
1001
		$oTemplate = &TemplateHandler::getInstance();
1002
		return $oTemplate->compile($this->module_path.'tpl', 'category_list');
1003
	}
1004
1005
	/**
1006
	 * Certain categories of information, return the template guhanhu
1007
	 * Manager on the page to add information about a particular menu from the server after compiling tpl compiled a direct return html
1008
	 * @return void|Object
1009
	 */
1010
	function getDocumentCategoryTplInfo()
1011
	{
1012
		$oModuleModel = getModel('module');
1013
		$oMemberModel = getModel('member');
0 ignored issues
show
Unused Code introduced by
$oMemberModel is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1014
		// Get information on the menu for the parameter settings
1015
		$module_srl = Context::get('module_srl');
1016
		$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
1017
		// Check permissions
1018
		$grant = $oModuleModel->getGrant($module_info, Context::get('logged_info'));
1019
		if(!$grant->manager) return new Object(-1,'msg_not_permitted');
1020
1021
		$category_srl = Context::get('category_srl');
1022
		$category_info = $this->getCategory($category_srl);
1023
		if(!$category_info)
1024
		{
1025
			return new Object(-1, 'msg_invalid_request');
1026
		}
1027
1028
		$this->add('category_info', $category_info);
1029
	}
1030
1031
	/**
1032
	 * Return docuent data by alias
1033
	 * @param string $mid
1034
	 * @param string $alias
1035
	 * @return int|void
1036
	 */
1037
	function getDocumentSrlByAlias($mid, $alias)
1038
	{
1039
		if(!$mid || !$alias) return null;
1040
		$site_module_info = Context::get('site_module_info');
1041
		$args = new stdClass;
1042
		$args->mid = $mid;
1043
		$args->alias_title = $alias;
1044
		$args->site_srl = $site_module_info->site_srl;
1045
		$output = executeQuery('document.getDocumentSrlByAlias', $args);
1046
		if(!$output->data) return null;
1047
		else return $output->data->document_srl;
1048
	}
1049
1050
	/**
1051
	 * Return docuent number by document title
1052
	 * @param int $module_srl
1053
	 * @param string $title
1054
	 * @return int|void
1055
	 */
1056
	function getDocumentSrlByTitle($module_srl, $title)
1057
	{
1058
		if(!$module_srl || !$title) return null;
1059
		$args = new stdClass;
1060
		$args->module_srl = $module_srl;
1061
		$args->title = $title;
1062
		$output = executeQuery('document.getDocumentSrlByTitle', $args);
1063
		if(!$output->data) return null;
1064
		else
1065
		{
1066
			if(is_array($output->data)) return $output->data[0]->document_srl;
1067
			return $output->data->document_srl;
1068
		}
1069
	}
1070
1071
	/**
1072
	 * Return docuent's alias
1073
	 * @param int $document_srl
1074
	 * @return string|void
1075
	 */
1076
	function getAlias($document_srl)
1077
	{
1078
		if(!$document_srl) return null;
1079
		$args = new stdClass;
1080
		$args->document_srl = $document_srl;
1081
		$output = executeQueryArray('document.getAliases', $args);
1082
1083
		if(!$output->data) return null;
1084
		else return $output->data[0]->alias_title;
1085
	}
1086
1087
	/**
1088
	 * Return document's history list
1089
	 * @param int $document_srl
1090
	 * @param int $list_count
1091
	 * @param int $page
1092
	 * @return object
1093
	 */
1094
	function getHistories($document_srl, $list_count, $page)
1095
	{
1096
		$args = new stdClass;
1097
		$args->list_count = $list_count;
1098
		$args->page = $page;
1099
		$args->document_srl = $document_srl;
1100
		$output = executeQueryArray('document.getHistories', $args);
1101
		return $output;
1102
	}
1103
1104
	/**
1105
	 * Return document's history
1106
	 * @param int $history_srl
1107
	 * @return object
1108
	 */
1109
	function getHistory($history_srl)
1110
	{
1111
		$args = new stdClass;
1112
		$args->history_srl = $history_srl;
1113
		$output = executeQuery('document.getHistory', $args);
1114
		return $output->data;
1115
	}
1116
1117
	/**
1118
	 * Module_srl value, bringing the list of documents
1119
	 * @param object $obj
1120
	 * @return object
1121
	 */
1122
	function getTrashList($obj)
1123
	{
1124
		// Variable check
1125
		$args = new stdClass;
1126
		$args->category_srl = $obj->category_srl?$obj->category_srl:null;
1127
		$args->sort_index = $obj->sort_index;
1128
		$args->order_type = $obj->order_type?$obj->order_type:'desc';
1129
		$args->page = $obj->page?$obj->page:1;
1130
		$args->list_count = $obj->list_count?$obj->list_count:20;
1131
		$args->page_count = $obj->page_count?$obj->page_count:10;
1132
		// Search options
1133
		$search_target = $obj->search_target;
1134
		$search_keyword = $obj->search_keyword;
1135
		if($search_target && $search_keyword)
1136
		{
1137
			switch($search_target)
1138
			{
1139
				case 'title' :
1140 View Code Duplication
				case 'content' :
1141
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1142
					$args->{"s_".$search_target} = $search_keyword;
1143
					$use_division = true;
0 ignored issues
show
Unused Code introduced by
$use_division is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1144
					break;
1145 View Code Duplication
				case 'title_content' :
1146
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1147
					$args->s_title = $search_keyword;
1148
					$args->s_content = $search_keyword;
1149
					break;
1150 View Code Duplication
				case 'user_id' :
1151
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1152
					$args->s_user_id = $search_keyword;
1153
					$args->sort_index = 'documents.'.$args->sort_index;
1154
					break;
1155
				case 'user_name' :
1156
				case 'nick_name' :
1157
				case 'email_address' :
1158 View Code Duplication
				case 'homepage' :
1159
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1160
					$args->{"s_".$search_target} = $search_keyword;
1161
					break;
1162
				case 'is_notice' :
1163
				case 'is_secret' :
1164
					if($search_keyword=='N') $args->statusList = array($this->getConfigStatus('public'));
1165
					elseif($search_keyword=='Y') $args->statusList = array($this->getConfigStatus('secret'));
1166
					break;
1167
				case 'member_srl' :
1168
				case 'readed_count' :
1169
				case 'voted_count' :
1170
				case 'blamed_count' :
1171
				case 'comment_count' :
1172
				case 'trackback_count' :
1173
				case 'uploaded_count' :
1174
					$args->{"s_".$search_target} = (int)$search_keyword;
1175
					break;
1176
				case 'regdate' :
1177
				case 'last_update' :
1178
				case 'ipaddress' :
1179
				case 'tag' :
1180
					$args->{"s_".$search_target} = $search_keyword;
1181
					break;
1182
			}
1183
		}
1184
1185
		$output = executeQueryArray('document.getTrashList', $args);
1186
		if($output->data)
1187
		{
1188
			foreach($output->data as $key => $attribute)
1189
			{
1190
				$oDocument = null;
0 ignored issues
show
Unused Code introduced by
$oDocument is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1191
				$oDocument = new documentItem();
1192
				$oDocument->setAttribute($attribute, false);
1193
				$attribute = $oDocument;
1194
			}
1195
		}
1196
		return $output;
1197
	}
1198
1199
	/**
1200
	 * vote up, vote down member list in Document View page
1201
	 * @return void|Object
1202
	 */
1203
	function getDocumentVotedMemberList()
1204
	{
1205
		$args = new stdClass;
1206
		$document_srl = Context::get('document_srl');
1207
		if(!$document_srl) return new Object(-1,'msg_invalid_request');
1208
1209
		$point = Context::get('point');
1210
		if($point != -1) $point = 1;
1211
1212
		$oDocumentModel = getModel('document');
1213
		$columnList = array('document_srl', 'module_srl');
1214
		$oDocument = $oDocumentModel->getDocument($document_srl, false, false, $columnList);
1215
		$module_srl = $oDocument->get('module_srl');
1216
		if(!$module_srl) return new Object(-1, 'msg_invalid_request');
1217
1218
		$oModuleModel = getModel('module');
1219
		$document_config = $oModuleModel->getModulePartConfig('document',$module_srl);
1220 View Code Duplication
		if($point == -1)
1221
		{
1222
			if($document_config->use_vote_down!='S') return new Object(-1, 'msg_invalid_request');
1223
			$args->below_point = 0;
1224
		}
1225
		else
1226
		{
1227
			if($document_config->use_vote_up!='S') return new Object(-1, 'msg_invalid_request');
1228
			$args->more_point = 0;
1229
		}
1230
1231
		$args->document_srl = $document_srl;
1232
1233
		$output = executeQueryArray('document.getVotedMemberList',$args);
1234
		if(!$output->toBool()) return $output;
1235
1236
		$oMemberModel = getModel('member');
1237 View Code Duplication
		if($output->data)
1238
		{
1239
			foreach($output->data as $k => $d)
1240
			{
1241
				$profile_image = $oMemberModel->getProfileImage($d->member_srl);
1242
				$output->data[$k]->src = $profile_image->src;
1243
			}
1244
		}
1245
1246
		$this->add('voted_member_list',$output->data);
1247
	}
1248
1249
	/**
1250
	 * Return status name list
1251
	 * @return array
1252
	 */
1253
	function getStatusNameList()
1254
	{
1255
		global $lang;
1256
		if(!isset($lang->status_name_list))
1257
			return array_flip($this->getStatusList());
1258
		else return $lang->status_name_list;
1259
	}
1260
1261
	/**
1262
	 * Setting sort index
1263
	 * @param object $obj
1264
	 * @param bool $load_extra_vars
1265
	 * @return object
1266
	 */
1267
	function _setSortIndex($obj, $load_extra_vars)
1268
	{
1269
		$sortIndex = $obj->sort_index;
1270
		$isExtraVars = false;
1271
		if(!in_array($sortIndex, array('list_order','regdate','last_update','update_order','readed_count','voted_count','blamed_count','comment_count','trackback_count','uploaded_count','title','category_srl')))
1272
		{
1273
			// get module_srl extra_vars list
1274
			if ($load_extra_vars)
1275
			{
1276
				$extra_args = new stdClass();
1277
				$extra_args->module_srl = $obj->module_srl;
1278
				$extra_output = executeQueryArray('document.getGroupsExtraVars', $extra_args);
1279
				if (!$extra_output->data || !$extra_output->toBool())
1280
				{
1281
					$sortIndex = 'list_order';
1282
				}
1283
				else
1284
				{
1285
					$check_array = array();
1286
					foreach($extra_output->data as $val)
1287
					{
1288
						$check_array[] = $val->eid;
1289
					}
1290
					if(!in_array($sortIndex, $check_array)) $sortIndex = 'list_order';
1291
					else $isExtraVars = true;
1292
				}
1293
			}
1294
			else
1295
				$sortIndex = 'list_order';
1296
		}
1297
		$returnObj = new stdClass();
1298
		$returnObj->sort_index = $sortIndex;
1299
		$returnObj->isExtraVars = $isExtraVars;
1300
1301
		return $returnObj;
1302
	}
1303
1304
	/**
1305
	 * 게시물 목록의 검색 옵션을 Setting함(2011.03.08 - cherryfilter)
1306
	 * page변수가 없는 상태에서 page 값을 알아오는 method(getDocumentPage)는 검색하지 않은 값을 return해서 검색한 값을 가져오도록 검색옵션이 추가 됨.
1307
	 * 검색옵션의 중복으로 인해 private method로 별도 분리
1308
	 * @param object $searchOpt
1309
	 * @param object $args
1310
	 * @param string $query_id
1311
	 * @param bool $use_division
1312
	 * @return void
1313
	 */
1314
	function _setSearchOption($searchOpt, &$args, &$query_id, &$use_division)
1315
	{
1316
		// Variable check
1317
		$args = new stdClass();
1318
		$args->category_srl = $searchOpt->category_srl?$searchOpt->category_srl:null;
1319
		$args->order_type = $searchOpt->order_type;
1320
		$args->page = $searchOpt->page?$searchOpt->page:1;
1321
		$args->list_count = $searchOpt->list_count?$searchOpt->list_count:20;
1322
		$args->page_count = $searchOpt->page_count?$searchOpt->page_count:10;
1323
		$args->start_date = $searchOpt->start_date?$searchOpt->start_date:null;
1324
		$args->end_date = $searchOpt->end_date?$searchOpt->end_date:null;
1325
		$args->member_srl = $searchOpt->member_srl;
1326
1327
		$logged_info = Context::get('logged_info');
1328
1329
		$args->sort_index = $searchOpt->sort_index;
1330
		
1331
		// Check the target and sequence alignment
1332
		$orderType = array('desc' => 1, 'asc' => 1);
1333
		if(!isset($orderType[$args->order_type])) $args->order_type = 'asc';
1334
1335
		// If that came across mid module_srl instead of a direct module_srl guhaejum
1336
		if($searchOpt->mid)
1337
		{
1338
			$oModuleModel = getModel('module');
1339
			$args->module_srl = $oModuleModel->getModuleSrlByMid($obj->mid);
0 ignored issues
show
Bug introduced by
The variable $obj does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1340
			unset($searchOpt->mid);
1341
		}
1342
1343
		// Module_srl passed the array may be a check whether the array
1344
		if(is_array($searchOpt->module_srl)) $args->module_srl = implode(',', $searchOpt->module_srl);
1345
		else $args->module_srl = $searchOpt->module_srl;
1346
1347
		// Except for the test module_srl
1348
		if(is_array($searchOpt->exclude_module_srl)) $args->exclude_module_srl = implode(',', $searchOpt->exclude_module_srl);
1349
		else $args->exclude_module_srl = $searchOpt->exclude_module_srl;
1350
1351
		// only admin document list, temp document showing
1352
		if($searchOpt->statusList) $args->statusList = $searchOpt->statusList;
1353
		else
1354
		{
1355
			if($logged_info->is_admin == 'Y' && !$searchOpt->module_srl)
1356
				$args->statusList = array($this->getConfigStatus('secret'), $this->getConfigStatus('public'), $this->getConfigStatus('temp'));
1357
			else
1358
				$args->statusList = array($this->getConfigStatus('secret'), $this->getConfigStatus('public'));
1359
		}
1360
1361
		// Category is selected, further sub-categories until all conditions
1362
		if($args->category_srl)
1363
		{
1364
			$category_list = $this->getCategoryList($args->module_srl);
1365
			$category_info = $category_list[$args->category_srl];
1366
			$category_info->childs[] = $args->category_srl;
1367
			$args->category_srl = implode(',',$category_info->childs);
1368
		}
1369
1370
		// Used to specify the default query id (based on several search options to query id modified)
1371
		$query_id = 'document.getDocumentList';
1372
1373
		// If the search by specifying the document division naeyonggeomsaekil processed for
1374
		$use_division = false;
1375
1376
		// Search options
1377
		$search_target = $searchOpt->search_target;
1378
		$search_keyword = $searchOpt->search_keyword;
1379
1380
		if($search_target && $search_keyword)
1381
		{
1382
			switch($search_target)
1383
			{
1384
				case 'title' :
1385 View Code Duplication
				case 'content' :
1386
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1387
					$args->{"s_".$search_target} = $search_keyword;
1388
					$use_division = true;
1389
					break;
1390 View Code Duplication
				case 'title_content' :
1391
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1392
					$args->s_title = $search_keyword;
1393
					$args->s_content = $search_keyword;
1394
					$use_division = true;
1395
					break;
1396 View Code Duplication
				case 'user_id' :
1397
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1398
					$args->s_user_id = $search_keyword;
1399
					$args->sort_index = 'documents.'.$args->sort_index;
1400
					break;
1401
				case 'user_name' :
1402
				case 'nick_name' :
1403
				case 'email_address' :
1404 View Code Duplication
				case 'homepage' :
1405
					if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword);
1406
					$args->{"s_".$search_target} = $search_keyword;
1407
					break;
1408
				case 'is_notice' :
1409
					if($search_keyword=='N') $args->{"s_".$search_target} = 'N';
1410
					elseif($search_keyword=='Y') $args->{"s_".$search_target} = 'Y';
1411
					else $args->{"s_".$search_target} = '';
1412
					break;
1413
				case 'is_secret' :
1414
					if($search_keyword=='N') $args->statusList = array($this->getConfigStatus('public'));
1415
					elseif($search_keyword=='Y') $args->statusList = array($this->getConfigStatus('secret'));
1416
					elseif($search_keyword=='temp') $args->statusList = array($this->getConfigStatus('temp'));
1417
					break;
1418
				case 'member_srl' :
1419
				case 'readed_count' :
1420
				case 'voted_count' :
1421
				case 'comment_count' :
1422
				case 'trackback_count' :
1423
				case 'uploaded_count' :
1424
					$args->{"s_".$search_target} = (int)$search_keyword;
1425
					break;
1426
				case 'blamed_count' :
1427
					$args->{"s_".$search_target} = (int)$search_keyword * -1;
1428
					break;
1429
				case 'regdate' :
1430
				case 'last_update' :
1431
				case 'ipaddress' :
1432
					$args->{"s_".$search_target} = $search_keyword;
1433
					break;
1434
				case 'comment' :
1435
					$args->s_comment = $search_keyword;
1436
					$query_id = 'document.getDocumentListWithinComment';
1437
					$use_division = true;
1438
					break;
1439
				case 'tag' :
1440
					$args->s_tags = str_replace(' ','%',$search_keyword);
1441
					$query_id = 'document.getDocumentListWithinTag';
1442
					break;
1443
				case 'extra_vars':
1444
					$args->var_value = str_replace(' ', '%', $search_keyword);
1445
					$query_id = 'document.getDocumentListWithinExtraVars';
1446
					break;
1447
				default :
1448 View Code Duplication
					if(strpos($search_target,'extra_vars')!==false) {
1449
						$args->var_idx = substr($search_target, strlen('extra_vars'));
1450
						$args->var_value = str_replace(' ','%',$search_keyword);
1451
						$args->sort_index = 'documents.'.$args->sort_index;
1452
						$query_id = 'document.getDocumentListWithExtraVars';
1453
					}
1454
					break;
1455
			}
1456
		}
1457
1458
		if ($searchOpt->isExtraVars)
1459
		{
1460
			$query_id = 'document.getDocumentListExtraSort';
1461
		}
1462
		else
1463
		{
1464
			/**
1465
			 * list_order asc sort of division that can be used only when
1466
			 */
1467
			if($args->sort_index != 'list_order' || $args->order_type != 'asc') $use_division = false;
1468
1469
			/**
1470
			 * If it is true, use_division changed to use the document division
1471
			 */
1472
			if($use_division)
1473
			{
1474
				// Division begins
1475
				$division = (int)Context::get('division');
1476
1477
				// order by list_order and (module_srl===0 or module_srl may count), therefore case table full scan
1478
				if($args->sort_index == 'list_order' && ($args->exclude_module_srl === '0' || count(explode(',', $args->module_srl)) > 5))
1479
				{
1480
					$listSqlID = 'document.getDocumentListUseIndex';
0 ignored issues
show
Unused Code introduced by
$listSqlID is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1481
					$divisionSqlID = 'document.getDocumentDivisionUseIndex';
1482
				}
1483
				else
1484
				{
1485
					$listSqlID = 'document.getDocumentList';
0 ignored issues
show
Unused Code introduced by
$listSqlID is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1486
					$divisionSqlID = 'document.getDocumentDivision';
1487
				}
1488
1489
				// If you do not value the best division top
1490 View Code Duplication
				if(!$division)
1491
				{
1492
					$division_args = new stdClass();
1493
					$division_args->module_srl = $args->module_srl;
1494
					$division_args->exclude_module_srl = $args->exclude_module_srl;
1495
					$division_args->list_count = 1;
1496
					$division_args->sort_index = $args->sort_index;
1497
					$division_args->order_type = $args->order_type;
1498
					$division_args->statusList = $args->statusList;
1499
1500
					$output = executeQuery($divisionSqlID, $division_args, array('list_order'));
1501
					if($output->data)
1502
					{
1503
						$item = array_pop($output->data);
1504
						$division = $item->list_order;
1505
					}
1506
					$division_args = null;
0 ignored issues
show
Unused Code introduced by
$division_args is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1507
				}
1508
1509
				// The last division
1510
				$last_division = (int)Context::get('last_division');
1511
1512
				// Division after division from the 5000 value of the specified Wanted
1513 View Code Duplication
				if(!$last_division)
1514
				{
1515
					$last_division_args = new stdClass();
1516
					$last_division_args->module_srl = $args->module_srl;
1517
					$last_division_args->exclude_module_srl = $args->exclude_module_srl;
1518
					$last_division_args->list_count = 1;
1519
					$last_division_args->sort_index = $args->sort_index;
1520
					$last_division_args->order_type = $args->order_type;
1521
					$last_division_args->list_order = $division;
1522
					$last_division_args->page = 5001;
1523
1524
					$output = executeQuery($divisionSqlID, $last_division_args, array('list_order'));
1525
					if($output->data)
1526
					{
1527
						$item = array_pop($output->data);
1528
						$last_division = $item->list_order;
1529
					}
1530
				}
1531
1532
				// Make sure that after last_division article
1533
				if($last_division)
1534
				{
1535
					$last_division_args = new stdClass();
1536
					$last_division_args->module_srl = $args->module_srl;
1537
					$last_division_args->exclude_module_srl = $args->exclude_module_srl;
1538
					$last_division_args->list_order = $last_division;
1539
					$output = executeQuery('document.getDocumentDivisionCount', $last_division_args);
1540
					if($output->data->count<1) $last_division = null;
1541
				}
1542
1543
				$args->division = $division;
1544
				$args->last_division = $last_division;
1545
				Context::set('division', $division);
1546
				Context::set('last_division', $last_division);
1547
			}
1548
		}
1549
	}
1550
1551
	/**
1552
	 * Get the total number of Document in corresponding with member_srl.
1553
	 * @param int $member_srl
1554
	 * @return int
1555
	 */
1556
	function getDocumentCountByMemberSrl($member_srl)
1557
	{
1558
		$args = new stdClass();
1559
		$args->member_srl = $member_srl;
1560
		$output = executeQuery('document.getDocumentCountByMemberSrl', $args);
1561
		return (int) $output->data->count;
1562
	}
1563
1564
	/**
1565
	 * Get document list of the doc in corresponding woth member_srl.
1566
	 * @param int $member_srl
1567
	 * @param array $columnList
1568
	 * @param int $page
1569
	 * @param bool $is_admin
1570
	 * @param int $count
1571
	 * @return object
1572
	 */
1573 View Code Duplication
	function getDocumentListByMemberSrl($member_srl, $columnList = array(), $page = 0, $is_admin = FALSE, $count = 0 )
0 ignored issues
show
Unused Code introduced by
The parameter $page 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...
Unused Code introduced by
The parameter $is_admin 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...
Duplication introduced by
This method seems to be duplicated in 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...
1574
	{
1575
		$args = new stdClass();
1576
		$args->member_srl = $member_srl;
1577
		$args->list_count = $count;
1578
		$output = executeQuery('document.getDocumentListByMemberSrl', $args, $columnList);
1579
		$document_list = $output->data;
1580
		
1581
		if(!$document_list) return array();
1582
		if(!is_array($document_list)) $document_list = array($document_list);
1583
1584
		return $document_list;	
1585
	}
1586
}
1587
/* End of file document.model.php */
1588
/* Location: ./modules/document/document.model.php */
1589