id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
220,500
moodle/moodle
mod/forum/classes/task/send_user_digests.php
send_user_digests.add_message_header
protected function add_message_header() { $site = get_site(); // Set the subject of the message. $this->postsubject = get_string('digestmailsubject', 'forum', format_string($site->shortname, true)); // And the content of the header in body. $headerdata = (object) [ 'sitename' => format_string($site->fullname, true), 'userprefs' => (new \moodle_url('/user/forum.php', [ 'id' => $this->recipient->id, 'course' => $site->id, ]))->out(false), ]; $this->notificationtext .= get_string('digestmailheader', 'forum', $headerdata) . "\n"; if ($this->allowhtml) { $headerdata->userprefs = html_writer::link($headerdata->userprefs, get_string('digestmailprefs', 'forum'), [ 'target' => '_blank', ]); $this->notificationhtml .= html_writer::tag('p', get_string('digestmailheader', 'forum', $headerdata)); $this->notificationhtml .= html_writer::empty_tag('br'); $this->notificationhtml .= html_writer::empty_tag('hr', [ 'size' => 1, 'noshade' => 'noshade', ]); } }
php
protected function add_message_header() { $site = get_site(); // Set the subject of the message. $this->postsubject = get_string('digestmailsubject', 'forum', format_string($site->shortname, true)); // And the content of the header in body. $headerdata = (object) [ 'sitename' => format_string($site->fullname, true), 'userprefs' => (new \moodle_url('/user/forum.php', [ 'id' => $this->recipient->id, 'course' => $site->id, ]))->out(false), ]; $this->notificationtext .= get_string('digestmailheader', 'forum', $headerdata) . "\n"; if ($this->allowhtml) { $headerdata->userprefs = html_writer::link($headerdata->userprefs, get_string('digestmailprefs', 'forum'), [ 'target' => '_blank', ]); $this->notificationhtml .= html_writer::tag('p', get_string('digestmailheader', 'forum', $headerdata)); $this->notificationhtml .= html_writer::empty_tag('br'); $this->notificationhtml .= html_writer::empty_tag('hr', [ 'size' => 1, 'noshade' => 'noshade', ]); } }
[ "protected", "function", "add_message_header", "(", ")", "{", "$", "site", "=", "get_site", "(", ")", ";", "// Set the subject of the message.", "$", "this", "->", "postsubject", "=", "get_string", "(", "'digestmailsubject'", ",", "'forum'", ",", "format_string", "(", "$", "site", "->", "shortname", ",", "true", ")", ")", ";", "// And the content of the header in body.", "$", "headerdata", "=", "(", "object", ")", "[", "'sitename'", "=>", "format_string", "(", "$", "site", "->", "fullname", ",", "true", ")", ",", "'userprefs'", "=>", "(", "new", "\\", "moodle_url", "(", "'/user/forum.php'", ",", "[", "'id'", "=>", "$", "this", "->", "recipient", "->", "id", ",", "'course'", "=>", "$", "site", "->", "id", ",", "]", ")", ")", "->", "out", "(", "false", ")", ",", "]", ";", "$", "this", "->", "notificationtext", ".=", "get_string", "(", "'digestmailheader'", ",", "'forum'", ",", "$", "headerdata", ")", ".", "\"\\n\"", ";", "if", "(", "$", "this", "->", "allowhtml", ")", "{", "$", "headerdata", "->", "userprefs", "=", "html_writer", "::", "link", "(", "$", "headerdata", "->", "userprefs", ",", "get_string", "(", "'digestmailprefs'", ",", "'forum'", ")", ",", "[", "'target'", "=>", "'_blank'", ",", "]", ")", ";", "$", "this", "->", "notificationhtml", ".=", "html_writer", "::", "tag", "(", "'p'", ",", "get_string", "(", "'digestmailheader'", ",", "'forum'", ",", "$", "headerdata", ")", ")", ";", "$", "this", "->", "notificationhtml", ".=", "html_writer", "::", "empty_tag", "(", "'br'", ")", ";", "$", "this", "->", "notificationhtml", ".=", "html_writer", "::", "empty_tag", "(", "'hr'", ",", "[", "'size'", "=>", "1", ",", "'noshade'", "=>", "'noshade'", ",", "]", ")", ";", "}", "}" ]
Add the header to this message.
[ "Add", "the", "header", "to", "this", "message", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_digests.php#L390-L419
220,501
moodle/moodle
mod/forum/classes/task/send_user_digests.php
send_user_digests.add_discussion_header
protected function add_discussion_header($discussion, $forum, $course) { global $CFG; $shortname = format_string($course->shortname, true, [ 'context' => \context_course::instance($course->id), ]); $strforums = get_string('forums', 'forum'); $this->discussiontext .= "\n=====================================================================\n\n"; $this->discussiontext .= "$shortname -> $strforums -> " . format_string($forum->name, true); if ($discussion->name != $forum->name) { $this->discussiontext .= " -> " . format_string($discussion->name, true); } $this->discussiontext .= "\n"; $this->discussiontext .= new \moodle_url('/mod/forum/discuss.php', [ 'd' => $discussion->id, ]); $this->discussiontext .= "\n"; if ($this->allowhtml) { $this->discussionhtml .= "<p><font face=\"sans-serif\">". "<a target=\"_blank\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$shortname</a> -> ". "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">$strforums</a> -> ". "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">" . format_string($forum->name, true)."</a>"; if ($discussion->name == $forum->name) { $this->discussionhtml .= "</font></p>"; } else { $this->discussionhtml .= " -> <a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id\">" . format_string($discussion->name, true)."</a></font></p>"; } $this->discussionhtml .= '<p>'; } }
php
protected function add_discussion_header($discussion, $forum, $course) { global $CFG; $shortname = format_string($course->shortname, true, [ 'context' => \context_course::instance($course->id), ]); $strforums = get_string('forums', 'forum'); $this->discussiontext .= "\n=====================================================================\n\n"; $this->discussiontext .= "$shortname -> $strforums -> " . format_string($forum->name, true); if ($discussion->name != $forum->name) { $this->discussiontext .= " -> " . format_string($discussion->name, true); } $this->discussiontext .= "\n"; $this->discussiontext .= new \moodle_url('/mod/forum/discuss.php', [ 'd' => $discussion->id, ]); $this->discussiontext .= "\n"; if ($this->allowhtml) { $this->discussionhtml .= "<p><font face=\"sans-serif\">". "<a target=\"_blank\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$shortname</a> -> ". "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">$strforums</a> -> ". "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">" . format_string($forum->name, true)."</a>"; if ($discussion->name == $forum->name) { $this->discussionhtml .= "</font></p>"; } else { $this->discussionhtml .= " -> <a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id\">" . format_string($discussion->name, true)."</a></font></p>"; } $this->discussionhtml .= '<p>'; } }
[ "protected", "function", "add_discussion_header", "(", "$", "discussion", ",", "$", "forum", ",", "$", "course", ")", "{", "global", "$", "CFG", ";", "$", "shortname", "=", "format_string", "(", "$", "course", "->", "shortname", ",", "true", ",", "[", "'context'", "=>", "\\", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ",", "]", ")", ";", "$", "strforums", "=", "get_string", "(", "'forums'", ",", "'forum'", ")", ";", "$", "this", "->", "discussiontext", ".=", "\"\\n=====================================================================\\n\\n\"", ";", "$", "this", "->", "discussiontext", ".=", "\"$shortname -> $strforums -> \"", ".", "format_string", "(", "$", "forum", "->", "name", ",", "true", ")", ";", "if", "(", "$", "discussion", "->", "name", "!=", "$", "forum", "->", "name", ")", "{", "$", "this", "->", "discussiontext", ".=", "\" -> \"", ".", "format_string", "(", "$", "discussion", "->", "name", ",", "true", ")", ";", "}", "$", "this", "->", "discussiontext", ".=", "\"\\n\"", ";", "$", "this", "->", "discussiontext", ".=", "new", "\\", "moodle_url", "(", "'/mod/forum/discuss.php'", ",", "[", "'d'", "=>", "$", "discussion", "->", "id", ",", "]", ")", ";", "$", "this", "->", "discussiontext", ".=", "\"\\n\"", ";", "if", "(", "$", "this", "->", "allowhtml", ")", "{", "$", "this", "->", "discussionhtml", ".=", "\"<p><font face=\\\"sans-serif\\\">\"", ".", "\"<a target=\\\"_blank\\\" href=\\\"$CFG->wwwroot/course/view.php?id=$course->id\\\">$shortname</a> -> \"", ".", "\"<a target=\\\"_blank\\\" href=\\\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\\\">$strforums</a> -> \"", ".", "\"<a target=\\\"_blank\\\" href=\\\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\\\">\"", ".", "format_string", "(", "$", "forum", "->", "name", ",", "true", ")", ".", "\"</a>\"", ";", "if", "(", "$", "discussion", "->", "name", "==", "$", "forum", "->", "name", ")", "{", "$", "this", "->", "discussionhtml", ".=", "\"</font></p>\"", ";", "}", "else", "{", "$", "this", "->", "discussionhtml", ".=", "\" -> <a target=\\\"_blank\\\" href=\\\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id\\\">\"", ".", "format_string", "(", "$", "discussion", "->", "name", ",", "true", ")", ".", "\"</a></font></p>\"", ";", "}", "$", "this", "->", "discussionhtml", ".=", "'<p>'", ";", "}", "}" ]
Add the header for this discussion. @param \stdClass $discussion The discussion to add the footer for @param \stdClass $forum The forum that the discussion belongs to @param \stdClass $course The course that the forum belongs to
[ "Add", "the", "header", "for", "this", "discussion", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_digests.php#L428-L464
220,502
moodle/moodle
mod/forum/classes/task/send_user_digests.php
send_user_digests.add_post_body
protected function add_post_body($author, $post, $discussion, $forum, $cm, $course) { global $CFG; $canreply = $this->canpostto[$discussion->id]; $data = new \mod_forum\output\forum_post_email( $course, $cm, $forum, $discussion, $post, $author, $this->recipient, $canreply ); // Override the viewfullnames value. $data->viewfullnames = $this->viewfullnames[$forum->id]; // Determine the type of digest being sent. $maildigest = $this->get_maildigest($forum->id); $textrenderer = $this->get_renderer($maildigest); $this->discussiontext .= $textrenderer->render($data); $this->discussiontext .= "\n"; if ($this->allowhtml) { $htmlrenderer = $this->get_renderer($maildigest, true); $this->discussionhtml .= $htmlrenderer->render($data); $this->log("Adding post {$post->id} in format {$maildigest} with HTML", 2); } else { $this->log("Adding post {$post->id} in format {$maildigest} without HTML", 2); } if ($maildigest == 1 && $CFG->forum_usermarksread) { // Create an array of postid's for this user to mark as read. $this->markpostsasread[] = $post->id; } }
php
protected function add_post_body($author, $post, $discussion, $forum, $cm, $course) { global $CFG; $canreply = $this->canpostto[$discussion->id]; $data = new \mod_forum\output\forum_post_email( $course, $cm, $forum, $discussion, $post, $author, $this->recipient, $canreply ); // Override the viewfullnames value. $data->viewfullnames = $this->viewfullnames[$forum->id]; // Determine the type of digest being sent. $maildigest = $this->get_maildigest($forum->id); $textrenderer = $this->get_renderer($maildigest); $this->discussiontext .= $textrenderer->render($data); $this->discussiontext .= "\n"; if ($this->allowhtml) { $htmlrenderer = $this->get_renderer($maildigest, true); $this->discussionhtml .= $htmlrenderer->render($data); $this->log("Adding post {$post->id} in format {$maildigest} with HTML", 2); } else { $this->log("Adding post {$post->id} in format {$maildigest} without HTML", 2); } if ($maildigest == 1 && $CFG->forum_usermarksread) { // Create an array of postid's for this user to mark as read. $this->markpostsasread[] = $post->id; } }
[ "protected", "function", "add_post_body", "(", "$", "author", ",", "$", "post", ",", "$", "discussion", ",", "$", "forum", ",", "$", "cm", ",", "$", "course", ")", "{", "global", "$", "CFG", ";", "$", "canreply", "=", "$", "this", "->", "canpostto", "[", "$", "discussion", "->", "id", "]", ";", "$", "data", "=", "new", "\\", "mod_forum", "\\", "output", "\\", "forum_post_email", "(", "$", "course", ",", "$", "cm", ",", "$", "forum", ",", "$", "discussion", ",", "$", "post", ",", "$", "author", ",", "$", "this", "->", "recipient", ",", "$", "canreply", ")", ";", "// Override the viewfullnames value.", "$", "data", "->", "viewfullnames", "=", "$", "this", "->", "viewfullnames", "[", "$", "forum", "->", "id", "]", ";", "// Determine the type of digest being sent.", "$", "maildigest", "=", "$", "this", "->", "get_maildigest", "(", "$", "forum", "->", "id", ")", ";", "$", "textrenderer", "=", "$", "this", "->", "get_renderer", "(", "$", "maildigest", ")", ";", "$", "this", "->", "discussiontext", ".=", "$", "textrenderer", "->", "render", "(", "$", "data", ")", ";", "$", "this", "->", "discussiontext", ".=", "\"\\n\"", ";", "if", "(", "$", "this", "->", "allowhtml", ")", "{", "$", "htmlrenderer", "=", "$", "this", "->", "get_renderer", "(", "$", "maildigest", ",", "true", ")", ";", "$", "this", "->", "discussionhtml", ".=", "$", "htmlrenderer", "->", "render", "(", "$", "data", ")", ";", "$", "this", "->", "log", "(", "\"Adding post {$post->id} in format {$maildigest} with HTML\"", ",", "2", ")", ";", "}", "else", "{", "$", "this", "->", "log", "(", "\"Adding post {$post->id} in format {$maildigest} without HTML\"", ",", "2", ")", ";", "}", "if", "(", "$", "maildigest", "==", "1", "&&", "$", "CFG", "->", "forum_usermarksread", ")", "{", "// Create an array of postid's for this user to mark as read.", "$", "this", "->", "markpostsasread", "[", "]", "=", "$", "post", "->", "id", ";", "}", "}" ]
Add the body of this post. @param \stdClass $author The author of the post @param \stdClass $post The post being sent @param \stdClass $discussion The discussion that the post is in @param \stdClass $forum The forum that the discussion belongs to @param \cminfo $cm The cminfo object for the forum @param \stdClass $course The course that the forum belongs to
[ "Add", "the", "body", "of", "this", "post", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_digests.php#L476-L514
220,503
moodle/moodle
mod/forum/classes/task/send_user_digests.php
send_user_digests.add_discussion_footer
protected function add_discussion_footer($discussion) { global $CFG; if ($this->allowhtml) { $footerlinks = []; $forum = $this->forums[$discussion->forum]; if (\mod_forum\subscriptions::is_forcesubscribed($forum)) { // This forum is force subscribed. The user cannot unsubscribe. $footerlinks[] = get_string("everyoneissubscribed", "forum"); } else { $footerlinks[] = "<a href=\"$CFG->wwwroot/mod/forum/subscribe.php?id=$forum->id\">" . get_string("unsubscribe", "forum") . "</a>"; } $footerlinks[] = "<a href='{$CFG->wwwroot}/mod/forum/index.php?id={$forum->course}'>" . get_string("digestmailpost", "forum") . '</a>'; $this->discussionhtml .= "\n<div class='mdl-right'><font size=\"1\">" . implode('&nbsp;', $footerlinks) . '</font></div>'; $this->discussionhtml .= '<hr size="1" noshade="noshade" /></p>'; } }
php
protected function add_discussion_footer($discussion) { global $CFG; if ($this->allowhtml) { $footerlinks = []; $forum = $this->forums[$discussion->forum]; if (\mod_forum\subscriptions::is_forcesubscribed($forum)) { // This forum is force subscribed. The user cannot unsubscribe. $footerlinks[] = get_string("everyoneissubscribed", "forum"); } else { $footerlinks[] = "<a href=\"$CFG->wwwroot/mod/forum/subscribe.php?id=$forum->id\">" . get_string("unsubscribe", "forum") . "</a>"; } $footerlinks[] = "<a href='{$CFG->wwwroot}/mod/forum/index.php?id={$forum->course}'>" . get_string("digestmailpost", "forum") . '</a>'; $this->discussionhtml .= "\n<div class='mdl-right'><font size=\"1\">" . implode('&nbsp;', $footerlinks) . '</font></div>'; $this->discussionhtml .= '<hr size="1" noshade="noshade" /></p>'; } }
[ "protected", "function", "add_discussion_footer", "(", "$", "discussion", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "this", "->", "allowhtml", ")", "{", "$", "footerlinks", "=", "[", "]", ";", "$", "forum", "=", "$", "this", "->", "forums", "[", "$", "discussion", "->", "forum", "]", ";", "if", "(", "\\", "mod_forum", "\\", "subscriptions", "::", "is_forcesubscribed", "(", "$", "forum", ")", ")", "{", "// This forum is force subscribed. The user cannot unsubscribe.", "$", "footerlinks", "[", "]", "=", "get_string", "(", "\"everyoneissubscribed\"", ",", "\"forum\"", ")", ";", "}", "else", "{", "$", "footerlinks", "[", "]", "=", "\"<a href=\\\"$CFG->wwwroot/mod/forum/subscribe.php?id=$forum->id\\\">\"", ".", "get_string", "(", "\"unsubscribe\"", ",", "\"forum\"", ")", ".", "\"</a>\"", ";", "}", "$", "footerlinks", "[", "]", "=", "\"<a href='{$CFG->wwwroot}/mod/forum/index.php?id={$forum->course}'>\"", ".", "get_string", "(", "\"digestmailpost\"", ",", "\"forum\"", ")", ".", "'</a>'", ";", "$", "this", "->", "discussionhtml", ".=", "\"\\n<div class='mdl-right'><font size=\\\"1\\\">\"", ".", "implode", "(", "'&nbsp;'", ",", "$", "footerlinks", ")", ".", "'</font></div>'", ";", "$", "this", "->", "discussionhtml", ".=", "'<hr size=\"1\" noshade=\"noshade\" /></p>'", ";", "}", "}" ]
Add the footer for this discussion. @param \stdClass $discussion The discussion to add the footer for
[ "Add", "the", "footer", "for", "this", "discussion", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_digests.php#L521-L542
220,504
moodle/moodle
mod/forum/classes/task/send_user_digests.php
send_user_digests.get_maildigest
protected function get_maildigest($forumid) { $maildigest = -1; if (isset($this->forumdigesttypes[$forumid])) { $maildigest = $this->forumdigesttypes[$forumid]; } if ($maildigest === -1 && !empty($this->recipient->maildigest)) { $maildigest = $this->recipient->maildigest; } if ($maildigest === -1) { // There is no maildigest type right now. $maildigest = 1; } return $maildigest; }
php
protected function get_maildigest($forumid) { $maildigest = -1; if (isset($this->forumdigesttypes[$forumid])) { $maildigest = $this->forumdigesttypes[$forumid]; } if ($maildigest === -1 && !empty($this->recipient->maildigest)) { $maildigest = $this->recipient->maildigest; } if ($maildigest === -1) { // There is no maildigest type right now. $maildigest = 1; } return $maildigest; }
[ "protected", "function", "get_maildigest", "(", "$", "forumid", ")", "{", "$", "maildigest", "=", "-", "1", ";", "if", "(", "isset", "(", "$", "this", "->", "forumdigesttypes", "[", "$", "forumid", "]", ")", ")", "{", "$", "maildigest", "=", "$", "this", "->", "forumdigesttypes", "[", "$", "forumid", "]", ";", "}", "if", "(", "$", "maildigest", "===", "-", "1", "&&", "!", "empty", "(", "$", "this", "->", "recipient", "->", "maildigest", ")", ")", "{", "$", "maildigest", "=", "$", "this", "->", "recipient", "->", "maildigest", ";", "}", "if", "(", "$", "maildigest", "===", "-", "1", ")", "{", "// There is no maildigest type right now.", "$", "maildigest", "=", "1", ";", "}", "return", "$", "maildigest", ";", "}" ]
Get the forum digest type for the specified forum, failing back to the default setting for the current user if not specified. @param int $forumid @return int
[ "Get", "the", "forum", "digest", "type", "for", "the", "specified", "forum", "failing", "back", "to", "the", "default", "setting", "for", "the", "current", "user", "if", "not", "specified", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_digests.php#L551-L568
220,505
moodle/moodle
mod/forum/classes/task/send_user_digests.php
send_user_digests.send_mail
protected function send_mail() { // Headers to help prevent auto-responders. $userfrom = \core_user::get_noreply_user(); $userfrom->customheaders = array( "Precedence: Bulk", 'X-Auto-Response-Suppress: All', 'Auto-Submitted: auto-generated', ); $eventdata = new \core\message\message(); $eventdata->courseid = SITEID; $eventdata->component = 'mod_forum'; $eventdata->name = 'digests'; $eventdata->userfrom = $userfrom; $eventdata->userto = $this->recipient; $eventdata->subject = $this->postsubject; $eventdata->fullmessage = $this->notificationtext; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $this->notificationhtml; $eventdata->notification = 1; $eventdata->smallmessage = get_string('smallmessagedigest', 'forum', $this->sentcount); return message_send($eventdata); }
php
protected function send_mail() { // Headers to help prevent auto-responders. $userfrom = \core_user::get_noreply_user(); $userfrom->customheaders = array( "Precedence: Bulk", 'X-Auto-Response-Suppress: All', 'Auto-Submitted: auto-generated', ); $eventdata = new \core\message\message(); $eventdata->courseid = SITEID; $eventdata->component = 'mod_forum'; $eventdata->name = 'digests'; $eventdata->userfrom = $userfrom; $eventdata->userto = $this->recipient; $eventdata->subject = $this->postsubject; $eventdata->fullmessage = $this->notificationtext; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $this->notificationhtml; $eventdata->notification = 1; $eventdata->smallmessage = get_string('smallmessagedigest', 'forum', $this->sentcount); return message_send($eventdata); }
[ "protected", "function", "send_mail", "(", ")", "{", "// Headers to help prevent auto-responders.", "$", "userfrom", "=", "\\", "core_user", "::", "get_noreply_user", "(", ")", ";", "$", "userfrom", "->", "customheaders", "=", "array", "(", "\"Precedence: Bulk\"", ",", "'X-Auto-Response-Suppress: All'", ",", "'Auto-Submitted: auto-generated'", ",", ")", ";", "$", "eventdata", "=", "new", "\\", "core", "\\", "message", "\\", "message", "(", ")", ";", "$", "eventdata", "->", "courseid", "=", "SITEID", ";", "$", "eventdata", "->", "component", "=", "'mod_forum'", ";", "$", "eventdata", "->", "name", "=", "'digests'", ";", "$", "eventdata", "->", "userfrom", "=", "$", "userfrom", ";", "$", "eventdata", "->", "userto", "=", "$", "this", "->", "recipient", ";", "$", "eventdata", "->", "subject", "=", "$", "this", "->", "postsubject", ";", "$", "eventdata", "->", "fullmessage", "=", "$", "this", "->", "notificationtext", ";", "$", "eventdata", "->", "fullmessageformat", "=", "FORMAT_PLAIN", ";", "$", "eventdata", "->", "fullmessagehtml", "=", "$", "this", "->", "notificationhtml", ";", "$", "eventdata", "->", "notification", "=", "1", ";", "$", "eventdata", "->", "smallmessage", "=", "get_string", "(", "'smallmessagedigest'", ",", "'forum'", ",", "$", "this", "->", "sentcount", ")", ";", "return", "message_send", "(", "$", "eventdata", ")", ";", "}" ]
Send the composed message to the user.
[ "Send", "the", "composed", "message", "to", "the", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_digests.php#L573-L596
220,506
moodle/moodle
mod/forum/classes/task/send_user_digests.php
send_user_digests.get_renderer
protected function get_renderer($maildigest, $html = false) { global $PAGE; $type = $maildigest == 2 ? 'emaildigestbasic' : 'emaildigestfull'; $target = $html ? 'htmlemail' : 'textemail'; if (!isset($this->renderers[$target][$type])) { $this->renderers[$target][$type] = $PAGE->get_renderer('mod_forum', $type, $target); } return $this->renderers[$target][$type]; }
php
protected function get_renderer($maildigest, $html = false) { global $PAGE; $type = $maildigest == 2 ? 'emaildigestbasic' : 'emaildigestfull'; $target = $html ? 'htmlemail' : 'textemail'; if (!isset($this->renderers[$target][$type])) { $this->renderers[$target][$type] = $PAGE->get_renderer('mod_forum', $type, $target); } return $this->renderers[$target][$type]; }
[ "protected", "function", "get_renderer", "(", "$", "maildigest", ",", "$", "html", "=", "false", ")", "{", "global", "$", "PAGE", ";", "$", "type", "=", "$", "maildigest", "==", "2", "?", "'emaildigestbasic'", ":", "'emaildigestfull'", ";", "$", "target", "=", "$", "html", "?", "'htmlemail'", ":", "'textemail'", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "renderers", "[", "$", "target", "]", "[", "$", "type", "]", ")", ")", "{", "$", "this", "->", "renderers", "[", "$", "target", "]", "[", "$", "type", "]", "=", "$", "PAGE", "->", "get_renderer", "(", "'mod_forum'", ",", "$", "type", ",", "$", "target", ")", ";", "}", "return", "$", "this", "->", "renderers", "[", "$", "target", "]", "[", "$", "type", "]", ";", "}" ]
Helper to fetch the required renderer, instantiating as required. @param int $maildigest The type of mail digest being sent @param bool $html Whether to fetch the HTML renderer @return \core_renderer
[ "Helper", "to", "fetch", "the", "required", "renderer", "instantiating", "as", "required", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_digests.php#L605-L616
220,507
moodle/moodle
mod/feedback/classes/privacy/provider.php
provider.extract_item_record_from_record
protected static function extract_item_record_from_record(stdClass $record) { $newrec = new stdClass(); foreach ($record as $key => $value) { if (strpos($key, 'item') !== 0) { continue; } $key = substr($key, 4); $newrec->{$key} = $value; } return $newrec; }
php
protected static function extract_item_record_from_record(stdClass $record) { $newrec = new stdClass(); foreach ($record as $key => $value) { if (strpos($key, 'item') !== 0) { continue; } $key = substr($key, 4); $newrec->{$key} = $value; } return $newrec; }
[ "protected", "static", "function", "extract_item_record_from_record", "(", "stdClass", "$", "record", ")", "{", "$", "newrec", "=", "new", "stdClass", "(", ")", ";", "foreach", "(", "$", "record", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "key", ",", "'item'", ")", "!==", "0", ")", "{", "continue", ";", "}", "$", "key", "=", "substr", "(", "$", "key", ",", "4", ")", ";", "$", "newrec", "->", "{", "$", "key", "}", "=", "$", "value", ";", "}", "return", "$", "newrec", ";", "}" ]
Extract an item record from a database record. @param stdClass $record The record. @return The item record.
[ "Extract", "an", "item", "record", "from", "a", "database", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/privacy/provider.php#L358-L368
220,508
moodle/moodle
mod/feedback/classes/privacy/provider.php
provider.prepare_export_query
protected static function prepare_export_query(array $contextids, $userid) { global $DB; $makefetchsql = function($istmp) use ($DB, $contextids, $userid) { $ctxfields = context_helper::get_preload_record_columns_sql('ctx'); list($insql, $inparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED); $i = $istmp ? 0 : 1; $istmpsqlval = $istmp ? 1 : 0; $prefix = $istmp ? 'idtmp' : 'id'; $uniqid = $DB->sql_concat("'$prefix'", 'fc.id'); $sql = " SELECT $uniqid AS uniqid, f.id AS feedbackid, ctx.id AS contextid, $istmpsqlval AS istmp, fc.id AS submissionid, fc.anonymous_response AS anonymousresponse, fc.timemodified AS timemodified, fv.id AS valueid, fv.course_id AS valuecourse_id, fv.item AS valueitem, fv.completed AS valuecompleted, fv.tmp_completed AS valuetmp_completed, $ctxfields FROM {context} ctx JOIN {course_modules} cm ON cm.id = ctx.instanceid JOIN {feedback} f ON f.id = cm.instance JOIN {%s} fc ON fc.feedback = f.id JOIN {%s} fv ON fv.completed = fc.id WHERE ctx.id $insql AND fc.userid = :userid{$i}"; $params = array_merge($inparams, [ 'userid' . $i => $userid, ]); $completedtbl = $istmp ? 'feedback_completedtmp' : 'feedback_completed'; $valuetbl = $istmp ? 'feedback_valuetmp' : 'feedback_value'; return [sprintf($sql, $completedtbl, $valuetbl), $params]; }; list($nontmpsql, $nontmpparams) = $makefetchsql(false); list($tmpsql, $tmpparams) = $makefetchsql(true); // Oracle does not support UNION on text fields, therefore we must get the itemdescription // and valuevalue after doing the union by joining on the result. $sql = " SELECT q.*, COALESCE(fv.value, fvt.value) AS valuevalue, fi.id AS itemid, fi.feedback AS itemfeedback, fi.template AS itemtemplate, fi.name AS itemname, fi.label AS itemlabel, fi.presentation AS itempresentation, fi.typ AS itemtyp, fi.hasvalue AS itemhasvalue, fi.position AS itemposition, fi.required AS itemrequired, fi.dependitem AS itemdependitem, fi.dependvalue AS itemdependvalue, fi.options AS itemoptions FROM ($nontmpsql UNION $tmpsql) q LEFT JOIN {feedback_value} fv ON fv.id = q.valueid AND q.istmp = 0 LEFT JOIN {feedback_valuetmp} fvt ON fvt.id = q.valueid AND q.istmp = 1 JOIN {feedback_item} fi ON (fi.id = fv.item OR fi.id = fvt.item) ORDER BY q.contextid, q.istmp, q.submissionid, q.valueid"; $params = array_merge($nontmpparams, $tmpparams); return [$sql, $params]; }
php
protected static function prepare_export_query(array $contextids, $userid) { global $DB; $makefetchsql = function($istmp) use ($DB, $contextids, $userid) { $ctxfields = context_helper::get_preload_record_columns_sql('ctx'); list($insql, $inparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED); $i = $istmp ? 0 : 1; $istmpsqlval = $istmp ? 1 : 0; $prefix = $istmp ? 'idtmp' : 'id'; $uniqid = $DB->sql_concat("'$prefix'", 'fc.id'); $sql = " SELECT $uniqid AS uniqid, f.id AS feedbackid, ctx.id AS contextid, $istmpsqlval AS istmp, fc.id AS submissionid, fc.anonymous_response AS anonymousresponse, fc.timemodified AS timemodified, fv.id AS valueid, fv.course_id AS valuecourse_id, fv.item AS valueitem, fv.completed AS valuecompleted, fv.tmp_completed AS valuetmp_completed, $ctxfields FROM {context} ctx JOIN {course_modules} cm ON cm.id = ctx.instanceid JOIN {feedback} f ON f.id = cm.instance JOIN {%s} fc ON fc.feedback = f.id JOIN {%s} fv ON fv.completed = fc.id WHERE ctx.id $insql AND fc.userid = :userid{$i}"; $params = array_merge($inparams, [ 'userid' . $i => $userid, ]); $completedtbl = $istmp ? 'feedback_completedtmp' : 'feedback_completed'; $valuetbl = $istmp ? 'feedback_valuetmp' : 'feedback_value'; return [sprintf($sql, $completedtbl, $valuetbl), $params]; }; list($nontmpsql, $nontmpparams) = $makefetchsql(false); list($tmpsql, $tmpparams) = $makefetchsql(true); // Oracle does not support UNION on text fields, therefore we must get the itemdescription // and valuevalue after doing the union by joining on the result. $sql = " SELECT q.*, COALESCE(fv.value, fvt.value) AS valuevalue, fi.id AS itemid, fi.feedback AS itemfeedback, fi.template AS itemtemplate, fi.name AS itemname, fi.label AS itemlabel, fi.presentation AS itempresentation, fi.typ AS itemtyp, fi.hasvalue AS itemhasvalue, fi.position AS itemposition, fi.required AS itemrequired, fi.dependitem AS itemdependitem, fi.dependvalue AS itemdependvalue, fi.options AS itemoptions FROM ($nontmpsql UNION $tmpsql) q LEFT JOIN {feedback_value} fv ON fv.id = q.valueid AND q.istmp = 0 LEFT JOIN {feedback_valuetmp} fvt ON fvt.id = q.valueid AND q.istmp = 1 JOIN {feedback_item} fi ON (fi.id = fv.item OR fi.id = fvt.item) ORDER BY q.contextid, q.istmp, q.submissionid, q.valueid"; $params = array_merge($nontmpparams, $tmpparams); return [$sql, $params]; }
[ "protected", "static", "function", "prepare_export_query", "(", "array", "$", "contextids", ",", "$", "userid", ")", "{", "global", "$", "DB", ";", "$", "makefetchsql", "=", "function", "(", "$", "istmp", ")", "use", "(", "$", "DB", ",", "$", "contextids", ",", "$", "userid", ")", "{", "$", "ctxfields", "=", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "contextids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "i", "=", "$", "istmp", "?", "0", ":", "1", ";", "$", "istmpsqlval", "=", "$", "istmp", "?", "1", ":", "0", ";", "$", "prefix", "=", "$", "istmp", "?", "'idtmp'", ":", "'id'", ";", "$", "uniqid", "=", "$", "DB", "->", "sql_concat", "(", "\"'$prefix'\"", ",", "'fc.id'", ")", ";", "$", "sql", "=", "\"\n SELECT $uniqid AS uniqid,\n f.id AS feedbackid,\n ctx.id AS contextid,\n\n $istmpsqlval AS istmp,\n fc.id AS submissionid,\n fc.anonymous_response AS anonymousresponse,\n fc.timemodified AS timemodified,\n\n fv.id AS valueid,\n fv.course_id AS valuecourse_id,\n fv.item AS valueitem,\n fv.completed AS valuecompleted,\n fv.tmp_completed AS valuetmp_completed,\n\n $ctxfields\n FROM {context} ctx\n JOIN {course_modules} cm\n ON cm.id = ctx.instanceid\n JOIN {feedback} f\n ON f.id = cm.instance\n JOIN {%s} fc\n ON fc.feedback = f.id\n JOIN {%s} fv\n ON fv.completed = fc.id\n WHERE ctx.id $insql\n AND fc.userid = :userid{$i}\"", ";", "$", "params", "=", "array_merge", "(", "$", "inparams", ",", "[", "'userid'", ".", "$", "i", "=>", "$", "userid", ",", "]", ")", ";", "$", "completedtbl", "=", "$", "istmp", "?", "'feedback_completedtmp'", ":", "'feedback_completed'", ";", "$", "valuetbl", "=", "$", "istmp", "?", "'feedback_valuetmp'", ":", "'feedback_value'", ";", "return", "[", "sprintf", "(", "$", "sql", ",", "$", "completedtbl", ",", "$", "valuetbl", ")", ",", "$", "params", "]", ";", "}", ";", "list", "(", "$", "nontmpsql", ",", "$", "nontmpparams", ")", "=", "$", "makefetchsql", "(", "false", ")", ";", "list", "(", "$", "tmpsql", ",", "$", "tmpparams", ")", "=", "$", "makefetchsql", "(", "true", ")", ";", "// Oracle does not support UNION on text fields, therefore we must get the itemdescription", "// and valuevalue after doing the union by joining on the result.", "$", "sql", "=", "\"\n SELECT q.*,\n\n COALESCE(fv.value, fvt.value) AS valuevalue,\n\n fi.id AS itemid,\n fi.feedback AS itemfeedback,\n fi.template AS itemtemplate,\n fi.name AS itemname,\n fi.label AS itemlabel,\n fi.presentation AS itempresentation,\n fi.typ AS itemtyp,\n fi.hasvalue AS itemhasvalue,\n fi.position AS itemposition,\n fi.required AS itemrequired,\n fi.dependitem AS itemdependitem,\n fi.dependvalue AS itemdependvalue,\n fi.options AS itemoptions\n\n FROM ($nontmpsql UNION $tmpsql) q\n LEFT JOIN {feedback_value} fv\n ON fv.id = q.valueid AND q.istmp = 0\n LEFT JOIN {feedback_valuetmp} fvt\n ON fvt.id = q.valueid AND q.istmp = 1\n JOIN {feedback_item} fi\n ON (fi.id = fv.item OR fi.id = fvt.item)\n ORDER BY q.contextid, q.istmp, q.submissionid, q.valueid\"", ";", "$", "params", "=", "array_merge", "(", "$", "nontmpparams", ",", "$", "tmpparams", ")", ";", "return", "[", "$", "sql", ",", "$", "params", "]", ";", "}" ]
Prepare the query to export all data. Doing it this way allows for merging all records from both the temporary and final tables as most of their columns are shared. It is a lot easier to deal with the records when exporting as we do not need to try to manually group the two types of submissions in the same reported dataset. The ordering may affect performance on large datasets. @param array $contextids The context IDs. @param int $userid The user ID. @return array With SQL and params.
[ "Prepare", "the", "query", "to", "export", "all", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/privacy/provider.php#L402-L487
220,509
moodle/moodle
auth/cas/CAS/CAS/ProxiedService/Imap.php
CAS_ProxiedService_Imap.setServiceUrl
public function setServiceUrl ($url) { if ($this->hasBeenOpened()) { throw new CAS_OutOfSequenceException( 'Cannot set the URL, stream already opened.' ); } if (!is_string($url) || !strlen($url)) { throw new CAS_InvalidArgumentException('Invalid url.'); } $this->_url = $url; }
php
public function setServiceUrl ($url) { if ($this->hasBeenOpened()) { throw new CAS_OutOfSequenceException( 'Cannot set the URL, stream already opened.' ); } if (!is_string($url) || !strlen($url)) { throw new CAS_InvalidArgumentException('Invalid url.'); } $this->_url = $url; }
[ "public", "function", "setServiceUrl", "(", "$", "url", ")", "{", "if", "(", "$", "this", "->", "hasBeenOpened", "(", ")", ")", "{", "throw", "new", "CAS_OutOfSequenceException", "(", "'Cannot set the URL, stream already opened.'", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "url", ")", "||", "!", "strlen", "(", "$", "url", ")", ")", "{", "throw", "new", "CAS_InvalidArgumentException", "(", "'Invalid url.'", ")", ";", "}", "$", "this", "->", "_url", "=", "$", "url", ";", "}" ]
Set the URL of the service to pass to CAS for proxy-ticket retrieval. @param string $url Url to set @return void @throws CAS_OutOfSequenceException If called after the stream has been opened.
[ "Set", "the", "URL", "of", "the", "service", "to", "pass", "to", "CAS", "for", "proxy", "-", "ticket", "retrieval", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/ProxiedService/Imap.php#L102-L114
220,510
moodle/moodle
lib/behat/form_field/behat_form_filemanager.php
behat_form_filemanager.get_value
public function get_value() { // Wait until DOM and JS is ready. $this->session->wait(behat_base::get_timeout(), behat_base::PAGE_READY_JS); // Get the label to restrict the files to this single form field. $fieldlabel = $this->get_field_locator(); // Get the name of the current directory elements. $xpath = "//label[contains(., '" . $fieldlabel . "')]" . "/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' fitem ')]" . "/descendant::div[@data-fieldtype = 'filemanager']" . "/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-filename ')]"; // We don't need to wait here, also we don't have access to protected // contexts find* methods. $files = $this->session->getPage()->findAll('xpath', $xpath); if (!$files) { return ''; } $filenames = array(); foreach ($files as $filenode) { $filenames[] = $filenode->getText(); } return implode(',', $filenames); }
php
public function get_value() { // Wait until DOM and JS is ready. $this->session->wait(behat_base::get_timeout(), behat_base::PAGE_READY_JS); // Get the label to restrict the files to this single form field. $fieldlabel = $this->get_field_locator(); // Get the name of the current directory elements. $xpath = "//label[contains(., '" . $fieldlabel . "')]" . "/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' fitem ')]" . "/descendant::div[@data-fieldtype = 'filemanager']" . "/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-filename ')]"; // We don't need to wait here, also we don't have access to protected // contexts find* methods. $files = $this->session->getPage()->findAll('xpath', $xpath); if (!$files) { return ''; } $filenames = array(); foreach ($files as $filenode) { $filenames[] = $filenode->getText(); } return implode(',', $filenames); }
[ "public", "function", "get_value", "(", ")", "{", "// Wait until DOM and JS is ready.", "$", "this", "->", "session", "->", "wait", "(", "behat_base", "::", "get_timeout", "(", ")", ",", "behat_base", "::", "PAGE_READY_JS", ")", ";", "// Get the label to restrict the files to this single form field.", "$", "fieldlabel", "=", "$", "this", "->", "get_field_locator", "(", ")", ";", "// Get the name of the current directory elements.", "$", "xpath", "=", "\"//label[contains(., '\"", ".", "$", "fieldlabel", ".", "\"')]\"", ".", "\"/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' fitem ')]\"", ".", "\"/descendant::div[@data-fieldtype = 'filemanager']\"", ".", "\"/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-filename ')]\"", ";", "// We don't need to wait here, also we don't have access to protected", "// contexts find* methods.", "$", "files", "=", "$", "this", "->", "session", "->", "getPage", "(", ")", "->", "findAll", "(", "'xpath'", ",", "$", "xpath", ")", ";", "if", "(", "!", "$", "files", ")", "{", "return", "''", ";", "}", "$", "filenames", "=", "array", "(", ")", ";", "foreach", "(", "$", "files", "as", "$", "filenode", ")", "{", "$", "filenames", "[", "]", "=", "$", "filenode", "->", "getText", "(", ")", ";", "}", "return", "implode", "(", "','", ",", "$", "filenames", ")", ";", "}" ]
Gets the value. @return string A comma-separated list of the root directory file names.
[ "Gets", "the", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_filemanager.php#L62-L90
220,511
moodle/moodle
lib/behat/form_field/behat_form_filemanager.php
behat_form_filemanager.set_value
public function set_value($value) { // Getting the filemanager label from the DOM. $fieldlabel = $this->get_field_locator(); // Getting the filepicker context and using the step definition // to upload the requested file. $uploadcontext = behat_context_helper::get('behat_repository_upload'); $uploadcontext->i_upload_file_to_filemanager($value, $fieldlabel); }
php
public function set_value($value) { // Getting the filemanager label from the DOM. $fieldlabel = $this->get_field_locator(); // Getting the filepicker context and using the step definition // to upload the requested file. $uploadcontext = behat_context_helper::get('behat_repository_upload'); $uploadcontext->i_upload_file_to_filemanager($value, $fieldlabel); }
[ "public", "function", "set_value", "(", "$", "value", ")", "{", "// Getting the filemanager label from the DOM.", "$", "fieldlabel", "=", "$", "this", "->", "get_field_locator", "(", ")", ";", "// Getting the filepicker context and using the step definition", "// to upload the requested file.", "$", "uploadcontext", "=", "behat_context_helper", "::", "get", "(", "'behat_repository_upload'", ")", ";", "$", "uploadcontext", "->", "i_upload_file_to_filemanager", "(", "$", "value", ",", "$", "fieldlabel", ")", ";", "}" ]
Sets the field value. @param string $value @return void
[ "Sets", "the", "field", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_filemanager.php#L98-L107
220,512
moodle/moodle
grade/report/lib.php
grade_report.get_numusers
public function get_numusers($groups = true, $users = false) { global $CFG, $DB; $userwheresql = ""; $groupsql = ""; $groupwheresql = ""; // Limit to users with a gradeable role. list($gradebookrolessql, $gradebookrolesparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0'); // Limit to users with an active enrollment. list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context); // We want to query both the current context and parent contexts. list($relatedctxsql, $relatedctxparams) = $DB->get_in_or_equal($this->context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'relatedctx'); $params = array_merge($gradebookrolesparams, $enrolledparams, $relatedctxparams); if ($users) { $userwheresql = $this->userwheresql; $params = array_merge($params, $this->userwheresql_params); } if ($groups) { $groupsql = $this->groupsql; $groupwheresql = $this->groupwheresql; $params = array_merge($params, $this->groupwheresql_params); } $sql = "SELECT DISTINCT u.id FROM {user} u JOIN ($enrolledsql) je ON je.id = u.id JOIN {role_assignments} ra ON u.id = ra.userid $groupsql WHERE ra.roleid $gradebookrolessql AND u.deleted = 0 $userwheresql $groupwheresql AND ra.contextid $relatedctxsql"; $selectedusers = $DB->get_records_sql($sql, $params); $count = 0; // Check if user's enrolment is active and should be displayed. if (!empty($selectedusers)) { $coursecontext = $this->context->get_course_context(true); $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $coursecontext); if ($showonlyactiveenrol) { $useractiveenrolments = get_enrolled_users($coursecontext, '', 0, 'u.id', null, 0, 0, true); } foreach ($selectedusers as $id => $value) { if (!$showonlyactiveenrol || ($showonlyactiveenrol && array_key_exists($id, $useractiveenrolments))) { $count++; } } } return $count; }
php
public function get_numusers($groups = true, $users = false) { global $CFG, $DB; $userwheresql = ""; $groupsql = ""; $groupwheresql = ""; // Limit to users with a gradeable role. list($gradebookrolessql, $gradebookrolesparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0'); // Limit to users with an active enrollment. list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context); // We want to query both the current context and parent contexts. list($relatedctxsql, $relatedctxparams) = $DB->get_in_or_equal($this->context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'relatedctx'); $params = array_merge($gradebookrolesparams, $enrolledparams, $relatedctxparams); if ($users) { $userwheresql = $this->userwheresql; $params = array_merge($params, $this->userwheresql_params); } if ($groups) { $groupsql = $this->groupsql; $groupwheresql = $this->groupwheresql; $params = array_merge($params, $this->groupwheresql_params); } $sql = "SELECT DISTINCT u.id FROM {user} u JOIN ($enrolledsql) je ON je.id = u.id JOIN {role_assignments} ra ON u.id = ra.userid $groupsql WHERE ra.roleid $gradebookrolessql AND u.deleted = 0 $userwheresql $groupwheresql AND ra.contextid $relatedctxsql"; $selectedusers = $DB->get_records_sql($sql, $params); $count = 0; // Check if user's enrolment is active and should be displayed. if (!empty($selectedusers)) { $coursecontext = $this->context->get_course_context(true); $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $coursecontext); if ($showonlyactiveenrol) { $useractiveenrolments = get_enrolled_users($coursecontext, '', 0, 'u.id', null, 0, 0, true); } foreach ($selectedusers as $id => $value) { if (!$showonlyactiveenrol || ($showonlyactiveenrol && array_key_exists($id, $useractiveenrolments))) { $count++; } } } return $count; }
[ "public", "function", "get_numusers", "(", "$", "groups", "=", "true", ",", "$", "users", "=", "false", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "userwheresql", "=", "\"\"", ";", "$", "groupsql", "=", "\"\"", ";", "$", "groupwheresql", "=", "\"\"", ";", "// Limit to users with a gradeable role.", "list", "(", "$", "gradebookrolessql", ",", "$", "gradebookrolesparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "explode", "(", "','", ",", "$", "this", "->", "gradebookroles", ")", ",", "SQL_PARAMS_NAMED", ",", "'grbr0'", ")", ";", "// Limit to users with an active enrollment.", "list", "(", "$", "enrolledsql", ",", "$", "enrolledparams", ")", "=", "get_enrolled_sql", "(", "$", "this", "->", "context", ")", ";", "// We want to query both the current context and parent contexts.", "list", "(", "$", "relatedctxsql", ",", "$", "relatedctxparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "this", "->", "context", "->", "get_parent_context_ids", "(", "true", ")", ",", "SQL_PARAMS_NAMED", ",", "'relatedctx'", ")", ";", "$", "params", "=", "array_merge", "(", "$", "gradebookrolesparams", ",", "$", "enrolledparams", ",", "$", "relatedctxparams", ")", ";", "if", "(", "$", "users", ")", "{", "$", "userwheresql", "=", "$", "this", "->", "userwheresql", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "this", "->", "userwheresql_params", ")", ";", "}", "if", "(", "$", "groups", ")", "{", "$", "groupsql", "=", "$", "this", "->", "groupsql", ";", "$", "groupwheresql", "=", "$", "this", "->", "groupwheresql", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "this", "->", "groupwheresql_params", ")", ";", "}", "$", "sql", "=", "\"SELECT DISTINCT u.id\n FROM {user} u\n JOIN ($enrolledsql) je\n ON je.id = u.id\n JOIN {role_assignments} ra\n ON u.id = ra.userid\n $groupsql\n WHERE ra.roleid $gradebookrolessql\n AND u.deleted = 0\n $userwheresql\n $groupwheresql\n AND ra.contextid $relatedctxsql\"", ";", "$", "selectedusers", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "count", "=", "0", ";", "// Check if user's enrolment is active and should be displayed.", "if", "(", "!", "empty", "(", "$", "selectedusers", ")", ")", "{", "$", "coursecontext", "=", "$", "this", "->", "context", "->", "get_course_context", "(", "true", ")", ";", "$", "defaultgradeshowactiveenrol", "=", "!", "empty", "(", "$", "CFG", "->", "grade_report_showonlyactiveenrol", ")", ";", "$", "showonlyactiveenrol", "=", "get_user_preferences", "(", "'grade_report_showonlyactiveenrol'", ",", "$", "defaultgradeshowactiveenrol", ")", ";", "$", "showonlyactiveenrol", "=", "$", "showonlyactiveenrol", "||", "!", "has_capability", "(", "'moodle/course:viewsuspendedusers'", ",", "$", "coursecontext", ")", ";", "if", "(", "$", "showonlyactiveenrol", ")", "{", "$", "useractiveenrolments", "=", "get_enrolled_users", "(", "$", "coursecontext", ",", "''", ",", "0", ",", "'u.id'", ",", "null", ",", "0", ",", "0", ",", "true", ")", ";", "}", "foreach", "(", "$", "selectedusers", "as", "$", "id", "=>", "$", "value", ")", "{", "if", "(", "!", "$", "showonlyactiveenrol", "||", "(", "$", "showonlyactiveenrol", "&&", "array_key_exists", "(", "$", "id", ",", "$", "useractiveenrolments", ")", ")", ")", "{", "$", "count", "++", ";", "}", "}", "}", "return", "$", "count", ";", "}" ]
Fetches and returns a count of all the users that will be shown on this page. @param boolean $groups include groups limit @param boolean $users include users limit - default false, used for searching purposes @return int Count of users
[ "Fetches", "and", "returns", "a", "count", "of", "all", "the", "users", "that", "will", "be", "shown", "on", "this", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/lib.php#L293-L355
220,513
moodle/moodle
grade/report/lib.php
grade_report.setup_groups
protected function setup_groups() { // find out current groups mode if ($this->groupmode = groups_get_course_groupmode($this->course)) { if (empty($this->gpr->groupid)) { $this->currentgroup = groups_get_course_group($this->course, true); } else { $this->currentgroup = $this->gpr->groupid; } $this->group_selector = groups_print_course_menu($this->course, $this->pbarurl, true); if ($this->groupmode == SEPARATEGROUPS and !$this->currentgroup and !has_capability('moodle/site:accessallgroups', $this->context)) { $this->currentgroup = -2; // means can not access any groups at all } if ($this->currentgroup) { $group = groups_get_group($this->currentgroup); $this->currentgroupname = $group->name; $this->groupsql = " JOIN {groups_members} gm ON gm.userid = u.id "; $this->groupwheresql = " AND gm.groupid = :gr_grpid "; $this->groupwheresql_params = array('gr_grpid'=>$this->currentgroup); } } }
php
protected function setup_groups() { // find out current groups mode if ($this->groupmode = groups_get_course_groupmode($this->course)) { if (empty($this->gpr->groupid)) { $this->currentgroup = groups_get_course_group($this->course, true); } else { $this->currentgroup = $this->gpr->groupid; } $this->group_selector = groups_print_course_menu($this->course, $this->pbarurl, true); if ($this->groupmode == SEPARATEGROUPS and !$this->currentgroup and !has_capability('moodle/site:accessallgroups', $this->context)) { $this->currentgroup = -2; // means can not access any groups at all } if ($this->currentgroup) { $group = groups_get_group($this->currentgroup); $this->currentgroupname = $group->name; $this->groupsql = " JOIN {groups_members} gm ON gm.userid = u.id "; $this->groupwheresql = " AND gm.groupid = :gr_grpid "; $this->groupwheresql_params = array('gr_grpid'=>$this->currentgroup); } } }
[ "protected", "function", "setup_groups", "(", ")", "{", "// find out current groups mode", "if", "(", "$", "this", "->", "groupmode", "=", "groups_get_course_groupmode", "(", "$", "this", "->", "course", ")", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "gpr", "->", "groupid", ")", ")", "{", "$", "this", "->", "currentgroup", "=", "groups_get_course_group", "(", "$", "this", "->", "course", ",", "true", ")", ";", "}", "else", "{", "$", "this", "->", "currentgroup", "=", "$", "this", "->", "gpr", "->", "groupid", ";", "}", "$", "this", "->", "group_selector", "=", "groups_print_course_menu", "(", "$", "this", "->", "course", ",", "$", "this", "->", "pbarurl", ",", "true", ")", ";", "if", "(", "$", "this", "->", "groupmode", "==", "SEPARATEGROUPS", "and", "!", "$", "this", "->", "currentgroup", "and", "!", "has_capability", "(", "'moodle/site:accessallgroups'", ",", "$", "this", "->", "context", ")", ")", "{", "$", "this", "->", "currentgroup", "=", "-", "2", ";", "// means can not access any groups at all", "}", "if", "(", "$", "this", "->", "currentgroup", ")", "{", "$", "group", "=", "groups_get_group", "(", "$", "this", "->", "currentgroup", ")", ";", "$", "this", "->", "currentgroupname", "=", "$", "group", "->", "name", ";", "$", "this", "->", "groupsql", "=", "\" JOIN {groups_members} gm ON gm.userid = u.id \"", ";", "$", "this", "->", "groupwheresql", "=", "\" AND gm.groupid = :gr_grpid \"", ";", "$", "this", "->", "groupwheresql_params", "=", "array", "(", "'gr_grpid'", "=>", "$", "this", "->", "currentgroup", ")", ";", "}", "}", "}" ]
Sets up this object's group variables, mainly to restrict the selection of users to display.
[ "Sets", "up", "this", "object", "s", "group", "variables", "mainly", "to", "restrict", "the", "selection", "of", "users", "to", "display", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/lib.php#L367-L388
220,514
moodle/moodle
grade/report/lib.php
grade_report.setup_users
public function setup_users() { global $SESSION, $DB; $this->userwheresql = ""; $this->userwheresql_params = array(); if (isset($SESSION->gradereport['filterfirstname']) && !empty($SESSION->gradereport['filterfirstname'])) { $this->userwheresql .= ' AND '.$DB->sql_like('u.firstname', ':firstname', false, false); $this->userwheresql_params['firstname'] = $SESSION->gradereport['filterfirstname'].'%'; } if (isset($SESSION->gradereport['filtersurname']) && !empty($SESSION->gradereport['filtersurname'])) { $this->userwheresql .= ' AND '.$DB->sql_like('u.lastname', ':lastname', false, false); $this->userwheresql_params['lastname'] = $SESSION->gradereport['filtersurname'].'%'; } }
php
public function setup_users() { global $SESSION, $DB; $this->userwheresql = ""; $this->userwheresql_params = array(); if (isset($SESSION->gradereport['filterfirstname']) && !empty($SESSION->gradereport['filterfirstname'])) { $this->userwheresql .= ' AND '.$DB->sql_like('u.firstname', ':firstname', false, false); $this->userwheresql_params['firstname'] = $SESSION->gradereport['filterfirstname'].'%'; } if (isset($SESSION->gradereport['filtersurname']) && !empty($SESSION->gradereport['filtersurname'])) { $this->userwheresql .= ' AND '.$DB->sql_like('u.lastname', ':lastname', false, false); $this->userwheresql_params['lastname'] = $SESSION->gradereport['filtersurname'].'%'; } }
[ "public", "function", "setup_users", "(", ")", "{", "global", "$", "SESSION", ",", "$", "DB", ";", "$", "this", "->", "userwheresql", "=", "\"\"", ";", "$", "this", "->", "userwheresql_params", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "SESSION", "->", "gradereport", "[", "'filterfirstname'", "]", ")", "&&", "!", "empty", "(", "$", "SESSION", "->", "gradereport", "[", "'filterfirstname'", "]", ")", ")", "{", "$", "this", "->", "userwheresql", ".=", "' AND '", ".", "$", "DB", "->", "sql_like", "(", "'u.firstname'", ",", "':firstname'", ",", "false", ",", "false", ")", ";", "$", "this", "->", "userwheresql_params", "[", "'firstname'", "]", "=", "$", "SESSION", "->", "gradereport", "[", "'filterfirstname'", "]", ".", "'%'", ";", "}", "if", "(", "isset", "(", "$", "SESSION", "->", "gradereport", "[", "'filtersurname'", "]", ")", "&&", "!", "empty", "(", "$", "SESSION", "->", "gradereport", "[", "'filtersurname'", "]", ")", ")", "{", "$", "this", "->", "userwheresql", ".=", "' AND '", ".", "$", "DB", "->", "sql_like", "(", "'u.lastname'", ",", "':lastname'", ",", "false", ",", "false", ")", ";", "$", "this", "->", "userwheresql_params", "[", "'lastname'", "]", "=", "$", "SESSION", "->", "gradereport", "[", "'filtersurname'", "]", ".", "'%'", ";", "}", "}" ]
Sets up this report's user criteria to restrict the selection of users to display.
[ "Sets", "up", "this", "report", "s", "user", "criteria", "to", "restrict", "the", "selection", "of", "users", "to", "display", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/lib.php#L393-L406
220,515
moodle/moodle
mod/assign/feedback/file/renderer.php
assignfeedback_file_renderer.render_assignfeedback_file_import_summary
public function render_assignfeedback_file_import_summary($summary) { $o = ''; $o .= $this->container(get_string('userswithnewfeedback', 'assignfeedback_file', $summary->userswithnewfeedback)); $o .= $this->container(get_string('filesupdated', 'assignfeedback_file', $summary->feedbackfilesupdated)); $o .= $this->container(get_string('filesadded', 'assignfeedback_file', $summary->feedbackfilesadded)); $url = new moodle_url('view.php', array('id'=>$summary->cmid, 'action'=>'grading')); $o .= $this->continue_button($url); return $o; }
php
public function render_assignfeedback_file_import_summary($summary) { $o = ''; $o .= $this->container(get_string('userswithnewfeedback', 'assignfeedback_file', $summary->userswithnewfeedback)); $o .= $this->container(get_string('filesupdated', 'assignfeedback_file', $summary->feedbackfilesupdated)); $o .= $this->container(get_string('filesadded', 'assignfeedback_file', $summary->feedbackfilesadded)); $url = new moodle_url('view.php', array('id'=>$summary->cmid, 'action'=>'grading')); $o .= $this->continue_button($url); return $o; }
[ "public", "function", "render_assignfeedback_file_import_summary", "(", "$", "summary", ")", "{", "$", "o", "=", "''", ";", "$", "o", ".=", "$", "this", "->", "container", "(", "get_string", "(", "'userswithnewfeedback'", ",", "'assignfeedback_file'", ",", "$", "summary", "->", "userswithnewfeedback", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "container", "(", "get_string", "(", "'filesupdated'", ",", "'assignfeedback_file'", ",", "$", "summary", "->", "feedbackfilesupdated", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "container", "(", "get_string", "(", "'filesadded'", ",", "'assignfeedback_file'", ",", "$", "summary", "->", "feedbackfilesadded", ")", ")", ";", "$", "url", "=", "new", "moodle_url", "(", "'view.php'", ",", "array", "(", "'id'", "=>", "$", "summary", "->", "cmid", ",", "'action'", "=>", "'grading'", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "continue_button", "(", "$", "url", ")", ";", "return", "$", "o", ";", "}" ]
Render a summary of the zip file import @param assignfeedback_file_import_summary $summary - Stats about the zip import @return string The html response
[ "Render", "a", "summary", "of", "the", "zip", "file", "import" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/renderer.php#L42-L53
220,516
moodle/moodle
backup/util/xml/parser/processors/simplified_parser_processor.class.php
simplified_parser_processor.selected_parent_exists
protected function selected_parent_exists($path) { $parentpath = progressive_parser::dirname($path); while ($parentpath != '/') { if ($this->path_is_selected($parentpath)) { return $parentpath; } $parentpath = progressive_parser::dirname($parentpath); } return false; }
php
protected function selected_parent_exists($path) { $parentpath = progressive_parser::dirname($path); while ($parentpath != '/') { if ($this->path_is_selected($parentpath)) { return $parentpath; } $parentpath = progressive_parser::dirname($parentpath); } return false; }
[ "protected", "function", "selected_parent_exists", "(", "$", "path", ")", "{", "$", "parentpath", "=", "progressive_parser", "::", "dirname", "(", "$", "path", ")", ";", "while", "(", "$", "parentpath", "!=", "'/'", ")", "{", "if", "(", "$", "this", "->", "path_is_selected", "(", "$", "parentpath", ")", ")", "{", "return", "$", "parentpath", ";", "}", "$", "parentpath", "=", "progressive_parser", "::", "dirname", "(", "$", "parentpath", ")", ";", "}", "return", "false", ";", "}" ]
Returns the first selected parent if available or false
[ "Returns", "the", "first", "selected", "parent", "if", "available", "or", "false" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/xml/parser/processors/simplified_parser_processor.class.php#L250-L259
220,517
moodle/moodle
lib/htmlpurifier/HTMLPurifier.php
HTMLPurifier.purifyArray
public function purifyArray($array_of_html, $config = null) { $context_array = array(); foreach ($array_of_html as $key => $html) { $array_of_html[$key] = $this->purify($html, $config); $context_array[$key] = $this->context; } $this->context = $context_array; return $array_of_html; }
php
public function purifyArray($array_of_html, $config = null) { $context_array = array(); foreach ($array_of_html as $key => $html) { $array_of_html[$key] = $this->purify($html, $config); $context_array[$key] = $this->context; } $this->context = $context_array; return $array_of_html; }
[ "public", "function", "purifyArray", "(", "$", "array_of_html", ",", "$", "config", "=", "null", ")", "{", "$", "context_array", "=", "array", "(", ")", ";", "foreach", "(", "$", "array_of_html", "as", "$", "key", "=>", "$", "html", ")", "{", "$", "array_of_html", "[", "$", "key", "]", "=", "$", "this", "->", "purify", "(", "$", "html", ",", "$", "config", ")", ";", "$", "context_array", "[", "$", "key", "]", "=", "$", "this", "->", "context", ";", "}", "$", "this", "->", "context", "=", "$", "context_array", ";", "return", "$", "array_of_html", ";", "}" ]
Filters an array of HTML snippets @param string[] $array_of_html Array of html snippets @param HTMLPurifier_Config $config Optional config object for this operation. See HTMLPurifier::purify() for more details. @return string[] Array of purified HTML
[ "Filters", "an", "array", "of", "HTML", "snippets" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier.php#L240-L249
220,518
moodle/moodle
lib/htmlpurifier/HTMLPurifier.php
HTMLPurifier.instance
public static function instance($prototype = null) { if (!self::$instance || $prototype) { if ($prototype instanceof HTMLPurifier) { self::$instance = $prototype; } elseif ($prototype) { self::$instance = new HTMLPurifier($prototype); } else { self::$instance = new HTMLPurifier(); } } return self::$instance; }
php
public static function instance($prototype = null) { if (!self::$instance || $prototype) { if ($prototype instanceof HTMLPurifier) { self::$instance = $prototype; } elseif ($prototype) { self::$instance = new HTMLPurifier($prototype); } else { self::$instance = new HTMLPurifier(); } } return self::$instance; }
[ "public", "static", "function", "instance", "(", "$", "prototype", "=", "null", ")", "{", "if", "(", "!", "self", "::", "$", "instance", "||", "$", "prototype", ")", "{", "if", "(", "$", "prototype", "instanceof", "HTMLPurifier", ")", "{", "self", "::", "$", "instance", "=", "$", "prototype", ";", "}", "elseif", "(", "$", "prototype", ")", "{", "self", "::", "$", "instance", "=", "new", "HTMLPurifier", "(", "$", "prototype", ")", ";", "}", "else", "{", "self", "::", "$", "instance", "=", "new", "HTMLPurifier", "(", ")", ";", "}", "}", "return", "self", "::", "$", "instance", ";", "}" ]
Singleton for enforcing just one HTML Purifier in your system @param HTMLPurifier|HTMLPurifier_Config $prototype Optional prototype HTMLPurifier instance to overload singleton with, or HTMLPurifier_Config instance to configure the generated version with. @return HTMLPurifier
[ "Singleton", "for", "enforcing", "just", "one", "HTML", "Purifier", "in", "your", "system" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier.php#L261-L273
220,519
moodle/moodle
lib/filestorage/file_storage.php
file_storage.setup_file_system
public function setup_file_system() { global $CFG; if ($this->filesystem === null) { require_once($CFG->libdir . '/filestorage/file_system.php'); if (!empty($CFG->alternative_file_system_class)) { $class = $CFG->alternative_file_system_class; } else { // The default file_system is the filedir. require_once($CFG->libdir . '/filestorage/file_system_filedir.php'); $class = file_system_filedir::class; } $this->filesystem = new $class(); } return $this->filesystem; }
php
public function setup_file_system() { global $CFG; if ($this->filesystem === null) { require_once($CFG->libdir . '/filestorage/file_system.php'); if (!empty($CFG->alternative_file_system_class)) { $class = $CFG->alternative_file_system_class; } else { // The default file_system is the filedir. require_once($CFG->libdir . '/filestorage/file_system_filedir.php'); $class = file_system_filedir::class; } $this->filesystem = new $class(); } return $this->filesystem; }
[ "public", "function", "setup_file_system", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "this", "->", "filesystem", "===", "null", ")", "{", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filestorage/file_system.php'", ")", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "alternative_file_system_class", ")", ")", "{", "$", "class", "=", "$", "CFG", "->", "alternative_file_system_class", ";", "}", "else", "{", "// The default file_system is the filedir.", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filestorage/file_system_filedir.php'", ")", ";", "$", "class", "=", "file_system_filedir", "::", "class", ";", "}", "$", "this", "->", "filesystem", "=", "new", "$", "class", "(", ")", ";", "}", "return", "$", "this", "->", "filesystem", ";", "}" ]
Complete setup procedure for the file_system component. @return file_system
[ "Complete", "setup", "procedure", "for", "the", "file_system", "component", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L69-L84
220,520
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_pathname_hash
public static function get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename) { return sha1("/$contextid/$component/$filearea/$itemid".$filepath.$filename); }
php
public static function get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename) { return sha1("/$contextid/$component/$filearea/$itemid".$filepath.$filename); }
[ "public", "static", "function", "get_pathname_hash", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", "{", "return", "sha1", "(", "\"/$contextid/$component/$filearea/$itemid\"", ".", "$", "filepath", ".", "$", "filename", ")", ";", "}" ]
Calculates sha1 hash of unique full path name information. This hash is a unique file identifier - it is used to improve performance and overcome db index size limits. @param int $contextid context ID @param string $component component @param string $filearea file area @param int $itemid item ID @param string $filepath file path @param string $filename file name @return string sha1 hash
[ "Calculates", "sha1", "hash", "of", "unique", "full", "path", "name", "information", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L109-L111
220,521
moodle/moodle
lib/filestorage/file_storage.php
file_storage.file_exists
public function file_exists($contextid, $component, $filearea, $itemid, $filepath, $filename) { $filepath = clean_param($filepath, PARAM_PATH); $filename = clean_param($filename, PARAM_FILE); if ($filename === '') { $filename = '.'; } $pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename); return $this->file_exists_by_hash($pathnamehash); }
php
public function file_exists($contextid, $component, $filearea, $itemid, $filepath, $filename) { $filepath = clean_param($filepath, PARAM_PATH); $filename = clean_param($filename, PARAM_FILE); if ($filename === '') { $filename = '.'; } $pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename); return $this->file_exists_by_hash($pathnamehash); }
[ "public", "function", "file_exists", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", "{", "$", "filepath", "=", "clean_param", "(", "$", "filepath", ",", "PARAM_PATH", ")", ";", "$", "filename", "=", "clean_param", "(", "$", "filename", ",", "PARAM_FILE", ")", ";", "if", "(", "$", "filename", "===", "''", ")", "{", "$", "filename", "=", "'.'", ";", "}", "$", "pathnamehash", "=", "$", "this", "->", "get_pathname_hash", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", ";", "return", "$", "this", "->", "file_exists_by_hash", "(", "$", "pathnamehash", ")", ";", "}" ]
Does this file exist? @param int $contextid context ID @param string $component component @param string $filearea file area @param int $itemid item ID @param string $filepath file path @param string $filename file name @return bool
[ "Does", "this", "file", "exist?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L124-L134
220,522
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_file_preview
public function get_file_preview(stored_file $file, $mode) { $context = context_system::instance(); $path = '/' . trim($mode, '/') . '/'; $preview = $this->get_file($context->id, 'core', 'preview', 0, $path, $file->get_contenthash()); if (!$preview) { $preview = $this->create_file_preview($file, $mode); if (!$preview) { return false; } } return $preview; }
php
public function get_file_preview(stored_file $file, $mode) { $context = context_system::instance(); $path = '/' . trim($mode, '/') . '/'; $preview = $this->get_file($context->id, 'core', 'preview', 0, $path, $file->get_contenthash()); if (!$preview) { $preview = $this->create_file_preview($file, $mode); if (!$preview) { return false; } } return $preview; }
[ "public", "function", "get_file_preview", "(", "stored_file", "$", "file", ",", "$", "mode", ")", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "path", "=", "'/'", ".", "trim", "(", "$", "mode", ",", "'/'", ")", ".", "'/'", ";", "$", "preview", "=", "$", "this", "->", "get_file", "(", "$", "context", "->", "id", ",", "'core'", ",", "'preview'", ",", "0", ",", "$", "path", ",", "$", "file", "->", "get_contenthash", "(", ")", ")", ";", "if", "(", "!", "$", "preview", ")", "{", "$", "preview", "=", "$", "this", "->", "create_file_preview", "(", "$", "file", ",", "$", "mode", ")", ";", "if", "(", "!", "$", "preview", ")", "{", "return", "false", ";", "}", "}", "return", "$", "preview", ";", "}" ]
Returns an image file that represent the given stored file as a preview At the moment, only GIF, JPEG and PNG files are supported to have previews. In the future, the support for other mimetypes can be added, too (eg. generate an image preview of PDF, text documents etc). @param stored_file $file the file we want to preview @param string $mode preview mode, eg. 'thumb' @return stored_file|bool false if unable to create the preview, stored file otherwise
[ "Returns", "an", "image", "file", "that", "represent", "the", "given", "stored", "file", "as", "a", "preview" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L235-L249
220,523
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_unused_filename
public function get_unused_filename($contextid, $component, $filearea, $itemid, $filepath, $filename) { global $DB; // Do not accept '.' or an empty file name (zero is acceptable). if ($filename == '.' || (empty($filename) && !is_numeric($filename))) { throw new coding_exception('Invalid file name passed', $filename); } // The file does not exist, we return the same file name. if (!$this->file_exists($contextid, $component, $filearea, $itemid, $filepath, $filename)) { return $filename; } // Trying to locate a file name using the used pattern. We remove the used pattern from the file name first. $pathinfo = pathinfo($filename); $basename = $pathinfo['filename']; $matches = array(); if (preg_match('~^(.+) \(([0-9]+)\)$~', $basename, $matches)) { $basename = $matches[1]; } $filenamelike = $DB->sql_like_escape($basename) . ' (%)'; if (isset($pathinfo['extension'])) { $filenamelike .= '.' . $DB->sql_like_escape($pathinfo['extension']); } $filenamelikesql = $DB->sql_like('f.filename', ':filenamelike'); $filenamelen = $DB->sql_length('f.filename'); $sql = "SELECT filename FROM {files} f WHERE f.contextid = :contextid AND f.component = :component AND f.filearea = :filearea AND f.itemid = :itemid AND f.filepath = :filepath AND $filenamelikesql ORDER BY $filenamelen DESC, f.filename DESC"; $params = array('contextid' => $contextid, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid, 'filepath' => $filepath, 'filenamelike' => $filenamelike); $results = $DB->get_fieldset_sql($sql, $params, IGNORE_MULTIPLE); // Loop over the results to make sure we are working on a valid file name. Because 'file (1).txt' and 'file (copy).txt' // would both be returned, but only the one only containing digits should be used. $number = 1; foreach ($results as $result) { $resultbasename = pathinfo($result, PATHINFO_FILENAME); $matches = array(); if (preg_match('~^(.+) \(([0-9]+)\)$~', $resultbasename, $matches)) { $number = $matches[2] + 1; break; } } // Constructing the new filename. $newfilename = $basename . ' (' . $number . ')'; if (isset($pathinfo['extension'])) { $newfilename .= '.' . $pathinfo['extension']; } return $newfilename; }
php
public function get_unused_filename($contextid, $component, $filearea, $itemid, $filepath, $filename) { global $DB; // Do not accept '.' or an empty file name (zero is acceptable). if ($filename == '.' || (empty($filename) && !is_numeric($filename))) { throw new coding_exception('Invalid file name passed', $filename); } // The file does not exist, we return the same file name. if (!$this->file_exists($contextid, $component, $filearea, $itemid, $filepath, $filename)) { return $filename; } // Trying to locate a file name using the used pattern. We remove the used pattern from the file name first. $pathinfo = pathinfo($filename); $basename = $pathinfo['filename']; $matches = array(); if (preg_match('~^(.+) \(([0-9]+)\)$~', $basename, $matches)) { $basename = $matches[1]; } $filenamelike = $DB->sql_like_escape($basename) . ' (%)'; if (isset($pathinfo['extension'])) { $filenamelike .= '.' . $DB->sql_like_escape($pathinfo['extension']); } $filenamelikesql = $DB->sql_like('f.filename', ':filenamelike'); $filenamelen = $DB->sql_length('f.filename'); $sql = "SELECT filename FROM {files} f WHERE f.contextid = :contextid AND f.component = :component AND f.filearea = :filearea AND f.itemid = :itemid AND f.filepath = :filepath AND $filenamelikesql ORDER BY $filenamelen DESC, f.filename DESC"; $params = array('contextid' => $contextid, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid, 'filepath' => $filepath, 'filenamelike' => $filenamelike); $results = $DB->get_fieldset_sql($sql, $params, IGNORE_MULTIPLE); // Loop over the results to make sure we are working on a valid file name. Because 'file (1).txt' and 'file (copy).txt' // would both be returned, but only the one only containing digits should be used. $number = 1; foreach ($results as $result) { $resultbasename = pathinfo($result, PATHINFO_FILENAME); $matches = array(); if (preg_match('~^(.+) \(([0-9]+)\)$~', $resultbasename, $matches)) { $number = $matches[2] + 1; break; } } // Constructing the new filename. $newfilename = $basename . ' (' . $number . ')'; if (isset($pathinfo['extension'])) { $newfilename .= '.' . $pathinfo['extension']; } return $newfilename; }
[ "public", "function", "get_unused_filename", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", "{", "global", "$", "DB", ";", "// Do not accept '.' or an empty file name (zero is acceptable).", "if", "(", "$", "filename", "==", "'.'", "||", "(", "empty", "(", "$", "filename", ")", "&&", "!", "is_numeric", "(", "$", "filename", ")", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid file name passed'", ",", "$", "filename", ")", ";", "}", "// The file does not exist, we return the same file name.", "if", "(", "!", "$", "this", "->", "file_exists", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", ")", "{", "return", "$", "filename", ";", "}", "// Trying to locate a file name using the used pattern. We remove the used pattern from the file name first.", "$", "pathinfo", "=", "pathinfo", "(", "$", "filename", ")", ";", "$", "basename", "=", "$", "pathinfo", "[", "'filename'", "]", ";", "$", "matches", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "'~^(.+) \\(([0-9]+)\\)$~'", ",", "$", "basename", ",", "$", "matches", ")", ")", "{", "$", "basename", "=", "$", "matches", "[", "1", "]", ";", "}", "$", "filenamelike", "=", "$", "DB", "->", "sql_like_escape", "(", "$", "basename", ")", ".", "' (%)'", ";", "if", "(", "isset", "(", "$", "pathinfo", "[", "'extension'", "]", ")", ")", "{", "$", "filenamelike", ".=", "'.'", ".", "$", "DB", "->", "sql_like_escape", "(", "$", "pathinfo", "[", "'extension'", "]", ")", ";", "}", "$", "filenamelikesql", "=", "$", "DB", "->", "sql_like", "(", "'f.filename'", ",", "':filenamelike'", ")", ";", "$", "filenamelen", "=", "$", "DB", "->", "sql_length", "(", "'f.filename'", ")", ";", "$", "sql", "=", "\"SELECT filename\n FROM {files} f\n WHERE\n f.contextid = :contextid AND\n f.component = :component AND\n f.filearea = :filearea AND\n f.itemid = :itemid AND\n f.filepath = :filepath AND\n $filenamelikesql\n ORDER BY\n $filenamelen DESC,\n f.filename DESC\"", ";", "$", "params", "=", "array", "(", "'contextid'", "=>", "$", "contextid", ",", "'component'", "=>", "$", "component", ",", "'filearea'", "=>", "$", "filearea", ",", "'itemid'", "=>", "$", "itemid", ",", "'filepath'", "=>", "$", "filepath", ",", "'filenamelike'", "=>", "$", "filenamelike", ")", ";", "$", "results", "=", "$", "DB", "->", "get_fieldset_sql", "(", "$", "sql", ",", "$", "params", ",", "IGNORE_MULTIPLE", ")", ";", "// Loop over the results to make sure we are working on a valid file name. Because 'file (1).txt' and 'file (copy).txt'", "// would both be returned, but only the one only containing digits should be used.", "$", "number", "=", "1", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "resultbasename", "=", "pathinfo", "(", "$", "result", ",", "PATHINFO_FILENAME", ")", ";", "$", "matches", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "'~^(.+) \\(([0-9]+)\\)$~'", ",", "$", "resultbasename", ",", "$", "matches", ")", ")", "{", "$", "number", "=", "$", "matches", "[", "2", "]", "+", "1", ";", "break", ";", "}", "}", "// Constructing the new filename.", "$", "newfilename", "=", "$", "basename", ".", "' ('", ".", "$", "number", ".", "')'", ";", "if", "(", "isset", "(", "$", "pathinfo", "[", "'extension'", "]", ")", ")", "{", "$", "newfilename", ".=", "'.'", ".", "$", "pathinfo", "[", "'extension'", "]", ";", "}", "return", "$", "newfilename", ";", "}" ]
Return an available file name. This will return the next available file name in the area, adding/incrementing a suffix of the file, ie: file.txt > file (1).txt > file (2).txt > etc... If the file name passed is available without modification, it is returned as is. @param int $contextid context ID. @param string $component component. @param string $filearea file area. @param int $itemid area item ID. @param string $filepath the file path. @param string $filename the file name. @return string available file name. @throws coding_exception if the file name is invalid. @since Moodle 2.5
[ "Return", "an", "available", "file", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L269-L332
220,524
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_unused_dirname
public function get_unused_dirname($contextid, $component, $filearea, $itemid, $suggestedpath) { global $DB; // Ensure suggestedpath has trailing '/' $suggestedpath = rtrim($suggestedpath, '/'). '/'; // The directory does not exist, we return the same file path. if (!$this->file_exists($contextid, $component, $filearea, $itemid, $suggestedpath, '.')) { return $suggestedpath; } // Trying to locate a file path using the used pattern. We remove the used pattern from the path first. if (preg_match('~^(/.+) \(([0-9]+)\)/$~', $suggestedpath, $matches)) { $suggestedpath = $matches[1]. '/'; } $filepathlike = $DB->sql_like_escape(rtrim($suggestedpath, '/')) . ' (%)/'; $filepathlikesql = $DB->sql_like('f.filepath', ':filepathlike'); $filepathlen = $DB->sql_length('f.filepath'); $sql = "SELECT filepath FROM {files} f WHERE f.contextid = :contextid AND f.component = :component AND f.filearea = :filearea AND f.itemid = :itemid AND f.filename = :filename AND $filepathlikesql ORDER BY $filepathlen DESC, f.filepath DESC"; $params = array('contextid' => $contextid, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid, 'filename' => '.', 'filepathlike' => $filepathlike); $results = $DB->get_fieldset_sql($sql, $params, IGNORE_MULTIPLE); // Loop over the results to make sure we are working on a valid file path. Because '/path (1)/' and '/path (copy)/' // would both be returned, but only the one only containing digits should be used. $number = 1; foreach ($results as $result) { if (preg_match('~ \(([0-9]+)\)/$~', $result, $matches)) { $number = (int)($matches[1]) + 1; break; } } return rtrim($suggestedpath, '/'). ' (' . $number . ')/'; }
php
public function get_unused_dirname($contextid, $component, $filearea, $itemid, $suggestedpath) { global $DB; // Ensure suggestedpath has trailing '/' $suggestedpath = rtrim($suggestedpath, '/'). '/'; // The directory does not exist, we return the same file path. if (!$this->file_exists($contextid, $component, $filearea, $itemid, $suggestedpath, '.')) { return $suggestedpath; } // Trying to locate a file path using the used pattern. We remove the used pattern from the path first. if (preg_match('~^(/.+) \(([0-9]+)\)/$~', $suggestedpath, $matches)) { $suggestedpath = $matches[1]. '/'; } $filepathlike = $DB->sql_like_escape(rtrim($suggestedpath, '/')) . ' (%)/'; $filepathlikesql = $DB->sql_like('f.filepath', ':filepathlike'); $filepathlen = $DB->sql_length('f.filepath'); $sql = "SELECT filepath FROM {files} f WHERE f.contextid = :contextid AND f.component = :component AND f.filearea = :filearea AND f.itemid = :itemid AND f.filename = :filename AND $filepathlikesql ORDER BY $filepathlen DESC, f.filepath DESC"; $params = array('contextid' => $contextid, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid, 'filename' => '.', 'filepathlike' => $filepathlike); $results = $DB->get_fieldset_sql($sql, $params, IGNORE_MULTIPLE); // Loop over the results to make sure we are working on a valid file path. Because '/path (1)/' and '/path (copy)/' // would both be returned, but only the one only containing digits should be used. $number = 1; foreach ($results as $result) { if (preg_match('~ \(([0-9]+)\)/$~', $result, $matches)) { $number = (int)($matches[1]) + 1; break; } } return rtrim($suggestedpath, '/'). ' (' . $number . ')/'; }
[ "public", "function", "get_unused_dirname", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "suggestedpath", ")", "{", "global", "$", "DB", ";", "// Ensure suggestedpath has trailing '/'", "$", "suggestedpath", "=", "rtrim", "(", "$", "suggestedpath", ",", "'/'", ")", ".", "'/'", ";", "// The directory does not exist, we return the same file path.", "if", "(", "!", "$", "this", "->", "file_exists", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "suggestedpath", ",", "'.'", ")", ")", "{", "return", "$", "suggestedpath", ";", "}", "// Trying to locate a file path using the used pattern. We remove the used pattern from the path first.", "if", "(", "preg_match", "(", "'~^(/.+) \\(([0-9]+)\\)/$~'", ",", "$", "suggestedpath", ",", "$", "matches", ")", ")", "{", "$", "suggestedpath", "=", "$", "matches", "[", "1", "]", ".", "'/'", ";", "}", "$", "filepathlike", "=", "$", "DB", "->", "sql_like_escape", "(", "rtrim", "(", "$", "suggestedpath", ",", "'/'", ")", ")", ".", "' (%)/'", ";", "$", "filepathlikesql", "=", "$", "DB", "->", "sql_like", "(", "'f.filepath'", ",", "':filepathlike'", ")", ";", "$", "filepathlen", "=", "$", "DB", "->", "sql_length", "(", "'f.filepath'", ")", ";", "$", "sql", "=", "\"SELECT filepath\n FROM {files} f\n WHERE\n f.contextid = :contextid AND\n f.component = :component AND\n f.filearea = :filearea AND\n f.itemid = :itemid AND\n f.filename = :filename AND\n $filepathlikesql\n ORDER BY\n $filepathlen DESC,\n f.filepath DESC\"", ";", "$", "params", "=", "array", "(", "'contextid'", "=>", "$", "contextid", ",", "'component'", "=>", "$", "component", ",", "'filearea'", "=>", "$", "filearea", ",", "'itemid'", "=>", "$", "itemid", ",", "'filename'", "=>", "'.'", ",", "'filepathlike'", "=>", "$", "filepathlike", ")", ";", "$", "results", "=", "$", "DB", "->", "get_fieldset_sql", "(", "$", "sql", ",", "$", "params", ",", "IGNORE_MULTIPLE", ")", ";", "// Loop over the results to make sure we are working on a valid file path. Because '/path (1)/' and '/path (copy)/'", "// would both be returned, but only the one only containing digits should be used.", "$", "number", "=", "1", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "if", "(", "preg_match", "(", "'~ \\(([0-9]+)\\)/$~'", ",", "$", "result", ",", "$", "matches", ")", ")", "{", "$", "number", "=", "(", "int", ")", "(", "$", "matches", "[", "1", "]", ")", "+", "1", ";", "break", ";", "}", "}", "return", "rtrim", "(", "$", "suggestedpath", ",", "'/'", ")", ".", "' ('", ".", "$", "number", ".", "')/'", ";", "}" ]
Return an available directory name. This will return the next available directory name in the area, adding/incrementing a suffix of the last portion of path, ie: /path/ > /path (1)/ > /path (2)/ > etc... If the file path passed is available without modification, it is returned as is. @param int $contextid context ID. @param string $component component. @param string $filearea file area. @param int $itemid area item ID. @param string $suggestedpath the suggested file path. @return string available file path @since Moodle 2.5
[ "Return", "an", "available", "directory", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L350-L397
220,525
moodle/moodle
lib/filestorage/file_storage.php
file_storage.create_file_preview
protected function create_file_preview(stored_file $file, $mode) { $mimetype = $file->get_mimetype(); if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') { // make a preview of the image $data = $this->create_imagefile_preview($file, $mode); } else { // unable to create the preview of this mimetype yet return false; } if (empty($data)) { return false; } $context = context_system::instance(); $record = array( 'contextid' => $context->id, 'component' => 'core', 'filearea' => 'preview', 'itemid' => 0, 'filepath' => '/' . trim($mode, '/') . '/', 'filename' => $file->get_contenthash(), ); $imageinfo = getimagesizefromstring($data); if ($imageinfo) { $record['mimetype'] = $imageinfo['mime']; } return $this->create_file_from_string($record, $data); }
php
protected function create_file_preview(stored_file $file, $mode) { $mimetype = $file->get_mimetype(); if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') { // make a preview of the image $data = $this->create_imagefile_preview($file, $mode); } else { // unable to create the preview of this mimetype yet return false; } if (empty($data)) { return false; } $context = context_system::instance(); $record = array( 'contextid' => $context->id, 'component' => 'core', 'filearea' => 'preview', 'itemid' => 0, 'filepath' => '/' . trim($mode, '/') . '/', 'filename' => $file->get_contenthash(), ); $imageinfo = getimagesizefromstring($data); if ($imageinfo) { $record['mimetype'] = $imageinfo['mime']; } return $this->create_file_from_string($record, $data); }
[ "protected", "function", "create_file_preview", "(", "stored_file", "$", "file", ",", "$", "mode", ")", "{", "$", "mimetype", "=", "$", "file", "->", "get_mimetype", "(", ")", ";", "if", "(", "$", "mimetype", "===", "'image/gif'", "or", "$", "mimetype", "===", "'image/jpeg'", "or", "$", "mimetype", "===", "'image/png'", ")", "{", "// make a preview of the image", "$", "data", "=", "$", "this", "->", "create_imagefile_preview", "(", "$", "file", ",", "$", "mode", ")", ";", "}", "else", "{", "// unable to create the preview of this mimetype yet", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "return", "false", ";", "}", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "record", "=", "array", "(", "'contextid'", "=>", "$", "context", "->", "id", ",", "'component'", "=>", "'core'", ",", "'filearea'", "=>", "'preview'", ",", "'itemid'", "=>", "0", ",", "'filepath'", "=>", "'/'", ".", "trim", "(", "$", "mode", ",", "'/'", ")", ".", "'/'", ",", "'filename'", "=>", "$", "file", "->", "get_contenthash", "(", ")", ",", ")", ";", "$", "imageinfo", "=", "getimagesizefromstring", "(", "$", "data", ")", ";", "if", "(", "$", "imageinfo", ")", "{", "$", "record", "[", "'mimetype'", "]", "=", "$", "imageinfo", "[", "'mime'", "]", ";", "}", "return", "$", "this", "->", "create_file_from_string", "(", "$", "record", ",", "$", "data", ")", ";", "}" ]
Generates a preview image for the stored file @param stored_file $file the file we want to preview @param string $mode preview mode, eg. 'thumb' @return stored_file|bool the newly created preview file or false
[ "Generates", "a", "preview", "image", "for", "the", "stored", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L406-L439
220,526
moodle/moodle
lib/filestorage/file_storage.php
file_storage.create_imagefile_preview
protected function create_imagefile_preview(stored_file $file, $mode) { global $CFG; require_once($CFG->libdir.'/gdlib.php'); if ($mode === 'tinyicon') { $data = $file->generate_image_thumbnail(24, 24); } else if ($mode === 'thumb') { $data = $file->generate_image_thumbnail(90, 90); } else if ($mode === 'bigthumb') { $data = $file->generate_image_thumbnail(250, 250); } else { throw new file_exception('storedfileproblem', 'Invalid preview mode requested'); } return $data; }
php
protected function create_imagefile_preview(stored_file $file, $mode) { global $CFG; require_once($CFG->libdir.'/gdlib.php'); if ($mode === 'tinyicon') { $data = $file->generate_image_thumbnail(24, 24); } else if ($mode === 'thumb') { $data = $file->generate_image_thumbnail(90, 90); } else if ($mode === 'bigthumb') { $data = $file->generate_image_thumbnail(250, 250); } else { throw new file_exception('storedfileproblem', 'Invalid preview mode requested'); } return $data; }
[ "protected", "function", "create_imagefile_preview", "(", "stored_file", "$", "file", ",", "$", "mode", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/gdlib.php'", ")", ";", "if", "(", "$", "mode", "===", "'tinyicon'", ")", "{", "$", "data", "=", "$", "file", "->", "generate_image_thumbnail", "(", "24", ",", "24", ")", ";", "}", "else", "if", "(", "$", "mode", "===", "'thumb'", ")", "{", "$", "data", "=", "$", "file", "->", "generate_image_thumbnail", "(", "90", ",", "90", ")", ";", "}", "else", "if", "(", "$", "mode", "===", "'bigthumb'", ")", "{", "$", "data", "=", "$", "file", "->", "generate_image_thumbnail", "(", "250", ",", "250", ")", ";", "}", "else", "{", "throw", "new", "file_exception", "(", "'storedfileproblem'", ",", "'Invalid preview mode requested'", ")", ";", "}", "return", "$", "data", ";", "}" ]
Generates a preview for the stored image file @param stored_file $file the image we want to preview @param string $mode preview mode, eg. 'thumb' @return string|bool false if a problem occurs, the thumbnail image data otherwise
[ "Generates", "a", "preview", "for", "the", "stored", "image", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L448-L466
220,527
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_file_by_id
public function get_file_by_id($fileid) { global $DB; $sql = "SELECT ".self::instance_sql_fields('f', 'r')." FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id WHERE f.id = ?"; if ($filerecord = $DB->get_record_sql($sql, array($fileid))) { return $this->get_file_instance($filerecord); } else { return false; } }
php
public function get_file_by_id($fileid) { global $DB; $sql = "SELECT ".self::instance_sql_fields('f', 'r')." FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id WHERE f.id = ?"; if ($filerecord = $DB->get_record_sql($sql, array($fileid))) { return $this->get_file_instance($filerecord); } else { return false; } }
[ "public", "function", "get_file_by_id", "(", "$", "fileid", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT \"", ".", "self", "::", "instance_sql_fields", "(", "'f'", ",", "'r'", ")", ".", "\"\n FROM {files} f\n LEFT JOIN {files_reference} r\n ON f.referencefileid = r.id\n WHERE f.id = ?\"", ";", "if", "(", "$", "filerecord", "=", "$", "DB", "->", "get_record_sql", "(", "$", "sql", ",", "array", "(", "$", "fileid", ")", ")", ")", "{", "return", "$", "this", "->", "get_file_instance", "(", "$", "filerecord", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Fetch file using local file id. Please do not rely on file ids, it is usually easier to use pathname hashes instead. @param int $fileid file ID @return stored_file|bool stored_file instance if exists, false if not
[ "Fetch", "file", "using", "local", "file", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L477-L490
220,528
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_file_by_hash
public function get_file_by_hash($pathnamehash) { global $DB; $sql = "SELECT ".self::instance_sql_fields('f', 'r')." FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id WHERE f.pathnamehash = ?"; if ($filerecord = $DB->get_record_sql($sql, array($pathnamehash))) { return $this->get_file_instance($filerecord); } else { return false; } }
php
public function get_file_by_hash($pathnamehash) { global $DB; $sql = "SELECT ".self::instance_sql_fields('f', 'r')." FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id WHERE f.pathnamehash = ?"; if ($filerecord = $DB->get_record_sql($sql, array($pathnamehash))) { return $this->get_file_instance($filerecord); } else { return false; } }
[ "public", "function", "get_file_by_hash", "(", "$", "pathnamehash", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT \"", ".", "self", "::", "instance_sql_fields", "(", "'f'", ",", "'r'", ")", ".", "\"\n FROM {files} f\n LEFT JOIN {files_reference} r\n ON f.referencefileid = r.id\n WHERE f.pathnamehash = ?\"", ";", "if", "(", "$", "filerecord", "=", "$", "DB", "->", "get_record_sql", "(", "$", "sql", ",", "array", "(", "$", "pathnamehash", ")", ")", ")", "{", "return", "$", "this", "->", "get_file_instance", "(", "$", "filerecord", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Fetch file using local file full pathname hash @param string $pathnamehash path name hash @return stored_file|bool stored_file instance if exists, false if not
[ "Fetch", "file", "using", "local", "file", "full", "pathname", "hash" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L498-L511
220,529
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_file
public function get_file($contextid, $component, $filearea, $itemid, $filepath, $filename) { $filepath = clean_param($filepath, PARAM_PATH); $filename = clean_param($filename, PARAM_FILE); if ($filename === '') { $filename = '.'; } $pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename); return $this->get_file_by_hash($pathnamehash); }
php
public function get_file($contextid, $component, $filearea, $itemid, $filepath, $filename) { $filepath = clean_param($filepath, PARAM_PATH); $filename = clean_param($filename, PARAM_FILE); if ($filename === '') { $filename = '.'; } $pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename); return $this->get_file_by_hash($pathnamehash); }
[ "public", "function", "get_file", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", "{", "$", "filepath", "=", "clean_param", "(", "$", "filepath", ",", "PARAM_PATH", ")", ";", "$", "filename", "=", "clean_param", "(", "$", "filename", ",", "PARAM_FILE", ")", ";", "if", "(", "$", "filename", "===", "''", ")", "{", "$", "filename", "=", "'.'", ";", "}", "$", "pathnamehash", "=", "$", "this", "->", "get_pathname_hash", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", ";", "return", "$", "this", "->", "get_file_by_hash", "(", "$", "pathnamehash", ")", ";", "}" ]
Fetch locally stored file. @param int $contextid context ID @param string $component component @param string $filearea file area @param int $itemid item ID @param string $filepath file path @param string $filename file name @return stored_file|bool stored_file instance if exists, false if not
[ "Fetch", "locally", "stored", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L524-L534
220,530
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_external_files
public function get_external_files($repositoryid, $sort = '') { global $DB; $sql = "SELECT ".self::instance_sql_fields('f', 'r')." FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id WHERE r.repositoryid = ?"; if (!empty($sort)) { $sql .= " ORDER BY {$sort}"; } $result = array(); $filerecords = $DB->get_records_sql($sql, array($repositoryid)); foreach ($filerecords as $filerecord) { $result[$filerecord->pathnamehash] = $this->get_file_instance($filerecord); } return $result; }
php
public function get_external_files($repositoryid, $sort = '') { global $DB; $sql = "SELECT ".self::instance_sql_fields('f', 'r')." FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id WHERE r.repositoryid = ?"; if (!empty($sort)) { $sql .= " ORDER BY {$sort}"; } $result = array(); $filerecords = $DB->get_records_sql($sql, array($repositoryid)); foreach ($filerecords as $filerecord) { $result[$filerecord->pathnamehash] = $this->get_file_instance($filerecord); } return $result; }
[ "public", "function", "get_external_files", "(", "$", "repositoryid", ",", "$", "sort", "=", "''", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT \"", ".", "self", "::", "instance_sql_fields", "(", "'f'", ",", "'r'", ")", ".", "\"\n FROM {files} f\n LEFT JOIN {files_reference} r\n ON f.referencefileid = r.id\n WHERE r.repositoryid = ?\"", ";", "if", "(", "!", "empty", "(", "$", "sort", ")", ")", "{", "$", "sql", ".=", "\" ORDER BY {$sort}\"", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "filerecords", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "array", "(", "$", "repositoryid", ")", ")", ";", "foreach", "(", "$", "filerecords", "as", "$", "filerecord", ")", "{", "$", "result", "[", "$", "filerecord", "->", "pathnamehash", "]", "=", "$", "this", "->", "get_file_instance", "(", "$", "filerecord", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns all files belonging to given repository @param int $repositoryid @param string $sort A fragment of SQL to use for sorting
[ "Returns", "all", "files", "belonging", "to", "given", "repository" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L576-L593
220,531
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_area_tree
public function get_area_tree($contextid, $component, $filearea, $itemid) { $result = array('dirname'=>'', 'dirfile'=>null, 'subdirs'=>array(), 'files'=>array()); $files = $this->get_area_files($contextid, $component, $filearea, $itemid, '', true); // first create directory structure foreach ($files as $hash=>$dir) { if (!$dir->is_directory()) { continue; } unset($files[$hash]); if ($dir->get_filepath() === '/') { $result['dirfile'] = $dir; continue; } $parts = explode('/', trim($dir->get_filepath(),'/')); $pointer =& $result; foreach ($parts as $part) { if ($part === '') { continue; } if (!isset($pointer['subdirs'][$part])) { $pointer['subdirs'][$part] = array('dirname'=>$part, 'dirfile'=>null, 'subdirs'=>array(), 'files'=>array()); } $pointer =& $pointer['subdirs'][$part]; } $pointer['dirfile'] = $dir; unset($pointer); } foreach ($files as $hash=>$file) { $parts = explode('/', trim($file->get_filepath(),'/')); $pointer =& $result; foreach ($parts as $part) { if ($part === '') { continue; } $pointer =& $pointer['subdirs'][$part]; } $pointer['files'][$file->get_filename()] = $file; unset($pointer); } $result = $this->sort_area_tree($result); return $result; }
php
public function get_area_tree($contextid, $component, $filearea, $itemid) { $result = array('dirname'=>'', 'dirfile'=>null, 'subdirs'=>array(), 'files'=>array()); $files = $this->get_area_files($contextid, $component, $filearea, $itemid, '', true); // first create directory structure foreach ($files as $hash=>$dir) { if (!$dir->is_directory()) { continue; } unset($files[$hash]); if ($dir->get_filepath() === '/') { $result['dirfile'] = $dir; continue; } $parts = explode('/', trim($dir->get_filepath(),'/')); $pointer =& $result; foreach ($parts as $part) { if ($part === '') { continue; } if (!isset($pointer['subdirs'][$part])) { $pointer['subdirs'][$part] = array('dirname'=>$part, 'dirfile'=>null, 'subdirs'=>array(), 'files'=>array()); } $pointer =& $pointer['subdirs'][$part]; } $pointer['dirfile'] = $dir; unset($pointer); } foreach ($files as $hash=>$file) { $parts = explode('/', trim($file->get_filepath(),'/')); $pointer =& $result; foreach ($parts as $part) { if ($part === '') { continue; } $pointer =& $pointer['subdirs'][$part]; } $pointer['files'][$file->get_filename()] = $file; unset($pointer); } $result = $this->sort_area_tree($result); return $result; }
[ "public", "function", "get_area_tree", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ")", "{", "$", "result", "=", "array", "(", "'dirname'", "=>", "''", ",", "'dirfile'", "=>", "null", ",", "'subdirs'", "=>", "array", "(", ")", ",", "'files'", "=>", "array", "(", ")", ")", ";", "$", "files", "=", "$", "this", "->", "get_area_files", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "''", ",", "true", ")", ";", "// first create directory structure", "foreach", "(", "$", "files", "as", "$", "hash", "=>", "$", "dir", ")", "{", "if", "(", "!", "$", "dir", "->", "is_directory", "(", ")", ")", "{", "continue", ";", "}", "unset", "(", "$", "files", "[", "$", "hash", "]", ")", ";", "if", "(", "$", "dir", "->", "get_filepath", "(", ")", "===", "'/'", ")", "{", "$", "result", "[", "'dirfile'", "]", "=", "$", "dir", ";", "continue", ";", "}", "$", "parts", "=", "explode", "(", "'/'", ",", "trim", "(", "$", "dir", "->", "get_filepath", "(", ")", ",", "'/'", ")", ")", ";", "$", "pointer", "=", "&", "$", "result", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "if", "(", "$", "part", "===", "''", ")", "{", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "pointer", "[", "'subdirs'", "]", "[", "$", "part", "]", ")", ")", "{", "$", "pointer", "[", "'subdirs'", "]", "[", "$", "part", "]", "=", "array", "(", "'dirname'", "=>", "$", "part", ",", "'dirfile'", "=>", "null", ",", "'subdirs'", "=>", "array", "(", ")", ",", "'files'", "=>", "array", "(", ")", ")", ";", "}", "$", "pointer", "=", "&", "$", "pointer", "[", "'subdirs'", "]", "[", "$", "part", "]", ";", "}", "$", "pointer", "[", "'dirfile'", "]", "=", "$", "dir", ";", "unset", "(", "$", "pointer", ")", ";", "}", "foreach", "(", "$", "files", "as", "$", "hash", "=>", "$", "file", ")", "{", "$", "parts", "=", "explode", "(", "'/'", ",", "trim", "(", "$", "file", "->", "get_filepath", "(", ")", ",", "'/'", ")", ")", ";", "$", "pointer", "=", "&", "$", "result", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "if", "(", "$", "part", "===", "''", ")", "{", "continue", ";", "}", "$", "pointer", "=", "&", "$", "pointer", "[", "'subdirs'", "]", "[", "$", "part", "]", ";", "}", "$", "pointer", "[", "'files'", "]", "[", "$", "file", "->", "get_filename", "(", ")", "]", "=", "$", "file", ";", "unset", "(", "$", "pointer", ")", ";", "}", "$", "result", "=", "$", "this", "->", "sort_area_tree", "(", "$", "result", ")", ";", "return", "$", "result", ";", "}" ]
Returns array based tree structure of area files @param int $contextid context ID @param string $component component @param string $filearea file area @param int $itemid item ID @return array each dir represented by dirname, subdirs, files and dirfile array elements
[ "Returns", "array", "based", "tree", "structure", "of", "area", "files" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L675-L716
220,532
moodle/moodle
lib/filestorage/file_storage.php
file_storage.delete_area_files_select
public function delete_area_files_select($contextid, $component, $filearea, $itemidstest, array $params = null) { global $DB; $where = "contextid = :contextid AND component = :component AND filearea = :filearea AND itemid $itemidstest"; $params['contextid'] = $contextid; $params['component'] = $component; $params['filearea'] = $filearea; $filerecords = $DB->get_recordset_select('files', $where, $params); foreach ($filerecords as $filerecord) { $this->get_file_instance($filerecord)->delete(); } $filerecords->close(); }
php
public function delete_area_files_select($contextid, $component, $filearea, $itemidstest, array $params = null) { global $DB; $where = "contextid = :contextid AND component = :component AND filearea = :filearea AND itemid $itemidstest"; $params['contextid'] = $contextid; $params['component'] = $component; $params['filearea'] = $filearea; $filerecords = $DB->get_recordset_select('files', $where, $params); foreach ($filerecords as $filerecord) { $this->get_file_instance($filerecord)->delete(); } $filerecords->close(); }
[ "public", "function", "delete_area_files_select", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemidstest", ",", "array", "$", "params", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "where", "=", "\"contextid = :contextid\n AND component = :component\n AND filearea = :filearea\n AND itemid $itemidstest\"", ";", "$", "params", "[", "'contextid'", "]", "=", "$", "contextid", ";", "$", "params", "[", "'component'", "]", "=", "$", "component", ";", "$", "params", "[", "'filearea'", "]", "=", "$", "filearea", ";", "$", "filerecords", "=", "$", "DB", "->", "get_recordset_select", "(", "'files'", ",", "$", "where", ",", "$", "params", ")", ";", "foreach", "(", "$", "filerecords", "as", "$", "filerecord", ")", "{", "$", "this", "->", "get_file_instance", "(", "$", "filerecord", ")", "->", "delete", "(", ")", ";", "}", "$", "filerecords", "->", "close", "(", ")", ";", "}" ]
Delete all the files from certain areas where itemid is limited by an arbitrary bit of SQL. @param int $contextid the id of the context the files belong to. Must be given. @param string $component the owning component. Must be given. @param string $filearea the file area name. Must be given. @param string $itemidstest an SQL fragment that the itemid must match. Used in the query like WHERE itemid $itemidstest. Must used named parameters, and may not used named parameters called contextid, component or filearea. @param array $params any query params used by $itemidstest.
[ "Delete", "all", "the", "files", "from", "certain", "areas", "where", "itemid", "is", "limited", "by", "an", "arbitrary", "bit", "of", "SQL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L874-L891
220,533
moodle/moodle
lib/filestorage/file_storage.php
file_storage.delete_component_files
public function delete_component_files($component) { global $DB; $filerecords = $DB->get_recordset('files', array('component' => $component)); foreach ($filerecords as $filerecord) { $this->get_file_instance($filerecord)->delete(); } $filerecords->close(); }
php
public function delete_component_files($component) { global $DB; $filerecords = $DB->get_recordset('files', array('component' => $component)); foreach ($filerecords as $filerecord) { $this->get_file_instance($filerecord)->delete(); } $filerecords->close(); }
[ "public", "function", "delete_component_files", "(", "$", "component", ")", "{", "global", "$", "DB", ";", "$", "filerecords", "=", "$", "DB", "->", "get_recordset", "(", "'files'", ",", "array", "(", "'component'", "=>", "$", "component", ")", ")", ";", "foreach", "(", "$", "filerecords", "as", "$", "filerecord", ")", "{", "$", "this", "->", "get_file_instance", "(", "$", "filerecord", ")", "->", "delete", "(", ")", ";", "}", "$", "filerecords", "->", "close", "(", ")", ";", "}" ]
Delete all files associated with the given component. @param string $component the component owning the file
[ "Delete", "all", "files", "associated", "with", "the", "given", "component", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L898-L906
220,534
moodle/moodle
lib/filestorage/file_storage.php
file_storage.move_area_files_to_new_context
public function move_area_files_to_new_context($oldcontextid, $newcontextid, $component, $filearea, $itemid = false) { // Note, this code is based on some code that Petr wrote in // forum_move_attachments in mod/forum/lib.php. I moved it here because // I needed it in the question code too. $count = 0; $oldfiles = $this->get_area_files($oldcontextid, $component, $filearea, $itemid, 'id', false); foreach ($oldfiles as $oldfile) { $filerecord = new stdClass(); $filerecord->contextid = $newcontextid; $this->create_file_from_storedfile($filerecord, $oldfile); $count += 1; } if ($count) { $this->delete_area_files($oldcontextid, $component, $filearea, $itemid); } return $count; }
php
public function move_area_files_to_new_context($oldcontextid, $newcontextid, $component, $filearea, $itemid = false) { // Note, this code is based on some code that Petr wrote in // forum_move_attachments in mod/forum/lib.php. I moved it here because // I needed it in the question code too. $count = 0; $oldfiles = $this->get_area_files($oldcontextid, $component, $filearea, $itemid, 'id', false); foreach ($oldfiles as $oldfile) { $filerecord = new stdClass(); $filerecord->contextid = $newcontextid; $this->create_file_from_storedfile($filerecord, $oldfile); $count += 1; } if ($count) { $this->delete_area_files($oldcontextid, $component, $filearea, $itemid); } return $count; }
[ "public", "function", "move_area_files_to_new_context", "(", "$", "oldcontextid", ",", "$", "newcontextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", "=", "false", ")", "{", "// Note, this code is based on some code that Petr wrote in", "// forum_move_attachments in mod/forum/lib.php. I moved it here because", "// I needed it in the question code too.", "$", "count", "=", "0", ";", "$", "oldfiles", "=", "$", "this", "->", "get_area_files", "(", "$", "oldcontextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "'id'", ",", "false", ")", ";", "foreach", "(", "$", "oldfiles", "as", "$", "oldfile", ")", "{", "$", "filerecord", "=", "new", "stdClass", "(", ")", ";", "$", "filerecord", "->", "contextid", "=", "$", "newcontextid", ";", "$", "this", "->", "create_file_from_storedfile", "(", "$", "filerecord", ",", "$", "oldfile", ")", ";", "$", "count", "+=", "1", ";", "}", "if", "(", "$", "count", ")", "{", "$", "this", "->", "delete_area_files", "(", "$", "oldcontextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ")", ";", "}", "return", "$", "count", ";", "}" ]
Move all the files in a file area from one context to another. @param int $oldcontextid the context the files are being moved from. @param int $newcontextid the context the files are being moved to. @param string $component the plugin that these files belong to. @param string $filearea the name of the file area. @param int $itemid file item ID @return int the number of files moved, for information.
[ "Move", "all", "the", "files", "in", "a", "file", "area", "from", "one", "context", "to", "another", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L918-L937
220,535
moodle/moodle
lib/filestorage/file_storage.php
file_storage.create_directory
public function create_directory($contextid, $component, $filearea, $itemid, $filepath, $userid = null) { global $DB; // validate all parameters, we do not want any rubbish stored in database, right? if (!is_number($contextid) or $contextid < 1) { throw new file_exception('storedfileproblem', 'Invalid contextid'); } $component = clean_param($component, PARAM_COMPONENT); if (empty($component)) { throw new file_exception('storedfileproblem', 'Invalid component'); } $filearea = clean_param($filearea, PARAM_AREA); if (empty($filearea)) { throw new file_exception('storedfileproblem', 'Invalid filearea'); } if (!is_number($itemid) or $itemid < 0) { throw new file_exception('storedfileproblem', 'Invalid itemid'); } $filepath = clean_param($filepath, PARAM_PATH); if (strpos($filepath, '/') !== 0 or strrpos($filepath, '/') !== strlen($filepath)-1) { // path must start and end with '/' throw new file_exception('storedfileproblem', 'Invalid file path'); } $pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, '.'); if ($dir_info = $this->get_file_by_hash($pathnamehash)) { return $dir_info; } static $contenthash = null; if (!$contenthash) { $this->add_string_to_pool(''); $contenthash = self::hash_from_string(''); } $now = time(); $dir_record = new stdClass(); $dir_record->contextid = $contextid; $dir_record->component = $component; $dir_record->filearea = $filearea; $dir_record->itemid = $itemid; $dir_record->filepath = $filepath; $dir_record->filename = '.'; $dir_record->contenthash = $contenthash; $dir_record->filesize = 0; $dir_record->timecreated = $now; $dir_record->timemodified = $now; $dir_record->mimetype = null; $dir_record->userid = $userid; $dir_record->pathnamehash = $pathnamehash; $DB->insert_record('files', $dir_record); $dir_info = $this->get_file_by_hash($pathnamehash); if ($filepath !== '/') { //recurse to parent dirs $filepath = trim($filepath, '/'); $filepath = explode('/', $filepath); array_pop($filepath); $filepath = implode('/', $filepath); $filepath = ($filepath === '') ? '/' : "/$filepath/"; $this->create_directory($contextid, $component, $filearea, $itemid, $filepath, $userid); } return $dir_info; }
php
public function create_directory($contextid, $component, $filearea, $itemid, $filepath, $userid = null) { global $DB; // validate all parameters, we do not want any rubbish stored in database, right? if (!is_number($contextid) or $contextid < 1) { throw new file_exception('storedfileproblem', 'Invalid contextid'); } $component = clean_param($component, PARAM_COMPONENT); if (empty($component)) { throw new file_exception('storedfileproblem', 'Invalid component'); } $filearea = clean_param($filearea, PARAM_AREA); if (empty($filearea)) { throw new file_exception('storedfileproblem', 'Invalid filearea'); } if (!is_number($itemid) or $itemid < 0) { throw new file_exception('storedfileproblem', 'Invalid itemid'); } $filepath = clean_param($filepath, PARAM_PATH); if (strpos($filepath, '/') !== 0 or strrpos($filepath, '/') !== strlen($filepath)-1) { // path must start and end with '/' throw new file_exception('storedfileproblem', 'Invalid file path'); } $pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, '.'); if ($dir_info = $this->get_file_by_hash($pathnamehash)) { return $dir_info; } static $contenthash = null; if (!$contenthash) { $this->add_string_to_pool(''); $contenthash = self::hash_from_string(''); } $now = time(); $dir_record = new stdClass(); $dir_record->contextid = $contextid; $dir_record->component = $component; $dir_record->filearea = $filearea; $dir_record->itemid = $itemid; $dir_record->filepath = $filepath; $dir_record->filename = '.'; $dir_record->contenthash = $contenthash; $dir_record->filesize = 0; $dir_record->timecreated = $now; $dir_record->timemodified = $now; $dir_record->mimetype = null; $dir_record->userid = $userid; $dir_record->pathnamehash = $pathnamehash; $DB->insert_record('files', $dir_record); $dir_info = $this->get_file_by_hash($pathnamehash); if ($filepath !== '/') { //recurse to parent dirs $filepath = trim($filepath, '/'); $filepath = explode('/', $filepath); array_pop($filepath); $filepath = implode('/', $filepath); $filepath = ($filepath === '') ? '/' : "/$filepath/"; $this->create_directory($contextid, $component, $filearea, $itemid, $filepath, $userid); } return $dir_info; }
[ "public", "function", "create_directory", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "userid", "=", "null", ")", "{", "global", "$", "DB", ";", "// validate all parameters, we do not want any rubbish stored in database, right?", "if", "(", "!", "is_number", "(", "$", "contextid", ")", "or", "$", "contextid", "<", "1", ")", "{", "throw", "new", "file_exception", "(", "'storedfileproblem'", ",", "'Invalid contextid'", ")", ";", "}", "$", "component", "=", "clean_param", "(", "$", "component", ",", "PARAM_COMPONENT", ")", ";", "if", "(", "empty", "(", "$", "component", ")", ")", "{", "throw", "new", "file_exception", "(", "'storedfileproblem'", ",", "'Invalid component'", ")", ";", "}", "$", "filearea", "=", "clean_param", "(", "$", "filearea", ",", "PARAM_AREA", ")", ";", "if", "(", "empty", "(", "$", "filearea", ")", ")", "{", "throw", "new", "file_exception", "(", "'storedfileproblem'", ",", "'Invalid filearea'", ")", ";", "}", "if", "(", "!", "is_number", "(", "$", "itemid", ")", "or", "$", "itemid", "<", "0", ")", "{", "throw", "new", "file_exception", "(", "'storedfileproblem'", ",", "'Invalid itemid'", ")", ";", "}", "$", "filepath", "=", "clean_param", "(", "$", "filepath", ",", "PARAM_PATH", ")", ";", "if", "(", "strpos", "(", "$", "filepath", ",", "'/'", ")", "!==", "0", "or", "strrpos", "(", "$", "filepath", ",", "'/'", ")", "!==", "strlen", "(", "$", "filepath", ")", "-", "1", ")", "{", "// path must start and end with '/'", "throw", "new", "file_exception", "(", "'storedfileproblem'", ",", "'Invalid file path'", ")", ";", "}", "$", "pathnamehash", "=", "$", "this", "->", "get_pathname_hash", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "'.'", ")", ";", "if", "(", "$", "dir_info", "=", "$", "this", "->", "get_file_by_hash", "(", "$", "pathnamehash", ")", ")", "{", "return", "$", "dir_info", ";", "}", "static", "$", "contenthash", "=", "null", ";", "if", "(", "!", "$", "contenthash", ")", "{", "$", "this", "->", "add_string_to_pool", "(", "''", ")", ";", "$", "contenthash", "=", "self", "::", "hash_from_string", "(", "''", ")", ";", "}", "$", "now", "=", "time", "(", ")", ";", "$", "dir_record", "=", "new", "stdClass", "(", ")", ";", "$", "dir_record", "->", "contextid", "=", "$", "contextid", ";", "$", "dir_record", "->", "component", "=", "$", "component", ";", "$", "dir_record", "->", "filearea", "=", "$", "filearea", ";", "$", "dir_record", "->", "itemid", "=", "$", "itemid", ";", "$", "dir_record", "->", "filepath", "=", "$", "filepath", ";", "$", "dir_record", "->", "filename", "=", "'.'", ";", "$", "dir_record", "->", "contenthash", "=", "$", "contenthash", ";", "$", "dir_record", "->", "filesize", "=", "0", ";", "$", "dir_record", "->", "timecreated", "=", "$", "now", ";", "$", "dir_record", "->", "timemodified", "=", "$", "now", ";", "$", "dir_record", "->", "mimetype", "=", "null", ";", "$", "dir_record", "->", "userid", "=", "$", "userid", ";", "$", "dir_record", "->", "pathnamehash", "=", "$", "pathnamehash", ";", "$", "DB", "->", "insert_record", "(", "'files'", ",", "$", "dir_record", ")", ";", "$", "dir_info", "=", "$", "this", "->", "get_file_by_hash", "(", "$", "pathnamehash", ")", ";", "if", "(", "$", "filepath", "!==", "'/'", ")", "{", "//recurse to parent dirs", "$", "filepath", "=", "trim", "(", "$", "filepath", ",", "'/'", ")", ";", "$", "filepath", "=", "explode", "(", "'/'", ",", "$", "filepath", ")", ";", "array_pop", "(", "$", "filepath", ")", ";", "$", "filepath", "=", "implode", "(", "'/'", ",", "$", "filepath", ")", ";", "$", "filepath", "=", "(", "$", "filepath", "===", "''", ")", "?", "'/'", ":", "\"/$filepath/\"", ";", "$", "this", "->", "create_directory", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "userid", ")", ";", "}", "return", "$", "dir_info", ";", "}" ]
Recursively creates directory. @param int $contextid context ID @param string $component component @param string $filearea file area @param int $itemid item ID @param string $filepath file path @param int $userid the user ID @return bool success
[ "Recursively", "creates", "directory", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L950-L1023
220,536
moodle/moodle
lib/filestorage/file_storage.php
file_storage.create_file
protected function create_file($newrecord) { global $DB; $newrecord->id = $DB->insert_record('files', $newrecord); if ($newrecord->filename !== '.') { // Callback for file created. if ($pluginsfunction = get_plugins_with_function('after_file_created')) { foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { $pluginfunction($newrecord); } } } } }
php
protected function create_file($newrecord) { global $DB; $newrecord->id = $DB->insert_record('files', $newrecord); if ($newrecord->filename !== '.') { // Callback for file created. if ($pluginsfunction = get_plugins_with_function('after_file_created')) { foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { $pluginfunction($newrecord); } } } } }
[ "protected", "function", "create_file", "(", "$", "newrecord", ")", "{", "global", "$", "DB", ";", "$", "newrecord", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'files'", ",", "$", "newrecord", ")", ";", "if", "(", "$", "newrecord", "->", "filename", "!==", "'.'", ")", "{", "// Callback for file created.", "if", "(", "$", "pluginsfunction", "=", "get_plugins_with_function", "(", "'after_file_created'", ")", ")", "{", "foreach", "(", "$", "pluginsfunction", "as", "$", "plugintype", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "pluginfunction", ")", "{", "$", "pluginfunction", "(", "$", "newrecord", ")", ";", "}", "}", "}", "}", "}" ]
Add new file record to database and handle callbacks. @param stdClass $newrecord
[ "Add", "new", "file", "record", "to", "database", "and", "handle", "callbacks", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L1030-L1044
220,537
moodle/moodle
lib/filestorage/file_storage.php
file_storage.synchronise_stored_file_from_file
public function synchronise_stored_file_from_file(stored_file $file, $path, $filerecord) { list($contenthash, $filesize) = $this->add_file_to_pool($path, null, $filerecord); $file->set_synchronized($contenthash, $filesize); }
php
public function synchronise_stored_file_from_file(stored_file $file, $path, $filerecord) { list($contenthash, $filesize) = $this->add_file_to_pool($path, null, $filerecord); $file->set_synchronized($contenthash, $filesize); }
[ "public", "function", "synchronise_stored_file_from_file", "(", "stored_file", "$", "file", ",", "$", "path", ",", "$", "filerecord", ")", "{", "list", "(", "$", "contenthash", ",", "$", "filesize", ")", "=", "$", "this", "->", "add_file_to_pool", "(", "$", "path", ",", "null", ",", "$", "filerecord", ")", ";", "$", "file", "->", "set_synchronized", "(", "$", "contenthash", ",", "$", "filesize", ")", ";", "}" ]
Synchronise stored file from file. @param stored_file $file Stored file to synchronise. @param string $path Path to the file to synchronise from. @param stdClass $filerecord The file record from the database.
[ "Synchronise", "stored", "file", "from", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L1468-L1471
220,538
moodle/moodle
lib/filestorage/file_storage.php
file_storage.synchronise_stored_file_from_string
public function synchronise_stored_file_from_string(stored_file $file, $content, $filerecord) { list($contenthash, $filesize) = $this->add_string_to_pool($content, $filerecord); $file->set_synchronized($contenthash, $filesize); }
php
public function synchronise_stored_file_from_string(stored_file $file, $content, $filerecord) { list($contenthash, $filesize) = $this->add_string_to_pool($content, $filerecord); $file->set_synchronized($contenthash, $filesize); }
[ "public", "function", "synchronise_stored_file_from_string", "(", "stored_file", "$", "file", ",", "$", "content", ",", "$", "filerecord", ")", "{", "list", "(", "$", "contenthash", ",", "$", "filesize", ")", "=", "$", "this", "->", "add_string_to_pool", "(", "$", "content", ",", "$", "filerecord", ")", ";", "$", "file", "->", "set_synchronized", "(", "$", "contenthash", ",", "$", "filesize", ")", ";", "}" ]
Synchronise stored file from string. @param stored_file $file Stored file to synchronise. @param string $content File content. @param stdClass $filerecord The file record from the database.
[ "Synchronise", "stored", "file", "from", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L1480-L1483
220,539
moodle/moodle
lib/filestorage/file_storage.php
file_storage.add_file_to_pool
public function add_file_to_pool($pathname, $contenthash = null, $newrecord = null) { $this->call_before_file_created_plugin_functions($newrecord, $pathname); return $this->filesystem->add_file_from_path($pathname, $contenthash); }
php
public function add_file_to_pool($pathname, $contenthash = null, $newrecord = null) { $this->call_before_file_created_plugin_functions($newrecord, $pathname); return $this->filesystem->add_file_from_path($pathname, $contenthash); }
[ "public", "function", "add_file_to_pool", "(", "$", "pathname", ",", "$", "contenthash", "=", "null", ",", "$", "newrecord", "=", "null", ")", "{", "$", "this", "->", "call_before_file_created_plugin_functions", "(", "$", "newrecord", ",", "$", "pathname", ")", ";", "return", "$", "this", "->", "filesystem", "->", "add_file_from_path", "(", "$", "pathname", ",", "$", "contenthash", ")", ";", "}" ]
Add file content to sha1 pool. @param string $pathname path to file @param string|null $contenthash sha1 hash of content if known (performance only) @param stdClass|null $newrecord New file record @return array (contenthash, filesize, newfile)
[ "Add", "file", "content", "to", "sha1", "pool", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L1792-L1795
220,540
moodle/moodle
lib/filestorage/file_storage.php
file_storage.add_string_to_pool
public function add_string_to_pool($content, $newrecord = null) { $this->call_before_file_created_plugin_functions($newrecord, null, $content); return $this->filesystem->add_file_from_string($content); }
php
public function add_string_to_pool($content, $newrecord = null) { $this->call_before_file_created_plugin_functions($newrecord, null, $content); return $this->filesystem->add_file_from_string($content); }
[ "public", "function", "add_string_to_pool", "(", "$", "content", ",", "$", "newrecord", "=", "null", ")", "{", "$", "this", "->", "call_before_file_created_plugin_functions", "(", "$", "newrecord", ",", "null", ",", "$", "content", ")", ";", "return", "$", "this", "->", "filesystem", "->", "add_file_from_string", "(", "$", "content", ")", ";", "}" ]
Add string content to sha1 pool. @param string $content file content - binary string @return array (contenthash, filesize, newfile)
[ "Add", "string", "content", "to", "sha1", "pool", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L1803-L1806
220,541
moodle/moodle
lib/filestorage/file_storage.php
file_storage.call_before_file_created_plugin_functions
protected function call_before_file_created_plugin_functions($newrecord, $pathname = null, $content = null) { $pluginsfunction = get_plugins_with_function('before_file_created'); foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { $pluginfunction($newrecord, ['pathname' => $pathname, 'content' => $content]); } } }
php
protected function call_before_file_created_plugin_functions($newrecord, $pathname = null, $content = null) { $pluginsfunction = get_plugins_with_function('before_file_created'); foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { $pluginfunction($newrecord, ['pathname' => $pathname, 'content' => $content]); } } }
[ "protected", "function", "call_before_file_created_plugin_functions", "(", "$", "newrecord", ",", "$", "pathname", "=", "null", ",", "$", "content", "=", "null", ")", "{", "$", "pluginsfunction", "=", "get_plugins_with_function", "(", "'before_file_created'", ")", ";", "foreach", "(", "$", "pluginsfunction", "as", "$", "plugintype", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "pluginfunction", ")", "{", "$", "pluginfunction", "(", "$", "newrecord", ",", "[", "'pathname'", "=>", "$", "pathname", ",", "'content'", "=>", "$", "content", "]", ")", ";", "}", "}", "}" ]
before_file_created hook. @param stdClass|null $newrecord New file record. @param string|null $pathname Path to file. @param string|null $content File content.
[ "before_file_created", "hook", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L1815-L1822
220,542
moodle/moodle
lib/filestorage/file_storage.php
file_storage.pack_reference
public static function pack_reference($params) { $params = (array)$params; $reference = array(); $reference['contextid'] = is_null($params['contextid']) ? null : clean_param($params['contextid'], PARAM_INT); $reference['component'] = is_null($params['component']) ? null : clean_param($params['component'], PARAM_COMPONENT); $reference['itemid'] = is_null($params['itemid']) ? null : clean_param($params['itemid'], PARAM_INT); $reference['filearea'] = is_null($params['filearea']) ? null : clean_param($params['filearea'], PARAM_AREA); $reference['filepath'] = is_null($params['filepath']) ? null : clean_param($params['filepath'], PARAM_PATH); $reference['filename'] = is_null($params['filename']) ? null : clean_param($params['filename'], PARAM_FILE); return base64_encode(serialize($reference)); }
php
public static function pack_reference($params) { $params = (array)$params; $reference = array(); $reference['contextid'] = is_null($params['contextid']) ? null : clean_param($params['contextid'], PARAM_INT); $reference['component'] = is_null($params['component']) ? null : clean_param($params['component'], PARAM_COMPONENT); $reference['itemid'] = is_null($params['itemid']) ? null : clean_param($params['itemid'], PARAM_INT); $reference['filearea'] = is_null($params['filearea']) ? null : clean_param($params['filearea'], PARAM_AREA); $reference['filepath'] = is_null($params['filepath']) ? null : clean_param($params['filepath'], PARAM_PATH); $reference['filename'] = is_null($params['filename']) ? null : clean_param($params['filename'], PARAM_FILE); return base64_encode(serialize($reference)); }
[ "public", "static", "function", "pack_reference", "(", "$", "params", ")", "{", "$", "params", "=", "(", "array", ")", "$", "params", ";", "$", "reference", "=", "array", "(", ")", ";", "$", "reference", "[", "'contextid'", "]", "=", "is_null", "(", "$", "params", "[", "'contextid'", "]", ")", "?", "null", ":", "clean_param", "(", "$", "params", "[", "'contextid'", "]", ",", "PARAM_INT", ")", ";", "$", "reference", "[", "'component'", "]", "=", "is_null", "(", "$", "params", "[", "'component'", "]", ")", "?", "null", ":", "clean_param", "(", "$", "params", "[", "'component'", "]", ",", "PARAM_COMPONENT", ")", ";", "$", "reference", "[", "'itemid'", "]", "=", "is_null", "(", "$", "params", "[", "'itemid'", "]", ")", "?", "null", ":", "clean_param", "(", "$", "params", "[", "'itemid'", "]", ",", "PARAM_INT", ")", ";", "$", "reference", "[", "'filearea'", "]", "=", "is_null", "(", "$", "params", "[", "'filearea'", "]", ")", "?", "null", ":", "clean_param", "(", "$", "params", "[", "'filearea'", "]", ",", "PARAM_AREA", ")", ";", "$", "reference", "[", "'filepath'", "]", "=", "is_null", "(", "$", "params", "[", "'filepath'", "]", ")", "?", "null", ":", "clean_param", "(", "$", "params", "[", "'filepath'", "]", ",", "PARAM_PATH", ")", ";", "$", "reference", "[", "'filename'", "]", "=", "is_null", "(", "$", "params", "[", "'filename'", "]", ")", "?", "null", ":", "clean_param", "(", "$", "params", "[", "'filename'", "]", ",", "PARAM_FILE", ")", ";", "return", "base64_encode", "(", "serialize", "(", "$", "reference", ")", ")", ";", "}" ]
When user referring to a moodle file, we build the reference field @param array $params @return string
[ "When", "user", "referring", "to", "a", "moodle", "file", "we", "build", "the", "reference", "field" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L1868-L1878
220,543
moodle/moodle
lib/filestorage/file_storage.php
file_storage.unpack_reference
public static function unpack_reference($str, $cleanparams = false) { $decoded = base64_decode($str, true); if ($decoded === false) { throw new file_reference_exception(null, $str, null, null, 'Invalid base64 format'); } $params = @unserialize($decoded); // hide E_NOTICE if ($params === false) { throw new file_reference_exception(null, $decoded, null, null, 'Not an unserializeable value'); } if (is_array($params) && $cleanparams) { $params = array( 'component' => is_null($params['component']) ? '' : clean_param($params['component'], PARAM_COMPONENT), 'filearea' => is_null($params['filearea']) ? '' : clean_param($params['filearea'], PARAM_AREA), 'itemid' => is_null($params['itemid']) ? 0 : clean_param($params['itemid'], PARAM_INT), 'filename' => is_null($params['filename']) ? null : clean_param($params['filename'], PARAM_FILE), 'filepath' => is_null($params['filepath']) ? null : clean_param($params['filepath'], PARAM_PATH), 'contextid' => is_null($params['contextid']) ? null : clean_param($params['contextid'], PARAM_INT) ); } return $params; }
php
public static function unpack_reference($str, $cleanparams = false) { $decoded = base64_decode($str, true); if ($decoded === false) { throw new file_reference_exception(null, $str, null, null, 'Invalid base64 format'); } $params = @unserialize($decoded); // hide E_NOTICE if ($params === false) { throw new file_reference_exception(null, $decoded, null, null, 'Not an unserializeable value'); } if (is_array($params) && $cleanparams) { $params = array( 'component' => is_null($params['component']) ? '' : clean_param($params['component'], PARAM_COMPONENT), 'filearea' => is_null($params['filearea']) ? '' : clean_param($params['filearea'], PARAM_AREA), 'itemid' => is_null($params['itemid']) ? 0 : clean_param($params['itemid'], PARAM_INT), 'filename' => is_null($params['filename']) ? null : clean_param($params['filename'], PARAM_FILE), 'filepath' => is_null($params['filepath']) ? null : clean_param($params['filepath'], PARAM_PATH), 'contextid' => is_null($params['contextid']) ? null : clean_param($params['contextid'], PARAM_INT) ); } return $params; }
[ "public", "static", "function", "unpack_reference", "(", "$", "str", ",", "$", "cleanparams", "=", "false", ")", "{", "$", "decoded", "=", "base64_decode", "(", "$", "str", ",", "true", ")", ";", "if", "(", "$", "decoded", "===", "false", ")", "{", "throw", "new", "file_reference_exception", "(", "null", ",", "$", "str", ",", "null", ",", "null", ",", "'Invalid base64 format'", ")", ";", "}", "$", "params", "=", "@", "unserialize", "(", "$", "decoded", ")", ";", "// hide E_NOTICE", "if", "(", "$", "params", "===", "false", ")", "{", "throw", "new", "file_reference_exception", "(", "null", ",", "$", "decoded", ",", "null", ",", "null", ",", "'Not an unserializeable value'", ")", ";", "}", "if", "(", "is_array", "(", "$", "params", ")", "&&", "$", "cleanparams", ")", "{", "$", "params", "=", "array", "(", "'component'", "=>", "is_null", "(", "$", "params", "[", "'component'", "]", ")", "?", "''", ":", "clean_param", "(", "$", "params", "[", "'component'", "]", ",", "PARAM_COMPONENT", ")", ",", "'filearea'", "=>", "is_null", "(", "$", "params", "[", "'filearea'", "]", ")", "?", "''", ":", "clean_param", "(", "$", "params", "[", "'filearea'", "]", ",", "PARAM_AREA", ")", ",", "'itemid'", "=>", "is_null", "(", "$", "params", "[", "'itemid'", "]", ")", "?", "0", ":", "clean_param", "(", "$", "params", "[", "'itemid'", "]", ",", "PARAM_INT", ")", ",", "'filename'", "=>", "is_null", "(", "$", "params", "[", "'filename'", "]", ")", "?", "null", ":", "clean_param", "(", "$", "params", "[", "'filename'", "]", ",", "PARAM_FILE", ")", ",", "'filepath'", "=>", "is_null", "(", "$", "params", "[", "'filepath'", "]", ")", "?", "null", ":", "clean_param", "(", "$", "params", "[", "'filepath'", "]", ",", "PARAM_PATH", ")", ",", "'contextid'", "=>", "is_null", "(", "$", "params", "[", "'contextid'", "]", ")", "?", "null", ":", "clean_param", "(", "$", "params", "[", "'contextid'", "]", ",", "PARAM_INT", ")", ")", ";", "}", "return", "$", "params", ";", "}" ]
Unpack reference field @param string $str @param bool $cleanparams if set to true, array elements will be passed through {@link clean_param()} @throws file_reference_exception if the $str does not have the expected format @return array
[ "Unpack", "reference", "field" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L1888-L1908
220,544
moodle/moodle
lib/filestorage/file_storage.php
file_storage.search_server_files
public function search_server_files($query, $from = 0, $limit = 20, $count = false) { global $DB; $params = array( 'contextlevel' => CONTEXT_USER, 'directory' => '.', 'query' => $query ); if ($count) { $select = 'COUNT(1)'; } else { $select = self::instance_sql_fields('f', 'r'); } $like = $DB->sql_like('f.filename', ':query', false); $sql = "SELECT $select FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id JOIN {context} c ON f.contextid = c.id WHERE c.contextlevel <> :contextlevel AND f.filename <> :directory AND " . $like . ""; if ($count) { return $DB->count_records_sql($sql, $params); } $sql .= " ORDER BY f.filename"; $result = array(); $filerecords = $DB->get_recordset_sql($sql, $params, $from, $limit); foreach ($filerecords as $filerecord) { $result[$filerecord->pathnamehash] = $this->get_file_instance($filerecord); } $filerecords->close(); return $result; }
php
public function search_server_files($query, $from = 0, $limit = 20, $count = false) { global $DB; $params = array( 'contextlevel' => CONTEXT_USER, 'directory' => '.', 'query' => $query ); if ($count) { $select = 'COUNT(1)'; } else { $select = self::instance_sql_fields('f', 'r'); } $like = $DB->sql_like('f.filename', ':query', false); $sql = "SELECT $select FROM {files} f LEFT JOIN {files_reference} r ON f.referencefileid = r.id JOIN {context} c ON f.contextid = c.id WHERE c.contextlevel <> :contextlevel AND f.filename <> :directory AND " . $like . ""; if ($count) { return $DB->count_records_sql($sql, $params); } $sql .= " ORDER BY f.filename"; $result = array(); $filerecords = $DB->get_recordset_sql($sql, $params, $from, $limit); foreach ($filerecords as $filerecord) { $result[$filerecord->pathnamehash] = $this->get_file_instance($filerecord); } $filerecords->close(); return $result; }
[ "public", "function", "search_server_files", "(", "$", "query", ",", "$", "from", "=", "0", ",", "$", "limit", "=", "20", ",", "$", "count", "=", "false", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'contextlevel'", "=>", "CONTEXT_USER", ",", "'directory'", "=>", "'.'", ",", "'query'", "=>", "$", "query", ")", ";", "if", "(", "$", "count", ")", "{", "$", "select", "=", "'COUNT(1)'", ";", "}", "else", "{", "$", "select", "=", "self", "::", "instance_sql_fields", "(", "'f'", ",", "'r'", ")", ";", "}", "$", "like", "=", "$", "DB", "->", "sql_like", "(", "'f.filename'", ",", "':query'", ",", "false", ")", ";", "$", "sql", "=", "\"SELECT $select\n FROM {files} f\n LEFT JOIN {files_reference} r\n ON f.referencefileid = r.id\n JOIN {context} c\n ON f.contextid = c.id\n WHERE c.contextlevel <> :contextlevel\n AND f.filename <> :directory\n AND \"", ".", "$", "like", ".", "\"\"", ";", "if", "(", "$", "count", ")", "{", "return", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}", "$", "sql", ".=", "\" ORDER BY f.filename\"", ";", "$", "result", "=", "array", "(", ")", ";", "$", "filerecords", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ",", "$", "from", ",", "$", "limit", ")", ";", "foreach", "(", "$", "filerecords", "as", "$", "filerecord", ")", "{", "$", "result", "[", "$", "filerecord", "->", "pathnamehash", "]", "=", "$", "this", "->", "get_file_instance", "(", "$", "filerecord", ")", ";", "}", "$", "filerecords", "->", "close", "(", ")", ";", "return", "$", "result", ";", "}" ]
Search through the server files. The query parameter will be used in conjuction with the SQL directive LIKE, so include '%' in it if you need to. This search will always ignore user files and directories. Note that the search is case insensitive. This query can quickly become inefficient so use it sparignly. @param string $query The string used with SQL LIKE. @param integer $from The offset to start the search at. @param integer $limit The maximum number of results. @param boolean $count When true this methods returns the number of results availabe, disregarding the parameters $from and $limit. @return int|array Integer when count, otherwise array of stored_file objects.
[ "Search", "through", "the", "server", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L1926-L1965
220,545
moodle/moodle
lib/filestorage/file_storage.php
file_storage.search_references
public function search_references($reference) { global $DB; if (is_null($reference)) { throw new coding_exception('NULL is not a valid reference to an external file'); } // Give {@link self::unpack_reference()} a chance to throw exception if the // reference is not in a valid format. self::unpack_reference($reference); $referencehash = sha1($reference); $sql = "SELECT ".self::instance_sql_fields('f', 'r')." FROM {files} f JOIN {files_reference} r ON f.referencefileid = r.id JOIN {repository_instances} ri ON r.repositoryid = ri.id WHERE r.referencehash = ? AND (f.component <> ? OR f.filearea <> ?)"; $rs = $DB->get_recordset_sql($sql, array($referencehash, 'user', 'draft')); $files = array(); foreach ($rs as $filerecord) { $files[$filerecord->pathnamehash] = $this->get_file_instance($filerecord); } $rs->close(); return $files; }
php
public function search_references($reference) { global $DB; if (is_null($reference)) { throw new coding_exception('NULL is not a valid reference to an external file'); } // Give {@link self::unpack_reference()} a chance to throw exception if the // reference is not in a valid format. self::unpack_reference($reference); $referencehash = sha1($reference); $sql = "SELECT ".self::instance_sql_fields('f', 'r')." FROM {files} f JOIN {files_reference} r ON f.referencefileid = r.id JOIN {repository_instances} ri ON r.repositoryid = ri.id WHERE r.referencehash = ? AND (f.component <> ? OR f.filearea <> ?)"; $rs = $DB->get_recordset_sql($sql, array($referencehash, 'user', 'draft')); $files = array(); foreach ($rs as $filerecord) { $files[$filerecord->pathnamehash] = $this->get_file_instance($filerecord); } $rs->close(); return $files; }
[ "public", "function", "search_references", "(", "$", "reference", ")", "{", "global", "$", "DB", ";", "if", "(", "is_null", "(", "$", "reference", ")", ")", "{", "throw", "new", "coding_exception", "(", "'NULL is not a valid reference to an external file'", ")", ";", "}", "// Give {@link self::unpack_reference()} a chance to throw exception if the", "// reference is not in a valid format.", "self", "::", "unpack_reference", "(", "$", "reference", ")", ";", "$", "referencehash", "=", "sha1", "(", "$", "reference", ")", ";", "$", "sql", "=", "\"SELECT \"", ".", "self", "::", "instance_sql_fields", "(", "'f'", ",", "'r'", ")", ".", "\"\n FROM {files} f\n JOIN {files_reference} r ON f.referencefileid = r.id\n JOIN {repository_instances} ri ON r.repositoryid = ri.id\n WHERE r.referencehash = ?\n AND (f.component <> ? OR f.filearea <> ?)\"", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "array", "(", "$", "referencehash", ",", "'user'", ",", "'draft'", ")", ")", ";", "$", "files", "=", "array", "(", ")", ";", "foreach", "(", "$", "rs", "as", "$", "filerecord", ")", "{", "$", "files", "[", "$", "filerecord", "->", "pathnamehash", "]", "=", "$", "this", "->", "get_file_instance", "(", "$", "filerecord", ")", ";", "}", "$", "rs", "->", "close", "(", ")", ";", "return", "$", "files", ";", "}" ]
Returns all aliases that refer to some stored_file via the given reference All repositories that provide access to a stored_file are expected to use {@link self::pack_reference()}. This method can't be used if the given reference does not use this format or if you are looking for references to an external file (for example it can't be used to search for all aliases that refer to a given Dropbox or Box.net file). Aliases in user draft areas are excluded from the returned list. @param string $reference identification of the referenced file @return array of stored_file indexed by its pathnamehash
[ "Returns", "all", "aliases", "that", "refer", "to", "some", "stored_file", "via", "the", "given", "reference" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L1981-L2009
220,546
moodle/moodle
lib/filestorage/file_storage.php
file_storage.search_references_count
public function search_references_count($reference) { global $DB; if (is_null($reference)) { throw new coding_exception('NULL is not a valid reference to an external file'); } // Give {@link self::unpack_reference()} a chance to throw exception if the // reference is not in a valid format. self::unpack_reference($reference); $referencehash = sha1($reference); $sql = "SELECT COUNT(f.id) FROM {files} f JOIN {files_reference} r ON f.referencefileid = r.id JOIN {repository_instances} ri ON r.repositoryid = ri.id WHERE r.referencehash = ? AND (f.component <> ? OR f.filearea <> ?)"; return (int)$DB->count_records_sql($sql, array($referencehash, 'user', 'draft')); }
php
public function search_references_count($reference) { global $DB; if (is_null($reference)) { throw new coding_exception('NULL is not a valid reference to an external file'); } // Give {@link self::unpack_reference()} a chance to throw exception if the // reference is not in a valid format. self::unpack_reference($reference); $referencehash = sha1($reference); $sql = "SELECT COUNT(f.id) FROM {files} f JOIN {files_reference} r ON f.referencefileid = r.id JOIN {repository_instances} ri ON r.repositoryid = ri.id WHERE r.referencehash = ? AND (f.component <> ? OR f.filearea <> ?)"; return (int)$DB->count_records_sql($sql, array($referencehash, 'user', 'draft')); }
[ "public", "function", "search_references_count", "(", "$", "reference", ")", "{", "global", "$", "DB", ";", "if", "(", "is_null", "(", "$", "reference", ")", ")", "{", "throw", "new", "coding_exception", "(", "'NULL is not a valid reference to an external file'", ")", ";", "}", "// Give {@link self::unpack_reference()} a chance to throw exception if the", "// reference is not in a valid format.", "self", "::", "unpack_reference", "(", "$", "reference", ")", ";", "$", "referencehash", "=", "sha1", "(", "$", "reference", ")", ";", "$", "sql", "=", "\"SELECT COUNT(f.id)\n FROM {files} f\n JOIN {files_reference} r ON f.referencefileid = r.id\n JOIN {repository_instances} ri ON r.repositoryid = ri.id\n WHERE r.referencehash = ?\n AND (f.component <> ? OR f.filearea <> ?)\"", ";", "return", "(", "int", ")", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "array", "(", "$", "referencehash", ",", "'user'", ",", "'draft'", ")", ")", ";", "}" ]
Returns the number of aliases that refer to some stored_file via the given reference All repositories that provide access to a stored_file are expected to use {@link self::pack_reference()}. This method can't be used if the given reference does not use this format or if you are looking for references to an external file (for example it can't be used to count aliases that refer to a given Dropbox or Box.net file). Aliases in user draft areas are not counted. @param string $reference identification of the referenced file @return int
[ "Returns", "the", "number", "of", "aliases", "that", "refer", "to", "some", "stored_file", "via", "the", "given", "reference" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L2025-L2046
220,547
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_references_by_storedfile
public function get_references_by_storedfile(stored_file $storedfile) { global $DB; $params = array(); $params['contextid'] = $storedfile->get_contextid(); $params['component'] = $storedfile->get_component(); $params['filearea'] = $storedfile->get_filearea(); $params['itemid'] = $storedfile->get_itemid(); $params['filename'] = $storedfile->get_filename(); $params['filepath'] = $storedfile->get_filepath(); return $this->search_references(self::pack_reference($params)); }
php
public function get_references_by_storedfile(stored_file $storedfile) { global $DB; $params = array(); $params['contextid'] = $storedfile->get_contextid(); $params['component'] = $storedfile->get_component(); $params['filearea'] = $storedfile->get_filearea(); $params['itemid'] = $storedfile->get_itemid(); $params['filename'] = $storedfile->get_filename(); $params['filepath'] = $storedfile->get_filepath(); return $this->search_references(self::pack_reference($params)); }
[ "public", "function", "get_references_by_storedfile", "(", "stored_file", "$", "storedfile", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", ")", ";", "$", "params", "[", "'contextid'", "]", "=", "$", "storedfile", "->", "get_contextid", "(", ")", ";", "$", "params", "[", "'component'", "]", "=", "$", "storedfile", "->", "get_component", "(", ")", ";", "$", "params", "[", "'filearea'", "]", "=", "$", "storedfile", "->", "get_filearea", "(", ")", ";", "$", "params", "[", "'itemid'", "]", "=", "$", "storedfile", "->", "get_itemid", "(", ")", ";", "$", "params", "[", "'filename'", "]", "=", "$", "storedfile", "->", "get_filename", "(", ")", ";", "$", "params", "[", "'filepath'", "]", "=", "$", "storedfile", "->", "get_filepath", "(", ")", ";", "return", "$", "this", "->", "search_references", "(", "self", "::", "pack_reference", "(", "$", "params", ")", ")", ";", "}" ]
Returns all aliases that link to the given stored_file Aliases in user draft areas are excluded from the returned list. @param stored_file $storedfile @return array of stored_file
[ "Returns", "all", "aliases", "that", "link", "to", "the", "given", "stored_file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L2056-L2068
220,548
moodle/moodle
lib/filestorage/file_storage.php
file_storage.get_references_count_by_storedfile
public function get_references_count_by_storedfile(stored_file $storedfile) { global $DB; $params = array(); $params['contextid'] = $storedfile->get_contextid(); $params['component'] = $storedfile->get_component(); $params['filearea'] = $storedfile->get_filearea(); $params['itemid'] = $storedfile->get_itemid(); $params['filename'] = $storedfile->get_filename(); $params['filepath'] = $storedfile->get_filepath(); return $this->search_references_count(self::pack_reference($params)); }
php
public function get_references_count_by_storedfile(stored_file $storedfile) { global $DB; $params = array(); $params['contextid'] = $storedfile->get_contextid(); $params['component'] = $storedfile->get_component(); $params['filearea'] = $storedfile->get_filearea(); $params['itemid'] = $storedfile->get_itemid(); $params['filename'] = $storedfile->get_filename(); $params['filepath'] = $storedfile->get_filepath(); return $this->search_references_count(self::pack_reference($params)); }
[ "public", "function", "get_references_count_by_storedfile", "(", "stored_file", "$", "storedfile", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", ")", ";", "$", "params", "[", "'contextid'", "]", "=", "$", "storedfile", "->", "get_contextid", "(", ")", ";", "$", "params", "[", "'component'", "]", "=", "$", "storedfile", "->", "get_component", "(", ")", ";", "$", "params", "[", "'filearea'", "]", "=", "$", "storedfile", "->", "get_filearea", "(", ")", ";", "$", "params", "[", "'itemid'", "]", "=", "$", "storedfile", "->", "get_itemid", "(", ")", ";", "$", "params", "[", "'filename'", "]", "=", "$", "storedfile", "->", "get_filename", "(", ")", ";", "$", "params", "[", "'filepath'", "]", "=", "$", "storedfile", "->", "get_filepath", "(", ")", ";", "return", "$", "this", "->", "search_references_count", "(", "self", "::", "pack_reference", "(", "$", "params", ")", ")", ";", "}" ]
Returns the number of aliases that link to the given stored_file Aliases in user draft areas are not counted. @param stored_file $storedfile @return int
[ "Returns", "the", "number", "of", "aliases", "that", "link", "to", "the", "given", "stored_file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L2078-L2090
220,549
moodle/moodle
lib/filestorage/file_storage.php
file_storage.update_references_to_storedfile
public function update_references_to_storedfile(stored_file $storedfile) { global $CFG, $DB; $params = array(); $params['contextid'] = $storedfile->get_contextid(); $params['component'] = $storedfile->get_component(); $params['filearea'] = $storedfile->get_filearea(); $params['itemid'] = $storedfile->get_itemid(); $params['filename'] = $storedfile->get_filename(); $params['filepath'] = $storedfile->get_filepath(); $reference = self::pack_reference($params); $referencehash = sha1($reference); $sql = "SELECT repositoryid, id FROM {files_reference} WHERE referencehash = ?"; $rs = $DB->get_recordset_sql($sql, array($referencehash)); $now = time(); foreach ($rs as $record) { $this->update_references($record->id, $now, null, $storedfile->get_contenthash(), $storedfile->get_filesize(), 0, $storedfile->get_timemodified()); } $rs->close(); }
php
public function update_references_to_storedfile(stored_file $storedfile) { global $CFG, $DB; $params = array(); $params['contextid'] = $storedfile->get_contextid(); $params['component'] = $storedfile->get_component(); $params['filearea'] = $storedfile->get_filearea(); $params['itemid'] = $storedfile->get_itemid(); $params['filename'] = $storedfile->get_filename(); $params['filepath'] = $storedfile->get_filepath(); $reference = self::pack_reference($params); $referencehash = sha1($reference); $sql = "SELECT repositoryid, id FROM {files_reference} WHERE referencehash = ?"; $rs = $DB->get_recordset_sql($sql, array($referencehash)); $now = time(); foreach ($rs as $record) { $this->update_references($record->id, $now, null, $storedfile->get_contenthash(), $storedfile->get_filesize(), 0, $storedfile->get_timemodified()); } $rs->close(); }
[ "public", "function", "update_references_to_storedfile", "(", "stored_file", "$", "storedfile", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "params", "=", "array", "(", ")", ";", "$", "params", "[", "'contextid'", "]", "=", "$", "storedfile", "->", "get_contextid", "(", ")", ";", "$", "params", "[", "'component'", "]", "=", "$", "storedfile", "->", "get_component", "(", ")", ";", "$", "params", "[", "'filearea'", "]", "=", "$", "storedfile", "->", "get_filearea", "(", ")", ";", "$", "params", "[", "'itemid'", "]", "=", "$", "storedfile", "->", "get_itemid", "(", ")", ";", "$", "params", "[", "'filename'", "]", "=", "$", "storedfile", "->", "get_filename", "(", ")", ";", "$", "params", "[", "'filepath'", "]", "=", "$", "storedfile", "->", "get_filepath", "(", ")", ";", "$", "reference", "=", "self", "::", "pack_reference", "(", "$", "params", ")", ";", "$", "referencehash", "=", "sha1", "(", "$", "reference", ")", ";", "$", "sql", "=", "\"SELECT repositoryid, id FROM {files_reference}\n WHERE referencehash = ?\"", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "array", "(", "$", "referencehash", ")", ")", ";", "$", "now", "=", "time", "(", ")", ";", "foreach", "(", "$", "rs", "as", "$", "record", ")", "{", "$", "this", "->", "update_references", "(", "$", "record", "->", "id", ",", "$", "now", ",", "null", ",", "$", "storedfile", "->", "get_contenthash", "(", ")", ",", "$", "storedfile", "->", "get_filesize", "(", ")", ",", "0", ",", "$", "storedfile", "->", "get_timemodified", "(", ")", ")", ";", "}", "$", "rs", "->", "close", "(", ")", ";", "}" ]
Updates all files that are referencing this file with the new contenthash and filesize @param stored_file $storedfile
[ "Updates", "all", "files", "that", "are", "referencing", "this", "file", "with", "the", "new", "contenthash", "and", "filesize" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L2098-L2120
220,550
moodle/moodle
lib/filestorage/file_storage.php
file_storage.import_external_file
public function import_external_file(stored_file $storedfile, $maxbytes = 0) { global $CFG; $storedfile->import_external_file_contents($maxbytes); $storedfile->delete_reference(); return $storedfile; }
php
public function import_external_file(stored_file $storedfile, $maxbytes = 0) { global $CFG; $storedfile->import_external_file_contents($maxbytes); $storedfile->delete_reference(); return $storedfile; }
[ "public", "function", "import_external_file", "(", "stored_file", "$", "storedfile", ",", "$", "maxbytes", "=", "0", ")", "{", "global", "$", "CFG", ";", "$", "storedfile", "->", "import_external_file_contents", "(", "$", "maxbytes", ")", ";", "$", "storedfile", "->", "delete_reference", "(", ")", ";", "return", "$", "storedfile", ";", "}" ]
Convert file alias to local file @throws moodle_exception if file could not be downloaded @param stored_file $storedfile a stored_file instances @param int $maxbytes throw an exception if file size is bigger than $maxbytes (0 means no limit) @return stored_file stored_file
[ "Convert", "file", "alias", "to", "local", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L2131-L2136
220,551
moodle/moodle
lib/filestorage/file_storage.php
file_storage.mimetype
public static function mimetype($fullpath, $filename = null) { if (empty($filename)) { $filename = $fullpath; } // The mimeinfo function determines the mimetype purely based on the file extension. $type = mimeinfo('type', $filename); if ($type === 'document/unknown') { // The type is unknown. Inspect the file now. $type = self::mimetype_from_file($fullpath); } return $type; }
php
public static function mimetype($fullpath, $filename = null) { if (empty($filename)) { $filename = $fullpath; } // The mimeinfo function determines the mimetype purely based on the file extension. $type = mimeinfo('type', $filename); if ($type === 'document/unknown') { // The type is unknown. Inspect the file now. $type = self::mimetype_from_file($fullpath); } return $type; }
[ "public", "static", "function", "mimetype", "(", "$", "fullpath", ",", "$", "filename", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "filename", ")", ")", "{", "$", "filename", "=", "$", "fullpath", ";", "}", "// The mimeinfo function determines the mimetype purely based on the file extension.", "$", "type", "=", "mimeinfo", "(", "'type'", ",", "$", "filename", ")", ";", "if", "(", "$", "type", "===", "'document/unknown'", ")", "{", "// The type is unknown. Inspect the file now.", "$", "type", "=", "self", "::", "mimetype_from_file", "(", "$", "fullpath", ")", ";", "}", "return", "$", "type", ";", "}" ]
Return mimetype by given file pathname. If file has a known extension, we return the mimetype based on extension. Otherwise (when possible) we try to get the mimetype from file contents. @param string $fullpath Full path to the file on disk @param string $filename Correct file name with extension, if omitted will be taken from $path @return string
[ "Return", "mimetype", "by", "given", "file", "pathname", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L2148-L2161
220,552
moodle/moodle
lib/filestorage/file_storage.php
file_storage.mimetype_from_file
public static function mimetype_from_file($fullpath) { if (file_exists($fullpath)) { // The type is unknown. Attempt to look up the file type now. $finfo = new finfo(FILEINFO_MIME_TYPE); return mimeinfo_from_type('type', $finfo->file($fullpath)); } return 'document/unknown'; }
php
public static function mimetype_from_file($fullpath) { if (file_exists($fullpath)) { // The type is unknown. Attempt to look up the file type now. $finfo = new finfo(FILEINFO_MIME_TYPE); return mimeinfo_from_type('type', $finfo->file($fullpath)); } return 'document/unknown'; }
[ "public", "static", "function", "mimetype_from_file", "(", "$", "fullpath", ")", "{", "if", "(", "file_exists", "(", "$", "fullpath", ")", ")", "{", "// The type is unknown. Attempt to look up the file type now.", "$", "finfo", "=", "new", "finfo", "(", "FILEINFO_MIME_TYPE", ")", ";", "return", "mimeinfo_from_type", "(", "'type'", ",", "$", "finfo", "->", "file", "(", "$", "fullpath", ")", ")", ";", "}", "return", "'document/unknown'", ";", "}" ]
Inspect a file on disk for it's mimetype. @param string $fullpath Path to file on disk @return string The mimetype
[ "Inspect", "a", "file", "on", "disk", "for", "it", "s", "mimetype", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L2169-L2177
220,553
moodle/moodle
lib/filestorage/file_storage.php
file_storage.update_references
public function update_references($referencefileid, $lastsync, $lifetime, $contenthash, $filesize, $status, $timemodified = null) { global $DB; $referencefileid = clean_param($referencefileid, PARAM_INT); $lastsync = clean_param($lastsync, PARAM_INT); validate_param($contenthash, PARAM_TEXT, NULL_NOT_ALLOWED); $filesize = clean_param($filesize, PARAM_INT); $status = clean_param($status, PARAM_INT); $params = array('contenthash' => $contenthash, 'filesize' => $filesize, 'status' => $status, 'referencefileid' => $referencefileid, 'timemodified' => $timemodified); $DB->execute('UPDATE {files} SET contenthash = :contenthash, filesize = :filesize, status = :status ' . ($timemodified ? ', timemodified = :timemodified' : '') . ' WHERE referencefileid = :referencefileid', $params); $data = array('id' => $referencefileid, 'lastsync' => $lastsync); $DB->update_record('files_reference', (object)$data); }
php
public function update_references($referencefileid, $lastsync, $lifetime, $contenthash, $filesize, $status, $timemodified = null) { global $DB; $referencefileid = clean_param($referencefileid, PARAM_INT); $lastsync = clean_param($lastsync, PARAM_INT); validate_param($contenthash, PARAM_TEXT, NULL_NOT_ALLOWED); $filesize = clean_param($filesize, PARAM_INT); $status = clean_param($status, PARAM_INT); $params = array('contenthash' => $contenthash, 'filesize' => $filesize, 'status' => $status, 'referencefileid' => $referencefileid, 'timemodified' => $timemodified); $DB->execute('UPDATE {files} SET contenthash = :contenthash, filesize = :filesize, status = :status ' . ($timemodified ? ', timemodified = :timemodified' : '') . ' WHERE referencefileid = :referencefileid', $params); $data = array('id' => $referencefileid, 'lastsync' => $lastsync); $DB->update_record('files_reference', (object)$data); }
[ "public", "function", "update_references", "(", "$", "referencefileid", ",", "$", "lastsync", ",", "$", "lifetime", ",", "$", "contenthash", ",", "$", "filesize", ",", "$", "status", ",", "$", "timemodified", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "referencefileid", "=", "clean_param", "(", "$", "referencefileid", ",", "PARAM_INT", ")", ";", "$", "lastsync", "=", "clean_param", "(", "$", "lastsync", ",", "PARAM_INT", ")", ";", "validate_param", "(", "$", "contenthash", ",", "PARAM_TEXT", ",", "NULL_NOT_ALLOWED", ")", ";", "$", "filesize", "=", "clean_param", "(", "$", "filesize", ",", "PARAM_INT", ")", ";", "$", "status", "=", "clean_param", "(", "$", "status", ",", "PARAM_INT", ")", ";", "$", "params", "=", "array", "(", "'contenthash'", "=>", "$", "contenthash", ",", "'filesize'", "=>", "$", "filesize", ",", "'status'", "=>", "$", "status", ",", "'referencefileid'", "=>", "$", "referencefileid", ",", "'timemodified'", "=>", "$", "timemodified", ")", ";", "$", "DB", "->", "execute", "(", "'UPDATE {files} SET contenthash = :contenthash, filesize = :filesize,\n status = :status '", ".", "(", "$", "timemodified", "?", "', timemodified = :timemodified'", ":", "''", ")", ".", "'\n WHERE referencefileid = :referencefileid'", ",", "$", "params", ")", ";", "$", "data", "=", "array", "(", "'id'", "=>", "$", "referencefileid", ",", "'lastsync'", "=>", "$", "lastsync", ")", ";", "$", "DB", "->", "update_record", "(", "'files_reference'", ",", "(", "object", ")", "$", "data", ")", ";", "}" ]
Updates a reference to the external resource and all files that use it This function is called after synchronisation of an external file and updates the contenthash, filesize and status of all files that reference this external file as well as time last synchronised. @param int $referencefileid @param int $lastsync @param int $lifetime argument not used any more, liefetime is returned by repository @param string $contenthash @param int $filesize @param int $status 0 if ok or 666 if source is missing @param int $timemodified last time modified of the source, if known
[ "Updates", "a", "reference", "to", "the", "external", "resource", "and", "all", "files", "that", "use", "it" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_storage.php#L2375-L2392
220,554
moodle/moodle
lib/form/listing.php
MoodleQuickForm_listing.toHtml
function toHtml() { global $CFG, $PAGE; $this->_generateId(); $elementid = $this->getAttribute('id'); $mainhtml = html_writer::tag('div', $this->items[$this->getValue()]->mainhtml, array('id' => $elementid . '_items_main', 'class' => 'formlistingmain')); // Add the main div containing the selected item (+ the caption: "More items"). $html = html_writer::tag('div', $mainhtml . html_writer::tag('div', $this->showall, array('id' => $elementid . '_items_caption', 'class' => 'formlistingmore')), array('id' => $elementid . '_items', 'class' => 'formlisting hide')); // Add collapsible region: all the items. $itemrows = ''; $html .= html_writer::tag('div', $itemrows, array('id' => $elementid . '_items_all', 'class' => 'formlistingall')); // Add radio buttons for non javascript support. $radiobuttons = ''; foreach ($this->items as $itemid => $item) { $radioparams = array('name' => $this->getName(), 'value' => $itemid, 'id' => 'id_'.$itemid, 'class' => 'formlistinginputradio', 'type' => 'radio'); if ($itemid == $this->getValue()) { $radioparams['checked'] = 'checked'; } $radiobuttons .= html_writer::tag('div', html_writer::tag('input', html_writer::tag('div', $item->rowhtml, array('class' => 'formlistingradiocontent')), $radioparams), array('class' => 'formlistingradio')); } // Container for the hidden hidden input which will contain the selected item. $html .= html_writer::tag('div', $radiobuttons, array('id' => 'formlistinginputcontainer_' . $elementid, 'class' => 'formlistinginputcontainer')); $module = array('name'=>'form_listing', 'fullpath'=>'/lib/form/yui/listing/listing.js', 'requires'=>array('node', 'event', 'transition', 'escape')); $PAGE->requires->js_init_call('M.form_listing.init', array(array( 'elementid' => $elementid.'_items', 'hideall' => $this->hideall, 'showall' => $this->showall, 'hiddeninputid' => $this->getAttribute('id'), 'items' => $this->items, 'inputname' => $elementid, 'currentvalue' => $this->getValue())), true, $module); return $html; }
php
function toHtml() { global $CFG, $PAGE; $this->_generateId(); $elementid = $this->getAttribute('id'); $mainhtml = html_writer::tag('div', $this->items[$this->getValue()]->mainhtml, array('id' => $elementid . '_items_main', 'class' => 'formlistingmain')); // Add the main div containing the selected item (+ the caption: "More items"). $html = html_writer::tag('div', $mainhtml . html_writer::tag('div', $this->showall, array('id' => $elementid . '_items_caption', 'class' => 'formlistingmore')), array('id' => $elementid . '_items', 'class' => 'formlisting hide')); // Add collapsible region: all the items. $itemrows = ''; $html .= html_writer::tag('div', $itemrows, array('id' => $elementid . '_items_all', 'class' => 'formlistingall')); // Add radio buttons for non javascript support. $radiobuttons = ''; foreach ($this->items as $itemid => $item) { $radioparams = array('name' => $this->getName(), 'value' => $itemid, 'id' => 'id_'.$itemid, 'class' => 'formlistinginputradio', 'type' => 'radio'); if ($itemid == $this->getValue()) { $radioparams['checked'] = 'checked'; } $radiobuttons .= html_writer::tag('div', html_writer::tag('input', html_writer::tag('div', $item->rowhtml, array('class' => 'formlistingradiocontent')), $radioparams), array('class' => 'formlistingradio')); } // Container for the hidden hidden input which will contain the selected item. $html .= html_writer::tag('div', $radiobuttons, array('id' => 'formlistinginputcontainer_' . $elementid, 'class' => 'formlistinginputcontainer')); $module = array('name'=>'form_listing', 'fullpath'=>'/lib/form/yui/listing/listing.js', 'requires'=>array('node', 'event', 'transition', 'escape')); $PAGE->requires->js_init_call('M.form_listing.init', array(array( 'elementid' => $elementid.'_items', 'hideall' => $this->hideall, 'showall' => $this->showall, 'hiddeninputid' => $this->getAttribute('id'), 'items' => $this->items, 'inputname' => $elementid, 'currentvalue' => $this->getValue())), true, $module); return $html; }
[ "function", "toHtml", "(", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "$", "this", "->", "_generateId", "(", ")", ";", "$", "elementid", "=", "$", "this", "->", "getAttribute", "(", "'id'", ")", ";", "$", "mainhtml", "=", "html_writer", "::", "tag", "(", "'div'", ",", "$", "this", "->", "items", "[", "$", "this", "->", "getValue", "(", ")", "]", "->", "mainhtml", ",", "array", "(", "'id'", "=>", "$", "elementid", ".", "'_items_main'", ",", "'class'", "=>", "'formlistingmain'", ")", ")", ";", "// Add the main div containing the selected item (+ the caption: \"More items\").", "$", "html", "=", "html_writer", "::", "tag", "(", "'div'", ",", "$", "mainhtml", ".", "html_writer", "::", "tag", "(", "'div'", ",", "$", "this", "->", "showall", ",", "array", "(", "'id'", "=>", "$", "elementid", ".", "'_items_caption'", ",", "'class'", "=>", "'formlistingmore'", ")", ")", ",", "array", "(", "'id'", "=>", "$", "elementid", ".", "'_items'", ",", "'class'", "=>", "'formlisting hide'", ")", ")", ";", "// Add collapsible region: all the items.", "$", "itemrows", "=", "''", ";", "$", "html", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "$", "itemrows", ",", "array", "(", "'id'", "=>", "$", "elementid", ".", "'_items_all'", ",", "'class'", "=>", "'formlistingall'", ")", ")", ";", "// Add radio buttons for non javascript support.", "$", "radiobuttons", "=", "''", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "itemid", "=>", "$", "item", ")", "{", "$", "radioparams", "=", "array", "(", "'name'", "=>", "$", "this", "->", "getName", "(", ")", ",", "'value'", "=>", "$", "itemid", ",", "'id'", "=>", "'id_'", ".", "$", "itemid", ",", "'class'", "=>", "'formlistinginputradio'", ",", "'type'", "=>", "'radio'", ")", ";", "if", "(", "$", "itemid", "==", "$", "this", "->", "getValue", "(", ")", ")", "{", "$", "radioparams", "[", "'checked'", "]", "=", "'checked'", ";", "}", "$", "radiobuttons", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "html_writer", "::", "tag", "(", "'input'", ",", "html_writer", "::", "tag", "(", "'div'", ",", "$", "item", "->", "rowhtml", ",", "array", "(", "'class'", "=>", "'formlistingradiocontent'", ")", ")", ",", "$", "radioparams", ")", ",", "array", "(", "'class'", "=>", "'formlistingradio'", ")", ")", ";", "}", "// Container for the hidden hidden input which will contain the selected item.", "$", "html", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "$", "radiobuttons", ",", "array", "(", "'id'", "=>", "'formlistinginputcontainer_'", ".", "$", "elementid", ",", "'class'", "=>", "'formlistinginputcontainer'", ")", ")", ";", "$", "module", "=", "array", "(", "'name'", "=>", "'form_listing'", ",", "'fullpath'", "=>", "'/lib/form/yui/listing/listing.js'", ",", "'requires'", "=>", "array", "(", "'node'", ",", "'event'", ",", "'transition'", ",", "'escape'", ")", ")", ";", "$", "PAGE", "->", "requires", "->", "js_init_call", "(", "'M.form_listing.init'", ",", "array", "(", "array", "(", "'elementid'", "=>", "$", "elementid", ".", "'_items'", ",", "'hideall'", "=>", "$", "this", "->", "hideall", ",", "'showall'", "=>", "$", "this", "->", "showall", ",", "'hiddeninputid'", "=>", "$", "this", "->", "getAttribute", "(", "'id'", ")", ",", "'items'", "=>", "$", "this", "->", "items", ",", "'inputname'", "=>", "$", "elementid", ",", "'currentvalue'", "=>", "$", "this", "->", "getValue", "(", ")", ")", ")", ",", "true", ",", "$", "module", ")", ";", "return", "$", "html", ";", "}" ]
Returns HTML for listing form element. @return string the HTML.
[ "Returns", "HTML", "for", "listing", "form", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/listing.php#L110-L160
220,555
Intervention/image
src/Intervention/Image/Gd/Commands/ResizeCommand.php
ResizeCommand.execute
public function execute($image) { $width = $this->argument(0)->value(); $height = $this->argument(1)->value(); $constraints = $this->argument(2)->type('closure')->value(); // resize box $resized = $image->getSize()->resize($width, $height, $constraints); // modify image $this->modify($image, 0, 0, 0, 0, $resized->getWidth(), $resized->getHeight(), $image->getWidth(), $image->getHeight()); return true; }
php
public function execute($image) { $width = $this->argument(0)->value(); $height = $this->argument(1)->value(); $constraints = $this->argument(2)->type('closure')->value(); // resize box $resized = $image->getSize()->resize($width, $height, $constraints); // modify image $this->modify($image, 0, 0, 0, 0, $resized->getWidth(), $resized->getHeight(), $image->getWidth(), $image->getHeight()); return true; }
[ "public", "function", "execute", "(", "$", "image", ")", "{", "$", "width", "=", "$", "this", "->", "argument", "(", "0", ")", "->", "value", "(", ")", ";", "$", "height", "=", "$", "this", "->", "argument", "(", "1", ")", "->", "value", "(", ")", ";", "$", "constraints", "=", "$", "this", "->", "argument", "(", "2", ")", "->", "type", "(", "'closure'", ")", "->", "value", "(", ")", ";", "// resize box", "$", "resized", "=", "$", "image", "->", "getSize", "(", ")", "->", "resize", "(", "$", "width", ",", "$", "height", ",", "$", "constraints", ")", ";", "// modify image", "$", "this", "->", "modify", "(", "$", "image", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "resized", "->", "getWidth", "(", ")", ",", "$", "resized", "->", "getHeight", "(", ")", ",", "$", "image", "->", "getWidth", "(", ")", ",", "$", "image", "->", "getHeight", "(", ")", ")", ";", "return", "true", ";", "}" ]
Resizes image dimensions @param \Intervention\Image\Image $image @return boolean
[ "Resizes", "image", "dimensions" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Gd/Commands/ResizeCommand.php#L13-L26
220,556
Intervention/image
src/Intervention/Image/Gd/Commands/ResizeCommand.php
ResizeCommand.modify
protected function modify($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) { // create new image $modified = imagecreatetruecolor($dst_w, $dst_h); // get current image $resource = $image->getCore(); // preserve transparency $transIndex = imagecolortransparent($resource); if ($transIndex != -1) { $rgba = imagecolorsforindex($modified, $transIndex); $transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127); imagefill($modified, 0, 0, $transColor); imagecolortransparent($modified, $transColor); } else { imagealphablending($modified, false); imagesavealpha($modified, true); } // copy content from resource $result = imagecopyresampled( $modified, $resource, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); // set new content as recource $image->setCore($modified); return $result; }
php
protected function modify($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) { // create new image $modified = imagecreatetruecolor($dst_w, $dst_h); // get current image $resource = $image->getCore(); // preserve transparency $transIndex = imagecolortransparent($resource); if ($transIndex != -1) { $rgba = imagecolorsforindex($modified, $transIndex); $transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127); imagefill($modified, 0, 0, $transColor); imagecolortransparent($modified, $transColor); } else { imagealphablending($modified, false); imagesavealpha($modified, true); } // copy content from resource $result = imagecopyresampled( $modified, $resource, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); // set new content as recource $image->setCore($modified); return $result; }
[ "protected", "function", "modify", "(", "$", "image", ",", "$", "dst_x", ",", "$", "dst_y", ",", "$", "src_x", ",", "$", "src_y", ",", "$", "dst_w", ",", "$", "dst_h", ",", "$", "src_w", ",", "$", "src_h", ")", "{", "// create new image", "$", "modified", "=", "imagecreatetruecolor", "(", "$", "dst_w", ",", "$", "dst_h", ")", ";", "// get current image", "$", "resource", "=", "$", "image", "->", "getCore", "(", ")", ";", "// preserve transparency", "$", "transIndex", "=", "imagecolortransparent", "(", "$", "resource", ")", ";", "if", "(", "$", "transIndex", "!=", "-", "1", ")", "{", "$", "rgba", "=", "imagecolorsforindex", "(", "$", "modified", ",", "$", "transIndex", ")", ";", "$", "transColor", "=", "imagecolorallocatealpha", "(", "$", "modified", ",", "$", "rgba", "[", "'red'", "]", ",", "$", "rgba", "[", "'green'", "]", ",", "$", "rgba", "[", "'blue'", "]", ",", "127", ")", ";", "imagefill", "(", "$", "modified", ",", "0", ",", "0", ",", "$", "transColor", ")", ";", "imagecolortransparent", "(", "$", "modified", ",", "$", "transColor", ")", ";", "}", "else", "{", "imagealphablending", "(", "$", "modified", ",", "false", ")", ";", "imagesavealpha", "(", "$", "modified", ",", "true", ")", ";", "}", "// copy content from resource", "$", "result", "=", "imagecopyresampled", "(", "$", "modified", ",", "$", "resource", ",", "$", "dst_x", ",", "$", "dst_y", ",", "$", "src_x", ",", "$", "src_y", ",", "$", "dst_w", ",", "$", "dst_h", ",", "$", "src_w", ",", "$", "src_h", ")", ";", "// set new content as recource", "$", "image", "->", "setCore", "(", "$", "modified", ")", ";", "return", "$", "result", ";", "}" ]
Wrapper function for 'imagecopyresampled' @param Image $image @param int $dst_x @param int $dst_y @param int $src_x @param int $src_y @param int $dst_w @param int $dst_h @param int $src_w @param int $src_h @return boolean
[ "Wrapper", "function", "for", "imagecopyresampled" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Gd/Commands/ResizeCommand.php#L42-L81
220,557
Intervention/image
src/Intervention/Image/Commands/OrientateCommand.php
OrientateCommand.execute
public function execute($image) { switch ($image->exif('Orientation')) { case 2: $image->flip(); break; case 3: $image->rotate(180); break; case 4: $image->rotate(180)->flip(); break; case 5: $image->rotate(270)->flip(); break; case 6: $image->rotate(270); break; case 7: $image->rotate(90)->flip(); break; case 8: $image->rotate(90); break; } return true; }
php
public function execute($image) { switch ($image->exif('Orientation')) { case 2: $image->flip(); break; case 3: $image->rotate(180); break; case 4: $image->rotate(180)->flip(); break; case 5: $image->rotate(270)->flip(); break; case 6: $image->rotate(270); break; case 7: $image->rotate(90)->flip(); break; case 8: $image->rotate(90); break; } return true; }
[ "public", "function", "execute", "(", "$", "image", ")", "{", "switch", "(", "$", "image", "->", "exif", "(", "'Orientation'", ")", ")", "{", "case", "2", ":", "$", "image", "->", "flip", "(", ")", ";", "break", ";", "case", "3", ":", "$", "image", "->", "rotate", "(", "180", ")", ";", "break", ";", "case", "4", ":", "$", "image", "->", "rotate", "(", "180", ")", "->", "flip", "(", ")", ";", "break", ";", "case", "5", ":", "$", "image", "->", "rotate", "(", "270", ")", "->", "flip", "(", ")", ";", "break", ";", "case", "6", ":", "$", "image", "->", "rotate", "(", "270", ")", ";", "break", ";", "case", "7", ":", "$", "image", "->", "rotate", "(", "90", ")", "->", "flip", "(", ")", ";", "break", ";", "case", "8", ":", "$", "image", "->", "rotate", "(", "90", ")", ";", "break", ";", "}", "return", "true", ";", "}" ]
Correct image orientation according to Exif data @param \Intervention\Image\Image $image @return boolean
[ "Correct", "image", "orientation", "according", "to", "Exif", "data" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Commands/OrientateCommand.php#L13-L47
220,558
Intervention/image
src/Intervention/Image/ImageManager.php
ImageManager.canvas
public function canvas($width, $height, $background = null) { return $this->createDriver()->newImage($width, $height, $background); }
php
public function canvas($width, $height, $background = null) { return $this->createDriver()->newImage($width, $height, $background); }
[ "public", "function", "canvas", "(", "$", "width", ",", "$", "height", ",", "$", "background", "=", "null", ")", "{", "return", "$", "this", "->", "createDriver", "(", ")", "->", "newImage", "(", "$", "width", ",", "$", "height", ",", "$", "background", ")", ";", "}" ]
Creates an empty image canvas @param int $width @param int $height @param mixed $background @return \Intervention\Image\Image
[ "Creates", "an", "empty", "image", "canvas" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/ImageManager.php#L64-L67
220,559
Intervention/image
src/Intervention/Image/Gd/Commands/GammaCommand.php
GammaCommand.execute
public function execute($image) { $gamma = $this->argument(0)->type('numeric')->required()->value(); return imagegammacorrect($image->getCore(), 1, $gamma); }
php
public function execute($image) { $gamma = $this->argument(0)->type('numeric')->required()->value(); return imagegammacorrect($image->getCore(), 1, $gamma); }
[ "public", "function", "execute", "(", "$", "image", ")", "{", "$", "gamma", "=", "$", "this", "->", "argument", "(", "0", ")", "->", "type", "(", "'numeric'", ")", "->", "required", "(", ")", "->", "value", "(", ")", ";", "return", "imagegammacorrect", "(", "$", "image", "->", "getCore", "(", ")", ",", "1", ",", "$", "gamma", ")", ";", "}" ]
Applies gamma correction to a given image @param \Intervention\Image\Image $image @return boolean
[ "Applies", "gamma", "correction", "to", "a", "given", "image" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Gd/Commands/GammaCommand.php#L13-L18
220,560
Intervention/image
src/Intervention/Image/Imagick/Encoder.php
Encoder.processTiff
protected function processTiff() { $format = 'tiff'; $compression = \Imagick::COMPRESSION_UNDEFINED; $imagick = $this->image->getCore(); $imagick->setFormat($format); $imagick->setImageFormat($format); $imagick->setCompression($compression); $imagick->setImageCompression($compression); $imagick->setCompressionQuality($this->quality); $imagick->setImageCompressionQuality($this->quality); return $imagick->getImagesBlob(); }
php
protected function processTiff() { $format = 'tiff'; $compression = \Imagick::COMPRESSION_UNDEFINED; $imagick = $this->image->getCore(); $imagick->setFormat($format); $imagick->setImageFormat($format); $imagick->setCompression($compression); $imagick->setImageCompression($compression); $imagick->setCompressionQuality($this->quality); $imagick->setImageCompressionQuality($this->quality); return $imagick->getImagesBlob(); }
[ "protected", "function", "processTiff", "(", ")", "{", "$", "format", "=", "'tiff'", ";", "$", "compression", "=", "\\", "Imagick", "::", "COMPRESSION_UNDEFINED", ";", "$", "imagick", "=", "$", "this", "->", "image", "->", "getCore", "(", ")", ";", "$", "imagick", "->", "setFormat", "(", "$", "format", ")", ";", "$", "imagick", "->", "setImageFormat", "(", "$", "format", ")", ";", "$", "imagick", "->", "setCompression", "(", "$", "compression", ")", ";", "$", "imagick", "->", "setImageCompression", "(", "$", "compression", ")", ";", "$", "imagick", "->", "setCompressionQuality", "(", "$", "this", "->", "quality", ")", ";", "$", "imagick", "->", "setImageCompressionQuality", "(", "$", "this", "->", "quality", ")", ";", "return", "$", "imagick", "->", "getImagesBlob", "(", ")", ";", "}" ]
Processes and returns encoded image as TIFF string @return string
[ "Processes", "and", "returns", "encoded", "image", "as", "TIFF", "string" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Imagick/Encoder.php#L96-L110
220,561
Intervention/image
src/Intervention/Image/Imagick/Encoder.php
Encoder.processPsd
protected function processPsd() { $format = 'psd'; $compression = \Imagick::COMPRESSION_UNDEFINED; $imagick = $this->image->getCore(); $imagick->setFormat($format); $imagick->setImageFormat($format); $imagick->setCompression($compression); $imagick->setImageCompression($compression); return $imagick->getImagesBlob(); }
php
protected function processPsd() { $format = 'psd'; $compression = \Imagick::COMPRESSION_UNDEFINED; $imagick = $this->image->getCore(); $imagick->setFormat($format); $imagick->setImageFormat($format); $imagick->setCompression($compression); $imagick->setImageCompression($compression); return $imagick->getImagesBlob(); }
[ "protected", "function", "processPsd", "(", ")", "{", "$", "format", "=", "'psd'", ";", "$", "compression", "=", "\\", "Imagick", "::", "COMPRESSION_UNDEFINED", ";", "$", "imagick", "=", "$", "this", "->", "image", "->", "getCore", "(", ")", ";", "$", "imagick", "->", "setFormat", "(", "$", "format", ")", ";", "$", "imagick", "->", "setImageFormat", "(", "$", "format", ")", ";", "$", "imagick", "->", "setCompression", "(", "$", "compression", ")", ";", "$", "imagick", "->", "setImageCompression", "(", "$", "compression", ")", ";", "return", "$", "imagick", "->", "getImagesBlob", "(", ")", ";", "}" ]
Processes and returns encoded image as PSD string @return string
[ "Processes", "and", "returns", "encoded", "image", "as", "PSD", "string" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Imagick/Encoder.php#L155-L167
220,562
Intervention/image
src/Intervention/Image/AbstractEncoder.php
AbstractEncoder.processDataUrl
protected function processDataUrl() { $mime = $this->image->mime ? $this->image->mime : 'image/png'; return sprintf('data:%s;base64,%s', $mime, base64_encode($this->process($this->image, $mime, $this->quality)) ); }
php
protected function processDataUrl() { $mime = $this->image->mime ? $this->image->mime : 'image/png'; return sprintf('data:%s;base64,%s', $mime, base64_encode($this->process($this->image, $mime, $this->quality)) ); }
[ "protected", "function", "processDataUrl", "(", ")", "{", "$", "mime", "=", "$", "this", "->", "image", "->", "mime", "?", "$", "this", "->", "image", "->", "mime", ":", "'image/png'", ";", "return", "sprintf", "(", "'data:%s;base64,%s'", ",", "$", "mime", ",", "base64_encode", "(", "$", "this", "->", "process", "(", "$", "this", "->", "image", ",", "$", "mime", ",", "$", "this", "->", "quality", ")", ")", ")", ";", "}" ]
Processes and returns encoded image as data-url string @return string
[ "Processes", "and", "returns", "encoded", "image", "as", "data", "-", "url", "string" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractEncoder.php#L185-L193
220,563
Intervention/image
src/Intervention/Image/AbstractEncoder.php
AbstractEncoder.setFormat
protected function setFormat($format = null) { if ($format == '' && $this->image instanceof Image) { $format = $this->image->mime; } $this->format = $format ? $format : 'jpg'; return $this; }
php
protected function setFormat($format = null) { if ($format == '' && $this->image instanceof Image) { $format = $this->image->mime; } $this->format = $format ? $format : 'jpg'; return $this; }
[ "protected", "function", "setFormat", "(", "$", "format", "=", "null", ")", "{", "if", "(", "$", "format", "==", "''", "&&", "$", "this", "->", "image", "instanceof", "Image", ")", "{", "$", "format", "=", "$", "this", "->", "image", "->", "mime", ";", "}", "$", "this", "->", "format", "=", "$", "format", "?", "$", "format", ":", "'jpg'", ";", "return", "$", "this", ";", "}" ]
Determines output format @param string $format
[ "Determines", "output", "format" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractEncoder.php#L210-L219
220,564
Intervention/image
src/Intervention/Image/AbstractEncoder.php
AbstractEncoder.setQuality
protected function setQuality($quality) { $quality = is_null($quality) ? 90 : $quality; $quality = $quality === 0 ? 1 : $quality; if ($quality < 0 || $quality > 100) { throw new \Intervention\Image\Exception\InvalidArgumentException( 'Quality must range from 0 to 100.' ); } $this->quality = intval($quality); return $this; }
php
protected function setQuality($quality) { $quality = is_null($quality) ? 90 : $quality; $quality = $quality === 0 ? 1 : $quality; if ($quality < 0 || $quality > 100) { throw new \Intervention\Image\Exception\InvalidArgumentException( 'Quality must range from 0 to 100.' ); } $this->quality = intval($quality); return $this; }
[ "protected", "function", "setQuality", "(", "$", "quality", ")", "{", "$", "quality", "=", "is_null", "(", "$", "quality", ")", "?", "90", ":", "$", "quality", ";", "$", "quality", "=", "$", "quality", "===", "0", "?", "1", ":", "$", "quality", ";", "if", "(", "$", "quality", "<", "0", "||", "$", "quality", ">", "100", ")", "{", "throw", "new", "\\", "Intervention", "\\", "Image", "\\", "Exception", "\\", "InvalidArgumentException", "(", "'Quality must range from 0 to 100.'", ")", ";", "}", "$", "this", "->", "quality", "=", "intval", "(", "$", "quality", ")", ";", "return", "$", "this", ";", "}" ]
Determines output quality @param int $quality
[ "Determines", "output", "quality" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractEncoder.php#L226-L240
220,565
Intervention/image
src/Intervention/Image/AbstractDriver.php
AbstractDriver.encode
public function encode($image, $format, $quality) { return $this->encoder->process($image, $format, $quality); }
php
public function encode($image, $format, $quality) { return $this->encoder->process($image, $format, $quality); }
[ "public", "function", "encode", "(", "$", "image", ",", "$", "format", ",", "$", "quality", ")", "{", "return", "$", "this", "->", "encoder", "->", "process", "(", "$", "image", ",", "$", "format", ",", "$", "quality", ")", ";", "}" ]
Encodes given image @param Image $image @param string $format @param int $quality @return \Intervention\Image\Image
[ "Encodes", "given", "image" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractDriver.php#L75-L78
220,566
Intervention/image
src/Intervention/Image/Imagick/Commands/FitCommand.php
FitCommand.execute
public function execute($image) { $width = $this->argument(0)->type('digit')->required()->value(); $height = $this->argument(1)->type('digit')->value($width); $constraints = $this->argument(2)->type('closure')->value(); $position = $this->argument(3)->type('string')->value('center'); // calculate size $cropped = $image->getSize()->fit(new Size($width, $height), $position); $resized = clone $cropped; $resized = $resized->resize($width, $height, $constraints); // crop image $image->getCore()->cropImage( $cropped->width, $cropped->height, $cropped->pivot->x, $cropped->pivot->y ); // resize image $image->getCore()->scaleImage($resized->getWidth(), $resized->getHeight()); $image->getCore()->setImagePage(0,0,0,0); return true; }
php
public function execute($image) { $width = $this->argument(0)->type('digit')->required()->value(); $height = $this->argument(1)->type('digit')->value($width); $constraints = $this->argument(2)->type('closure')->value(); $position = $this->argument(3)->type('string')->value('center'); // calculate size $cropped = $image->getSize()->fit(new Size($width, $height), $position); $resized = clone $cropped; $resized = $resized->resize($width, $height, $constraints); // crop image $image->getCore()->cropImage( $cropped->width, $cropped->height, $cropped->pivot->x, $cropped->pivot->y ); // resize image $image->getCore()->scaleImage($resized->getWidth(), $resized->getHeight()); $image->getCore()->setImagePage(0,0,0,0); return true; }
[ "public", "function", "execute", "(", "$", "image", ")", "{", "$", "width", "=", "$", "this", "->", "argument", "(", "0", ")", "->", "type", "(", "'digit'", ")", "->", "required", "(", ")", "->", "value", "(", ")", ";", "$", "height", "=", "$", "this", "->", "argument", "(", "1", ")", "->", "type", "(", "'digit'", ")", "->", "value", "(", "$", "width", ")", ";", "$", "constraints", "=", "$", "this", "->", "argument", "(", "2", ")", "->", "type", "(", "'closure'", ")", "->", "value", "(", ")", ";", "$", "position", "=", "$", "this", "->", "argument", "(", "3", ")", "->", "type", "(", "'string'", ")", "->", "value", "(", "'center'", ")", ";", "// calculate size", "$", "cropped", "=", "$", "image", "->", "getSize", "(", ")", "->", "fit", "(", "new", "Size", "(", "$", "width", ",", "$", "height", ")", ",", "$", "position", ")", ";", "$", "resized", "=", "clone", "$", "cropped", ";", "$", "resized", "=", "$", "resized", "->", "resize", "(", "$", "width", ",", "$", "height", ",", "$", "constraints", ")", ";", "// crop image", "$", "image", "->", "getCore", "(", ")", "->", "cropImage", "(", "$", "cropped", "->", "width", ",", "$", "cropped", "->", "height", ",", "$", "cropped", "->", "pivot", "->", "x", ",", "$", "cropped", "->", "pivot", "->", "y", ")", ";", "// resize image", "$", "image", "->", "getCore", "(", ")", "->", "scaleImage", "(", "$", "resized", "->", "getWidth", "(", ")", ",", "$", "resized", "->", "getHeight", "(", ")", ")", ";", "$", "image", "->", "getCore", "(", ")", "->", "setImagePage", "(", "0", ",", "0", ",", "0", ",", "0", ")", ";", "return", "true", ";", "}" ]
Crops and resized an image at the same time @param \Intervention\Image\Image $image @return boolean
[ "Crops", "and", "resized", "an", "image", "at", "the", "same", "time" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Imagick/Commands/FitCommand.php#L15-L40
220,567
Intervention/image
src/Intervention/Image/Gd/Driver.php
Driver.cloneCore
public function cloneCore($core) { $width = imagesx($core); $height = imagesy($core); $clone = imagecreatetruecolor($width, $height); imagealphablending($clone, false); imagesavealpha($clone, true); $transparency = imagecolorallocatealpha($clone, 0, 0, 0, 127); imagefill($clone, 0, 0, $transparency); imagecopy($clone, $core, 0, 0, 0, 0, $width, $height); return $clone; }
php
public function cloneCore($core) { $width = imagesx($core); $height = imagesy($core); $clone = imagecreatetruecolor($width, $height); imagealphablending($clone, false); imagesavealpha($clone, true); $transparency = imagecolorallocatealpha($clone, 0, 0, 0, 127); imagefill($clone, 0, 0, $transparency); imagecopy($clone, $core, 0, 0, 0, 0, $width, $height); return $clone; }
[ "public", "function", "cloneCore", "(", "$", "core", ")", "{", "$", "width", "=", "imagesx", "(", "$", "core", ")", ";", "$", "height", "=", "imagesy", "(", "$", "core", ")", ";", "$", "clone", "=", "imagecreatetruecolor", "(", "$", "width", ",", "$", "height", ")", ";", "imagealphablending", "(", "$", "clone", ",", "false", ")", ";", "imagesavealpha", "(", "$", "clone", ",", "true", ")", ";", "$", "transparency", "=", "imagecolorallocatealpha", "(", "$", "clone", ",", "0", ",", "0", ",", "0", ",", "127", ")", ";", "imagefill", "(", "$", "clone", ",", "0", ",", "0", ",", "$", "transparency", ")", ";", "imagecopy", "(", "$", "clone", ",", "$", "core", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "width", ",", "$", "height", ")", ";", "return", "$", "clone", ";", "}" ]
Returns clone of given core @return mixed
[ "Returns", "clone", "of", "given", "core" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Gd/Driver.php#L72-L85
220,568
Intervention/image
src/Intervention/Image/Size.php
Size.relativePosition
public function relativePosition(Size $size) { $x = $this->pivot->x - $size->pivot->x; $y = $this->pivot->y - $size->pivot->y; return new Point($x, $y); }
php
public function relativePosition(Size $size) { $x = $this->pivot->x - $size->pivot->x; $y = $this->pivot->y - $size->pivot->y; return new Point($x, $y); }
[ "public", "function", "relativePosition", "(", "Size", "$", "size", ")", "{", "$", "x", "=", "$", "this", "->", "pivot", "->", "x", "-", "$", "size", "->", "pivot", "->", "x", ";", "$", "y", "=", "$", "this", "->", "pivot", "->", "y", "-", "$", "size", "->", "pivot", "->", "y", ";", "return", "new", "Point", "(", "$", "x", ",", "$", "y", ")", ";", "}" ]
Calculate the relative position to another Size based on the pivot point settings of both sizes. @param Size $size @return \Intervention\Image\Point
[ "Calculate", "the", "relative", "position", "to", "another", "Size", "based", "on", "the", "pivot", "point", "settings", "of", "both", "sizes", "." ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Size.php#L211-L217
220,569
Intervention/image
src/Intervention/Image/Size.php
Size.fit
public function fit(Size $size, $position = 'center') { // create size with auto height $auto_height = clone $size; $auto_height->resize($this->width, null, function ($constraint) { $constraint->aspectRatio(); }); // decide which version to use if ($auto_height->fitsInto($this)) { $size = $auto_height; } else { // create size with auto width $auto_width = clone $size; $auto_width->resize(null, $this->height, function ($constraint) { $constraint->aspectRatio(); }); $size = $auto_width; } $this->align($position); $size->align($position); $size->setPivot($this->relativePosition($size)); return $size; }
php
public function fit(Size $size, $position = 'center') { // create size with auto height $auto_height = clone $size; $auto_height->resize($this->width, null, function ($constraint) { $constraint->aspectRatio(); }); // decide which version to use if ($auto_height->fitsInto($this)) { $size = $auto_height; } else { // create size with auto width $auto_width = clone $size; $auto_width->resize(null, $this->height, function ($constraint) { $constraint->aspectRatio(); }); $size = $auto_width; } $this->align($position); $size->align($position); $size->setPivot($this->relativePosition($size)); return $size; }
[ "public", "function", "fit", "(", "Size", "$", "size", ",", "$", "position", "=", "'center'", ")", "{", "// create size with auto height", "$", "auto_height", "=", "clone", "$", "size", ";", "$", "auto_height", "->", "resize", "(", "$", "this", "->", "width", ",", "null", ",", "function", "(", "$", "constraint", ")", "{", "$", "constraint", "->", "aspectRatio", "(", ")", ";", "}", ")", ";", "// decide which version to use", "if", "(", "$", "auto_height", "->", "fitsInto", "(", "$", "this", ")", ")", "{", "$", "size", "=", "$", "auto_height", ";", "}", "else", "{", "// create size with auto width", "$", "auto_width", "=", "clone", "$", "size", ";", "$", "auto_width", "->", "resize", "(", "null", ",", "$", "this", "->", "height", ",", "function", "(", "$", "constraint", ")", "{", "$", "constraint", "->", "aspectRatio", "(", ")", ";", "}", ")", ";", "$", "size", "=", "$", "auto_width", ";", "}", "$", "this", "->", "align", "(", "$", "position", ")", ";", "$", "size", "->", "align", "(", "$", "position", ")", ";", "$", "size", "->", "setPivot", "(", "$", "this", "->", "relativePosition", "(", "$", "size", ")", ")", ";", "return", "$", "size", ";", "}" ]
Resize given Size to best fitting size of current size. @param Size $size @return \Intervention\Image\Size
[ "Resize", "given", "Size", "to", "best", "fitting", "size", "of", "current", "size", "." ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Size.php#L225-L256
220,570
Intervention/image
src/Intervention/Image/Size.php
Size.fitsInto
public function fitsInto(Size $size) { return ($this->width <= $size->width) && ($this->height <= $size->height); }
php
public function fitsInto(Size $size) { return ($this->width <= $size->width) && ($this->height <= $size->height); }
[ "public", "function", "fitsInto", "(", "Size", "$", "size", ")", "{", "return", "(", "$", "this", "->", "width", "<=", "$", "size", "->", "width", ")", "&&", "(", "$", "this", "->", "height", "<=", "$", "size", "->", "height", ")", ";", "}" ]
Checks if given size fits into current size @param Size $size @return boolean
[ "Checks", "if", "given", "size", "fits", "into", "current", "size" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Size.php#L264-L267
220,571
Intervention/image
src/Intervention/Image/Size.php
Size.align
public function align($position, $offset_x = 0, $offset_y = 0) { switch (strtolower($position)) { case 'top': case 'top-center': case 'top-middle': case 'center-top': case 'middle-top': $x = intval($this->width / 2); $y = 0 + $offset_y; break; case 'top-right': case 'right-top': $x = $this->width - $offset_x; $y = 0 + $offset_y; break; case 'left': case 'left-center': case 'left-middle': case 'center-left': case 'middle-left': $x = 0 + $offset_x; $y = intval($this->height / 2); break; case 'right': case 'right-center': case 'right-middle': case 'center-right': case 'middle-right': $x = $this->width - $offset_x; $y = intval($this->height / 2); break; case 'bottom-left': case 'left-bottom': $x = 0 + $offset_x; $y = $this->height - $offset_y; break; case 'bottom': case 'bottom-center': case 'bottom-middle': case 'center-bottom': case 'middle-bottom': $x = intval($this->width / 2); $y = $this->height - $offset_y; break; case 'bottom-right': case 'right-bottom': $x = $this->width - $offset_x; $y = $this->height - $offset_y; break; case 'center': case 'middle': case 'center-center': case 'middle-middle': $x = intval($this->width / 2); $y = intval($this->height / 2); break; default: case 'top-left': case 'left-top': $x = 0 + $offset_x; $y = 0 + $offset_y; break; } $this->pivot->setPosition($x, $y); return $this; }
php
public function align($position, $offset_x = 0, $offset_y = 0) { switch (strtolower($position)) { case 'top': case 'top-center': case 'top-middle': case 'center-top': case 'middle-top': $x = intval($this->width / 2); $y = 0 + $offset_y; break; case 'top-right': case 'right-top': $x = $this->width - $offset_x; $y = 0 + $offset_y; break; case 'left': case 'left-center': case 'left-middle': case 'center-left': case 'middle-left': $x = 0 + $offset_x; $y = intval($this->height / 2); break; case 'right': case 'right-center': case 'right-middle': case 'center-right': case 'middle-right': $x = $this->width - $offset_x; $y = intval($this->height / 2); break; case 'bottom-left': case 'left-bottom': $x = 0 + $offset_x; $y = $this->height - $offset_y; break; case 'bottom': case 'bottom-center': case 'bottom-middle': case 'center-bottom': case 'middle-bottom': $x = intval($this->width / 2); $y = $this->height - $offset_y; break; case 'bottom-right': case 'right-bottom': $x = $this->width - $offset_x; $y = $this->height - $offset_y; break; case 'center': case 'middle': case 'center-center': case 'middle-middle': $x = intval($this->width / 2); $y = intval($this->height / 2); break; default: case 'top-left': case 'left-top': $x = 0 + $offset_x; $y = 0 + $offset_y; break; } $this->pivot->setPosition($x, $y); return $this; }
[ "public", "function", "align", "(", "$", "position", ",", "$", "offset_x", "=", "0", ",", "$", "offset_y", "=", "0", ")", "{", "switch", "(", "strtolower", "(", "$", "position", ")", ")", "{", "case", "'top'", ":", "case", "'top-center'", ":", "case", "'top-middle'", ":", "case", "'center-top'", ":", "case", "'middle-top'", ":", "$", "x", "=", "intval", "(", "$", "this", "->", "width", "/", "2", ")", ";", "$", "y", "=", "0", "+", "$", "offset_y", ";", "break", ";", "case", "'top-right'", ":", "case", "'right-top'", ":", "$", "x", "=", "$", "this", "->", "width", "-", "$", "offset_x", ";", "$", "y", "=", "0", "+", "$", "offset_y", ";", "break", ";", "case", "'left'", ":", "case", "'left-center'", ":", "case", "'left-middle'", ":", "case", "'center-left'", ":", "case", "'middle-left'", ":", "$", "x", "=", "0", "+", "$", "offset_x", ";", "$", "y", "=", "intval", "(", "$", "this", "->", "height", "/", "2", ")", ";", "break", ";", "case", "'right'", ":", "case", "'right-center'", ":", "case", "'right-middle'", ":", "case", "'center-right'", ":", "case", "'middle-right'", ":", "$", "x", "=", "$", "this", "->", "width", "-", "$", "offset_x", ";", "$", "y", "=", "intval", "(", "$", "this", "->", "height", "/", "2", ")", ";", "break", ";", "case", "'bottom-left'", ":", "case", "'left-bottom'", ":", "$", "x", "=", "0", "+", "$", "offset_x", ";", "$", "y", "=", "$", "this", "->", "height", "-", "$", "offset_y", ";", "break", ";", "case", "'bottom'", ":", "case", "'bottom-center'", ":", "case", "'bottom-middle'", ":", "case", "'center-bottom'", ":", "case", "'middle-bottom'", ":", "$", "x", "=", "intval", "(", "$", "this", "->", "width", "/", "2", ")", ";", "$", "y", "=", "$", "this", "->", "height", "-", "$", "offset_y", ";", "break", ";", "case", "'bottom-right'", ":", "case", "'right-bottom'", ":", "$", "x", "=", "$", "this", "->", "width", "-", "$", "offset_x", ";", "$", "y", "=", "$", "this", "->", "height", "-", "$", "offset_y", ";", "break", ";", "case", "'center'", ":", "case", "'middle'", ":", "case", "'center-center'", ":", "case", "'middle-middle'", ":", "$", "x", "=", "intval", "(", "$", "this", "->", "width", "/", "2", ")", ";", "$", "y", "=", "intval", "(", "$", "this", "->", "height", "/", "2", ")", ";", "break", ";", "default", ":", "case", "'top-left'", ":", "case", "'left-top'", ":", "$", "x", "=", "0", "+", "$", "offset_x", ";", "$", "y", "=", "0", "+", "$", "offset_y", ";", "break", ";", "}", "$", "this", "->", "pivot", "->", "setPosition", "(", "$", "x", ",", "$", "y", ")", ";", "return", "$", "this", ";", "}" ]
Aligns current size's pivot point to given position and moves point automatically by offset. @param string $position @param int $offset_x @param int $offset_y @return \Intervention\Image\Size
[ "Aligns", "current", "size", "s", "pivot", "point", "to", "given", "position", "and", "moves", "point", "automatically", "by", "offset", "." ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Size.php#L278-L355
220,572
Intervention/image
src/Intervention/Image/Imagick/Decoder.php
Decoder.initFromImagick
public function initFromImagick(\Imagick $object) { // currently animations are not supported // so all images are turned into static $object = $this->removeAnimation($object); // reset image orientation $object->setImageOrientation(\Imagick::ORIENTATION_UNDEFINED); return new Image(new Driver, $object); }
php
public function initFromImagick(\Imagick $object) { // currently animations are not supported // so all images are turned into static $object = $this->removeAnimation($object); // reset image orientation $object->setImageOrientation(\Imagick::ORIENTATION_UNDEFINED); return new Image(new Driver, $object); }
[ "public", "function", "initFromImagick", "(", "\\", "Imagick", "$", "object", ")", "{", "// currently animations are not supported", "// so all images are turned into static", "$", "object", "=", "$", "this", "->", "removeAnimation", "(", "$", "object", ")", ";", "// reset image orientation", "$", "object", "->", "setImageOrientation", "(", "\\", "Imagick", "::", "ORIENTATION_UNDEFINED", ")", ";", "return", "new", "Image", "(", "new", "Driver", ",", "$", "object", ")", ";", "}" ]
Initiates new image from Imagick object @param Imagick $object @return \Intervention\Image\Image
[ "Initiates", "new", "image", "from", "Imagick", "object" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Imagick/Decoder.php#L59-L69
220,573
Intervention/image
src/Intervention/Image/Imagick/Decoder.php
Decoder.removeAnimation
private function removeAnimation(\Imagick $object) { $imagick = new \Imagick; foreach ($object as $frame) { $imagick->addImage($frame->getImage()); break; } $object->destroy(); return $imagick; }
php
private function removeAnimation(\Imagick $object) { $imagick = new \Imagick; foreach ($object as $frame) { $imagick->addImage($frame->getImage()); break; } $object->destroy(); return $imagick; }
[ "private", "function", "removeAnimation", "(", "\\", "Imagick", "$", "object", ")", "{", "$", "imagick", "=", "new", "\\", "Imagick", ";", "foreach", "(", "$", "object", "as", "$", "frame", ")", "{", "$", "imagick", "->", "addImage", "(", "$", "frame", "->", "getImage", "(", ")", ")", ";", "break", ";", "}", "$", "object", "->", "destroy", "(", ")", ";", "return", "$", "imagick", ";", "}" ]
Turns object into one frame Imagick object by removing all frames except first @param Imagick $object @return Imagick
[ "Turns", "object", "into", "one", "frame", "Imagick", "object", "by", "removing", "all", "frames", "except", "first" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Imagick/Decoder.php#L108-L120
220,574
Intervention/image
src/Intervention/Image/Commands/ChecksumCommand.php
ChecksumCommand.execute
public function execute($image) { $colors = []; $size = $image->getSize(); for ($x=0; $x <= ($size->width-1); $x++) { for ($y=0; $y <= ($size->height-1); $y++) { $colors[] = $image->pickColor($x, $y, 'array'); } } $this->setOutput(md5(serialize($colors))); return true; }
php
public function execute($image) { $colors = []; $size = $image->getSize(); for ($x=0; $x <= ($size->width-1); $x++) { for ($y=0; $y <= ($size->height-1); $y++) { $colors[] = $image->pickColor($x, $y, 'array'); } } $this->setOutput(md5(serialize($colors))); return true; }
[ "public", "function", "execute", "(", "$", "image", ")", "{", "$", "colors", "=", "[", "]", ";", "$", "size", "=", "$", "image", "->", "getSize", "(", ")", ";", "for", "(", "$", "x", "=", "0", ";", "$", "x", "<=", "(", "$", "size", "->", "width", "-", "1", ")", ";", "$", "x", "++", ")", "{", "for", "(", "$", "y", "=", "0", ";", "$", "y", "<=", "(", "$", "size", "->", "height", "-", "1", ")", ";", "$", "y", "++", ")", "{", "$", "colors", "[", "]", "=", "$", "image", "->", "pickColor", "(", "$", "x", ",", "$", "y", ",", "'array'", ")", ";", "}", "}", "$", "this", "->", "setOutput", "(", "md5", "(", "serialize", "(", "$", "colors", ")", ")", ")", ";", "return", "true", ";", "}" ]
Calculates checksum of given image @param \Intervention\Image\Image $image @return boolean
[ "Calculates", "checksum", "of", "given", "image" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Commands/ChecksumCommand.php#L13-L28
220,575
Intervention/image
src/Intervention/Image/Imagick/Commands/WidenCommand.php
WidenCommand.execute
public function execute($image) { $width = $this->argument(0)->type('digit')->required()->value(); $additionalConstraints = $this->argument(1)->type('closure')->value(); $this->arguments[0] = $width; $this->arguments[1] = null; $this->arguments[2] = function ($constraint) use ($additionalConstraints) { $constraint->aspectRatio(); if(is_callable($additionalConstraints)) $additionalConstraints($constraint); }; return parent::execute($image); }
php
public function execute($image) { $width = $this->argument(0)->type('digit')->required()->value(); $additionalConstraints = $this->argument(1)->type('closure')->value(); $this->arguments[0] = $width; $this->arguments[1] = null; $this->arguments[2] = function ($constraint) use ($additionalConstraints) { $constraint->aspectRatio(); if(is_callable($additionalConstraints)) $additionalConstraints($constraint); }; return parent::execute($image); }
[ "public", "function", "execute", "(", "$", "image", ")", "{", "$", "width", "=", "$", "this", "->", "argument", "(", "0", ")", "->", "type", "(", "'digit'", ")", "->", "required", "(", ")", "->", "value", "(", ")", ";", "$", "additionalConstraints", "=", "$", "this", "->", "argument", "(", "1", ")", "->", "type", "(", "'closure'", ")", "->", "value", "(", ")", ";", "$", "this", "->", "arguments", "[", "0", "]", "=", "$", "width", ";", "$", "this", "->", "arguments", "[", "1", "]", "=", "null", ";", "$", "this", "->", "arguments", "[", "2", "]", "=", "function", "(", "$", "constraint", ")", "use", "(", "$", "additionalConstraints", ")", "{", "$", "constraint", "->", "aspectRatio", "(", ")", ";", "if", "(", "is_callable", "(", "$", "additionalConstraints", ")", ")", "$", "additionalConstraints", "(", "$", "constraint", ")", ";", "}", ";", "return", "parent", "::", "execute", "(", "$", "image", ")", ";", "}" ]
Resize image proportionally to given width @param \Intervention\Image\Image $image @return boolean
[ "Resize", "image", "proportionally", "to", "given", "width" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Imagick/Commands/WidenCommand.php#L13-L27
220,576
Intervention/image
src/Intervention/Image/AbstractDecoder.php
AbstractDecoder.initFromUrl
public function initFromUrl($url) { $options = [ 'http' => [ 'method'=>"GET", 'header'=>"Accept-language: en\r\n". "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2\r\n" ] ]; $context = stream_context_create($options); if ($data = @file_get_contents($url, false, $context)) { return $this->initFromBinary($data); } throw new \Intervention\Image\Exception\NotReadableException( "Unable to init from given url (".$url.")." ); }
php
public function initFromUrl($url) { $options = [ 'http' => [ 'method'=>"GET", 'header'=>"Accept-language: en\r\n". "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2\r\n" ] ]; $context = stream_context_create($options); if ($data = @file_get_contents($url, false, $context)) { return $this->initFromBinary($data); } throw new \Intervention\Image\Exception\NotReadableException( "Unable to init from given url (".$url.")." ); }
[ "public", "function", "initFromUrl", "(", "$", "url", ")", "{", "$", "options", "=", "[", "'http'", "=>", "[", "'method'", "=>", "\"GET\"", ",", "'header'", "=>", "\"Accept-language: en\\r\\n\"", ".", "\"User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2\\r\\n\"", "]", "]", ";", "$", "context", "=", "stream_context_create", "(", "$", "options", ")", ";", "if", "(", "$", "data", "=", "@", "file_get_contents", "(", "$", "url", ",", "false", ",", "$", "context", ")", ")", "{", "return", "$", "this", "->", "initFromBinary", "(", "$", "data", ")", ";", "}", "throw", "new", "\\", "Intervention", "\\", "Image", "\\", "Exception", "\\", "NotReadableException", "(", "\"Unable to init from given url (\"", ".", "$", "url", ".", "\").\"", ")", ";", "}" ]
Init from given URL @param string $url @return \Intervention\Image\Image
[ "Init", "from", "given", "URL" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractDecoder.php#L65-L86
220,577
Intervention/image
src/Intervention/Image/AbstractDecoder.php
AbstractDecoder.isFilePath
public function isFilePath() { if (is_string($this->data)) { try { return is_file($this->data); } catch (\Exception $e) { return false; } } return false; }
php
public function isFilePath() { if (is_string($this->data)) { try { return is_file($this->data); } catch (\Exception $e) { return false; } } return false; }
[ "public", "function", "isFilePath", "(", ")", "{", "if", "(", "is_string", "(", "$", "this", "->", "data", ")", ")", "{", "try", "{", "return", "is_file", "(", "$", "this", "->", "data", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "false", ";", "}", "}", "return", "false", ";", "}" ]
Determines if current source data is file path @return boolean
[ "Determines", "if", "current", "source", "data", "is", "file", "path" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractDecoder.php#L190-L201
220,578
Intervention/image
src/Intervention/Image/AbstractDecoder.php
AbstractDecoder.isDataUrl
public function isDataUrl() { $data = $this->decodeDataUrl($this->data); return is_null($data) ? false : true; }
php
public function isDataUrl() { $data = $this->decodeDataUrl($this->data); return is_null($data) ? false : true; }
[ "public", "function", "isDataUrl", "(", ")", "{", "$", "data", "=", "$", "this", "->", "decodeDataUrl", "(", "$", "this", "->", "data", ")", ";", "return", "is_null", "(", "$", "data", ")", "?", "false", ":", "true", ";", "}" ]
Determines if current source data is data-url @return boolean
[ "Determines", "if", "current", "source", "data", "is", "data", "-", "url" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractDecoder.php#L247-L252
220,579
Intervention/image
src/Intervention/Image/AbstractDecoder.php
AbstractDecoder.isBase64
public function isBase64() { if (!is_string($this->data)) { return false; } return base64_encode(base64_decode($this->data)) === $this->data; }
php
public function isBase64() { if (!is_string($this->data)) { return false; } return base64_encode(base64_decode($this->data)) === $this->data; }
[ "public", "function", "isBase64", "(", ")", "{", "if", "(", "!", "is_string", "(", "$", "this", "->", "data", ")", ")", "{", "return", "false", ";", "}", "return", "base64_encode", "(", "base64_decode", "(", "$", "this", "->", "data", ")", ")", "===", "$", "this", "->", "data", ";", "}" ]
Determines if current source data is base64 encoded @return boolean
[ "Determines", "if", "current", "source", "data", "is", "base64", "encoded" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractDecoder.php#L259-L266
220,580
Intervention/image
src/Intervention/Image/AbstractDecoder.php
AbstractDecoder.decodeDataUrl
private function decodeDataUrl($data_url) { if (!is_string($data_url)) { return null; } $pattern = "/^data:(?:image\/[a-zA-Z\-\.]+)(?:charset=\".+\")?;base64,(?P<data>.+)$/"; preg_match($pattern, $data_url, $matches); if (is_array($matches) && array_key_exists('data', $matches)) { return base64_decode($matches['data']); } return null; }
php
private function decodeDataUrl($data_url) { if (!is_string($data_url)) { return null; } $pattern = "/^data:(?:image\/[a-zA-Z\-\.]+)(?:charset=\".+\")?;base64,(?P<data>.+)$/"; preg_match($pattern, $data_url, $matches); if (is_array($matches) && array_key_exists('data', $matches)) { return base64_decode($matches['data']); } return null; }
[ "private", "function", "decodeDataUrl", "(", "$", "data_url", ")", "{", "if", "(", "!", "is_string", "(", "$", "data_url", ")", ")", "{", "return", "null", ";", "}", "$", "pattern", "=", "\"/^data:(?:image\\/[a-zA-Z\\-\\.]+)(?:charset=\\\".+\\\")?;base64,(?P<data>.+)$/\"", ";", "preg_match", "(", "$", "pattern", ",", "$", "data_url", ",", "$", "matches", ")", ";", "if", "(", "is_array", "(", "$", "matches", ")", "&&", "array_key_exists", "(", "'data'", ",", "$", "matches", ")", ")", "{", "return", "base64_decode", "(", "$", "matches", "[", "'data'", "]", ")", ";", "}", "return", "null", ";", "}" ]
Parses and decodes binary image data from data-url @param string $data_url @return string
[ "Parses", "and", "decodes", "binary", "image", "data", "from", "data", "-", "url" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractDecoder.php#L285-L299
220,581
Intervention/image
src/Intervention/Image/AbstractDecoder.php
AbstractDecoder.init
public function init($data) { $this->data = $data; switch (true) { case $this->isGdResource(): return $this->initFromGdResource($this->data); case $this->isImagick(): return $this->initFromImagick($this->data); case $this->isInterventionImage(): return $this->initFromInterventionImage($this->data); case $this->isSplFileInfo(): return $this->initFromPath($this->data->getRealPath()); case $this->isBinary(): return $this->initFromBinary($this->data); case $this->isUrl(): return $this->initFromUrl($this->data); case $this->isStream(): return $this->initFromStream($this->data); case $this->isDataUrl(): return $this->initFromBinary($this->decodeDataUrl($this->data)); case $this->isFilePath(): return $this->initFromPath($this->data); // isBase64 has to be after isFilePath to prevent false positives case $this->isBase64(): return $this->initFromBinary(base64_decode($this->data)); default: throw new Exception\NotReadableException("Image source not readable"); } }
php
public function init($data) { $this->data = $data; switch (true) { case $this->isGdResource(): return $this->initFromGdResource($this->data); case $this->isImagick(): return $this->initFromImagick($this->data); case $this->isInterventionImage(): return $this->initFromInterventionImage($this->data); case $this->isSplFileInfo(): return $this->initFromPath($this->data->getRealPath()); case $this->isBinary(): return $this->initFromBinary($this->data); case $this->isUrl(): return $this->initFromUrl($this->data); case $this->isStream(): return $this->initFromStream($this->data); case $this->isDataUrl(): return $this->initFromBinary($this->decodeDataUrl($this->data)); case $this->isFilePath(): return $this->initFromPath($this->data); // isBase64 has to be after isFilePath to prevent false positives case $this->isBase64(): return $this->initFromBinary(base64_decode($this->data)); default: throw new Exception\NotReadableException("Image source not readable"); } }
[ "public", "function", "init", "(", "$", "data", ")", "{", "$", "this", "->", "data", "=", "$", "data", ";", "switch", "(", "true", ")", "{", "case", "$", "this", "->", "isGdResource", "(", ")", ":", "return", "$", "this", "->", "initFromGdResource", "(", "$", "this", "->", "data", ")", ";", "case", "$", "this", "->", "isImagick", "(", ")", ":", "return", "$", "this", "->", "initFromImagick", "(", "$", "this", "->", "data", ")", ";", "case", "$", "this", "->", "isInterventionImage", "(", ")", ":", "return", "$", "this", "->", "initFromInterventionImage", "(", "$", "this", "->", "data", ")", ";", "case", "$", "this", "->", "isSplFileInfo", "(", ")", ":", "return", "$", "this", "->", "initFromPath", "(", "$", "this", "->", "data", "->", "getRealPath", "(", ")", ")", ";", "case", "$", "this", "->", "isBinary", "(", ")", ":", "return", "$", "this", "->", "initFromBinary", "(", "$", "this", "->", "data", ")", ";", "case", "$", "this", "->", "isUrl", "(", ")", ":", "return", "$", "this", "->", "initFromUrl", "(", "$", "this", "->", "data", ")", ";", "case", "$", "this", "->", "isStream", "(", ")", ":", "return", "$", "this", "->", "initFromStream", "(", "$", "this", "->", "data", ")", ";", "case", "$", "this", "->", "isDataUrl", "(", ")", ":", "return", "$", "this", "->", "initFromBinary", "(", "$", "this", "->", "decodeDataUrl", "(", "$", "this", "->", "data", ")", ")", ";", "case", "$", "this", "->", "isFilePath", "(", ")", ":", "return", "$", "this", "->", "initFromPath", "(", "$", "this", "->", "data", ")", ";", "// isBase64 has to be after isFilePath to prevent false positives", "case", "$", "this", "->", "isBase64", "(", ")", ":", "return", "$", "this", "->", "initFromBinary", "(", "base64_decode", "(", "$", "this", "->", "data", ")", ")", ";", "default", ":", "throw", "new", "Exception", "\\", "NotReadableException", "(", "\"Image source not readable\"", ")", ";", "}", "}" ]
Initiates new image from mixed data @param mixed $data @return \Intervention\Image\Image
[ "Initiates", "new", "image", "from", "mixed", "data" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractDecoder.php#L307-L347
220,582
Intervention/image
src/Intervention/Image/AbstractColor.php
AbstractColor.format
public function format($type) { switch (strtolower($type)) { case 'rgba': return $this->getRgba(); case 'hex': return $this->getHex('#'); case 'int': case 'integer': return $this->getInt(); case 'array': return $this->getArray(); case 'obj': case 'object': return $this; default: throw new \Intervention\Image\Exception\NotSupportedException( "Color format ({$type}) is not supported." ); } }
php
public function format($type) { switch (strtolower($type)) { case 'rgba': return $this->getRgba(); case 'hex': return $this->getHex('#'); case 'int': case 'integer': return $this->getInt(); case 'array': return $this->getArray(); case 'obj': case 'object': return $this; default: throw new \Intervention\Image\Exception\NotSupportedException( "Color format ({$type}) is not supported." ); } }
[ "public", "function", "format", "(", "$", "type", ")", "{", "switch", "(", "strtolower", "(", "$", "type", ")", ")", "{", "case", "'rgba'", ":", "return", "$", "this", "->", "getRgba", "(", ")", ";", "case", "'hex'", ":", "return", "$", "this", "->", "getHex", "(", "'#'", ")", ";", "case", "'int'", ":", "case", "'integer'", ":", "return", "$", "this", "->", "getInt", "(", ")", ";", "case", "'array'", ":", "return", "$", "this", "->", "getArray", "(", ")", ";", "case", "'obj'", ":", "case", "'object'", ":", "return", "$", "this", ";", "default", ":", "throw", "new", "\\", "Intervention", "\\", "Image", "\\", "Exception", "\\", "NotSupportedException", "(", "\"Color format ({$type}) is not supported.\"", ")", ";", "}", "}" ]
Formats current color instance into given format @param string $type @return mixed
[ "Formats", "current", "color", "instance", "into", "given", "format" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractColor.php#L153-L179
220,583
Intervention/image
src/Intervention/Image/Imagick/Commands/BackupCommand.php
BackupCommand.execute
public function execute($image) { $backupName = $this->argument(0)->value(); // clone current image resource $clone = clone $image; $image->setBackup($clone->getCore(), $backupName); return true; }
php
public function execute($image) { $backupName = $this->argument(0)->value(); // clone current image resource $clone = clone $image; $image->setBackup($clone->getCore(), $backupName); return true; }
[ "public", "function", "execute", "(", "$", "image", ")", "{", "$", "backupName", "=", "$", "this", "->", "argument", "(", "0", ")", "->", "value", "(", ")", ";", "// clone current image resource", "$", "clone", "=", "clone", "$", "image", ";", "$", "image", "->", "setBackup", "(", "$", "clone", "->", "getCore", "(", ")", ",", "$", "backupName", ")", ";", "return", "true", ";", "}" ]
Saves a backups of current state of image core @param \Intervention\Image\Image $image @return boolean
[ "Saves", "a", "backups", "of", "current", "state", "of", "image", "core" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Imagick/Commands/BackupCommand.php#L13-L22
220,584
Intervention/image
src/Intervention/Image/AbstractShape.php
AbstractShape.border
public function border($width, $color = null) { $this->border_width = is_numeric($width) ? intval($width) : 0; $this->border_color = is_null($color) ? '#000000' : $color; }
php
public function border($width, $color = null) { $this->border_width = is_numeric($width) ? intval($width) : 0; $this->border_color = is_null($color) ? '#000000' : $color; }
[ "public", "function", "border", "(", "$", "width", ",", "$", "color", "=", "null", ")", "{", "$", "this", "->", "border_width", "=", "is_numeric", "(", "$", "width", ")", "?", "intval", "(", "$", "width", ")", ":", "0", ";", "$", "this", "->", "border_color", "=", "is_null", "(", "$", "color", ")", "?", "'#000000'", ":", "$", "color", ";", "}" ]
Set border width and color of current shape @param int $width @param string $color @return void
[ "Set", "border", "width", "and", "color", "of", "current", "shape" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/AbstractShape.php#L56-L60
220,585
Intervention/image
src/Intervention/Image/Gd/Commands/CropCommand.php
CropCommand.execute
public function execute($image) { $width = $this->argument(0)->type('digit')->required()->value(); $height = $this->argument(1)->type('digit')->required()->value(); $x = $this->argument(2)->type('digit')->value(); $y = $this->argument(3)->type('digit')->value(); if (is_null($width) || is_null($height)) { throw new \Intervention\Image\Exception\InvalidArgumentException( "Width and height of cutout needs to be defined." ); } $cropped = new Size($width, $height); $position = new Point($x, $y); // align boxes if (is_null($x) && is_null($y)) { $position = $image->getSize()->align('center')->relativePosition($cropped->align('center')); } // crop image core return $this->modify($image, 0, 0, $position->x, $position->y, $cropped->width, $cropped->height, $cropped->width, $cropped->height); }
php
public function execute($image) { $width = $this->argument(0)->type('digit')->required()->value(); $height = $this->argument(1)->type('digit')->required()->value(); $x = $this->argument(2)->type('digit')->value(); $y = $this->argument(3)->type('digit')->value(); if (is_null($width) || is_null($height)) { throw new \Intervention\Image\Exception\InvalidArgumentException( "Width and height of cutout needs to be defined." ); } $cropped = new Size($width, $height); $position = new Point($x, $y); // align boxes if (is_null($x) && is_null($y)) { $position = $image->getSize()->align('center')->relativePosition($cropped->align('center')); } // crop image core return $this->modify($image, 0, 0, $position->x, $position->y, $cropped->width, $cropped->height, $cropped->width, $cropped->height); }
[ "public", "function", "execute", "(", "$", "image", ")", "{", "$", "width", "=", "$", "this", "->", "argument", "(", "0", ")", "->", "type", "(", "'digit'", ")", "->", "required", "(", ")", "->", "value", "(", ")", ";", "$", "height", "=", "$", "this", "->", "argument", "(", "1", ")", "->", "type", "(", "'digit'", ")", "->", "required", "(", ")", "->", "value", "(", ")", ";", "$", "x", "=", "$", "this", "->", "argument", "(", "2", ")", "->", "type", "(", "'digit'", ")", "->", "value", "(", ")", ";", "$", "y", "=", "$", "this", "->", "argument", "(", "3", ")", "->", "type", "(", "'digit'", ")", "->", "value", "(", ")", ";", "if", "(", "is_null", "(", "$", "width", ")", "||", "is_null", "(", "$", "height", ")", ")", "{", "throw", "new", "\\", "Intervention", "\\", "Image", "\\", "Exception", "\\", "InvalidArgumentException", "(", "\"Width and height of cutout needs to be defined.\"", ")", ";", "}", "$", "cropped", "=", "new", "Size", "(", "$", "width", ",", "$", "height", ")", ";", "$", "position", "=", "new", "Point", "(", "$", "x", ",", "$", "y", ")", ";", "// align boxes", "if", "(", "is_null", "(", "$", "x", ")", "&&", "is_null", "(", "$", "y", ")", ")", "{", "$", "position", "=", "$", "image", "->", "getSize", "(", ")", "->", "align", "(", "'center'", ")", "->", "relativePosition", "(", "$", "cropped", "->", "align", "(", "'center'", ")", ")", ";", "}", "// crop image core", "return", "$", "this", "->", "modify", "(", "$", "image", ",", "0", ",", "0", ",", "$", "position", "->", "x", ",", "$", "position", "->", "y", ",", "$", "cropped", "->", "width", ",", "$", "cropped", "->", "height", ",", "$", "cropped", "->", "width", ",", "$", "cropped", "->", "height", ")", ";", "}" ]
Crop an image instance @param \Intervention\Image\Image $image @return boolean
[ "Crop", "an", "image", "instance" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Gd/Commands/CropCommand.php#L16-L39
220,586
Intervention/image
src/Intervention/Image/Commands/ResponseCommand.php
ResponseCommand.execute
public function execute($image) { $format = $this->argument(0)->value(); $quality = $this->argument(1)->between(0, 100)->value(); $response = new Response($image, $format, $quality); $this->setOutput($response->make()); return true; }
php
public function execute($image) { $format = $this->argument(0)->value(); $quality = $this->argument(1)->between(0, 100)->value(); $response = new Response($image, $format, $quality); $this->setOutput($response->make()); return true; }
[ "public", "function", "execute", "(", "$", "image", ")", "{", "$", "format", "=", "$", "this", "->", "argument", "(", "0", ")", "->", "value", "(", ")", ";", "$", "quality", "=", "$", "this", "->", "argument", "(", "1", ")", "->", "between", "(", "0", ",", "100", ")", "->", "value", "(", ")", ";", "$", "response", "=", "new", "Response", "(", "$", "image", ",", "$", "format", ",", "$", "quality", ")", ";", "$", "this", "->", "setOutput", "(", "$", "response", "->", "make", "(", ")", ")", ";", "return", "true", ";", "}" ]
Builds HTTP response from given image @param \Intervention\Image\Image $image @return boolean
[ "Builds", "HTTP", "response", "from", "given", "image" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Commands/ResponseCommand.php#L15-L25
220,587
Intervention/image
src/Intervention/Image/File.php
File.basePath
public function basePath() { if ($this->dirname && $this->basename) { return ($this->dirname .'/'. $this->basename); } return null; }
php
public function basePath() { if ($this->dirname && $this->basename) { return ($this->dirname .'/'. $this->basename); } return null; }
[ "public", "function", "basePath", "(", ")", "{", "if", "(", "$", "this", "->", "dirname", "&&", "$", "this", "->", "basename", ")", "{", "return", "(", "$", "this", "->", "dirname", ".", "'/'", ".", "$", "this", "->", "basename", ")", ";", "}", "return", "null", ";", "}" ]
Get fully qualified path @return string
[ "Get", "fully", "qualified", "path" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/File.php#L83-L90
220,588
Intervention/image
src/Intervention/Image/ImageManagerStatic.php
ImageManagerStatic.canvas
public static function canvas($width, $height, $background = null) { return self::getManager()->canvas($width, $height, $background); }
php
public static function canvas($width, $height, $background = null) { return self::getManager()->canvas($width, $height, $background); }
[ "public", "static", "function", "canvas", "(", "$", "width", ",", "$", "height", ",", "$", "background", "=", "null", ")", "{", "return", "self", "::", "getManager", "(", ")", "->", "canvas", "(", "$", "width", ",", "$", "height", ",", "$", "background", ")", ";", "}" ]
Statically creates an empty image canvas @param int $width @param int $height @param mixed $background @return \Intervention\Image\Image
[ "Statically", "creates", "an", "empty", "image", "canvas" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/ImageManagerStatic.php#L70-L73
220,589
Intervention/image
src/Intervention/Image/ImageManagerStatic.php
ImageManagerStatic.cache
public static function cache(Closure $callback, $lifetime = null, $returnObj = false) { return self::getManager()->cache($callback, $lifetime, $returnObj); }
php
public static function cache(Closure $callback, $lifetime = null, $returnObj = false) { return self::getManager()->cache($callback, $lifetime, $returnObj); }
[ "public", "static", "function", "cache", "(", "Closure", "$", "callback", ",", "$", "lifetime", "=", "null", ",", "$", "returnObj", "=", "false", ")", "{", "return", "self", "::", "getManager", "(", ")", "->", "cache", "(", "$", "callback", ",", "$", "lifetime", ",", "$", "returnObj", ")", ";", "}" ]
Create new cached image and run callback statically @param Closure $callback @param int $lifetime @param boolean $returnObj @return mixed
[ "Create", "new", "cached", "image", "and", "run", "callback", "statically" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/ImageManagerStatic.php#L84-L87
220,590
Intervention/image
src/Intervention/Image/Imagick/Shapes/CircleShape.php
CircleShape.applyToImage
public function applyToImage(Image $image, $x = 0, $y = 0) { return parent::applyToImage($image, $x, $y); }
php
public function applyToImage(Image $image, $x = 0, $y = 0) { return parent::applyToImage($image, $x, $y); }
[ "public", "function", "applyToImage", "(", "Image", "$", "image", ",", "$", "x", "=", "0", ",", "$", "y", "=", "0", ")", "{", "return", "parent", "::", "applyToImage", "(", "$", "image", ",", "$", "x", ",", "$", "y", ")", ";", "}" ]
Draw current circle on given image @param Image $image @param int $x @param int $y @return boolean
[ "Draw", "current", "circle", "on", "given", "image" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Imagick/Shapes/CircleShape.php#L36-L39
220,591
Intervention/image
src/Intervention/Image/Imagick/Shapes/PolygonShape.php
PolygonShape.formatPoints
private function formatPoints($points) { $ipoints = []; $count = 1; foreach ($points as $key => $value) { if ($count%2 === 0) { $y = $value; $ipoints[] = ['x' => $x, 'y' => $y]; } else { $x = $value; } $count++; } return $ipoints; }
php
private function formatPoints($points) { $ipoints = []; $count = 1; foreach ($points as $key => $value) { if ($count%2 === 0) { $y = $value; $ipoints[] = ['x' => $x, 'y' => $y]; } else { $x = $value; } $count++; } return $ipoints; }
[ "private", "function", "formatPoints", "(", "$", "points", ")", "{", "$", "ipoints", "=", "[", "]", ";", "$", "count", "=", "1", ";", "foreach", "(", "$", "points", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "count", "%", "2", "===", "0", ")", "{", "$", "y", "=", "$", "value", ";", "$", "ipoints", "[", "]", "=", "[", "'x'", "=>", "$", "x", ",", "'y'", "=>", "$", "y", "]", ";", "}", "else", "{", "$", "x", "=", "$", "value", ";", "}", "$", "count", "++", ";", "}", "return", "$", "ipoints", ";", "}" ]
Format polygon points to Imagick format @param Array $points @return Array
[ "Format", "polygon", "points", "to", "Imagick", "format" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Imagick/Shapes/PolygonShape.php#L63-L79
220,592
Intervention/image
src/Intervention/Image/Gd/Decoder.php
Decoder.gdResourceToTruecolor
public function gdResourceToTruecolor(&$resource) { $width = imagesx($resource); $height = imagesy($resource); // new canvas $canvas = imagecreatetruecolor($width, $height); // fill with transparent color imagealphablending($canvas, false); $transparent = imagecolorallocatealpha($canvas, 255, 255, 255, 127); imagefilledrectangle($canvas, 0, 0, $width, $height, $transparent); imagecolortransparent($canvas, $transparent); imagealphablending($canvas, true); // copy original imagecopy($canvas, $resource, 0, 0, 0, 0, $width, $height); imagedestroy($resource); $resource = $canvas; return true; }
php
public function gdResourceToTruecolor(&$resource) { $width = imagesx($resource); $height = imagesy($resource); // new canvas $canvas = imagecreatetruecolor($width, $height); // fill with transparent color imagealphablending($canvas, false); $transparent = imagecolorallocatealpha($canvas, 255, 255, 255, 127); imagefilledrectangle($canvas, 0, 0, $width, $height, $transparent); imagecolortransparent($canvas, $transparent); imagealphablending($canvas, true); // copy original imagecopy($canvas, $resource, 0, 0, 0, 0, $width, $height); imagedestroy($resource); $resource = $canvas; return true; }
[ "public", "function", "gdResourceToTruecolor", "(", "&", "$", "resource", ")", "{", "$", "width", "=", "imagesx", "(", "$", "resource", ")", ";", "$", "height", "=", "imagesy", "(", "$", "resource", ")", ";", "// new canvas", "$", "canvas", "=", "imagecreatetruecolor", "(", "$", "width", ",", "$", "height", ")", ";", "// fill with transparent color", "imagealphablending", "(", "$", "canvas", ",", "false", ")", ";", "$", "transparent", "=", "imagecolorallocatealpha", "(", "$", "canvas", ",", "255", ",", "255", ",", "255", ",", "127", ")", ";", "imagefilledrectangle", "(", "$", "canvas", ",", "0", ",", "0", ",", "$", "width", ",", "$", "height", ",", "$", "transparent", ")", ";", "imagecolortransparent", "(", "$", "canvas", ",", "$", "transparent", ")", ";", "imagealphablending", "(", "$", "canvas", ",", "true", ")", ";", "// copy original", "imagecopy", "(", "$", "canvas", ",", "$", "resource", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "width", ",", "$", "height", ")", ";", "imagedestroy", "(", "$", "resource", ")", ";", "$", "resource", "=", "$", "canvas", ";", "return", "true", ";", "}" ]
Transform GD resource into Truecolor version @param resource $resource @return bool
[ "Transform", "GD", "resource", "into", "Truecolor", "version" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Gd/Decoder.php#L130-L152
220,593
Intervention/image
src/Intervention/Image/Commands/Argument.php
Argument.getCommandName
public function getCommandName() { preg_match("/\\\\([\w]+)Command$/", get_class($this->command), $matches); return isset($matches[1]) ? lcfirst($matches[1]).'()' : 'Method'; }
php
public function getCommandName() { preg_match("/\\\\([\w]+)Command$/", get_class($this->command), $matches); return isset($matches[1]) ? lcfirst($matches[1]).'()' : 'Method'; }
[ "public", "function", "getCommandName", "(", ")", "{", "preg_match", "(", "\"/\\\\\\\\([\\w]+)Command$/\"", ",", "get_class", "(", "$", "this", "->", "command", ")", ",", "$", "matches", ")", ";", "return", "isset", "(", "$", "matches", "[", "1", "]", ")", "?", "lcfirst", "(", "$", "matches", "[", "1", "]", ")", ".", "'()'", ":", "'Method'", ";", "}" ]
Returns name of current arguments command @return string
[ "Returns", "name", "of", "current", "arguments", "command" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Commands/Argument.php#L38-L42
220,594
Intervention/image
src/Intervention/Image/Commands/Argument.php
Argument.value
public function value($default = null) { $arguments = $this->command->arguments; if (is_array($arguments)) { return isset($arguments[$this->key]) ? $arguments[$this->key] : $default; } return $default; }
php
public function value($default = null) { $arguments = $this->command->arguments; if (is_array($arguments)) { return isset($arguments[$this->key]) ? $arguments[$this->key] : $default; } return $default; }
[ "public", "function", "value", "(", "$", "default", "=", "null", ")", "{", "$", "arguments", "=", "$", "this", "->", "command", "->", "arguments", ";", "if", "(", "is_array", "(", "$", "arguments", ")", ")", "{", "return", "isset", "(", "$", "arguments", "[", "$", "this", "->", "key", "]", ")", "?", "$", "arguments", "[", "$", "this", "->", "key", "]", ":", "$", "default", ";", "}", "return", "$", "default", ";", "}" ]
Returns value of current argument @param mixed $default @return mixed
[ "Returns", "value", "of", "current", "argument" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Commands/Argument.php#L50-L59
220,595
Intervention/image
src/Intervention/Image/Image.php
Image.encode
public function encode($format = null, $quality = 90) { return $this->driver->encode($this, $format, $quality); }
php
public function encode($format = null, $quality = 90) { return $this->driver->encode($this, $format, $quality); }
[ "public", "function", "encode", "(", "$", "format", "=", "null", ",", "$", "quality", "=", "90", ")", "{", "return", "$", "this", "->", "driver", "->", "encode", "(", "$", "this", ",", "$", "format", ",", "$", "quality", ")", ";", "}" ]
Starts encoding of current image @param string $format @param int $quality @return \Intervention\Image\Image
[ "Starts", "encoding", "of", "current", "image" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Image.php#L117-L120
220,596
Intervention/image
src/Intervention/Image/Image.php
Image.save
public function save($path = null, $quality = null) { $path = is_null($path) ? $this->basePath() : $path; if (is_null($path)) { throw new Exception\NotWritableException( "Can't write to undefined path." ); } $data = $this->encode(pathinfo($path, PATHINFO_EXTENSION), $quality); $saved = @file_put_contents($path, $data); if ($saved === false) { throw new Exception\NotWritableException( "Can't write image data to path ({$path})" ); } // set new file info $this->setFileInfoFromPath($path); return $this; }
php
public function save($path = null, $quality = null) { $path = is_null($path) ? $this->basePath() : $path; if (is_null($path)) { throw new Exception\NotWritableException( "Can't write to undefined path." ); } $data = $this->encode(pathinfo($path, PATHINFO_EXTENSION), $quality); $saved = @file_put_contents($path, $data); if ($saved === false) { throw new Exception\NotWritableException( "Can't write image data to path ({$path})" ); } // set new file info $this->setFileInfoFromPath($path); return $this; }
[ "public", "function", "save", "(", "$", "path", "=", "null", ",", "$", "quality", "=", "null", ")", "{", "$", "path", "=", "is_null", "(", "$", "path", ")", "?", "$", "this", "->", "basePath", "(", ")", ":", "$", "path", ";", "if", "(", "is_null", "(", "$", "path", ")", ")", "{", "throw", "new", "Exception", "\\", "NotWritableException", "(", "\"Can't write to undefined path.\"", ")", ";", "}", "$", "data", "=", "$", "this", "->", "encode", "(", "pathinfo", "(", "$", "path", ",", "PATHINFO_EXTENSION", ")", ",", "$", "quality", ")", ";", "$", "saved", "=", "@", "file_put_contents", "(", "$", "path", ",", "$", "data", ")", ";", "if", "(", "$", "saved", "===", "false", ")", "{", "throw", "new", "Exception", "\\", "NotWritableException", "(", "\"Can't write image data to path ({$path})\"", ")", ";", "}", "// set new file info", "$", "this", "->", "setFileInfoFromPath", "(", "$", "path", ")", ";", "return", "$", "this", ";", "}" ]
Saves encoded image in filesystem @param string $path @param int $quality @return \Intervention\Image\Image
[ "Saves", "encoded", "image", "in", "filesystem" ]
a8fca2aeead8168c16cd36b2507ed520d3f4fc66
https://github.com/Intervention/image/blob/a8fca2aeead8168c16cd36b2507ed520d3f4fc66/src/Intervention/Image/Image.php#L129-L152
220,597
Maatwebsite/Laravel-Excel
src/Reader.php
Reader.garbageCollect
private function garbageCollect() { $this->setDefaultValueBinder(); // Force garbage collecting unset($this->sheetImports, $this->spreadsheet); $this->currentFile->delete(); }
php
private function garbageCollect() { $this->setDefaultValueBinder(); // Force garbage collecting unset($this->sheetImports, $this->spreadsheet); $this->currentFile->delete(); }
[ "private", "function", "garbageCollect", "(", ")", "{", "$", "this", "->", "setDefaultValueBinder", "(", ")", ";", "// Force garbage collecting", "unset", "(", "$", "this", "->", "sheetImports", ",", "$", "this", "->", "spreadsheet", ")", ";", "$", "this", "->", "currentFile", "->", "delete", "(", ")", ";", "}" ]
Garbage collect.
[ "Garbage", "collect", "." ]
1e502de0a3265704b7c48b8f0dbe67cb7fe5b71f
https://github.com/Maatwebsite/Laravel-Excel/blob/1e502de0a3265704b7c48b8f0dbe67cb7fe5b71f/src/Reader.php#L412-L420
220,598
Maatwebsite/Laravel-Excel
src/HasEventBus.php
HasEventBus.registerListeners
public function registerListeners(array $listeners) { foreach ($listeners as $event => $listener) { $this->events[$event][] = $listener; } }
php
public function registerListeners(array $listeners) { foreach ($listeners as $event => $listener) { $this->events[$event][] = $listener; } }
[ "public", "function", "registerListeners", "(", "array", "$", "listeners", ")", "{", "foreach", "(", "$", "listeners", "as", "$", "event", "=>", "$", "listener", ")", "{", "$", "this", "->", "events", "[", "$", "event", "]", "[", "]", "=", "$", "listener", ";", "}", "}" ]
Register local event listeners. @param array $listeners
[ "Register", "local", "event", "listeners", "." ]
1e502de0a3265704b7c48b8f0dbe67cb7fe5b71f
https://github.com/Maatwebsite/Laravel-Excel/blob/1e502de0a3265704b7c48b8f0dbe67cb7fe5b71f/src/HasEventBus.php#L22-L27
220,599
swooletw/laravel-swoole
src/Server/Manager.php
Manager.bindToLaravelApp
protected function bindToLaravelApp() { $this->bindSandbox(); $this->bindSwooleTable(); if ($this->isServerWebsocket) { $this->bindRoom(); $this->bindWebsocket(); } }
php
protected function bindToLaravelApp() { $this->bindSandbox(); $this->bindSwooleTable(); if ($this->isServerWebsocket) { $this->bindRoom(); $this->bindWebsocket(); } }
[ "protected", "function", "bindToLaravelApp", "(", ")", "{", "$", "this", "->", "bindSandbox", "(", ")", ";", "$", "this", "->", "bindSwooleTable", "(", ")", ";", "if", "(", "$", "this", "->", "isServerWebsocket", ")", "{", "$", "this", "->", "bindRoom", "(", ")", ";", "$", "this", "->", "bindWebsocket", "(", ")", ";", "}", "}" ]
Set bindings to Laravel app.
[ "Set", "bindings", "to", "Laravel", "app", "." ]
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Manager.php#L307-L316