_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q258900 | Note.getModelClassAndId | test | protected function getModelClassAndId()
{
$oInput = Factory::service('Input');
$sModelName = $oInput->get('model_name') ?: $oInput->post('model_name');
$sModelProvider = $oInput->get('model_provider') ?: $oInput->post('model_provider');
$iItemId = (int) $oInput->get('item_id');
try {
$oModel = Factory::model($sModelName, $sModelProvider);
$sModel = get_class($oModel);
} catch (\Exception $e) {
throw new ApiException('"' . $sModelProvider . ':' . $sModelName . '" is not a valid model');
}
return [$sModel, $iItemId];
} | php | {
"resource": ""
} |
q258901 | Note.formatObject | test | protected function formatObject($oObj)
{
return (object) [
'id' => $oObj->id,
'message' => auto_typography($oObj->message),
'date' => toUserDatetime($oObj->created),
'user' => (object) [
'id' => $oObj->created_by ? (int) $oObj->created_by->id : null,
'first_name' => $oObj->created_by ? $oObj->created_by->first_name : null,
'last_name' => $oObj->created_by ? $oObj->created_by->last_name : null,
],
];
} | php | {
"resource": ""
} |
q258902 | SimpleCalendar.setDate | test | public function setDate( $date_string = null ) {
if( $date_string ) {
$this->now = getdate(strtotime($date_string));
} else {
$this->now = getdate();
}
} | php | {
"resource": ""
} |
q258903 | SimpleCalendar.addDailyHtml | test | public function addDailyHtml( $html, $start_date_string, $end_date_string = null ) {
static $htmlCount = 0;
$start_date = strtotime($start_date_string);
if( $end_date_string ) {
$end_date = strtotime($end_date_string);
} else {
$end_date = $start_date;
}
$working_date = $start_date;
do {
$tDate = getdate($working_date);
$working_date += 86400;
$this->dailyHtml[$tDate['year']][$tDate['mon']][$tDate['mday']][$htmlCount] = $html;
} while( $working_date < $end_date + 1 );
$htmlCount++;
} | php | {
"resource": ""
} |
q258904 | SimpleCalendar.setStartOfWeek | test | public function setStartOfWeek( $offset ) {
if( is_int($offset) ) {
$this->offset = $offset % 7;
} else {
$this->offset = date('N', strtotime($offset)) % 7;
}
} | php | {
"resource": ""
} |
q258905 | Debug.p | test | public static function p($str, $args = false)
{
if (self::$_debug === true || ApiConfig::get('debug') === true) {
// first call
if (self::$_debug === false) {
self::$_debug = true;
}
if ($args !== false) {
$str .= ', dump: ' . var_export($args, true);
}
$str .= ".\n";
print_r('> ' . $str);
}
} | php | {
"resource": ""
} |
q258906 | Payments.submitBonus | test | public function submitBonus($teamReference, $params)
{
ApiDebug::p(__FUNCTION__);
$adjustments = $this->_client->post('/hr/v2/teams/' . $teamReference . '/adjustments', $params);
ApiDebug::p('found adjustments info', $adjustments);
return $adjustments;
} | php | {
"resource": ""
} |
q258907 | Engagement.assign | test | public function assign($company, $team, $engagement, $params)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->put('/otask/v1/tasks/companies/' .$company . '/teams/' . $team . '/engagements/' . $engagement . '/tasks', $params);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258908 | Engagement.assignToEngagement | test | public function assignToEngagement($engagement, $params)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->put('/tasks/v2/tasks/contracts/' . $engagement, $params);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258909 | Earnings.getByFreelancer | test | public function getByFreelancer($freelancerReference, $params)
{
ApiDebug::p(__FUNCTION__);
$report = $this->_client->get('/finreports/v2/providers/' . $freelancerReference . '/earnings', $params);
ApiDebug::p('found report info', $report);
return $report;
} | php | {
"resource": ""
} |
q258910 | Earnings.getByFreelancersTeam | test | public function getByFreelancersTeam($freelancerTeamReference, $params)
{
ApiDebug::p(__FUNCTION__);
$report = $this->_client->get('/finreports/v2/provider_teams/' . $freelancerTeamReference . '/earnings', $params);
ApiDebug::p('found report info', $report);
return $report;
} | php | {
"resource": ""
} |
q258911 | Earnings.getByFreelancersCompany | test | public function getByFreelancersCompany($freelancerCompanyReference, $params)
{
ApiDebug::p(__FUNCTION__);
$report = $this->_client->get('/finreports/v2/provider_companies/' . $freelancerCompanyReference . '/earnings', $params);
ApiDebug::p('found report info', $report);
return $report;
} | php | {
"resource": ""
} |
q258912 | Earnings.getByBuyersTeam | test | public function getByBuyersTeam($buyerTeamReference, $params)
{
ApiDebug::p(__FUNCTION__);
$report = $this->_client->get('/finreports/v2/buyer_teams/' . $buyerTeamReference . '/earnings', $params);
ApiDebug::p('found report info', $report);
return $report;
} | php | {
"resource": ""
} |
q258913 | Earnings.getByBuyersCompany | test | public function getByBuyersCompany($buyerCompanyReference, $params)
{
ApiDebug::p(__FUNCTION__);
$report = $this->_client->get('/finreports/v2/buyer_companies/' . $buyerCompanyReference . '/earnings', $params);
ApiDebug::p('found report info', $report);
return $report;
} | php | {
"resource": ""
} |
q258914 | Engagements.getList | test | public function getList($params)
{
ApiDebug::p(__FUNCTION__);
$engagements = $this->_client->get('/hr/v2/engagements', $params);
ApiDebug::p('found response info', $engagements);
return $engagements;
} | php | {
"resource": ""
} |
q258915 | Engagements.getSpecific | test | public function getSpecific($reference)
{
ApiDebug::p(__FUNCTION__);
$engagement = $this->_client->get('/hr/v2/engagements/' . $reference);
ApiDebug::p('found response info', $engagement);
return $engagement;
} | php | {
"resource": ""
} |
q258916 | Utils.getFullUrl | test | static public function getFullUrl($url, $ep = null)
{
ApiDebug::p('create full url, based on global constant');
$name = ($ep)
? 'UPWORK_BASE_URL_' . strtoupper($ep)
: 'UPWORK_BASE_URL';
$fullUrl = constant($name) . $url;
ApiDebug::p('url', $fullUrl);
return $fullUrl;
} | php | {
"resource": ""
} |
q258917 | Offers.getList | test | public function getList($params)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/offers/v1/contractors/offers', $params);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258918 | Offers.actions | test | public function actions($reference, $params)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->post('/offers/v1/contractors/actions/' . $reference, $params);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258919 | Accounts.getSpecific | test | public function getSpecific($entityReference, $params)
{
ApiDebug::p(__FUNCTION__);
$report = $this->_client->get('/finreports/v2/financial_accounts/' . $entityReference, $params);
ApiDebug::p('found auth info', $report);
return $report;
} | php | {
"resource": ""
} |
q258920 | Roles.getAll | test | public function getAll()
{
ApiDebug::p(__FUNCTION__);
$roles = $this->_client->get('/hr/v2/userroles');
ApiDebug::p('found response info', $roles);
return $roles;
} | php | {
"resource": ""
} |
q258921 | Roles.getBySpecificUser | test | public function getBySpecificUser($reference)
{
ApiDebug::p(__FUNCTION__);
$roles = $this->_client->get('/hr/v2/userroles/' . $reference);
ApiDebug::p('found auth info', $roles);
return $roles;
} | php | {
"resource": ""
} |
q258922 | Interviews.invite | test | public function invite($jobKey, $params)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->post('/hr/v1/jobs/' . $jobKey . '/candidates', $params);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258923 | Time.getByAgency | test | public function getByAgency($company, $agency, $params)
{
ApiDebug::p(__FUNCTION__);
return $this->_getByType($company, null, $agency, $params);
} | php | {
"resource": ""
} |
q258924 | Time.getByCompany | test | public function getByCompany($company, $params)
{
ApiDebug::p(__FUNCTION__);
return $this->_getByType($company, null, null, $params);
} | php | {
"resource": ""
} |
q258925 | Teams.getUsersInTeam | test | public function getUsersInTeam($teamReference)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/hr/v2/teams/' . $teamReference . '/users');
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258926 | Jobs.getList | test | public function getList($params)
{
ApiDebug::p(__FUNCTION__);
$jobs = $this->_client->get('/hr/v2/jobs', $params);
ApiDebug::p('found response info', $jobs);
return $jobs;
} | php | {
"resource": ""
} |
q258927 | Jobs.getSpecific | test | public function getSpecific($key)
{
ApiDebug::p(__FUNCTION__);
$job = $this->_client->get('/hr/v2/jobs/' . $key);
ApiDebug::p('found response info', $job);
return $job;
} | php | {
"resource": ""
} |
q258928 | Jobs.postJob | test | public function postJob($params)
{
ApiDebug::p(__FUNCTION__);
$job = $this->_client->post('/hr/v2/jobs', $params);
ApiDebug::p('found response info', $job);
return $job;
} | php | {
"resource": ""
} |
q258929 | Jobs.editJob | test | public function editJob($key, $params)
{
ApiDebug::p(__FUNCTION__);
$job = $this->_client->put('/hr/v2/jobs/' . $key, $params);
ApiDebug::p('found response info', $job);
return $job;
} | php | {
"resource": ""
} |
q258930 | Jobs.deleteJob | test | public function deleteJob($key, $params)
{
ApiDebug::p(__FUNCTION__);
$job = $this->_client->delete('/hr/v2/jobs/' . $key, $params);
ApiDebug::p('found response info', $job);
return $job;
} | php | {
"resource": ""
} |
q258931 | Users.getMyInfo | test | public function getMyInfo()
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/hr/v2/users/me');
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258932 | Users.getSpecific | test | public function getSpecific($userReference)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/hr/v2/users/' . $userReference);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258933 | Team._getByType | test | private function _getByType($company, $team, $code = null)
{
ApiDebug::p(__FUNCTION__);
$_url = '';
if (!empty($code)) {
$_url = '/' . $code;
}
$response = $this->_client->get('/otask/v1/tasks/companies/' . $company . '/teams/' . $team . '/tasks' . $_url);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258934 | Messages.getRoomDetails | test | public function getRoomDetails($company, $roomId, $params = array())
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/messages/v3/' . $company . '/rooms/' . $roomId, $params);
ApiDebug::p('received data', $response);
return $response;
} | php | {
"resource": ""
} |
q258935 | Messages.getRoomByOffer | test | public function getRoomByOffer($company, $offerId, $params = array())
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/messages/v3/' . $company . '/rooms/offers/' . $offerId, $params);
ApiDebug::p('received data', $response);
return $response;
} | php | {
"resource": ""
} |
q258936 | Messages.getRoomByApplication | test | public function getRoomByApplication($company, $applicationId, $params = array())
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/messages/v3/' . $company . '/rooms/applications/' . $applicationId, $params);
ApiDebug::p('received data', $response);
return $response;
} | php | {
"resource": ""
} |
q258937 | Messages.getRoomByContract | test | public function getRoomByContract($company, $contractId, $params = array())
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/messages/v3/' . $company . '/rooms/contracts/' . $contractId, $params);
ApiDebug::p('received data', $response);
return $response;
} | php | {
"resource": ""
} |
q258938 | Messages.createRoom | test | public function createRoom($company, $params = array())
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->post('/messages/v3/' . $company . '/rooms', $params);
ApiDebug::p('received data', $response);
return $response;
} | php | {
"resource": ""
} |
q258939 | Messages.sendMessageToRoom | test | public function sendMessageToRoom($company, $roomId, $params = array())
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->post('/messages/v3/' . $company . '/rooms/' . $roomId . '/stories', $params);
ApiDebug::p('received data', $response);
return $response;
} | php | {
"resource": ""
} |
q258940 | Messages.updateRoomSettings | test | public function updateRoomSettings($company, $roomId, $username, $params = array())
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->put('/messages/v3/' . $company . '/rooms/' . $roomId . '/users/' . $username, $params);
ApiDebug::p('received data', $response);
return $response;
} | php | {
"resource": ""
} |
q258941 | Messages.updateRoomMetadata | test | public function updateRoomMetadata($company, $roomId, $params = array())
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->put('/messages/v3/' . $company . '/rooms/' . $roomId, $params);
ApiDebug::p('received data', $response);
return $response;
} | php | {
"resource": ""
} |
q258942 | Snapshot.getByContract | test | public function getByContract($contractId, $ts)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/team/v3/snapshots/contracts/' . $contractId . '/' . $ts);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258943 | Snapshot.updateByContract | test | public function updateByContract($contractId, $ts, $params)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->put('/team/v3/snapshots/contracts/' . $contractId . '/' . $ts, $params);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258944 | Snapshot.deleteByContract | test | public function deleteByContract($contractId, $ts)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->delete('/team/v3/snapshots/contracts/' . $contractId . '/' . $ts);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258945 | Milestones.getActiveMilestone | test | public function getActiveMilestone($contractId)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/hr/v3/fp/milestones/statuses/active/contracts/' . $contractId);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258946 | Milestones.getSubmissions | test | public function getSubmissions($milestoneId)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->get('/hr/v3/fp/milestones/' . $milestoneId . '/submissions');
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258947 | Milestones.create | test | public function create($params)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->post('/hr/v3/fp/milestones', $params);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258948 | Milestones.edit | test | public function edit($milestoneId, $params)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->put('/hr/v3/fp/milestones/' . $milestoneId, $params);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258949 | Milestones.delete | test | public function delete($milestoneId)
{
ApiDebug::p(__FUNCTION__);
$response = $this->_client->delete('/hr/v3/fp/milestones/' . $milestoneId);
ApiDebug::p('found response info', $response);
return $response;
} | php | {
"resource": ""
} |
q258950 | Client._request | test | protected function _request($type, $url, $params = array())
{
ApiDebug::p('running Client request', $this->_server);
$method = 'POST';
switch ($type) {
case 'PUT':
$params['http_method'] = 'put';
break;
case 'DELETE':
$params['http_method'] = 'delete';
break;
case 'GET':
$method = 'GET';
break;
default:
break;
}
if (self::$_epoint == UPWORK_API_EP_NAME) {
$url = $url . '.' . self::DATA_FORMAT;
} elseif (self::$_epoint == UPWORK_GDS_EP_NAME) {
$params['tqx'] = 'out:' . self::DATA_FORMAT;
}
$this->_server->option('sigMethod', ApiConfig::get('sigMethod'));
$this->_server->option('epoint', self::$_epoint);
$response = $this->_server->request($method, $url, $params);
return json_decode($response);
} | php | {
"resource": ""
} |
q258951 | FacebookAccountKitServiceProvider.boot | test | public function boot()
{
$config = realpath(__DIR__ . '/../resources/config/accountKit.php');
$js = realpath(__DIR__ . '/../resources/config/accountkit.js');
$this->publishes([
$config => config_path('accountKit.php')
], 'config');
$this->publishes([
$js => public_path('js/accountkit.js')
], 'public');
} | php | {
"resource": ""
} |
q258952 | AccountKit.getContentBody | test | private function getContentBody($url)
{
$data = $this->client->request('GET', $url);
return json_decode($data->getBody());
} | php | {
"resource": ""
} |
q258953 | FacebookAccountKit.accountKitData | test | public function accountKitData($code)
{
$data = $this->data($code);
$output = [
'id' => $data->id,
'phoneNumber' => '',
'email' => '',
];
if (array_key_exists('phone', $data)) {
$output['phoneNumber'] = $data->phone->number ?? null;
}
if (array_key_exists('email', $data)) {
$output['email'] = $data->email->address ?? null;
}
return $output;
} | php | {
"resource": ""
} |
q258954 | ContactResourceController.index | test | public function index(ContactRequest $request)
{
if ($this->response->typeIs('json')) {
$pageLimit = $request->input('pageLimit');
$data = $this->repository
->setPresenter(\Litecms\Contact\Repositories\Presenter\ContactListPresenter::class)
->getDataTable($pageLimit);
return $this->response
->data($data)
->output();
}
$contacts = $this->repository->paginate();
$this->response->theme->asset()->container('footer')->add('gmap', 'https://maps.googleapis.com/maps/api/js?key=' . config('litecms.contact.gmapapi'));
return $this->response->setMetaTitle(trans('contact::contact.names'))
->view('contact::contact.index', true)
->data(compact('contacts'))
->output();
} | php | {
"resource": ""
} |
q258955 | ContactResourceController.show | test | public function show(ContactRequest $request, Contact $contact)
{
if ($contact->exists) {
$view = 'contact::contact.show';
} else {
$view = 'contact::contact.new';
}
return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('contact::contact.name'))
->data(compact('contact'))
->view($view)
->output();
} | php | {
"resource": ""
} |
q258956 | ContactResourceController.create | test | public function create(ContactRequest $request)
{
$contact = $this->repository->newInstance([]);
return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('contact::contact.name'))
->view('contact::contact.create', true)
->data(compact('contact'))
->output();
} | php | {
"resource": ""
} |
q258957 | ContactResourceController.edit | test | public function edit(ContactRequest $request, Contact $contact)
{
return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('contact::contact.name'))
->view('contact::contact.edit', true)
->data(compact('contact'))
->output();
} | php | {
"resource": ""
} |
q258958 | ContactResourceController.update | test | public function update(ContactRequest $request, Contact $contact)
{
try {
$attributes = $request->all();
$contact->update($attributes);
return $this->response->message(trans('messages.success.updated', ['Module' => trans('contact::contact.name')]))
->code(204)
->status('success')
->url(guard_url('contact/contact/' . $contact->getRouteKey()))
->redirect();
} catch (Exception $e) {
return $this->response->message($e->getMessage())
->code(400)
->status('error')
->url(guard_url('contact/contact/' . $contact->getRouteKey()))
->redirect();
}
} | php | {
"resource": ""
} |
q258959 | ContactResourceController.destroy | test | public function destroy(ContactRequest $request, Contact $contact)
{
try {
$contact->delete();
return $this->response->message(trans('messages.success.deleted', ['Module' => trans('contact::contact.name')]))
->code(202)
->status('success')
->url(guard_url('contact/contact'))
->redirect();
} catch (Exception $e) {
return $this->response->message($e->getMessage())
->code(400)
->status('error')
->url(guard_url('contact/contact/' . $contact->getRouteKey()))
->redirect();
}
} | php | {
"resource": ""
} |
q258960 | Contact.gadget | test | public function gadget($view = 'admin.contact.gadget', $count = 10)
{
if (User::hasRole('user')) {
$this->contact->pushCriteria(new \Litecms\Litecms\Repositories\Criteria\ContactUserCriteria());
}
$contact = $this->contact->scopeQuery(function ($query) use ($count) {
return $query->orderBy('id', 'DESC')->take($count);
})->all();
return view('contact::' . $view, compact('contact'))->render();
} | php | {
"resource": ""
} |
q258961 | Contact.get | test | public function get($field)
{
$data= $this->contact->scopeQuery(function($query){
return $query->orderBy('id','DESC');
})->first([$field]);
return $data[$field];
} | php | {
"resource": ""
} |
q258962 | ContactPolicy.view | test | public function view(User $user, Contact $contact)
{
if ($user->canDo('contact.contact.view') && $user->isAdmin()) {
return true;
}
} | php | {
"resource": ""
} |
q258963 | ContactPolicy.update | test | public function update(User $user, Contact $contact)
{
if ($user->canDo('contact.contact.update') && $user->isAdmin()) {
return true;
}
} | php | {
"resource": ""
} |
q258964 | ContactPolicy.destroy | test | public function destroy(User $user, Contact $contact)
{
if ($user->canDo('contact.contact.delete') && $user->isAdmin()) {
return true;
}
} | php | {
"resource": ""
} |
q258965 | ContactPublicController.index | test | protected function index()
{
$this->response->theme->asset()->container('footer')->add('gmap', 'https://maps.googleapis.com/maps/api/js?key=' . config('litecms.contact.gmapapi'));
$contact = $this->repository
->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria'))
->scopeQuery(function ($query) {
return $query->orderBy('id', 'DESC');
})->first();
return $this->response->setMetaTitle(trans('contact::contact.names'))
->view('contact::index')
->populate(false)
->data(compact('contact'))
->output();
} | php | {
"resource": ""
} |
q258966 | HtmlParser.parseHtml | test | protected function parseHtml(LinkInterface $link)
{
$images = [];
try {
$parser = new Crawler();
$parser->addHtmlContent($link->getContent());
// Parse all known tags
foreach($this->tags as $tag => $selectors) {
foreach($selectors as $selector) {
if ($parser->filter($selector['selector'])->count() > 0) {
if (isset($selector['attribute'])) {
${$tag} = $parser->filter($selector['selector'])->first()->attr($selector['attribute']);
} else {
${$tag} = $parser->filter($selector['selector'])->first()->text();
}
break;
}
}
// Default is empty string
if (!isset(${$tag})) ${$tag} = '';
}
// Parse all images on this page
foreach($parser->filter('img') as $image) {
if (!$image->hasAttribute('src')) continue;
if (filter_var($image->getAttribute('src'), FILTER_VALIDATE_URL) === false) continue;
// This is not bulletproof, actual image maybe bigger than tags
if ($image->hasAttribute('width') && $image->getAttribute('width') < $this->imageMinimumWidth) continue;
if ($image->hasAttribute('height') && $image->getAttribute('height') < $this->imageMinimumHeight) continue;
$images[] = $image->getAttribute('src');
}
} catch (\InvalidArgumentException $e) {
// Ignore exceptions
}
$images = array_unique($images);
if (!isset($cover) && count($images)) $cover = $images[0];
return compact('cover', 'title', 'description', 'images', 'video', 'videoType');
} | php | {
"resource": ""
} |
q258967 | Client.getPreviews | test | public function getPreviews()
{
$parsed = [];
foreach ($this->getParsers() as $name => $parser) {
if ($parser->canParseLink($this->link))
$parsed[$name] = $parser->parseLink($this->link)->getPreview();
}
return $parsed;
} | php | {
"resource": ""
} |
q258968 | Client.getPreview | test | public function getPreview($parserId)
{
if (array_key_exists($parserId, $this->getParsers())) {
$parser = $this->getParsers()[$parserId];
} else throw new UnknownParserException();
return $parser->parseLink($this->link)->getPreview();
} | php | {
"resource": ""
} |
q258969 | Client.addParser | test | public function addParser(ParserInterface $parser)
{
$this->parsers = [(string) $parser => $parser] + $this->parsers;
return $this;
} | php | {
"resource": ""
} |
q258970 | Client.removeParser | test | public function removeParser($name)
{
if (in_array($name, $this->parsers, false)) {
unset($this->parsers[$name]);
}
return $this;
} | php | {
"resource": ""
} |
q258971 | Client.addDefaultParsers | test | protected function addDefaultParsers()
{
$this->addParser(new HtmlParser());
$this->addParser(new YouTubeParser());
$this->addParser(new VimeoParser());
} | php | {
"resource": ""
} |
q258972 | Color.contrastFromHex | test | public function contrastFromHex($hex)
{
$hash = '';
if (substr($hex, 0, 1) === '#') {
$hash = '#';
$hex = substr($hex, 1);
}
$color = $this->contrastFromRGB(...sscanf($hex, '%02x%02x%02x'));
return sprintf('%s%02x%02x%02x', $hash, $color['r'], $color['g'], $color['b']);
} | php | {
"resource": ""
} |
q258973 | FileSystem.enclosePath | test | public function enclosePath($path)
{
// Add starting slash.
if (substr($path, 0, 1) !== '/') {
$path = '/'.$path;
}
// Add trailing slash.
if (substr($path, -1, 1) !== '/') {
$path .= '/';
}
return $path;
} | php | {
"resource": ""
} |
q258974 | Database.convertInterval | test | public function convertInterval($interval)
{
switch (strtolower($interval)) {
case 'y':
case 'year':
$interval = 'YEAR';
break;
case 'm':
case 'month':
$interval = 'MONTH';
break;
case 'd':
case 'day':
$interval = 'DAY';
break;
case 'h':
case 'hour':
$interval = 'HOUR';
break;
case 'i':
case 'min':
case 'minute':
$iterval = 'MINUTE';
break;
case 's':
case 'sec':
case 'second':
$interval = 'SECOND';
break;
default:
$interval = false;
}
return $interval;
} | php | {
"resource": ""
} |
q258975 | MacroServiceProvider.boot | test | public function boot()
{
// Providesd the ability to download a file from a given path.
// Will also return a not modified header if file has not changed.
Response::macro('downloadAndCache', function ($file_path) {
if (!empty(request()->header('If-Modified-Since'))) {
$cache_last_modified = strtotime(request()->header('If-Modified-Since'));
$file_last_modified = filemtime($file_path);
if ($file_last_modified == $cache_last_modified) {
header('HTTP/1.1 304 Not Modified');
exit();
}
}
return Response::file($file_path);
});
} | php | {
"resource": ""
} |
q258976 | Timezone.data | test | public static function data($config = [])
{
foreach (self::$regions as $region => $mask) {
$zones = DateTimeZone::listIdentifiers($mask);
foreach ($zones as $timezone) {
// Time at this timezone.
$time = Carbon::now($timezone);
// Convert timezone to human readable.
$offset = '('.app('Human')->timeOffset($time->offsetHours).')';
// Default name.
$name = $timezone;
// Remove the region from the name.
if (array_get($config, 'remove-region', false)) {
$name = substr($timezone, strlen($region) + 1);
}
// Remove the offset.
if (array_get($config, 'remove-offset', false)) {
$offset = '';
}
// Show the time.
$current_time = '';
if (array_get($config, 'show-time', false)) {
$current_time = $time->format(array_get($config, 'show-time-format', 'g:ia'));
}
// Place entry.
array_set($timezones, strtoupper($region).'.'.$timezone, sprintf('%s %s %s',
$name,
$offset,
$current_time
));
}
}
return $timezones;
} | php | {
"resource": ""
} |
q258977 | Timezone.optionsArray | test | public static function optionsArray($config = [])
{
$data = self::data($config);
$result = [];
foreach ($data as $name => $zones) {
if (array_get($config, 'include-region', false)) {
$result[] = [array_get($config, 'region-value', null), $name];
}
foreach ($zones as $timezone => $zone) {
$result[] = [$timezone, $zone];
}
}
return $result;
} | php | {
"resource": ""
} |
q258978 | LaravelModel.getModelRelation | test | private function getModelRelation($relation)
{
$method = basename(str_replace('\\', '/', get_class($relation)));
switch ($method) {
case 'BelongsTo':
case 'HasMany':
case 'HasOne':
$model = $relation->getRelated();
break;
default:
$model = $relation;
}
$table = $model->getTable();
switch ($method) {
case 'BelongsTo':
case 'BelongsToMany':
$parent_key = $relation->getQualifiedForeignKey();
$foreign_key = $relation->getQualifiedOwnerKeyName();
break;
case 'HasMany':
$parent_key = $relation->getQualifiedParentKeyName();
$foreign_key = $relation->getQualifiedForeignKeyName();
break;
case 'HasOne':
$parent_key = $table.'.'.$relation->getParentKey();
$foreign_key = $table.'.'.$relation->getForeignKeyName();
break;
}
return [
'model' => $model,
'method' => $method,
'table' => $table,
'parent_key' => $parent_key,
'foreign_key' => $foreign_key,
];
} | php | {
"resource": ""
} |
q258979 | LaravelModel.modelJoin | test | public function modelJoin(&$query, &$primary_model, &$relationships, $operator = '=', $type = 'left', $where = false)
{
if (is_string($relationships)) {
$relationships = [$relationships => []];
}
if (!is_array($relationships)) {
$relationships = [$relationships];
}
if (empty($query->columns)) {
$query->selectRaw('DISTINCT '.$primary_model->getTable().'.*');
}
foreach ($relationships as $relation_name => &$relationship) {
if (empty($relationship)) {
$relationship = $this->getModelRelation($primary_model->$relation_name());
}
// Required variables.
$model = array_get($relationship, 'model');
$method = array_get($relationship, 'method');
$table = array_get($relationship, 'table');
$parent_key = array_get($relationship, 'parent_key');
$foreign_key = array_get($relationship, 'foreign_key');
// Add the columns from the other table.
// @todo do we need this?
//$this->query->addSelect(new Expression("`$table`.*"));
$query->join($table, $parent_key, $operator, $foreign_key, $type, $where);
// The join above is to the intimidatory table. This joins the query to the actual model.
if ($method === 'BelongsToMany') {
$related_foreign_key = $model->getQualifiedRelatedKeyName();
$related_relation = $model->getRelated();
$related_table = $related_relation->getTable();
$related_qualified_key_name = $related_relation->getQualifiedKeyName();
$query->join($related_table, $related_qualified_key_name, $operator, $related_foreign_key, $type, $where);
}
}
// Group by the original model.
$query->groupBy($primary_model->getQualifiedKeyName());
} | php | {
"resource": ""
} |
q258980 | Aws.client | test | public function client($override = [])
{
return [
'version' => array_get($override, 'version', config('hnhdigital.aws.version')),
'region' => array_get($override, 'region', config('hnhdigital.aws.region')),
'credentials' => [
'key' => array_get($override, 'key', config('hnhdigital.aws.key')),
'secret' => array_get($override, 'secret', config('hnhdigital.aws.secret')),
],
];
} | php | {
"resource": ""
} |
q258981 | SemanticVersion.toNumber | test | public static function toNumber($value)
{
$version_array = explode('-', $value, 2);
$version = array_pad(explode('.', $version_array[0]), 4, '00000');
$version_extra = array_get($version_array, 1, '');
if (strlen($version[0]) == 8) {
$version_number = (int) $version[0] * 100 + array_get($version, 1, 0);
} else {
$version_number = '';
foreach ($version as $value) {
$version_number .= str_pad($value, 5, '0', STR_PAD_LEFT);
}
$version_number = (int) $version_number;
}
return [$version_number, $version_extra];
} | php | {
"resource": ""
} |
q258982 | JobTrait.scopeLookupKeyValue | test | public function scopeLookupKeyValue($query, $key, $value, $class_name = '', $data_type = 's')
{
// Lookup serialized array.
if (is_array($value)) {
$value = serialize($value);
$value = self::encodeQueryValue(addslashes($value));
$sql = sprintf(
'payload->"$.data.command" LIKE \'%%%s\\\\\\\\";%s%%\'',
$key,
$value
);
$query->whereRaw($sql);
return;
}
if ($value === false) {
$data = sprintf(
$data_type.':%s:\\\\\\\\"%s\\\\\\\\"',
mb_strlen($class_name),
self::encodeQueryValue($class_name)
);
$sql = sprintf(
'payload->"$.data.command" LIKE \'%%%s\\\\\\\\";%s%%\'',
$key,
$data
);
} elseif ($value !== false) {
if (stripos($value, '%') === false) {
$value_length = mb_strlen($value);
} else {
$value_length = '%';
}
$data = sprintf(
's:%s:\\\\\\\\"%s\\\\\\\\"',
$value_length,
$value
);
if (is_numeric($value)) {
$data = sprintf('i:%s', $value);
}
$sql = sprintf(
'payload->"$.data.command" LIKE \'%%%s\\\\\\\\";%s;%%\'',
$key,
$data
);
}
$query->whereRaw($sql);
} | php | {
"resource": ""
} |
q258983 | JobTrait.setAvailableAtAttribute | test | public function setAvailableAtAttribute($value)
{
$this->attributes['available_at'] = empty($value) ? 0 : $this->asDateTime($value)->timestamp;
return $this;
} | php | {
"resource": ""
} |
q258984 | JobTrait.getPayloadAttribute | test | public function getPayloadAttribute($value)
{
$value = json_decode($value);
data_set($value, 'data.command', unserialize(data_get($value, 'data.command')));
return $value;
} | php | {
"resource": ""
} |
q258985 | Human.bytes | test | public function bytes($bytes, $decimals = 2, $mod = 1024)
{
$factor = floor((strlen($bytes) - 1) / 3);
$byte_name = $this->units_of_bytes[$factor];
if ($mod == 1000) {
$byte_name = str_replace('B', 'bit', $byte_name);
}
return sprintf("%.{$decimals}f %s", $bytes / pow($mod, $factor), $byte_name);
} | php | {
"resource": ""
} |
q258986 | Human.timeOffset | test | public function timeOffset($offset)
{
$offset_whole = round($offset);
$offset_decimal = abs($offset - $offset_whole) * 60;
return (substr($offset, 0, 1) != '-' ? '+' : '').$offset_whole.':'.str_pad($offset_decimal, 2, '0', STR_PAD_LEFT);
} | php | {
"resource": ""
} |
q258987 | Human.seconds | test | public function seconds($seconds, $options = [])
{
// Seconds.
if ($seconds < 60) {
$time = $seconds;
$name = 'second';
}
// Minutes.
if ($seconds >= 60) {
$time = round($seconds / 60, 0);
$name = 'minute';
}
// Hours.
if ($time >= 60) {
$time = round($time / 60, 0);
$name = 'hour';
}
// Days.
if ($time >= 24) {
$time = round($time / 24, 0);
$name = 'day';
}
if (array_has($options, 'abbrev')) {
switch ($name) {
case 'second':
$name = 'sec';
break;
case 'minute':
$name = 'min';
break;
}
}
if (array_has($options, 'single')) {
$name = substr($name, 0, 1);
}
if ($time == 1) {
$time = '';
$period = $name;
} else {
$period = str_plural($name, $time);
}
return sprintf('%s %s', $time, $period);
} | php | {
"resource": ""
} |
q258988 | Human.truncate | test | public function truncate($long_text, $length, $options = [])
{
$short_text = mb_substr($long_text, 0, $length);
if ($short_text === $long_text) {
return $long_text;
}
$short_text .= '...';
if (array_get($options, 'html', false)) {
$short_text .= ' <span class="f-10 f-w-100">(truncated)</span>';
}
if (array_get($options, 'html', false)) {
$short_text = sprintf('<span title="%s">%s</span>', htmlspecialchars($long_text), $short_text);
}
return $short_text;
} | php | {
"resource": ""
} |
q258989 | AmazonSNS.addPermission | test | public function addPermission($topicArn, $label, $permissions = array()) {
if(empty($topicArn) || empty($label)) {
throw new InvalidArgumentException('Must supply TopicARN and a Label for this permission');
}
// Add standard params as normal
$params = array(
'TopicArn' => $topicArn,
'Label' => $label
);
// Compile permissions into separate sequential arrays
$memberFlatArray = array();
$permissionFlatArray = array();
foreach($permissions as $member => $permission) {
if(is_array($permission)) {
// Array of permissions
foreach($permission as $singlePermission) {
$memberFlatArray[] = $member;
$permissionFlatArray[] = $singlePermission;
}
}
else {
// Just a single permission
$memberFlatArray[] = $member;
$permissionFlatArray[] = $permission;
}
}
// Dummy check
if(count($memberFlatArray) !== count($permissionFlatArray)) {
// Something went wrong
throw new InvalidArgumentException('Mismatch of permissions to users');
}
// Finally add to params
for($x = 1; $x <= count($memberFlatArray); $x++) {
$params['ActionName.member.' . $x] = $permissionFlatArray[$x];
$params['AWSAccountID.member.' . $x] = $memberFlatArray[$x];
}
// Finally send request
$this->_request('AddPermission', $params);
return true;
} | php | {
"resource": ""
} |
q258990 | AmazonSNS.confirmSubscription | test | public function confirmSubscription($topicArn, $token, $authenticateOnUnsubscribe = null) {
if(empty($topicArn) || empty($token)) {
throw new InvalidArgumentException('Must supply a TopicARN and a Token to confirm subscription');
}
$params = array(
'TopicArn' => $topicArn,
'Token' => $token
);
if(!is_null($authenticateOnUnsubscribe)) {
$params['AuthenticateOnUnsubscribe'] = $authenticateOnUnsubscribe;
}
$resultXml = $this->_request('ConfirmSubscription', $params);
return strval($resultXml->ConfirmSubscriptionResult->SubscriptionArn);
} | php | {
"resource": ""
} |
q258991 | AmazonSNS.createTopic | test | public function createTopic($name) {
if(empty($name)) {
throw new InvalidArgumentException('Must supply a Name to create topic');
}
$resultXml = $this->_request('CreateTopic', array('Name' => $name));
return strval($resultXml->CreateTopicResult->TopicArn);
} | php | {
"resource": ""
} |
q258992 | AmazonSNS.getTopicAttributes | test | public function getTopicAttributes($topicArn) {
if(empty($topicArn)) {
throw new InvalidArgumentException('Must supply a TopicARN to get topic attributes');
}
$resultXml = $this->_request('GetTopicAttributes', array('TopicArn' => $topicArn));
// Get attributes
$attributes = $resultXml->GetTopicAttributesResult->Attributes->entry;
// Unfortunately cannot use _processXmlToArray here, so process manually
$returnArray = array();
// Process into array
foreach($attributes as $attribute) {
// Store attribute key as array key
$returnArray[strval($attribute->key)] = strval($attribute->value);
}
return $returnArray;
} | php | {
"resource": ""
} |
q258993 | AmazonSNS.listSubscriptions | test | public function listSubscriptions($nextToken = null) {
$params = array();
if(!is_null($nextToken)) {
$params['NextToken'] = $nextToken;
}
$resultXml = $this->_request('ListSubscriptions', $params);
// Get subscriptions
$subs = $resultXml->ListSubscriptionsResult->Subscriptions->member;
$return = ['members' => $this->_processXmlToArray($subs)];
if(isset($resultXml->ListSubscriptionsResult->NextToken)) {
$return['nextToken'] = strval($resultXml->ListSubscriptionsResult->NextToken);
}
return $return;
} | php | {
"resource": ""
} |
q258994 | AmazonSNS.listSubscriptionsByTopic | test | public function listSubscriptionsByTopic($topicArn, $nextToken = null) {
if(empty($topicArn)) {
throw new InvalidArgumentException('Must supply a TopicARN to show subscriptions to a topic');
}
$params = array(
'TopicArn' => $topicArn
);
if(!is_null($nextToken)) {
$params['NextToken'] = $nextToken;
}
$resultXml = $this->_request('ListSubscriptionsByTopic', $params);
// Get subscriptions
$subs = $resultXml->ListSubscriptionsByTopicResult->Subscriptions->member;
$return = ['members' => $this->_processXmlToArray($subs)];
if(isset($resultXml->ListSubscriptionsByTopicResult->NextToken)) {
$return['nextToken'] = strval($resultXml->ListSubscriptionsByTopicResult->NextToken);
}
return $return;
} | php | {
"resource": ""
} |
q258995 | AmazonSNS.listTopics | test | public function listTopics($nextToken = null) {
$params = array();
if(!is_null($nextToken)) {
$params['NextToken'] = $nextToken;
}
$resultXml = $this->_request('ListTopics', $params);
// Get Topics
$topics = $resultXml->ListTopicsResult->Topics->member;
return $this->_processXmlToArray($topics);
} | php | {
"resource": ""
} |
q258996 | AmazonSNS.publish | test | public function publish($topicArn, $message, $subject = '', $messageStructure = '') {
if(empty($topicArn) || empty($message)) {
throw new InvalidArgumentException('Must supply a TopicARN and Message to publish to a topic');
}
$params = array(
'TopicArn' => $topicArn,
'Message' => $message
);
if(!empty($subject)) {
$params['Subject'] = $subject;
}
if(!empty($messageStructure)) {
$params['MessageStructure'] = $messageStructure;
}
$resultXml = $this->_request('Publish', $params);
return strval($resultXml->PublishResult->MessageId);
} | php | {
"resource": ""
} |
q258997 | AmazonSNS.removePermission | test | public function removePermission($topicArn, $label) {
if(empty($topicArn) || empty($label)) {
throw new InvalidArgumentException('Must supply a TopicARN and Label to remove a permission');
}
$this->_request('RemovePermission', array('Label' => $label));
return true;
} | php | {
"resource": ""
} |
q258998 | AmazonSNS.setTopicAttributes | test | public function setTopicAttributes($topicArn, $attrName, $attrValue) {
if(empty($topicArn) || empty($attrName) || empty($attrValue)) {
throw new InvalidArgumentException('Must supply a TopicARN, AttributeName and AttributeValue to set a topic attribute');
}
$this->_request('SetTopicAttributes', array(
'TopicArn' => $topicArn,
'AttributeName' => $attrName,
'AttributeValue' => $attrValue
));
return true;
} | php | {
"resource": ""
} |
q258999 | AmazonSNS.subscribe | test | public function subscribe($topicArn, $protocol, $endpoint) {
if(empty($topicArn) || empty($protocol) || empty($endpoint)) {
throw new InvalidArgumentException('Must supply a TopicARN, Protocol and Endpoint to subscribe to a topic');
}
$response = $this->_request('Subscribe', array(
'TopicArn' => $topicArn,
'Protocol' => $protocol,
'Endpoint' => $endpoint
));
return strval($response->SubscribeResult->SubscriptionArn);
} | php | {
"resource": ""
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.