コード例 #1
0
ファイル: appstore.php プロジェクト: NIIF/DiscoJuice-Backend
     header('Content-Type: image/png');
     echo $data['logo']->bin;
     exit;
 }
 $gk = new GateKeeperController($apiconfig['token']);
 $gk->requireToken()->requireUser();
 if (DiscoUtils::route('get', '^/apps$', $parameters, $body)) {
     $services = FeideService::getAll();
     usort($services, 'ss');
     $col = new Collection($services);
     $response = $col->getView(array('realm' => 'uninett.no'));
 } else {
     if (DiscoUtils::route('get', '^/apps/([^/]+)/([^/]+)$', $parameters, $qs)) {
         $realm = $parameters[1];
         $type = $parameters[2];
         $services = FeideService::getAll();
         usort($services, 'ss');
         $col = new ServiceCollection($services);
         if ($type === 'available') {
             $col->filterByRealm($realm, true);
         } else {
             if ($type === 'all') {
             } else {
                 if ($type === 'favs') {
                     $userid = $gk->getUserID();
                     $fav = Favourites::getByID($userid);
                     $col->filterByList($fav->get('favs'));
                 } else {
                     if ($type === 'potential') {
                         $col->filterByRealm($realm, false);
                         $col->filterByTarget('other', true);
コード例 #2
0
 function update()
 {
     $items = array();
     $cachefile = '/tmp/feide-services.json';
     if (file_exists($cachefile)) {
         $services = json_decode(file_get_contents($cachefile), true);
     } else {
         $url = 'https://api.feide.no/spinfo/0/all';
         $data = file_get_contents($url);
         file_put_contents($cachefile, $data);
         $services = json_decode($data, true);
     }
     /**
      * Load special file based upon Kind ID to entityID from kundeportalen / KIND.
      */
     global $BASE;
     $mapFile = dirname($BASE) . '/etc/entityIDmapping.json';
     $entityIDmapping = json_decode(file_get_contents($mapFile), true);
     /**
      * Load metadata...
      */
     $metadataFile = dirname($BASE) . '/var/dynamic/metadata-prod/saml20-sp-remote.php';
     require_once $metadataFile;
     $metadataId2entityID = array();
     foreach ($metadata as $entityID => $meta) {
         if (isset($meta['feide:kindID'])) {
             if (!isset($metadataId2entityID[$meta['feide:kindID']])) {
                 $metadataId2entityID[$meta['feide:kindID']] = array();
             }
             $metadataId2entityID[$meta['feide:kindID']][] = $entityID;
             // echo "entity id " . $meta['feide:kindID'] . '    ' . $entityID . "\n";
         }
     }
     // print_r($metadataId2entityID);
     // exit;
     $logocache = new LogoCache('feide');
     $items = array();
     foreach ($services as $k => $d) {
         // If we found a mapping from Kind ID to entities based upon metadat, use that
         if (isset($metadataId2entityID[$d['id']])) {
             $d['entityIDs'] = $metadataId2entityID[$d['id']];
             // If not, then use the mapping found in the external file.
         } else {
             $entityIDs = $this->getEntityIDs($d['id'], $entityIDmapping);
             if (!empty($entityIDs)) {
                 $d['entityIDs'] = $entityIDs;
             } else {
                 continue;
             }
             foreach ($entityIDs as $entityID) {
                 if (isset($metadata[$entityID]) && isset($metadata[$entityID]['logo'])) {
                     // feide/splogos/eu-supply_logo.jpg
                     if (preg_match('|feide/splogos/(.*)|', $metadata[$entityID]['logo'], $matches)) {
                         $d['logo'] = $matches[1];
                     }
                 }
             }
         }
         // $entityIDhash = sha1(join(',', $entityIDs));
         if (isset($d['logo'])) {
             // echo " " . $d['id'] . " logo => " . $d['logo'] . "\n";
             $src = dirname($BASE) . '/var/dynamic/splogos/' . $d['logo'];
             if (!file_exists($src)) {
                 DiscoUtils::error('Could not find local logo file ' . $src);
             } else {
                 $id = 'feide:sp:' . $d['id'];
                 $meta = array('type' => 'feide-sp');
                 if (count($entityIDs) === 1) {
                     $meta['entityID'] = $entityIDs[0];
                 }
                 // $id, $src, $meta, $localFile = false)
                 $ok = $logocache->getLogoURL($id, $src, $meta, true);
                 // $ok = $logocache->getLogo($this->entityId, $this->feed, $cl);
                 if (!empty($ok)) {
                     $d['icon'] = $ok;
                 }
             }
         } else {
             DiscoUtils::debug('No logo available for ' . $d['id']);
             // echo " " . $d['id'] . " ----- ----- ----- \n";
         }
         // echo "Dump"; print_r($d);
         // if ($i++ > 3) exit;
         // print_r($services[$k]);
         $item = new FeideService($d);
         $items[] = $item;
     }
     function arrSum($a, $b)
     {
         $res = array();
         foreach ($a as $k => $v) {
             if (isset($b[$k]) && isset($a[$k])) {
                 $res[] = $a[$k] + $b[$k];
             } else {
                 if (isset($a[$k])) {
                     $res[] = $a[$k];
                 } else {
                     $res[] = $b[$k];
                 }
             }
         }
         return $res;
     }
     // exit;
     $stats = $this->getStatisticsTotal();
     $statsfull = $this->getStatsAllWeeks(array_keys($stats));
     // print_r($statsfull); exit;
     foreach ($items as $item) {
         $entityIDs = $item->get('entityIDs');
         $total = 0;
         foreach ($entityIDs as $entityID) {
             if (isset($stats[$entityID])) {
                 $total += $stats[$entityID];
             }
         }
         $item->set('statistics', $total);
         $fullStat = array();
         foreach ($entityIDs as $entityID) {
             if (isset($statsfull[$entityID])) {
                 $fullStat = arrSum($statsfull[$entityID], $total);
                 // $total += $stats[$entityID];
             }
         }
         $item->set('statistics-full', $fullStat);
         // $item->save();
         // print_r($item); exit;
     }
     // exit;
     foreach ($items as $item) {
         $item->save();
         // print_r($item); exit;
     }
 }