/** * Apply the Revcheck tools recursively on all lang * * @param $path The directory from which we start. * @param $revType Can be 'new' when we start a new revcheck with a clean database or 'update' when we revcheck just one folder (and all is sub-folders). Default to 'new' * @param $revLang The lang we want to apply the recheck. By default, it's 'all' lang available. * @return Nothing. */ public function applyRevCheck($path = '/', $revType = 'new', $revLang = 'all') { $am = AccountManager::getInstance(); $appConf = $am->appConf; $project = $am->project; if ($dh = @opendir($appConf[$project]['vcs.path'] . 'en' . $path)) { $dirs = array(); $files = array(); while (($name = readdir($dh)) !== false) { if ($name == '.' || $name == '..') { continue; } $file = new File('en', $path . $name); if (!$this->needParsing($file)) { continue; } if ($file->isDir) { $dirs[] = $file; } elseif ($file->isFile) { $files[] = $file; } } closedir($dh); foreach ($files as $f) { $en_size = intval(filesize($f->full_path) / 1024); $en_date = filemtime($f->full_path); $infoEN = $f->getInfo(); $en_revision = $infoEN['rev'] == 'NULL' ? 'NULL' : $infoEN['rev']; $xmlid = $infoEN['xmlid'] == 'NULL' ? 'NULL' : $infoEN['xmlid']; $tmp = explode('/', $f->path); // Only for Php project if ($project == 'PHP') { $check_doc = new ToolsCheckDoc(); $ToolsCheckDocResult = $check_doc->checkDoc($infoEN['content'], $f->path); } else { $ToolsCheckDocResult['check_oldstyle'] = 'NULL'; $ToolsCheckDocResult['check_undoc'] = 'NULL'; $ToolsCheckDocResult['check_roleerror'] = 'NULL'; $ToolsCheckDocResult['check_badorder'] = 'NULL'; $ToolsCheckDocResult['check_noseealso'] = 'NULL'; $ToolsCheckDocResult['check_noreturnvalues'] = 'NULL'; $ToolsCheckDocResult['check_noparameters'] = 'NULL'; $ToolsCheckDocResult['check_noexamples'] = 'NULL'; $ToolsCheckDocResult['check_noerrors'] = 'NULL'; } // If the type of this revcheck is an update, we start to remove all reference to this file from... if ($revType == 'update') { //... table `files` $query = 'DELETE FROM `files` WHERE `project`="%s" AND `lang`="en" AND `path`="%s" AND `name`="%s"'; $params = array($am->project, $f->path, $f->name); $this->conn->query($query, $params); //... table `errorfiles` $query = 'DELETE FROM `errorfiles` WHERE `project`="%s" AND `lang`="en" AND `path`="%s" AND `name`="%s"'; $params = array($am->project, $f->path, $f->name); $this->conn->query($query, $params); } // Sql insert. $query = 'INSERT INTO `files` (`project`, `lang`, `xmlid`, `path`, `name`, `revision`, `size`, `mdate`, `maintainer`, `status`, `check_oldstyle`, `check_undoc`, `check_roleerror`, `check_badorder`, `check_noseealso`, `check_noreturnvalues`, `check_noparameters`, `check_noexamples`, `check_noerrors`) VALUES ("%s", "en", "%s", "%s", "%s", "%s", "%s", "%s", NULL, NULL, "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")'; $params = array($am->project, $xmlid, $f->path, $f->name, $en_revision, $en_size, $en_date, $ToolsCheckDocResult['check_oldstyle'], $ToolsCheckDocResult['check_undoc'], $ToolsCheckDocResult['check_roleerror'], $ToolsCheckDocResult['check_badorder'], $ToolsCheckDocResult['check_noseealso'], $ToolsCheckDocResult['check_noreturnvalues'], $ToolsCheckDocResult['check_noparameters'], $ToolsCheckDocResult['check_noexamples'], $ToolsCheckDocResult['check_noerrors']); $this->conn->query($query, $params); /* $error = new ToolsError(); $error->setParams($infoEN['content'], '', 'en', $f->path, $f->name, ''); $error->run(); $error->saveError(); */ if ($revType == 'update') { // If we are in update, we have 2 case. $revLang can be en or LANG. // If revLang is en, we must re-check all available language to reflect changes. if ($revLang == 'en') { $ExistingLanguage = $this->getExistingLanguage(); } else { $ExistingLanguage[] = array("code" => $revLang); } } else { // If this is not an update, we check all languages $ExistingLanguage = $this->getExistingLanguage(); } foreach ($ExistingLanguage as $lang) { $lang = $lang["code"]; // We skip en language if ($lang == 'en') { continue; } $lang_file = new File($lang, $f->path . $f->name); // If the type of this revcheck is an update, we start be delete all reference to this file in table... if ($revType == 'update') { // ... `file` $query = 'DELETE FROM `files` WHERE `project`="%s" AND `lang`="%s" AND `path`="%s" AND `name`="%s"'; $params = array($project, $lang, $lang_file->path, $lang_file->name); $this->conn->query($query, $params); //... table `errorfiles` $query = 'DELETE FROM `errorfiles` WHERE `project`="%s" AND `lang`="%s" AND `path`="%s" AND `name`="%s"'; $params = array($project, $lang, $lang_file->path, $lang_file->name); $this->conn->query($query, $params); } if ($lang_file->exist()) { // Initial revcheck method $size = intval(filesize($lang_file->full_path) / 1024); $date = filemtime($lang_file->full_path); $size_diff = $en_size - $size; $date_diff = intval((time() - $en_date) / 86400) - intval((time() - $date) / 86400); $infoLANG = $lang_file->getInfo(); $revision = $infoLANG['en-rev'] == 'NULL' ? 'NULL' : $infoLANG['en-rev']; $maintainer = $infoLANG['maintainer'] == 'NULL' ? 'NULL' : $infoLANG['maintainer']; $status = $infoLANG['status'] == 'NULL' ? 'NULL' : $infoLANG['status']; $xmlid = $infoLANG['xmlid'] == 'NULL' ? 'NULL' : $infoLANG['xmlid']; $reviewed = $infoLANG['reviewed'] == 'NULL' ? 'NULL' : $infoLANG['reviewed']; $reviewed_maintainer = $infoLANG['reviewed_maintainer'] == 'NULL' ? 'NULL' : $infoLANG['reviewed_maintainer']; $query = 'INSERT INTO `files` (`project`, `lang`, `xmlid`, `path`, `name`, `revision`, `en_revision`, `reviewed`, `reviewed_maintainer`, `size`, `size_diff`, `mdate`, `mdate_diff`, `maintainer`, `status`) VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")'; $params = array($project, $lang, $xmlid, $lang_file->path, $lang_file->name, $revision, $en_revision, $reviewed, $reviewed_maintainer, $size, $size_diff, $date, $date_diff, $maintainer, $status); $this->conn->query($query, $params); /* // Check for error in this file ONLY if this file is uptodate if ($revision == $en_revision && $revision != 0 ) { $error = new ToolsError(); $error->setParams( $infoEN['content'], $infoLANG['content'], $lang, $lang_file->path, $lang_file->name, $maintainer ); $error->run(); $error->saveError(); } */ } else { $query = 'INSERT INTO `files` (`project`, `lang`, `path`, `name`, `size`) VALUES ("%s", "%s", "%s", "%s", "%s")'; $params = array($project, $lang, $lang_file->path, $lang_file->name, $en_size); $this->conn->query($query, $params); } } } foreach ($dirs as $d) { $this->applyRevCheck($d->path, $revType, $revLang); } } }
break; case 2: case 5: $error = lng('UPLOAD_FAIL'); break; case 6: $error = lng('DEL_FAIL'); break; case 7: $error = lng('FILE_EXIST'); break; } if ($result > 0 and $result != 7) { aExit($result, $error); } $file_info = $file->getInfo(); $ajax_message['file_id'] = $file_info['id']; $ajax_message['file_name'] = $file_info['name']; $ajax_message['file_size'] = $file_info['size']; $ajax_message['file_html'] = $file->Show(); aExit($result, $error); break; case 'like': $id = Filter::input('id', 'post', 'int'); $type = Filter::input('type', 'post', 'int'); $dislike = Filter::input('dislike', 'post', 'bool'); if (!$type or !$id) { break; } if (empty($user)) { aExit(3, 'Like not authed');
/** * Save a file. The new file have an extension like ".new", and is saved in the same folder as the original. * * @HERE : The new file no more have an extension '.new'. Now, it's saved into 'module-name-'new folder, with the same folder's hierarchie * * */ public function saveFile() { $am = AccountManager::getInstance(); $tx = new ToolsXmllint(); if (!$am->isLogged()) { return JsonResponseBuilder::failure(); } $filePath = $this->getRequestVariable('filePath'); $fileName = $this->getRequestVariable('fileName'); $fileLang = $this->getRequestVariable('fileLang'); $type = $this->hasRequestVariable('type') ? $this->getRequestVariable('type') : 'file'; $emailAlert = $this->hasRequestVariable('emailAlert') ? $this->getRequestVariable('emailAlert') : ''; // Clean up path $filePath = str_replace('//', '/', $filePath); // Extract lang from path if ($fileLang == 'all') { $t = explode('/', $filePath); $fileLang = $t[0]; array_shift($t); $filePath = '/' . implode('/', $t); } // Remove \ $fileContent = $this->getRequestVariable('fileContent'); // Replace by space $fileContent = str_replace(" ", "", $fileContent); // We check the Xml consistence only for .xml file if (substr($fileName, -3) == 'xml') { $xmlError = $tx->checkForError($fileContent); if ($xmlError != 'no_error') { return JsonResponseBuilder::failure(array('XmlError' => $xmlError)); } } // Get file object $file = new File($fileLang, $filePath . $fileName); // Rules to allow this file to be saved or not. if ($infoModified = $file->isModified()) { $infoModified = json_decode($infoModified); // If the user who have modified this file isn't the current one if ($am->userID == $infoModified->userID) { // We can modify it, it's mine ;) } else { // If the current user have karma, he can modify it. if ($am->haveKarma) { // The current user can modify it } else { // We must trow an error. We can't modify it. return JsonResponseBuilder::failure(array('type' => 'save_you_cant_modify_it')); } } } // Detect encoding $charset = $file->getEncoding($fileContent); // If the new charset is set to utf-8, we don't need to decode it if ($charset != 'utf-8') { $fileContent = iconv("UTF-8", $charset, $fileContent); } // We detect tab caracters and trow an error if we find one. if (strstr("\t", $fileContent)) { return JsonResponseBuilder::failure(array('type' => 'tabs_found')); } // Get revision $info = $file->getInfo($fileContent); if ($type == 'file') { $er = $file->save($fileContent); $isError = is_array($er) && empty($er['state']); if (!$isError) { $r = RepositoryManager::getInstance()->addProgressWork($file, $info['rev'], $info['en-rev'], $info['reviewed'], $info['reviewed_maintainer'], $info['maintainer']); return JsonResponseBuilder::success(array('id' => $r, 'lang' => $fileLang, 'revision' => $info['rev'], 'en_revision' => $info['en-rev'], 'maintainer' => $info['maintainer'], 'reviewed' => $info['reviewed'], 'reviewed_maintainer' => $info['reviewed_maintainer'])); } else { return JsonResponseBuilder::failure(array('type' => 'fs_error')); } } else { if ($type == 'trans') { // We must ensure that this folder exist localy if ($file->folderExist()) { $er = $file->save($fileContent); if ($er['state']) { $r = RepositoryManager::getInstance()->addProgressWork($file, $info['rev'], $info['en-rev'], $info['reviewed'], $info['reviewed_maintainer'], $info['maintainer'], 'new'); return JsonResponseBuilder::success(array('id' => $r, 'lang' => $fileLang, 'revision' => $info['rev'], 'en_revision' => $info['en-rev'], 'maintainer' => $info['maintainer'], 'reviewed' => $info['reviewed'], 'reviewed_maintainer' => $info['reviewed_maintainer'])); } else { return JsonResponseBuilder::failure(array('type' => 'fs_error')); } } else { return JsonResponseBuilder::failure(); } } } }
private function getOutputId() { // The output file name is the first ID of the file $file = explode('/', $this->path); $lang = $file[0]; array_shift($file); $path = implode('/', $file); $fileInfo = new File($lang, $path); $info = $fileInfo->getInfo(); $xmlIDs = explode('|', $info['xmlid']); $xmlID = $xmlIDs[0]; return $xmlID; }
public function Create($post_name, $user_id, $id_word = null, $id_rewrite = false) { $user_id = (int) $user_id; if (!POSTGood($post_name, self::$formats)) { return 1; } if ($id_word and !preg_match("/^[a-zA-Z0-9._-]+\$/", $id_word)) { return 3; } $new_file_info = POSTSafeMove($post_name, $this->base_dir); if (!$new_file_info) { return 2; } $way = $this->base_dir . $new_file_info['tmp_name']; $hash = md5_file($this->base_dir . $new_file_info['tmp_name']); $sql_part = $id_word ? " OR `id_word`=:id_word" : ''; $data = $id_word ? array('id_word' => $id_word) : false; $line = getDB()->fetchRow("SELECT `id` FROM `{$this->db}` " . "WHERE `hash`='" . $hash . "'" . $sql_part, $data, 'num'); if ($line) { $file_similar = new File($line[0]); $similar_info = $file_similar->getInfo(); if ($similar_info['hash'] == $hash) { if (file_exists($way)) { unlink($way); } $this->id = $similar_info['id']; $this->user_id = $similar_info['user_id']; $this->id_word = $similar_info['id_word']; $this->name = $similar_info['name']; $this->size = $similar_info['size']; $this->hash = $similar_info['hash']; $this->downloads = $similar_info['downloads']; $this->way = $file_similar->getWay(); return 7; } else { if (!$id_rewrite) { if (file_exists($way)) { unlink($way); } return 4; } else { if (!$file_similar->Delete()) { return 6; } unset($file_similar); } } } $sql = "INSERT INTO {$this->db} (id_word, user_id, way, name, size, hash) " . "VALUES (:id_word, :user_id, :fway, :fname, :fsize, '{$hash}')"; $result = getDB()->ask($sql, array('id_word' => $id_word ? $id_word : '', 'user_id' => $user_id, 'fway' => $new_file_info['tmp_name'], 'fname' => $new_file_info['name'], 'fsize' => $new_file_info['size_mb'])); if ($result) { $this->id = getDB()->lastInsertId(); $this->user_id = $user_id; $this->id_word = $id_word ? $id_word : ''; $this->way = $way; $this->name = $new_file_info['name']; $this->size = $new_file_info['size_mb']; $this->hash = $hash; $this->downloads = 0; } else { if (file_exists($way)) { unlink($way); } return 5; } return 0; }
/** * {@inheritdoc} * @param string $locale * @return array */ public function getInfo($locale = null) { $info = parent::getInfo($locale); $info['sizes'] = array(); $sizes = $this->getImageSizeCollection(); foreach ($sizes as $size) { $sizeName = $size->getName(); $info['sizes'][$sizeName] = array('id' => $sizeName, 'width' => $size->getWidth(), 'height' => $size->getHeight()); } $info['sizes']['original'] = array('id' => 'original', 'width' => $this->getWidth(), 'height' => $this->getHeight()); return $info; }