PluginProbe
CSS & JavaScript Toolbox / 8.0.3
CSS & JavaScript Toolbox v8.0.3
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / models / statistics-metabox.php

statistics-metabox.php in CSS & JavaScript Toolbox 8.0.3, at models/statistics-metabox.php

109 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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('time' => 0));
61 // Only if cache is expires read feed from server.
62 if ((time() - $widgetTransitFeed['time']) > self::LATEST_SCRIPT_EXPIRES) {
63 # INitiaize
64 $fieldsNames = array('title', 'link', 'description');
65 # Get Latest Scripts/Packages from feed.
66 $scriptsFeed = new CJT_Framework_Wordpress_Feed(cssJSToolbox::CJT_WEB_SITE_DOMAIN, 'category/scripts/feed/', $fieldsNames);
67 $widgetTransitFeed['scripts'] = $scriptsFeed->getLatestItems(7);
68 # Get latest extensions from feed
69 $extensionsFeed = new CJT_Framework_Wordpress_Feed(cssJSToolbox::CJT_WEB_SITE_DOMAIN, 'category/extensions/feed/', $fieldsNames);
70 $widgetTransitFeed['extensions'] = $extensionsFeed->getLatestItems(7);
71 # Get latest news from news feed.
72 $newsFeed = new CJT_Framework_Wordpress_Feed(cssJSToolbox::CJT_WEB_SITE_DOMAIN, 'category/news/feed/', $fieldsNames);
73 $widgetTransitFeed['news'] = $newsFeed->getLatestItems(1);
74 # Cache only if there is no errors.
75 if (!$newsFeed->isError() && !$scriptsFeed->isError() && !$extensionsFeed->isError()) {
76 # Store cache time.
77 $widgetTransitFeed['time'] = time();
78 update_option(self::CJT_LASTEST_SCRIPT_OPTION_NAME, $widgetTransitFeed);
79 }
80 }
81 # For versions 8.0 it will produce PHP notice because extensions item is not being exists in the cache
82 # The error will be always visible until next caching cycle!
83 # temporary solution
84 else if (!isset($widgetTransitFeed['extensions'])) {
85 $widgetTransitFeed['extensions'] = array();
86 }
87 # Returns
88 return $widgetTransitFeed;
89 }
90
91 /**
92 * put your comment there...
93 *
94 */
95 public function getPackagesCount() {
96 $result = $this->dbDriver->select('SELECT count(*) packagesCount FROM #__cjtoolbox_packages;', ARRAY_A);
97 return $result[0]['packagesCount'];
98 }
99
100 /**
101 * put your comment there...
102 *
103 */
104 public function getTemplatesCount() {
105 $result = $this->dbDriver->select('SELECT count(*) templatesCount FROM #__cjtoolbox_templates WHERE (attributes & 1) = 0;', ARRAY_A);
106 return $result[0]['templatesCount'];
107 }
108
109 } // End class.