Esempio n. 1
0
 /** @test */
 public function it_is_configurable_via_constructor()
 {
     $resolver = new Resolver(array('mapping' => array('width' => 'w', 'dpr' => 'device-pixel-ratio'), 'whitelist' => array('width', 'dpr')));
     $params = $resolver->resolve(array('HTTP_WIDTH' => '123', 'HTTP_DPR' => '2', 'HTTP_FOO' => 'bar'));
     $expected = array('device-pixel-ratio' => '2', 'w' => '123');
     $this->assertEquals($expected, $params);
 }
Esempio n. 2
0
 public function testCanResolveFalse()
 {
     require_once __DIR__ . '/../helpers/TestCommandHandler.php';
     $resolver = new Resolver();
     $result = $resolver->canResolve('UnknownClass');
     $this->assertFalse($result);
 }
 /**
  * {@inheritdoc}
  */
 public function isActive(array $options = [])
 {
     $resolver = new Resolver();
     foreach ($options as $name => $resolver_options) {
         $resolver->addResolver($this->feature_container->getResolver($name), $resolver_options);
     }
     return $resolver->resolve(Resolver::STRATEGY_AFFIRMATIVE);
 }
 /**
  * Create and resolve a feature based on the name and the options.
  *
  * Options array should be structured as follows:
  * [
  *     resolver1 => [<resolver specific options>],
  *     resolver2 => [<resolver specific options>],
  *     // etc.
  * ]
  *
  * @param string $feature_name
  * @param array  $options
  * @return Feature
  */
 public function createFeature($feature_name, array $options = [])
 {
     $resolver = new Resolver();
     foreach ($options as $name => $resolver_options) {
         $resolver->addResolver($this->feature_container->getResolver($name), $resolver_options);
     }
     return new ResolvableFeature($feature_name, $resolver);
 }
 public function __construct()
 {
     global $bootstrapSettings;
     foreach ($bootstrapSettings->menus as $menu) {
         $dir = __DIR__ . '/../menus/' . $menu->name;
         $newMenu = new stdClass();
         $newMenu->slug = $menu->name;
         $newMenu->location = $menu->location;
         $newMenu->items = [];
         foreach ($this->getFiles($dir) as $file) {
             $menuItem = new \stdClass();
             $menuItem->done = false;
             $menuItem->id = 0;
             $menuItem->parentId = 0;
             $menuItem->slug = $file;
             $menuItem->meta = unserialize(file_get_contents($dir . '/' . $file));
             $newMenu->items[] = $menuItem;
         }
         usort($newMenu->items, function ($a, $b) {
             return (int) $a->meta->menu_order - (int) $b->meta->menu_order;
         });
         $this->menus[] = $newMenu;
     }
     $baseUrl = get_option('siteurl');
     $neutralUrl = 'NEUTRALURL';
     Resolver::field_search_replace($this->menus, $neutralUrl, $baseUrl);
     $this->process();
 }
Esempio n. 6
0
 function __construct($url)
 {
     parent::__construct($url);
     $this->tag = @$_REQUEST['tag'];
     // find all blog items
     $this->pages = Resolver::find_all_pages('blog');
 }
Esempio n. 7
0
 /**
  * Retrieve template name or template resolver
  *
  * @param  null|string $name
  * @return string|Resolver
  */
 public function resolver($name = null)
 {
     if ($name) {
         return $this->templateResolver->resolve($name);
     }
     return $this->templateResolver;
 }
 public function __construct()
 {
     $this->bootstrap = Bootstrap::getInstance();
     $this->import = Import::getInstance();
     $this->resolver = Resolver::getInstance();
     $dir = BASEPATH . '/bootstrap/sidebars';
     foreach ($this->bootstrap->getFiles($dir) as $sidebar) {
         $subdir = BASEPATH . "/bootstrap/sidebars/{$sidebar}";
         $newSidebar = new \stdClass();
         $newSidebar->slug = $sidebar;
         $newSidebar->items = array();
         $newSidebar->meta = unserialize(file_get_contents($subdir . '/meta'));
         foreach ($newSidebar->meta as $key => $widgetRef) {
             $widget = new \stdClass();
             $parts = explode('-', $widgetRef);
             $ord = end($parts);
             $type = substr($widgetRef, 0, -1 * strlen('-' . $ord));
             $widget->type = $type;
             $widget->ord = $ord;
             $widget->meta = unserialize(file_get_contents($subdir . '/' . $widgetRef));
             $newSidebar->items[] = $widget;
         }
         $this->sidebars[] = $newSidebar;
     }
     $baseUrl = get_option('siteurl');
     $neutralUrl = Bootstrap::NETURALURL;
     $this->resolver->fieldSearchReplace($this->sidebars, Bootstrap::NETURALURL, $this->import->baseUrl);
     $this->process();
 }
Esempio n. 9
0
 public function __construct()
 {
     $this->bootstrap = Bootstrap::getInstance();
     $this->import = Import::getInstance();
     $this->resolver = Resolver::getInstance();
     foreach ($this->bootstrap->appSettings->wpbootstrap->menus as $menu => $locations) {
         $dir = BASEPATH . "/bootstrap/menus/{$menu}";
         $newMenu = new \stdClass();
         $newMenu->slug = $menu;
         $newMenu->locations = $locations;
         $newMenu->items = array();
         foreach ($this->getFiles($dir) as $file) {
             $menuItem = new \stdClass();
             $menuItem->done = false;
             $menuItem->id = 0;
             $menuItem->parentId = 0;
             $menuItem->slug = $file;
             $menuItem->menu = unserialize(file_get_contents($dir . '/' . $file));
             $newMenu->items[] = $menuItem;
         }
         usort($newMenu->items, function ($a, $b) {
             return (int) $a->menu->menu_order - (int) $b->menu->menu_order;
         });
         $this->menus[] = $newMenu;
     }
     $baseUrl = get_option('siteurl');
     $neutralUrl = Bootstrap::NETURALURL;
     $this->resolver->fieldSearchReplace($this->menus, Bootstrap::NETURALURL, $this->import->baseUrl);
     $this->process();
 }
Esempio n. 10
0
 public function __construct()
 {
     if (PHP_SAPI != 'cli') {
         try {
             $resolver = new Resolver();
             $this->extension = $resolver->getExtensionFromURL();
             $this->module = Camelizer::firstToUpper($resolver->getModule());
             $this->action = Camelizer::firstToLower($resolver->getAction());
         } catch (ResolverException $re) {
             $this->extension = 'tao';
         }
     }
     $this->epoch = time();
     $this->user = common_session_SessionManager::getSession()->getUserUri();
     $this->script = $_SERVER['PHP_SELF'];
     $this->system = new common_profiler_System();
 }
 /**
  * Constructor. Please use only getInstance to retrieve the single instance.
  * 
  * @see Context#getInstance
  */
 private function __construct()
 {
     $this->request = new Request();
     $this->response = new Response();
     $this->viewData = array();
     $this->behaviors = array();
     if (PHP_SAPI != 'cli') {
         try {
             $resolver = new Resolver();
             $this->extensionName = $resolver->getExtensionFromURL();
             $this->moduleName = Camelizer::firstToUpper($resolver->getModule());
             $this->actionName = Camelizer::firstToLower($resolver->getAction());
         } catch (ResolverException $re) {
             $this->extensionName = 'tao';
         }
     }
 }
Esempio n. 12
0
 public function testMatches()
 {
     $resolver = new Resolver('pattern', 'translation');
     $this->assertTrue($resolver->matches('pattern'));
     $this->assertTrue($resolver->matches('pattern', 'translation'));
     $this->assertFalse($resolver->matches('other_pattern', 'translation'));
     $this->assertFalse($resolver->matches('pattern', 'other_translation'));
     $this->assertFalse($resolver->matches('other_pattern', 'other_translation'));
     $this->assertFalse($resolver->matches('other_pattern'));
 }
 /**
  * 
  * (non-PHPdoc)
  * @see GenerisActionEnforcer::getControllerClass()
  */
 protected function getControllerClass()
 {
     $resolver = new Resolver();
     $relUrl = $resolver->getRelativeUrl();
     $controllerClass = null;
     foreach ($this->getRoutes() as $path => $ns) {
         $path = trim($path, '/');
         if (substr($relUrl, 0, strlen($path)) == $path) {
             $rest = trim(substr($relUrl, strlen($path)), '/');
             if (!empty($rest)) {
                 $parts = explode('/', $rest, 2);
                 return $ns . '\\' . $parts[0];
             } elseif (defined('DEFAULT_MODULE_NAME')) {
                 return $ns . '\\' . DEFAULT_MODULE_NAME;
             }
         }
     }
     // DEFAULT_MODULE_NAME
     // no explicit route found
     return parent::getControllerClass();
 }
Esempio n. 14
0
 public function export()
 {
     $this->bootstrap = Bootstrap::getInstance();
     $this->resolver = Resolver::getInstance();
     $this->extractMedia = new Extractmedia();
     $this->bootstrap->init();
     $this->bootstrap->includeWordPress();
     $this->mediaIds = array();
     $this->baseUrl = get_option('siteurl');
     $this->exportSettings();
     $this->exportContent();
 }
Esempio n. 15
0
 private static function find_all_pages_($path, &$pages)
 {
     foreach (new DirectoryIterator($path) as $file) {
         if ($file->isDot()) {
             continue;
         }
         if ($file->isDir()) {
             Resolver::find_all_pages_($file->getPathname(), $pages);
         } elseif (preg_match('@[.](txt|lhs)$@', $file->getFilename())) {
             $pages[] = new TextFilePage('', $file->getPathname(), false);
         }
     }
 }
Esempio n. 16
0
 public function import()
 {
     error_reporting(-1);
     $this->bootstrap = Bootstrap::getInstance();
     $this->resolver = Resolver::getInstance();
     $this->bootstrap->init();
     $this->bootstrap->includeWordPress();
     require_once $this->bootstrap->localSettings->wppath . '/wp-admin/includes/image.php';
     $this->baseUrl = get_option('siteurl');
     $this->uploadDir = wp_upload_dir();
     $this->importSettings();
     $this->importContent();
     // references
     $this->resolveMetaReferences();
     $this->resolvePostReferences();
     $this->resolveOptionReferences();
 }
 public function __construct($configItem)
 {
     global $bootstrapSettings;
     $this->type = $configItem;
     foreach ($bootstrapSettings->{$configItem} as $slug) {
         $newPost = new \stdClass();
         $newPost->done = false;
         $newPost->id = 0;
         $newPost->parentId = 0;
         $newPost->slug = $slug;
         $dir = __DIR__ . '/../pages/' . $slug;
         $newPost->meta = unserialize(file_get_contents($dir . '/meta'));
         $newPost->content = file_get_contents($dir . '/content');
         $this->posts[] = $newPost;
     }
     $baseUrl = get_option('siteurl');
     $neutralUrl = 'NEUTRALURL';
     Resolver::field_search_replace($this->posts, $neutralUrl, $baseUrl);
     $this->process();
 }
Esempio n. 18
0
 public function __construct()
 {
     $this->bootstrap = Bootstrap::getInstance();
     $this->import = Import::getInstance();
     $this->resolver = Resolver::getInstance();
     $dir = BASEPATH . '/bootstrap/posts';
     foreach ($this->bootstrap->getFiles($dir) as $postType) {
         foreach ($this->bootstrap->getFiles($dir . '/' . $postType) as $slug) {
             $newPost = new \stdClass();
             $newPost->done = false;
             $newPost->id = 0;
             $newPost->parentId = 0;
             $newPost->slug = $slug;
             $file = BASEPATH . "/bootstrap/posts/{$postType}/{$slug}";
             $newPost->post = unserialize(file_get_contents($file));
             $this->posts[] = $newPost;
         }
     }
     $this->resolver->fieldSearchReplace($this->posts, Bootstrap::NETURALURL, $this->import->baseUrl);
     $this->process();
 }
Esempio n. 19
0
 function __construct($root, $tag = false)
 {
     $this->pages = Resolver::find_all_pages($root);
     $this->tag = $tag;
 }
 public function testDefinitions()
 {
     $serviceDefinitionClass = new core_kernel_classes_Class(CLASS_SERVICESDEFINITION);
     foreach ($serviceDefinitionClass->getInstances(true) as $serviceDefinition) {
         if ($serviceDefinition->getUri() == 'http://www.tao.lu/Ontologies/TAODelivery.rdf#ServiceTestContainer' || $serviceDefinition->getUri() == 'http://www.tao.lu/Ontologies/TAOTest.rdf#FakeItemRunner') {
             // don't test the item / testcontainer since it's not a real service
             continue;
         }
         $serviceDefinitionUrl = $serviceDefinition->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_SUPPORTSERVICES_URL));
         $this->assertNotNull($serviceDefinitionUrl);
         $this->assertTrue(!empty($serviceDefinitionUrl));
         $fullUri = ROOT_URL . ltrim($serviceDefinitionUrl, '/');
         $resolver = new Resolver($fullUri);
         $ext = common_ext_ExtensionsManager::singleton()->getExtensionById($resolver->getExtensionFromURL());
         $controller = $ext->getModule($resolver->getModule());
         $this->assertTrue(method_exists($controller, $resolver->getAction()), 'action of service definition "' . $serviceDefinition->getLabel() . '" does not exist');
     }
 }
 /**
  * Some actions should not be redirected (such as retrieving requireJs config)
  *
  * @return array
  */
 protected function getExcludedRoutes()
 {
     $result = $this->excludedRoutes;
     $resolver = new \Resolver($this->getTransformedUrl());
     $result[] = ['extension' => $resolver->getExtensionFromURL(), 'module' => $resolver->getModule(), 'action' => $resolver->getAction()];
     return $result;
 }
Esempio n. 22
0
 /**
  * Test default object creation.
  */
 public function testClass()
 {
     // Note: ResolverTestExampleService is implemented at the bottom of this file.
     $obj = $this->resolver->get('Civi\\Core\\ResolverTestExampleService');
     $this->assertTrue($obj instanceof ResolverTestExampleService);
 }
Esempio n. 23
0
 /**
  * Some actions should not be redirected (such as retrieving requireJs config)
  * @return array
  */
 private function getExcludedRoutes()
 {
     $result = $this->excludedRoutes;
     $resolver = new \Resolver($this->url);
     $result[] = ['extension' => $resolver->getExtensionFromURL(), 'module' => $resolver->getModule(), 'action' => $resolver->getAction()];
     return $result;
 }
Esempio n. 24
0
    }
}
//menus
foreach ($bootstrapSettings->menus as $menu) {
    wp_set_current_user(1);
    $loggedInmenuItems = wp_get_nav_menu_items($menu->name);
    wp_set_current_user(0);
    $notloggedInmenuItems = wp_get_nav_menu_items($menu->name);
    $menuItems = array_merge($loggedInmenuItems, $notloggedInmenuItems);
    $dir = __DIR__ . '/menus/' . $menu->name;
    array_map('unlink', glob("{$dir}/*"));
    @mkdir($dir, 0777, true);
    foreach ($menuItems as $menuItem) {
        $obj = get_post($menuItem->ID);
        $obj->postMeta = get_post_meta($obj->ID);
        $file = $dir . '/' . $menuItem->post_name;
        Resolver::field_search_replace($obj, $baseUrl, $neutralUrl);
        file_put_contents($file, serialize($obj));
    }
}
function recursiveRemoveDirectory($directory)
{
    foreach (glob("{$directory}/*") as $file) {
        if (is_dir($file)) {
            recursiveRemoveDirectory($file);
        } else {
            unlink($file);
        }
    }
    rmdir($directory);
}
Esempio n. 25
0
<?php

define('BASEPATH', dirname(__DIR__));
if (isset($argv[1]) && $argv[1] == 'test') {
    define('TESTMODE', true);
}
require_once __DIR__ . "/src/Settings.php";
$localSettings = new Settings();
$bootstrapSettings = json_decode(file_get_contents(__DIR__ . '/settings.json'));
require_once $localSettings->wppath . "/wp-load.php";
require_once __DIR__ . "/src/Pushposts.php";
require_once __DIR__ . "/src/Pushmenus.php";
require_once __DIR__ . "/src/Resolver.php";
require_once $localSettings->wppath . "/wp-admin/includes/image.php";
global $pages, $posts, $menus;
// pages
$pages = new Pushposts('pages');
$menues = new Pushmenus();
Resolver::resolveReferences();
function findTargetPostId($target)
{
    global $pages;
    foreach ($pages->posts as $page) {
        if ($page->meta->ID == $target) {
            return $page->id;
        }
    }
    return 0;
}
Esempio n. 26
0
 /**
  * _init performs basic
  * functions to set up all
  * the subclasses. Will call the 
  * normal execution order.
  *
  * - first attach the client
  * - check if the schema is properly formed
  * - initialize path with dependancies
  * - return the appropriate object use in resolver
  * added: 1/29/2015
  *
  */
 public function _init($data, $depends, $loads, $schema, $extras = null)
 {
     $plain = $data->get();
     $input_is_str = $data->is_string();
     $double_string = $data->is_double_string();
     /*
      * replace all numerical keys with the ones defined in schema    
      *
      * this is to support backwards compatilbility and 
      * add trivial loading for certain objects.
      *
      * i.e 
      * Gather('call_id', array(params))
      * same as
      * Gather(array('call_id' => '', params))
      */
     /** don't overload a 'GET' which is '1' in arity. This can be 2+ **/
     if (sizeof($plain) > 1 && !$double_string) {
         foreach ($plain as $k => $p) {
             if (is_numeric($k) && isset($loads->init[$k])) {
                 $plain[$loads->init[$k]] = $p;
                 unset($plain[$k]);
             }
         }
     }
     /**
      * another backwards compatable thing 
      * arguments were passed as singular and
      * id being intialized is the parent's
      * so it should be:
      * Gather('call_id')
      * and not:
      * Gather('gather_id')
      *
      * other resources, i.e calls would not need there
      * conference id to be initialized thus can be called normally
      * 
      * 
      * this is only for models that use other models.
      * without their main resource's id they cannot
      * do anything.
      */
     if ($input_is_str && $loads->silent && !$double_string) {
         $plain = array($loads->init[0] => $plain);
     }
     /**
      * two based arguments
      * Gather('call_id', 'gather_id')
      * 
      * this is for resources that need there parent
      * resource to operate
      */
     if ($double_string) {
         $plain = array($loads->init[0] => $plain[0], "id" => $plain[1]);
     }
     $pargs = func_get_args();
     /** string endpoint has been added in params **/
     $cl = preg_replace("/^Catapult\\\\/", "", get_class($this));
     $bpath = self::$paths[$cl];
     $sets = array("depends" => $depends, "loads" => $loads, "schema" => $schema, "path", $bpath);
     foreach ($sets as $k => $s) {
         $this->{$k} = $s;
     }
     $this->path = $bpath;
     $this->subfunctions = $extras;
     /** attach the main client to this object **/
     ClientResource::attach($this);
     /** use depends **/
     PathResource::make($this, $plain);
     /** use schema **/
     VerifyResource::verify($this, $plain);
     /** attach functions **/
     //FunctionResource::register($extras);
     Resolver::find($this, $plain);
     /** dispose these resources they can take some space **/
     /** we only need the client now **/
     foreach ($sets as $k => $s) {
         unset($this->{$k});
     }
 }
Esempio n. 27
0
 /**
  * Parses links of a given url page to donwload
  * 
  * @param string $url             Page Url to donwload and harvest links
  * @param string $referer         Url referer to register when donwloading page
  * @param string $open_tag        Links open tags
  * @param string $close_tag       Links close tags
  * @return array                  Array of links
  */
 protected function harvestLinks($url, $referer, $open_tag, $close_tag)
 {
     $links = array();
     # Get page base for $url
     $page_base = Resolver::getBasePageAddress($url);
     if ($this->config['webbot']['base_domain_relative_links'] == TRUE) {
         $page_base = Resolver::getBaseDomainAddress($page_base);
     }
     # Download webpage
     $downloaded_page = $this->downloadPage($url, $referer);
     // esto se puede pponer en una configuracion
     $anchor_tags = HtmlParser::parse2Array($downloaded_page['FILE'], $open_tag, $close_tag);
     # Put http attributes for each tag into an array
     for ($i = 0; $i < count($anchor_tags); $i++) {
         $href = HtmlParser::getAttribute($anchor_tags[$i], "href");
         //echo $links[$i]."<br>";
         $resolved_addres = Resolver::resolveAddress($href, $page_base);
         $links[] = $resolved_addres;
         //logging
         $this->logActivity("Harvested: " . $resolved_addres);
     }
     return $links;
 }
 /**
  * {@inheritdoc}
  */
 public function isActive()
 {
     return $this->resolver->resolve();
 }
Esempio n. 29
0
        $comments = Comments::get_all($page->url, true);
        $change = false;
        foreach ($comments as $comment) {
            if ($comment->is_spam() && $comment->visible) {
                $comment->visible = false;
                $change = true;
                $total_change++;
            }
        }
        Comments::set_all($page->url, $comments);
    }
    $p->body .= "Hidden {$total_change} comments";
}
$num_new_spam = 0;
$p->body .= '<table class="spam">';
foreach (Resolver::find_all_pages('blog') as $page) {
    $comments = Comments::get_all($page->url, true);
    $com_body = array();
    foreach ($comments as $comment) {
        $is_spam = ($comment->visible ? 'visible' : 'hidden') . ' ' . ($comment->is_spam() ? 'spam' : 'nonspam');
        if ($comment->visible || !$comment->is_spam()) {
            $com_body[] = "<td class='{$is_spam} summary'>" . htmlspecialchars($comment->author_name) . ', ' . htmlspecialchars($comment->author_email) . ', ' . htmlspecialchars($comment->author_url) . ', ' . htmlspecialchars($comment->author_ip) . "<td class='{$is_spam} summary'>" . htmlspecialchars(substr($comment->body, 0, 100));
            //"<td class='$is_spam summary'>" . $comment->body_html();
        }
        if ($comment->visible && $comment->is_spam()) {
            $num_new_spam++;
        }
    }
    if ($com_body) {
        $p->body .= "<tr class='first'><td rowspan='" . count($com_body) . "'><a href='" . htmlspecialchars($page->url) . "'>" . $page->title . '</a>';
        $p->body .= implode('<tr>', $com_body);
Esempio n. 30
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The strategy "henk" is not supported.
  */
 public function testResolveUnknown()
 {
     $this->resolver->addResolver($this->prophesize(FeatureResolverInterface::class)->reveal(), ['henk']);
     $this->resolver->addResolver($this->prophesize(FeatureResolverInterface::class)->reveal(), ['hans']);
     self::assertFalse($this->resolver->resolve('henk'));
 }