| 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 |
$result = $this->dbDriver->select("SELECT count(*) blocksCount FROM #__cjtoolbox_blocks WHERE state = '{$state}' AND type='{$type}';", ARRAY_A); |
| 51 |
return $result[0]['blocksCount']; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* put your comment there... |
| 56 |
* |
| 57 |
*/ |
| 58 |
public function getFeed() { |
| 59 |
// Initialize. |
| 60 |
$widgetTransitFeed = get_option(self::CJT_LASTEST_SCRIPT_OPTION_NAME, array( |
| 61 |
'scripts' => array(array('title' => 'cjt-script.com', 'link' => 'http://' . cssJSToolbox::CJT_SCRTIPS_WEB_SITE_DOMAIN)), |
| 62 |
'news' => array(array('title' => 'css-javascript-toolbox.com', 'link' => 'http://' . cssJSToolbox::CJT_WEB_SITE_DOMAIN)), |
| 63 |
'time' => 0 |
| 64 |
)); |
| 65 |
// Only if cache is expires read feed from server. |
| 66 |
if ((time() - $widgetTransitFeed['time']) > self::LATEST_SCRIPT_EXPIRES) { |
| 67 |
# Get Latest Scripts/Packages from feed. |
| 68 |
$scriptsFeed = new CJT_Framework_Wordpress_Feed( |
| 69 |
cssJSToolbox::CJT_SCRTIPS_WEB_SITE_DOMAIN, |
| 70 |
'forums/script-packages/user-scripts/feed/', |
| 71 |
array('title', 'link') |
| 72 |
); |
| 73 |
if (!$scriptsFeed->isError()) { |
| 74 |
$widgetTransitFeed['scripts'] = $scriptsFeed->getLatestItems(1); |
| 75 |
} |
| 76 |
# Get latest news from news feed. |
| 77 |
$newsFeed = new CJT_Framework_Wordpress_Feed( |
| 78 |
cssJSToolbox::CJT_WEB_SITE_DOMAIN, |
| 79 |
'category/news/feed/', |
| 80 |
array('title', 'link', 'description') |
| 81 |
); |
| 82 |
if (!$newsFeed->isError()) { |
| 83 |
$widgetTransitFeed['news'] = $newsFeed->getLatestItems(1); |
| 84 |
} |
| 85 |
# Store cache time. |
| 86 |
$widgetTransitFeed['time'] = time(); |
| 87 |
update_option(self::CJT_LASTEST_SCRIPT_OPTION_NAME, $widgetTransitFeed); |
| 88 |
} |
| 89 |
return $widgetTransitFeed; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* put your comment there... |
| 94 |
* |
| 95 |
*/ |
| 96 |
public function getPackagesCount() { |
| 97 |
$result = $this->dbDriver->select('SELECT count(*) packagesCount FROM #__cjtoolbox_packages;', ARRAY_A); |
| 98 |
return $result[0]['packagesCount']; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* put your comment there... |
| 103 |
* |
| 104 |
*/ |
| 105 |
public function getTemplatesCount() { |
| 106 |
$result = $this->dbDriver->select('SELECT count(*) templatesCount FROM #__cjtoolbox_templates WHERE (attributes & 1) = 0;', ARRAY_A); |
| 107 |
return $result[0]['templatesCount']; |
| 108 |
} |
| 109 |
|
| 110 |
} // End class. |