Exemple #1
0
 /**
  * Invokes hook_mostpopular_service('throttles') on the given service to get
  * the default throttles to use for the currently-configured intervals.
  *
  * @param integer $sid
  *   The service ID.
  * @return array
  *   An array, hashed by $sid and by $iid, of the default throttle
  *   strtotime() strings.
  */
 public static function getDefaultThrottles($sid)
 {
     if (!isset(self::$default_throttles[$sid])) {
         $service = MostPopularService::fetch($sid);
         $intervals = MostPopularInterval::fetchAll();
         $options = array();
         foreach ($intervals as $interval) {
             $options[$interval->iid] = $interval->timestamp();
         }
         $out = module_invoke($service->module, 'mostpopular_service', 'throttles', $service->delta, $options);
         foreach ($intervals as $interval) {
             if (!isset($out[$interval->iid])) {
                 $out[$interval->iid] = '';
             }
         }
         self::$default_throttles[$sid] = $out;
     }
     return self::$default_throttles;
 }
Exemple #2
0
 /**
  * Fetches all of the available services from the enabled modules that define
  * them.
  */
 public static function fetchAvailable()
 {
     if (!isset(self::$availableList)) {
         self::$availableList = array();
         self::$enabledList = array();
         self::$disabledList = array();
         // Fetch all of the service definitions from the modules
         $modules = module_implements('mostpopular_service');
         foreach ($modules as $module) {
             $s = module_invoke($module, 'mostpopular_service', 'list');
             foreach ($s as $delta => $service) {
                 $service['module'] = $module;
                 $service['delta'] = $delta;
                 // Augment the service with stored data from the database
                 $sql = "SELECT * FROM {" . self::$table . "} ";
                 $sql .= "WHERE module = '%s' AND delta = '%s'";
                 $result = db_query($sql, $module, $delta);
                 if ($row = db_fetch_array($result)) {
                     foreach ($row as $key => $val) {
                         if (isset($val) && drupal_strlen(trim($val)) > 0) {
                             $service[$key] = $val;
                         }
                     }
                 }
                 $service = new MostPopularService($service);
                 // If we've never seen the service before, add it first
                 if ($service->new) {
                     $service->save();
                 }
                 // Store the service by module and delta.
                 self::$availableList[$module][$delta] = $service;
                 // Store the service by availability
                 if ($service->enabled) {
                     self::$enabledList[$service->sid] = $service;
                 } else {
                     self::$disabledList[$service->sid] = $service;
                 }
             }
         }
         // Sort the list of enabled services by weight
         uasort(self::$enabledList, '_mostpopular_service_sort');
     }
     return self::$availableList;
 }