public function indexAction() { if ($_SESSION["userRole"] == USER_ROLE_ADMIN) { CApp::setTitle(CApp::getAppName() . " | " . CApp::getTranslate('translateApp')); $arrResult = CApp::getTranslateAll(); if (!empty($_POST["TRANSLATE"])) { $translateArray = array(); foreach ($_POST["TRANSLATE"] as $key => $value) { if ($key == "newVal" && empty($value[0]) && empty($value[1])) { continue; } if (empty($value[0]) && empty($value[1])) { continue; } $translateArray[filterGetValue($value[0])] = filterGetValue($value[1]); } $model = new TranslateModel(); $arrResult = $model->update($translateArray, $arrResult); } $this->render("changeTranslate", "translate", $arrResult); } else { CApp::redirect("/"); } }
/** * Create element from row. * * @param array $row * * @return TranslateModel */ public function populateElementModel($row) { return TranslateModel::populateModel($row); }
/** * Open file and parse translate tags. * * @param string $path * @param string $file * @param ElementCriteriaModel $criteria * * @return array */ protected function _parseFile($path, $file, ElementCriteriaModel $criteria) { // Collect matches in file $occurences = array(); // Get file contents $contents = IOHelper::getFileContents($file); // Get extension $extension = IOHelper::getExtension($file); // Get matches per extension foreach ($this->_expressions[$extension] as $regex) { // Match translation functions if (preg_match_all($regex, $contents, $matches)) { // Collect foreach ($matches[2] as $original) { // Translate $translation = Craft::t($original, array(), null, $criteria->locale); // Show translation in textfield $field = craft()->templates->render('_includes/forms/text', array('id' => ElementHelper::createSlug($original), 'name' => 'translation[' . $original . ']', 'value' => $translation, 'placeholder' => $translation)); // Fill element with translation data $element = TranslateModel::populateModel(array('id' => ElementHelper::createSlug($original), 'original' => $original, 'translation' => $translation, 'source' => $path, 'file' => $file, 'locale' => $criteria->locale, 'field' => $field)); // If searching, only return matches if ($criteria->search && !stristr($element->original, $criteria->search) && !stristr($element->translation, $criteria->search)) { continue; } // If wanting one status, ditch the rest if ($criteria->status && $criteria->status != $element->getStatus()) { continue; } // Collect in array $occurences[$original] = $element; } } } // Return occurences return $occurences; }
public static function initDB() { global $dbConn; self::$dbConn = $dbConn; }