Completed
Push — develop ( 1719ba...d15620 )
by David
04:51 queued 01:38
created

wordlift_constants.php ➔ wl_temp_dir()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file contains WordLift-related constants.
4
 *
5
 * @package Wordlift
6
 */
7
8
// Define the basic options for HTTP calls to REDLINK.
9
define( 'WL_REDLINK_API_HTTP_OPTIONS', serialize( array(
10
	'timeout'         => 300,
11
	'redirection'     => 5,
12
	'httpversion'     => '1.1',
13
	'blocking'        => true,
14
	'cookies'         => array(),
15
	'sslverify'       => ( 'false' === getenv( 'WL_SSL_VERIFY_ENABLED' ) ) ? false : true,
16
	'sslcertificates' => dirname( __FILE__ ) . '/ssl/ca-bundle.crt',
17
	'decompress'      => false,
18
) ) );
19
20
// Create a unique ID for this request, useful to hook async HTTP requests.
21
define( 'WL_REQUEST_ID', uniqid( true ) );
22
23
// Set the temporary files folder.
24
defined( 'WL_TEMP_DIR' ) || define( 'WL_TEMP_DIR', wl_temp_dir() );
25
26
define( 'WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING', wl_is_sparql_update_queries_buffering_enabled() );
27
28
function wl_is_sparql_update_queries_buffering_enabled() {
0 ignored issues
show
Coding Style introduced by
wl_is_sparql_update_queries_buffering_enabled uses the super-global variable $_REQUEST 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...
29
30
	if ( isset( $_REQUEST['wl-async'] ) && 'false' === $_REQUEST['wl-async'] ) {
31
		return false;
32
	}
33
34
	return 'true' !== getenv( 'WL_DISABLE_SPARQL_UPDATE_QUERIES_BUFFERING' );
35
}
36
37
// Define the meta name used to store the entity URL.
38
define( 'WL_ENTITY_URL_META_NAME', 'entity_url' );
39
40
// Max number of recursions when printing microdata.
41
define( 'WL_RECURSION_DEPTH_ON_ENTITY_METADATA_PRINTING', 3 );
42
43
// 3.13.0, we use by default WLS 1.11 which provides us with the new, faster
44
// chunked analysis.
45
define( 'WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined( 'WORDLIFT_API_URL' ) ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.it/' );
46
47
define( 'WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://developers.google.com/structured-data/testing-tool/?url=' );
48
49
// If is set to true, there will be additional button in 'Download Your Data' page
50
// that will allow users to download their data in JSON-LD format.
51
defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) || define( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA', false );
52
53
54
/**
55
 * Get an array with commonly supported prefixes.
56
 *
57
 * @return array An array of prefixes and URIs
58
 */
59
function wl_prefixes() {
60
61
	$items    = wl_prefixes_list();
62
	$prefixes = array();
63
64
	foreach ( $items as $item ) {
65
		$prefixes[ $item['prefix'] ] = $item['namespace'];
66
	}
67
68
	return $prefixes;
69
70
}
71
72
/**
73
 * Get a site unique directory under the system or WordPress temporary directory.
74
 * The WordPress get_temp_dir API, do not take into account that different sites
75
 * might need to store segregated information from each other. We will use the
76
 * site URL and blog number to create a "private" area below the temp directory
77
 * provided by the WordPress API.
78
 *
79
 * @since 3.16.0
80
 *
81
 * @return string The path to the temp directory for the specific site.
82
 */
83
function wl_temp_dir() {
84
	$tempdir = get_temp_dir();
85
	$unique = md5( site_url() . get_current_blog_id() );
86
	$unique_temp_dir = $tempdir . 'wl_' . $unique; // $tempdir should have a trailing slash.
87
88
	// If directory do not exist, create it.
89
	if ( ! file_exists( $unique_temp_dir ) ) {
90
		mkdir( $unique_temp_dir );
91
	}
92
93
	return $unique_temp_dir . '/';
94
}
95