function content_by_tag($tag, $max = 1000000) { require_once 'lib/css2xpath.inc.php'; if ($this->output_dir) { $this->output_dir = $this->get_output_dir($this->output_dir . '/' . preg_replace('/\\W/', '_', $tag)); } // FIXME: proper sanitising $css2xpath = new CSS2XPath(); $xpath = array_map(array($css2xpath, 'transform'), array('item' => '#bookmarklist .post .bookmark', 'link' => 'a.taggedlink', 'user' => 'a.user span', 'next' => '#pagination .next', 'count' => '.delNavCount', 'tag' => 'a[rel=tag] span', 'date' => '.dateGroup span')); $page = 1; $n = 100; $count = 0; do { $this->get_data('http://delicious.com/tag/' . urlencode($tag), array('setcount' => $n, 'page' => $page), 'html', $http); foreach ($this->data->xpath($xpath['item']) as $item) { $link = current($item->xpath($xpath['link'])); $result = $item->xpath($xpath['date']); if (!empty($result)) { $date = strtotime((string) $result[0]['title']); } if (!$date) { break 2; } $data = array('uri' => (string) $link['href'], 'title' => (string) $link, 'user' => (string) current($item->xpath($xpath['user'])), 'count' => (int) current($item->xpath($xpath['count'])), 'date' => $date); if (!$data['uri']) { break 2; } $tags = array(); foreach ($item->xpath($xpath['tag']) as $tag) { $data['tags'][] = (string) $tag; } if ($this->output_dir) { file_put_contents(sprintf('%s/%s.js', $this->output_dir, base64_encode_file($data['user'] . '*' . $data['uri'])), json_encode($data)); } else { $this->results[] = $item; } } $next = current($xml->xpath($xpath['next'])); $page = 0; if (preg_match('/page=(\\d+)$/', (string) $next['href'], $matches)) { $page = $matches[1]; sleep(1); } debug('Page ' . $page); } while ($page); }
function core_files_upload_object() { //first, gather the necessary variables global $_POST; //then, convert variables for the Moodle object: /* [contextid] => int [component] => string [filearea] => string [itemid] => int [filepath] => string [filename] => string [filecontent] => string */ //For a User Avatar, looking at mdl_files table for example: /* contextid = 5 (context = USER, userid = instance = 2), use local_getcontexts_get_contexts function component = user filearea = draft itemid = 230987549 or 1 filepath = / filename = xxx.jpeg filecontent = base64_encode */ //For the moment, component = user && filearea = private is hardcoded... // see http://tracker.moodle.org/browse/MDL-31116 return null; global $moodle_contextlevel, $moodle_instance; $moodle_contextlevel = CONTEXT_USER; $rosario_id = $_POST['userId']; //gather the Moodle user ID $column = mb_strpos($_POST['modname'], 'Users') !== false ? 'staff_id' : 'student_id'; $moodle_instance = DBGet(DBQuery("SELECT moodle_id FROM moodlexrosario WHERE rosario_id='" . $rosario_id . "' AND \"column\"='" . $column . "'")); if (count($moodle_instance)) { $moodle_instance = (int) $moodle_instance[1]['MOODLE_ID']; } else { return null; } //get contextid first: $contexts = Moodle('Global/functions.php', 'local_getcontexts_get_contexts'); $contextid = $contexts[0]['id']; $component = 'user'; $filearea = 'draft'; $itemid = 1; $filepath = '/'; $filename = $_POST['userId'] . '.jpg'; function base64_encode_file($file) { $filename = file_exists($file) ? htmlentities($file) : die('File name does not exist'); $filetype = pathinfo($filename, PATHINFO_EXTENSION); $filebinary = fread(fopen($filename, "r"), filesize($filename)); return base64_encode($filebinary); } global $wkhtmltopdfAssetsPath; $filecontent = base64_encode_file($wkhtmltopdfAssetsPath . str_replace('assets/', '', $_POST['photoPath']) . $_POST['sYear'] . '/' . $_POST['userId'] . '.jpg'); $file = array($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent); return $file; }
<form method='post' action="" enctype="multipart/form-data"> {!!csrf_field()!!} <input type="file" name="image" /> <input type="submit"/> </form> <?php print_r($_FILES); if (isset($_FILES['image'])) { $image = $_FILES['image']; $filename = $image['tmp_name']; $base64 = base64_encode_file($filename); echo '<img src="' . $base64 . '"/>'; } else { echo "no file uploaded"; } function base64_encode_file($filename) { return 'data:' . mime_content_type($filename) . ';base64,' . base64_encode(file_get_contents($filename)); }