예제 #1
0
 function get_index($type = null, $object = null)
 {
     $object = (int) $object;
     $parent = $this->in('parent', null);
     if (!$this->accessible('list', $object, $parent)) {
         return false;
     }
     $rows = Post::with('author')->where('type', '=', $type)->where('object', '=', $object)->order_by('created_at', 'desc');
     "{$parent}" === '' or $rows->where('parent', '=', $parent ?: null);
     $rows = $rows->get();
     if ($rows and !$this->can('post.hidefiles')) {
         $files = File::fromLists('post', prop('id', $rows));
         $rows = S($rows, function ($model) use($files) {
             $attachments = (array) array_get($files, $model->id);
             return compact('attachments') + $model->withHTML()->to_array();
         });
     }
     return compact('rows');
 }
예제 #2
0
    return $result;
});
// Fired when a new unique File ID (UNSIGNED INT) needs to be generated.
// Make it as random as possible.
//
//= int non-zero
Event::listen(VANE_NS . 'file.new.id', function () {
    do {
        if (function_exists('openssl_random_pseudo_bytes')) {
            $bytes = S(str_split(openssl_random_pseudo_bytes(4)), 'ord');
        } else {
            $bytes = array(mt_rand(), mt_rand(), mt_rand(), mt_rand());
        }
        $bytes[0] %= 4;
        $id = join($bytes);
    } while (File::find($id));
    return $id;
});
// Fired when a new (prepared) File model needs to be inserted into the database.
//
//= bool
Event::listen(VANE_NS . 'file.insert', function (File &$file) {
    return $file->save();
});
// Fired once a new File has been successfully placed.
Event::listen(VANE_NS . 'file.inserted', function (File $file) {
});
// Fired when a File instance has been used in another context thus its reference
// counter should be updated.
//
//= bool