コード例 #1
0
ファイル: storage.php プロジェクト: LeonB/site
 public function getUri($title, $id = 0, $contenttypeslug, $fulluri = true)
 {
     $contenttype = $this->getContentType($contenttypeslug);
     $tablename = $this->prefix . $contenttype['slug'];
     $id = intval($id);
     $fulluri = util::str_to_bool($fulluri);
     $slug = makeSlug($title);
     // don't allow strictly numeric slugs.
     if (is_numeric($slug)) {
         $slug = $contenttype['singular_slug'] . "-" . $slug;
     }
     // Only add 'entry/' if $full is requested.
     if ($fulluri) {
         $prefix = "/" . $contenttype['singular_slug'] . "/";
     }
     $query = "SELECT id from {$tablename} WHERE slug='{$slug}' and id!='{$id}';";
     $res = $this->db->query($query)->fetch();
     if (!$res) {
         $uri = $prefix . $slug;
     } else {
         for ($i = 1; $i <= 10; $i++) {
             $newslug = $slug . '-' . $i;
             $query = "SELECT id from {$tablename} WHERE slug='{$newslug}' and id!='{$id}';";
             $res = $this->db->query($query)->fetch();
             if (!$res) {
                 $uri = $prefix . $newslug;
                 break;
             }
         }
         // otherwise, just get a random slug.
         if (empty($uri)) {
             $slug = trimText($slug, 32, false, false) . "-" . makeKey(6);
             $uri = $prefix . $slug;
         }
     }
     return $uri;
 }
コード例 #2
0
        $s .= $value;
        if ($i < $c) {
            $s .= ',';
        }
        $i++;
    }
    $s .= ']';
    return $s;
}
function textToHTML($s)
{
    $s = preg_replace('/(\\r?\\n){2,}/', '</p><p>', $s);
    $s = preg_replace('/(\\r?\\n)+/', '<br>', $s);
    return '<p>' . $s . '</p>';
}
$key = makeKey($_POST['name']);
$icon = $_POST['icon'];
$label = $_POST['name'];
$countries = makeYamlArray($_POST['countries']);
$location = sprintf('[%s]', $_POST['location']);
$content = textToHTML($_POST['description']);
$url = $_POST['website'];
$coins = makeYamlArray($_POST['coins']);
$file = './data/services.yaml';
$current = file_get_contents($file);
$yaml = "\n{$key}:\n  label: {$label}\n  icon: {$icon}\n  countries: {$countries}\n  location: {$location}\n  url: {$url}\n  content: |\n    {$content}\n  coins: {$coins}\n";
try {
    $branchname = 'update/' . time() . '_' . $key;
    $git = new Git();
    $git->createNewBranch($branchname);
    $fileInfo = $git->getFileInformation('master');
コード例 #3
0
ファイル: objects.php プロジェクト: laiello/pivotx-sqlite
 /**
  * Attempt to log in a user, using the passed credentials. If succesfull,
  * the session info is updated and 'true' is returned. When unsuccesful
  * the session remains unaltered, and false is returned
  *
  *
  * @param string $username
  * @param string $password
  * @param int $stay
  * @return boolean
  */
 function login($username, $password, $stay)
 {
     global $PIVOTX;
     $this->loadLogins();
     if (!$this->checkFailedLogins()) {
         debug(sprintf(__("Blocked login attempt from '%s'."), $_SERVER['REMOTE_ADDR']));
         $this->message = __('Too many failed login attempts from this IP address. ' . 'Please contact your site administrator to unblock your account.');
         return false;
     }
     $username = strtolower($username);
     $match = $PIVOTX['users']->checkPassword($username, $password);
     if (!$match) {
         $this->message = __('Incorrect username/password');
         $this->logFailedLogin();
         return false;
     } else {
         $this->message = __('Successfully logged in');
         $key = makeKey(16);
         $_SESSION['pivotxsession'] = $key;
         // Add the 'lastseen' to the user settings and remove and reset_ids.
         $PIVOTX['users']->updateUser($username, array('lastseen' => time(), 'reset_id' => ''));
         // Keep track of people logging in (and remove any failed logins
         // for IP if any).
         $this->logins['succeeded'][] = array('username' => $username, 'time' => time(), 'ip' => $_SERVER['REMOTE_ADDR']);
         unset($this->logins['failed'][$_SERVER['REMOTE_ADDR']]);
         $this->saveLogins();
         $_SESSION['user'] = $PIVOTX['users']->getUser($username);
         $path = $PIVOTX['paths']['site_url'];
         // Set to 'site url' instead of 'pivotx_url', because then we
         // can use 'edit this entry' and the like.
         if ($stay == 1) {
             $this->setCookie($this->cookie_name, $key);
         } else {
             $this->setCookie($this->cookie_name, $key, 0);
         }
         $this->permsessions[$key] = array('username' => $username, 'ip' => $_SERVER['REMOTE_ADDR'], 'lastseen' => time());
         $this->savePermsessions();
         return true;
     }
 }