Passed
Push — crawler_data ( c91d9a )
by
unknown
18:13
created

start.php ➔ elgg_display_comment_handler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 4
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
elgg_register_event_handler('init','system','gc_elgg_sitemap_init');
4
5
6
function gc_elgg_sitemap_init() {
0 ignored issues
show
Coding Style introduced by
gc_elgg_sitemap_init uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
7
8
	// display text only if user agent string is gsa-crawler (or whatever is set)
9
	if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'gsa-crawler') !== false || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'solr-crawler') !== false) {
10
11
	    elgg_register_plugin_hook_handler('register', 'menu:site', 'elgg_site_menu_handler', array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

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...
12
	    elgg_register_plugin_hook_handler('register', 'menu:user_menu', 'elgg_user_menu_handler', array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

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...
13
	    elgg_register_plugin_hook_handler('register', 'menu:title', 'elgg_user_menu_handler', array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

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...
14
	    elgg_register_plugin_hook_handler('register', 'menu:filter', 'elgg_entity_menu_handler', array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

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...
15
	    elgg_register_plugin_hook_handler('prepare', 'breadcrumbs', 'elgg_breadcrumb_handler', array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

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...
16
	    elgg_register_plugin_hook_handler('register', 'menu:title2', 'elgg_site_menu_handler', array());
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

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...
17
18
	    elgg_register_menu_item('site', array('name' => 'pages', 'text' => 'Pages', 'href' => '/pages/all'));
19
20
	
21
	    /// remove all the sidebars across the site
22
	    elgg_register_plugin_hook_handler('view', 'bookmarks/sidebar', 'elgg_sidebar_handler');
23
	    elgg_register_plugin_hook_handler('view', 'blog/sidebar', 'elgg_sidebar_handler');
24
	    elgg_register_plugin_hook_handler('view', 'event_calendar/sidebar', 'elgg_sidebar_handler');
25
	    elgg_register_plugin_hook_handler('view', 'file/sidebar', 'elgg_sidebar_handler');
26
	    elgg_register_plugin_hook_handler('view', 'groups/sidebar', 'elgg_sidebar_handler');
27
	    elgg_register_plugin_hook_handler('view', 'members/sidebar', 'elgg_sidebar_handler');
28
	    elgg_register_plugin_hook_handler('view', 'missiona/sidebar', 'elgg_sidebar_handler');
29
	    elgg_register_plugin_hook_handler('view', 'thewire/sidebar', 'elgg_sidebar_handler');
30
	    elgg_register_plugin_hook_handler('view', 'photos/sidebar', 'elgg_sidebar_handler');
31
	    elgg_register_plugin_hook_handler('view', 'file/sidebar', 'elgg_sidebar_handler');
32
		elgg_register_plugin_hook_handler('view', 'input/longtext', 'elgg_comment_view_handler');
33
		elgg_register_plugin_hook_handler('view', 'input/submit', 'elgg_comment_view_handler');
34
		elgg_register_plugin_hook_handler('view', 'ouptput/url', 'elgg_comment_view_handler');
35
		elgg_register_plugin_hook_handler('view', 'event_calendar/show_events', 'elgg_event_calendar_list_handler');
36
37
		elgg_register_plugin_hook_handler('view', 'groups/profile/widget_area', 'elgg_generic_view_handler');
38
		elgg_register_plugin_hook_handler('view', 'page/elements/comments', 'elgg_comment_view_handler');
39
		elgg_register_plugin_hook_handler('view', 'page/elements/topbar_wrapper', 'elgg_view_topbar_handler');
40
41
	    /// renmove these pages so that it doesn't get crawled
42
		elgg_unregister_page_handler('activity');
43
		elgg_unregister_page_handler('dashboard');
44
		elgg_unregister_menu_item('topbar', 'dashboard');
45
		elgg_unregister_menu_item('site', 'activity');
46
		elgg_unregister_menu_item('site', 'career');
47
		elgg_unregister_menu_item('site', 'Help');
48
		elgg_unregister_menu_item('site', 'newsfeed');
49
		elgg_unregister_menu_item('site', 'communities');
50
		elgg_unregister_menu_item('title2', 'new_folder');
51
52
		/// list all entities
53
54
		/* WARNING: "Argument 2 passed to Elgg\\ViewsService::renderView() must be of the type array, null given */
55
		elgg_register_plugin_hook_handler('view_vars', 'object/elements/summary', 'elgg_entities_list_handler');
56
		elgg_register_plugin_hook_handler('view_vars', 'object/elements/full', 'elgg_full_entities_view_handler');
57
		elgg_register_plugin_hook_handler('view_vars', 'object/elements/thewire_summary', 'elgg_thewire_list_handler');
58
		elgg_register_plugin_hook_handler('view_vars', 'group/elements/summary', 'elgg_entities_list_handler');
59
		elgg_register_plugin_hook_handler('view_vars', 'page/components/image_block', 'elgg_sidebar_handler');
60
61
		elgg_register_plugin_hook_handler('view', 'members/nav', 'elgg_members_menu_handler');
62
		elgg_register_plugin_hook_handler('view', 'event_calendar/filter_menu', 'elgg_members_menu_handler');
63
64
		elgg_register_plugin_hook_handler('route', 'comment', 'elgg_display_comment_handler');
65
66
	    elgg_register_plugin_hook_handler('register','menu:owner_block','group_navigation_handler');
67
		elgg_extend_view('groups/profile/summary', 'group_tabs', 600);
68
69
		elgg_register_plugin_hook_handler('entity:url', 'group', 'redirect_group_url');
70
		elgg_register_plugin_hook_handler('entity:url', 'object', 'redirect_content_url', 1);
71
		elgg_register_plugin_hook_handler('view', 'output/longtext', 'strip_content_hyperlinks_handler');
72
73
		// modifying view in the user's profile
74
		elgg_register_plugin_hook_handler('view', 'b_extended_profile/portfolio', 'linkedin_profile_handler');
75
		elgg_register_plugin_hook_handler('view', 'b_extended_profile/skills', 'elgg_view_topbar_handler');
76
77
	}
78
}
79
80
function elgg_display_comment_handler($hook, $type, $return, $params) {
81
    $segments = elgg_extract('segments', $return, array());
82
83
    if ($segments[0] === 'view') {
84
        $entity = get_entity($segments[1]);
85
        $title = $entity->description;
86
        $content = $entity->description;
87
88
        echo elgg_view_page($title, $content);
89
90
        // in the route hook, return false says, "stop rendering, we've handled this request"
91
        return false;
92
    }
93
}
94
95
function elgg_view_topbar_handler($hook, $type, $return, $params) {
96
	return "";
97
}
98
99
function linkedin_profile_handler($hook, $type, $return, $params) {
100
101
	$user = elgg_get_page_owner_entity();
102
	$portfolio_guid = $user->portfolio;
103
104
	// when no portfolio for user exists
105
	if (empty($portfolio_guid) || $portfolio_guid == NULL)
106
		return;
107
108
	if (!is_array($portfolio_guid))
109
		$portfolio_guid = array($portfolio_guid);
110
111
	foreach ($portfolio_guid as $guid) {
112
		
113
		$entry = get_entity($guid);
114
		if ($entry instanceof ElggEntity) {
115
			echo gc_explode_translation($entry->title, 'en').' / '.gc_explode_translation($entry->title, 'fr');
116
		}
117
	}
118
119
	return "";
120
}
121
122
123
function strip_content_hyperlinks_handler($hook, $type, $return, $params) {
124
	
125
	// pull the user agent string and/or user testing
126
	$gsa_agentstring = strtolower(elgg_get_plugin_setting('gsa_agentstring','gc_fedsearch_gsa'));
127
	$gsa_usertest = elgg_get_plugin_setting('gsa_test','gc_fedsearch_gsa');
128
	if ($gsa_usertest) $current_user = elgg_get_logged_in_user_entity();
129
130
	/*blog pages bookmarks file discussion*/
131
	$filter_entity = array('blog', 'pages', 'discussion', 'file', 'bookmarks');
132
	$context = get_context();
133
134
	// only do it for the main content, comments will be left the way it is
135
	$comment = new DOMDocument();
136
	$comment->loadHTML($return);
137
	$comment_block = $comment->getElementsByTagName('div');
138
139
	if (strstr($return, 'data-role="comment-text"') !== false) {
140
		return;
141
	}
142
143
	if (!empty($comment_block) || $comment_block === null)
144
		$comment_text = $comment_block->item(0)->getAttribute('data-role');
145
	else
146
		$comment_text = "";
147
148
	if (( strcmp($comment_text,'comment-text') == 0 || strcmp($comment_text, 'discussion-reply-text') == 0 ))
149
		return;
150
151
	if (!in_array($context, $filter_entity))
152
		return;
153
154
155
	$page_url = get_sanitized_url();
156
	// url: /file/view/1102
157
	$entity = get_entity($page_url[2]);
158
159
	// if $entity is not valid, then just don't do anything, to avoid error
160
	if (!($entity instanceof ElggEntity))
161
		return;
162
163
	if (isJsonString($entity->description)) {
164
		$json = json_decode($entity->description, true);
165
		$description_en = $json['en'];
166
		$description_fr = $json['fr'];
167
	} else {
168
		$description_en = $entity->description;
169
		$description_fr = $entity->description2;
170
171
	}
172
173
	// english body text
174
	$description = new DOMDocument();
175
	$description->loadHTML($description_en);
176
	$links = $description->getElementsByTagName('a');
177 View Code Duplication
	for ($i = $links->length - 1; $i >= 0; $i--) {
178
		$linkNode = $links->item($i);
179
		$lnkText = $linkNode->textContent;
180
		$newTxtNode = $description->createTextNode($lnkText);
181
		$linkNode->parentNode->replaceChild($newTxtNode, $linkNode);
182
	}
183
	$return = $description->textContent."<br/><br/>";
184
185
186
	// french body text
187
	if (!empty($description_fr)) {
188
		$description->loadHTML($description_fr);
189
		$links = $description->getElementsByTagName('a');
190 View Code Duplication
		for ($i = $links->length - 1; $i >= 0; $i--) {
191
			$linkNode = $links->item($i);
192
			$lnkText = $linkNode->textContent;
193
			$newTxtNode = $description->createTextNode($lnkText);
194
			$linkNode->parentNode->replaceChild($newTxtNode, $linkNode);
195
		}
196
	}
197
	$return .= $description->textContent;
198
199
	return $return;
200
}
201
202
203
function redirect_group_url($hook, $type, $url, $params) {
0 ignored issues
show
Coding Style introduced by
redirect_group_url uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
204
	// from: 192.168.xx.xx/gcconnex/groups/profile/1111/group-name
205
	// to: 192.168.xx.xx/gcconnex/groups/profile/1111/
206
	if (strpos($_SERVER['REQUEST_URI'],"/groups/profile/") !== false && sizeof(get_sanitized_url()) > 3)
207
		forward("groups/profile/{$params['entity']->guid}");
208
}
209
210
211
function get_sanitized_url() {
0 ignored issues
show
Coding Style introduced by
get_sanitized_url uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
212
213
	$base_site_url = str_replace('/', ' ', elgg_get_site_entity()->getURL());
214
	$current_url = str_replace('/', ' ', ((isset($_SERVER['HTTPS']) ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"));
215
	$current_url = str_replace($base_site_url, '', $current_url);
216
	$current_url = str_replace(' ', '/', $current_url);
217
	$current_url = explode("/", $current_url);
218
219
	return $current_url;
220
}
221
222
/**
223
 * covers: blogs, files, pages
224
 * does not cover: bookmarks, missions, images, polls, wire, event
225
 */
226
function redirect_content_url($hook, $type, $url, $params) {
0 ignored issues
show
Coding Style introduced by
redirect_content_url uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
227
228
	// display only the comment when the url is directing to a specific comment
229
	// only do this when the user agent is solr-crawler
230
	if (strpos($_SERVER['REQUEST_URI'], '/comment/view/') !== false ) return;
231
232
	if (strpos($_SERVER['REQUEST_URI'],"/view/") !== false)
233
	{
234
		$subtype = $params['entity']->getSubtype();
235
		error_log("comment >>> <<<  {$subtype}");
236
		if ($subtype === 'groupforumtopic') $subtype = 'discussion';
237
		if ($subtype === 'page_top') $subtype = 'pages';
238
		if ($subtype === 'idea') $subtype = 'ideas';
239
240
		if (sizeof(get_sanitized_url()) > 3)
241
			forward("{$subtype}/view/{$params['entity']->guid}");
242
	}
243
}
244
245
246
function group_navigation_handler($hook, $type, $value, $params) {
247
248
	if (elgg_get_context() === 'group_profile' || elgg_get_context() === 'groupSubPage') {
249
	
250
		$base_url = elgg_get_site_entity()->getURL();
251
		$group_id = elgg_get_page_owner_entity()->guid;
252
253
		foreach ($value as $key => $item) {
254
255
			if ($item->getName() === 'activity' || $item->getName() === 'more' || $item->getName() === 'photo_albums' || $item->getName() === 'event_calendar' || $item->getName() === 'polls' || $item->getName() === 'pages') 
256
				continue;
257
258
			if ($item->getName() === 'discussion') {
259
				$url = "{$base_url}{$item->getName()}/owner/{$group_id}";
260
				echo "<a href='{$url}'>{$item->getName()}</a> <br/>";
261
			} else if ($item->getName() === 'about') {
262
				$url = "{$base_url}groups/profile/{$group_id}";
263
				echo "<a href='{$url}'>{$item->getName()}</a> <br/>";
264
			} else {
265
				$url = "{$base_url}{$item->getName()}/group/{$group_id}";
266
				echo "<a href='{$url}'>{$item->getName()}</a> <br/>";
267
			}
268
269
		}
270
	}
271
	return array();
272
}
273
274
275
function elgg_members_menu_handler($hook, $type, $menu, $params) {
276
	return "";
277
}
278
279
function elgg_generic_view_handler($hook, $type, $value, $params) {
280
	return array();
281
}
282
283
284
285
function elgg_comment_view_handler($hook, $type, $value, $params) {
286
	//echo "type: {$type} /// hook: {$hook} /// ".print_r($value,true);
287
288
	if ($type === 'page/elements/comments') {
289
290
		$comments = elgg_get_entities(array(
291
			'type' => 'object',
292
			'subtype' => 'comment',
293
			'container_guid' => $params['vars']['entity']->guid,
294
			'limit' => 0,
295
			'distinct' => false
296
		));
297
298
		foreach ($comments as $comment) {
299
			$comment_list .= "<a href='{$comment->getURL()}'>{$comment->description}</a> <br/>";
0 ignored issues
show
Bug introduced by
The variable $comment_list 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...
300
		}
301
	}
302
303
	return $comment_list;
304
}
305
306
function elgg_event_calendar_list_handler($hook, $type, $value, $params) {
307
308
	$event_list = elgg_list_entities([
309
	    'type' => 'object',
310
	    'subtype' => 'event_calendar',
311
	]);
312
313
	return $event_list;
314
}
315
316
317
318
function elgg_entity_menu_handler($hook, $type, $menu, $params) {
319
	return array();
320
}
321
322
/**
323
 * checks if string input is json
324
 * @param string $string
325
 */
326
function isJsonString($string) {
327
	json_decode($string);
328
	return (json_last_error() == JSON_ERROR_NONE);
329
}
330
331
332
function elgg_full_entities_view_handler($hook, $type, $value, $params) {
333
334
	$description = "";
335
336
	switch ($value['entity']->getSubtype()) {
337
338 View Code Duplication
		case 'event_calendar':
339
			if (isJsonString($value['entity']->long_description)) {
340
				
341
				$description_array = json_decode($value['entity']->long_description, true);
342
				$description .= "<p> {$description_array['en']} </p> <p> {$description_array['fr']} </p>";
343
			} else {
344
				
345
				$description .= "<p> {$value['entity']->long_description} </p> <p> {$value['entity']->long_description2} </p>";
346
			}
347
			break;
348
349 View Code Duplication
		default:
350
			if (isJsonString($value['entity']->description)) {
351
				
352
				$description_array = json_decode($value['entity']->description, true);
353
				$description .= "<p> {$description_array['en']} </p> <p> {$description_array['fr']} </p>";
354
			} else {
355
				
356
				$description .= "<p> {$value['entity']->description} </p> <p> {$value['entity']->description2} </p>";
357
			}
358
	}
359
360
	echo $description;
361
362
	return array();
363
}
364
365
366
function elgg_thewire_list_handler($hook, $type, $value, $params) {
0 ignored issues
show
Coding Style introduced by
elgg_thewire_list_handler uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
367
368
	if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'solr-crawler') !== false) {
369
		echo "<a href='{$value['entity']->getURL()}?language=en'>{$value['entity']->description}</a>  <br/>";
370
		echo "<a href='{$value['entity']->getURL()}?language=fr'>{$value['entity']->description}</a>  <br/>";
371
	} else {
372
		echo "<a href='{$value['entity']->getURL()}'>{$value['entity']->description}</a>  <br/>";
373
	}
374
	return array();
375
376
}
377
378
/// lists out all the entities on the page
379
function elgg_entities_list_handler($hook, $type, $value, $params) {
0 ignored issues
show
Coding Style introduced by
elgg_entities_list_handler uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
380
	
381
	$empty = array();
382
	// brief view: display content (excerpt)
383
	// full view: content does not exist (it will display the title link again)
384
	if (!$value['content'] && get_context() !== 'members' && get_context() !== 'polls' && get_context() !== 'event_calendar' && get_context() !== 'file' && get_context() !== 'groups') {
385
		return $empty;
386
	}
387
388
389
	if ($value['entity']->title !== '') {
390
		$pArray = json_decode($value['entity']->title);
391
		if ($pArray->en === '' && $pArray->fr === '') return $empty;
392
	} 
393
394
	$context = get_context();
395
	switch ($context) {
396
		case 'file':
397 View Code Duplication
		case 'event_calendar':
398
			if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'solr-crawler') !== false) {
399
				echo "<a href='{$value['entity']->getURL()}?language=en'>{$value['entity']->title}</a>  <br/>";
400
				echo "<a href='{$value['entity']->getURL()}?language=fr'>{$value['entity']->title}</a>  <br/>";
401
			} else {
402
				echo "<a href='{$value['entity']->getURL()}'>{$value['entity']->title}</a>  <br/>";
403
			}
404
			break;
405 View Code Duplication
		case 'groups':
406
			$group_url = elgg_get_site_url()."groups/profile/{$value['entity']->guid}/";
407
			if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'solr-crawler') !== false) {
408
				echo "<a href='{$group_url}?language=en'>{$value['entity']->name}</a>  <br/>";
409
				echo "<a href='{$group_url}?language=fr'>{$value['entity']->name}</a>  <br/>";
410
			} else {
411
				echo "<a href='{$group_url}'>{$value['entity']->name}</a>  <br/>";
412
			}
413
414
			break;
415
416 View Code Duplication
		case 'members':
417
			$member_url = elgg_get_site_url()."profile/{$value['entity']->username}";
418
			if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'solr-crawler') !== false) {
419
				echo "<a href='{$member_url}?language=en'>{$value['entity']->username}</a>  <br/>";
420
				echo "<a href='{$member_url}?language=fr'>{$value['entity']->username}</a>  <br/>";
421
			} else {
422
				echo "<a href='{$member_url}'>{$value['entity']->username}</a>  <br/>";
423
			}
424
			break;
425
426 View Code Duplication
		default:
427
			if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'solr-crawler') !== false) {
428
				echo "<a href='{$value['entity']->getURL()}?language=en'>{$value['entity']->title}</a>  <br/>";
429
				echo "<a href='{$value['entity']->getURL()}?language=fr'>{$value['entity']->title}</a>  <br/>";
430
			} else {
431
				echo "<a href='{$value['entity']->getURL()}'>{$value['entity']->title}</a>  <br/>";
432
			}
433
		
434
	}
435
436
	return $empty;
437
}
438
439
function elgg_sidebar_handler($hook, $type, $menu, $params) {
440
	if (is_array($menu) && $menu['body'])
441
		echo $menu['body'];
442
	return array();
443
}
444
445
/**
446
 * hide the breadcrumbs
447
 */
448
function elgg_breadcrumb_handler($hook, $type, $menu, $params) {
449
	return array();
450
}
451
452
453
454
/**
455
 * hide the user menu bar
456
 */
457
function elgg_user_menu_handler($hook, $type, $menu, $params) {
458
	return array();
459
}
460
461
462
/**
463
 * xml the links for the site navigation
464
 */
465
function elgg_site_menu_handler($hook, $type, $menu, $params) {
466
	$menu_item = "";
467
	foreach ($menu as $key => $item) {
468
469
		if ($item->getName() === 'translation_editor' || $item->getName() === 'new_folder' || $item->getName() === 'questions' || $item->getName() === 'polls')
470
			continue;
471
472
		if ($item->getName() === 'groups') {
473
			$group_url = elgg_get_site_url()."groups/";
474
			$menu_item .= " <a style='color:white;' href='{$group_url}'> {$item->getName()}</a> ";
475
		}
476
		else 
477
			$menu_item .= " <a style='color:white;' href='{$item->getHref()}'> {$item->getName()}</a> ";
478
	}
479
	echo $menu_item;
480
481
	return array();
482
}
483
484