Skip to content

Commit

Permalink
Merge pull request #3 from lairdshaw/remove-dynamic-object-properties
Browse files Browse the repository at this point in the history
Convert dynamic object properties to global vars
  • Loading branch information
Sama34 authored Dec 19, 2023
2 parents 6991628 + 1356be2 commit dee08ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
4 changes: 2 additions & 2 deletions inc/plugins/google_seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function google_seo_expand($string, $array)
function google_seo_tid($pid, $tid=0, $mode='default', $limit=1)
{
global $db, $style, $thread, $post;
global $google_seo_tid;
global $google_seo_tid, $google_seo_query_limit;

if($google_seo_tid === NULL || $pid === NULL || !isset($google_seo_tid[$pid]))
{
Expand Down Expand Up @@ -229,7 +229,7 @@ function google_seo_tid($pid, $tid=0, $mode='default', $limit=1)
&& ($mode == 'verify' || ($tid <= 0 && $mode != 'ignore')))
{
$pid = (int)$pid;
$db->google_seo_query_limit--;
$google_seo_query_limit--;
$query = $db->simple_select('posts', 'tid', "pid={$pid}");
$tid = (int)$db->fetch_field($query, 'tid');

Expand Down
65 changes: 32 additions & 33 deletions inc/plugins/google_seo/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
/* --- Global Variables: --- */

global $db, $mybb, $settings, $plugins, $cache;
global $google_seo_query_limit, $google_seo_url;

// Required for database queries to the google_seo table. In theory this
// could be used to coerce Google SEO into managing URLs of other types.
Expand Down Expand Up @@ -139,14 +140,12 @@
$google_seo_url[GOOGLE_SEO_EVENT]['parent_type'] = GOOGLE_SEO_CALENDAR;
}

@$db->google_seo_url = $google_seo_url;
// Query limit. Decreases by 1 for every query.
$google_seo_query_limit = (int)$settings['google_seo_url_query_limit'];

@$db->google_seo_query_limit = (int)$settings['google_seo_url_query_limit'];

if($db->google_seo_query_limit <= 0)
if($google_seo_query_limit <= 0)
{
$db->google_seo_query_limit = 32767;
$google_seo_query_limit = 32767;
}

// Cache
Expand Down Expand Up @@ -378,7 +377,7 @@ function google_seo_url_finalize($url, $scheme)
function google_seo_url_create($type, $ids)
{
global $db, $settings;
global $google_seo_url_cache;
global $google_seo_url_cache, $google_seo_query_limit, $google_seo_url;

$ids = array_map('intval', (array)$ids);

Expand All @@ -387,18 +386,18 @@ function google_seo_url_create($type, $ids)
$google_seo_url_cache[$type][$id] = 0;
}

if($db->google_seo_query_limit <= 0)
if($google_seo_query_limit <= 0)
{
return;
}

$data = $db->google_seo_url[$type];
$data = $google_seo_url[$type];

// Is Google SEO URL enabled for this type?
if($data['scheme'])
{
// Query the item title as base for our URL.
$db->google_seo_query_limit--;
$google_seo_query_limit--;

if(!isset($data['extra']))
{
Expand Down Expand Up @@ -458,29 +457,29 @@ function google_seo_url_create($type, $ids)
// Parents
if(isset($row['parent']))
{
$parent_type = $db->google_seo_url[$type]['parent_type'];
$parent_type = $google_seo_url[$type]['parent_type'];
$parent_id = (int)$row['parent'];

// TODO: Parents costs us an extra query. Cache?
$db->google_seo_query_limit--;
$google_seo_query_limit--;
$query = $db->simple_select('google_seo',
'url AS parent',
"active=1 AND idtype={$parent_type} AND id={$parent_id}");
$parent = $db->fetch_field($query, 'parent');

if($parent)
{
$url = google_seo_expand($db->google_seo_url[$type]['parent'],
$url = google_seo_expand($google_seo_url[$type]['parent'],
array('url' => $url,
'parent' => $parent));
$uniqueurl = google_seo_expand($db->google_seo_url[$type]['parent'],
$uniqueurl = google_seo_expand($google_seo_url[$type]['parent'],
array('url' => $url,
'parent' => $parent));
}
}

// Check for existing entry and possible collisions.
$db->google_seo_query_limit--;
$google_seo_query_limit--;
$query = $db->query("SELECT url,id FROM ".TABLE_PREFIX."google_seo
WHERE active=1 AND idtype={$type} AND id<={$id}
AND url IN ('"
Expand Down Expand Up @@ -515,15 +514,15 @@ function google_seo_url_create($type, $ids)
}

// Set old entries for us to not active.
$db->google_seo_query_limit--;
$google_seo_query_limit--;
$db->write_query("UPDATE ".TABLE_PREFIX."google_seo
SET active=NULL
WHERE active=1
AND idtype={$type}
AND id={$id}");

// Insert new entry (while possibly replacing old ones).
$db->google_seo_query_limit--;
$google_seo_query_limit--;
$db->write_query("REPLACE INTO ".TABLE_PREFIX."google_seo
VALUES (active,idtype,id,url),
('1','{$type}','{$id}','".$db->escape_string($url)."')");
Expand Down Expand Up @@ -563,7 +562,7 @@ function google_seo_url_create($type, $ids)
function google_seo_url_optimize($type, $id)
{
global $db, $mybb, $settings, $cache;
global $google_seo_url_optimize, $google_seo_url_cache;
global $google_seo_url_optimize, $google_seo_url_cache, $google_seo_url;

switch(THIS_SCRIPT)
{
Expand All @@ -589,7 +588,7 @@ function google_seo_url_optimize($type, $id)
}
}

global $google_seo_index;
global $google_seo_index, $google_seo_query_limit;

if(!$google_seo_index)
{
Expand All @@ -603,7 +602,7 @@ function google_seo_url_optimize($type, $id)
if($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0)
{
$timesearch = TIME_NOW - $mybb->settings['wolcutoff'];
$db->google_seo_query_limit--;
$google_seo_query_limit--;
$query = $db->query("SELECT uid FROM ".TABLE_PREFIX."sessions
WHERE uid != '0' AND time > '$timesearch'");

Expand Down Expand Up @@ -857,7 +856,7 @@ function google_seo_url_optimize($type, $id)
// Clean up
foreach($google_seo_url_optimize as $key => $value)
{
if(!$db->google_seo_url[$key]['scheme'])
if(!$google_seo_url[$key]['scheme'])
{
unset($google_seo_url_optimize[$key]);
}
Expand All @@ -884,11 +883,11 @@ function google_seo_url_optimize($type, $id)
function google_seo_url_cache($type, $id)
{
global $db, $settings;
global $google_seo_url_cache, $google_seo_url_lazy;
global $google_seo_url_cache, $google_seo_url_lazy, $google_seo_query_limit, $google_seo_url;

// If it's not in the cache, try loading the cache.
if((empty($google_seo_url_cache) || empty($google_seo_url_cache[$type]) || empty($google_seo_url_cache[$type][$id]))
&& $db->google_seo_query_limit > 0)
&& $google_seo_query_limit > 0)
{
$google_seo_url_cache['dirty'] = 1;

Expand All @@ -907,7 +906,7 @@ function google_seo_url_cache($type, $id)

// Create a temporary placeholder (but working) URL.
$url = google_seo_expand(
$db->google_seo_url[$type]['lazy'],
$google_seo_url[$type]['lazy'],
array('id' => $id)
);

Expand Down Expand Up @@ -952,7 +951,7 @@ function google_seo_url_cache($type, $id)
$condition = implode(" OR ", $condition);

// Run database query.
$db->google_seo_query_limit--;
$google_seo_query_limit--;
$query = $db->query("SELECT $what
FROM ".TABLE_PREFIX."google_seo
WHERE active=1
Expand All @@ -965,7 +964,7 @@ function google_seo_url_cache($type, $id)
$rowtype = (int)$row['idtype'];
$google_seo_url_cache[$rowtype][$rowid] =
google_seo_url_finalize($row['url'],
$db->google_seo_url[$rowtype]['scheme']);
$google_seo_url[$rowtype]['scheme']);
unset($ids[$rowtype][$rowid]);
}

Expand All @@ -982,7 +981,7 @@ function google_seo_url_cache($type, $id)
}

// Return the cached entry for the originally requested type and id.
return @$google_seo_url_cache[$type][$id];
return $google_seo_url_cache[$type][$id];
}

/*
Expand Down Expand Up @@ -1086,9 +1085,9 @@ function google_seo_url_cache_hook()
*/
function google_seo_url_id($type, $url)
{
global $db, $settings;
global $db, $settings, $google_seo_query_limit;

$db->google_seo_query_limit--;
$google_seo_query_limit--;
$query = $db->query("SELECT id
FROM ".TABLE_PREFIX."google_seo
WHERE idtype={$type}
Expand All @@ -1107,7 +1106,7 @@ function google_seo_url_id($type, $url)
$urls[2] = $db->escape_string(google_seo_url_separate($urls[1]));
}

$db->google_seo_query_limit--;
$google_seo_query_limit--;
$query = $db->query("SELECT id
FROM ".TABLE_PREFIX."google_seo
WHERE idtype={$type}
Expand Down Expand Up @@ -1374,14 +1373,14 @@ function google_seo_url_merge_hook()
*/
function google_seo_url_after_merge_hook($arguments)
{
global $db;
global $db, $google_seo_query_limit;

$mergetid = (int)$arguments['mergetid'];
$tid = (int)$arguments['tid'];

// Integrate mergetid into tid:
$type = GOOGLE_SEO_THREAD;
$db->google_seo_query_limit--;
$google_seo_query_limit--;
$db->write_query("UPDATE ".TABLE_PREFIX."google_seo
SET active=NULL, id={$tid}
WHERE idtype={$type} AND id={$mergetid}");
Expand Down Expand Up @@ -1502,12 +1501,12 @@ function google_seo_url_thread($tid, $page=0, $action='')
function google_seo_url_post($pid, $tid=0)
{
global $db, $settings;
global $google_seo_url_tid;
global $google_seo_url_tid, $google_seo_query_limit;

if($settings['google_seo_url_threads'] && $pid > 0)
{
$tid = google_seo_tid($pid, $tid, $settings['google_seo_url_posts'],
$db->google_seo_query_limit);
$google_seo_query_limit);

if($tid > 0)
{
Expand Down

0 comments on commit dee08ef

Please sign in to comment.