private function exportLanguageCanonical() { $base_url = \CMF\Model\DevSettings::instance()->parent_site; if (!empty($base_url)) { $url = $base_url . "/api/_lang-canonicals_"; $curl = \Request::forge($url, 'curl'); if (!empty($api_key)) { $curl->set_header('Authorization', 'bearer ' . \CMF\Model\DevSettings::instance()->parent_site_api_key); } $curl->set_method('post'); $curl->set_header('Content-Type', 'application/json'); $curl->set_header('Content-Language', \Config::get('language'), true); $curl->set_params(json_encode($this->jsonObject)); $curl->execute(); } }
public function get_index($table_name) { // Find class name and metadata etc $class_name = \Admin::getClassForTable($table_name); if ($class_name === false) { return $this->show404(null, "type"); } $this->table_name = $table_name; $this->plural = $class_name::plural(); $this->singular = $class_name::singular(); $this->icon = $class_name::icon(); $this->template = 'admin/import/form.twig'; $this->methods = $methods = $class_name::importMethods(); $this->type = $class_name::importType(); $this->show_all = empty($methods); $this->importUrl = ''; $base_url = rtrim(\CMF\Model\DevSettings::instance()->parent_site, '/'); if (!empty($base_url)) { $this->importUrl = $base_url . '/api/' . \Inflector::pluralize($table_name) . '.json'; } }
protected function getCanonicalLink($model = null) { if (empty($model)) { $model = $this->model; } if (!empty($model)) { $base = rtrim(\Uri::base(false), '/'); // If this model was imported, we set the canonical base to where it came from if (is_array($model->settings) && \Arr::get($model->settings, 'original_id', false)) { $canonical_base = rtrim(\CMF\Model\DevSettings::instance()->parent_site ?: '', '/'); if (empty($canonical_base)) { $canonical_base = rtrim(\Arr::get($model->settings, 'imported_from', $base), '/'); } } else { $canonical_base = $base; } $current_uri = '/' . trim($_SERVER['REQUEST_URI'], '/'); $uri = property_exists($model, 'url') ? strval($model->get('url', $current_uri)) : $current_uri; if (!empty($canonical_base)) { return $canonical_base . $uri; } } return null; }
protected static function getDataFromUrl($url) { $request = \Request::forge($url, 'curl'); $api_key = \CMF\Model\DevSettings::instance()->parent_site_api_key; if (!empty($api_key)) { $request->set_header('Authorization', 'bearer ' . \CMF\Model\DevSettings::instance()->parent_site_api_key); } $request->set_option('HEADER', true); try { $request->execute(); } catch (\Exception $e) { switch ($request->response()->status) { case 401: $message = \Lang::get('admin.errors.import.url_auth_required'); break; default: $message = \Lang::get('admin.errors.import.url_inaccessible'); break; } throw new \Exception($message, $request->response()->status); } $reponse = $request->response(); $language = $reponse->get_header('Content-Language'); $returnValue = array(); $returnValue['body'] = $reponse->body; if (!empty($language)) { $returnValue['lang'] = $language; } return $returnValue; }
/** * @inheritdoc */ public static function _init_manager($connection) { ///////////////////////// START FROM PARENT METHOD ////////////////////////// $settings = static::connection_settings($connection); $config = new \Doctrine\ORM\Configuration(); $cache = static::_init_cache($settings); if ($cache) { $config->setMetadataCacheImpl($cache); if (!\CMF::$lang_enabled) { $config->setQueryCacheImpl($cache); } $config->setResultCacheImpl($cache); } $config->setProxyDir($settings['proxy_dir']); $config->setProxyNamespace($settings['proxy_namespace']); $config->setAutoGenerateProxyClasses(\Arr::get($settings, 'auto_generate_proxy_classes', false)); $config->setMetadataDriverImpl(static::_init_metadata($config, $settings)); $EventManager = new \Doctrine\Common\EventManager(); static::$_managers[$connection] = \Doctrine\ORM\EntityManager::create($settings['connection'], $config, $EventManager); if (!empty($settings['profiling'])) { static::$_managers[$connection]->getConnection()->getConfiguration()->setSQLLogger(new \CMF\Doctrine\QueryLogger()); } // Connection init callback if (!empty($settings['init_callback'])) { // If array merge combined this numeric array, grab last two array elements as the real callback if (is_array($settings['init_callback']) && count($settings['init_callback']) > 2) { $settings['init_callback'] = array_slice($settings['init_callback'], -2); } call_user_func($settings['init_callback'], static::$_managers[$connection], $connection); } ///////////////////////// END FROM PARENT METHOD ////////////////////////// if (isset(static::$_logger)) { $current_logger = static::$_managers[$connection]->getConnection()->getConfiguration()->getSQLLogger(static::$_logger); if (!is_null($current_logger) && method_exists(static::$_logger, 'setLogger')) { static::$_logger->setLogger($current_logger); } static::$_managers[$connection]->getConnection()->getConfiguration()->setSQLLogger(static::$_logger); } if (empty($connection) || is_null($connection)) { $connection = static::$settings['active']; } // First, add custom types from our config $types = \Arr::get(static::$settings, 'doctrine2.types', array()); $em = static::$_managers[$connection]; $platform = $em->getConnection()->getDatabasePlatform(); foreach ($types as $type => $info) { if (!Type::hasType($type)) { try { Type::addType($type, $info['class']); if (isset($info['dbtype'])) { $platform->registerDoctrineTypeMapping($info['dbtype'], $type); } } catch (\Exception $e) { } } } // Now initialise any extensions from our config $evm = $em->getEventManager(); $reader = $em->getConfiguration()->getMetadataDriverImpl()->getDefaultDriver()->getReader(); $extensions = \Arr::get(static::$settings, 'doctrine2.extensions', array()); // Add custom DQL functions $em->getConfiguration()->addCustomStringFunction('TYPE', 'CMF\\Doctrine\\Functions\\TypeFunction'); // Ensure UTF-8 support $em->getEventManager()->addEventSubscriber(new MysqlSessionInit("utf8", "utf8_unicode_ci")); //Add Event Listener For exporting language canonicals $language = \Config::get('language'); try { if (!empty(\CMF\Model\DevSettings::instance()->parent_site) && !empty($language) && \Config::get('update_language_canonical', false)) { $em->getEventManager()->addEventSubscriber(new \CMF\Doctrine\Extensions\Canonicallistener()); } } catch (\Exception $e) { } foreach ($extensions as $extension_class) { if (!is_subclass_of($extension_class, 'CMF\\Doctrine\\Extensions\\Extension')) { throw new \Exception($extension_class . ' is not a subclass of Doctrine\\Fuel\\Extensions\\Extension'); } $extension_class::init($em, $reader); } }