protected function executeSave() { $redirect = $this->getRequestParameter('redirect'); $id = $this->getRequestParameter(); $m = $this->getRequestParameter('m', 'array', array()); try { $ex = ProjectManager::getInstance()->getByPk($id, true); $ex->addField('oldImage', 'string', $ex->image); $ex->updateFromRequest($m); if (!$ex->isValid()) { throw new EUserMessageError("Ошибка при сохранении", $ex); } if (!$ex->save()) { throw new EUserMessageError("Ошибка при сохранении", $ex); } $this->setFlash('Данные успешно сохранены', self::$FLASH_SUCCESS); $this->setHeader('redirect', fvSite::$fvConfig->get('dir_web_root') . $this->getRequest()->getRequestParameter('module') . ($redirect ? "" : "/edit/?id=" . $ex->getPk())); } catch (EUserMessageError $e) { $this->setFlash($e->getMessage(), self::$FLASH_ERROR); $this->setHeader('X-JSON', json_encode($e->getValidationResult())); } catch (EDatabaseError $db) { $this->setFlash($db->getMessage(), self::$FLASH_ERROR); } return $this->getRequest()->isXmlHttpRequest() ? self::$FV_AJAX_CALL : self::$FV_OK; }
function showEdit() { $id = $this->getRequestParameter(); $ex = ProjectManager::getInstance()->getByPk($id, true); $this->__assign("tmpDir", fvSite::$fvConfig->get("path.upload.web_temp_image")); $this->__assign("ex", $ex); $this->__assign("wt", range(-20, 20)); return $this->__display('edit.tpl'); }
function validateUrl($value) { $valid = $this->doValidateEmpty($value); if (!$valid) { $msg = "Поле обязательное."; } $inst = ProjectManager::getInstance()->getOneByurl($value); if (ProjectManager::getInstance()->isRootInstance($inst) && $inst->getPk() != $this->getPk()) { $valid = false; $msg = "Поле должно быть уникально."; } $this->setValidationResult('url', $valid, $msg); return $valid; }
<?php /*** * This script is intended to be placed in a cronjob. * It must be run every Thursday, at 01hOO for example. * On Unix, you can use crontab -e and place this : * 00 01 * * 4 /path/php/binary /path/to/your/vcs/dir/doc-editor/scripts/cron/check_entities.php ****/ require_once dirname(__FILE__) . '/../../php/Conf.php'; require_once dirname(__FILE__) . '/../../php/LockFile.php'; require_once dirname(__FILE__) . '/../../php/ProjectManager.php'; require_once dirname(__FILE__) . '/../../php/RepositoryManager.php'; require_once dirname(__FILE__) . '/../../php/ToolsCheckEntities.php'; $rm = RepositoryManager::getInstance(); $pm = ProjectManager::getInstance(); $availableProject = $pm->getAvailableProject(); while (list($key, $project) = each($availableProject)) { if ($project['code'] != "php") { continue; } // Define it as a project $pm->setProject($project['code']); $lock = new LockFile('project_' . $project['code'] . '_lock_check_entities'); if ($lock->lock()) { ToolsCheckEntities::getInstance()->startCheck(); // Set lastUpdate date/time $info = array(); $info['user'] = '******'; $rm->setStaticValue('info', 'checkEntities', json_encode($info), true); } // Remove the lock File
/** * Get all available project */ public function getAvailableProject() { $r = ProjectManager::getInstance()->getAvailableProject(); return JsonResponseBuilder::success(array('nbItems' => count($r), 'Items' => $r)); }
function showIndex() { $List = ProjectManager::getInstance()->getAll("is_show=1", "weight asc"); $this->__assign("List", $List); return $this->__display("index.tpl"); }
/** * Log into this application. * * @param $project The project we want to work on. * @param $vcsLogin The login use to identify this user into PHP VCS server. * @param $vcsPasswd The password, in plain text, to identify this user into PHP VCS server. * @param $email The email for this user. Need to contact him via the application. * @param $lang The language we want to access. * @return An associated array. */ public function login($project, $vcsLogin, $vcsPasswd, $email, $lang = 'en', $authService = 'VCS', $authServiceID) { // Var to return into ExtJs $return = array(); // We manage the project if (ProjectManager::getInstance()->setProject($project)) { $this->project = strtoupper($project); } else { $return['state'] = false; $return['msg'] = 'Bad project'; $return['authMethod'] = '-'; return $return; } $this->authService = $authService; $this->authServiceID = $authServiceID; /* * VCS AUTH SYSTEM * */ if ($this->authService == 'VCS') { /* * ANONYMOUS VCS * */ // Anonymous's user can logging into this app by providing this login/pass => anonymous/(empty) ou (empty)/(empty) // The result is the same. $this->vcsLogin will be "anonymous" and $this->vcsPasswd, (empty) if ($vcsLogin == "anonymous" && $vcsPasswd == "" || $vcsLogin == "" && $vcsPasswd == "") { $this->isAnonymous = true; $this->haveKarma = false; // Even if the user provide an empty login, we force it to be 'anonymous' $vcsLogin = '******'; $this->anonymousIdent = isset($_COOKIE['anonymousIdent']) ? $_COOKIE['anonymousIdent'] : uniqid('', true); setcookie("anonymousIdent", $this->anonymousIdent, time() + 3600 * 24 * 365, "/"); // One year ;) // Register var $this->vcsLogin = $vcsLogin; $this->vcsPasswd = ''; $this->vcsLang = $lang; $this->email = $email; // Check DB $s = 'SELECT * FROM `users` WHERE `project` = "%s" AND `authService` = "VCS" AND `vcs_login` = "%s" AND `anonymousIdent` = "%s"'; $params = array($project, $this->vcsLogin, $this->anonymousIdent); $r = $this->conn->query($s, $params); if ($r->num_rows == 1) { //This anonymous user exist into DB. We store his configuration into ... $a = $r->fetch_object(); // ... object's property ... $this->userConf = json_decode($a->conf); $this->userID = $a->userID; // ... and into the php's session (only specific var) $_SESSION['userConf'] = $this->userConf; // We update the email if this user have decided to change it. $this->updateEmail(); } else { // We register this new valid user $userID = $this->register(); $this->userID = $userID; // Store in session only specific var $_SESSION['userConf'] = $this->defaultConf; } // Generic session var for VALID & ANONYMOUS VCS user $_SESSION['userID'] = $this->userID; $_SESSION['project'] = $this->project; $_SESSION['vcsLogin'] = $this->vcsLogin = $this->vcsLogin . ' #' . $this->userID; $_SESSION['vcsPasswd'] = $this->vcsPasswd; $_SESSION['isAnonymous'] = $this->isAnonymous; $_SESSION['haveKarma'] = $this->haveKarma; $_SESSION['anonymousIdent'] = $this->anonymousIdent; $_SESSION['lang'] = $this->vcsLang; $_SESSION['email'] = $this->email; $_SESSION['authService'] = $this->authService; $_SESSION['authServiceID'] = $this->authServiceID; // We set up the CSRF token $_SESSION['csrfToken'] = sha1(uniqid(rand(), true)); // Store some user info in cookies: we can use this to pre-fill the // login page if the user's session expires. setcookie("loginApp", 'anonymous', time() + 3600 * 24 * 365, "/"); // One year ;) setcookie("email", $this->email, time() + 3600 * 24 * 365, "/"); setcookie("lang", $this->vcsLang, time() + 3600 * 24 * 365, "/"); // We construct the return's var for ExtJs $return['state'] = true; $return['msg'] = 'Welcome !'; return $return; } else { $this->isAnonymous = false; $this->anonymousIdent = ''; // If this app is installed into Php's server, we use the standad way to verify login/password if ($_SERVER["SERVER_NAME"] == "doc.php.net") { // We try to authenticate this user to master php server. $AuthReturn = VCSFactory::getInstance()->masterPhpAuthenticate($vcsLogin, $vcsPasswd); $return['authMethod'] = 'masterPhp'; } else { // We try to authenticate this user to VCS server. $AuthReturn = VCSFactory::getInstance()->svnAuthenticate($vcsLogin, $vcsPasswd); $return['authMethod'] = 'svnServer'; } if ($AuthReturn !== true) { $return['state'] = false; $return['msg'] = $AuthReturn; return $return; } else { // Check the karma $karma = $this->checkKarma($vcsLogin, $lang); $this->haveKarma = $karma === true; // Register var $this->vcsLogin = $vcsLogin; $this->vcsPasswd = $vcsPasswd; $this->vcsLang = $lang; $this->email = $email; // Check DB $s = 'SELECT * FROM `users` WHERE `project` = "%s" AND `authService` = "VCS" AND `vcs_login` = "%s"'; $params = array($project, $this->vcsLogin); $r = $this->conn->query($s, $params); if ($r->num_rows == 1) { //This user exist into DB. We store his configuration into ... $a = $r->fetch_object(); // ... object's property ... $this->userConf = json_decode($a->conf); $this->userID = $a->userID; // ... and into the php's session (only specific var) $_SESSION['userConf'] = $this->userConf; // We update the email if this user have decided to change it. $this->updateEmail(); } else { // We register this new valid user $userID = $this->register(); $this->userID = $userID; // Store in session only specific var $_SESSION['userConf'] = $this->defaultConf; } // Generic session var for VALID & ANONYMOUS VCS user $_SESSION['userID'] = $this->userID; $_SESSION['project'] = $this->project; $_SESSION['vcsLogin'] = $this->vcsLogin; $_SESSION['vcsPasswd'] = $this->vcsPasswd; $_SESSION['isAnonymous'] = $this->isAnonymous; $_SESSION['haveKarma'] = $this->haveKarma; $_SESSION['anonymousIdent'] = $this->anonymousIdent; $_SESSION['lang'] = $this->vcsLang; $_SESSION['email'] = $this->email; $_SESSION['authService'] = $this->authService; $_SESSION['authServiceID'] = $this->authServiceID; // We set up the CSRF token $_SESSION['csrfToken'] = sha1(uniqid(rand(), true)); // Store some user info in cookies: we can use this to pre-fill the // login page if the user's session expires. setcookie("loginApp", utf8_encode($this->vcsLogin), time() + 3600 * 24 * 365, "/"); // One year ;) setcookie("email", $this->email, time() + 3600 * 24 * 365, "/"); setcookie("lang", $this->vcsLang, time() + 3600 * 24 * 365, "/"); // We construct the return's var for ExtJs $return['state'] = true; $return['msg'] = 'Welcome !'; return $return; } } } else { if ($this->authService == 'google' || $this->authService == 'facebook' || $this->authService == 'github' || $this->authService == 'stackoverflow' || $this->authService == 'linkedin' || $this->authService == 'instagram' || $this->authService == 'twitter') { $this->isAnonymous = true; $this->haveKarma = false; $this->anonymousIdent = $this->authService . '-' . $this->authServiceID; // Register var $this->vcsLogin = $vcsLogin; $this->vcsPasswd = ''; $this->vcsLang = $lang; $this->email = $email; // Check DB $s = 'SELECT * FROM `users` WHERE `project` = "%s" AND `authService` = "%s" AND `authServiceID` = "%s" AND `vcs_login` = "%s" AND `anonymousIdent` = "%s"'; $params = array($project, $this->authService, $this->authServiceID, $this->vcsLogin, $this->anonymousIdent); $r = $this->conn->query($s, $params); if ($r->num_rows == 1) { //This anonymous user exist into DB. We store his configuration into ... $a = $r->fetch_object(); // ... object's property ... $this->userConf = json_decode($a->conf); $this->userID = $a->userID; // ... and into the php's session (only specific var) $_SESSION['userConf'] = $this->userConf; // We update the email if this user have decided to change it. $this->updateEmail(); } else { // We register this new valid user $userID = $this->register(); $this->userID = $userID; // Store in session only specific var $_SESSION['userConf'] = $this->defaultConf; } // Generic session var for VALID & ANONYMOUS VCS user $_SESSION['userID'] = $this->userID; $_SESSION['project'] = $this->project; $_SESSION['vcsLogin'] = $this->vcsLogin; $_SESSION['vcsPasswd'] = $this->vcsPasswd; $_SESSION['isAnonymous'] = $this->isAnonymous; $_SESSION['haveKarma'] = $this->haveKarma; $_SESSION['anonymousIdent'] = $this->anonymousIdent; $_SESSION['lang'] = $this->vcsLang; $_SESSION['email'] = $this->email; $_SESSION['authService'] = $this->authService; $_SESSION['authServiceID'] = $this->authServiceID; // We set up the CSRF token $_SESSION['csrfToken'] = sha1(uniqid(rand(), true)); // Store some user info in cookies: we can use this to pre-fill the // login page if the user's session expires. setcookie("loginApp", htmlentities($this->vcsLogin), time() + 3600 * 24 * 365, "/"); // One year ;) setcookie("email", $this->email, time() + 3600 * 24 * 365, "/"); setcookie("lang", $this->vcsLang, time() + 3600 * 24 * 365, "/"); // We construct the return's var for ExtJs $return['state'] = true; $return['msg'] = 'Welcome !'; return $return; } else { $return['state'] = false; $return['msg'] = 'Bad authService'; $return['authMethod'] = '-'; return $return; } } }
/** * Start the check. * */ public function startCheck() { $project = ProjectManager::getInstance()->project; $this->cleanUpDatabase(); $file = $this->getEntitiesContent(); $array = explode('<!-- Obsoletes -->', $file); // Find entity names and URLs $schemes_preg = '(?:' . join('|', $this->supportedSchemes) . ')'; preg_match_all("@<!ENTITY\\s+(\\S+)\\s+([\"'])({$schemes_preg}://[^\\2]+)\\2\\s*>@U", $array[0], $entitiesFound); // These are the useful parts $this->entityNames = $entitiesFound[1]; $this->entityUrls = $entitiesFound[3]; if ($this->forkUrlAllow) { // use the forking method ... MUCH faster declare (ticks=1); $children = 0; for ($num = 0; $num < count($this->entityUrls); $num++) { $name = $this->entityNames[$num]; $url = $this->entityUrls[$num]; if ($children < $this->forkNumAllowed) { $pid = pcntl_fork(); if ($pid) { // parent ++$children; } else { // child if (!in_array($name, $this->EntitiesNotChecked)) { $r = $this->checkUrl($num, $url); $query = 'INSERT INTO `checkEntities` (`project`, `entities`, `url`, `result`, `date`) VALUES ("%s", "%s", "%s", "%s", now())'; $params = array($project, $name, $url, $r[0]); $this->conn->query($query, $params); } exit; } } else { // enough $children $status = 0; $child = pcntl_wait($status); --$children; } } while ($children) { $status = 0; $child = pcntl_wait($status); --$children; } } else { // no forking // walk through entities found foreach ($this->entityUrls as $num => $entityUrl) { if (!in_array($this->entityNames[$num], $this->EntitiesNotChecked)) { $r = $this->checkUrl($num, $entityUrl); $query = 'INSERT INTO `checkEntities` (`project`, `entities`, `url`, `result`, `date`) VALUES ("%s", "%s", "%s", "%s", now())'; $params = array($project, $this->entityNames[$num], $entityUrl, $r[0]); $this->conn->query($query, $params); } } ++$num; // (for the count) } }
$patchID = trim($_REQUEST['patchID'], '/ '); $_project = $_REQUEST['project']; require_once dirname(__FILE__) . '/php/ProjectManager.php'; require_once dirname(__FILE__) . '/php/RepositoryManager.php'; // Set the project ProjectManager::getInstance()->setProject($_project); $patchInfo = RepositoryManager::getInstance()->getPatchInfo($patchID); $jsVar = "\n" . 'var directAccess = {"link":"patchID", "lang":"en", "patchID":"' . htmlspecialchars($patchID) . '", "patchName":"' . htmlspecialchars($patchInfo->name) . '", "project":"' . htmlspecialchars($_project) . '"},'; } else { if (isset($_REQUEST['action'])) { $_project = $_REQUEST['project']; $_action = $_REQUEST['action']; $_idDB = $_REQUEST['idDB']; require_once dirname(__FILE__) . '/php/ProjectManager.php'; // Set the project ProjectManager::getInstance()->setProject($_project); $jsVar = "\n" . 'var directAccess = { "project":"' . htmlspecialchars($_project) . '", "action": "' . htmlspecialchars($_action) . '", "idDB": "' . htmlspecialchars($_idDB) . '" },'; } else { $jsVar = "\nvar directAccess = false,"; } } } } // Init auth var if (isset($_COOKIE['loginApp'])) { $jsVar .= " loginApp = \"" . html_entity_decode($_COOKIE['loginApp']) . "\","; } else {