Exemplo n.º 1
0
 public function getBaseUrl()
 {
     $base = $this->getCrawler()->filter('base');
     $data = $base->extract(array('href'));
     if (isset($data[0])) {
         return Url::trailing($data[0]);
     }
     return false;
 }
Exemplo n.º 2
0
 public function init()
 {
     if ($this->baseUrl === null) {
         throw new InvalidConfigException("argument 'baseUrl' can not be null.");
     }
     $this->baseUrl = Url::trailing($this->baseUrl);
     $this->baseHost = parse_url($this->baseUrl, PHP_URL_HOST);
     Yii::$app->db->createCommand()->truncateTable('crawler_builder_index')->execute();
     // init base url
     $this->urlStatus($this->baseUrl);
     $this->find();
 }
Exemplo n.º 3
0
 public function renderException($exception)
 {
     if ($exception instanceof NotFoundHttpException || !$this->transferException) {
         return parent::renderException($exception);
     }
     $data = json_encode($this->getExceptionArray($exception));
     $curl = new \Curl\Curl();
     $rsp = $curl->post(Url::trailing($this->api) . 'create', ['error_json' => $data]);
     if (!YII_DEBUG) {
         return '<html><head><title>Fehler</title></head><body style="padding:40px;"><h2>Seiten Fehler</h2><p>Es ist ein unerwartet Fehler passiert, wir bitten um Entschuldigung. Bitte versuchen Sie es später erneut.</p></body></html>';
     }
     return parent::renderException($exception);
 }
 public function init()
 {
     if ($this->baseUrl === null) {
         throw new InvalidConfigException("argument 'baseUrl' can not be null.");
     }
     $this->baseUrl = Url::trailing($this->baseUrl);
     $this->baseHost = parse_url($this->baseUrl, PHP_URL_HOST);
     $this->verbosePrint('baseUrl', $this->baseUrl);
     $this->verbosePrint('baseHost', $this->baseHost);
     $this->verbosePrint('useH1', $this->useH1);
     $this->verbosePrint('filterRegex', $this->filterRegex);
     $this->verbosePrint('doNotFollowExtensions', $this->doNotFollowExtensions);
     Yii::$app->db->createCommand()->truncateTable('crawler_builder_index')->execute();
     $this->verbosePrint('truncate of table crawerl_builder_index', 'yes');
     // init base url
     $this->urlStatus($this->baseUrl);
     $this->find();
 }
Exemplo n.º 5
0
 public function getRemote()
 {
     $url = Url::trailing($this->url);
     $data = Yii::$app->cache->get($url);
     if ($data === false) {
         $curl = new \Curl\Curl();
         if ($this->auth_is_enabled) {
             $curl->setBasicAuthentication($this->auth_user, $this->auth_pass);
         }
         $curl->get($url . 'admin/api-admin-remote?token=' . sha1($this->token));
         if ($curl->error) {
             $data = false;
         } else {
             $data = json_decode($curl->response, true);
         }
         Yii::$app->cache->set($url, $data, 60 * 2);
     }
     return $data;
 }
Exemplo n.º 6
0
 public function getFull()
 {
     if ($this->hidden) {
         return;
     }
     return Url::trailing(implode('/', $this->_composition));
     // Remove trailing slash
 }
Exemplo n.º 7
0
 public function getBaseConfig()
 {
     return Url::trailing($this->configPath) . $this->configName;
 }
Exemplo n.º 8
0
 public function testTrailing()
 {
     Yii::$app->composition->hidden = true;
     $this->assertEquals('foo/', Url::trailing('foo'));
 }
Exemplo n.º 9
0
 public function init()
 {
     parent::init();
     $this->dir = Url::trailing(Yii::getAlias($this->dir), DIRECTORY_SEPARATOR);
     $this->httpDir = Url::trailing($this->httpDir, DIRECTORY_SEPARATOR);
 }
Exemplo n.º 10
0
 public function createUrl($params)
 {
     if (!Yii::$app->has('composition')) {
         return parent::createUrl($params);
     }
     $links = Yii::$app->get('links', false);
     $composition = Yii::$app->composition->getFull();
     $originalParams = $params;
     $params[0] = $composition . $params[0];
     $response = parent::createUrl($params);
     // we have not found the composition rule matching against rules, so use the original params and try again!
     if (strpos($response, $params[0]) !== false) {
         $params = $originalParams;
         $response = parent::createUrl($params);
     } else {
         // now we have to remove the composition informations from the links to make a valid link parsing (read module)
         $params[0] = str_replace($composition, '', $params[0]);
     }
     $params = (array) $params;
     $moduleName = \luya\helpers\Url::fromRoute($params[0], 'module');
     if ($this->getContextNavItemId() && $links !== null) {
         $link = $links->findOneByArguments(['id' => (int) $this->getContextNavItemId()]);
         $this->resetContext();
         return preg_replace("/{$moduleName}/", $composition . $link['url'], $response, 1);
     }
     $context = false;
     if ($moduleName !== false) {
         $moduleObject = \yii::$app->getModule($moduleName);
         if (method_exists($moduleObject, 'setContext') && !empty($moduleObject->context)) {
             if ($links !== null) {
                 $context = true;
                 $options = $moduleObject->getContextOptions();
                 $link = $links->findOneByArguments(['id' => (int) $options['navItemId']]);
                 $response = preg_replace("/{$moduleName}/", $composition . $link['url'], $response, 1);
             }
         }
     }
     if (!$context) {
         // because the urlCreation of yii returns a realtive url we have to manually add the composition getFull() path.
         $baseUrl = yii::$app->request->baseUrl;
         if (empty($baseUrl)) {
             $response = Url::removeTrailing($composition) . $response;
         } else {
             $response = str_replace($baseUrl, Url::trailing($baseUrl) . Url::removeTrailing($composition), $response);
         }
     }
     return $response;
 }