/** * Constructor * @param string $base_class Base class in relation * @param string $table_name Name/alias of table in relation * @param string $relation_class Classname that has to be created on joining * @param boolean $ignore Flag for not creating object instances for this class */ public function __construct($base_class, $table_name_simple, $relation_class = null, $ignore = false) { // If table name passed without namespace consider it as activerecord namespace $table_name = \samson\core\AutoLoader::className($table_name_simple, 'samson\\activerecord'); // If relation class not specified if (!isset($relation_class)) { // if there is no class exists for table name specified if (!class_exists($table_name, false)) { // PHP < 5.3 get relation aliases eval('$_relation_alias = ' . $base_class . '::$_relation_alias;'); // Try to find classname in relation aliases if (isset($_relation_alias[$table_name_simple])) { $relation_class = \samson\core\AutoLoader::className($_relation_alias[$table_name_simple], __NAMESPACE__); } else { if (isset($_relation_alias[$table_name])) { $relation_class = \samson\core\AutoLoader::className($_relation_alias[$table_name], __NAMESPACE__); } else { // use thi table name as class $relation_class = $table_name; } } } else { $relation_class = $table_name; } // Try to find closest parent class to dbRecord class $parent_class = get_parent_class($relation_class); if ($parent_class != \samson\core\AutoLoader::className('dbRecord', 'samson\\activerecord')) { $table_name = \samson\core\AutoLoader::getOnlyClass($parent_class); } } // Set defined class fields $this->base = $base_class; $this->relation = $relation_class; $this->table = \samson\core\AutoLoader::getOnlyClass($table_name); $this->ignore = $ignore; // TODO: fix this problem $this->table = str_replace('samson_activerecord_', '', $this->table); }
/** * Get CMSNav by selector * Field to search for can be specified, by default search if performed by URL field * * @param string $selector * @param string $field * @return string|NULL */ public function &navigation($selector, $field = 'Url') { $cmsnav = null; // If no selector passed if (!isset($selector)) { return $cmsnav; } // If id passed switch to real table column name if ($field == 'id') { $field = 'StructureID'; } // Build classname with PHP < 5.3 compatibility $classname = \samson\core\AutoLoader::className('CMSNav', 'samson\\cms'); // If instance of CMSNav passed - just return it if (is_a($selector, $classname)) { return $selector; } else { if (isset(dbRecord::$instances[$classname][$selector])) { $cmsnav =& dbRecord::$instances[$classname][$selector]; } else { if (dbQuery($classname)->cond('Active', 1)->cond($field, $selector)->join('children_relations')->join('children', '\\samson\\cms\\CMSNav')->join('parents_relations')->join('parents', '\\samson\\cms\\CMSNav')->first($cmsnav)) { $cmsnav->prepare(); } } } return $cmsnav; }
/** * Сформировать правильное имя класса с использованием namespace, если оно не указано * Функция нужна для обратной совместимости с именами классов без NS * * @param string $class_name Имя класса для исправления * @param string $ns Пространство имен которому принадлежит класс * * @deprecated use \samson\core\AutoLoader::value() and pass full class name to it without splitting into class * name and namespace * @return string Исправленное имя класса */ function ns_classname($class_name, $ns = null) { return \samson\core\AutoLoader::className($class_name, $ns); }
/** Callback for CSS url rewriting */ public function src_replace_callback($matches) { // Если мы нашли шаблон - переберем все найденные патерны if (isset($matches[2]) && strpos($matches[2], 'data:') === false) { // Remove relative path from resource path $url = str_replace('../', '/', $matches[2]); // Routes with this module controller do not need changes if (strpos($url, '/' . $this->id . '/') === false) { // Remove possible GET parameters from resource path if (($getStart = stripos($url, '?')) !== false) { $url = substr($url, 0, $getStart); } // Remove possible HASH parameters from resource path if (($getStart = stripos($url, '#')) !== false) { $url = substr($url, 0, $getStart); } //trace($this->c_module->id.'-'.get_class($this->c_module).'-'.$url.'-'.is_a( $this->c_module, ns_classname('ExternalModule','samson\core')));; // Always rewrite url's for external modules and for remote web applications if (is_a($this->c_module, \samson\core\AutoLoader::className('ExternalModule', 'samson\\core')) || __SAMSON_REMOTE_APP) { // Build real path to resource $realPath = $this->c_module->path() . $url; // Try to find path in module root folder if (!file_exists($realPath)) { // Build path to "new" module public folder www $realPath = $this->c_module->path() . __SAMSON_PUBLIC_PATH . $url; // Try to find path in module Public folder if (file_exists($realPath)) { $url = 'www/' . $url; } else { // Signal error //e('[##][##] Cannot find CSS resource[##] in path[##]',D_SAMSON_DEBUG, array($this->c_module->id, $realPath, $url, $this->cResource)); } } // Rewrite URL using router $url = self::url($url, $this->c_module); } else { if (is_a($this->c_module, \samson\core\AutoLoader::className('LocalModule', 'samson\\core'))) { $url = url()->base() . $url; } } return 'url("' . $url . '")'; } else { return 'url("' . $matches[2] . '")'; } } else { // Just return original value return $matches[0]; } }