Exemplo n.º 1
0
 /**
  * Tests Gadget->getJsLibraries()
  */
 public function testGetJsLibraries()
 {
     $this->Gadget->addJsLibrary('A');
     $this->Gadget->addJsLibrary('B');
     $this->Gadget->addJsLibrary('C');
     $this->Gadget->addJsLibrary('D');
     $string = implode('', $this->Gadget->getJsLibraries());
     $this->assertEquals('ABCD', $string);
 }
Exemplo n.º 2
0
 /**
  * generates the library string (core:caja:etc.js) including a checksum of all the
  * javascript content (?v=<sha1 of js) for cache busting
  *
  * @param string $libs
  * @param Gadget $gadget
  * @return string the list of libraries in core:caja:etc.js?v=checksum> format
  */
 private function getJsUrl($libs, $gadget)
 {
     $buf = '';
     if (!is_array($libs) || !count($libs)) {
         $buf = 'core';
     } else {
         $firstDone = false;
         foreach ($libs as $lib) {
             if ($firstDone) {
                 $buf .= ':';
             } else {
                 $firstDone = true;
             }
             $buf .= $lib;
         }
     }
     // Build a version string from the sha1() checksum of all included javascript
     // to ensure the client always has the right version
     $inlineJs = '';
     foreach ($gadget->getJsLibraries() as $library) {
         $type = $library->getType();
         if ($type != 'URL') {
             $inlineJs .= $library->getContent() . "\n";
         }
     }
     $buf .= ".js?v=" . sha1($inlineJs);
     return $buf;
 }
Exemplo n.º 3
0
 /**
  * Appends the javascript features configuration string
  *
  * @param Gadget $gadget
  * @param unknown_type $hasForcedLibs
  * @return string
  */
 private function appendJsConfig(Gadget $gadget, $hasForcedLibs)
 {
     $container = $this->context->getContainer();
     $containerConfig = $this->context->getContainerConfig();
     //TODO some day we should parse the forcedLibs too, and include their config selectivly as well for now we just include everything if forced libs is set.
     if ($hasForcedLibs) {
         $gadgetConfig = $containerConfig->getConfig($container, 'gadgets.features');
     } else {
         $gadgetConfig = array();
         $featureConfig = $containerConfig->getConfig($container, 'gadgets.features');
         foreach ($gadget->getJsLibraries() as $library) {
             $feature = $library->getFeatureName();
             if (!isset($gadgetConfig[$feature]) && !empty($featureConfig[$feature])) {
                 $gadgetConfig[$feature] = $featureConfig[$feature];
             }
         }
     }
     // Add gadgets.util support. This is calculated dynamically based on request inputs.
     // See java/org/apache/shindig/gadgets/render/RenderingContentRewriter.java for reference.
     $requires = array();
     foreach ($gadget->features as $feature) {
         $requires[$feature] = new EmptyClass();
     }
     $gadgetConfig['core.util'] = $requires;
     if (isset($gadgetConfig['osml'])) {
         unset($gadgetConfig['osml']);
     }
     if (!isset($gadgetConfig['osapi.services']) || count($gadgetConfig['osapi.services']) == 1) {
         // this should really be set in config/container.js, but if not, we build a complete default set so at least most of it works out-of-the-box
         $gadgetConfig['osapi.services'] = array('gadgets.rpc' => array('container.listMethods'), 'http://%host%/social/rpc' => array("messages.update", "albums.update", "activities.delete", "activities.update", "activities.supportedFields", "albums.get", "activities.get", "mediaitems.update", "messages.get", "appdata.get", "system.listMethods", "people.supportedFields", "messages.create", "mediaitems.delete", "mediaitems.create", "people.get", "people.create", "albums.delete", "messages.delete", "appdata.update", "activities.create", "mediaitems.get", "albums.create", "appdata.delete", "people.update", "appdata.create"), 'http://%host%/gadgets/api/rpc' => array('cache.invalidate'));
     }
     return "gadgets.config.init(" . json_encode($gadgetConfig) . ");\n";
 }