| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version $ Id; ----.php 21-03-2012 03:22:10 Ahmed Said $ |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* No direct access. |
| 8 |
*/ |
| 9 |
defined('ABSPATH') or die("Access denied"); |
| 10 |
|
| 11 |
/** |
| 12 |
* |
| 13 |
* @author Ahmed Said |
| 14 |
* @version 6 |
| 15 |
*/ |
| 16 |
class CJTStatisticsMetaboxModel { |
| 17 |
|
| 18 |
/** |
| 19 |
* |
| 20 |
*/ |
| 21 |
const CJT_LASTEST_SCRIPT_OPTION_NAME = 'CJTStatisticsMetaboxModel.latestscripts'; |
| 22 |
|
| 23 |
/** |
| 24 |
* |
| 25 |
*/ |
| 26 |
const LATEST_SCRIPT_EXPIRES = 86400; |
| 27 |
|
| 28 |
/** |
| 29 |
* put your comment there... |
| 30 |
* |
| 31 |
* @var mixed |
| 32 |
*/ |
| 33 |
protected $dbDriver; |
| 34 |
|
| 35 |
/** |
| 36 |
* put your comment there... |
| 37 |
* |
| 38 |
*/ |
| 39 |
public function __construct() { |
| 40 |
$this->dbDriver =& cssJSToolbox::getInstance()->getDBDriver(); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* put your comment there... |
| 45 |
* |
| 46 |
* @param mixed $state |
| 47 |
* @param mixed $type |
| 48 |
*/ |
| 49 |
public function getBlocksCount($state, $type) |
| 50 |
{ |
| 51 |
|
| 52 |
$query = " SELECT count(*) blocksCount |
| 53 |
FROM #__cjtoolbox_blocks |
| 54 |
WHERE backupId IS NULL AND state = '{$state}' AND type='{$type}';"; |
| 55 |
|
| 56 |
$result = $this->dbDriver->select($query, ARRAY_A); |
| 57 |
|
| 58 |
$count = $result[0]['blocksCount']; |
| 59 |
|
| 60 |
return $count; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* put your comment there... |
| 65 |
* |
| 66 |
*/ |
| 67 |
public function getCodeFilesCount() |
| 68 |
{ |
| 69 |
|
| 70 |
$query = ' SELECT count(*) codeFilesCount |
| 71 |
FROM #__cjtoolbox_blocks b LEFT JOIN #__cjtoolbox_block_files f |
| 72 |
ON b.id = f.blockId |
| 73 |
WHERE b.BackupId IS NULL AND b.type != "revision";'; |
| 74 |
|
| 75 |
$result = $this->dbDriver->select($query, ARRAY_A); |
| 76 |
|
| 77 |
$count = $result[0]['codeFilesCount']; |
| 78 |
|
| 79 |
return $count; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* put your comment there... |
| 84 |
* |
| 85 |
*/ |
| 86 |
public function getFeed() { |
| 87 |
// Initialize. |
| 88 |
$widgetTransitFeed = get_option(self::CJT_LASTEST_SCRIPT_OPTION_NAME, array('time' => 0)); |
| 89 |
// Only if cache is expires read feed from server. |
| 90 |
if ((time() - $widgetTransitFeed['time']) > self::LATEST_SCRIPT_EXPIRES) { |
| 91 |
# INitiaize |
| 92 |
$fieldsNames = array('title', 'link', 'description', 'pubDate'); |
| 93 |
# Get Latest Scripts/Packages from feed. |
| 94 |
$scriptsFeed = new CJT_Framework_Wordpress_Feed(cssJSToolbox::CJT_WEB_SITE_DOMAIN, 'category/scripts/feed/', $fieldsNames); |
| 95 |
$widgetTransitFeed['scripts'] = $scriptsFeed->getLatestItems(7); |
| 96 |
# Get latest extensions from feed |
| 97 |
$extensionsFeed = new CJT_Framework_Wordpress_Feed(cssJSToolbox::CJT_WEB_SITE_DOMAIN, 'category/extensions/feed/', $fieldsNames); |
| 98 |
$widgetTransitFeed['extensions'] = $extensionsFeed->getLatestItems(7); |
| 99 |
# Get latest news from news feed. |
| 100 |
$newsFeed = new CJT_Framework_Wordpress_Feed(cssJSToolbox::CJT_WEB_SITE_DOMAIN, 'category/news/feed/', $fieldsNames); |
| 101 |
$widgetTransitFeed['news'] = $newsFeed->getLatestItems(1); |
| 102 |
# Cache only if there is no errors. |
| 103 |
if (!$newsFeed->isError() && !$scriptsFeed->isError() && !$extensionsFeed->isError()) { |
| 104 |
# Store cache time. |
| 105 |
$widgetTransitFeed['time'] = time(); |
| 106 |
update_option(self::CJT_LASTEST_SCRIPT_OPTION_NAME, $widgetTransitFeed); |
| 107 |
} |
| 108 |
} |
| 109 |
# For versions 8.0 it will produce PHP notice because extensions item is not being exists in the cache |
| 110 |
# The error will be always visible until next caching cycle! |
| 111 |
# temporary solution |
| 112 |
else if (!isset($widgetTransitFeed['extensions'])) { |
| 113 |
$widgetTransitFeed['extensions'] = array(); |
| 114 |
} |
| 115 |
# Returns |
| 116 |
return $widgetTransitFeed; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* put your comment there... |
| 121 |
* |
| 122 |
*/ |
| 123 |
public function getPackagesCount() { |
| 124 |
$result = $this->dbDriver->select('SELECT count(*) packagesCount FROM #__cjtoolbox_packages;', ARRAY_A); |
| 125 |
return $result[0]['packagesCount']; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* put your comment there... |
| 130 |
* |
| 131 |
*/ |
| 132 |
public function getTemplatesCount() { |
| 133 |
$result = $this->dbDriver->select('SELECT count(*) templatesCount FROM #__cjtoolbox_templates WHERE (attributes & 1) = 0;', ARRAY_A); |
| 134 |
return $result[0]['templatesCount']; |
| 135 |
} |
| 136 |
|
| 137 |
} // End class. |