Example #1
0
 /**
  * Read a key from the cache
  *
  * @param string $key Identifier for the data
  * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
  */
 public function read($key)
 {
     if (!$this->_init || $this->_setKey($key) === false) {
         return false;
     }
     if ($this->settings['lock']) {
         $this->_File->flock(LOCK_SH);
     }
     $this->_File->rewind();
     $time = time();
     $cachetime = intval($this->_File->current());
     if ($cachetime !== false && ($cachetime < $time || $time + $this->settings['duration'] < $cachetime)) {
         if ($this->settings['lock']) {
             $this->_File->flock(LOCK_UN);
         }
         return false;
     }
     $data = '';
     $this->_File->next();
     while ($this->_File->valid()) {
         $data .= $this->_File->current();
         $this->_File->next();
     }
     if ($this->settings['lock']) {
         $this->_File->flock(LOCK_UN);
     }
     $data = trim($data);
     if ($data !== '' && !empty($this->settings['serialize'])) {
         if ($this->settings['isWindows']) {
             $data = str_replace('\\\\\\\\', '\\', $data);
         }
         $data = unserialize((string) $data);
     }
     return $data;
 }
Example #2
0
 /**
  * Retrieves info for the current user account
  *
  * @author Thibaud Rohmer
  */
 public static function init()
 {
     CurrentUser::$accounts_file = Settings::$conf_dir . "/accounts.xml";
     CurrentUser::$groups_file = Settings::$conf_dir . "/groups.xml";
     /// Set path
     if (isset($_GET['f'])) {
         CurrentUser::$path = stripslashes(File::r2a($_GET['f']));
         if (isset($_GET['p'])) {
             switch ($_GET['p']) {
                 case 'n':
                     CurrentUser::$path = File::next(CurrentUser::$path);
                     break;
                 case 'p':
                     CurrentUser::$path = File::prev(CurrentUser::$path);
                     break;
             }
         }
     } else {
         /// Path not defined in URL
         CurrentUser::$path = Settings::$photos_dir;
     }
     /// Set CurrentUser account
     if (isset($_SESSION['login'])) {
         self::$account = new Account($_SESSION['login']);
         // groups sometimes can be null
         $groups = self::$account->groups === NULL ? array() : self::$account->groups;
         self::$admin = in_array("root", $groups);
         self::$uploader = in_array("uploaders", $groups);
     }
     /// Set action (needed for page layout)
     if (isset($_GET['t'])) {
         switch ($_GET['t']) {
             case "Page":
             case "Img":
             case "Thb":
                 CurrentUser::$action = $_GET['t'];
                 break;
             case "Big":
             case "BDl":
             case "Zip":
                 if (!Settings::$nodownload) {
                     CurrentUser::$action = $_GET['t'];
                 }
                 break;
             case "Reg":
                 if (isset($_POST['login']) && isset($_POST['password'])) {
                     if (!Account::create($_POST['login'], $_POST['password'], $_POST['verif'])) {
                         echo "Error creating account.";
                     }
                 }
             case "Log":
                 if (isset($_SESSION['login'])) {
                     CurrentUser::logout();
                     echo "logged out";
                     break;
                 }
                 if (isset($_POST['login']) && isset($_POST['password'])) {
                     try {
                         if (!CurrentUser::login($_POST['login'], $_POST['password'])) {
                             echo "Wrong password";
                         }
                     } catch (Exception $e) {
                         echo "Account not found";
                     }
                 }
                 if (!isset(CurrentUser::$account)) {
                     CurrentUser::$action = $_GET['t'];
                 }
                 break;
             case "Acc":
                 if (isset($_POST['old_password'])) {
                     Account::edit($_POST['login'], $_POST['old_password'], $_POST['password'], $_POST['name'], $_POST['email']);
                 }
                 CurrentUser::$action = "Acc";
                 break;
             case "Adm":
                 if (CurrentUser::$admin) {
                     CurrentUser::$action = "Adm";
                 }
                 break;
             case "Com":
                 Comments::add(CurrentUser::$path, $_POST['content'], $_POST['login']);
                 break;
             case "Rig":
                 Judge::edit(CurrentUser::$path, $_POST['users'], $_POST['groups'], true);
                 CurrentUser::$action = "Judge";
                 break;
             case "Pub":
                 Judge::edit(CurrentUser::$path);
                 CurrentUser::$action = "Judge";
                 break;
             case "Pri":
                 Judge::edit(CurrentUser::$path, array(), array(), true);
                 CurrentUser::$action = "Judge";
                 break;
             case "Inf":
                 CurrentUser::$action = "Inf";
                 break;
             case "Fs":
                 if (is_file(CurrentUser::$path)) {
                     CurrentUser::$action = "Fs";
                 }
                 break;
             default:
                 CurrentUser::$action = "Page";
                 break;
         }
     } else {
         CurrentUser::$action = "Page";
     }
     if (isset($_GET['a']) && CurrentUser::$action != "Adm") {
         if (CurrentUser::$admin || CurrentUser::$uploader) {
             new Admin();
         }
     }
     if (isset($_GET['j'])) {
         CurrentUser::$action = "JS";
     }
     /// Set default action
     if (!isset(CurrentUser::$action)) {
         CurrentUser::$action = "Page";
     }
     /// Throw exception if accounts file is missing
     if (!file_exists(CurrentUser::$accounts_file)) {
         throw new Exception("Accounts file missing", 69);
     }
     /// Create Group File if it doesn't exist
     if (!file_exists(CurrentUser::$groups_file)) {
         Group::create_group_file();
     }
     if (isset(CurrentUser::$account)) {
         CurrentUser::$admin = in_array("root", CurrentUser::$account->groups);
     }
 }
Example #3
0
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//-----------------------------------------------------------------------------
//
// $Revision$
//
//-----------------------------------------------------------------------------
require_once "../php-marc/php-marc.php";
// Other way to access file
/*$string = file("example.mrc");
$file = new USMARC($string[0]);*/
// Open file
$file = new File("example.mrc");
// Read next record
$record = $file->next();
// Create new field
$field = new Field("245", "", "", array("a" => "Mumin"));
// Add subfield
$field->add_subfields(array("b" => "Det Osynliga Barnet"));
// Other ways to update field
$field->update(array("ind2" => "1", "b" => "Vinter i Mumindalen", "c" => "Tove Jansson"));
// Replace existing field
$existing =& $record->field("245");
$existing->replace_with($field);
$clone = $field->make_clone();
// Change some more
$clone->update(array("a" => "Muminsagor", "b" => "Muminpappans memoarer"));
// And append to record
$record->append_fields($clone);
// Some output
Example #4
0
}
$_REQUEST['limit'] = intval($_REQUEST['limit']);
if ($_REQUEST['offset']) {
    $_REQUEST['offset'] = intval($_REQUEST['offset']);
} else {
    $_REQUEST['offset'] = 0;
}
if (!$_REQUEST['sort'] && !@$_REQUEST['order']) {
    $_REQUEST['sort'] = "name";
    $_REQUEST['order'] = "ascend";
}
// Retrieve all files...
$file = new File();
$data = array();
$max = 0;
for ($name = $file->first(); $name; $name = $file->next()) {
    $max++;
    $data[$name] = $file->stamp;
}
if ($max < 1) {
    pieError("NoFiles");
}
// ... and sort them.
if ($_REQUEST['sort'] == "name" && $_REQUEST['order'] == "descend") {
    krsort($data);
} elseif ($_REQUEST['sort'] == "name") {
    ksort($data);
} elseif ($_REQUEST['sort'] == "date" && $_REQUEST['order'] == "descend") {
    arsort($data);
} elseif ($_REQUEST['sort'] == "date") {
    asort($data);
Example #5
0
//database connection settings
require_once "php-marc/php-marc.php";
//does the MaRC heavy lifting
//require_once 'ansel/Ansel2Unicode.php';
//$a2u = new Ansel2Unicode();
$marc_data = new File("marc_import_files/toc-data.mrc");
//the file we want to process
//   -----Timer-----    //
$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
//   -----Timer-----    //
$count = 0;
//just counting MARC records
while ($record = $marc_data->next()) {
    $count++;
    $fields = $record->fields();
    //var_dump($record);  //troubleshooting - dumps a php-marc generated array
    $i = 0;
    $j = 0;
    //used for for/foreach loops below
    //   ----------LOOP THROUGH MARC FIELDS----------   //
    foreach ($fields as $field) {
        switch ((string) $field[0]->tagno) {
            case '001':
                //Innovative-supplied Bibid
                $bibid = $field[0]->data;
                break;
            case '005':
                //last updated
Example #6
0
        pieError("ErrorExists", array('original' => htmlspecialchars($original), 'alias' => htmlspecialchars($alias), 'context' => $context));
    }
    if (!$resource->read($alias, 0)) {
        pieError("SourceReadError");
    }
    $data = array_map('htmlspecialchars', $resource->meta);
    $data['alias'] = htmlspecialchars($alias);
    $data['stamp'] = date($GLOBALS['pie']['time_format'], $data['stamp']);
    $data['context'] = $context;
    pieNotice("AliasInfo", $data);
    pieError("CreateAlias", array('original' => htmlspecialchars($original), 'context' => $context));
} elseif (@$original) {
    // Display information about the resource.
    // Built a list of all aliases of the resource.
    $aliases = array();
    for ($i = $resource->first(); $i; $i = $resource->next()) {
        if ($resource->read($i, 0) === false) {
            pieError("SourceReadError");
        }
        if ($resource->meta['type'] != 'alias') {
            continue;
        }
        if ($resource->meta['original'] != $original) {
            continue;
        }
        $aliases[] = $i;
    }
    if (!count($aliases)) {
        if (@$is_alias) {
            pieTail();
            exit;