Skip to content

Commit

Permalink
More uneeded stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Suki <suki@missallsunday.com>
  • Loading branch information
MissAllSunday committed Dec 20, 2014
1 parent 8b0397b commit 65bd857
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 71 deletions.
94 changes: 24 additions & 70 deletions Sources/ModSite/ModSiteDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ public function add($data)
if (empty($data))
return false;

/* Clear the cache */
$this->cleanCache();

$smcFunc['db_insert']('',
'{db_prefix}'. $this->_table['name'],
array('name' => 'string-255'),
Expand All @@ -70,9 +67,6 @@ public function edit($data)
if (empty($data))
return false;

/* Clear the cache */
$this->cleanCache();

$smcFunc['db_query']('', '
UPDATE {db_prefix}' . ($this->_table['name']) . '
SET name = {string:name}
Expand Down Expand Up @@ -126,22 +120,17 @@ public function getAll($start, $maxIndex)

public function getSingle($id)
{
global $smcFunc, $scripturl, $txt;
global $smcFunc;

/* Can we avoid another query? */
if (($return = cache_get_data(modsite::$name .'_all', 3600)) != null)
if (in_array($id, array_keys($return)))
return $return[$id];
if (empty($id))
return array();

/* No? :( */
$result = $smcFunc['db_query']('', '
SELECT '. (implode(', ', $this->_table['columns'])) .'
FROM {db_prefix}' . ($this->_table['name']) . '
WHERE id = {int:id}
LIMIT {int:limit}',
WHERE id = {int:id}',
array(
'id' => (int) $id,
'limit' => 1
'id' => $id,
)
);

Expand All @@ -156,45 +145,38 @@ public function getSingle($id)

$smcFunc['db_free_result']($result);

/* Done? */
// Done!
return $return;
}

public function getBy($column, $value)
{
global $smcFunc, $scripturl, $txt;

/* We need both */
// We need both.
if (empty($column) || empty($value))
return false;

/* Use the cache when possible */
if (($return = cache_get_data(modsite::$name .'_'. $column.'_'. $value, 3600)) == null)
{
// Get the data as requested.
$result = $smcFunc['db_query']('', '
SELECT '. (implode(', ', $this->_table['columns'])) .'
FROM {db_prefix}' . ($this->_table['name']) . '
WHERE '. ($column) .' = '. ($value) .'',
array()
);

/* Get the data as requested */
$result = $smcFunc['db_query']('', '
SELECT '. (implode(', ', $this->_table['columns'])) .'
FROM {db_prefix}' . ($this->_table['name']) . '
WHERE '. ($column) .' = '. ($value) .'',
array()
while ($row = $smcFunc['db_fetch_assoc']($result))
$return[$row['id']] = array(
'id' => $row['id'],
'name' => $row['name'],
'info' => $this->parse($row['name']),
'category' => $this->getSingleCat($row['cat']),
'downloads' => $row['downloads'],
);

while ($row = $smcFunc['db_fetch_assoc']($result))
$return[$row['id']] = array(
'id' => $row['id'],
'name' => $row['name'],
'info' => $this->parse($row['name']),
'category' => $this->getSingleCat($row['cat']),
'downloads' => $row['downloads'],
);

$smcFunc['db_free_result']($result);

cache_put_data(modsite::$name .'_'. $column.'_'. $value, $return, 3600);
}
$smcFunc['db_free_result']($result);

/* Done? */
// Done!
return $return;
}

Expand All @@ -205,9 +187,6 @@ public function updateCount($id)
if (empty($id))
return false;

/* Clear the cache */
$this->cleanCache();

$smcFunc['db_query']('', '
UPDATE {db_prefix}' . ($this->_table['name']) . '
SET downloads = downloads + 1
Expand All @@ -226,9 +205,6 @@ public function delete($id)
if (empty($id))
return false;

/* Clear the cache */
$this->cleanCache();

$smcFunc['db_query']('', '
DELETE FROM {db_prefix}' . ($this->_table['table']) .'
WHERE id = {int:id}',
Expand Down Expand Up @@ -273,26 +249,4 @@ public function getPermissions($type, $fatal_error = false)
elseif ($fatal_error == false && in_array(1, $allowed))
return true;
}

protected function cleanCache()
{
cache_put_data(modsite::$name .'_all', null, 3600);
}

public function truncateString($string, $limit, $break = ' ', $pad = '...')
{
if(empty($limit))
$limit = 30;

// return with no change if string is shorter than $limit
if(strlen($string) <= $limit)
return $string;

// is $break present between $limit and the end of the string?
if(false !== ($breakpoint = strpos($string, $break, $limit)))
if($breakpoint < strlen($string) - 1)
$string = substr($string, 0, $breakpoint) . $pad;

return $string;
}
}
}
2 changes: 1 addition & 1 deletion Sources/ModSite/ModSiteParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct()

$this->_jsonDir = $this->enable('json_dir') ? '/'. $this->setting('json_dir') .'/%s.json' : '%s';

/* Get the cats! */
// Get the cats!
$this->getCats();
}

Expand Down

0 comments on commit 65bd857

Please sign in to comment.