Пример #1
0
 /**
  * Get a unique filename within given target folder, remove uniqid() suffix from file (optional, add $strPrefix) and append file count by name to
  * file if file with same name already exists in target folder
  *
  * @param string $strTarget The target file path
  * @param string $strPrefix A uniqid prefix from the given target file, that was added to the file before and should be removed again
  * @param        $i         integer Internal counter for recursion usage or if you want to add the number to the file
  *
  * @return string | false The filename with the target folder and unique id or false if something went wrong (e.g. target does not exist)
  */
 public static function getUniqueFileNameWithinTarget($strTarget, $strPrefix = null, $i = 0)
 {
     $objFile = new \File($strTarget, true);
     $strTarget = ltrim(str_replace(TL_ROOT, '', $strTarget), '/');
     $strPath = str_replace('.' . $objFile->extension, '', $strTarget);
     if ($strPrefix && ($pos = strpos($strPath, $strPrefix)) !== false) {
         $strPath = str_replace(substr($strPath, $pos, strlen($strPath)), '', $strPath);
         $strTarget = $strPath . '.' . $objFile->extension;
     }
     // Create the parent folder
     if (!file_exists($objFile->dirname)) {
         $objFolder = new \Folder(ltrim(str_replace(TL_ROOT, '', $objFile->dirname), '/'));
         // something went wrong with folder creation
         if ($objFolder->getModel() === null) {
             return false;
         }
     }
     if (file_exists(TL_ROOT . '/' . $strTarget)) {
         // remove suffix
         if ($i > 0 && StringUtil::endsWith($strPath, '_' . $i)) {
             $strPath = rtrim($strPath, '_' . $i);
         }
         // increment counter & add extension again
         $i++;
         // for performance reasons, add new unique id to path to make recursion come to end after 100 iterations
         if ($i > 100) {
             return static::getUniqueFileNameWithinTarget(static::addUniqIdToFilename($strPath . '.' . $objFile->extension, null, false));
         }
         return static::getUniqueFileNameWithinTarget($strPath . '_' . $i . '.' . $objFile->extension, $strPrefix, $i);
     }
     return $strTarget;
 }
Пример #2
0
 /**
  * @param string|array $mConfig navigation name/navigation config
  * each navigation part needs configuration in section called 'navigation' in the site/config/config.yml
  * @return void
  * @throws Exception on missing configuration
  */
 public function __construct($mConfig, $sLinkPrefix = null, $sTemplatesDir = null)
 {
     if ($sTemplatesDir === null) {
         $this->sTemplatesDir = array(DIRNAME_TEMPLATES, DIRNAME_NAVIGATION);
     } else {
         $this->sTemplatesDir = $sTemplatesDir;
     }
     if (is_string($mConfig)) {
         $this->aConfig = Settings::getSetting("navigations", $mConfig, null);
         $this->sNavigationName = $mConfig;
     } else {
         if (is_array($mConfig)) {
             $this->aConfig = $mConfig;
         }
     }
     if ($this->aConfig === null) {
         throw new Exception("Navigation {$mConfig} not configured");
     }
     if ($sLinkPrefix === null) {
         $sLinkPrefix = LinkUtil::link();
     }
     if (!StringUtil::endsWith($sLinkPrefix, "/")) {
         $sLinkPrefix .= "/";
     }
     $this->sLinkPrefix = $sLinkPrefix;
     $this->iMaxLevel = max(array_keys($this->aConfig));
     if (!is_numeric($this->iMaxLevel) || isset($this->aConfig['all'])) {
         $this->iMaxLevel = null;
     }
     $this->bShowOnlyEnabledChildren = isset($this->aConfig["show_inactive"]) ? $this->aConfig["show_inactive"] !== true : true;
     $this->bShowOnlyVisibleChildren = isset($this->aConfig["show_hidden"]) ? $this->aConfig["show_hidden"] !== true : true;
     $this->bExcludeDuplicates = isset($this->aConfig["exclude_duplicates"]) ? $this->aConfig["exclude_duplicates"] === true : false;
     $this->bPrintNewline = isset($this->aConfig["no_newline"]) ? $this->aConfig["no_newline"] !== true : true;
     $this->sLanguageId = isset($this->aConfig["language"]) ? $this->aConfig["language"] : Session::language();
 }
Пример #3
0
 /**
  * $value = callNestedGetter($person, "name.firstName")
  */
 public static function callNestedGetter($object, $nestedProperty)
 {
     StringUtil::checkTypes($nestedProperty);
     if ($nestedProperty === "") {
         return $object;
     }
     $properties = explode(".", $nestedProperty);
     if (empty($properties) || !is_object($object)) {
         throw new InvalidTypeException("Should be called on object");
     }
     foreach ($properties as $property) {
         if (is_null($object)) {
             throw new NullPointerException();
         }
         $className = get_class($object);
         $isListItem = StringUtil::endsWith($property, ")");
         $strippedProperty = $isListItem ? substr($property, 0, strpos($property, "(")) : $property;
         try {
             $getterMethod = new ReflectionMethod($className, StringUtil::getter($strippedProperty));
         } catch (ReflectionException $e) {
             try {
                 $getterMethod = new ReflectionMethod($className, StringUtil::boolGetter($strippedProperty));
             } catch (ReflectionException $e) {
                 throw new MethodNotExistsException($className, StringUtil::getter($strippedProperty));
             }
         }
         $object = $getterMethod->invoke($object);
         if ($isListItem) {
             $index = StringUtil::getSubstringBetween($property, "(", ")");
             $object = $object[$index];
         }
     }
     return $object;
 }
 private static function nullifyEmptyParams(&$params)
 {
     foreach ($params as $key => $value) {
         if ($value === '' && StringUtil::endsWith($key, '_value')) {
             unset($params[$key]);
         }
     }
 }
Пример #5
0
 public static function suite()
 {
     $oResult = new PHPUnit_Framework_TestSuite("ResourceFinder test suite");
     foreach (ResourceFinder::getFolderContents(dirname(__FILE__)) as $sFileName => $sFilePath) {
         if (StringUtil::endsWith($sFileName, "Tests.php") && (StringUtil::startsWith($sFileName, "ResourceFinder") || StringUtil::startsWith($sFileName, "FileResource") || StringUtil::startsWith($sFileName, "ResourceIncluder"))) {
             $oResult->addTestFile($sFilePath);
         }
     }
     return $oResult;
 }
Пример #6
0
 public static function suite()
 {
     $oResult = new PHPUnit_Framework_TestSuite("Complete test suite");
     foreach (ResourceFinder::getFolderContents(dirname(__FILE__)) as $sFileName => $sFilePath) {
         if (StringUtil::endsWith($sFileName, ".php") && StringUtil::startsWith($sFileName, "Test") && !StringUtil::startsWith($sFileName, "TestUtil") && $sFilePath !== __FILE__) {
             require_once $sFilePath;
             $oResult->addTest(call_user_func(array(substr($sFileName, 0, -strlen('.php')), "suite")));
         }
     }
     return $oResult;
 }
 private static function getFieldValues($instance, $fields)
 {
     $values = array();
     foreach ($fields as $field) {
         if (StringUtil::endsWith(strtolower($field->get('@type')), 'combo')) {
             $values[$field->get('@name') . '_value'] = $field->get('@selected', null);
         } else {
             $values[$field->get('@name')] = afEditView::getFieldValue($field, $instance);
         }
     }
     return $values;
 }
Пример #8
0
 /**
  * @param $name name of variable to check, for error message
  * @throws \InvalidArgumentException if $dir is not a string pointing to an existing directory
  * @return absolute path for given string, using forward slashes, ending with a slash.
  */
 public static function assertDir($var, $name)
 {
     self::assertString($var, $name);
     $dir = str_replace('\\', '/', realpath($var));
     if (!is_dir($dir)) {
         throw new \InvalidArgumentException($name . ' must be an existing directory, but is ' . $var);
     }
     if (!StringUtil::endsWith($dir, '/')) {
         $dir .= '/';
     }
     return $dir;
 }
Пример #9
0
 /**
  * Scan the $PAGE_TEMPLATE_PATH dir and return the list of file finished by $TEMPLATE_SUFFIX
  * @return multitype:unknown
  */
 public static function getTemplateList()
 {
     $fileList = scandir(TemplateUtil::getPageTemplateAbsolutePath());
     $templateList = array();
     //Filter
     foreach ($fileList as $file) {
         if (StringUtil::endsWith($file, TemplateUtil::getTemplateSuffix())) {
             $templateList[$file] = $file;
         }
     }
     return $templateList;
 }
 private static function collectOptions($params)
 {
     $options = array();
     $messages = array();
     foreach ($params as $key => $param) {
         if (StringUtil::endsWith($key, '_error')) {
             $messages[preg_replace('/_error$/', '', $key)] = $param;
         } else {
             $options[$key] = $param === 'false' ? false : $param;
         }
     }
     return array($options, $messages);
 }
Пример #11
0
function getPatches($dir, $after)
{
    $result = array();
    if ($dirHandle = opendir($dir)) {
        while (($fileName = readdir($dirHandle)) !== false) {
            if (preg_match(PATCH_REGEXP, $fileName) && stripExtension($fileName) > $after && !StringUtil::endsWith($fileName, '~')) {
                $result[] = $fileName;
            }
        }
        closedir($dirHandle);
        sort($result);
    }
    return $result;
}
Пример #12
0
 public function loadFromBackup($sFileName = null)
 {
     $sFilePath = ResourceFinder::findResource(array(DIRNAME_DATA, 'sql', $sFileName));
     $oConnection = Propel::getConnection();
     $bFileError = false;
     if ($sFilePath === null) {
         $bFileError = true;
     }
     if (!$bFileError) {
         if (!is_readable($sFilePath)) {
             $bFileError = true;
         }
         if (!$bFileError) {
             $rFile = fopen($sFilePath, 'r');
             if (!$rFile) {
                 $bFileError = true;
             }
         }
     }
     // throw error and filename on error
     if ($bFileError) {
         throw new LocalizedException('wns.backup.loader.load_error', array('filename' => $sFilePath));
     }
     // continue importing from local file
     $sStatement = "";
     $sReadLine = "";
     $iQueryCount = 1;
     while (($sReadLine = fgets($rFile)) !== false) {
         if ($sReadLine !== "\n" && !StringUtil::startsWith($sReadLine, "#") && !StringUtil::startsWith($sReadLine, "--")) {
             $sStatement .= $sReadLine;
         }
         if ($sReadLine === "\n" || StringUtil::endsWith($sReadLine, ";\n")) {
             if (trim($sStatement) !== "") {
                 $oConnection->exec($sStatement);
                 $iQueryCount++;
             }
             $sStatement = "";
         }
     }
     if (trim($sStatement) !== "") {
         $oConnection->exec($sStatement);
     }
     Cache::clearAllCaches();
     return $iQueryCount;
 }
Пример #13
0
 /**
  * Used to create FileResource instances. ResourceFinder will call this with given full path, instance prefix, relative path;
  * other uses will likely let the function figure out instance prefix and relative path.
  * Setting relative path to non-null and instance prefix null is not allowed.
  * Setting instance prefix but not relative path is redundant.
  * @param string $sFullPath The absolute file path
  * @param string $sInstancePrefix The part of the CMS’ folder which this file belongs to (base, site or plugins/*); includes trailing slash
  * @param string $sRelativePath The file path following the instance prefix. There can be multiple files in the installation with the same relative paths if the instance prefix differs.
  */
 public function __construct($sFullPath, $sInstancePrefix = null, $sRelativePath = null)
 {
     if (file_exists($sFullPath)) {
         if (($sRealPath = realpath($sFullPath)) === false) {
             throw new Exception("File resource does not have the permissions for realpath({$sFullPath})");
         }
         $sFullPath = $sRealPath;
     }
     if ($sInstancePrefix !== null && !StringUtil::endsWith($sInstancePrefix, '/')) {
         $sInstancePrefix .= '/';
     }
     if ($sRelativePath === null) {
         if (strpos($sFullPath, self::mainDirCanonical()) !== 0) {
             throw new Exception("Tried to instanciate file resource {$sFullPath}, which is not inside main dir (" . self::mainDirCanonical() . ")");
         }
         //Also remove leading slash
         $sRelativePath = substr($sFullPath, strlen(self::mainDirCanonical()) + 1);
         $sPreviousRelativePath = $sRelativePath;
         $sTempInstancePrefix = '';
         do {
             if (strpos($sRelativePath, '/') === false) {
                 $sTempInstancePrefix = '';
                 $sRelativePath = $sPreviousRelativePath;
                 break;
             }
             $sTempInstancePrefix .= substr($sRelativePath, 0, strpos($sRelativePath, '/') + 1);
             if ($sInstancePrefix !== null && $sTempInstancePrefix !== $sInstancePrefix) {
                 throw new Exception("Error in FileResource::__construct(): Supplied instance prefix {$sInstancePrefix} does not match supplied path’s {$sTempInstancePrefix}");
             }
             $sRelativePath = substr($sPreviousRelativePath, strlen($sTempInstancePrefix));
         } while ($sTempInstancePrefix === 'plugins/');
         $sInstancePrefix = $sTempInstancePrefix;
     }
     $this->sFullPath = $sFullPath;
     $this->sInstancePrefix = $sInstancePrefix;
     $this->sRelativePath = $sRelativePath;
 }
Пример #14
0
 public function regenerateLongInfinitive()
 {
     $infl = Inflection::loadLongInfinitive();
     $f107 = FlexModel::get_by_modelType_number('F', '107');
     $f113 = FlexModel::get_by_modelType_number('F', '113');
     // Iterate through all the participle forms of this Lexem
     foreach ($this->getLexemModels() as $lm) {
         $ifs = InflectedForm::get_all_by_lexemModelId_inflectionId($lm->id, $infl->id);
         foreach ($ifs as $if) {
             $model = StringUtil::endsWith($if->formNoAccent, 'are') ? $f113 : $f107;
             $lexem = Model::factory('Lexem')->select('l.*')->table_alias('l')->distinct()->join('LexemModel', 'l.id = lm.lexemId', 'lm')->where('l.formNoAccent', $if->formNoAccent)->where_raw("(lm.modelType = 'T' or (lm.modelType = 'F' and lm.modelNumber = '{$model->number}'))")->find_one();
             if ($lexem) {
                 $infLm = $lexem->getFirstLexemModel();
                 if ($infLm->modelType != 'F' || $infLm->modelNumber != $model->number || $inf->restriction != '') {
                     $infLm->modelType = 'F';
                     $infLm->modelNumber = $model->number;
                     $infLm->restriction = '';
                     if ($this->isLoc() && !$infLm->isLoc) {
                         $infLm->isLoc = true;
                         FlashMessage::add("Lexemul {$lexem->formNoAccent}, care nu era în LOC, a fost inclus automat în LOC.", 'info');
                     }
                     $lexem->deepSave();
                 }
             } else {
                 $lexem = Lexem::deepCreate($if->form, 'F', $model->number, '', $this->isLoc());
                 $lexem->deepSave();
                 // Also associate the new lexem with the same definitions as $this.
                 $ldms = LexemDefinitionMap::get_all_by_lexemId($this->id);
                 foreach ($ldms as $ldm) {
                     LexemDefinitionMap::associate($lexem->id, $ldm->definitionId);
                 }
                 FlashMessage::add("Am creat automat lexemul {$lexem->formNoAccent} (F{$model->number}) și l-am asociat cu toate definițiile verbului.", 'info');
             }
         }
     }
 }
Пример #15
0
 /**
  * @param string $sPostfix string of template 'list item' identifier
  * retrieve all templates from site template dir that follow a naming convention
  * list template name: examplename.tmpl
  * list_item template name: examplename_item.tmpl
  * @return array assoc of path to examplename in key and value
  */
 public static function getSiteTemplatesForListOutput($sPostfix = '_item')
 {
     $aTemplateList = ArrayUtil::arrayWithValuesAsKeys(Template::listTemplates(DIRNAME_TEMPLATES, true));
     $aListTemplates = array();
     foreach ($aTemplateList as $sPath => $sListName) {
         if (StringUtil::endsWith($sListName, $sPostfix)) {
             $sPath = substr($sListName, 0, -strlen($sPostfix));
             $aListTemplates[$sPath] = $sPath;
         }
     }
     foreach ($aListTemplates as $sListPath) {
         if (!in_array($sListPath, $aTemplateList)) {
             unset($aListTemplates[$sListPath]);
         }
     }
     return $aListTemplates;
 }
Пример #16
0
 public function regenerateLongInfinitive()
 {
     $infl = Inflection::loadLongInfinitive();
     $ifs = Model::factory('InflectedForm')->where('lexemId', $this->id)->where('inflectionId', $infl->id)->find_many();
     $f107 = Model::factory('FlexModel')->where('modelType', 'F')->where('number', '107')->find_one();
     $f113 = Model::factory('FlexModel')->where('modelType', 'F')->where('number', '113')->find_one();
     foreach ($ifs as $if) {
         $model = StringUtil::endsWith($if->formNoAccent, 'are') ? $f113 : $f107;
         // Load an existing lexem only if it has one of the models F113, F107 or T1. Otherwise create a new lexem.
         $lexems = Lexem::get_all_by_formNoAccent($if->formNoAccent);
         $lexem = null;
         foreach ($lexems as $l) {
             if ($l->modelType == 'T' || $l->modelType == 'F' && $l->modelNumber == $model->number) {
                 $lexem = $l;
             } else {
                 if ($this->isLoc && !$l->isLoc) {
                     FlashMessage::add("Lexemul {$l->formNoAccent} ({$l->modelType}{$l->modelNumber}), care nu este în LOC, nu a fost modificat.", 'info');
                 }
             }
         }
         if ($lexem) {
             $lexem->modelType = 'F';
             $lexem->modelNumber = $model->number;
             $lexem->restriction = '';
             if ($this->isLoc && !$lexem->isLoc) {
                 $lexem->isLoc = $this->isLoc;
                 FlashMessage::add("Lexemul {$lexem->formNoAccent}, care nu era în LOC, a fost inclus automat în LOC.", 'info');
             }
             $lexem->noAccent = false;
             $lexem->save();
         } else {
             $lexem = Lexem::create($if->form, 'F', $model->number, '');
             $lexem->isLoc = $this->isLoc;
             $lexem->save();
             // Also associate the new lexem with the same definitions as $this.
             $ldms = LexemDefinitionMap::get_all_by_lexemId($this->id);
             foreach ($ldms as $ldm) {
                 LexemDefinitionMap::associate($lexem->id, $ldm->definitionId);
             }
             FlashMessage::add("Am creat automat lexemul {$lexem->formNoAccent} (F{$lexem->modelNumber}) și l-am asociat cu toate definițiile verbului.", 'info');
         }
         $lexem->regenerateParadigm();
     }
 }
 public static function resolveUnsignedByHintType($hint, $assumeSigned = false, $hintName = null)
 {
     if (RedBeanDatabase::getDatabaseType() == 'mysql') {
         $integerHintTypes = array_keys(static::resolveIntegerMaxAllowedValuesByType());
         if (in_array($hint, $integerHintTypes) && (!$assumeSigned || StringUtil::endsWith($hintName, '_id'))) {
             return "UNSIGNED";
         }
         return null;
     }
     throw new NotSupportedException();
 }
Пример #18
0
 /**
  * Ensures that endsWith() returns false if the string does not even contain
  * the given suffix.
  */
 public function testEndsWithReturnsFalseIfTheStringDoesNotContainTheSuffix()
 {
     $result = StringUtil::endsWith('this is a test string', 'demo');
     $this->assertFalse($result);
 }
Пример #19
0
 public static function getManager()
 {
     self::$ORIGINAL_PATH = self::getRequestedPath();
     $oRouteConfig = self::routeConfig();
     foreach ($oRouteConfig->routes as $sRouteName => $sClassName) {
         if (StringUtil::startsWith(self::getRequestedPath(), $sRouteName . '/') || StringUtil::endsWith(self::getRequestedPath(), $sRouteName) && StringUtil::startsWith(self::getRequestedPath(), $sRouteName)) {
             self::setRequestedPath(substr(self::getRequestedPath(), strlen($sRouteName . '/')));
             if (self::getRequestedPath() === false) {
                 self::setRequestedPath('');
             }
             new $sClassName();
             return self::$CURRENT_MANAGER;
         }
     }
     $sClassName = $oRouteConfig->default;
     new $sClassName();
     return self::$CURRENT_MANAGER;
 }
 public function listWidgets()
 {
     $aWidgetTypes = array();
     $aWidgetTypesOrdered = array();
     foreach (get_class_methods($this) as $sMethodName) {
         if (StringUtil::startsWith($sMethodName, 'render') && StringUtil::endsWith($sMethodName, 'Widget')) {
             $oWidget = new StdClass();
             $oWidget->name = StringUtil::deCamelize(substr($sMethodName, strlen('render'), -strlen('Widget')));
             $oWidget->current = in_array($oWidget->name, $this->aWidgets, true);
             $sStringKey = 'journal_config.' . $oWidget->name;
             $oWidget->title = TranslationPeer::getString('journal_config.' . $oWidget->name, null, StringUtil::makeReadableName($oWidget->name));
             if ($oWidget->current) {
                 $iKey = array_search($oWidget->name, $this->aWidgets);
                 if ($iKey !== false) {
                     $aWidgetTypesOrdered[$iKey] = $oWidget;
                 } else {
                     $aWidgetTypes[] = $oWidget;
                 }
             } else {
                 $aWidgetTypes[] = $oWidget;
             }
         }
     }
     ksort($aWidgetTypesOrdered);
     $aWidgetTypes = array_merge($aWidgetTypesOrdered, $aWidgetTypes);
     return $aWidgetTypes;
 }
Пример #21
0
$apiKey = pref_getServerPreference('googleSearchApiKey');
$url = $urlGoogle . "&q=" . urlencode($to_search) . "&key=" . $apiKey;
$body = util_fetchUrl($url);
# now, process the JSON string
$json = json_decode($body);
$rezultate = $json->responseData->results;
$listAll = array();
$content = "";
$messageAlert = array();
$blackList = array();
foreach ($rezultate as $iter) {
    # Skip dexonline.ro from results
    #if(stripos($iter->url, "dexonline.ro") == true)
    #	continue;
    $components = parse_url($iter->url);
    if (StringUtil::endsWith($components['host'], 'dexonline.ro')) {
        continue;
    }
    $listAll[] = $iter->url;
    # Search for "licenta GPL" or "dexonline.ro" in resulted page
    $content = @file_get_contents($iter->url);
    $poslink = stripos($content, "dexonline.ro");
    $posGPL = stripos($content, "GPL");
    if ($poslink === false && $posGPL === false) {
        $blackList[] = $iter->url;
        $messageAlert[] = "Licenta GPL sau link catre dexonline.ro negasite in site-ul {$iter->url} ";
    } else {
        $messageAlert[] = "A fost gasita o mentiune catre licenta GPL sau un link catre dexonline.ro in site-ul {$iter->url} ";
    }
}
smarty_assign('page_title', 'Site Clones');
Пример #22
0
 /**
  * @param string $sTemplateName template name
  * @param string|array $mPath template dir path
  * @param boolean $bTemplateIsTextOnly template is text only (name will be used as content, path can be used to decide origin [null=filesystem, "db"=database, "browser"=request])
  * @param boolean $bDirectOutput template will output directly to stream? only one the main template should have set this to true
  * @param string $sTargetEncoding target encoding. usually the browser encoding. text will be converted from the source encoding (default is utf-8, at the moment only changed when using text-only templates) into the target encoding
  * @param string $sRootTemplateName root template name, used internally when including subtemplates, default=null
  * @param int $iDefaultFlags default flags, will be ORed to the flags you provide when calling {@link replaceIdentifier()} and {@link replaceIdentifierMultiple()}
  */
 public function __construct($sTemplateName, $mPath = null, $bTemplateIsTextOnly = false, $bDirectOutput = false, $sTargetEncoding = null, $sRootTemplateName = null, $iDefaultFlags = 0)
 {
     if ($sTargetEncoding === null) {
         $sTargetEncoding = Settings::getSetting("encoding", "browser", "utf-8");
     }
     if ($mPath === "db") {
         $this->sEncoding = Settings::getSetting("encoding", "db", "utf-8");
     } else {
         if ($mPath === "browser") {
             $this->sEncoding = Settings::getSetting("encoding", "browser", "utf-8");
         }
     }
     if ($mPath === null || $mPath === "db" || $mPath === "browser") {
         $mPath = DIRNAME_TEMPLATES;
     }
     $sTemplateText = "";
     $this->aTemplateContents = array();
     $oCache = null;
     $bCacheIsCurrent = false;
     if ($bTemplateIsTextOnly) {
         $sTemplateText = $sTemplateName;
         $sTemplateName = $sRootTemplateName;
     } else {
         if ($sTemplateName instanceof FileResource) {
             $oPath = $sTemplateName;
             $aPath = explode('/', $oPath->getRelativePath());
             $sTemplateName = $oPath->getFileName(self::$SUFFIX);
         } else {
             $aPath = ResourceFinder::parsePathArguments(null, $mPath, $sTemplateName . self::$SUFFIX);
             $oPath = ResourceFinder::findResourceObject($aPath);
         }
         if ($oPath === null) {
             throw new Exception("Error in Template construct: Template file " . implode("/", $aPath + array($sTemplateName . self::$SUFFIX)) . " does not exist");
         }
         if (Settings::getSetting('general', 'template_caching', false)) {
             $oCache = new Cache($oPath->getFullPath() . "_" . LocaleUtil::getLocaleId() . "_" . $sTargetEncoding . "_" . $sRootTemplateName, DIRNAME_TEMPLATES);
             $bCacheIsCurrent = $oCache->entryExists() && !$oCache->isOutdated($oPath->getFullPath());
         }
         if (!$bCacheIsCurrent) {
             $sTemplateText = file_get_contents($oPath->getFullPath());
         }
         $mPath = $aPath;
         array_pop($mPath);
     }
     if ($sRootTemplateName === null && !$bTemplateIsTextOnly) {
         $sRootTemplateName = $sTemplateName;
     }
     if ($sRootTemplateName === null) {
         $sRootTemplateName = '';
     }
     $this->sTemplateName = $sRootTemplateName;
     if (StringUtil::startsWith($sTemplateName, 'e_mail_') || StringUtil::startsWith($sTemplateName, 'email_')) {
         $iDefaultFlags |= self::NO_HTML_ESCAPE;
     } else {
         if (StringUtil::endsWith($sTemplateName, '.js') || StringUtil::endsWith($sTemplateName, '.css')) {
             $iDefaultFlags |= self::NO_HTML_ESCAPE | self::ESCAPE;
         } else {
             if (StringUtil::endsWith($this->sTemplateName, '.js') || StringUtil::endsWith($this->sTemplateName, '.css')) {
                 //I’m not a js template but my parent is
                 $iDefaultFlags &= ~(self::NO_HTML_ESCAPE | self::ESCAPE);
             }
         }
     }
     $this->mPath = $mPath;
     $this->oSpecialTemplateIdentifierActions = new SpecialTemplateIdentifierActions($this);
     $this->iDefaultFlags = $iDefaultFlags;
     if ($bCacheIsCurrent) {
         $this->aTemplateContents = $oCache->getContentsAsVariable();
         foreach ($this->aTemplateContents as &$mContent) {
             if ($mContent instanceof TemplatePart) {
                 $mContent->setTemplate($this);
             }
         }
     } else {
         if (is_array($sTemplateText)) {
             $this->aTemplateContents = $sTemplateText;
         } else {
             $sTemplateText = StringUtil::encode($sTemplateText, $this->sEncoding, $sTargetEncoding);
             $this->aTemplateContents = self::templateContentsFromText($sTemplateText, $this);
             $this->replaceConditionals(true);
             $this->renderDirectOutput();
         }
         $this->replaceSpecialIdentifiersOnStart();
         if ($oCache !== null) {
             $oCache->setContents($this->aTemplateContents);
         }
     }
     $this->sEncoding = $sTargetEncoding;
     $this->bDirectOutput = $bDirectOutput;
     $this->replaceConditionals(true);
     $this->renderDirectOutput();
 }
Пример #23
0
        $lexem->modelNumber = 1;
    }
}
if ($lexemDescription !== null) {
    $lexem->description = AdminStringUtil::internalize($lexemDescription, false);
}
if ($lexemTags !== null) {
    $lexem->tags = AdminStringUtil::internalize($lexemTags, false);
}
if ($lexemSources !== null) {
    $lexem->source = join(',', $lexemSources);
}
if ($lexemComment !== null) {
    $newComment = trim(AdminStringUtil::internalize($lexemComment, false));
    $oldComment = trim($lexem->comment);
    if (StringUtil::startsWith($newComment, $oldComment) && $newComment != $oldComment && !StringUtil::endsWith($newComment, ']]')) {
        $newComment .= " [[" . session_getUser() . ", " . strftime("%d %b %Y %H:%M") . "]]\n";
    } else {
        if ($newComment) {
            $newComment .= "\n";
        }
    }
    $lexem->comment = $newComment;
}
if ($lexemIsLoc !== null) {
    $lexem->isLoc = $lexemIsLoc != '';
}
if ($lexemNoAccent !== null) {
    $lexem->noAccent = $lexemNoAccent != '';
}
// The new model type, number and restrictions can come from three sources:
Пример #24
0
 /**
  * Displays the login page
  */
 public function actionLogin()
 {
     $this->layout = "login";
     // Languages
     $languages = array();
     $files = opendir(Yii::app()->basePath . DIRECTORY_SEPARATOR . 'messages');
     while ($file = readdir($files)) {
         if (preg_match("/^\\w\\w(_\\w\\w)?\$/", $file)) {
             $languages[] = array('label' => Yii::t('language', $file), 'icon' => 'images/language/' . $file . '.png', 'url' => Yii::app()->createUrl('/site/changeLanguage/' . $file), 'htmlOptions' => array('class' => 'icon'));
         }
     }
     $currentLanguage = Yii::app()->getLanguage();
     if (strlen($currentLanguage) == 2) {
         $currentLanguage .= '_' . $currentLanguage;
     }
     $availableThemes = Yii::app()->getThemeManager()->getThemeNames();
     $activeTheme = Yii::app()->getTheme()->getName();
     $themes = array();
     foreach ($availableThemes as $theme) {
         if ($activeTheme == $theme) {
             continue;
         }
         $themes[] = array('label' => ucfirst($theme), 'icon' => '/themes/' . $theme . '/images/icon.png', 'url' => Yii::app()->request->baseUrl . '/site/changeTheme/' . $theme, 'htmlOptions' => array('class' => 'icon'));
     }
     // Hosts
     $hosts = array('web' => 'web', 'localhost' => 'localhost', '127.0.0.1' => '127.0.0.1');
     $form = new LoginForm();
     // collect user input data
     $request = Yii::app()->getRequest();
     if ($request->isPostRequest || $request->getQuery("host") !== null && $request->getQuery("username") !== null) {
         if ($request->isPostRequest) {
             $form->attributes = array("host" => $request->getPost("host"), "port" => $request->getPost("port"), "username" => $request->getPost("username"), "password" => $request->getPost("password"));
             $form->redirectUrl = $request->getPost("redirectUrl");
         } else {
             $form->attributes = array("host" => $request->getQuery("host"), "port" => $request->getPost("port"), "username" => $request->getQuery("username"), "password" => $request->getQuery("password") !== null ? $request->getQuery("password") : "");
         }
         // validate user input and redirect to previous page if valid
         if ($form->validate()) {
             $redirectUrl = $request->getPost("redirectUrl");
             if ($redirectUrl !== null && !StringUtil::endsWith($redirectUrl, "site/login")) {
                 $this->redirect($redirectUrl);
             } else {
                 $this->redirect(Yii::app()->homeUrl);
             }
         }
     }
     $validBrowser = true;
     if ($_SERVER['HTTP_USER_AGENT']) {
         preg_match('/MSIE (\\d+)\\.\\d+/i', $_SERVER['HTTP_USER_AGENT'], $res);
         if (count($res) == 2 && $res[1] <= 7) {
             $validBrowser = false;
         }
     }
     $this->render('login', array('form' => $form, 'languages' => $languages, 'hosts' => $hosts, 'themes' => $themes, 'validBrowser' => $validBrowser));
 }
Пример #25
0
function populate(&$lexem, &$original, $lexemForm, $lexemNumber, $lexemDescription, $lexemComment, $needsAccent, $hyphenations, $pronunciations, $variantOfId, $structStatus, $modelType, $modelNumber, $restriction, $lmTags, $isLoc, $sourceIds)
{
    $lexem->form = AdminStringUtil::formatLexem($lexemForm);
    $lexem->formNoAccent = str_replace("'", '', $lexem->form);
    $lexem->number = $lexemNumber;
    $lexem->description = AdminStringUtil::internalize($lexemDescription, false);
    $lexem->comment = trim(AdminStringUtil::internalize($lexemComment, false));
    // Sign appended comments
    if (StringUtil::startsWith($lexem->comment, $original->comment) && $lexem->comment != $original->comment && !StringUtil::endsWith($lexem->comment, ']]')) {
        $lexem->comment .= " [[" . session_getUser() . ", " . strftime("%d %b %Y %H:%M") . "]]";
    }
    $lexem->noAccent = !$needsAccent;
    $lexem->hyphenations = $hyphenations;
    $lexem->pronunciations = $pronunciations;
    $lexem->variantOfId = $variantOfId ? $variantOfId : null;
    $lexem->structStatus = $structStatus;
    // Create LexemModels and LexemSources
    $lexemModels = array();
    for ($i = 1; $i < count($modelType); $i++) {
        $lm = Model::factory('LexemModel')->create();
        $lm->lexemId = $lexem->id;
        $lm->setLexem($lexem);
        // Otherwise it will reload the original
        $lm->displayOrder = $i;
        $lm->modelType = $modelType[$i];
        $lm->modelNumber = $modelNumber[$i];
        $lm->restriction = $restriction[$i];
        $lm->tags = $lmTags[$i];
        $lm->isLoc = $isLoc[$i];
        $lm->generateInflectedFormMap();
        $lexemSources = array();
        foreach (explode(',', $sourceIds[$i]) as $sourceId) {
            $ls = Model::factory('LexemSource')->create();
            $ls->sourceId = $sourceId;
            $lexemSources[] = $ls;
        }
        $lm->setSources($lexemSources);
        $lexemModels[] = $lm;
    }
    $lexem->setLexemModels($lexemModels);
}
Пример #26
0
 /**
  * GET method handler for directories
  *
  * This is a very simple mod_index lookalike.
  * See RFC 2518, Section 8.4 on GET/HEAD for collections
  *
  * @param	 string	 directory path
  * @return void	 function has to handle HTTP response itself
  */
 private function getDir($sFullPath, &$aOptions)
 {
     if (!StringUtil::endsWith(Manager::getOriginalPath(), '/')) {
         LinkUtil::redirect($this->_slashify(LinkUtil::link($aOptions["path"])));
     }
     // fixed width directory column format
     $format = "%15s\t %-19s\t%-s\n";
     $handle = @opendir($sFullPath);
     if (!$handle) {
         return false;
     }
     echo "<html><head><title>Index of " . htmlspecialchars($aOptions['path']) . "</title></head>\n";
     echo "<h1>Index of " . htmlspecialchars($aOptions['path']) . "</h1>\n";
     echo "<pre>";
     printf($format, "Size", "Last modified", "Filename");
     echo "<hr>";
     while ($filename = readdir($handle)) {
         if ($filename === '.') {
             continue;
         }
         if (!$this->hasReadAccess($aOptions["path"] . '/' . $filename)) {
             continue;
         }
         //Add the file
         $sSubPath = $sFullPath . "/" . $filename;
         $name = htmlspecialchars($filename);
         $name_href = htmlspecialchars(rawurlencode($filename));
         printf($format, number_format(filesize($sSubPath)), strftime("%Y-%m-%d %H:%M:%S", filemtime($sSubPath)), "<a href='{$name_href}'>{$name}</a>");
     }
     echo "</pre>";
     closedir($handle);
     echo "</html>\n";
     exit;
 }
Пример #27
0
 public static function isValidModuleClassNameOfAnyType($sName)
 {
     return StringUtil::endsWith($sName, "Module");
 }
Пример #28
0
 public static function getRealm()
 {
     return str_replace(array('/', '.'), '_', StringUtil::endsWith(MAIN_DIR_FE, '/') ? substr(MAIN_DIR_FE, 0, -1) : MAIN_DIR_FE);
 }
 public static function getStarredModelClassName($modelClassName)
 {
     if (!StringUtil::endsWith($modelClassName, 'Starred')) {
         $modelClassName .= 'Starred';
     }
     return $modelClassName;
 }
Пример #30
0
 /**
  * Set the asic pager url without page number
  *
  * @param string base url
  * description: the base url without the page id
  * @return  void
  */
 public function setPageLinkBase($sPageLinkBaseBase)
 {
     if (!StringUtil::endsWith('/', $sPageLinkBaseBase)) {
         $sPageLinkBaseBase = $sPageLinkBaseBase . '/';
     }
     $this->sPageLinkBase = $sPageLinkBaseBase;
 }