repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
OKTOTV/OktolabMediaBundle | Controller/EpisodeController.php | EpisodeController.newAction | public function newAction(Request $request)
{
$entity = new Episode();
$form = $this->createCreateForm($entity);
return [
'entity' => $entity,
'form' => $form->createView(),
];
} | php | public function newAction(Request $request)
{
$entity = new Episode();
$form = $this->createCreateForm($entity);
return [
'entity' => $entity,
'form' => $form->createView(),
];
} | [
"public",
"function",
"newAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"entity",
"=",
"new",
"Episode",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"entity",
")",
";",
"return",
"[",
"'entity'",
"=>",
"$",
"entity",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"]",
";",
"}"
] | Displays a form to create a new Episode entity.
@Route("/new", name="oktolab_episode_new")
@Method("GET")
@Template() | [
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"Episode",
"entity",
"."
] | train | https://github.com/OKTOTV/OktolabMediaBundle/blob/f9c1eac4f6b19d2ab25288b301dd0d9350478bb3/Controller/EpisodeController.php#L125-L134 |
OKTOTV/OktolabMediaBundle | Controller/EpisodeController.php | EpisodeController.showAction | public function showAction($uniqID)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository(
$this->container->getParameter('oktolab_media.episode_class')
)->findOneBy(array('uniqID' => $uniqID));
if (!$entity) {
throw $this->createNotFoundException('Unable to find Episode entity.');
}
return ['episode' => $entity];
} | php | public function showAction($uniqID)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository(
$this->container->getParameter('oktolab_media.episode_class')
)->findOneBy(array('uniqID' => $uniqID));
if (!$entity) {
throw $this->createNotFoundException('Unable to find Episode entity.');
}
return ['episode' => $entity];
} | [
"public",
"function",
"showAction",
"(",
"$",
"uniqID",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'oktolab_media.episode_class'",
")",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"'uniqID'",
"=>",
"$",
"uniqID",
")",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find Episode entity.'",
")",
";",
"}",
"return",
"[",
"'episode'",
"=>",
"$",
"entity",
"]",
";",
"}"
] | Finds and displays a Episode entity.
@Route("/{uniqID}", name="oktolab_episode_show")
@Method("GET")
@Template() | [
"Finds",
"and",
"displays",
"a",
"Episode",
"entity",
"."
] | train | https://github.com/OKTOTV/OktolabMediaBundle/blob/f9c1eac4f6b19d2ab25288b301dd0d9350478bb3/Controller/EpisodeController.php#L186-L198 |
OKTOTV/OktolabMediaBundle | Controller/EpisodeController.php | EpisodeController.editAction | public function editAction(Request $request, $episode)
{
$entity = $episode;
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return [
'entity' => $entity,
'form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
];
} | php | public function editAction(Request $request, $episode)
{
$entity = $episode;
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return [
'entity' => $entity,
'form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
];
} | [
"public",
"function",
"editAction",
"(",
"Request",
"$",
"request",
",",
"$",
"episode",
")",
"{",
"$",
"entity",
"=",
"$",
"episode",
";",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createEditForm",
"(",
"$",
"entity",
")",
";",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"id",
")",
";",
"return",
"[",
"'entity'",
"=>",
"$",
"entity",
",",
"'form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
"]",
";",
"}"
] | Displays a form to edit an existing Episode entity.
@Route("/{episode}/edit", name="oktolab_episode_edit")
@ParamConverter("episode", class="OktolabMediaBundle:Episode")
@Method("GET")
@Template() | [
"Displays",
"a",
"form",
"to",
"edit",
"an",
"existing",
"Episode",
"entity",
"."
] | train | https://github.com/OKTOTV/OktolabMediaBundle/blob/f9c1eac4f6b19d2ab25288b301dd0d9350478bb3/Controller/EpisodeController.php#L208-L220 |
OKTOTV/OktolabMediaBundle | Controller/EpisodeController.php | EpisodeController.createEditForm | private function createEditForm(Episode $entity)
{
$form = $this->createForm(
new EpisodeType(),
$entity,
[
'action' => $this->generateUrl(
'oktolab_episode_update',
['id' => $entity->getId()]
),
'method' => 'POST'
]
);
$form->add(
'submit',
'submit',
['label' => 'oktolab_media.edit_episode_button']
);
return $form;
} | php | private function createEditForm(Episode $entity)
{
$form = $this->createForm(
new EpisodeType(),
$entity,
[
'action' => $this->generateUrl(
'oktolab_episode_update',
['id' => $entity->getId()]
),
'method' => 'POST'
]
);
$form->add(
'submit',
'submit',
['label' => 'oktolab_media.edit_episode_button']
);
return $form;
} | [
"private",
"function",
"createEditForm",
"(",
"Episode",
"$",
"entity",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"EpisodeType",
"(",
")",
",",
"$",
"entity",
",",
"[",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'oktolab_episode_update'",
",",
"[",
"'id'",
"=>",
"$",
"entity",
"->",
"getId",
"(",
")",
"]",
")",
",",
"'method'",
"=>",
"'POST'",
"]",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'submit'",
",",
"'submit'",
",",
"[",
"'label'",
"=>",
"'oktolab_media.edit_episode_button'",
"]",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Creates a form to edit a Episode entity.
@param Episode $entity The entity
@return \Symfony\Component\Form\Form The form | [
"Creates",
"a",
"form",
"to",
"edit",
"a",
"Episode",
"entity",
"."
] | train | https://github.com/OKTOTV/OktolabMediaBundle/blob/f9c1eac4f6b19d2ab25288b301dd0d9350478bb3/Controller/EpisodeController.php#L229-L250 |
OKTOTV/OktolabMediaBundle | Controller/EpisodeController.php | EpisodeController.deleteAction | public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('OktolabMediaBundle:Episode')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Episode entity.');
}
$this->get('oktolab_media_helper')->deleteEpisode($episode);
}
return $this->redirect($this->generateUrl('oktolab_episode'));
} | php | public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('OktolabMediaBundle:Episode')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Episode entity.');
}
$this->get('oktolab_media_helper')->deleteEpisode($episode);
}
return $this->redirect($this->generateUrl('oktolab_episode'));
} | [
"public",
"function",
"deleteAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"id",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'OktolabMediaBundle:Episode'",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find Episode entity.'",
")",
";",
"}",
"$",
"this",
"->",
"get",
"(",
"'oktolab_media_helper'",
")",
"->",
"deleteEpisode",
"(",
"$",
"episode",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'oktolab_episode'",
")",
")",
";",
"}"
] | Deletes a Episode entity.
@Route("/{id}", name="oktolab_episode_delete")
@Method("DELETE") | [
"Deletes",
"a",
"Episode",
"entity",
"."
] | train | https://github.com/OKTOTV/OktolabMediaBundle/blob/f9c1eac4f6b19d2ab25288b301dd0d9350478bb3/Controller/EpisodeController.php#L306-L323 |
OKTOTV/OktolabMediaBundle | Controller/EpisodeController.php | EpisodeController.listRemoteEpisodes | public function listRemoteEpisodes(Keychain $keychain)
{
$episodes_url = $this->get('bprs_applink')->getApiUrlsForKey(
$keychain,
'oktolab_media_api_list_episodes'
);
if ($episodes_url) {
$client = new Client();
$response = $client->request(
'GET',
$episodes_url,
['auth' => [$keychain->getUser(), $keychain->getApiKey()]]
);
if ($response->getStatusCode() == 200) {
$info = json_decode(
html_entity_decode((string)$response->getBody()), true
);
return ['result' => $info, 'keychain' => $keychain];
}
}
return new Response('', Response::HTTP_BAD_REQUEST);
} | php | public function listRemoteEpisodes(Keychain $keychain)
{
$episodes_url = $this->get('bprs_applink')->getApiUrlsForKey(
$keychain,
'oktolab_media_api_list_episodes'
);
if ($episodes_url) {
$client = new Client();
$response = $client->request(
'GET',
$episodes_url,
['auth' => [$keychain->getUser(), $keychain->getApiKey()]]
);
if ($response->getStatusCode() == 200) {
$info = json_decode(
html_entity_decode((string)$response->getBody()), true
);
return ['result' => $info, 'keychain' => $keychain];
}
}
return new Response('', Response::HTTP_BAD_REQUEST);
} | [
"public",
"function",
"listRemoteEpisodes",
"(",
"Keychain",
"$",
"keychain",
")",
"{",
"$",
"episodes_url",
"=",
"$",
"this",
"->",
"get",
"(",
"'bprs_applink'",
")",
"->",
"getApiUrlsForKey",
"(",
"$",
"keychain",
",",
"'oktolab_media_api_list_episodes'",
")",
";",
"if",
"(",
"$",
"episodes_url",
")",
"{",
"$",
"client",
"=",
"new",
"Client",
"(",
")",
";",
"$",
"response",
"=",
"$",
"client",
"->",
"request",
"(",
"'GET'",
",",
"$",
"episodes_url",
",",
"[",
"'auth'",
"=>",
"[",
"$",
"keychain",
"->",
"getUser",
"(",
")",
",",
"$",
"keychain",
"->",
"getApiKey",
"(",
")",
"]",
"]",
")",
";",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"==",
"200",
")",
"{",
"$",
"info",
"=",
"json_decode",
"(",
"html_entity_decode",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
",",
"true",
")",
";",
"return",
"[",
"'result'",
"=>",
"$",
"info",
",",
"'keychain'",
"=>",
"$",
"keychain",
"]",
";",
"}",
"}",
"return",
"new",
"Response",
"(",
"''",
",",
"Response",
"::",
"HTTP_BAD_REQUEST",
")",
";",
"}"
] | Browse Episodes of an remote application (with the keychain)
@Route("/remote/{keychain}", name="oktolab_media_remote_episodes")
@Method("GET")
@Template() | [
"Browse",
"Episodes",
"of",
"an",
"remote",
"application",
"(",
"with",
"the",
"keychain",
")"
] | train | https://github.com/OKTOTV/OktolabMediaBundle/blob/f9c1eac4f6b19d2ab25288b301dd0d9350478bb3/Controller/EpisodeController.php#L423-L448 |
simbiosis-group/yii2-helper | actions/DeleteAllAction.php | DeleteAllAction.run | public function run()
{
$model = $this->modelFullName;
if ($model::deleteAll($this->conditions)) {
Yii::$app->getSession()->setFlash('success', 'You have deleted all selected records!');
return $this->controller->goBack();
}
Yii::$app->getSession()->setFlash('error', 'You have failed to deleted all selected records!');
return $this->controller->goBack();
} | php | public function run()
{
$model = $this->modelFullName;
if ($model::deleteAll($this->conditions)) {
Yii::$app->getSession()->setFlash('success', 'You have deleted all selected records!');
return $this->controller->goBack();
}
Yii::$app->getSession()->setFlash('error', 'You have failed to deleted all selected records!');
return $this->controller->goBack();
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"modelFullName",
";",
"if",
"(",
"$",
"model",
"::",
"deleteAll",
"(",
"$",
"this",
"->",
"conditions",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getSession",
"(",
")",
"->",
"setFlash",
"(",
"'success'",
",",
"'You have deleted all selected records!'",
")",
";",
"return",
"$",
"this",
"->",
"controller",
"->",
"goBack",
"(",
")",
";",
"}",
"Yii",
"::",
"$",
"app",
"->",
"getSession",
"(",
")",
"->",
"setFlash",
"(",
"'error'",
",",
"'You have failed to deleted all selected records!'",
")",
";",
"return",
"$",
"this",
"->",
"controller",
"->",
"goBack",
"(",
")",
";",
"}"
] | Runs the action
@return string result content | [
"Runs",
"the",
"action"
] | train | https://github.com/simbiosis-group/yii2-helper/blob/c85c4204dd06b16e54210e75fe6deb51869d1dd9/actions/DeleteAllAction.php#L69-L81 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox.Image_Toolbox | function Image_Toolbox()
{
$args = func_get_args();
$argc = func_num_args();
//get GD information. see what types we can handle
$gd_info = function_exists('gd_info') ? gd_info() : $this->_gd_info();
preg_match("/\A[\D]*([\d+\.]*)[\D]*\Z/", $gd_info['GD Version'], $matches);
list($this->_gd_version_string, $this->_gd_version_number) = $matches;
$this->_gd_version = substr($this->_gd_version_number, 0, strpos($this->_gd_version_number, '.'));
if ($this->_gd_version >= 2)
{
$this->_imagecreatefunction = 'imagecreatetruecolor';
$this->_resize_function = 'imagecopyresampled';
}
else
{
$this->_imagecreatefunction = 'imagecreate';
$this->_resize_function = 'imagecopyresized';
}
$this->_gd_ttf = $gd_info['FreeType Support'];
$this->_gd_ps = $gd_info['T1Lib Support'];
if (isset($gd_info['GIF Read Support']))
{
$this->_types[1]['supported'] = 1;
if ($gd_info['GIF Create Support'])
{
$this->_types[1]['supported'] = 2;
}
}
if (isset($gd_info['JPEG Support']) || isset($gd_info['JPG Support']))
{
$this->_types[2]['supported'] = 2;
}
if (isset($gd_info['PNG Support']))
{
$this->_types[3]['supported'] = 2;
}
//load or create main image
if ($argc == 0)
{
return true;
}
else
{
if ($this->_addImage($argc, $args))
{
foreach ($this->_img['operator'] as $key => $value)
{
$this->_img['main'][$key] = $value;
}
$this->_img['main']['output_type'] = $this->_img['main']['type'];
unset($this->_img['operator']);
return true;
}
else
{
//trigger_error($this->_error_prefix . 'No appropriate constructor found.', E_USER_ERROR);
return null;
}
}
} | php | function Image_Toolbox()
{
$args = func_get_args();
$argc = func_num_args();
//get GD information. see what types we can handle
$gd_info = function_exists('gd_info') ? gd_info() : $this->_gd_info();
preg_match("/\A[\D]*([\d+\.]*)[\D]*\Z/", $gd_info['GD Version'], $matches);
list($this->_gd_version_string, $this->_gd_version_number) = $matches;
$this->_gd_version = substr($this->_gd_version_number, 0, strpos($this->_gd_version_number, '.'));
if ($this->_gd_version >= 2)
{
$this->_imagecreatefunction = 'imagecreatetruecolor';
$this->_resize_function = 'imagecopyresampled';
}
else
{
$this->_imagecreatefunction = 'imagecreate';
$this->_resize_function = 'imagecopyresized';
}
$this->_gd_ttf = $gd_info['FreeType Support'];
$this->_gd_ps = $gd_info['T1Lib Support'];
if (isset($gd_info['GIF Read Support']))
{
$this->_types[1]['supported'] = 1;
if ($gd_info['GIF Create Support'])
{
$this->_types[1]['supported'] = 2;
}
}
if (isset($gd_info['JPEG Support']) || isset($gd_info['JPG Support']))
{
$this->_types[2]['supported'] = 2;
}
if (isset($gd_info['PNG Support']))
{
$this->_types[3]['supported'] = 2;
}
//load or create main image
if ($argc == 0)
{
return true;
}
else
{
if ($this->_addImage($argc, $args))
{
foreach ($this->_img['operator'] as $key => $value)
{
$this->_img['main'][$key] = $value;
}
$this->_img['main']['output_type'] = $this->_img['main']['type'];
unset($this->_img['operator']);
return true;
}
else
{
//trigger_error($this->_error_prefix . 'No appropriate constructor found.', E_USER_ERROR);
return null;
}
}
} | [
"function",
"Image_Toolbox",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"argc",
"=",
"func_num_args",
"(",
")",
";",
"//get GD information. see what types we can handle",
"$",
"gd_info",
"=",
"function_exists",
"(",
"'gd_info'",
")",
"?",
"gd_info",
"(",
")",
":",
"$",
"this",
"->",
"_gd_info",
"(",
")",
";",
"preg_match",
"(",
"\"/\\A[\\D]*([\\d+\\.]*)[\\D]*\\Z/\"",
",",
"$",
"gd_info",
"[",
"'GD Version'",
"]",
",",
"$",
"matches",
")",
";",
"list",
"(",
"$",
"this",
"->",
"_gd_version_string",
",",
"$",
"this",
"->",
"_gd_version_number",
")",
"=",
"$",
"matches",
";",
"$",
"this",
"->",
"_gd_version",
"=",
"substr",
"(",
"$",
"this",
"->",
"_gd_version_number",
",",
"0",
",",
"strpos",
"(",
"$",
"this",
"->",
"_gd_version_number",
",",
"'.'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_gd_version",
">=",
"2",
")",
"{",
"$",
"this",
"->",
"_imagecreatefunction",
"=",
"'imagecreatetruecolor'",
";",
"$",
"this",
"->",
"_resize_function",
"=",
"'imagecopyresampled'",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_imagecreatefunction",
"=",
"'imagecreate'",
";",
"$",
"this",
"->",
"_resize_function",
"=",
"'imagecopyresized'",
";",
"}",
"$",
"this",
"->",
"_gd_ttf",
"=",
"$",
"gd_info",
"[",
"'FreeType Support'",
"]",
";",
"$",
"this",
"->",
"_gd_ps",
"=",
"$",
"gd_info",
"[",
"'T1Lib Support'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"gd_info",
"[",
"'GIF Read Support'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_types",
"[",
"1",
"]",
"[",
"'supported'",
"]",
"=",
"1",
";",
"if",
"(",
"$",
"gd_info",
"[",
"'GIF Create Support'",
"]",
")",
"{",
"$",
"this",
"->",
"_types",
"[",
"1",
"]",
"[",
"'supported'",
"]",
"=",
"2",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"gd_info",
"[",
"'JPEG Support'",
"]",
")",
"||",
"isset",
"(",
"$",
"gd_info",
"[",
"'JPG Support'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_types",
"[",
"2",
"]",
"[",
"'supported'",
"]",
"=",
"2",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"gd_info",
"[",
"'PNG Support'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_types",
"[",
"3",
"]",
"[",
"'supported'",
"]",
"=",
"2",
";",
"}",
"//load or create main image",
"if",
"(",
"$",
"argc",
"==",
"0",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"_addImage",
"(",
"$",
"argc",
",",
"$",
"args",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'output_type'",
"]",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'type'",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"//trigger_error($this->_error_prefix . 'No appropriate constructor found.', E_USER_ERROR);",
"return",
"null",
";",
"}",
"}",
"}"
] | The class constructor.
Determines the image features of the server and sets the according values.<br>
Additionally you can specify a image to be created/loaded. like {@link addImage() addImage}.
If no parameter is given, no image resource will be generated<br>
Or:<br>
<i>string</i> <b>$file</b> imagefile to load<br>
Or:<br>
<i>integer</i> <b>$width</b> imagewidth of new image to be created<br>
<i>integer</i> <b>$height</b> imageheight of new image to be created<br>
<i>string</i> <b>$fillcolor</b> optional fill the new image with this color (hexformat, e.g. '#FF0000')<br> | [
"The",
"class",
"constructor",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L175-L239 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox.getServerFeatures | function getServerFeatures()
{
$features = array();
$features['gd_version'] = $this->_gd_version_number;
$features['gif'] = $this->_types[1]['supported'];
$features['jpg'] = $this->_types[2]['supported'];
$features['png'] = $this->_types[3]['supported'];
$features['ttf'] = $this->_gd_ttf;
return $features;
} | php | function getServerFeatures()
{
$features = array();
$features['gd_version'] = $this->_gd_version_number;
$features['gif'] = $this->_types[1]['supported'];
$features['jpg'] = $this->_types[2]['supported'];
$features['png'] = $this->_types[3]['supported'];
$features['ttf'] = $this->_gd_ttf;
return $features;
} | [
"function",
"getServerFeatures",
"(",
")",
"{",
"$",
"features",
"=",
"array",
"(",
")",
";",
"$",
"features",
"[",
"'gd_version'",
"]",
"=",
"$",
"this",
"->",
"_gd_version_number",
";",
"$",
"features",
"[",
"'gif'",
"]",
"=",
"$",
"this",
"->",
"_types",
"[",
"1",
"]",
"[",
"'supported'",
"]",
";",
"$",
"features",
"[",
"'jpg'",
"]",
"=",
"$",
"this",
"->",
"_types",
"[",
"2",
"]",
"[",
"'supported'",
"]",
";",
"$",
"features",
"[",
"'png'",
"]",
"=",
"$",
"this",
"->",
"_types",
"[",
"3",
"]",
"[",
"'supported'",
"]",
";",
"$",
"features",
"[",
"'ttf'",
"]",
"=",
"$",
"this",
"->",
"_gd_ttf",
";",
"return",
"$",
"features",
";",
"}"
] | Returns an assocative array with information about the image features of this server
Array values:
<ul>
<li>'gd_version' -> what GD version is installed on this server (e.g. 2.0)</li>
<li>'gif' -> 0 = not supported, 1 = reading is supported, 2 = creating is supported</li>
<li>'jpg' -> 0 = not supported, 1 = reading is supported, 2 = creating is supported</li>
<li>'png' -> 0 = not supported, 1 = reading is supported, 2 = creating is supported</li>
<li>'ttf' -> TTF text creation. true = supported, false = not supported
</ul>
@return array | [
"Returns",
"an",
"assocative",
"array",
"with",
"information",
"about",
"the",
"image",
"features",
"of",
"this",
"server"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L255-L264 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox.newImage | function newImage()
{
$args = func_get_args();
$argc = func_num_args();
if ($this->_addImage($argc, $args))
{
foreach ($this->_img['operator'] as $key => $value)
{
$this->_img['main'][$key] = $value;
}
$this->_img['main']['output_type'] = $this->_img['main']['type'];
unset($this->_img['operator']);
return true;
}
else
{
//trigger_error($this->_error_prefix . 'No appropriate constructor found.', E_USER_ERROR);
return null;
}
} | php | function newImage()
{
$args = func_get_args();
$argc = func_num_args();
if ($this->_addImage($argc, $args))
{
foreach ($this->_img['operator'] as $key => $value)
{
$this->_img['main'][$key] = $value;
}
$this->_img['main']['output_type'] = $this->_img['main']['type'];
unset($this->_img['operator']);
return true;
}
else
{
//trigger_error($this->_error_prefix . 'No appropriate constructor found.', E_USER_ERROR);
return null;
}
} | [
"function",
"newImage",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"argc",
"=",
"func_num_args",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_addImage",
"(",
"$",
"argc",
",",
"$",
"args",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'output_type'",
"]",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'type'",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"//trigger_error($this->_error_prefix . 'No appropriate constructor found.', E_USER_ERROR);",
"return",
"null",
";",
"}",
"}"
] | Flush all image resources and init a new one
Parameter:<br>
<i>string</i> <b>$file</b> imagefile to load<br>
Or:<br>
<i>integer</i> <b>$width</b> imagewidth of new image to be created<br>
<i>integer</i> <b>$height</b> imageheight of new image to be created<br>
<i>string</i> <b>$fillcolor</b> optional fill the new image with this color (hexformat, e.g. '#FF0000')<br> | [
"Flush",
"all",
"image",
"resources",
"and",
"init",
"a",
"new",
"one"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L276-L296 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox._gd_info | function _gd_info()
{
$array = array(
"GD Version" => "",
"FreeType Support" => false,
"FreeType Linkage" => "",
"T1Lib Support" => false,
"GIF Read Support" => false,
"GIF Create Support" => false,
"JPG Support" => false,
"PNG Support" => false,
"WBMP Support" => false,
"XBM Support" => false
);
$gif_support = 0;
ob_start();
eval("phpinfo();");
$info = ob_get_contents();
ob_end_clean();
foreach (explode("\n", $info) as $line)
{
if (strpos($line, "GD Version") !== false)
{
$array["GD Version"] = trim(str_replace("GD Version", "", strip_tags($line)));
}
if (strpos($line, "FreeType Support") !== false)
{
$array["FreeType Support"] = trim(str_replace("FreeType Support", "", strip_tags($line)));
}
if (strpos($line, "FreeType Linkage") !== false)
{
$array["FreeType Linkage"] = trim(str_replace("FreeType Linkage", "", strip_tags($line)));
}
if (strpos($line, "T1Lib Support") !== false)
{
$array["T1Lib Support"] = trim(str_replace("T1Lib Support", "", strip_tags($line)));
}
if (strpos($line, "GIF Read Support") !== false)
{
$array["GIF Read Support"] = trim(str_replace("GIF Read Support", "", strip_tags($line)));
}
if (strpos($line, "GIF Create Support") !== false)
{
$array["GIF Create Support"] = trim(str_replace("GIF Create Support", "", strip_tags($line)));
}
if (strpos($line, "GIF Support") !== false)
{
$gif_support = trim(str_replace("GIF Support", "", strip_tags($line)));
}
if (strpos($line, "JPG Support") !== false)
{
$array["JPG Support"] = trim(str_replace("JPG Support", "", strip_tags($line)));
}
if (strpos($line, "PNG Support") !== false)
{
$array["PNG Support"] = trim(str_replace("PNG Support", "", strip_tags($line)));
}
if (strpos($line, "WBMP Support") !== false)
{
$array["WBMP Support"] = trim(str_replace("WBMP Support", "", strip_tags($line)));
}
if (strpos($line, "XBM Support") !== false)
{
$array["XBM Support"] = trim(str_replace("XBM Support", "", strip_tags($line)));
}
}
if ($gif_support === "enabled")
{
$array["GIF Read Support"] = true;
$array["GIF Create Support"] = true;
}
if ($array["FreeType Support"] === "enabled")
{
$array["FreeType Support"] = true;
}
if ($array["T1Lib Support"] === "enabled")
{
$array["T1Lib Support"] = true;
}
if ($array["GIF Read Support"] === "enabled")
{
$array["GIF Read Support"] = true;
}
if ($array["GIF Create Support"] === "enabled")
{
$array["GIF Create Support"] = true;
}
if ($array["JPG Support"] === "enabled")
{
$array["JPG Support"] = true;
}
if ($array["PNG Support"] === "enabled")
{
$array["PNG Support"] = true;
}
if ($array["WBMP Support"] === "enabled")
{
$array["WBMP Support"] = true;
}
if ($array["XBM Support"] === "enabled")
{
$array["XBM Support"] = true;
}
return $array;
} | php | function _gd_info()
{
$array = array(
"GD Version" => "",
"FreeType Support" => false,
"FreeType Linkage" => "",
"T1Lib Support" => false,
"GIF Read Support" => false,
"GIF Create Support" => false,
"JPG Support" => false,
"PNG Support" => false,
"WBMP Support" => false,
"XBM Support" => false
);
$gif_support = 0;
ob_start();
eval("phpinfo();");
$info = ob_get_contents();
ob_end_clean();
foreach (explode("\n", $info) as $line)
{
if (strpos($line, "GD Version") !== false)
{
$array["GD Version"] = trim(str_replace("GD Version", "", strip_tags($line)));
}
if (strpos($line, "FreeType Support") !== false)
{
$array["FreeType Support"] = trim(str_replace("FreeType Support", "", strip_tags($line)));
}
if (strpos($line, "FreeType Linkage") !== false)
{
$array["FreeType Linkage"] = trim(str_replace("FreeType Linkage", "", strip_tags($line)));
}
if (strpos($line, "T1Lib Support") !== false)
{
$array["T1Lib Support"] = trim(str_replace("T1Lib Support", "", strip_tags($line)));
}
if (strpos($line, "GIF Read Support") !== false)
{
$array["GIF Read Support"] = trim(str_replace("GIF Read Support", "", strip_tags($line)));
}
if (strpos($line, "GIF Create Support") !== false)
{
$array["GIF Create Support"] = trim(str_replace("GIF Create Support", "", strip_tags($line)));
}
if (strpos($line, "GIF Support") !== false)
{
$gif_support = trim(str_replace("GIF Support", "", strip_tags($line)));
}
if (strpos($line, "JPG Support") !== false)
{
$array["JPG Support"] = trim(str_replace("JPG Support", "", strip_tags($line)));
}
if (strpos($line, "PNG Support") !== false)
{
$array["PNG Support"] = trim(str_replace("PNG Support", "", strip_tags($line)));
}
if (strpos($line, "WBMP Support") !== false)
{
$array["WBMP Support"] = trim(str_replace("WBMP Support", "", strip_tags($line)));
}
if (strpos($line, "XBM Support") !== false)
{
$array["XBM Support"] = trim(str_replace("XBM Support", "", strip_tags($line)));
}
}
if ($gif_support === "enabled")
{
$array["GIF Read Support"] = true;
$array["GIF Create Support"] = true;
}
if ($array["FreeType Support"] === "enabled")
{
$array["FreeType Support"] = true;
}
if ($array["T1Lib Support"] === "enabled")
{
$array["T1Lib Support"] = true;
}
if ($array["GIF Read Support"] === "enabled")
{
$array["GIF Read Support"] = true;
}
if ($array["GIF Create Support"] === "enabled")
{
$array["GIF Create Support"] = true;
}
if ($array["JPG Support"] === "enabled")
{
$array["JPG Support"] = true;
}
if ($array["PNG Support"] === "enabled")
{
$array["PNG Support"] = true;
}
if ($array["WBMP Support"] === "enabled")
{
$array["WBMP Support"] = true;
}
if ($array["XBM Support"] === "enabled")
{
$array["XBM Support"] = true;
}
return $array;
} | [
"function",
"_gd_info",
"(",
")",
"{",
"$",
"array",
"=",
"array",
"(",
"\"GD Version\"",
"=>",
"\"\"",
",",
"\"FreeType Support\"",
"=>",
"false",
",",
"\"FreeType Linkage\"",
"=>",
"\"\"",
",",
"\"T1Lib Support\"",
"=>",
"false",
",",
"\"GIF Read Support\"",
"=>",
"false",
",",
"\"GIF Create Support\"",
"=>",
"false",
",",
"\"JPG Support\"",
"=>",
"false",
",",
"\"PNG Support\"",
"=>",
"false",
",",
"\"WBMP Support\"",
"=>",
"false",
",",
"\"XBM Support\"",
"=>",
"false",
")",
";",
"$",
"gif_support",
"=",
"0",
";",
"ob_start",
"(",
")",
";",
"eval",
"(",
"\"phpinfo();\"",
")",
";",
"$",
"info",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"foreach",
"(",
"explode",
"(",
"\"\\n\"",
",",
"$",
"info",
")",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"GD Version\"",
")",
"!==",
"false",
")",
"{",
"$",
"array",
"[",
"\"GD Version\"",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"\"GD Version\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"FreeType Support\"",
")",
"!==",
"false",
")",
"{",
"$",
"array",
"[",
"\"FreeType Support\"",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"\"FreeType Support\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"FreeType Linkage\"",
")",
"!==",
"false",
")",
"{",
"$",
"array",
"[",
"\"FreeType Linkage\"",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"\"FreeType Linkage\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"T1Lib Support\"",
")",
"!==",
"false",
")",
"{",
"$",
"array",
"[",
"\"T1Lib Support\"",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"\"T1Lib Support\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"GIF Read Support\"",
")",
"!==",
"false",
")",
"{",
"$",
"array",
"[",
"\"GIF Read Support\"",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"\"GIF Read Support\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"GIF Create Support\"",
")",
"!==",
"false",
")",
"{",
"$",
"array",
"[",
"\"GIF Create Support\"",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"\"GIF Create Support\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"GIF Support\"",
")",
"!==",
"false",
")",
"{",
"$",
"gif_support",
"=",
"trim",
"(",
"str_replace",
"(",
"\"GIF Support\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"JPG Support\"",
")",
"!==",
"false",
")",
"{",
"$",
"array",
"[",
"\"JPG Support\"",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"\"JPG Support\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"PNG Support\"",
")",
"!==",
"false",
")",
"{",
"$",
"array",
"[",
"\"PNG Support\"",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"\"PNG Support\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"WBMP Support\"",
")",
"!==",
"false",
")",
"{",
"$",
"array",
"[",
"\"WBMP Support\"",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"\"WBMP Support\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"\"XBM Support\"",
")",
"!==",
"false",
")",
"{",
"$",
"array",
"[",
"\"XBM Support\"",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"\"XBM Support\"",
",",
"\"\"",
",",
"strip_tags",
"(",
"$",
"line",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"gif_support",
"===",
"\"enabled\"",
")",
"{",
"$",
"array",
"[",
"\"GIF Read Support\"",
"]",
"=",
"true",
";",
"$",
"array",
"[",
"\"GIF Create Support\"",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"array",
"[",
"\"FreeType Support\"",
"]",
"===",
"\"enabled\"",
")",
"{",
"$",
"array",
"[",
"\"FreeType Support\"",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"array",
"[",
"\"T1Lib Support\"",
"]",
"===",
"\"enabled\"",
")",
"{",
"$",
"array",
"[",
"\"T1Lib Support\"",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"array",
"[",
"\"GIF Read Support\"",
"]",
"===",
"\"enabled\"",
")",
"{",
"$",
"array",
"[",
"\"GIF Read Support\"",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"array",
"[",
"\"GIF Create Support\"",
"]",
"===",
"\"enabled\"",
")",
"{",
"$",
"array",
"[",
"\"GIF Create Support\"",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"array",
"[",
"\"JPG Support\"",
"]",
"===",
"\"enabled\"",
")",
"{",
"$",
"array",
"[",
"\"JPG Support\"",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"array",
"[",
"\"PNG Support\"",
"]",
"===",
"\"enabled\"",
")",
"{",
"$",
"array",
"[",
"\"PNG Support\"",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"array",
"[",
"\"WBMP Support\"",
"]",
"===",
"\"enabled\"",
")",
"{",
"$",
"array",
"[",
"\"WBMP Support\"",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"array",
"[",
"\"XBM Support\"",
"]",
"===",
"\"enabled\"",
")",
"{",
"$",
"array",
"[",
"\"XBM Support\"",
"]",
"=",
"true",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Reimplements the original PHP {@link gd_info()} function for older PHP versions
@access private
@return array associative array with info about the GD library of the server | [
"Reimplements",
"the",
"original",
"PHP",
"{",
"@link",
"gd_info",
"()",
"}",
"function",
"for",
"older",
"PHP",
"versions"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L304-L420 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox._hexToPHPColor | function _hexToPHPColor($hex)
{
$length = strlen($hex);
$dr = hexdec(substr($hex, $length - 6, 2));
$dg = hexdec(substr($hex, $length - 4, 2));
$db = hexdec(substr($hex, $length - 2, 2));
$color = ($dr << 16) + ($dg << 8) + $db;
return $color;
} | php | function _hexToPHPColor($hex)
{
$length = strlen($hex);
$dr = hexdec(substr($hex, $length - 6, 2));
$dg = hexdec(substr($hex, $length - 4, 2));
$db = hexdec(substr($hex, $length - 2, 2));
$color = ($dr << 16) + ($dg << 8) + $db;
return $color;
} | [
"function",
"_hexToPHPColor",
"(",
"$",
"hex",
")",
"{",
"$",
"length",
"=",
"strlen",
"(",
"$",
"hex",
")",
";",
"$",
"dr",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"hex",
",",
"$",
"length",
"-",
"6",
",",
"2",
")",
")",
";",
"$",
"dg",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"hex",
",",
"$",
"length",
"-",
"4",
",",
"2",
")",
")",
";",
"$",
"db",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"hex",
",",
"$",
"length",
"-",
"2",
",",
"2",
")",
")",
";",
"$",
"color",
"=",
"(",
"$",
"dr",
"<<",
"16",
")",
"+",
"(",
"$",
"dg",
"<<",
"8",
")",
"+",
"$",
"db",
";",
"return",
"$",
"color",
";",
"}"
] | Convert a color defined in hexvalues to the PHP color format
@access private
@param string $hex color value in hexformat (e.g. '#FF0000')
@return integer color value in PHP format | [
"Convert",
"a",
"color",
"defined",
"in",
"hexvalues",
"to",
"the",
"PHP",
"color",
"format"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L429-L437 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox._hexToDecColor | function _hexToDecColor($hex)
{
$length = strlen($hex);
$color['red'] = hexdec(substr($hex, $length - 6, 2));
$color['green'] = hexdec(substr($hex, $length - 4, 2));
$color['blue'] = hexdec(substr($hex, $length - 2, 2));
return $color;
} | php | function _hexToDecColor($hex)
{
$length = strlen($hex);
$color['red'] = hexdec(substr($hex, $length - 6, 2));
$color['green'] = hexdec(substr($hex, $length - 4, 2));
$color['blue'] = hexdec(substr($hex, $length - 2, 2));
return $color;
} | [
"function",
"_hexToDecColor",
"(",
"$",
"hex",
")",
"{",
"$",
"length",
"=",
"strlen",
"(",
"$",
"hex",
")",
";",
"$",
"color",
"[",
"'red'",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"hex",
",",
"$",
"length",
"-",
"6",
",",
"2",
")",
")",
";",
"$",
"color",
"[",
"'green'",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"hex",
",",
"$",
"length",
"-",
"4",
",",
"2",
")",
")",
";",
"$",
"color",
"[",
"'blue'",
"]",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"hex",
",",
"$",
"length",
"-",
"2",
",",
"2",
")",
")",
";",
"return",
"$",
"color",
";",
"}"
] | Convert a color defined in hexvalues to corresponding dezimal values
@access private
@param string $hex color value in hexformat (e.g. '#FF0000')
@return array associative array with color values in dezimal format (fields: 'red', 'green', 'blue') | [
"Convert",
"a",
"color",
"defined",
"in",
"hexvalues",
"to",
"corresponding",
"dezimal",
"values"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L446-L453 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox._addImage | function _addImage($argc, $args)
{
if (($argc == 2 || $argc == 3) && is_int($args[0]) && is_int($args[1]) && (is_string($args[2]) || !isset($args[2])))
{
//neues leeres bild mit width und height (fillcolor optional)
$this->_img['operator']['width'] = $args[0];
$this->_img['operator']['height'] = $args[1];
($this->_img['operator']['width'] >= $this->_img['operator']['height']) ? ($this->_img['operator']['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL) : ($this->_img['operator']['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
$this->_img['operator']['aspectratio'] = $this->_img['operator']['width'] / $this->_img['operator']['height'];
$this->_img['operator']['indexedcolors'] = 0;
$functionname = $this->_imagecreatefunction;
$this->_img['operator']['resource'] = $functionname($this->_img['operator']['width'], $this->_img['operator']['height']);
// set default type jpg.
$this->_img['operator']['type'] = 2;
if (isset($args[2]) && is_string($args[2]))
{
//neues bild mit farbe f�llen
$fillcolor = $this->_hexToPHPColor($args[2]);
imagefill($this->_img['operator']['resource'], 0, 0, $fillcolor);
$this->_img['operator']['color'] = $fillcolor;
}
else
{
$this->_img['operator']['color'] = 0;
}
}
elseif ($argc == 1 && is_string($args[0]))
{
//bild aus datei laden. width und height original gr�sse
$this->_img['operator'] = $this->_loadFile($args[0]);
$this->_img['operator']['indexedcolors'] = imagecolorstotal($this->_img['operator']['resource']);
$this->_img['operator']['color'] = -1;
}
else
{
return false;
}
return true;
} | php | function _addImage($argc, $args)
{
if (($argc == 2 || $argc == 3) && is_int($args[0]) && is_int($args[1]) && (is_string($args[2]) || !isset($args[2])))
{
//neues leeres bild mit width und height (fillcolor optional)
$this->_img['operator']['width'] = $args[0];
$this->_img['operator']['height'] = $args[1];
($this->_img['operator']['width'] >= $this->_img['operator']['height']) ? ($this->_img['operator']['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL) : ($this->_img['operator']['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
$this->_img['operator']['aspectratio'] = $this->_img['operator']['width'] / $this->_img['operator']['height'];
$this->_img['operator']['indexedcolors'] = 0;
$functionname = $this->_imagecreatefunction;
$this->_img['operator']['resource'] = $functionname($this->_img['operator']['width'], $this->_img['operator']['height']);
// set default type jpg.
$this->_img['operator']['type'] = 2;
if (isset($args[2]) && is_string($args[2]))
{
//neues bild mit farbe f�llen
$fillcolor = $this->_hexToPHPColor($args[2]);
imagefill($this->_img['operator']['resource'], 0, 0, $fillcolor);
$this->_img['operator']['color'] = $fillcolor;
}
else
{
$this->_img['operator']['color'] = 0;
}
}
elseif ($argc == 1 && is_string($args[0]))
{
//bild aus datei laden. width und height original gr�sse
$this->_img['operator'] = $this->_loadFile($args[0]);
$this->_img['operator']['indexedcolors'] = imagecolorstotal($this->_img['operator']['resource']);
$this->_img['operator']['color'] = -1;
}
else
{
return false;
}
return true;
} | [
"function",
"_addImage",
"(",
"$",
"argc",
",",
"$",
"args",
")",
"{",
"if",
"(",
"(",
"$",
"argc",
"==",
"2",
"||",
"$",
"argc",
"==",
"3",
")",
"&&",
"is_int",
"(",
"$",
"args",
"[",
"0",
"]",
")",
"&&",
"is_int",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"&&",
"(",
"is_string",
"(",
"$",
"args",
"[",
"2",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"args",
"[",
"2",
"]",
")",
")",
")",
"{",
"//neues leeres bild mit width und height (fillcolor optional)",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
"=",
"$",
"args",
"[",
"1",
"]",
";",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
">=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
")",
"?",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'bias'",
"]",
"=",
"IMAGE_TOOLBOX_BIAS_HORIZONTAL",
")",
":",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'bias'",
"]",
"=",
"IMAGE_TOOLBOX_BIAS_VERTICAL",
")",
";",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'aspectratio'",
"]",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
"/",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
";",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'indexedcolors'",
"]",
"=",
"0",
";",
"$",
"functionname",
"=",
"$",
"this",
"->",
"_imagecreatefunction",
";",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'resource'",
"]",
"=",
"$",
"functionname",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
")",
";",
"// set default type jpg.",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'type'",
"]",
"=",
"2",
";",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"2",
"]",
")",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"2",
"]",
")",
")",
"{",
"//neues bild mit farbe f�llen",
"$",
"fillcolor",
"=",
"$",
"this",
"->",
"_hexToPHPColor",
"(",
"$",
"args",
"[",
"2",
"]",
")",
";",
"imagefill",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'resource'",
"]",
",",
"0",
",",
"0",
",",
"$",
"fillcolor",
")",
";",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'color'",
"]",
"=",
"$",
"fillcolor",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'color'",
"]",
"=",
"0",
";",
"}",
"}",
"elseif",
"(",
"$",
"argc",
"==",
"1",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"//bild aus datei laden. width und height original gr�sse",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"=",
"$",
"this",
"->",
"_loadFile",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'indexedcolors'",
"]",
"=",
"imagecolorstotal",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'resource'",
"]",
")",
";",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'color'",
"]",
"=",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Generate a new image resource based on the given parameters
Parameter:
<i>string</i> <b>$file</b> imagefile to load<br>
Or:<br>
<i>integer</i> <b>$width</b> imagewidth of new image to be created<br>
<i>integer</i> <b>$height</b> imageheight of new image to be created<br>
<i>string</i> <b>$fillcolor</b> optional fill the new image with this color (hexformat, e.g. '#FF0000')<br>
@access private | [
"Generate",
"a",
"new",
"image",
"resource",
"based",
"on",
"the",
"given",
"parameters"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L467-L505 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox._loadFile | function _loadFile($filename)
{
if (file_exists($filename))
{
$info = getimagesize($filename);
$filedata['width'] = $info[0];
$filedata['height'] = $info[1];
($filedata['width'] >= $filedata['height']) ? ($filedata['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL) : ($filedata['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
$filedata['aspectratio'] = $filedata['width'] / $filedata['height'];
$filedata['type'] = $info[2];
if ($this->_types[$filedata['type']]['supported'] < 1)
{
//trigger_error($this->_error_prefix . 'Imagetype ('.$this->_types[$filedata['type']]['ext'].') not supported for reading.', E_USER_ERROR);
return null;
}
switch ($filedata['type'])
{
case 1:
$dummy = imagecreatefromgif($filename);
$functionname = $this->_imagecreatefunction;
$filedata['resource'] = $functionname($filedata['width'], $filedata['height']);
imagecopy($filedata['resource'], $dummy, 0, 0, 0, 0, $filedata['width'], $filedata['height']);
imagedestroy($dummy);
break;
case 2:
$filedata['resource'] = imagecreatefromjpeg($filename);
break;
case 3:
$dummy = imagecreatefrompng($filename);
if (imagecolorstotal($dummy) != 0)
{
$functionname = $this->_imagecreatefunction;
$filedata['resource'] = $functionname($filedata['width'], $filedata['height']);
imagecopy($filedata['resource'], $dummy, 0, 0, 0, 0, $filedata['width'], $filedata['height']);
}
else
{
$filedata['resource'] = $dummy;
}
unset($dummy);
break;
default:
//trigger_error($this->_error_prefix . 'Imagetype not supported.', E_USER_ERROR);
return null;
}
return $filedata;
}
else
{
//trigger_error($this->_error_prefix . 'Imagefile (' . $filename . ') does not exist.', E_USER_ERROR);
return null;
}
} | php | function _loadFile($filename)
{
if (file_exists($filename))
{
$info = getimagesize($filename);
$filedata['width'] = $info[0];
$filedata['height'] = $info[1];
($filedata['width'] >= $filedata['height']) ? ($filedata['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL) : ($filedata['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
$filedata['aspectratio'] = $filedata['width'] / $filedata['height'];
$filedata['type'] = $info[2];
if ($this->_types[$filedata['type']]['supported'] < 1)
{
//trigger_error($this->_error_prefix . 'Imagetype ('.$this->_types[$filedata['type']]['ext'].') not supported for reading.', E_USER_ERROR);
return null;
}
switch ($filedata['type'])
{
case 1:
$dummy = imagecreatefromgif($filename);
$functionname = $this->_imagecreatefunction;
$filedata['resource'] = $functionname($filedata['width'], $filedata['height']);
imagecopy($filedata['resource'], $dummy, 0, 0, 0, 0, $filedata['width'], $filedata['height']);
imagedestroy($dummy);
break;
case 2:
$filedata['resource'] = imagecreatefromjpeg($filename);
break;
case 3:
$dummy = imagecreatefrompng($filename);
if (imagecolorstotal($dummy) != 0)
{
$functionname = $this->_imagecreatefunction;
$filedata['resource'] = $functionname($filedata['width'], $filedata['height']);
imagecopy($filedata['resource'], $dummy, 0, 0, 0, 0, $filedata['width'], $filedata['height']);
}
else
{
$filedata['resource'] = $dummy;
}
unset($dummy);
break;
default:
//trigger_error($this->_error_prefix . 'Imagetype not supported.', E_USER_ERROR);
return null;
}
return $filedata;
}
else
{
//trigger_error($this->_error_prefix . 'Imagefile (' . $filename . ') does not exist.', E_USER_ERROR);
return null;
}
} | [
"function",
"_loadFile",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"info",
"=",
"getimagesize",
"(",
"$",
"filename",
")",
";",
"$",
"filedata",
"[",
"'width'",
"]",
"=",
"$",
"info",
"[",
"0",
"]",
";",
"$",
"filedata",
"[",
"'height'",
"]",
"=",
"$",
"info",
"[",
"1",
"]",
";",
"(",
"$",
"filedata",
"[",
"'width'",
"]",
">=",
"$",
"filedata",
"[",
"'height'",
"]",
")",
"?",
"(",
"$",
"filedata",
"[",
"'bias'",
"]",
"=",
"IMAGE_TOOLBOX_BIAS_HORIZONTAL",
")",
":",
"(",
"$",
"filedata",
"[",
"'bias'",
"]",
"=",
"IMAGE_TOOLBOX_BIAS_VERTICAL",
")",
";",
"$",
"filedata",
"[",
"'aspectratio'",
"]",
"=",
"$",
"filedata",
"[",
"'width'",
"]",
"/",
"$",
"filedata",
"[",
"'height'",
"]",
";",
"$",
"filedata",
"[",
"'type'",
"]",
"=",
"$",
"info",
"[",
"2",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"_types",
"[",
"$",
"filedata",
"[",
"'type'",
"]",
"]",
"[",
"'supported'",
"]",
"<",
"1",
")",
"{",
"//trigger_error($this->_error_prefix . 'Imagetype ('.$this->_types[$filedata['type']]['ext'].') not supported for reading.', E_USER_ERROR);",
"return",
"null",
";",
"}",
"switch",
"(",
"$",
"filedata",
"[",
"'type'",
"]",
")",
"{",
"case",
"1",
":",
"$",
"dummy",
"=",
"imagecreatefromgif",
"(",
"$",
"filename",
")",
";",
"$",
"functionname",
"=",
"$",
"this",
"->",
"_imagecreatefunction",
";",
"$",
"filedata",
"[",
"'resource'",
"]",
"=",
"$",
"functionname",
"(",
"$",
"filedata",
"[",
"'width'",
"]",
",",
"$",
"filedata",
"[",
"'height'",
"]",
")",
";",
"imagecopy",
"(",
"$",
"filedata",
"[",
"'resource'",
"]",
",",
"$",
"dummy",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"$",
"filedata",
"[",
"'width'",
"]",
",",
"$",
"filedata",
"[",
"'height'",
"]",
")",
";",
"imagedestroy",
"(",
"$",
"dummy",
")",
";",
"break",
";",
"case",
"2",
":",
"$",
"filedata",
"[",
"'resource'",
"]",
"=",
"imagecreatefromjpeg",
"(",
"$",
"filename",
")",
";",
"break",
";",
"case",
"3",
":",
"$",
"dummy",
"=",
"imagecreatefrompng",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"imagecolorstotal",
"(",
"$",
"dummy",
")",
"!=",
"0",
")",
"{",
"$",
"functionname",
"=",
"$",
"this",
"->",
"_imagecreatefunction",
";",
"$",
"filedata",
"[",
"'resource'",
"]",
"=",
"$",
"functionname",
"(",
"$",
"filedata",
"[",
"'width'",
"]",
",",
"$",
"filedata",
"[",
"'height'",
"]",
")",
";",
"imagecopy",
"(",
"$",
"filedata",
"[",
"'resource'",
"]",
",",
"$",
"dummy",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"$",
"filedata",
"[",
"'width'",
"]",
",",
"$",
"filedata",
"[",
"'height'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"filedata",
"[",
"'resource'",
"]",
"=",
"$",
"dummy",
";",
"}",
"unset",
"(",
"$",
"dummy",
")",
";",
"break",
";",
"default",
":",
"//trigger_error($this->_error_prefix . 'Imagetype not supported.', E_USER_ERROR);",
"return",
"null",
";",
"}",
"return",
"$",
"filedata",
";",
"}",
"else",
"{",
"//trigger_error($this->_error_prefix . 'Imagefile (' . $filename . ') does not exist.', E_USER_ERROR);",
"return",
"null",
";",
"}",
"}"
] | Loads a image file
@access private
@param string $filename imagefile to load
@return array associative array with the loaded filedata | [
"Loads",
"a",
"image",
"file"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L514-L570 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox.output | function output($output_type = false, $output_quality = false, $dither = false)
{
if ($output_type === false)
{
$output_type = $this->_img['main']['output_type'];
}
switch ($output_type)
{
case 1:
case 'gif':
case 'GIF':
if ($this->_types[1]['supported'] < 2)
{
//trigger_error($this->_error_prefix . 'Imagetype ('.$this->_types[$output_type]['ext'].') not supported for creating/writing.', E_USER_ERROR);
return null;
}
header('Content-type: ' . $this->_types[$output_type]['mime']);
if ($this->_gd_version >= 2)
{
if ($this->_img['main']['indexedcolors'] == 0)
{
$dummy = imagecreatetruecolor($this->_img['main']['width'], $this->_img['main']['height']);
imagecopy($dummy, $this->_img['main']['resource'], 0, 0, 0, 0, $this->_img['main']['width'], $this->_img['main']['height']);
if ($output_quality === false)
{
$output_quality = IMAGE_TOOLBOX_DEFAULT_8BIT_COLORS;
}
imagetruecolortopalette($dummy, $dither, $output_quality);
imagegif($dummy);
imagedestroy($dummy);
}
}
else
{
imagegif($this->_img['main']['resource']);
}
break;
case 2:
case 'jpg':
case 'jpeg':
case 'JPG':
case 'JPEG':
if ($this->_types[2]['supported'] < 2)
{
return null;
}
header('Content-type: ' . $this->_types[$output_type]['mime']);
if ($output_quality === false)
{
$output_quality = IMAGE_TOOLBOX_DEFAULT_JPEG_QUALITY;
}
imagejpeg($this->_img['main']['resource'], '', $output_quality);
break;
case 3:
case 'png':
case 'PNG':
case 'png24':
case 'PNG24':
if ($this->_types[3]['supported'] < 2)
{
return null;
}
header('Content-type: ' . $this->_types[$output_type]['mime']);
imagepng($this->_img['main']['resource']);
break;
case 4:
case 'png8':
case 'PNG8':
if ($this->_types[3]['supported'] < 2)
{
return null;
}
header('Content-type: ' . $this->_types[$output_type]['mime']);
if ($this->_gd_version >= 2)
{
if ($this->_img['main']['indexedcolors'] == 0)
{
$dummy = imagecreatetruecolor($this->_img['main']['width'], $this->_img['main']['height']);
imagecopy($dummy, $this->_img['main']['resource'], 0, 0, 0, 0, $this->_img['main']['width'], $this->_img['main']['height']);
if ($output_quality === false)
{
$output_quality = IMAGE_TOOLBOX_DEFAULT_8BIT_COLORS;
}
imagetruecolortopalette($dummy, $dither, $output_quality);
imagepng($dummy);
imagedestroy($dummy);
}
}
else
{
imagepng($this->_img['main']['resource']);
}
break;
default:
return null;
}
return true;
} | php | function output($output_type = false, $output_quality = false, $dither = false)
{
if ($output_type === false)
{
$output_type = $this->_img['main']['output_type'];
}
switch ($output_type)
{
case 1:
case 'gif':
case 'GIF':
if ($this->_types[1]['supported'] < 2)
{
//trigger_error($this->_error_prefix . 'Imagetype ('.$this->_types[$output_type]['ext'].') not supported for creating/writing.', E_USER_ERROR);
return null;
}
header('Content-type: ' . $this->_types[$output_type]['mime']);
if ($this->_gd_version >= 2)
{
if ($this->_img['main']['indexedcolors'] == 0)
{
$dummy = imagecreatetruecolor($this->_img['main']['width'], $this->_img['main']['height']);
imagecopy($dummy, $this->_img['main']['resource'], 0, 0, 0, 0, $this->_img['main']['width'], $this->_img['main']['height']);
if ($output_quality === false)
{
$output_quality = IMAGE_TOOLBOX_DEFAULT_8BIT_COLORS;
}
imagetruecolortopalette($dummy, $dither, $output_quality);
imagegif($dummy);
imagedestroy($dummy);
}
}
else
{
imagegif($this->_img['main']['resource']);
}
break;
case 2:
case 'jpg':
case 'jpeg':
case 'JPG':
case 'JPEG':
if ($this->_types[2]['supported'] < 2)
{
return null;
}
header('Content-type: ' . $this->_types[$output_type]['mime']);
if ($output_quality === false)
{
$output_quality = IMAGE_TOOLBOX_DEFAULT_JPEG_QUALITY;
}
imagejpeg($this->_img['main']['resource'], '', $output_quality);
break;
case 3:
case 'png':
case 'PNG':
case 'png24':
case 'PNG24':
if ($this->_types[3]['supported'] < 2)
{
return null;
}
header('Content-type: ' . $this->_types[$output_type]['mime']);
imagepng($this->_img['main']['resource']);
break;
case 4:
case 'png8':
case 'PNG8':
if ($this->_types[3]['supported'] < 2)
{
return null;
}
header('Content-type: ' . $this->_types[$output_type]['mime']);
if ($this->_gd_version >= 2)
{
if ($this->_img['main']['indexedcolors'] == 0)
{
$dummy = imagecreatetruecolor($this->_img['main']['width'], $this->_img['main']['height']);
imagecopy($dummy, $this->_img['main']['resource'], 0, 0, 0, 0, $this->_img['main']['width'], $this->_img['main']['height']);
if ($output_quality === false)
{
$output_quality = IMAGE_TOOLBOX_DEFAULT_8BIT_COLORS;
}
imagetruecolortopalette($dummy, $dither, $output_quality);
imagepng($dummy);
imagedestroy($dummy);
}
}
else
{
imagepng($this->_img['main']['resource']);
}
break;
default:
return null;
}
return true;
} | [
"function",
"output",
"(",
"$",
"output_type",
"=",
"false",
",",
"$",
"output_quality",
"=",
"false",
",",
"$",
"dither",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"output_type",
"===",
"false",
")",
"{",
"$",
"output_type",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'output_type'",
"]",
";",
"}",
"switch",
"(",
"$",
"output_type",
")",
"{",
"case",
"1",
":",
"case",
"'gif'",
":",
"case",
"'GIF'",
":",
"if",
"(",
"$",
"this",
"->",
"_types",
"[",
"1",
"]",
"[",
"'supported'",
"]",
"<",
"2",
")",
"{",
"//trigger_error($this->_error_prefix . 'Imagetype ('.$this->_types[$output_type]['ext'].') not supported for creating/writing.', E_USER_ERROR);",
"return",
"null",
";",
"}",
"header",
"(",
"'Content-type: '",
".",
"$",
"this",
"->",
"_types",
"[",
"$",
"output_type",
"]",
"[",
"'mime'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_gd_version",
">=",
"2",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'indexedcolors'",
"]",
"==",
"0",
")",
"{",
"$",
"dummy",
"=",
"imagecreatetruecolor",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
")",
";",
"imagecopy",
"(",
"$",
"dummy",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
")",
";",
"if",
"(",
"$",
"output_quality",
"===",
"false",
")",
"{",
"$",
"output_quality",
"=",
"IMAGE_TOOLBOX_DEFAULT_8BIT_COLORS",
";",
"}",
"imagetruecolortopalette",
"(",
"$",
"dummy",
",",
"$",
"dither",
",",
"$",
"output_quality",
")",
";",
"imagegif",
"(",
"$",
"dummy",
")",
";",
"imagedestroy",
"(",
"$",
"dummy",
")",
";",
"}",
"}",
"else",
"{",
"imagegif",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
")",
";",
"}",
"break",
";",
"case",
"2",
":",
"case",
"'jpg'",
":",
"case",
"'jpeg'",
":",
"case",
"'JPG'",
":",
"case",
"'JPEG'",
":",
"if",
"(",
"$",
"this",
"->",
"_types",
"[",
"2",
"]",
"[",
"'supported'",
"]",
"<",
"2",
")",
"{",
"return",
"null",
";",
"}",
"header",
"(",
"'Content-type: '",
".",
"$",
"this",
"->",
"_types",
"[",
"$",
"output_type",
"]",
"[",
"'mime'",
"]",
")",
";",
"if",
"(",
"$",
"output_quality",
"===",
"false",
")",
"{",
"$",
"output_quality",
"=",
"IMAGE_TOOLBOX_DEFAULT_JPEG_QUALITY",
";",
"}",
"imagejpeg",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
",",
"''",
",",
"$",
"output_quality",
")",
";",
"break",
";",
"case",
"3",
":",
"case",
"'png'",
":",
"case",
"'PNG'",
":",
"case",
"'png24'",
":",
"case",
"'PNG24'",
":",
"if",
"(",
"$",
"this",
"->",
"_types",
"[",
"3",
"]",
"[",
"'supported'",
"]",
"<",
"2",
")",
"{",
"return",
"null",
";",
"}",
"header",
"(",
"'Content-type: '",
".",
"$",
"this",
"->",
"_types",
"[",
"$",
"output_type",
"]",
"[",
"'mime'",
"]",
")",
";",
"imagepng",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
")",
";",
"break",
";",
"case",
"4",
":",
"case",
"'png8'",
":",
"case",
"'PNG8'",
":",
"if",
"(",
"$",
"this",
"->",
"_types",
"[",
"3",
"]",
"[",
"'supported'",
"]",
"<",
"2",
")",
"{",
"return",
"null",
";",
"}",
"header",
"(",
"'Content-type: '",
".",
"$",
"this",
"->",
"_types",
"[",
"$",
"output_type",
"]",
"[",
"'mime'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_gd_version",
">=",
"2",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'indexedcolors'",
"]",
"==",
"0",
")",
"{",
"$",
"dummy",
"=",
"imagecreatetruecolor",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
")",
";",
"imagecopy",
"(",
"$",
"dummy",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
")",
";",
"if",
"(",
"$",
"output_quality",
"===",
"false",
")",
"{",
"$",
"output_quality",
"=",
"IMAGE_TOOLBOX_DEFAULT_8BIT_COLORS",
";",
"}",
"imagetruecolortopalette",
"(",
"$",
"dummy",
",",
"$",
"dither",
",",
"$",
"output_quality",
")",
";",
"imagepng",
"(",
"$",
"dummy",
")",
";",
"imagedestroy",
"(",
"$",
"dummy",
")",
";",
"}",
"}",
"else",
"{",
"imagepng",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
")",
";",
"}",
"break",
";",
"default",
":",
"return",
"null",
";",
"}",
"return",
"true",
";",
"}"
] | Output a image to the browser
$output_type can be one of the following:<br>
<ul>
<li>'gif' -> gif image (if supported) (8-bit indexed colors)</li>
<li>'png' -> png image (if supported) (truecolor)</li>
<li>'png8' -> png image (if supported) (8-bit indexed colors)</li>
<li>'jpg' -> jpeg image (if supported) (truecolor)</li>
</ul>
(default: same as original)
$dither:<br>
If this is true than dither is used on the conversion from truecolor to 8-bit indexed imageformats (png8, gif)<br>
(default = false)
@param string|integer $output_type type of outputted image
@param integer $output_quality jpeg quality of outputted image (default: IMAGE_TOOLBOX_DEFAULT_JPEG_QUALITY)
@param bool $dither use dither
@return bool true on success, otherwise false | [
"Output",
"a",
"image",
"to",
"the",
"browser"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L593-L690 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox.setResizeMethod | function setResizeMethod($method)
{
switch ($method)
{
case 1:
case 'resize':
$this->_resize_function = 'imagecopyresized';
break;
case 2:
case 'resample':
if (!function_exists('imagecopyresampled'))
{
// no error message. just return false.
return null;
}
$this->_resize_function = 'imagecopyresampled';
break;
case 3:
case 'resample_workaround':
case 'workaround':
case 'bicubic':
$this->_resize_function = '$this->_imageCopyResampledWorkaround';
break;
case 4:
case 'resample_workaround2':
case 'workaround2':
case 'bicubic2':
$this->_resize_function = '$this->_imageCopyResampledWorkaround2';
break;
default:
return null;
}
return true;
} | php | function setResizeMethod($method)
{
switch ($method)
{
case 1:
case 'resize':
$this->_resize_function = 'imagecopyresized';
break;
case 2:
case 'resample':
if (!function_exists('imagecopyresampled'))
{
// no error message. just return false.
return null;
}
$this->_resize_function = 'imagecopyresampled';
break;
case 3:
case 'resample_workaround':
case 'workaround':
case 'bicubic':
$this->_resize_function = '$this->_imageCopyResampledWorkaround';
break;
case 4:
case 'resample_workaround2':
case 'workaround2':
case 'bicubic2':
$this->_resize_function = '$this->_imageCopyResampledWorkaround2';
break;
default:
return null;
}
return true;
} | [
"function",
"setResizeMethod",
"(",
"$",
"method",
")",
"{",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"1",
":",
"case",
"'resize'",
":",
"$",
"this",
"->",
"_resize_function",
"=",
"'imagecopyresized'",
";",
"break",
";",
"case",
"2",
":",
"case",
"'resample'",
":",
"if",
"(",
"!",
"function_exists",
"(",
"'imagecopyresampled'",
")",
")",
"{",
"// no error message. just return false.",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"_resize_function",
"=",
"'imagecopyresampled'",
";",
"break",
";",
"case",
"3",
":",
"case",
"'resample_workaround'",
":",
"case",
"'workaround'",
":",
"case",
"'bicubic'",
":",
"$",
"this",
"->",
"_resize_function",
"=",
"'$this->_imageCopyResampledWorkaround'",
";",
"break",
";",
"case",
"4",
":",
"case",
"'resample_workaround2'",
":",
"case",
"'workaround2'",
":",
"case",
"'bicubic2'",
":",
"$",
"this",
"->",
"_resize_function",
"=",
"'$this->_imageCopyResampledWorkaround2'",
";",
"break",
";",
"default",
":",
"return",
"null",
";",
"}",
"return",
"true",
";",
"}"
] | Sets the resize method of choice
$method can be one of the following:<br>
<ul>
<li>'resize' -> supported by every version of GD (fast but ugly resize of image)</li>
<li>'resample' -> only supported by GD version >= 2.0 (slower but antialiased resize of image)</li>
<li>'workaround' -> supported by every version of GD (workaround function for bicubic resizing, downsizing, VERY slow!, taken from php.net comments)</li>
<li>'workaround2' -> supported by every version of GD (alternative workaround function for bicubic resizing, down- and upsizing, VERY VERY slow!, taken from php.net comments)</li>
</ul>
@param string|integer $method resize method
@return bool true on success, otherwise false | [
"Sets",
"the",
"resize",
"method",
"of",
"choice"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L827-L860 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox.newOutputSize | function newOutputSize($width, $height, $mode = 0, $autorotate = false, $bgcolor = '#000000')
{
if ($width > 0 && $height > 0 && is_int($width) && is_int($height))
{
//ignore aspectratio
if (!$mode)
{
//do not crop to get correct aspectratio
($width >= $height) ? ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL) : ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
if ($this->_img['main']['bias'] == $this->_img['target']['bias'] || !$autorotate)
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = $height;
}
else
{
$this->_img['target']['width'] = $height;
$this->_img['target']['height'] = $width;
}
$this->_img['target']['aspectratio'] = $this->_img['target']['width'] / $this->_img['target']['height'];
$cpy_w = $this->_img['main']['width'];
$cpy_h = $this->_img['main']['height'];
$cpy_w_offset = 0;
$cpy_h_offset = 0;
}
elseif ($mode == 1)
{
//crop to get correct aspectratio
($width >= $height) ? ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL) : ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
if ($this->_img['main']['bias'] == $this->_img['target']['bias'] || !$autorotate)
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = $height;
}
else
{
$this->_img['target']['width'] = $height;
$this->_img['target']['height'] = $width;
}
$this->_img['target']['aspectratio'] = $this->_img['target']['width'] / $this->_img['target']['height'];
if ($this->_img['main']['width'] / $this->_img['target']['width'] >= $this->_img['main']['height'] / $this->_img['target']['height'])
{
$cpy_h = $this->_img['main']['height'];
$cpy_w = (integer)$this->_img['main']['height'] * $this->_img['target']['aspectratio'];
$cpy_w_offset = (integer)($this->_img['main']['width'] - $cpy_w) / 2;
$cpy_h_offset = 0;
}
else
{
$cpy_w = $this->_img['main']['width'];
$cpy_h = (integer)$this->_img['main']['width'] / $this->_img['target']['aspectratio'];
$cpy_h_offset = (integer)($this->_img['main']['height'] - $cpy_h) / 2;
$cpy_w_offset = 0;
}
}
elseif ($mode == 2)
{
//fill remaining background with a color to keep aspectratio
$final_aspectratio = $width / $height;
if ($final_aspectratio < $this->_img['main']['aspectratio'])
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = (integer)$width / $this->_img['main']['aspectratio'];
$cpy_w_offset2 = 0;
$cpy_h_offset2 = (integer)(($height - $this->_img['target']['height']) / 2);
}
else
{
$this->_img['target']['height'] = $height;
$this->_img['target']['width'] = (integer)$height * $this->_img['main']['aspectratio'];
$cpy_h_offset2 = 0;
$cpy_w_offset2 = (integer)(($width - $this->_img['target']['width']) / 2);
}
$this->_img['target']['aspectratio'] = $this->_img['main']['aspectratio'];
$cpy_w = $this->_img['main']['width'];
$cpy_h = $this->_img['main']['height'];
$cpy_w_offset = 0;
$cpy_h_offset = 0;
}
}
elseif (($width == 0 && $height > 0) || ($width > 0 && $height == 0) && is_int($width) && is_int($height))
{
//keep aspectratio
if ($autorotate == true)
{
if ($this->_img['main']['bias'] == IMAGE_TOOLBOX_BIAS_HORIZONTAL && $width > 0)
{
$height = $width;
$width = 0;
}
elseif ($this->_img['main']['bias'] == IMAGE_TOOLBOX_BIAS_VERTICAL && $height > 0)
{
$width = $height;
$height = 0;
}
}
($width >= $height) ? ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL) : ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
if ($width != 0)
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = (integer)$width / $this->_img['main']['aspectratio'];
}
else
{
$this->_img['target']['height'] = $height;
$this->_img['target']['width'] = (integer)$height * $this->_img['main']['aspectratio'];
}
$this->_img['target']['aspectratio'] = $this->_img['main']['aspectratio'];
$cpy_w = $this->_img['main']['width'];
$cpy_h = $this->_img['main']['height'];
$cpy_w_offset = 0;
$cpy_h_offset = 0;
}
else
{
//trigger_error($this->_error_prefix . 'Outputwidth and -height must be integers greater zero.', E_USER_ERROR);
return null;
}
//create resized picture
$functionname = $this->_imagecreatefunction;
$dummy = $functionname($this->_img['target']['width'] + 1, $this->_img['target']['height'] + 1);
eval($this->_resize_function . '($dummy, $this->_img["main"]["resource"], 0, 0, $cpy_w_offset, $cpy_h_offset, $this->_img["target"]["width"], $this->_img["target"]["height"], $cpy_w, $cpy_h);');
if ($mode == 2)
{
$this->_img['target']['resource'] = $functionname($width, $height);
$fillcolor = $this->_hexToPHPColor($bgcolor);
imagefill($this->_img['target']['resource'], 0, 0, $fillcolor);
}
else
{
$this->_img['target']['resource'] = $functionname($this->_img['target']['width'], $this->_img['target']['height']);
$cpy_w_offset2 = 0;
$cpy_h_offset2 = 0;
}
imagecopy($this->_img['target']['resource'], $dummy, $cpy_w_offset2, $cpy_h_offset2, 0, 0, $this->_img['target']['width'], $this->_img['target']['height']);
imagedestroy($dummy);
if ($mode == 2)
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = $height;
}
//update _img['main'] with new data
foreach ($this->_img['target'] as $key => $value)
{
$this->_img['main'][$key] = $value;
}
unset ($this->_img['target']);
return true;
} | php | function newOutputSize($width, $height, $mode = 0, $autorotate = false, $bgcolor = '#000000')
{
if ($width > 0 && $height > 0 && is_int($width) && is_int($height))
{
//ignore aspectratio
if (!$mode)
{
//do not crop to get correct aspectratio
($width >= $height) ? ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL) : ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
if ($this->_img['main']['bias'] == $this->_img['target']['bias'] || !$autorotate)
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = $height;
}
else
{
$this->_img['target']['width'] = $height;
$this->_img['target']['height'] = $width;
}
$this->_img['target']['aspectratio'] = $this->_img['target']['width'] / $this->_img['target']['height'];
$cpy_w = $this->_img['main']['width'];
$cpy_h = $this->_img['main']['height'];
$cpy_w_offset = 0;
$cpy_h_offset = 0;
}
elseif ($mode == 1)
{
//crop to get correct aspectratio
($width >= $height) ? ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL) : ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
if ($this->_img['main']['bias'] == $this->_img['target']['bias'] || !$autorotate)
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = $height;
}
else
{
$this->_img['target']['width'] = $height;
$this->_img['target']['height'] = $width;
}
$this->_img['target']['aspectratio'] = $this->_img['target']['width'] / $this->_img['target']['height'];
if ($this->_img['main']['width'] / $this->_img['target']['width'] >= $this->_img['main']['height'] / $this->_img['target']['height'])
{
$cpy_h = $this->_img['main']['height'];
$cpy_w = (integer)$this->_img['main']['height'] * $this->_img['target']['aspectratio'];
$cpy_w_offset = (integer)($this->_img['main']['width'] - $cpy_w) / 2;
$cpy_h_offset = 0;
}
else
{
$cpy_w = $this->_img['main']['width'];
$cpy_h = (integer)$this->_img['main']['width'] / $this->_img['target']['aspectratio'];
$cpy_h_offset = (integer)($this->_img['main']['height'] - $cpy_h) / 2;
$cpy_w_offset = 0;
}
}
elseif ($mode == 2)
{
//fill remaining background with a color to keep aspectratio
$final_aspectratio = $width / $height;
if ($final_aspectratio < $this->_img['main']['aspectratio'])
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = (integer)$width / $this->_img['main']['aspectratio'];
$cpy_w_offset2 = 0;
$cpy_h_offset2 = (integer)(($height - $this->_img['target']['height']) / 2);
}
else
{
$this->_img['target']['height'] = $height;
$this->_img['target']['width'] = (integer)$height * $this->_img['main']['aspectratio'];
$cpy_h_offset2 = 0;
$cpy_w_offset2 = (integer)(($width - $this->_img['target']['width']) / 2);
}
$this->_img['target']['aspectratio'] = $this->_img['main']['aspectratio'];
$cpy_w = $this->_img['main']['width'];
$cpy_h = $this->_img['main']['height'];
$cpy_w_offset = 0;
$cpy_h_offset = 0;
}
}
elseif (($width == 0 && $height > 0) || ($width > 0 && $height == 0) && is_int($width) && is_int($height))
{
//keep aspectratio
if ($autorotate == true)
{
if ($this->_img['main']['bias'] == IMAGE_TOOLBOX_BIAS_HORIZONTAL && $width > 0)
{
$height = $width;
$width = 0;
}
elseif ($this->_img['main']['bias'] == IMAGE_TOOLBOX_BIAS_VERTICAL && $height > 0)
{
$width = $height;
$height = 0;
}
}
($width >= $height) ? ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL) : ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
if ($width != 0)
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = (integer)$width / $this->_img['main']['aspectratio'];
}
else
{
$this->_img['target']['height'] = $height;
$this->_img['target']['width'] = (integer)$height * $this->_img['main']['aspectratio'];
}
$this->_img['target']['aspectratio'] = $this->_img['main']['aspectratio'];
$cpy_w = $this->_img['main']['width'];
$cpy_h = $this->_img['main']['height'];
$cpy_w_offset = 0;
$cpy_h_offset = 0;
}
else
{
//trigger_error($this->_error_prefix . 'Outputwidth and -height must be integers greater zero.', E_USER_ERROR);
return null;
}
//create resized picture
$functionname = $this->_imagecreatefunction;
$dummy = $functionname($this->_img['target']['width'] + 1, $this->_img['target']['height'] + 1);
eval($this->_resize_function . '($dummy, $this->_img["main"]["resource"], 0, 0, $cpy_w_offset, $cpy_h_offset, $this->_img["target"]["width"], $this->_img["target"]["height"], $cpy_w, $cpy_h);');
if ($mode == 2)
{
$this->_img['target']['resource'] = $functionname($width, $height);
$fillcolor = $this->_hexToPHPColor($bgcolor);
imagefill($this->_img['target']['resource'], 0, 0, $fillcolor);
}
else
{
$this->_img['target']['resource'] = $functionname($this->_img['target']['width'], $this->_img['target']['height']);
$cpy_w_offset2 = 0;
$cpy_h_offset2 = 0;
}
imagecopy($this->_img['target']['resource'], $dummy, $cpy_w_offset2, $cpy_h_offset2, 0, 0, $this->_img['target']['width'], $this->_img['target']['height']);
imagedestroy($dummy);
if ($mode == 2)
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = $height;
}
//update _img['main'] with new data
foreach ($this->_img['target'] as $key => $value)
{
$this->_img['main'][$key] = $value;
}
unset ($this->_img['target']);
return true;
} | [
"function",
"newOutputSize",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"mode",
"=",
"0",
",",
"$",
"autorotate",
"=",
"false",
",",
"$",
"bgcolor",
"=",
"'#000000'",
")",
"{",
"if",
"(",
"$",
"width",
">",
"0",
"&&",
"$",
"height",
">",
"0",
"&&",
"is_int",
"(",
"$",
"width",
")",
"&&",
"is_int",
"(",
"$",
"height",
")",
")",
"{",
"//ignore aspectratio",
"if",
"(",
"!",
"$",
"mode",
")",
"{",
"//do not crop to get correct aspectratio",
"(",
"$",
"width",
">=",
"$",
"height",
")",
"?",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'bias'",
"]",
"=",
"IMAGE_TOOLBOX_BIAS_HORIZONTAL",
")",
":",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'bias'",
"]",
"=",
"IMAGE_TOOLBOX_BIAS_VERTICAL",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'bias'",
"]",
"==",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'bias'",
"]",
"||",
"!",
"$",
"autorotate",
")",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"=",
"$",
"width",
";",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
"=",
"$",
"height",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"=",
"$",
"height",
";",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
"=",
"$",
"width",
";",
"}",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'aspectratio'",
"]",
"=",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"/",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
";",
"$",
"cpy_w",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
";",
"$",
"cpy_h",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
";",
"$",
"cpy_w_offset",
"=",
"0",
";",
"$",
"cpy_h_offset",
"=",
"0",
";",
"}",
"elseif",
"(",
"$",
"mode",
"==",
"1",
")",
"{",
"//crop to get correct aspectratio",
"(",
"$",
"width",
">=",
"$",
"height",
")",
"?",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'bias'",
"]",
"=",
"IMAGE_TOOLBOX_BIAS_HORIZONTAL",
")",
":",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'bias'",
"]",
"=",
"IMAGE_TOOLBOX_BIAS_VERTICAL",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'bias'",
"]",
"==",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'bias'",
"]",
"||",
"!",
"$",
"autorotate",
")",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"=",
"$",
"width",
";",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
"=",
"$",
"height",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"=",
"$",
"height",
";",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
"=",
"$",
"width",
";",
"}",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'aspectratio'",
"]",
"=",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"/",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
"/",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
">=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
"/",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
")",
"{",
"$",
"cpy_h",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
";",
"$",
"cpy_w",
"=",
"(",
"integer",
")",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
"*",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'aspectratio'",
"]",
";",
"$",
"cpy_w_offset",
"=",
"(",
"integer",
")",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
"-",
"$",
"cpy_w",
")",
"/",
"2",
";",
"$",
"cpy_h_offset",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"cpy_w",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
";",
"$",
"cpy_h",
"=",
"(",
"integer",
")",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
"/",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'aspectratio'",
"]",
";",
"$",
"cpy_h_offset",
"=",
"(",
"integer",
")",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
"-",
"$",
"cpy_h",
")",
"/",
"2",
";",
"$",
"cpy_w_offset",
"=",
"0",
";",
"}",
"}",
"elseif",
"(",
"$",
"mode",
"==",
"2",
")",
"{",
"//fill remaining background with a color to keep aspectratio",
"$",
"final_aspectratio",
"=",
"$",
"width",
"/",
"$",
"height",
";",
"if",
"(",
"$",
"final_aspectratio",
"<",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'aspectratio'",
"]",
")",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"=",
"$",
"width",
";",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
"=",
"(",
"integer",
")",
"$",
"width",
"/",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'aspectratio'",
"]",
";",
"$",
"cpy_w_offset2",
"=",
"0",
";",
"$",
"cpy_h_offset2",
"=",
"(",
"integer",
")",
"(",
"(",
"$",
"height",
"-",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
")",
"/",
"2",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
"=",
"$",
"height",
";",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"=",
"(",
"integer",
")",
"$",
"height",
"*",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'aspectratio'",
"]",
";",
"$",
"cpy_h_offset2",
"=",
"0",
";",
"$",
"cpy_w_offset2",
"=",
"(",
"integer",
")",
"(",
"(",
"$",
"width",
"-",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
")",
"/",
"2",
")",
";",
"}",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'aspectratio'",
"]",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'aspectratio'",
"]",
";",
"$",
"cpy_w",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
";",
"$",
"cpy_h",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
";",
"$",
"cpy_w_offset",
"=",
"0",
";",
"$",
"cpy_h_offset",
"=",
"0",
";",
"}",
"}",
"elseif",
"(",
"(",
"$",
"width",
"==",
"0",
"&&",
"$",
"height",
">",
"0",
")",
"||",
"(",
"$",
"width",
">",
"0",
"&&",
"$",
"height",
"==",
"0",
")",
"&&",
"is_int",
"(",
"$",
"width",
")",
"&&",
"is_int",
"(",
"$",
"height",
")",
")",
"{",
"//keep aspectratio",
"if",
"(",
"$",
"autorotate",
"==",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'bias'",
"]",
"==",
"IMAGE_TOOLBOX_BIAS_HORIZONTAL",
"&&",
"$",
"width",
">",
"0",
")",
"{",
"$",
"height",
"=",
"$",
"width",
";",
"$",
"width",
"=",
"0",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'bias'",
"]",
"==",
"IMAGE_TOOLBOX_BIAS_VERTICAL",
"&&",
"$",
"height",
">",
"0",
")",
"{",
"$",
"width",
"=",
"$",
"height",
";",
"$",
"height",
"=",
"0",
";",
"}",
"}",
"(",
"$",
"width",
">=",
"$",
"height",
")",
"?",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'bias'",
"]",
"=",
"IMAGE_TOOLBOX_BIAS_HORIZONTAL",
")",
":",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'bias'",
"]",
"=",
"IMAGE_TOOLBOX_BIAS_VERTICAL",
")",
";",
"if",
"(",
"$",
"width",
"!=",
"0",
")",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"=",
"$",
"width",
";",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
"=",
"(",
"integer",
")",
"$",
"width",
"/",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'aspectratio'",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
"=",
"$",
"height",
";",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"=",
"(",
"integer",
")",
"$",
"height",
"*",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'aspectratio'",
"]",
";",
"}",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'aspectratio'",
"]",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'aspectratio'",
"]",
";",
"$",
"cpy_w",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
";",
"$",
"cpy_h",
"=",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
";",
"$",
"cpy_w_offset",
"=",
"0",
";",
"$",
"cpy_h_offset",
"=",
"0",
";",
"}",
"else",
"{",
"//trigger_error($this->_error_prefix . 'Outputwidth and -height must be integers greater zero.', E_USER_ERROR);",
"return",
"null",
";",
"}",
"//create resized picture",
"$",
"functionname",
"=",
"$",
"this",
"->",
"_imagecreatefunction",
";",
"$",
"dummy",
"=",
"$",
"functionname",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"+",
"1",
",",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
"+",
"1",
")",
";",
"eval",
"(",
"$",
"this",
"->",
"_resize_function",
".",
"'($dummy, $this->_img[\"main\"][\"resource\"], 0, 0, $cpy_w_offset, $cpy_h_offset, $this->_img[\"target\"][\"width\"], $this->_img[\"target\"][\"height\"], $cpy_w, $cpy_h);'",
")",
";",
"if",
"(",
"$",
"mode",
"==",
"2",
")",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'resource'",
"]",
"=",
"$",
"functionname",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"$",
"fillcolor",
"=",
"$",
"this",
"->",
"_hexToPHPColor",
"(",
"$",
"bgcolor",
")",
";",
"imagefill",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'resource'",
"]",
",",
"0",
",",
"0",
",",
"$",
"fillcolor",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'resource'",
"]",
"=",
"$",
"functionname",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
")",
";",
"$",
"cpy_w_offset2",
"=",
"0",
";",
"$",
"cpy_h_offset2",
"=",
"0",
";",
"}",
"imagecopy",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"dummy",
",",
"$",
"cpy_w_offset2",
",",
"$",
"cpy_h_offset2",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
")",
";",
"imagedestroy",
"(",
"$",
"dummy",
")",
";",
"if",
"(",
"$",
"mode",
"==",
"2",
")",
"{",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'width'",
"]",
"=",
"$",
"width",
";",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'height'",
"]",
"=",
"$",
"height",
";",
"}",
"//update _img['main'] with new data",
"foreach",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
")",
";",
"return",
"true",
";",
"}"
] | Resize the current image
if $width = 0 the new width will be calculated from the $height value preserving the correct aspectratio.<br>
if $height = 0 the new height will be calculated from the $width value preserving the correct aspectratio.<br>
$mode can be one of the following:<br>
<ul>
<li>0 -> image will be resized to the new output size, regardless of the original aspectratio. (default)</li>
<li>1 -> image will be cropped if necessary to preserve the aspectratio and avoid image distortions.</li>
<li>2 -> image will be resized preserving its original aspectratio. differences to the new outputsize will be filled with $bgcolor</li>
</ul>
if $autorotate is set to true the given $width and $height values may "change place" if the given image bias is different from the original one.<br>
if either $width or $height is 0, the new size will be applied to either the new width or the new height based on the bias value of the original image.<br>
(default = false)
@param integer $width new width of image
@param integer $height new height of image
@param integer $mode resize mode
@param bool $autorotate use autorotating
@param string $bgcolor background fillcolor (hexformat, e.g. '#FF0000')
@return bool true on success, otherwise false | [
"Resize",
"the",
"current",
"image"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L887-L1041 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox.addImage | function addImage()
{
$args = func_get_args();
$argc = func_num_args();
if ($this->_addImage($argc, $args))
{
return true;
}
else
{
//trigger_error($this->_error_prefix . 'failed to add image.', E_USER_ERROR);
return false;
}
} | php | function addImage()
{
$args = func_get_args();
$argc = func_num_args();
if ($this->_addImage($argc, $args))
{
return true;
}
else
{
//trigger_error($this->_error_prefix . 'failed to add image.', E_USER_ERROR);
return false;
}
} | [
"function",
"addImage",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"argc",
"=",
"func_num_args",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_addImage",
"(",
"$",
"argc",
",",
"$",
"args",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"//trigger_error($this->_error_prefix . 'failed to add image.', E_USER_ERROR);",
"return",
"false",
";",
"}",
"}"
] | Adds a new image resource based on the given parameters.
It does not overwrite the existing image resource.<br>
Instead it is used to load a second image to merge with the existing image.
Parameter:<br>
<i>string</i> <b>$file</b> imagefile to load<br>
Or:<br>
<i>integer</i> <b>$width</b> imagewidth of new image to be created<br>
<i>integer</i> <b>$height</b> imageheight of new image to be created<br>
<i>string</i> <b>$fillcolor</b> optional fill the new image with this color (hexformat, e.g. '#FF0000')<br> | [
"Adds",
"a",
"new",
"image",
"resource",
"based",
"on",
"the",
"given",
"parameters",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L1056-L1070 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox.blend | function blend($x = 0, $y = 0, $mode = IMAGE_TOOLBOX_BLEND_COPY, $percent = 100)
{
if (is_string($x) || is_string($y))
{
list($xalign, $xalign_offset) = explode(" ", $x);
list($yalign, $yalign_offset) = explode(" ", $y);
}
if (is_string($x))
{
switch ($xalign)
{
case 'left':
$dst_x = 0 + $xalign_offset;
$src_x = 0;
$src_w = $this->_img['operator']['width'];
break;
case 'right':
$dst_x = ($this->_img['main']['width'] - $this->_img['operator']['width']) + $xalign_offset;
$src_x = 0;
$src_w = $this->_img['operator']['width'];
break;
case 'middle':
case 'center':
$dst_x = (($this->_img['main']['width'] / 2) - ($this->_img['operator']['width'] / 2)) + $yalign_offset;
$src_x = 0;
$src_w = $this->_img['operator']['width'];
break;
}
}
else
{
if ($x >= 0)
{
$dst_x = $x;
$src_x = 0;
$src_w = $this->_img['operator']['width'];
}
else
{
$dst_x = 0;
$src_x = abs($x);
$src_w = $this->_img['operator']['width'] - $src_x;
}
}
if (is_string($y))
{
switch ($yalign)
{
case 'top':
$dst_y = 0 + $yalign_offset;
$src_y = 0;
$src_h = $this->_img['operator']['height'];
break;
case 'bottom':
$dst_y = ($this->_img['main']['height'] - $this->_img['operator']['height']) + $yalign_offset;
$src_y = 0;
$src_h = $this->_img['operator']['height'];
break;
case 'middle':
case 'center':
$dst_y = (($this->_img['main']['height'] / 2) - ($this->_img['operator']['height'] / 2)) + $yalign_offset;
$src_y = 0;
$src_h = $this->_img['operator']['height'];
break;
}
}
else
{
if ($y >= 0)
{
$dst_y = $y;
$src_y = 0;
$src_h = $this->_img['operator']['height'];
}
else
{
$dst_y = 0;
$src_y = abs($y);
$src_h = $this->_img['operator']['height'] - $src_y;
}
}
$this->_imageBlend($mode, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent);
return true;
} | php | function blend($x = 0, $y = 0, $mode = IMAGE_TOOLBOX_BLEND_COPY, $percent = 100)
{
if (is_string($x) || is_string($y))
{
list($xalign, $xalign_offset) = explode(" ", $x);
list($yalign, $yalign_offset) = explode(" ", $y);
}
if (is_string($x))
{
switch ($xalign)
{
case 'left':
$dst_x = 0 + $xalign_offset;
$src_x = 0;
$src_w = $this->_img['operator']['width'];
break;
case 'right':
$dst_x = ($this->_img['main']['width'] - $this->_img['operator']['width']) + $xalign_offset;
$src_x = 0;
$src_w = $this->_img['operator']['width'];
break;
case 'middle':
case 'center':
$dst_x = (($this->_img['main']['width'] / 2) - ($this->_img['operator']['width'] / 2)) + $yalign_offset;
$src_x = 0;
$src_w = $this->_img['operator']['width'];
break;
}
}
else
{
if ($x >= 0)
{
$dst_x = $x;
$src_x = 0;
$src_w = $this->_img['operator']['width'];
}
else
{
$dst_x = 0;
$src_x = abs($x);
$src_w = $this->_img['operator']['width'] - $src_x;
}
}
if (is_string($y))
{
switch ($yalign)
{
case 'top':
$dst_y = 0 + $yalign_offset;
$src_y = 0;
$src_h = $this->_img['operator']['height'];
break;
case 'bottom':
$dst_y = ($this->_img['main']['height'] - $this->_img['operator']['height']) + $yalign_offset;
$src_y = 0;
$src_h = $this->_img['operator']['height'];
break;
case 'middle':
case 'center':
$dst_y = (($this->_img['main']['height'] / 2) - ($this->_img['operator']['height'] / 2)) + $yalign_offset;
$src_y = 0;
$src_h = $this->_img['operator']['height'];
break;
}
}
else
{
if ($y >= 0)
{
$dst_y = $y;
$src_y = 0;
$src_h = $this->_img['operator']['height'];
}
else
{
$dst_y = 0;
$src_y = abs($y);
$src_h = $this->_img['operator']['height'] - $src_y;
}
}
$this->_imageBlend($mode, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent);
return true;
} | [
"function",
"blend",
"(",
"$",
"x",
"=",
"0",
",",
"$",
"y",
"=",
"0",
",",
"$",
"mode",
"=",
"IMAGE_TOOLBOX_BLEND_COPY",
",",
"$",
"percent",
"=",
"100",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"x",
")",
"||",
"is_string",
"(",
"$",
"y",
")",
")",
"{",
"list",
"(",
"$",
"xalign",
",",
"$",
"xalign_offset",
")",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"x",
")",
";",
"list",
"(",
"$",
"yalign",
",",
"$",
"yalign_offset",
")",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"y",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"x",
")",
")",
"{",
"switch",
"(",
"$",
"xalign",
")",
"{",
"case",
"'left'",
":",
"$",
"dst_x",
"=",
"0",
"+",
"$",
"xalign_offset",
";",
"$",
"src_x",
"=",
"0",
";",
"$",
"src_w",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
";",
"break",
";",
"case",
"'right'",
":",
"$",
"dst_x",
"=",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
"-",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
")",
"+",
"$",
"xalign_offset",
";",
"$",
"src_x",
"=",
"0",
";",
"$",
"src_w",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
";",
"break",
";",
"case",
"'middle'",
":",
"case",
"'center'",
":",
"$",
"dst_x",
"=",
"(",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
"/",
"2",
")",
"-",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
"/",
"2",
")",
")",
"+",
"$",
"yalign_offset",
";",
"$",
"src_x",
"=",
"0",
";",
"$",
"src_w",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
";",
"break",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"x",
">=",
"0",
")",
"{",
"$",
"dst_x",
"=",
"$",
"x",
";",
"$",
"src_x",
"=",
"0",
";",
"$",
"src_w",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
";",
"}",
"else",
"{",
"$",
"dst_x",
"=",
"0",
";",
"$",
"src_x",
"=",
"abs",
"(",
"$",
"x",
")",
";",
"$",
"src_w",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'width'",
"]",
"-",
"$",
"src_x",
";",
"}",
"}",
"if",
"(",
"is_string",
"(",
"$",
"y",
")",
")",
"{",
"switch",
"(",
"$",
"yalign",
")",
"{",
"case",
"'top'",
":",
"$",
"dst_y",
"=",
"0",
"+",
"$",
"yalign_offset",
";",
"$",
"src_y",
"=",
"0",
";",
"$",
"src_h",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
";",
"break",
";",
"case",
"'bottom'",
":",
"$",
"dst_y",
"=",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
"-",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
")",
"+",
"$",
"yalign_offset",
";",
"$",
"src_y",
"=",
"0",
";",
"$",
"src_h",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
";",
"break",
";",
"case",
"'middle'",
":",
"case",
"'center'",
":",
"$",
"dst_y",
"=",
"(",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
"/",
"2",
")",
"-",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
"/",
"2",
")",
")",
"+",
"$",
"yalign_offset",
";",
"$",
"src_y",
"=",
"0",
";",
"$",
"src_h",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
";",
"break",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"y",
">=",
"0",
")",
"{",
"$",
"dst_y",
"=",
"$",
"y",
";",
"$",
"src_y",
"=",
"0",
";",
"$",
"src_h",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
";",
"}",
"else",
"{",
"$",
"dst_y",
"=",
"0",
";",
"$",
"src_y",
"=",
"abs",
"(",
"$",
"y",
")",
";",
"$",
"src_h",
"=",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'height'",
"]",
"-",
"$",
"src_y",
";",
"}",
"}",
"$",
"this",
"->",
"_imageBlend",
"(",
"$",
"mode",
",",
"$",
"dst_x",
",",
"$",
"dst_y",
",",
"$",
"src_x",
",",
"$",
"src_y",
",",
"$",
"src_w",
",",
"$",
"src_h",
",",
"$",
"percent",
")",
";",
"return",
"true",
";",
"}"
] | Blend two images.
Original image and the image loaded with {@link addImage() addImage}<br>
NOTE: This operation can take very long and is not intended for realtime use.
(but of course depends on the power of your server :) )
IMPORTANT: {@link imagecopymerge() imagecopymerged} doesn't work with PHP 4.3.2. Bug ID: {@link http://bugs.php.net/bug.php?id=24816 24816}<br>
$x:<br>
negative values are possible.<br>
You can also use the following keywords ('left', 'center' or 'middle', 'right').<br>
Additionally you can specify an offset in pixel with the keywords like this 'left +10'.<br>
(default = 0)
$y:<br>
negative values are possible.<br>
You can also use the following keywords ('top', 'center' or 'middle', 'bottom').<br>
Additionally you can specify an offset in pixel with the keywords like this 'bottom -10'.<br>
(default = 0)
Possible values for $mode:
<ul>
<li>IMAGE_TOOLBOX_BLEND_COPY</li>
<li>IMAGE_TOOLBOX_BLEND_MULTIPLY</li>
<li>IMAGE_TOOLBOX_BLEND_SCREEN</li>
<li>IMAGE_TOOLBOX_BLEND_DIFFERENCE</li>
<li>IMAGE_TOOLBOX_BLEND_EXCLUSION</li>
<li>IMAGE_TOOLBOX_BLEND_OVERLAY</li>
</ul>
$percent:<br>
alpha value in percent of blend effect (0 - 100)<br>
(default = 100)
@param string|integer $x Horizontal position of second image.
@param integer $y Vertical position of second image. negative values are possible.
@param integer $mode blend mode.
@param integer $percent alpha value | [
"Blend",
"two",
"images",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L1112-L1199 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox._imageBlend | function _imageBlend($mode, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent)
{
if ($mode == IMAGE_TOOLBOX_BLEND_COPY)
{
if ($percent == 100)
{
imagecopy($this->_img['main']['resource'], $this->_img['operator']['resource'], $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
}
else
{
imagecopymerge($this->_img['main']['resource'], $this->_img['operator']['resource'], $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent);
}
}
else
{
$functionname = $this->_imagecreatefunction;
$dummy = $functionname($src_w, $src_h);
for ($y = 0; $y < $src_h; $y++)
{
for ($x = 0; $x < $src_w; $x++)
{
$colorindex = imagecolorat($this->_img['main']['resource'], $dst_x + $x, $dst_y + $y);
$colorrgb1 = imagecolorsforindex($this->_img['main']['resource'], $colorindex);
$colorindex = imagecolorat($this->_img['operator']['resource'], $src_x + $x, $src_y + $y);
$colorrgb2 = imagecolorsforindex($this->_img['operator']['resource'], $colorindex);
$colorblend = $this->_calculateBlendvalue($mode, $colorrgb1, $colorrgb2);
$newcolor = imagecolorallocate($dummy, $colorblend['red'], $colorblend['green'], $colorblend['blue']);
imagesetpixel($dummy, $x, $y, $newcolor);
}
}
$this->_img['target']['resource'] = $functionname($this->_img['main']['width'], $this->_img['main']['height']);
imagecopy($this->_img['target']['resource'], $this->_img['main']['resource'], 0, 0, 0, 0, $this->_img['main']['width'], $this->_img['main']['height']);
imagecopymerge($this->_img['target']['resource'], $dummy, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent);
$this->_img['main']['resource'] = $this->_img['target']['resource'];
unset($this->_img['target']);
}
} | php | function _imageBlend($mode, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent)
{
if ($mode == IMAGE_TOOLBOX_BLEND_COPY)
{
if ($percent == 100)
{
imagecopy($this->_img['main']['resource'], $this->_img['operator']['resource'], $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
}
else
{
imagecopymerge($this->_img['main']['resource'], $this->_img['operator']['resource'], $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent);
}
}
else
{
$functionname = $this->_imagecreatefunction;
$dummy = $functionname($src_w, $src_h);
for ($y = 0; $y < $src_h; $y++)
{
for ($x = 0; $x < $src_w; $x++)
{
$colorindex = imagecolorat($this->_img['main']['resource'], $dst_x + $x, $dst_y + $y);
$colorrgb1 = imagecolorsforindex($this->_img['main']['resource'], $colorindex);
$colorindex = imagecolorat($this->_img['operator']['resource'], $src_x + $x, $src_y + $y);
$colorrgb2 = imagecolorsforindex($this->_img['operator']['resource'], $colorindex);
$colorblend = $this->_calculateBlendvalue($mode, $colorrgb1, $colorrgb2);
$newcolor = imagecolorallocate($dummy, $colorblend['red'], $colorblend['green'], $colorblend['blue']);
imagesetpixel($dummy, $x, $y, $newcolor);
}
}
$this->_img['target']['resource'] = $functionname($this->_img['main']['width'], $this->_img['main']['height']);
imagecopy($this->_img['target']['resource'], $this->_img['main']['resource'], 0, 0, 0, 0, $this->_img['main']['width'], $this->_img['main']['height']);
imagecopymerge($this->_img['target']['resource'], $dummy, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $percent);
$this->_img['main']['resource'] = $this->_img['target']['resource'];
unset($this->_img['target']);
}
} | [
"function",
"_imageBlend",
"(",
"$",
"mode",
",",
"$",
"dst_x",
",",
"$",
"dst_y",
",",
"$",
"src_x",
",",
"$",
"src_y",
",",
"$",
"src_w",
",",
"$",
"src_h",
",",
"$",
"percent",
")",
"{",
"if",
"(",
"$",
"mode",
"==",
"IMAGE_TOOLBOX_BLEND_COPY",
")",
"{",
"if",
"(",
"$",
"percent",
"==",
"100",
")",
"{",
"imagecopy",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"dst_x",
",",
"$",
"dst_y",
",",
"$",
"src_x",
",",
"$",
"src_y",
",",
"$",
"src_w",
",",
"$",
"src_h",
")",
";",
"}",
"else",
"{",
"imagecopymerge",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"dst_x",
",",
"$",
"dst_y",
",",
"$",
"src_x",
",",
"$",
"src_y",
",",
"$",
"src_w",
",",
"$",
"src_h",
",",
"$",
"percent",
")",
";",
"}",
"}",
"else",
"{",
"$",
"functionname",
"=",
"$",
"this",
"->",
"_imagecreatefunction",
";",
"$",
"dummy",
"=",
"$",
"functionname",
"(",
"$",
"src_w",
",",
"$",
"src_h",
")",
";",
"for",
"(",
"$",
"y",
"=",
"0",
";",
"$",
"y",
"<",
"$",
"src_h",
";",
"$",
"y",
"++",
")",
"{",
"for",
"(",
"$",
"x",
"=",
"0",
";",
"$",
"x",
"<",
"$",
"src_w",
";",
"$",
"x",
"++",
")",
"{",
"$",
"colorindex",
"=",
"imagecolorat",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"dst_x",
"+",
"$",
"x",
",",
"$",
"dst_y",
"+",
"$",
"y",
")",
";",
"$",
"colorrgb1",
"=",
"imagecolorsforindex",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"colorindex",
")",
";",
"$",
"colorindex",
"=",
"imagecolorat",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"src_x",
"+",
"$",
"x",
",",
"$",
"src_y",
"+",
"$",
"y",
")",
";",
"$",
"colorrgb2",
"=",
"imagecolorsforindex",
"(",
"$",
"this",
"->",
"_img",
"[",
"'operator'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"colorindex",
")",
";",
"$",
"colorblend",
"=",
"$",
"this",
"->",
"_calculateBlendvalue",
"(",
"$",
"mode",
",",
"$",
"colorrgb1",
",",
"$",
"colorrgb2",
")",
";",
"$",
"newcolor",
"=",
"imagecolorallocate",
"(",
"$",
"dummy",
",",
"$",
"colorblend",
"[",
"'red'",
"]",
",",
"$",
"colorblend",
"[",
"'green'",
"]",
",",
"$",
"colorblend",
"[",
"'blue'",
"]",
")",
";",
"imagesetpixel",
"(",
"$",
"dummy",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"newcolor",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'resource'",
"]",
"=",
"$",
"functionname",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
")",
";",
"imagecopy",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
",",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
")",
";",
"imagecopymerge",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"dummy",
",",
"$",
"dst_x",
",",
"$",
"dst_y",
",",
"$",
"src_x",
",",
"$",
"src_y",
",",
"$",
"src_w",
",",
"$",
"src_h",
",",
"$",
"percent",
")",
";",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
"=",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
"[",
"'resource'",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"_img",
"[",
"'target'",
"]",
")",
";",
"}",
"}"
] | Blend two images.
@access private | [
"Blend",
"two",
"images",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L1206-L1244 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox._calculateBlendvalue | function _calculateBlendvalue($mode, $colorrgb1, $colorrgb2)
{
switch ($mode)
{
case IMAGE_TOOLBOX_BLEND_MULTIPLY:
$c['red'] = ($colorrgb1['red'] * $colorrgb2['red']) >> 8;
$c['green'] = ($colorrgb1['green'] * $colorrgb2['green']) >> 8;
$c['blue'] = ($colorrgb1['blue'] * $colorrgb2['blue']) >> 8;
break;
case IMAGE_TOOLBOX_BLEND_SCREEN:
$c['red'] = 255 - ((255 - $colorrgb1['red']) * (255 - $colorrgb2['red']) >> 8);
$c['green'] = 255 - ((255 - $colorrgb1['green']) * (255 - $colorrgb2['green']) >> 8);
$c['blue'] = 255 - ((255 - $colorrgb1['blue']) * (255 - $colorrgb2['blue']) >> 8);
break;
case IMAGE_TOOLBOX_BLEND_DIFFERENCE:
$c['red'] = abs($colorrgb1['red'] - $colorrgb2['red']);
$c['green'] = abs($colorrgb1['green'] - $colorrgb2['green']);
$c['blue'] = abs($colorrgb1['blue'] - $colorrgb2['blue']);
break;
case IMAGE_TOOLBOX_BLEND_NEGATION:
$c['red'] = 255 - abs(255 - $colorrgb1['red'] - $colorrgb2['red']);
$c['green'] = 255 - abs(255 - $colorrgb1['green'] - $colorrgb2['green']);
$c['blue'] = 255 - abs(255 - $colorrgb1['blue'] - $colorrgb2['blue']);
break;
case IMAGE_TOOLBOX_BLEND_EXCLUSION:
$c['red'] = $colorrgb1['red'] + $colorrgb2['red'] - (($colorrgb1['red'] * $colorrgb2['red']) >> 7);
$c['green'] = $colorrgb1['green'] + $colorrgb2['green'] - (($colorrgb1['green'] * $colorrgb2['green']) >> 7);
$c['blue'] = $colorrgb1['blue'] + $colorrgb2['blue'] - (($colorrgb1['blue'] * $colorrgb2['blue']) >> 7);
break;
case IMAGE_TOOLBOX_BLEND_OVERLAY:
if ($colorrgb1['red'] < 128)
{
$c['red'] = ($colorrgb1['red'] * $colorrgb2['red']) >> 7;
}
else
{
$c['red'] = 255 - ((255 - $colorrgb1['red']) * (255 - $colorrgb2['red']) >> 7);
}
if ($colorrgb1['green'] < 128)
{
$c['green'] = ($colorrgb1['green'] * $colorrgb2['green']) >> 7;
}
else
{
$c['green'] = 255 - ((255 - $colorrgb1['green']) * (255 - $colorrgb2['green']) >> 7);
}
if ($colorrgb1['blue'] < 128)
{
$c['blue'] = ($colorrgb1['blue'] * $colorrgb2['blue']) >> 7;
}
else
{
$c['blue'] = 255 - ((255 - $colorrgb1['blue']) * (255 - $colorrgb2['blue']) >> 7);
}
break;
default:
break;
}
return $c;
} | php | function _calculateBlendvalue($mode, $colorrgb1, $colorrgb2)
{
switch ($mode)
{
case IMAGE_TOOLBOX_BLEND_MULTIPLY:
$c['red'] = ($colorrgb1['red'] * $colorrgb2['red']) >> 8;
$c['green'] = ($colorrgb1['green'] * $colorrgb2['green']) >> 8;
$c['blue'] = ($colorrgb1['blue'] * $colorrgb2['blue']) >> 8;
break;
case IMAGE_TOOLBOX_BLEND_SCREEN:
$c['red'] = 255 - ((255 - $colorrgb1['red']) * (255 - $colorrgb2['red']) >> 8);
$c['green'] = 255 - ((255 - $colorrgb1['green']) * (255 - $colorrgb2['green']) >> 8);
$c['blue'] = 255 - ((255 - $colorrgb1['blue']) * (255 - $colorrgb2['blue']) >> 8);
break;
case IMAGE_TOOLBOX_BLEND_DIFFERENCE:
$c['red'] = abs($colorrgb1['red'] - $colorrgb2['red']);
$c['green'] = abs($colorrgb1['green'] - $colorrgb2['green']);
$c['blue'] = abs($colorrgb1['blue'] - $colorrgb2['blue']);
break;
case IMAGE_TOOLBOX_BLEND_NEGATION:
$c['red'] = 255 - abs(255 - $colorrgb1['red'] - $colorrgb2['red']);
$c['green'] = 255 - abs(255 - $colorrgb1['green'] - $colorrgb2['green']);
$c['blue'] = 255 - abs(255 - $colorrgb1['blue'] - $colorrgb2['blue']);
break;
case IMAGE_TOOLBOX_BLEND_EXCLUSION:
$c['red'] = $colorrgb1['red'] + $colorrgb2['red'] - (($colorrgb1['red'] * $colorrgb2['red']) >> 7);
$c['green'] = $colorrgb1['green'] + $colorrgb2['green'] - (($colorrgb1['green'] * $colorrgb2['green']) >> 7);
$c['blue'] = $colorrgb1['blue'] + $colorrgb2['blue'] - (($colorrgb1['blue'] * $colorrgb2['blue']) >> 7);
break;
case IMAGE_TOOLBOX_BLEND_OVERLAY:
if ($colorrgb1['red'] < 128)
{
$c['red'] = ($colorrgb1['red'] * $colorrgb2['red']) >> 7;
}
else
{
$c['red'] = 255 - ((255 - $colorrgb1['red']) * (255 - $colorrgb2['red']) >> 7);
}
if ($colorrgb1['green'] < 128)
{
$c['green'] = ($colorrgb1['green'] * $colorrgb2['green']) >> 7;
}
else
{
$c['green'] = 255 - ((255 - $colorrgb1['green']) * (255 - $colorrgb2['green']) >> 7);
}
if ($colorrgb1['blue'] < 128)
{
$c['blue'] = ($colorrgb1['blue'] * $colorrgb2['blue']) >> 7;
}
else
{
$c['blue'] = 255 - ((255 - $colorrgb1['blue']) * (255 - $colorrgb2['blue']) >> 7);
}
break;
default:
break;
}
return $c;
} | [
"function",
"_calculateBlendvalue",
"(",
"$",
"mode",
",",
"$",
"colorrgb1",
",",
"$",
"colorrgb2",
")",
"{",
"switch",
"(",
"$",
"mode",
")",
"{",
"case",
"IMAGE_TOOLBOX_BLEND_MULTIPLY",
":",
"$",
"c",
"[",
"'red'",
"]",
"=",
"(",
"$",
"colorrgb1",
"[",
"'red'",
"]",
"*",
"$",
"colorrgb2",
"[",
"'red'",
"]",
")",
">>",
"8",
";",
"$",
"c",
"[",
"'green'",
"]",
"=",
"(",
"$",
"colorrgb1",
"[",
"'green'",
"]",
"*",
"$",
"colorrgb2",
"[",
"'green'",
"]",
")",
">>",
"8",
";",
"$",
"c",
"[",
"'blue'",
"]",
"=",
"(",
"$",
"colorrgb1",
"[",
"'blue'",
"]",
"*",
"$",
"colorrgb2",
"[",
"'blue'",
"]",
")",
">>",
"8",
";",
"break",
";",
"case",
"IMAGE_TOOLBOX_BLEND_SCREEN",
":",
"$",
"c",
"[",
"'red'",
"]",
"=",
"255",
"-",
"(",
"(",
"255",
"-",
"$",
"colorrgb1",
"[",
"'red'",
"]",
")",
"*",
"(",
"255",
"-",
"$",
"colorrgb2",
"[",
"'red'",
"]",
")",
">>",
"8",
")",
";",
"$",
"c",
"[",
"'green'",
"]",
"=",
"255",
"-",
"(",
"(",
"255",
"-",
"$",
"colorrgb1",
"[",
"'green'",
"]",
")",
"*",
"(",
"255",
"-",
"$",
"colorrgb2",
"[",
"'green'",
"]",
")",
">>",
"8",
")",
";",
"$",
"c",
"[",
"'blue'",
"]",
"=",
"255",
"-",
"(",
"(",
"255",
"-",
"$",
"colorrgb1",
"[",
"'blue'",
"]",
")",
"*",
"(",
"255",
"-",
"$",
"colorrgb2",
"[",
"'blue'",
"]",
")",
">>",
"8",
")",
";",
"break",
";",
"case",
"IMAGE_TOOLBOX_BLEND_DIFFERENCE",
":",
"$",
"c",
"[",
"'red'",
"]",
"=",
"abs",
"(",
"$",
"colorrgb1",
"[",
"'red'",
"]",
"-",
"$",
"colorrgb2",
"[",
"'red'",
"]",
")",
";",
"$",
"c",
"[",
"'green'",
"]",
"=",
"abs",
"(",
"$",
"colorrgb1",
"[",
"'green'",
"]",
"-",
"$",
"colorrgb2",
"[",
"'green'",
"]",
")",
";",
"$",
"c",
"[",
"'blue'",
"]",
"=",
"abs",
"(",
"$",
"colorrgb1",
"[",
"'blue'",
"]",
"-",
"$",
"colorrgb2",
"[",
"'blue'",
"]",
")",
";",
"break",
";",
"case",
"IMAGE_TOOLBOX_BLEND_NEGATION",
":",
"$",
"c",
"[",
"'red'",
"]",
"=",
"255",
"-",
"abs",
"(",
"255",
"-",
"$",
"colorrgb1",
"[",
"'red'",
"]",
"-",
"$",
"colorrgb2",
"[",
"'red'",
"]",
")",
";",
"$",
"c",
"[",
"'green'",
"]",
"=",
"255",
"-",
"abs",
"(",
"255",
"-",
"$",
"colorrgb1",
"[",
"'green'",
"]",
"-",
"$",
"colorrgb2",
"[",
"'green'",
"]",
")",
";",
"$",
"c",
"[",
"'blue'",
"]",
"=",
"255",
"-",
"abs",
"(",
"255",
"-",
"$",
"colorrgb1",
"[",
"'blue'",
"]",
"-",
"$",
"colorrgb2",
"[",
"'blue'",
"]",
")",
";",
"break",
";",
"case",
"IMAGE_TOOLBOX_BLEND_EXCLUSION",
":",
"$",
"c",
"[",
"'red'",
"]",
"=",
"$",
"colorrgb1",
"[",
"'red'",
"]",
"+",
"$",
"colorrgb2",
"[",
"'red'",
"]",
"-",
"(",
"(",
"$",
"colorrgb1",
"[",
"'red'",
"]",
"*",
"$",
"colorrgb2",
"[",
"'red'",
"]",
")",
">>",
"7",
")",
";",
"$",
"c",
"[",
"'green'",
"]",
"=",
"$",
"colorrgb1",
"[",
"'green'",
"]",
"+",
"$",
"colorrgb2",
"[",
"'green'",
"]",
"-",
"(",
"(",
"$",
"colorrgb1",
"[",
"'green'",
"]",
"*",
"$",
"colorrgb2",
"[",
"'green'",
"]",
")",
">>",
"7",
")",
";",
"$",
"c",
"[",
"'blue'",
"]",
"=",
"$",
"colorrgb1",
"[",
"'blue'",
"]",
"+",
"$",
"colorrgb2",
"[",
"'blue'",
"]",
"-",
"(",
"(",
"$",
"colorrgb1",
"[",
"'blue'",
"]",
"*",
"$",
"colorrgb2",
"[",
"'blue'",
"]",
")",
">>",
"7",
")",
";",
"break",
";",
"case",
"IMAGE_TOOLBOX_BLEND_OVERLAY",
":",
"if",
"(",
"$",
"colorrgb1",
"[",
"'red'",
"]",
"<",
"128",
")",
"{",
"$",
"c",
"[",
"'red'",
"]",
"=",
"(",
"$",
"colorrgb1",
"[",
"'red'",
"]",
"*",
"$",
"colorrgb2",
"[",
"'red'",
"]",
")",
">>",
"7",
";",
"}",
"else",
"{",
"$",
"c",
"[",
"'red'",
"]",
"=",
"255",
"-",
"(",
"(",
"255",
"-",
"$",
"colorrgb1",
"[",
"'red'",
"]",
")",
"*",
"(",
"255",
"-",
"$",
"colorrgb2",
"[",
"'red'",
"]",
")",
">>",
"7",
")",
";",
"}",
"if",
"(",
"$",
"colorrgb1",
"[",
"'green'",
"]",
"<",
"128",
")",
"{",
"$",
"c",
"[",
"'green'",
"]",
"=",
"(",
"$",
"colorrgb1",
"[",
"'green'",
"]",
"*",
"$",
"colorrgb2",
"[",
"'green'",
"]",
")",
">>",
"7",
";",
"}",
"else",
"{",
"$",
"c",
"[",
"'green'",
"]",
"=",
"255",
"-",
"(",
"(",
"255",
"-",
"$",
"colorrgb1",
"[",
"'green'",
"]",
")",
"*",
"(",
"255",
"-",
"$",
"colorrgb2",
"[",
"'green'",
"]",
")",
">>",
"7",
")",
";",
"}",
"if",
"(",
"$",
"colorrgb1",
"[",
"'blue'",
"]",
"<",
"128",
")",
"{",
"$",
"c",
"[",
"'blue'",
"]",
"=",
"(",
"$",
"colorrgb1",
"[",
"'blue'",
"]",
"*",
"$",
"colorrgb2",
"[",
"'blue'",
"]",
")",
">>",
"7",
";",
"}",
"else",
"{",
"$",
"c",
"[",
"'blue'",
"]",
"=",
"255",
"-",
"(",
"(",
"255",
"-",
"$",
"colorrgb1",
"[",
"'blue'",
"]",
")",
"*",
"(",
"255",
"-",
"$",
"colorrgb2",
"[",
"'blue'",
"]",
")",
">>",
"7",
")",
";",
"}",
"break",
";",
"default",
":",
"break",
";",
"}",
"return",
"$",
"c",
";",
"}"
] | Calculate blend values for given blend mode
@access private | [
"Calculate",
"blend",
"values",
"for",
"given",
"blend",
"mode"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L1251-L1316 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox._iso2uni | function _iso2uni($isoline)
{
$iso2uni = array(
173 => "¡",
155 => "¢",
156 => "£",
15 => "¤",
157 => "¥",
124 => "¦",
21 => "§",
249 => "¨",
184 => "©",
166 => "ª",
174 => "«",
170 => "¬",
169 => "®",
238 => "¯",
248 => "°",
241 => "±",
253 => "²",
252 => "³",
239 => "´",
230 => "µ",
20 => "¶",
250 => "·",
247 => "¸",
251 => "¹",
167 => "º",
175 => "»",
172 => "¼",
171 => "½",
243 => "¾",
168 => "¿",
183 => "À",
181 => "Á",
182 => "Â",
199 => "Ã",
142 => "Ä",
143 => "Å",
146 => "Æ",
128 => "Ç",
212 => "È",
144 => "É",
210 => "Ê",
211 => "Ë",
141 => "Ì",
161 => "Í",
140 => "Î",
139 => "Ï",
209 => "Ð",
165 => "Ñ",
227 => "Ò",
224 => "Ó",
226 => "Ô",
229 => "Õ",
153 => "Ö",
158 => "×",
157 => "Ø",
235 => "Ù",
233 => "Ú",
234 => "Û",
154 => "Ü",
237 => "Ý",
232 => "Þ",
225 => "ß",
133 => "à",
160 => "á",
131 => "â",
198 => "ã",
132 => "ä",
134 => "å",
145 => "æ",
135 => "ç",
138 => "è",
130 => "é",
136 => "ê",
137 => "ë",
141 => "ì",
161 => "í",
140 => "î",
139 => "ï",
208 => "ð",
164 => "ñ",
149 => "ò",
162 => "ó",
147 => "ô",
228 => "õ",
148 => "ö",
246 => "÷",
155 => "ø",
151 => "ù",
163 => "ú",
150 => "û",
129 => "ü",
236 => "ý",
231 => "þ",
152 => "ÿ"
);
for ($i = 0; $i < strlen($isoline); $i++)
{
$thischar = substr($isoline, $i, 1);
$new = $iso2uni[ord($thischar)];
$uniline .= ($new != "") ? $new : $thischar;
}
return $uniline;
} | php | function _iso2uni($isoline)
{
$iso2uni = array(
173 => "¡",
155 => "¢",
156 => "£",
15 => "¤",
157 => "¥",
124 => "¦",
21 => "§",
249 => "¨",
184 => "©",
166 => "ª",
174 => "«",
170 => "¬",
169 => "®",
238 => "¯",
248 => "°",
241 => "±",
253 => "²",
252 => "³",
239 => "´",
230 => "µ",
20 => "¶",
250 => "·",
247 => "¸",
251 => "¹",
167 => "º",
175 => "»",
172 => "¼",
171 => "½",
243 => "¾",
168 => "¿",
183 => "À",
181 => "Á",
182 => "Â",
199 => "Ã",
142 => "Ä",
143 => "Å",
146 => "Æ",
128 => "Ç",
212 => "È",
144 => "É",
210 => "Ê",
211 => "Ë",
141 => "Ì",
161 => "Í",
140 => "Î",
139 => "Ï",
209 => "Ð",
165 => "Ñ",
227 => "Ò",
224 => "Ó",
226 => "Ô",
229 => "Õ",
153 => "Ö",
158 => "×",
157 => "Ø",
235 => "Ù",
233 => "Ú",
234 => "Û",
154 => "Ü",
237 => "Ý",
232 => "Þ",
225 => "ß",
133 => "à",
160 => "á",
131 => "â",
198 => "ã",
132 => "ä",
134 => "å",
145 => "æ",
135 => "ç",
138 => "è",
130 => "é",
136 => "ê",
137 => "ë",
141 => "ì",
161 => "í",
140 => "î",
139 => "ï",
208 => "ð",
164 => "ñ",
149 => "ò",
162 => "ó",
147 => "ô",
228 => "õ",
148 => "ö",
246 => "÷",
155 => "ø",
151 => "ù",
163 => "ú",
150 => "û",
129 => "ü",
236 => "ý",
231 => "þ",
152 => "ÿ"
);
for ($i = 0; $i < strlen($isoline); $i++)
{
$thischar = substr($isoline, $i, 1);
$new = $iso2uni[ord($thischar)];
$uniline .= ($new != "") ? $new : $thischar;
}
return $uniline;
} | [
"function",
"_iso2uni",
"(",
"$",
"isoline",
")",
"{",
"$",
"iso2uni",
"=",
"array",
"(",
"173",
"=>",
"\"¡\"",
",",
"155",
"=>",
"\"¢\"",
",",
"156",
"=>",
"\"£\"",
",",
"15",
"=>",
"\"¤\"",
",",
"157",
"=>",
"\"¥\"",
",",
"124",
"=>",
"\"¦\"",
",",
"21",
"=>",
"\"§\"",
",",
"249",
"=>",
"\"¨\"",
",",
"184",
"=>",
"\"©\"",
",",
"166",
"=>",
"\"ª\"",
",",
"174",
"=>",
"\"«\"",
",",
"170",
"=>",
"\"¬\"",
",",
"169",
"=>",
"\"®\"",
",",
"238",
"=>",
"\"¯\"",
",",
"248",
"=>",
"\"°\"",
",",
"241",
"=>",
"\"±\"",
",",
"253",
"=>",
"\"²\"",
",",
"252",
"=>",
"\"³\"",
",",
"239",
"=>",
"\"´\"",
",",
"230",
"=>",
"\"µ\"",
",",
"20",
"=>",
"\"¶\"",
",",
"250",
"=>",
"\"·\"",
",",
"247",
"=>",
"\"¸\"",
",",
"251",
"=>",
"\"¹\"",
",",
"167",
"=>",
"\"º\"",
",",
"175",
"=>",
"\"»\"",
",",
"172",
"=>",
"\"¼\"",
",",
"171",
"=>",
"\"½\"",
",",
"243",
"=>",
"\"¾\"",
",",
"168",
"=>",
"\"¿\"",
",",
"183",
"=>",
"\"À\"",
",",
"181",
"=>",
"\"Á\"",
",",
"182",
"=>",
"\"Â\"",
",",
"199",
"=>",
"\"Ã\"",
",",
"142",
"=>",
"\"Ä\"",
",",
"143",
"=>",
"\"Å\"",
",",
"146",
"=>",
"\"Æ\"",
",",
"128",
"=>",
"\"Ç\"",
",",
"212",
"=>",
"\"È\"",
",",
"144",
"=>",
"\"É\"",
",",
"210",
"=>",
"\"Ê\"",
",",
"211",
"=>",
"\"Ë\"",
",",
"141",
"=>",
"\"Ì\"",
",",
"161",
"=>",
"\"Í\"",
",",
"140",
"=>",
"\"Î\"",
",",
"139",
"=>",
"\"Ï\"",
",",
"209",
"=>",
"\"Ð\"",
",",
"165",
"=>",
"\"Ñ\"",
",",
"227",
"=>",
"\"Ò\"",
",",
"224",
"=>",
"\"Ó\"",
",",
"226",
"=>",
"\"Ô\"",
",",
"229",
"=>",
"\"Õ\"",
",",
"153",
"=>",
"\"Ö\"",
",",
"158",
"=>",
"\"×\"",
",",
"157",
"=>",
"\"Ø\"",
",",
"235",
"=>",
"\"Ù\"",
",",
"233",
"=>",
"\"Ú\"",
",",
"234",
"=>",
"\"Û\"",
",",
"154",
"=>",
"\"Ü\"",
",",
"237",
"=>",
"\"Ý\"",
",",
"232",
"=>",
"\"Þ\"",
",",
"225",
"=>",
"\"ß\"",
",",
"133",
"=>",
"\"à\"",
",",
"160",
"=>",
"\"á\"",
",",
"131",
"=>",
"\"â\"",
",",
"198",
"=>",
"\"ã\"",
",",
"132",
"=>",
"\"ä\"",
",",
"134",
"=>",
"\"å\"",
",",
"145",
"=>",
"\"æ\"",
",",
"135",
"=>",
"\"ç\"",
",",
"138",
"=>",
"\"è\"",
",",
"130",
"=>",
"\"é\"",
",",
"136",
"=>",
"\"ê\"",
",",
"137",
"=>",
"\"ë\"",
",",
"141",
"=>",
"\"ì\"",
",",
"161",
"=>",
"\"í\"",
",",
"140",
"=>",
"\"î\"",
",",
"139",
"=>",
"\"ï\"",
",",
"208",
"=>",
"\"ð\"",
",",
"164",
"=>",
"\"ñ\"",
",",
"149",
"=>",
"\"ò\"",
",",
"162",
"=>",
"\"ó\"",
",",
"147",
"=>",
"\"ô\"",
",",
"228",
"=>",
"\"õ\"",
",",
"148",
"=>",
"\"ö\"",
",",
"246",
"=>",
"\"÷\"",
",",
"155",
"=>",
"\"ø\"",
",",
"151",
"=>",
"\"ù\"",
",",
"163",
"=>",
"\"ú\"",
",",
"150",
"=>",
"\"û\"",
",",
"129",
"=>",
"\"ü\"",
",",
"236",
"=>",
"\"ý\"",
",",
"231",
"=>",
"\"þ\"",
",",
"152",
"=>",
"\"ÿ\"",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"isoline",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"thischar",
"=",
"substr",
"(",
"$",
"isoline",
",",
"$",
"i",
",",
"1",
")",
";",
"$",
"new",
"=",
"$",
"iso2uni",
"[",
"ord",
"(",
"$",
"thischar",
")",
"]",
";",
"$",
"uniline",
".=",
"(",
"$",
"new",
"!=",
"\"\"",
")",
"?",
"$",
"new",
":",
"$",
"thischar",
";",
"}",
"return",
"$",
"uniline",
";",
"}"
] | convert iso character coding to unicode (PHP conform)
needed for TTF text generation of special characters (Latin-2)
@access private | [
"convert",
"iso",
"character",
"coding",
"to",
"unicode",
"(",
"PHP",
"conform",
")",
"needed",
"for",
"TTF",
"text",
"generation",
"of",
"special",
"characters",
"(",
"Latin",
"-",
"2",
")"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L1324-L1429 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox.addText | function addText($text, $font, $size, $color, $x, $y, $angle = 0)
{
global $HTTP_SERVER_VARS;
if (substr($font, 0, 1) == DIRECTORY_SEPARATOR || (substr($font, 1, 1) == ":" && (substr($font, 2, 1) == "\\" || substr($font, 2, 1) == "/")))
{
$prepath = '';
}
else
{
$prepath = substr($HTTP_SERVER_VARS['SCRIPT_FILENAME'], 0, strrpos($HTTP_SERVER_VARS['SCRIPT_FILENAME'], DIRECTORY_SEPARATOR)) . DIRECTORY_SEPARATOR;
}
$text = $this->_iso2uni($text);
if (is_string($x) || is_string($y))
{
$textsize = imagettfbbox($size, $angle, $prepath . $font, $text);
$textwidth = abs($textsize[2]);
$textheight = abs($textsize[7]);
list($xalign, $xalign_offset) = explode(" ", $x);
list($yalign, $yalign_offset) = explode(" ", $y);
}
if (is_string($x))
{
switch ($xalign)
{
case 'left':
$x = 0 + $xalign_offset;
break;
case 'right':
$x = ($this->_img['main']['width'] - $textwidth) + $xalign_offset;
break;
case 'middle':
case 'center':
$x = (($this->_img['main']['width'] - $textwidth) / 2) + $xalign_offset;
break;
}
}
if (is_string($y))
{
switch ($yalign)
{
case 'top':
$y = (0 + $textheight) + $yalign_offset;
break;
case 'bottom':
$y = ($this->_img['main']['height']) + $yalign_offset;
break;
case 'middle':
case 'center':
$y = ((($this->_img['main']['height'] - $textheight) / 2) + $textheight) + $yalign_offset;
break;
}
}
imagettftext($this->_img['main']['resource'], $size, $angle, $x, $y, $this->_hexToPHPColor($color), $prepath . $font, $text);
return true;
} | php | function addText($text, $font, $size, $color, $x, $y, $angle = 0)
{
global $HTTP_SERVER_VARS;
if (substr($font, 0, 1) == DIRECTORY_SEPARATOR || (substr($font, 1, 1) == ":" && (substr($font, 2, 1) == "\\" || substr($font, 2, 1) == "/")))
{
$prepath = '';
}
else
{
$prepath = substr($HTTP_SERVER_VARS['SCRIPT_FILENAME'], 0, strrpos($HTTP_SERVER_VARS['SCRIPT_FILENAME'], DIRECTORY_SEPARATOR)) . DIRECTORY_SEPARATOR;
}
$text = $this->_iso2uni($text);
if (is_string($x) || is_string($y))
{
$textsize = imagettfbbox($size, $angle, $prepath . $font, $text);
$textwidth = abs($textsize[2]);
$textheight = abs($textsize[7]);
list($xalign, $xalign_offset) = explode(" ", $x);
list($yalign, $yalign_offset) = explode(" ", $y);
}
if (is_string($x))
{
switch ($xalign)
{
case 'left':
$x = 0 + $xalign_offset;
break;
case 'right':
$x = ($this->_img['main']['width'] - $textwidth) + $xalign_offset;
break;
case 'middle':
case 'center':
$x = (($this->_img['main']['width'] - $textwidth) / 2) + $xalign_offset;
break;
}
}
if (is_string($y))
{
switch ($yalign)
{
case 'top':
$y = (0 + $textheight) + $yalign_offset;
break;
case 'bottom':
$y = ($this->_img['main']['height']) + $yalign_offset;
break;
case 'middle':
case 'center':
$y = ((($this->_img['main']['height'] - $textheight) / 2) + $textheight) + $yalign_offset;
break;
}
}
imagettftext($this->_img['main']['resource'], $size, $angle, $x, $y, $this->_hexToPHPColor($color), $prepath . $font, $text);
return true;
} | [
"function",
"addText",
"(",
"$",
"text",
",",
"$",
"font",
",",
"$",
"size",
",",
"$",
"color",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"angle",
"=",
"0",
")",
"{",
"global",
"$",
"HTTP_SERVER_VARS",
";",
"if",
"(",
"substr",
"(",
"$",
"font",
",",
"0",
",",
"1",
")",
"==",
"DIRECTORY_SEPARATOR",
"||",
"(",
"substr",
"(",
"$",
"font",
",",
"1",
",",
"1",
")",
"==",
"\":\"",
"&&",
"(",
"substr",
"(",
"$",
"font",
",",
"2",
",",
"1",
")",
"==",
"\"\\\\\"",
"||",
"substr",
"(",
"$",
"font",
",",
"2",
",",
"1",
")",
"==",
"\"/\"",
")",
")",
")",
"{",
"$",
"prepath",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"prepath",
"=",
"substr",
"(",
"$",
"HTTP_SERVER_VARS",
"[",
"'SCRIPT_FILENAME'",
"]",
",",
"0",
",",
"strrpos",
"(",
"$",
"HTTP_SERVER_VARS",
"[",
"'SCRIPT_FILENAME'",
"]",
",",
"DIRECTORY_SEPARATOR",
")",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"$",
"text",
"=",
"$",
"this",
"->",
"_iso2uni",
"(",
"$",
"text",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"x",
")",
"||",
"is_string",
"(",
"$",
"y",
")",
")",
"{",
"$",
"textsize",
"=",
"imagettfbbox",
"(",
"$",
"size",
",",
"$",
"angle",
",",
"$",
"prepath",
".",
"$",
"font",
",",
"$",
"text",
")",
";",
"$",
"textwidth",
"=",
"abs",
"(",
"$",
"textsize",
"[",
"2",
"]",
")",
";",
"$",
"textheight",
"=",
"abs",
"(",
"$",
"textsize",
"[",
"7",
"]",
")",
";",
"list",
"(",
"$",
"xalign",
",",
"$",
"xalign_offset",
")",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"x",
")",
";",
"list",
"(",
"$",
"yalign",
",",
"$",
"yalign_offset",
")",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"y",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"x",
")",
")",
"{",
"switch",
"(",
"$",
"xalign",
")",
"{",
"case",
"'left'",
":",
"$",
"x",
"=",
"0",
"+",
"$",
"xalign_offset",
";",
"break",
";",
"case",
"'right'",
":",
"$",
"x",
"=",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
"-",
"$",
"textwidth",
")",
"+",
"$",
"xalign_offset",
";",
"break",
";",
"case",
"'middle'",
":",
"case",
"'center'",
":",
"$",
"x",
"=",
"(",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'width'",
"]",
"-",
"$",
"textwidth",
")",
"/",
"2",
")",
"+",
"$",
"xalign_offset",
";",
"break",
";",
"}",
"}",
"if",
"(",
"is_string",
"(",
"$",
"y",
")",
")",
"{",
"switch",
"(",
"$",
"yalign",
")",
"{",
"case",
"'top'",
":",
"$",
"y",
"=",
"(",
"0",
"+",
"$",
"textheight",
")",
"+",
"$",
"yalign_offset",
";",
"break",
";",
"case",
"'bottom'",
":",
"$",
"y",
"=",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
")",
"+",
"$",
"yalign_offset",
";",
"break",
";",
"case",
"'middle'",
":",
"case",
"'center'",
":",
"$",
"y",
"=",
"(",
"(",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'height'",
"]",
"-",
"$",
"textheight",
")",
"/",
"2",
")",
"+",
"$",
"textheight",
")",
"+",
"$",
"yalign_offset",
";",
"break",
";",
"}",
"}",
"imagettftext",
"(",
"$",
"this",
"->",
"_img",
"[",
"'main'",
"]",
"[",
"'resource'",
"]",
",",
"$",
"size",
",",
"$",
"angle",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"this",
"->",
"_hexToPHPColor",
"(",
"$",
"color",
")",
",",
"$",
"prepath",
".",
"$",
"font",
",",
"$",
"text",
")",
";",
"return",
"true",
";",
"}"
] | Writes text over the image
only TTF fonts are supported at the moment
$x:<br>
You can also use the following keywords ('left', 'center' or 'middle', 'right').<br>
Additionally you can specify an offset in pixel with the keywords like this 'left +10'.<br>
(default = 0)
$y:<br>
You can also use the following keywords ('top', 'center' or 'middle', 'bottom').<br>
Additionally you can specify an offset in pixel with the keywords like this 'bottom -10'.<br>
(default = 0)
@param string $text text to be generated.
@param string $font TTF fontfile to be used. (relative paths are ok).
@param integer $size textsize.
@param string $color textcolor in hexformat (e.g. '#FF0000').
@param string|integer $x horizontal postion in pixel.
@param string|integer $y vertical postion in pixel.
@param integer $angle rotation of the text. | [
"Writes",
"text",
"over",
"the",
"image"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L1454-L1513 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox._imageCopyResampledWorkaround | function _imageCopyResampledWorkaround(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
/*
for ($i = 0; $i < imagecolorstotal($src_img); $i++)
{
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'],$colors['green'], $colors['blue']);
}
*/
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;
for ($j = $src_y; $j < $src_y + $dst_h; $j++)
{
$sY = $j * $scaleY;
for ($i = $src_x; $i < $src_x + $dst_w; $i++)
{
$sX = $i * $scaleX;
$c1 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX, (int)$sY + $scaleY2));
$c2 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX, (int)$sY));
$c3 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX + $scaleX2, (int)$sY + $scaleY2));
$c4 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX + $scaleX2, (int)$sY));
$red = (integer)(($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
$green = (integer)(($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
$blue = (integer)(($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
$color = ImageColorClosest($dst_img, $red, $green, $blue);
ImageSetPixel($dst_img, $dst_x + $i - $src_x, $dst_y + $j - $src_y, $color);
}
}
} | php | function _imageCopyResampledWorkaround(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
/*
for ($i = 0; $i < imagecolorstotal($src_img); $i++)
{
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'],$colors['green'], $colors['blue']);
}
*/
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;
for ($j = $src_y; $j < $src_y + $dst_h; $j++)
{
$sY = $j * $scaleY;
for ($i = $src_x; $i < $src_x + $dst_w; $i++)
{
$sX = $i * $scaleX;
$c1 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX, (int)$sY + $scaleY2));
$c2 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX, (int)$sY));
$c3 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX + $scaleX2, (int)$sY + $scaleY2));
$c4 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX + $scaleX2, (int)$sY));
$red = (integer)(($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
$green = (integer)(($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
$blue = (integer)(($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
$color = ImageColorClosest($dst_img, $red, $green, $blue);
ImageSetPixel($dst_img, $dst_x + $i - $src_x, $dst_y + $j - $src_y, $color);
}
}
} | [
"function",
"_imageCopyResampledWorkaround",
"(",
"&",
"$",
"dst_img",
",",
"&",
"$",
"src_img",
",",
"$",
"dst_x",
",",
"$",
"dst_y",
",",
"$",
"src_x",
",",
"$",
"src_y",
",",
"$",
"dst_w",
",",
"$",
"dst_h",
",",
"$",
"src_w",
",",
"$",
"src_h",
")",
"{",
"/*\n for ($i = 0; $i < imagecolorstotal($src_img); $i++)\n {\n $colors = ImageColorsForIndex ($src_img, $i);\n ImageColorAllocate ($dst_img, $colors['red'],$colors['green'], $colors['blue']);\n }\n */",
"$",
"scaleX",
"=",
"(",
"$",
"src_w",
"-",
"1",
")",
"/",
"$",
"dst_w",
";",
"$",
"scaleY",
"=",
"(",
"$",
"src_h",
"-",
"1",
")",
"/",
"$",
"dst_h",
";",
"$",
"scaleX2",
"=",
"$",
"scaleX",
"/",
"2.0",
";",
"$",
"scaleY2",
"=",
"$",
"scaleY",
"/",
"2.0",
";",
"for",
"(",
"$",
"j",
"=",
"$",
"src_y",
";",
"$",
"j",
"<",
"$",
"src_y",
"+",
"$",
"dst_h",
";",
"$",
"j",
"++",
")",
"{",
"$",
"sY",
"=",
"$",
"j",
"*",
"$",
"scaleY",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"src_x",
";",
"$",
"i",
"<",
"$",
"src_x",
"+",
"$",
"dst_w",
";",
"$",
"i",
"++",
")",
"{",
"$",
"sX",
"=",
"$",
"i",
"*",
"$",
"scaleX",
";",
"$",
"c1",
"=",
"ImageColorsForIndex",
"(",
"$",
"src_img",
",",
"ImageColorAt",
"(",
"$",
"src_img",
",",
"(",
"int",
")",
"$",
"sX",
",",
"(",
"int",
")",
"$",
"sY",
"+",
"$",
"scaleY2",
")",
")",
";",
"$",
"c2",
"=",
"ImageColorsForIndex",
"(",
"$",
"src_img",
",",
"ImageColorAt",
"(",
"$",
"src_img",
",",
"(",
"int",
")",
"$",
"sX",
",",
"(",
"int",
")",
"$",
"sY",
")",
")",
";",
"$",
"c3",
"=",
"ImageColorsForIndex",
"(",
"$",
"src_img",
",",
"ImageColorAt",
"(",
"$",
"src_img",
",",
"(",
"int",
")",
"$",
"sX",
"+",
"$",
"scaleX2",
",",
"(",
"int",
")",
"$",
"sY",
"+",
"$",
"scaleY2",
")",
")",
";",
"$",
"c4",
"=",
"ImageColorsForIndex",
"(",
"$",
"src_img",
",",
"ImageColorAt",
"(",
"$",
"src_img",
",",
"(",
"int",
")",
"$",
"sX",
"+",
"$",
"scaleX2",
",",
"(",
"int",
")",
"$",
"sY",
")",
")",
";",
"$",
"red",
"=",
"(",
"integer",
")",
"(",
"(",
"$",
"c1",
"[",
"'red'",
"]",
"+",
"$",
"c2",
"[",
"'red'",
"]",
"+",
"$",
"c3",
"[",
"'red'",
"]",
"+",
"$",
"c4",
"[",
"'red'",
"]",
")",
"/",
"4",
")",
";",
"$",
"green",
"=",
"(",
"integer",
")",
"(",
"(",
"$",
"c1",
"[",
"'green'",
"]",
"+",
"$",
"c2",
"[",
"'green'",
"]",
"+",
"$",
"c3",
"[",
"'green'",
"]",
"+",
"$",
"c4",
"[",
"'green'",
"]",
")",
"/",
"4",
")",
";",
"$",
"blue",
"=",
"(",
"integer",
")",
"(",
"(",
"$",
"c1",
"[",
"'blue'",
"]",
"+",
"$",
"c2",
"[",
"'blue'",
"]",
"+",
"$",
"c3",
"[",
"'blue'",
"]",
"+",
"$",
"c4",
"[",
"'blue'",
"]",
")",
"/",
"4",
")",
";",
"$",
"color",
"=",
"ImageColorClosest",
"(",
"$",
"dst_img",
",",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
";",
"ImageSetPixel",
"(",
"$",
"dst_img",
",",
"$",
"dst_x",
"+",
"$",
"i",
"-",
"$",
"src_x",
",",
"$",
"dst_y",
"+",
"$",
"j",
"-",
"$",
"src_y",
",",
"$",
"color",
")",
";",
"}",
"}",
"}"
] | workaround function for bicubic resizing. works well for downsizing only. VERY slow. taken from php.net comments
@access private | [
"workaround",
"function",
"for",
"bicubic",
"resizing",
".",
"works",
"well",
"for",
"downsizing",
"only",
".",
"VERY",
"slow",
".",
"taken",
"from",
"php",
".",
"net",
"comments"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L1520-L1555 |
Eresus/EresusCMS | src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php | Image_Toolbox._imageCopyResampledWorkaround2 | function _imageCopyResampledWorkaround2(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
ImagePaletteCopy($dst_img, $src_img);
$rX = $src_w / $dst_w;
$rY = $src_h / $dst_h;
$w = 0;
for ($y = $dst_y; $y < $dst_h; $y++)
{
$ow = $w;
$w = round(($y + 1) * $rY);
$t = 0;
for ($x = $dst_x; $x < $dst_w; $x++)
{
$r = $g = $b = 0;
$a = 0;
$ot = $t;
$t = round(($x + 1) * $rX);
for ($u = 0; $u < ($w - $ow); $u++)
{
for ($p = 0; $p < ($t - $ot); $p++)
{
$c = ImageColorsForIndex($src_img, ImageColorAt($src_img, $ot + $p, $ow + $u));
$r += $c['red'];
$g += $c['green'];
$b += $c['blue'];
$a++;
}
}
ImageSetPixel($dst_img, $x, $y, ImageColorClosest($dst_img, $r / $a, $g / $a, $b / $a));
}
}
} | php | function _imageCopyResampledWorkaround2(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
ImagePaletteCopy($dst_img, $src_img);
$rX = $src_w / $dst_w;
$rY = $src_h / $dst_h;
$w = 0;
for ($y = $dst_y; $y < $dst_h; $y++)
{
$ow = $w;
$w = round(($y + 1) * $rY);
$t = 0;
for ($x = $dst_x; $x < $dst_w; $x++)
{
$r = $g = $b = 0;
$a = 0;
$ot = $t;
$t = round(($x + 1) * $rX);
for ($u = 0; $u < ($w - $ow); $u++)
{
for ($p = 0; $p < ($t - $ot); $p++)
{
$c = ImageColorsForIndex($src_img, ImageColorAt($src_img, $ot + $p, $ow + $u));
$r += $c['red'];
$g += $c['green'];
$b += $c['blue'];
$a++;
}
}
ImageSetPixel($dst_img, $x, $y, ImageColorClosest($dst_img, $r / $a, $g / $a, $b / $a));
}
}
} | [
"function",
"_imageCopyResampledWorkaround2",
"(",
"&",
"$",
"dst_img",
",",
"&",
"$",
"src_img",
",",
"$",
"dst_x",
",",
"$",
"dst_y",
",",
"$",
"src_x",
",",
"$",
"src_y",
",",
"$",
"dst_w",
",",
"$",
"dst_h",
",",
"$",
"src_w",
",",
"$",
"src_h",
")",
"{",
"ImagePaletteCopy",
"(",
"$",
"dst_img",
",",
"$",
"src_img",
")",
";",
"$",
"rX",
"=",
"$",
"src_w",
"/",
"$",
"dst_w",
";",
"$",
"rY",
"=",
"$",
"src_h",
"/",
"$",
"dst_h",
";",
"$",
"w",
"=",
"0",
";",
"for",
"(",
"$",
"y",
"=",
"$",
"dst_y",
";",
"$",
"y",
"<",
"$",
"dst_h",
";",
"$",
"y",
"++",
")",
"{",
"$",
"ow",
"=",
"$",
"w",
";",
"$",
"w",
"=",
"round",
"(",
"(",
"$",
"y",
"+",
"1",
")",
"*",
"$",
"rY",
")",
";",
"$",
"t",
"=",
"0",
";",
"for",
"(",
"$",
"x",
"=",
"$",
"dst_x",
";",
"$",
"x",
"<",
"$",
"dst_w",
";",
"$",
"x",
"++",
")",
"{",
"$",
"r",
"=",
"$",
"g",
"=",
"$",
"b",
"=",
"0",
";",
"$",
"a",
"=",
"0",
";",
"$",
"ot",
"=",
"$",
"t",
";",
"$",
"t",
"=",
"round",
"(",
"(",
"$",
"x",
"+",
"1",
")",
"*",
"$",
"rX",
")",
";",
"for",
"(",
"$",
"u",
"=",
"0",
";",
"$",
"u",
"<",
"(",
"$",
"w",
"-",
"$",
"ow",
")",
";",
"$",
"u",
"++",
")",
"{",
"for",
"(",
"$",
"p",
"=",
"0",
";",
"$",
"p",
"<",
"(",
"$",
"t",
"-",
"$",
"ot",
")",
";",
"$",
"p",
"++",
")",
"{",
"$",
"c",
"=",
"ImageColorsForIndex",
"(",
"$",
"src_img",
",",
"ImageColorAt",
"(",
"$",
"src_img",
",",
"$",
"ot",
"+",
"$",
"p",
",",
"$",
"ow",
"+",
"$",
"u",
")",
")",
";",
"$",
"r",
"+=",
"$",
"c",
"[",
"'red'",
"]",
";",
"$",
"g",
"+=",
"$",
"c",
"[",
"'green'",
"]",
";",
"$",
"b",
"+=",
"$",
"c",
"[",
"'blue'",
"]",
";",
"$",
"a",
"++",
";",
"}",
"}",
"ImageSetPixel",
"(",
"$",
"dst_img",
",",
"$",
"x",
",",
"$",
"y",
",",
"ImageColorClosest",
"(",
"$",
"dst_img",
",",
"$",
"r",
"/",
"$",
"a",
",",
"$",
"g",
"/",
"$",
"a",
",",
"$",
"b",
"/",
"$",
"a",
")",
")",
";",
"}",
"}",
"}"
] | alternative workaround function for bicubic resizing. works well for downsizing and upsizing. VERY VERY slow. taken from php.net comments
@access private | [
"alternative",
"workaround",
"function",
"for",
"bicubic",
"resizing",
".",
"works",
"well",
"for",
"downsizing",
"and",
"upsizing",
".",
"VERY",
"VERY",
"slow",
".",
"taken",
"from",
"php",
".",
"net",
"comments"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/ext-3rd/tinymce/plugins/images/connector/php/Image_Toolbox.class.php#L1562-L1593 |
99designs/ergo-http | src/HeaderField.php | HeaderField.fromString | public static function fromString($headerString)
{
$headerString = trim($headerString);
list($name, $value) = explode(': ', trim($headerString), 2);
return new self($name, $value);
} | php | public static function fromString($headerString)
{
$headerString = trim($headerString);
list($name, $value) = explode(': ', trim($headerString), 2);
return new self($name, $value);
} | [
"public",
"static",
"function",
"fromString",
"(",
"$",
"headerString",
")",
"{",
"$",
"headerString",
"=",
"trim",
"(",
"$",
"headerString",
")",
";",
"list",
"(",
"$",
"name",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"': '",
",",
"trim",
"(",
"$",
"headerString",
")",
",",
"2",
")",
";",
"return",
"new",
"self",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}"
] | Creates a header from a string representing a single header.
@param string $headerString
@return | [
"Creates",
"a",
"header",
"from",
"a",
"string",
"representing",
"a",
"single",
"header",
"."
] | train | https://github.com/99designs/ergo-http/blob/979b789f2e011a1cb70a00161e6b7bcd0d2e9c71/src/HeaderField.php#L76-L81 |
tequila/mongodb-odm | src/Proxy/Factory/GeneratorFactory.php | GeneratorFactory.generateProxyClass | public function generateProxyClass(string $documentClass): string
{
if (array_key_exists($documentClass, $this->proxyClassNames)) {
return $this->proxyClassNames[$documentClass];
}
$proxyClassName = $this->getProxyClassName($documentClass);
$proxyGenerator = $this->getGenerator($documentClass);
$classGenerator = $proxyGenerator->generateClass();
$proxyFile = $this->getProxyFileName($proxyClassName);
$proxyDir = dirname($proxyFile);
is_dir($proxyDir) || mkdir($proxyDir, 0777, true);
$fileGenerator = new FileGenerator();
$fileGenerator->setClass($classGenerator);
$code = $fileGenerator->generate();
file_put_contents($proxyFile, $code);
$this->proxyClassNames[$documentClass] = $proxyClassName;
return $proxyClassName;
} | php | public function generateProxyClass(string $documentClass): string
{
if (array_key_exists($documentClass, $this->proxyClassNames)) {
return $this->proxyClassNames[$documentClass];
}
$proxyClassName = $this->getProxyClassName($documentClass);
$proxyGenerator = $this->getGenerator($documentClass);
$classGenerator = $proxyGenerator->generateClass();
$proxyFile = $this->getProxyFileName($proxyClassName);
$proxyDir = dirname($proxyFile);
is_dir($proxyDir) || mkdir($proxyDir, 0777, true);
$fileGenerator = new FileGenerator();
$fileGenerator->setClass($classGenerator);
$code = $fileGenerator->generate();
file_put_contents($proxyFile, $code);
$this->proxyClassNames[$documentClass] = $proxyClassName;
return $proxyClassName;
} | [
"public",
"function",
"generateProxyClass",
"(",
"string",
"$",
"documentClass",
")",
":",
"string",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"documentClass",
",",
"$",
"this",
"->",
"proxyClassNames",
")",
")",
"{",
"return",
"$",
"this",
"->",
"proxyClassNames",
"[",
"$",
"documentClass",
"]",
";",
"}",
"$",
"proxyClassName",
"=",
"$",
"this",
"->",
"getProxyClassName",
"(",
"$",
"documentClass",
")",
";",
"$",
"proxyGenerator",
"=",
"$",
"this",
"->",
"getGenerator",
"(",
"$",
"documentClass",
")",
";",
"$",
"classGenerator",
"=",
"$",
"proxyGenerator",
"->",
"generateClass",
"(",
")",
";",
"$",
"proxyFile",
"=",
"$",
"this",
"->",
"getProxyFileName",
"(",
"$",
"proxyClassName",
")",
";",
"$",
"proxyDir",
"=",
"dirname",
"(",
"$",
"proxyFile",
")",
";",
"is_dir",
"(",
"$",
"proxyDir",
")",
"||",
"mkdir",
"(",
"$",
"proxyDir",
",",
"0777",
",",
"true",
")",
";",
"$",
"fileGenerator",
"=",
"new",
"FileGenerator",
"(",
")",
";",
"$",
"fileGenerator",
"->",
"setClass",
"(",
"$",
"classGenerator",
")",
";",
"$",
"code",
"=",
"$",
"fileGenerator",
"->",
"generate",
"(",
")",
";",
"file_put_contents",
"(",
"$",
"proxyFile",
",",
"$",
"code",
")",
";",
"$",
"this",
"->",
"proxyClassNames",
"[",
"$",
"documentClass",
"]",
"=",
"$",
"proxyClassName",
";",
"return",
"$",
"proxyClassName",
";",
"}"
] | @param string $documentClass
@return string
@throws \ReflectionException | [
"@param",
"string",
"$documentClass"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/Proxy/Factory/GeneratorFactory.php#L54-L74 |
tequila/mongodb-odm | src/Proxy/Factory/GeneratorFactory.php | GeneratorFactory.getGenerator | private function getGenerator(string $documentClass): AbstractGenerator
{
if (!array_key_exists($documentClass, $this->generatorsCache)) {
$metadata = $this->metadataFactory->getClassMetadata($documentClass);
$this->generatorsCache[$documentClass] = $metadata->isNested()
? new NestedProxyGenerator($metadata, $this, $this->proxiesNamespace)
: new RootProxyGenerator($metadata, $this, $this->proxiesNamespace);
}
return $this->generatorsCache[$documentClass];
} | php | private function getGenerator(string $documentClass): AbstractGenerator
{
if (!array_key_exists($documentClass, $this->generatorsCache)) {
$metadata = $this->metadataFactory->getClassMetadata($documentClass);
$this->generatorsCache[$documentClass] = $metadata->isNested()
? new NestedProxyGenerator($metadata, $this, $this->proxiesNamespace)
: new RootProxyGenerator($metadata, $this, $this->proxiesNamespace);
}
return $this->generatorsCache[$documentClass];
} | [
"private",
"function",
"getGenerator",
"(",
"string",
"$",
"documentClass",
")",
":",
"AbstractGenerator",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"documentClass",
",",
"$",
"this",
"->",
"generatorsCache",
")",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"getClassMetadata",
"(",
"$",
"documentClass",
")",
";",
"$",
"this",
"->",
"generatorsCache",
"[",
"$",
"documentClass",
"]",
"=",
"$",
"metadata",
"->",
"isNested",
"(",
")",
"?",
"new",
"NestedProxyGenerator",
"(",
"$",
"metadata",
",",
"$",
"this",
",",
"$",
"this",
"->",
"proxiesNamespace",
")",
":",
"new",
"RootProxyGenerator",
"(",
"$",
"metadata",
",",
"$",
"this",
",",
"$",
"this",
"->",
"proxiesNamespace",
")",
";",
"}",
"return",
"$",
"this",
"->",
"generatorsCache",
"[",
"$",
"documentClass",
"]",
";",
"}"
] | @param string $documentClass
@return AbstractGenerator | [
"@param",
"string",
"$documentClass"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/Proxy/Factory/GeneratorFactory.php#L81-L91 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.isInstalled | public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
{
if ($repo->hasPackage($package)) {
return is_readable($this->getInstallPath($package) . '/' . $package->getExtra()['main']);
}
return false;
} | php | public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package)
{
if ($repo->hasPackage($package)) {
return is_readable($this->getInstallPath($package) . '/' . $package->getExtra()['main']);
}
return false;
} | [
"public",
"function",
"isInstalled",
"(",
"InstalledRepositoryInterface",
"$",
"repo",
",",
"PackageInterface",
"$",
"package",
")",
"{",
"if",
"(",
"$",
"repo",
"->",
"hasPackage",
"(",
"$",
"package",
")",
")",
"{",
"return",
"is_readable",
"(",
"$",
"this",
"->",
"getInstallPath",
"(",
"$",
"package",
")",
".",
"'/'",
".",
"$",
"package",
"->",
"getExtra",
"(",
")",
"[",
"'main'",
"]",
")",
";",
"}",
"return",
"false",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L60-L67 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.install | public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{
$this->installCode($package);
if (! $repo->hasPackage($package)) {
$repo->addPackage(clone $package);
}
} | php | public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{
$this->installCode($package);
if (! $repo->hasPackage($package)) {
$repo->addPackage(clone $package);
}
} | [
"public",
"function",
"install",
"(",
"InstalledRepositoryInterface",
"$",
"repo",
",",
"PackageInterface",
"$",
"package",
")",
"{",
"$",
"this",
"->",
"installCode",
"(",
"$",
"package",
")",
";",
"if",
"(",
"!",
"$",
"repo",
"->",
"hasPackage",
"(",
"$",
"package",
")",
")",
"{",
"$",
"repo",
"->",
"addPackage",
"(",
"clone",
"$",
"package",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L72-L79 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.installGitignore | protected function installGitignore(PackageInterface $package)
{
$installPath = $this->getInstallPath($package) . '/.gitignore';
$templatePath = $this->getTempPath($package) . '/.gitignore.template';
$data = ['APP_PUBLIC' => $this->plugin->getPublicDirectory()];
if (! file_exists($installPath)) {
return $this->compileTemplate($templatePath, $installPath, $data);
}
$downloadGitignore = $this->compileTemplate($templatePath, $data);
$installGitignore = file_get_contents($installPath);
$gitignore = preg_split('/\r?\n/', $downloadGitignore . PHP_EOL . '# User rules' . PHP_EOL . $installGitignore);
$group = 'user rules';
$groups = [];
$rules = [];
$groups['user rules'] = [];
foreach ($gitignore as $rule) {
if (preg_match('/^#\s*(.*)/', $rule, $matches)) {
$group = strtolower($matches[1]);
if (! isset($groups[$group])) {
$groups[$group] = [];
}
} elseif (! preg_match('/^\s*$/', $rule) && ! in_array($rule, $rules)) {
$groups[$group][] = $rules[] = $rule;
}
}
$gitignore = [];
foreach ($groups as $group => $rules) {
if (! count($rules) || $group == 'user rules') {
continue;
}
$this->sortRules($rules);
$gitignore[] = '# ' . ucfirst($group);
$gitignore = array_merge($gitignore, $rules);
$gitignore[] = '';
}
$this->sortRules($groups['user rules']);
$gitignore[] = '# User rules';
$gitignore = array_merge($gitignore, $groups['user rules']);
$gitignore[] = '';
file_put_contents($installPath, implode(PHP_EOL, $gitignore));
} | php | protected function installGitignore(PackageInterface $package)
{
$installPath = $this->getInstallPath($package) . '/.gitignore';
$templatePath = $this->getTempPath($package) . '/.gitignore.template';
$data = ['APP_PUBLIC' => $this->plugin->getPublicDirectory()];
if (! file_exists($installPath)) {
return $this->compileTemplate($templatePath, $installPath, $data);
}
$downloadGitignore = $this->compileTemplate($templatePath, $data);
$installGitignore = file_get_contents($installPath);
$gitignore = preg_split('/\r?\n/', $downloadGitignore . PHP_EOL . '# User rules' . PHP_EOL . $installGitignore);
$group = 'user rules';
$groups = [];
$rules = [];
$groups['user rules'] = [];
foreach ($gitignore as $rule) {
if (preg_match('/^#\s*(.*)/', $rule, $matches)) {
$group = strtolower($matches[1]);
if (! isset($groups[$group])) {
$groups[$group] = [];
}
} elseif (! preg_match('/^\s*$/', $rule) && ! in_array($rule, $rules)) {
$groups[$group][] = $rules[] = $rule;
}
}
$gitignore = [];
foreach ($groups as $group => $rules) {
if (! count($rules) || $group == 'user rules') {
continue;
}
$this->sortRules($rules);
$gitignore[] = '# ' . ucfirst($group);
$gitignore = array_merge($gitignore, $rules);
$gitignore[] = '';
}
$this->sortRules($groups['user rules']);
$gitignore[] = '# User rules';
$gitignore = array_merge($gitignore, $groups['user rules']);
$gitignore[] = '';
file_put_contents($installPath, implode(PHP_EOL, $gitignore));
} | [
"protected",
"function",
"installGitignore",
"(",
"PackageInterface",
"$",
"package",
")",
"{",
"$",
"installPath",
"=",
"$",
"this",
"->",
"getInstallPath",
"(",
"$",
"package",
")",
".",
"'/.gitignore'",
";",
"$",
"templatePath",
"=",
"$",
"this",
"->",
"getTempPath",
"(",
"$",
"package",
")",
".",
"'/.gitignore.template'",
";",
"$",
"data",
"=",
"[",
"'APP_PUBLIC'",
"=>",
"$",
"this",
"->",
"plugin",
"->",
"getPublicDirectory",
"(",
")",
"]",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"installPath",
")",
")",
"{",
"return",
"$",
"this",
"->",
"compileTemplate",
"(",
"$",
"templatePath",
",",
"$",
"installPath",
",",
"$",
"data",
")",
";",
"}",
"$",
"downloadGitignore",
"=",
"$",
"this",
"->",
"compileTemplate",
"(",
"$",
"templatePath",
",",
"$",
"data",
")",
";",
"$",
"installGitignore",
"=",
"file_get_contents",
"(",
"$",
"installPath",
")",
";",
"$",
"gitignore",
"=",
"preg_split",
"(",
"'/\\r?\\n/'",
",",
"$",
"downloadGitignore",
".",
"PHP_EOL",
".",
"'# User rules'",
".",
"PHP_EOL",
".",
"$",
"installGitignore",
")",
";",
"$",
"group",
"=",
"'user rules'",
";",
"$",
"groups",
"=",
"[",
"]",
";",
"$",
"rules",
"=",
"[",
"]",
";",
"$",
"groups",
"[",
"'user rules'",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"gitignore",
"as",
"$",
"rule",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^#\\s*(.*)/'",
",",
"$",
"rule",
",",
"$",
"matches",
")",
")",
"{",
"$",
"group",
"=",
"strtolower",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"groups",
"[",
"$",
"group",
"]",
")",
")",
"{",
"$",
"groups",
"[",
"$",
"group",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"elseif",
"(",
"!",
"preg_match",
"(",
"'/^\\s*$/'",
",",
"$",
"rule",
")",
"&&",
"!",
"in_array",
"(",
"$",
"rule",
",",
"$",
"rules",
")",
")",
"{",
"$",
"groups",
"[",
"$",
"group",
"]",
"[",
"]",
"=",
"$",
"rules",
"[",
"]",
"=",
"$",
"rule",
";",
"}",
"}",
"$",
"gitignore",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
"=>",
"$",
"rules",
")",
"{",
"if",
"(",
"!",
"count",
"(",
"$",
"rules",
")",
"||",
"$",
"group",
"==",
"'user rules'",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"sortRules",
"(",
"$",
"rules",
")",
";",
"$",
"gitignore",
"[",
"]",
"=",
"'# '",
".",
"ucfirst",
"(",
"$",
"group",
")",
";",
"$",
"gitignore",
"=",
"array_merge",
"(",
"$",
"gitignore",
",",
"$",
"rules",
")",
";",
"$",
"gitignore",
"[",
"]",
"=",
"''",
";",
"}",
"$",
"this",
"->",
"sortRules",
"(",
"$",
"groups",
"[",
"'user rules'",
"]",
")",
";",
"$",
"gitignore",
"[",
"]",
"=",
"'# User rules'",
";",
"$",
"gitignore",
"=",
"array_merge",
"(",
"$",
"gitignore",
",",
"$",
"groups",
"[",
"'user rules'",
"]",
")",
";",
"$",
"gitignore",
"[",
"]",
"=",
"''",
";",
"file_put_contents",
"(",
"$",
"installPath",
",",
"implode",
"(",
"PHP_EOL",
",",
"$",
"gitignore",
")",
")",
";",
"}"
] | Set up the .gitignore file.
@param \Composer\Package\PackageInterface $package
@return void | [
"Set",
"up",
"the",
".",
"gitignore",
"file",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L151-L205 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.installDotEnv | protected function installDotEnv(PackageInterface $package)
{
$templatePath = $this->getTempPath($package) . '/.env.template';
$dotEnvPath = $this->getInstallPath($package) . '/.env';
$dotEnvExamplePath = $this->getInstallPath($package) . '/.env.example';
if (! file_exists($templatePath)) {
return;
}
$saltKeys = [
'AUTH_KEY',
'SECURE_AUTH_KEY',
'LOGGED_IN_KEY',
'NONCE_KEY',
'AUTH_SALT',
'SECURE_AUTH_SALT',
'LOGGED_IN_SALT',
'NONCE_SALT',
];
$envExample = ['APP_PUBLIC' => 'public'];
foreach ($saltKeys as $salt) {
$envExample[$salt] = 'YOUR_' . $salt . '_GOES_HERE';
}
$this->compileTemplate($templatePath, $dotEnvExamplePath, $envExample);
if (file_exists($dotEnvPath)) {
return;
}
$env = ['APP_PUBLIC' => $this->plugin->getPublicDirectory()];
foreach ($saltKeys as $salt) {
$env[$salt] = $this->generateSalt();
}
$this->compileTemplate($templatePath, $dotEnvPath, $env);
} | php | protected function installDotEnv(PackageInterface $package)
{
$templatePath = $this->getTempPath($package) . '/.env.template';
$dotEnvPath = $this->getInstallPath($package) . '/.env';
$dotEnvExamplePath = $this->getInstallPath($package) . '/.env.example';
if (! file_exists($templatePath)) {
return;
}
$saltKeys = [
'AUTH_KEY',
'SECURE_AUTH_KEY',
'LOGGED_IN_KEY',
'NONCE_KEY',
'AUTH_SALT',
'SECURE_AUTH_SALT',
'LOGGED_IN_SALT',
'NONCE_SALT',
];
$envExample = ['APP_PUBLIC' => 'public'];
foreach ($saltKeys as $salt) {
$envExample[$salt] = 'YOUR_' . $salt . '_GOES_HERE';
}
$this->compileTemplate($templatePath, $dotEnvExamplePath, $envExample);
if (file_exists($dotEnvPath)) {
return;
}
$env = ['APP_PUBLIC' => $this->plugin->getPublicDirectory()];
foreach ($saltKeys as $salt) {
$env[$salt] = $this->generateSalt();
}
$this->compileTemplate($templatePath, $dotEnvPath, $env);
} | [
"protected",
"function",
"installDotEnv",
"(",
"PackageInterface",
"$",
"package",
")",
"{",
"$",
"templatePath",
"=",
"$",
"this",
"->",
"getTempPath",
"(",
"$",
"package",
")",
".",
"'/.env.template'",
";",
"$",
"dotEnvPath",
"=",
"$",
"this",
"->",
"getInstallPath",
"(",
"$",
"package",
")",
".",
"'/.env'",
";",
"$",
"dotEnvExamplePath",
"=",
"$",
"this",
"->",
"getInstallPath",
"(",
"$",
"package",
")",
".",
"'/.env.example'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"templatePath",
")",
")",
"{",
"return",
";",
"}",
"$",
"saltKeys",
"=",
"[",
"'AUTH_KEY'",
",",
"'SECURE_AUTH_KEY'",
",",
"'LOGGED_IN_KEY'",
",",
"'NONCE_KEY'",
",",
"'AUTH_SALT'",
",",
"'SECURE_AUTH_SALT'",
",",
"'LOGGED_IN_SALT'",
",",
"'NONCE_SALT'",
",",
"]",
";",
"$",
"envExample",
"=",
"[",
"'APP_PUBLIC'",
"=>",
"'public'",
"]",
";",
"foreach",
"(",
"$",
"saltKeys",
"as",
"$",
"salt",
")",
"{",
"$",
"envExample",
"[",
"$",
"salt",
"]",
"=",
"'YOUR_'",
".",
"$",
"salt",
".",
"'_GOES_HERE'",
";",
"}",
"$",
"this",
"->",
"compileTemplate",
"(",
"$",
"templatePath",
",",
"$",
"dotEnvExamplePath",
",",
"$",
"envExample",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"dotEnvPath",
")",
")",
"{",
"return",
";",
"}",
"$",
"env",
"=",
"[",
"'APP_PUBLIC'",
"=>",
"$",
"this",
"->",
"plugin",
"->",
"getPublicDirectory",
"(",
")",
"]",
";",
"foreach",
"(",
"$",
"saltKeys",
"as",
"$",
"salt",
")",
"{",
"$",
"env",
"[",
"$",
"salt",
"]",
"=",
"$",
"this",
"->",
"generateSalt",
"(",
")",
";",
"}",
"$",
"this",
"->",
"compileTemplate",
"(",
"$",
"templatePath",
",",
"$",
"dotEnvPath",
",",
"$",
"env",
")",
";",
"}"
] | Set up the .env file.
@param \Composer\Package\PackageInterface $package
@return void | [
"Set",
"up",
"the",
".",
"env",
"file",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L213-L253 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.checkWordPressInstallation | protected function checkWordPressInstallation()
{
$defaultWpInstallDir = $this->plugin->getRootDirectory() . '/wordpress';
$wpInstallDir = $this->getComposerConfigurator()->getWordPressInstallDirectory();
if (file_exists($defaultWpInstallDir) && is_dir($defaultWpInstallDir)) {
if (! is_dir($wpInstallDir)) {
if (file_exists($wpInstallDir)) {
unlink($wpInstallDir);
}
rename($defaultWpInstallDir, $wpInstallDir);
} else {
rmdir($defaultWpInstallDir);
}
}
} | php | protected function checkWordPressInstallation()
{
$defaultWpInstallDir = $this->plugin->getRootDirectory() . '/wordpress';
$wpInstallDir = $this->getComposerConfigurator()->getWordPressInstallDirectory();
if (file_exists($defaultWpInstallDir) && is_dir($defaultWpInstallDir)) {
if (! is_dir($wpInstallDir)) {
if (file_exists($wpInstallDir)) {
unlink($wpInstallDir);
}
rename($defaultWpInstallDir, $wpInstallDir);
} else {
rmdir($defaultWpInstallDir);
}
}
} | [
"protected",
"function",
"checkWordPressInstallation",
"(",
")",
"{",
"$",
"defaultWpInstallDir",
"=",
"$",
"this",
"->",
"plugin",
"->",
"getRootDirectory",
"(",
")",
".",
"'/wordpress'",
";",
"$",
"wpInstallDir",
"=",
"$",
"this",
"->",
"getComposerConfigurator",
"(",
")",
"->",
"getWordPressInstallDirectory",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"defaultWpInstallDir",
")",
"&&",
"is_dir",
"(",
"$",
"defaultWpInstallDir",
")",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"wpInstallDir",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"wpInstallDir",
")",
")",
"{",
"unlink",
"(",
"$",
"wpInstallDir",
")",
";",
"}",
"rename",
"(",
"$",
"defaultWpInstallDir",
",",
"$",
"wpInstallDir",
")",
";",
"}",
"else",
"{",
"rmdir",
"(",
"$",
"defaultWpInstallDir",
")",
";",
"}",
"}",
"}"
] | Check if WordPress is installed in the correct directory,
and move it there if it is not.
@return void | [
"Check",
"if",
"WordPress",
"is",
"installed",
"in",
"the",
"correct",
"directory",
"and",
"move",
"it",
"there",
"if",
"it",
"is",
"not",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L281-L297 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.selectPreferredLanguageOnWordPressInstall | protected function selectPreferredLanguageOnWordPressInstall()
{
$wpInstallScriptPath = $this->getComposerConfigurator()->getWordPressInstallDirectory() . '/wp-admin/install.php';
if (file_exists($wpInstallScriptPath)) {
$wpInstallScript = file_get_contents($wpInstallScriptPath);
$wpInstallScript = preg_replace('/<\\/body>\\n<\\/html>\\s*$/', '<script>' . PHP_EOL
. 'if (jQuery(\'#language\').find(\'option[value="en_GB"]\').length) {' . PHP_EOL
. ' jQuery(\'#language\').val(\'en_GB\').change();' . PHP_EOL
. '}' . PHP_EOL
. '</script>' . PHP_EOL
. '</body>' . PHP_EOL
. '</html>' . PHP_EOL, $wpInstallScript);
file_put_contents($wpInstallScriptPath, $wpInstallScript);
}
} | php | protected function selectPreferredLanguageOnWordPressInstall()
{
$wpInstallScriptPath = $this->getComposerConfigurator()->getWordPressInstallDirectory() . '/wp-admin/install.php';
if (file_exists($wpInstallScriptPath)) {
$wpInstallScript = file_get_contents($wpInstallScriptPath);
$wpInstallScript = preg_replace('/<\\/body>\\n<\\/html>\\s*$/', '<script>' . PHP_EOL
. 'if (jQuery(\'#language\').find(\'option[value="en_GB"]\').length) {' . PHP_EOL
. ' jQuery(\'#language\').val(\'en_GB\').change();' . PHP_EOL
. '}' . PHP_EOL
. '</script>' . PHP_EOL
. '</body>' . PHP_EOL
. '</html>' . PHP_EOL, $wpInstallScript);
file_put_contents($wpInstallScriptPath, $wpInstallScript);
}
} | [
"protected",
"function",
"selectPreferredLanguageOnWordPressInstall",
"(",
")",
"{",
"$",
"wpInstallScriptPath",
"=",
"$",
"this",
"->",
"getComposerConfigurator",
"(",
")",
"->",
"getWordPressInstallDirectory",
"(",
")",
".",
"'/wp-admin/install.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"wpInstallScriptPath",
")",
")",
"{",
"$",
"wpInstallScript",
"=",
"file_get_contents",
"(",
"$",
"wpInstallScriptPath",
")",
";",
"$",
"wpInstallScript",
"=",
"preg_replace",
"(",
"'/<\\\\/body>\\\\n<\\\\/html>\\\\s*$/'",
",",
"'<script>'",
".",
"PHP_EOL",
".",
"'if (jQuery(\\'#language\\').find(\\'option[value=\"en_GB\"]\\').length) {'",
".",
"PHP_EOL",
".",
"' jQuery(\\'#language\\').val(\\'en_GB\\').change();'",
".",
"PHP_EOL",
".",
"'}'",
".",
"PHP_EOL",
".",
"'</script>'",
".",
"PHP_EOL",
".",
"'</body>'",
".",
"PHP_EOL",
".",
"'</html>'",
".",
"PHP_EOL",
",",
"$",
"wpInstallScript",
")",
";",
"file_put_contents",
"(",
"$",
"wpInstallScriptPath",
",",
"$",
"wpInstallScript",
")",
";",
"}",
"}"
] | Select the preferred en_GB option in the WordPress installation language form.
@return void | [
"Select",
"the",
"preferred",
"en_GB",
"option",
"in",
"the",
"WordPress",
"installation",
"language",
"form",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L304-L320 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.installCode | protected function installCode(PackageInterface $package)
{
$files = $this->getInstallFiles($package);
$installPath = $this->getInstallPath($package);
$downloadPath = $this->getTempPath($package);
$publicPath = $this->plugin->getPublicDirectory();
$this->downloadManager->download($package, $downloadPath);
$this->installFiles($installPath, $downloadPath, $publicPath, $files);
$this->installGitignore($package);
$this->installDotEnv($package);
$this->configureComposer();
$this->checkWordPressInstallation();
$this->selectPreferredLanguageOnWordPressInstall();
$this->filesystem->remove($downloadPath);
} | php | protected function installCode(PackageInterface $package)
{
$files = $this->getInstallFiles($package);
$installPath = $this->getInstallPath($package);
$downloadPath = $this->getTempPath($package);
$publicPath = $this->plugin->getPublicDirectory();
$this->downloadManager->download($package, $downloadPath);
$this->installFiles($installPath, $downloadPath, $publicPath, $files);
$this->installGitignore($package);
$this->installDotEnv($package);
$this->configureComposer();
$this->checkWordPressInstallation();
$this->selectPreferredLanguageOnWordPressInstall();
$this->filesystem->remove($downloadPath);
} | [
"protected",
"function",
"installCode",
"(",
"PackageInterface",
"$",
"package",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"getInstallFiles",
"(",
"$",
"package",
")",
";",
"$",
"installPath",
"=",
"$",
"this",
"->",
"getInstallPath",
"(",
"$",
"package",
")",
";",
"$",
"downloadPath",
"=",
"$",
"this",
"->",
"getTempPath",
"(",
"$",
"package",
")",
";",
"$",
"publicPath",
"=",
"$",
"this",
"->",
"plugin",
"->",
"getPublicDirectory",
"(",
")",
";",
"$",
"this",
"->",
"downloadManager",
"->",
"download",
"(",
"$",
"package",
",",
"$",
"downloadPath",
")",
";",
"$",
"this",
"->",
"installFiles",
"(",
"$",
"installPath",
",",
"$",
"downloadPath",
",",
"$",
"publicPath",
",",
"$",
"files",
")",
";",
"$",
"this",
"->",
"installGitignore",
"(",
"$",
"package",
")",
";",
"$",
"this",
"->",
"installDotEnv",
"(",
"$",
"package",
")",
";",
"$",
"this",
"->",
"configureComposer",
"(",
")",
";",
"$",
"this",
"->",
"checkWordPressInstallation",
"(",
")",
";",
"$",
"this",
"->",
"selectPreferredLanguageOnWordPressInstall",
"(",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"remove",
"(",
"$",
"downloadPath",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L325-L343 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.updateCode | protected function updateCode(PackageInterface $current, PackageInterface $target)
{
$currentInstallPath = $this->getInstallPath($current);
$targetInstallPath = $this->getInstallPath($target);
if ($targetInstallPath !== $currentInstallPath) {
// if the target and initial dirs intersect, we force a remove + install
// to avoid the rename wiping the target dir as part of the initial dir cleanup
if (substr($currentInstallPath, 0, strlen($targetInstallPath)) === $targetInstallPath
|| substr($targetInstallPath, 0, strlen($currentInstallPath)) === $currentInstallPath
) {
$this->removeCode($current);
$this->installCode($target);
return;
}
$this->filesystem->rename($currentInstallPath, $targetInstallPath);
}
$currentFiles = $this->getInstallFiles($current);
$targetFiles = $this->getInstallFiles($target);
$deleteFiles = array_diff($currentFiles, $targetFiles);
foreach ($deleteFiles as $file) {
$this->filesystem->remove($targetInstallPath . '/' . $file);
}
$this->installCode($target);
} | php | protected function updateCode(PackageInterface $current, PackageInterface $target)
{
$currentInstallPath = $this->getInstallPath($current);
$targetInstallPath = $this->getInstallPath($target);
if ($targetInstallPath !== $currentInstallPath) {
// if the target and initial dirs intersect, we force a remove + install
// to avoid the rename wiping the target dir as part of the initial dir cleanup
if (substr($currentInstallPath, 0, strlen($targetInstallPath)) === $targetInstallPath
|| substr($targetInstallPath, 0, strlen($currentInstallPath)) === $currentInstallPath
) {
$this->removeCode($current);
$this->installCode($target);
return;
}
$this->filesystem->rename($currentInstallPath, $targetInstallPath);
}
$currentFiles = $this->getInstallFiles($current);
$targetFiles = $this->getInstallFiles($target);
$deleteFiles = array_diff($currentFiles, $targetFiles);
foreach ($deleteFiles as $file) {
$this->filesystem->remove($targetInstallPath . '/' . $file);
}
$this->installCode($target);
} | [
"protected",
"function",
"updateCode",
"(",
"PackageInterface",
"$",
"current",
",",
"PackageInterface",
"$",
"target",
")",
"{",
"$",
"currentInstallPath",
"=",
"$",
"this",
"->",
"getInstallPath",
"(",
"$",
"current",
")",
";",
"$",
"targetInstallPath",
"=",
"$",
"this",
"->",
"getInstallPath",
"(",
"$",
"target",
")",
";",
"if",
"(",
"$",
"targetInstallPath",
"!==",
"$",
"currentInstallPath",
")",
"{",
"// if the target and initial dirs intersect, we force a remove + install",
"// to avoid the rename wiping the target dir as part of the initial dir cleanup",
"if",
"(",
"substr",
"(",
"$",
"currentInstallPath",
",",
"0",
",",
"strlen",
"(",
"$",
"targetInstallPath",
")",
")",
"===",
"$",
"targetInstallPath",
"||",
"substr",
"(",
"$",
"targetInstallPath",
",",
"0",
",",
"strlen",
"(",
"$",
"currentInstallPath",
")",
")",
"===",
"$",
"currentInstallPath",
")",
"{",
"$",
"this",
"->",
"removeCode",
"(",
"$",
"current",
")",
";",
"$",
"this",
"->",
"installCode",
"(",
"$",
"target",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"filesystem",
"->",
"rename",
"(",
"$",
"currentInstallPath",
",",
"$",
"targetInstallPath",
")",
";",
"}",
"$",
"currentFiles",
"=",
"$",
"this",
"->",
"getInstallFiles",
"(",
"$",
"current",
")",
";",
"$",
"targetFiles",
"=",
"$",
"this",
"->",
"getInstallFiles",
"(",
"$",
"target",
")",
";",
"$",
"deleteFiles",
"=",
"array_diff",
"(",
"$",
"currentFiles",
",",
"$",
"targetFiles",
")",
";",
"foreach",
"(",
"$",
"deleteFiles",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"remove",
"(",
"$",
"targetInstallPath",
".",
"'/'",
".",
"$",
"file",
")",
";",
"}",
"$",
"this",
"->",
"installCode",
"(",
"$",
"target",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L348-L377 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.removeCode | protected function removeCode(PackageInterface $package)
{
$files = $this->getInstallFiles($package);
$installPath = $this->getInstallPath($package);
foreach ($files as $file) {
$this->filesystem->remove($installPath . '/' . $file);
}
} | php | protected function removeCode(PackageInterface $package)
{
$files = $this->getInstallFiles($package);
$installPath = $this->getInstallPath($package);
foreach ($files as $file) {
$this->filesystem->remove($installPath . '/' . $file);
}
} | [
"protected",
"function",
"removeCode",
"(",
"PackageInterface",
"$",
"package",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"getInstallFiles",
"(",
"$",
"package",
")",
";",
"$",
"installPath",
"=",
"$",
"this",
"->",
"getInstallPath",
"(",
"$",
"package",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"remove",
"(",
"$",
"installPath",
".",
"'/'",
".",
"$",
"file",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L382-L390 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.installFiles | protected function installFiles($installPath, $downloadPath, $publicPath, $files = [])
{
foreach ($files as $file => $overwrite) {
if ($overwrite || (! $overwrite && ! file_exists($installPath . '/' . $file))) {
if (! file_exists($downloadPath . '/' . $file)) {
throw new FilesystemException('The file ' . $file . ' could not be found. Please report to cupoftea/wordpress.');
}
$installFile = $installPath . '/' . $file;
if ($publicPath != 'public') {
$installFile = $installPath . '/' . preg_replace('/^public/', $publicPath, $file);
}
if (preg_match('/\\/$/', $file)) {
$this->filesystem->ensureDirectoryExists($installFile);
continue;
}
$this->filesystem->rename($downloadPath . '/' . $file, $installFile);
}
}
} | php | protected function installFiles($installPath, $downloadPath, $publicPath, $files = [])
{
foreach ($files as $file => $overwrite) {
if ($overwrite || (! $overwrite && ! file_exists($installPath . '/' . $file))) {
if (! file_exists($downloadPath . '/' . $file)) {
throw new FilesystemException('The file ' . $file . ' could not be found. Please report to cupoftea/wordpress.');
}
$installFile = $installPath . '/' . $file;
if ($publicPath != 'public') {
$installFile = $installPath . '/' . preg_replace('/^public/', $publicPath, $file);
}
if (preg_match('/\\/$/', $file)) {
$this->filesystem->ensureDirectoryExists($installFile);
continue;
}
$this->filesystem->rename($downloadPath . '/' . $file, $installFile);
}
}
} | [
"protected",
"function",
"installFiles",
"(",
"$",
"installPath",
",",
"$",
"downloadPath",
",",
"$",
"publicPath",
",",
"$",
"files",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
"=>",
"$",
"overwrite",
")",
"{",
"if",
"(",
"$",
"overwrite",
"||",
"(",
"!",
"$",
"overwrite",
"&&",
"!",
"file_exists",
"(",
"$",
"installPath",
".",
"'/'",
".",
"$",
"file",
")",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"downloadPath",
".",
"'/'",
".",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"FilesystemException",
"(",
"'The file '",
".",
"$",
"file",
".",
"' could not be found. Please report to cupoftea/wordpress.'",
")",
";",
"}",
"$",
"installFile",
"=",
"$",
"installPath",
".",
"'/'",
".",
"$",
"file",
";",
"if",
"(",
"$",
"publicPath",
"!=",
"'public'",
")",
"{",
"$",
"installFile",
"=",
"$",
"installPath",
".",
"'/'",
".",
"preg_replace",
"(",
"'/^public/'",
",",
"$",
"publicPath",
",",
"$",
"file",
")",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/\\\\/$/'",
",",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"ensureDirectoryExists",
"(",
"$",
"installFile",
")",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"filesystem",
"->",
"rename",
"(",
"$",
"downloadPath",
".",
"'/'",
".",
"$",
"file",
",",
"$",
"installFile",
")",
";",
"}",
"}",
"}"
] | Install files.
@param string $installPath
@param string $downloadPath
@param string $publicPath
@param array $files
@return void | [
"Install",
"files",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L401-L424 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.compileTemplate | private function compileTemplate($templatePath, $destinationPath, $data = null)
{
if ($data == null) {
$data = $destinationPath;
$destinationPath = null;
}
if (! isset($this->templates[$templatePath])) {
$this->templates[$templatePath] = file_get_contents($templatePath);
}
$compiled = preg_replace_callback('/{{\s*([A-z0-9_-]+)\s*}}/', function ($matches) use ($data) {
if (isset($data[$matches[1]])) {
return $data[$matches[1]];
}
return $matches[0];
}, $this->templates[$templatePath]);
if ($destinationPath) {
file_put_contents($destinationPath, $compiled);
}
return $compiled;
} | php | private function compileTemplate($templatePath, $destinationPath, $data = null)
{
if ($data == null) {
$data = $destinationPath;
$destinationPath = null;
}
if (! isset($this->templates[$templatePath])) {
$this->templates[$templatePath] = file_get_contents($templatePath);
}
$compiled = preg_replace_callback('/{{\s*([A-z0-9_-]+)\s*}}/', function ($matches) use ($data) {
if (isset($data[$matches[1]])) {
return $data[$matches[1]];
}
return $matches[0];
}, $this->templates[$templatePath]);
if ($destinationPath) {
file_put_contents($destinationPath, $compiled);
}
return $compiled;
} | [
"private",
"function",
"compileTemplate",
"(",
"$",
"templatePath",
",",
"$",
"destinationPath",
",",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"data",
"==",
"null",
")",
"{",
"$",
"data",
"=",
"$",
"destinationPath",
";",
"$",
"destinationPath",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"templates",
"[",
"$",
"templatePath",
"]",
")",
")",
"{",
"$",
"this",
"->",
"templates",
"[",
"$",
"templatePath",
"]",
"=",
"file_get_contents",
"(",
"$",
"templatePath",
")",
";",
"}",
"$",
"compiled",
"=",
"preg_replace_callback",
"(",
"'/{{\\s*([A-z0-9_-]+)\\s*}}/'",
",",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
";",
"}",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
",",
"$",
"this",
"->",
"templates",
"[",
"$",
"templatePath",
"]",
")",
";",
"if",
"(",
"$",
"destinationPath",
")",
"{",
"file_put_contents",
"(",
"$",
"destinationPath",
",",
"$",
"compiled",
")",
";",
"}",
"return",
"$",
"compiled",
";",
"}"
] | Compile a template file.
@param string $templatePath
@param string $destinationPath
@param array|null $data
@return string | [
"Compile",
"a",
"template",
"file",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L434-L458 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.sortRules | private function sortRules(&$rules)
{
sort($rules);
usort($rules, function ($a, $b) {
return strlen($a) - strlen($b);
});
} | php | private function sortRules(&$rules)
{
sort($rules);
usort($rules, function ($a, $b) {
return strlen($a) - strlen($b);
});
} | [
"private",
"function",
"sortRules",
"(",
"&",
"$",
"rules",
")",
"{",
"sort",
"(",
"$",
"rules",
")",
";",
"usort",
"(",
"$",
"rules",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"return",
"strlen",
"(",
"$",
"a",
")",
"-",
"strlen",
"(",
"$",
"b",
")",
";",
"}",
")",
";",
"}"
] | Sort gitignore rules.
@param array &$rules
@return void | [
"Sort",
"gitignore",
"rules",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L466-L472 |
CupOfTea696/WordPress-Composer | src/Installer.php | Installer.generateSalt | private function generateSalt()
{
$str = '';
$length = 64;
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(){}[]/|`,.?+-_=:;<> ';
$count = strlen($chars);
while ($length--) {
$str .= $chars[mt_rand(0, $count - 1)];
}
return 'base64:' . base64_encode($str);
} | php | private function generateSalt()
{
$str = '';
$length = 64;
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(){}[]/|`,.?+-_=:;<> ';
$count = strlen($chars);
while ($length--) {
$str .= $chars[mt_rand(0, $count - 1)];
}
return 'base64:' . base64_encode($str);
} | [
"private",
"function",
"generateSalt",
"(",
")",
"{",
"$",
"str",
"=",
"''",
";",
"$",
"length",
"=",
"64",
";",
"$",
"chars",
"=",
"'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(){}[]/|`,.?+-_=:;<> '",
";",
"$",
"count",
"=",
"strlen",
"(",
"$",
"chars",
")",
";",
"while",
"(",
"$",
"length",
"--",
")",
"{",
"$",
"str",
".=",
"$",
"chars",
"[",
"mt_rand",
"(",
"0",
",",
"$",
"count",
"-",
"1",
")",
"]",
";",
"}",
"return",
"'base64:'",
".",
"base64_encode",
"(",
"$",
"str",
")",
";",
"}"
] | Generate a Salt Key.
@return string | [
"Generate",
"a",
"Salt",
"Key",
"."
] | train | https://github.com/CupOfTea696/WordPress-Composer/blob/8c0abc10f82b8ce1db5354f6a041c7587ad3fb90/src/Installer.php#L479-L491 |
ShaoZeMing/laravel-merchant | src/Form/Field.php | Field.removeElementClass | public function removeElementClass($class)
{
$delClass = [];
if (is_string($class) || is_array($class)) {
$delClass = (array) $class;
}
foreach ($delClass as $del) {
if (($key = array_search($del, $this->elementClass))) {
unset($this->elementClass[$key]);
}
}
return $this;
} | php | public function removeElementClass($class)
{
$delClass = [];
if (is_string($class) || is_array($class)) {
$delClass = (array) $class;
}
foreach ($delClass as $del) {
if (($key = array_search($del, $this->elementClass))) {
unset($this->elementClass[$key]);
}
}
return $this;
} | [
"public",
"function",
"removeElementClass",
"(",
"$",
"class",
")",
"{",
"$",
"delClass",
"=",
"[",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"class",
")",
"||",
"is_array",
"(",
"$",
"class",
")",
")",
"{",
"$",
"delClass",
"=",
"(",
"array",
")",
"$",
"class",
";",
"}",
"foreach",
"(",
"$",
"delClass",
"as",
"$",
"del",
")",
"{",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"del",
",",
"$",
"this",
"->",
"elementClass",
")",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"elementClass",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove element class.
@param $class
@return $this | [
"Remove",
"element",
"class",
"."
] | train | https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Form/Field.php#L835-L850 |
ShaoZeMing/laravel-merchant | src/Form/Field.php | Field.getView | public function getView()
{
if (!empty($this->view)) {
return $this->view;
}
$class = explode('\\', get_called_class());
return 'merchant::form.'.strtolower(end($class));
} | php | public function getView()
{
if (!empty($this->view)) {
return $this->view;
}
$class = explode('\\', get_called_class());
return 'merchant::form.'.strtolower(end($class));
} | [
"public",
"function",
"getView",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"view",
")",
")",
"{",
"return",
"$",
"this",
"->",
"view",
";",
"}",
"$",
"class",
"=",
"explode",
"(",
"'\\\\'",
",",
"get_called_class",
"(",
")",
")",
";",
"return",
"'merchant::form.'",
".",
"strtolower",
"(",
"end",
"(",
"$",
"class",
")",
")",
";",
"}"
] | Get view of this field.
@return string | [
"Get",
"view",
"of",
"this",
"field",
"."
] | train | https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Form/Field.php#L879-L888 |
ShaoZeMing/laravel-merchant | src/Form/Field.php | Field.render | public function render()
{
Merchant::script($this->script);
return view($this->getView(), $this->variables());
} | php | public function render()
{
Merchant::script($this->script);
return view($this->getView(), $this->variables());
} | [
"public",
"function",
"render",
"(",
")",
"{",
"Merchant",
"::",
"script",
"(",
"$",
"this",
"->",
"script",
")",
";",
"return",
"view",
"(",
"$",
"this",
"->",
"getView",
"(",
")",
",",
"$",
"this",
"->",
"variables",
"(",
")",
")",
";",
"}"
] | Render this filed.
@return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | [
"Render",
"this",
"filed",
"."
] | train | https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Form/Field.php#L905-L910 |
php-lug/lug | src/Bundle/GridBundle/Sort/SorterRenderer.php | SorterRenderer.render | public function render(GridViewInterface $grid, ColumnInterface $column, $sorting)
{
$definition = $grid->getDefinition();
$name = $column->getName();
if (!$definition->hasSort($name)) {
return;
}
$sort = $sorting === SorterInterface::ASC ? $name : '-'.$name;
$routeParameters = [];
if (($request = $this->requestStack->getMasterRequest()) !== null) {
$routeParameters = array_merge($request->attributes->get('_route_params', []), $request->query->all());
}
if (!isset($routeParameters['grid']['reset'])
&& isset($routeParameters['grid']['sorting'])
&& $routeParameters['grid']['sorting'] === $sort) {
return;
}
if ($definition->hasOption('persistent') && $definition->getOption('persistent')) {
$filters = $this->filterManager->get($definition);
if (isset($filters['sorting']) && $filters['sorting'] === $sort) {
return;
}
}
$routeParameters['grid']['sorting'] = $sort;
unset($routeParameters['grid']['reset']);
return $this->urlGenerator->generate($definition->getOption('grid_route'), $routeParameters);
} | php | public function render(GridViewInterface $grid, ColumnInterface $column, $sorting)
{
$definition = $grid->getDefinition();
$name = $column->getName();
if (!$definition->hasSort($name)) {
return;
}
$sort = $sorting === SorterInterface::ASC ? $name : '-'.$name;
$routeParameters = [];
if (($request = $this->requestStack->getMasterRequest()) !== null) {
$routeParameters = array_merge($request->attributes->get('_route_params', []), $request->query->all());
}
if (!isset($routeParameters['grid']['reset'])
&& isset($routeParameters['grid']['sorting'])
&& $routeParameters['grid']['sorting'] === $sort) {
return;
}
if ($definition->hasOption('persistent') && $definition->getOption('persistent')) {
$filters = $this->filterManager->get($definition);
if (isset($filters['sorting']) && $filters['sorting'] === $sort) {
return;
}
}
$routeParameters['grid']['sorting'] = $sort;
unset($routeParameters['grid']['reset']);
return $this->urlGenerator->generate($definition->getOption('grid_route'), $routeParameters);
} | [
"public",
"function",
"render",
"(",
"GridViewInterface",
"$",
"grid",
",",
"ColumnInterface",
"$",
"column",
",",
"$",
"sorting",
")",
"{",
"$",
"definition",
"=",
"$",
"grid",
"->",
"getDefinition",
"(",
")",
";",
"$",
"name",
"=",
"$",
"column",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"$",
"definition",
"->",
"hasSort",
"(",
"$",
"name",
")",
")",
"{",
"return",
";",
"}",
"$",
"sort",
"=",
"$",
"sorting",
"===",
"SorterInterface",
"::",
"ASC",
"?",
"$",
"name",
":",
"'-'",
".",
"$",
"name",
";",
"$",
"routeParameters",
"=",
"[",
"]",
";",
"if",
"(",
"(",
"$",
"request",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getMasterRequest",
"(",
")",
")",
"!==",
"null",
")",
"{",
"$",
"routeParameters",
"=",
"array_merge",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'_route_params'",
",",
"[",
"]",
")",
",",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"routeParameters",
"[",
"'grid'",
"]",
"[",
"'reset'",
"]",
")",
"&&",
"isset",
"(",
"$",
"routeParameters",
"[",
"'grid'",
"]",
"[",
"'sorting'",
"]",
")",
"&&",
"$",
"routeParameters",
"[",
"'grid'",
"]",
"[",
"'sorting'",
"]",
"===",
"$",
"sort",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"definition",
"->",
"hasOption",
"(",
"'persistent'",
")",
"&&",
"$",
"definition",
"->",
"getOption",
"(",
"'persistent'",
")",
")",
"{",
"$",
"filters",
"=",
"$",
"this",
"->",
"filterManager",
"->",
"get",
"(",
"$",
"definition",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"filters",
"[",
"'sorting'",
"]",
")",
"&&",
"$",
"filters",
"[",
"'sorting'",
"]",
"===",
"$",
"sort",
")",
"{",
"return",
";",
"}",
"}",
"$",
"routeParameters",
"[",
"'grid'",
"]",
"[",
"'sorting'",
"]",
"=",
"$",
"sort",
";",
"unset",
"(",
"$",
"routeParameters",
"[",
"'grid'",
"]",
"[",
"'reset'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"urlGenerator",
"->",
"generate",
"(",
"$",
"definition",
"->",
"getOption",
"(",
"'grid_route'",
")",
",",
"$",
"routeParameters",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Sort/SorterRenderer.php#L60-L94 |
ezsystems/ezcomments-ls-extension | classes/ezcomcommentmanager.php | ezcomCommentManager.addComment | public function addComment( $comment, $user, $time = null, $notification = null )
{
if ( $time === null )
{
$time = time();
}
$beforeAddingResult = $this->beforeAddingComment( $comment, $user, $notification );
if ( $beforeAddingResult !== true )
{
return $beforeAddingResult;
}
$comment->store();
eZDebugSetting::writeNotice( 'extension-ezcomments', 'Comment has been added', __METHOD__ );
$this->afterAddingComment( $comment, $notification );
return true;
} | php | public function addComment( $comment, $user, $time = null, $notification = null )
{
if ( $time === null )
{
$time = time();
}
$beforeAddingResult = $this->beforeAddingComment( $comment, $user, $notification );
if ( $beforeAddingResult !== true )
{
return $beforeAddingResult;
}
$comment->store();
eZDebugSetting::writeNotice( 'extension-ezcomments', 'Comment has been added', __METHOD__ );
$this->afterAddingComment( $comment, $notification );
return true;
} | [
"public",
"function",
"addComment",
"(",
"$",
"comment",
",",
"$",
"user",
",",
"$",
"time",
"=",
"null",
",",
"$",
"notification",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"time",
"===",
"null",
")",
"{",
"$",
"time",
"=",
"time",
"(",
")",
";",
"}",
"$",
"beforeAddingResult",
"=",
"$",
"this",
"->",
"beforeAddingComment",
"(",
"$",
"comment",
",",
"$",
"user",
",",
"$",
"notification",
")",
";",
"if",
"(",
"$",
"beforeAddingResult",
"!==",
"true",
")",
"{",
"return",
"$",
"beforeAddingResult",
";",
"}",
"$",
"comment",
"->",
"store",
"(",
")",
";",
"eZDebugSetting",
"::",
"writeNotice",
"(",
"'extension-ezcomments'",
",",
"'Comment has been added'",
",",
"__METHOD__",
")",
";",
"$",
"this",
"->",
"afterAddingComment",
"(",
"$",
"comment",
",",
"$",
"notification",
")",
";",
"return",
"true",
";",
"}"
] | Add comment into ezcomment table and do action
The adding doesn't validate the data in http
@param $comment: ezcomComment object which has not been stored
title, name, url, email, created, modified, text, notification
@param $user: user object
@param $time: comment time
@return true : if adding succeeds
false otherwise | [
"Add",
"comment",
"into",
"ezcomment",
"table",
"and",
"do",
"action",
"The",
"adding",
"doesn",
"t",
"validate",
"the",
"data",
"in",
"http",
"@param",
"$comment",
":",
"ezcomComment",
"object",
"which",
"has",
"not",
"been",
"stored",
"title",
"name",
"url",
"email",
"created",
"modified",
"text",
"notification",
"@param",
"$user",
":",
"user",
"object",
"@param",
"$time",
":",
"comment",
"time",
"@return",
"true",
":",
"if",
"adding",
"succeeds",
"false",
"otherwise"
] | train | https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcomcommentmanager.php#L92-L110 |
ezsystems/ezcomments-ls-extension | classes/ezcomcommentmanager.php | ezcomCommentManager.updateComment | public function updateComment( $comment, $user=null, $time = null , $notified = null )
{
if ( $time === null )
{
$time = time();
}
$beforeUpdating = $this->beforeUpdatingComment( $comment, $notified, $time );
if ( $beforeUpdating !== true )
{
return $beforeUpdating;
}
$comment->store();
$afterUpdating = $this->afterUpdatingComment( $comment, $notified, $time );
if ( $afterUpdating !== true )
{
return $afterUpdating;
}
return true;
} | php | public function updateComment( $comment, $user=null, $time = null , $notified = null )
{
if ( $time === null )
{
$time = time();
}
$beforeUpdating = $this->beforeUpdatingComment( $comment, $notified, $time );
if ( $beforeUpdating !== true )
{
return $beforeUpdating;
}
$comment->store();
$afterUpdating = $this->afterUpdatingComment( $comment, $notified, $time );
if ( $afterUpdating !== true )
{
return $afterUpdating;
}
return true;
} | [
"public",
"function",
"updateComment",
"(",
"$",
"comment",
",",
"$",
"user",
"=",
"null",
",",
"$",
"time",
"=",
"null",
",",
"$",
"notified",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"time",
"===",
"null",
")",
"{",
"$",
"time",
"=",
"time",
"(",
")",
";",
"}",
"$",
"beforeUpdating",
"=",
"$",
"this",
"->",
"beforeUpdatingComment",
"(",
"$",
"comment",
",",
"$",
"notified",
",",
"$",
"time",
")",
";",
"if",
"(",
"$",
"beforeUpdating",
"!==",
"true",
")",
"{",
"return",
"$",
"beforeUpdating",
";",
"}",
"$",
"comment",
"->",
"store",
"(",
")",
";",
"$",
"afterUpdating",
"=",
"$",
"this",
"->",
"afterUpdatingComment",
"(",
"$",
"comment",
",",
"$",
"notified",
",",
"$",
"time",
")",
";",
"if",
"(",
"$",
"afterUpdating",
"!==",
"true",
")",
"{",
"return",
"$",
"afterUpdating",
";",
"}",
"return",
"true",
";",
"}"
] | Update the comment
@param $comment comment to be updated
@param $notified change the notification
@param $time
@param $user user to change
@return | [
"Update",
"the",
"comment"
] | train | https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcomcommentmanager.php#L120-L140 |
ezsystems/ezcomments-ls-extension | classes/ezcomcommentmanager.php | ezcomCommentManager.instance | public static function instance()
{
if ( !isset( self::$instance ) )
{
$ini = eZINI::instance( 'ezcomments.ini' );
$className = $ini->variable( 'ManagerClasses', 'CommentManagerClass' );
self::$instance = new $className();
}
return self::$instance;
} | php | public static function instance()
{
if ( !isset( self::$instance ) )
{
$ini = eZINI::instance( 'ezcomments.ini' );
$className = $ini->variable( 'ManagerClasses', 'CommentManagerClass' );
self::$instance = new $className();
}
return self::$instance;
} | [
"public",
"static",
"function",
"instance",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"instance",
")",
")",
"{",
"$",
"ini",
"=",
"eZINI",
"::",
"instance",
"(",
"'ezcomments.ini'",
")",
";",
"$",
"className",
"=",
"$",
"ini",
"->",
"variable",
"(",
"'ManagerClasses'",
",",
"'CommentManagerClass'",
")",
";",
"self",
"::",
"$",
"instance",
"=",
"new",
"$",
"className",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"instance",
";",
"}"
] | create an instance of ezcomCommentManager
@return ezcomCommentManager | [
"create",
"an",
"instance",
"of",
"ezcomCommentManager"
] | train | https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcomcommentmanager.php#L159-L168 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/instance.php | ezcDbInstance.get | public static function get( $identifier = false )
{
if ( $identifier === false && self::$DefaultInstanceIdentifier )
{
$identifier = self::$DefaultInstanceIdentifier;
}
if ( !isset( self::$Instances[$identifier] ) )
{
// The DatabaseInstanceFetchConfig callback should return an
// ezcDbHandler object which will then be set as instance.
$ret = ezcBaseInit::fetchConfig( 'ezcInitDatabaseInstance', $identifier );
if ( $ret === null )
{
throw new ezcDbHandlerNotFoundException( $identifier );
}
else
{
self::set( $ret, $identifier );
}
}
return self::$Instances[$identifier];
} | php | public static function get( $identifier = false )
{
if ( $identifier === false && self::$DefaultInstanceIdentifier )
{
$identifier = self::$DefaultInstanceIdentifier;
}
if ( !isset( self::$Instances[$identifier] ) )
{
// The DatabaseInstanceFetchConfig callback should return an
// ezcDbHandler object which will then be set as instance.
$ret = ezcBaseInit::fetchConfig( 'ezcInitDatabaseInstance', $identifier );
if ( $ret === null )
{
throw new ezcDbHandlerNotFoundException( $identifier );
}
else
{
self::set( $ret, $identifier );
}
}
return self::$Instances[$identifier];
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"identifier",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"identifier",
"===",
"false",
"&&",
"self",
"::",
"$",
"DefaultInstanceIdentifier",
")",
"{",
"$",
"identifier",
"=",
"self",
"::",
"$",
"DefaultInstanceIdentifier",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"Instances",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"// The DatabaseInstanceFetchConfig callback should return an",
"// ezcDbHandler object which will then be set as instance.",
"$",
"ret",
"=",
"ezcBaseInit",
"::",
"fetchConfig",
"(",
"'ezcInitDatabaseInstance'",
",",
"$",
"identifier",
")",
";",
"if",
"(",
"$",
"ret",
"===",
"null",
")",
"{",
"throw",
"new",
"ezcDbHandlerNotFoundException",
"(",
"$",
"identifier",
")",
";",
"}",
"else",
"{",
"self",
"::",
"set",
"(",
"$",
"ret",
",",
"$",
"identifier",
")",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"Instances",
"[",
"$",
"identifier",
"]",
";",
"}"
] | Returns the database instance $identifier.
If $identifier is ommited the default database instance
specified by chooseDefault() is returned.
@throws ezcDbHandlerNotFoundException if the specified instance is not found.
@param string $identifier
@return ezcDbHandler | [
"Returns",
"the",
"database",
"instance",
"$identifier",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/instance.php#L85-L108 |
LeaseCloud/leasecloud-php-sdk | src/ApiResource.php | ApiResource.staticRequest | protected static function staticRequest($method, $url, $params)
{
$requestor = new ApiRequestor();
list($response, $code) = $requestor->request($method, $url, $params);
return array($response, $code);
} | php | protected static function staticRequest($method, $url, $params)
{
$requestor = new ApiRequestor();
list($response, $code) = $requestor->request($method, $url, $params);
return array($response, $code);
} | [
"protected",
"static",
"function",
"staticRequest",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"params",
")",
"{",
"$",
"requestor",
"=",
"new",
"ApiRequestor",
"(",
")",
";",
"list",
"(",
"$",
"response",
",",
"$",
"code",
")",
"=",
"$",
"requestor",
"->",
"request",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"params",
")",
";",
"return",
"array",
"(",
"$",
"response",
",",
"$",
"code",
")",
";",
"}"
] | Make the http GET or POST request
@param string $method
@param string $url
@param array|null $params
@return array | [
"Make",
"the",
"http",
"GET",
"or",
"POST",
"request"
] | train | https://github.com/LeaseCloud/leasecloud-php-sdk/blob/091b073dd4f79ba915a68c0ed151bd9bfa61e7ca/src/ApiResource.php#L68-L73 |
LeaseCloud/leasecloud-php-sdk | src/ApiResource.php | ApiResource.create | protected static function create($params = null)
{
$url = static::classUrl();
list($response) = static::staticRequest('post', $url, $params);
return $response;
} | php | protected static function create($params = null)
{
$url = static::classUrl();
list($response) = static::staticRequest('post', $url, $params);
return $response;
} | [
"protected",
"static",
"function",
"create",
"(",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"static",
"::",
"classUrl",
"(",
")",
";",
"list",
"(",
"$",
"response",
")",
"=",
"static",
"::",
"staticRequest",
"(",
"'post'",
",",
"$",
"url",
",",
"$",
"params",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Create (post) a resource via the remote API
@param array|null $params
@return mixed | [
"Create",
"(",
"post",
")",
"a",
"resource",
"via",
"the",
"remote",
"API"
] | train | https://github.com/LeaseCloud/leasecloud-php-sdk/blob/091b073dd4f79ba915a68c0ed151bd9bfa61e7ca/src/ApiResource.php#L82-L87 |
LeaseCloud/leasecloud-php-sdk | src/ApiResource.php | ApiResource.retrieve | protected static function retrieve($id = null, $params = [])
{
$url = static::classUrl();
if ($id) {
$url = $url . '/' . $id;
}
list($response) = static::staticRequest('get', $url, $params);
return $response;
} | php | protected static function retrieve($id = null, $params = [])
{
$url = static::classUrl();
if ($id) {
$url = $url . '/' . $id;
}
list($response) = static::staticRequest('get', $url, $params);
return $response;
} | [
"protected",
"static",
"function",
"retrieve",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"static",
"::",
"classUrl",
"(",
")",
";",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"url",
"=",
"$",
"url",
".",
"'/'",
".",
"$",
"id",
";",
"}",
"list",
"(",
"$",
"response",
")",
"=",
"static",
"::",
"staticRequest",
"(",
"'get'",
",",
"$",
"url",
",",
"$",
"params",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Retrieve (get) data from the remote API
@param null $id
@param array $params
@return mixed | [
"Retrieve",
"(",
"get",
")",
"data",
"from",
"the",
"remote",
"API"
] | train | https://github.com/LeaseCloud/leasecloud-php-sdk/blob/091b073dd4f79ba915a68c0ed151bd9bfa61e7ca/src/ApiResource.php#L96-L104 |
xiewulong/yii2-fileupload | oss/libs/guzzle/http/Guzzle/Http/Message/Response.php | Response.xml | public function xml()
{
try {
// Allow XML to be retrieved even if there is no response body
$xml = new \SimpleXMLElement((string) $this->body ?: '<root />');
} catch (\Exception $e) {
throw new RuntimeException('Unable to parse response body into XML: ' . $e->getMessage());
}
return $xml;
} | php | public function xml()
{
try {
// Allow XML to be retrieved even if there is no response body
$xml = new \SimpleXMLElement((string) $this->body ?: '<root />');
} catch (\Exception $e) {
throw new RuntimeException('Unable to parse response body into XML: ' . $e->getMessage());
}
return $xml;
} | [
"public",
"function",
"xml",
"(",
")",
"{",
"try",
"{",
"// Allow XML to be retrieved even if there is no response body",
"$",
"xml",
"=",
"new",
"\\",
"SimpleXMLElement",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"body",
"?",
":",
"'<root />'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Unable to parse response body into XML: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"xml",
";",
"}"
] | Parse the XML response body and return a SimpleXMLElement
@return \SimpleXMLElement
@throws RuntimeException if the response body is not in XML format | [
"Parse",
"the",
"XML",
"response",
"body",
"and",
"return",
"a",
"SimpleXMLElement"
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/Message/Response.php#L873-L883 |
simbiosis-group/yii2-helper | actions/ExportAction.php | ExportAction.run | public function run()
{
$objPHPExcel = new \PHPExcel();
$objPHPExcel->getActiveSheet()->fromArray($this->excelData, null, 'A1');
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $this->file . '"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
return true;
} | php | public function run()
{
$objPHPExcel = new \PHPExcel();
$objPHPExcel->getActiveSheet()->fromArray($this->excelData, null, 'A1');
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $this->file . '"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
return true;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"objPHPExcel",
"=",
"new",
"\\",
"PHPExcel",
"(",
")",
";",
"$",
"objPHPExcel",
"->",
"getActiveSheet",
"(",
")",
"->",
"fromArray",
"(",
"$",
"this",
"->",
"excelData",
",",
"null",
",",
"'A1'",
")",
";",
"// Redirect output to a client’s web browser (Excel5)\r",
"header",
"(",
"'Content-Type: application/vnd.ms-excel'",
")",
";",
"header",
"(",
"'Content-Disposition: attachment;filename=\"'",
".",
"$",
"this",
"->",
"file",
".",
"'\"'",
")",
";",
"header",
"(",
"'Cache-Control: max-age=0'",
")",
";",
"// If you're serving to IE 9, then the following may be needed\r",
"header",
"(",
"'Cache-Control: max-age=1'",
")",
";",
"// If you're serving to IE over SSL, then the following may be needed\r",
"header",
"(",
"'Expires: Mon, 26 Jul 1997 05:00:00 GMT'",
")",
";",
"// Date in the past\r",
"header",
"(",
"'Last-Modified: '",
".",
"gmdate",
"(",
"'D, d M Y H:i:s'",
")",
".",
"' GMT'",
")",
";",
"// always modified\r",
"header",
"(",
"'Cache-Control: cache, must-revalidate'",
")",
";",
"// HTTP/1.1\r",
"header",
"(",
"'Pragma: public'",
")",
";",
"// HTTP/1.0\r",
"$",
"objWriter",
"=",
"\\",
"PHPExcel_IOFactory",
"::",
"createWriter",
"(",
"$",
"objPHPExcel",
",",
"'Excel5'",
")",
";",
"$",
"objWriter",
"->",
"save",
"(",
"'php://output'",
")",
";",
"exit",
";",
"return",
"true",
";",
"}"
] | Runs the action
@return string result content | [
"Runs",
"the",
"action"
] | train | https://github.com/simbiosis-group/yii2-helper/blob/c85c4204dd06b16e54210e75fe6deb51869d1dd9/actions/ExportAction.php#L70-L94 |
j-d/draggy | src/Draggy/Utils/Yaml/YamlLoader.php | YamlLoader.mergeArrays | protected static function mergeArrays($target, $source)
{
foreach ($source as $node => $values) {
if (!array_key_exists($node, $target)) {
$target[$node] = $values;
} elseif (is_array($values)) {
$target[$node] = self::mergeArrays($target[$node], $values);
} else {
$target[$node] = $values;
}
}
return $target;
} | php | protected static function mergeArrays($target, $source)
{
foreach ($source as $node => $values) {
if (!array_key_exists($node, $target)) {
$target[$node] = $values;
} elseif (is_array($values)) {
$target[$node] = self::mergeArrays($target[$node], $values);
} else {
$target[$node] = $values;
}
}
return $target;
} | [
"protected",
"static",
"function",
"mergeArrays",
"(",
"$",
"target",
",",
"$",
"source",
")",
"{",
"foreach",
"(",
"$",
"source",
"as",
"$",
"node",
"=>",
"$",
"values",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"node",
",",
"$",
"target",
")",
")",
"{",
"$",
"target",
"[",
"$",
"node",
"]",
"=",
"$",
"values",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"$",
"target",
"[",
"$",
"node",
"]",
"=",
"self",
"::",
"mergeArrays",
"(",
"$",
"target",
"[",
"$",
"node",
"]",
",",
"$",
"values",
")",
";",
"}",
"else",
"{",
"$",
"target",
"[",
"$",
"node",
"]",
"=",
"$",
"values",
";",
"}",
"}",
"return",
"$",
"target",
";",
"}"
] | Overwrite / complete the target array with the values found on the source array
@param array $target
@param array $source
@return array | [
"Overwrite",
"/",
"complete",
"the",
"target",
"array",
"with",
"the",
"values",
"found",
"on",
"the",
"source",
"array"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Yaml/YamlLoader.php#L25-L38 |
j-d/draggy | src/Draggy/Utils/Yaml/YamlLoader.php | YamlLoader.mergeConfigurations | public static function mergeConfigurations($target, $source)
{
foreach (['attributes', 'entities', 'relationships', 'autocode', 'languages', 'frameworks', 'orms'] as $configurationPart) {
if (isset($source[$configurationPart])) {
$target[$configurationPart] = self::mergeArrays($target[$configurationPart], $source[$configurationPart]);
}
}
return $target;
} | php | public static function mergeConfigurations($target, $source)
{
foreach (['attributes', 'entities', 'relationships', 'autocode', 'languages', 'frameworks', 'orms'] as $configurationPart) {
if (isset($source[$configurationPart])) {
$target[$configurationPart] = self::mergeArrays($target[$configurationPart], $source[$configurationPart]);
}
}
return $target;
} | [
"public",
"static",
"function",
"mergeConfigurations",
"(",
"$",
"target",
",",
"$",
"source",
")",
"{",
"foreach",
"(",
"[",
"'attributes'",
",",
"'entities'",
",",
"'relationships'",
",",
"'autocode'",
",",
"'languages'",
",",
"'frameworks'",
",",
"'orms'",
"]",
"as",
"$",
"configurationPart",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"source",
"[",
"$",
"configurationPart",
"]",
")",
")",
"{",
"$",
"target",
"[",
"$",
"configurationPart",
"]",
"=",
"self",
"::",
"mergeArrays",
"(",
"$",
"target",
"[",
"$",
"configurationPart",
"]",
",",
"$",
"source",
"[",
"$",
"configurationPart",
"]",
")",
";",
"}",
"}",
"return",
"$",
"target",
";",
"}"
] | Complete the different configuration sections on the target array with those ones found on the source array
@param array $target
@param array $source
@return array | [
"Complete",
"the",
"different",
"configuration",
"sections",
"on",
"the",
"target",
"array",
"with",
"those",
"ones",
"found",
"on",
"the",
"source",
"array"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Yaml/YamlLoader.php#L48-L57 |
j-d/draggy | src/Draggy/Utils/Yaml/YamlLoader.php | YamlLoader.loadConfiguration | public static function loadConfiguration()
{
$defaultsFile = __DIR__ . '/../../../../app/config/defaults.yml';
$draggyFile = __DIR__ . '/../../../../app/config/draggy.yml';
$userFile = __DIR__ . '/../../../../app/config/user.yml';
$defaultsArray = Yaml::parse($defaultsFile);
$configurationArray = is_file($userFile)
? Yaml::parse($userFile)
: Yaml::parse($draggyFile);
$mergedArray = self::mergeConfigurations($defaultsArray, $configurationArray);
return $mergedArray;
} | php | public static function loadConfiguration()
{
$defaultsFile = __DIR__ . '/../../../../app/config/defaults.yml';
$draggyFile = __DIR__ . '/../../../../app/config/draggy.yml';
$userFile = __DIR__ . '/../../../../app/config/user.yml';
$defaultsArray = Yaml::parse($defaultsFile);
$configurationArray = is_file($userFile)
? Yaml::parse($userFile)
: Yaml::parse($draggyFile);
$mergedArray = self::mergeConfigurations($defaultsArray, $configurationArray);
return $mergedArray;
} | [
"public",
"static",
"function",
"loadConfiguration",
"(",
")",
"{",
"$",
"defaultsFile",
"=",
"__DIR__",
".",
"'/../../../../app/config/defaults.yml'",
";",
"$",
"draggyFile",
"=",
"__DIR__",
".",
"'/../../../../app/config/draggy.yml'",
";",
"$",
"userFile",
"=",
"__DIR__",
".",
"'/../../../../app/config/user.yml'",
";",
"$",
"defaultsArray",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"defaultsFile",
")",
";",
"$",
"configurationArray",
"=",
"is_file",
"(",
"$",
"userFile",
")",
"?",
"Yaml",
"::",
"parse",
"(",
"$",
"userFile",
")",
":",
"Yaml",
"::",
"parse",
"(",
"$",
"draggyFile",
")",
";",
"$",
"mergedArray",
"=",
"self",
"::",
"mergeConfigurations",
"(",
"$",
"defaultsArray",
",",
"$",
"configurationArray",
")",
";",
"return",
"$",
"mergedArray",
";",
"}"
] | Load the model configuration, merge it onto the default one and return the result array
@return array | [
"Load",
"the",
"model",
"configuration",
"merge",
"it",
"onto",
"the",
"default",
"one",
"and",
"return",
"the",
"result",
"array"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Yaml/YamlLoader.php#L64-L79 |
m4grio/bangkok-insurance-php | src/ClientBuilder.php | ClientBuilder.setProcess | public function setProcess(ProcessInterface $process)
{
$this->process = $process;
$this->setClient($process->getClient());
return $this;
} | php | public function setProcess(ProcessInterface $process)
{
$this->process = $process;
$this->setClient($process->getClient());
return $this;
} | [
"public",
"function",
"setProcess",
"(",
"ProcessInterface",
"$",
"process",
")",
"{",
"$",
"this",
"->",
"process",
"=",
"$",
"process",
";",
"$",
"this",
"->",
"setClient",
"(",
"$",
"process",
"->",
"getClient",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param ProcessInterface $process
@return ClientBuilder | [
"@param",
"ProcessInterface",
"$process"
] | train | https://github.com/m4grio/bangkok-insurance-php/blob/400266d043abe6b7cacb9da36064cbb169149c2a/src/ClientBuilder.php#L110-L116 |
m4grio/bangkok-insurance-php | src/ClientBuilder.php | ClientBuilder.build | public function build()
{
$soapClient = (new Factory)->getClient($this->getEndpoint(), $this->getSoapOptions());
$params['user_id'] = $this->userId;
$params['agent_code'] = $this->agentCode;
$params['agent_seq'] = $this->agentSeq;
$client = new $this->client($soapClient, $params);
if ($this->log) {
//
}
return $client;
} | php | public function build()
{
$soapClient = (new Factory)->getClient($this->getEndpoint(), $this->getSoapOptions());
$params['user_id'] = $this->userId;
$params['agent_code'] = $this->agentCode;
$params['agent_seq'] = $this->agentSeq;
$client = new $this->client($soapClient, $params);
if ($this->log) {
//
}
return $client;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"soapClient",
"=",
"(",
"new",
"Factory",
")",
"->",
"getClient",
"(",
"$",
"this",
"->",
"getEndpoint",
"(",
")",
",",
"$",
"this",
"->",
"getSoapOptions",
"(",
")",
")",
";",
"$",
"params",
"[",
"'user_id'",
"]",
"=",
"$",
"this",
"->",
"userId",
";",
"$",
"params",
"[",
"'agent_code'",
"]",
"=",
"$",
"this",
"->",
"agentCode",
";",
"$",
"params",
"[",
"'agent_seq'",
"]",
"=",
"$",
"this",
"->",
"agentSeq",
";",
"$",
"client",
"=",
"new",
"$",
"this",
"->",
"client",
"(",
"$",
"soapClient",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"this",
"->",
"log",
")",
"{",
"//",
"}",
"return",
"$",
"client",
";",
"}"
] | Build a new client's instance
@return Client | [
"Build",
"a",
"new",
"client",
"s",
"instance"
] | train | https://github.com/m4grio/bangkok-insurance-php/blob/400266d043abe6b7cacb9da36064cbb169149c2a/src/ClientBuilder.php#L147-L161 |
tigron/skeleton-file | migration/20171215_124319_filename_on_disk.php | Migration_20171215_124319_Filename_on_disk.up | public function up() {
$db = Database::get();
$db->query("
ALTER TABLE `file`
ADD `path` varchar(128) COLLATE 'utf8_unicode_ci' NOT NULL AFTER `name`;
", []);
$data = $db->get_all('SELECT * FROM file WHERE path = "" AND md5sum != ""', []);
foreach ($data as $row) {
$path = $this->get_path($row);
$db->query('UPDATE file SET path=? WHERE id=?', [ $path, $row['id'] ]);
}
} | php | public function up() {
$db = Database::get();
$db->query("
ALTER TABLE `file`
ADD `path` varchar(128) COLLATE 'utf8_unicode_ci' NOT NULL AFTER `name`;
", []);
$data = $db->get_all('SELECT * FROM file WHERE path = "" AND md5sum != ""', []);
foreach ($data as $row) {
$path = $this->get_path($row);
$db->query('UPDATE file SET path=? WHERE id=?', [ $path, $row['id'] ]);
}
} | [
"public",
"function",
"up",
"(",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"get",
"(",
")",
";",
"$",
"db",
"->",
"query",
"(",
"\"\n\t\t\tALTER TABLE `file`\n\t\t\tADD `path` varchar(128) COLLATE 'utf8_unicode_ci' NOT NULL AFTER `name`;\n\t\t\"",
",",
"[",
"]",
")",
";",
"$",
"data",
"=",
"$",
"db",
"->",
"get_all",
"(",
"'SELECT * FROM file WHERE path = \"\" AND md5sum != \"\"'",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"row",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"get_path",
"(",
"$",
"row",
")",
";",
"$",
"db",
"->",
"query",
"(",
"'UPDATE file SET path=? WHERE id=?'",
",",
"[",
"$",
"path",
",",
"$",
"row",
"[",
"'id'",
"]",
"]",
")",
";",
"}",
"}"
] | Migrate up
@access public | [
"Migrate",
"up"
] | train | https://github.com/tigron/skeleton-file/blob/97978d49f179f07c76380ddc8919b8a7d56dee61/migration/20171215_124319_filename_on_disk.php#L21-L33 |
tigron/skeleton-file | migration/20171215_124319_filename_on_disk.php | Migration_20171215_124319_Filename_on_disk.get_path | public function get_path($file) {
$parts = str_split($file['md5sum'], 2);
$subpath = $parts[0] . '/' . $parts[1] . '/' . $parts[2] . '/';
$path = $subpath . $file['id'] . '-' . $this->sanitize_filename($file['name']);
return $path;
} | php | public function get_path($file) {
$parts = str_split($file['md5sum'], 2);
$subpath = $parts[0] . '/' . $parts[1] . '/' . $parts[2] . '/';
$path = $subpath . $file['id'] . '-' . $this->sanitize_filename($file['name']);
return $path;
} | [
"public",
"function",
"get_path",
"(",
"$",
"file",
")",
"{",
"$",
"parts",
"=",
"str_split",
"(",
"$",
"file",
"[",
"'md5sum'",
"]",
",",
"2",
")",
";",
"$",
"subpath",
"=",
"$",
"parts",
"[",
"0",
"]",
".",
"'/'",
".",
"$",
"parts",
"[",
"1",
"]",
".",
"'/'",
".",
"$",
"parts",
"[",
"2",
"]",
".",
"'/'",
";",
"$",
"path",
"=",
"$",
"subpath",
".",
"$",
"file",
"[",
"'id'",
"]",
".",
"'-'",
".",
"$",
"this",
"->",
"sanitize_filename",
"(",
"$",
"file",
"[",
"'name'",
"]",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Get path
@access public
@return string $path | [
"Get",
"path"
] | train | https://github.com/tigron/skeleton-file/blob/97978d49f179f07c76380ddc8919b8a7d56dee61/migration/20171215_124319_filename_on_disk.php#L41-L48 |
tigron/skeleton-file | migration/20171215_124319_filename_on_disk.php | Migration_20171215_124319_Filename_on_disk.sanitize_filename | public function sanitize_filename($name, $max_length = 50) {
$special_chars = ['#','$','%','^','&','*','!','~','‘','"','’','\'','=','?','/','[',']','(',')','|','<','>',';','\\',',','+'];
$name = preg_replace('/^[.]*/','',$name); // remove leading dots
$name = preg_replace('/[.]*$/','',$name); // remove trailing dots
$name = str_replace($special_chars, '', $name);// remove special characters
$name = str_replace(' ','_',$name); // replace spaces with _
$name_array = explode('.', $name);
if (count($name_array) > 1) {
$extension = array_pop($name_array);
} else {
$extension = null;
}
$name = implode('.', $name_array);
if ($max_length != null) {
$name = substr($name, 0, $max_length);
}
if ($extension != null) {
$name = $name . '.' . $extension;
}
return $name;
} | php | public function sanitize_filename($name, $max_length = 50) {
$special_chars = ['#','$','%','^','&','*','!','~','‘','"','’','\'','=','?','/','[',']','(',')','|','<','>',';','\\',',','+'];
$name = preg_replace('/^[.]*/','',$name); // remove leading dots
$name = preg_replace('/[.]*$/','',$name); // remove trailing dots
$name = str_replace($special_chars, '', $name);// remove special characters
$name = str_replace(' ','_',$name); // replace spaces with _
$name_array = explode('.', $name);
if (count($name_array) > 1) {
$extension = array_pop($name_array);
} else {
$extension = null;
}
$name = implode('.', $name_array);
if ($max_length != null) {
$name = substr($name, 0, $max_length);
}
if ($extension != null) {
$name = $name . '.' . $extension;
}
return $name;
} | [
"public",
"function",
"sanitize_filename",
"(",
"$",
"name",
",",
"$",
"max_length",
"=",
"50",
")",
"{",
"$",
"special_chars",
"=",
"[",
"'#'",
",",
"'$'",
",",
"'%'",
",",
"'^'",
",",
"'&'",
",",
"'*'",
",",
"'!'",
",",
"'~'",
",",
"'‘','",
"\"",
"','",
"’",
"','\\'",
"'",
",'='",
",",
"'?'",
",",
"'/'",
",",
"'['",
",",
"']'",
",",
"'('",
",",
"')'",
",",
"'|'",
",",
"'<'",
",",
"'>'",
",",
"';'",
",",
"'\\\\",
"'",
",','",
",",
"'+'",
"]",
";",
"",
"",
"$",
"name",
"=",
"preg_replace",
"(",
"'/^[.]*/'",
",",
"''",
",",
"$",
"name",
")",
";",
"// remove leading dots",
"$",
"name",
"=",
"preg_replace",
"(",
"'/[.]*$/'",
",",
"''",
",",
"$",
"name",
")",
";",
"// remove trailing dots",
"$",
"name",
"=",
"str_replace",
"(",
"$",
"special_chars",
",",
"''",
",",
"$",
"name",
")",
";",
"// remove special characters",
"$",
"name",
"=",
"str_replace",
"(",
"' '",
",",
"'_'",
",",
"$",
"name",
")",
";",
"// replace spaces with _",
"$",
"name_array",
"=",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
";",
"if",
"(",
"count",
"(",
"$",
"name_array",
")",
">",
"1",
")",
"{",
"$",
"extension",
"=",
"array_pop",
"(",
"$",
"name_array",
")",
";",
"}",
"else",
"{",
"$",
"extension",
"=",
"null",
";",
"}",
"$",
"name",
"=",
"implode",
"(",
"'.'",
",",
"$",
"name_array",
")",
";",
"if",
"(",
"$",
"max_length",
"!=",
"null",
")",
"{",
"$",
"name",
"=",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"$",
"max_length",
")",
";",
"}",
"if",
"(",
"$",
"extension",
"!=",
"null",
")",
"{",
"$",
"name",
"=",
"$",
"name",
".",
"'.'",
".",
"$",
"extension",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Sanitize the filename (old way)
@access public
@param string $name | [
"Sanitize",
"the",
"filename",
"(",
"old",
"way",
")"
] | train | https://github.com/tigron/skeleton-file/blob/97978d49f179f07c76380ddc8919b8a7d56dee61/migration/20171215_124319_filename_on_disk.php#L56-L81 |
husccexo/php-handlersocket-core | src/HSCore/Socket.php | Socket.openIndex | public function openIndex($dbName, $tableName, $indexName = null, array $columns = [], array $fColumns = null)
{
if (empty($indexName)) {
$indexName = 'PRIMARY';
}
$params = [$dbName, $tableName, $indexName, join(',', $columns)];
if (!is_null($fColumns)) {
$params[] = join(',', $fColumns);
}
$key = join(';', $params);
return $this->socket->registerIndex(
$key,
function ($index) use ($params) {
$this->send(array_merge(['P', $index], $params));
}
);
} | php | public function openIndex($dbName, $tableName, $indexName = null, array $columns = [], array $fColumns = null)
{
if (empty($indexName)) {
$indexName = 'PRIMARY';
}
$params = [$dbName, $tableName, $indexName, join(',', $columns)];
if (!is_null($fColumns)) {
$params[] = join(',', $fColumns);
}
$key = join(';', $params);
return $this->socket->registerIndex(
$key,
function ($index) use ($params) {
$this->send(array_merge(['P', $index], $params));
}
);
} | [
"public",
"function",
"openIndex",
"(",
"$",
"dbName",
",",
"$",
"tableName",
",",
"$",
"indexName",
"=",
"null",
",",
"array",
"$",
"columns",
"=",
"[",
"]",
",",
"array",
"$",
"fColumns",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"indexName",
")",
")",
"{",
"$",
"indexName",
"=",
"'PRIMARY'",
";",
"}",
"$",
"params",
"=",
"[",
"$",
"dbName",
",",
"$",
"tableName",
",",
"$",
"indexName",
",",
"join",
"(",
"','",
",",
"$",
"columns",
")",
"]",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"fColumns",
")",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"join",
"(",
"','",
",",
"$",
"fColumns",
")",
";",
"}",
"$",
"key",
"=",
"join",
"(",
"';'",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"socket",
"->",
"registerIndex",
"(",
"$",
"key",
",",
"function",
"(",
"$",
"index",
")",
"use",
"(",
"$",
"params",
")",
"{",
"$",
"this",
"->",
"send",
"(",
"array_merge",
"(",
"[",
"'P'",
",",
"$",
"index",
"]",
",",
"$",
"params",
")",
")",
";",
"}",
")",
";",
"}"
] | Perform opening index $indexId over $indexName of table $dbName.$tableName,
preparing read $columns and filters $fColumns
@param string $dbName
@param string $tableName
@param string $indexName
@param array $columns
@param array|null $fColumns
@return int | [
"Perform",
"opening",
"index",
"$indexId",
"over",
"$indexName",
"of",
"table",
"$dbName",
".",
"$tableName",
"preparing",
"read",
"$columns",
"and",
"filters",
"$fColumns"
] | train | https://github.com/husccexo/php-handlersocket-core/blob/aaeeece9c90a89bbc861a6fe390bc0c892496bf0/src/HSCore/Socket.php#L32-L52 |
husccexo/php-handlersocket-core | src/HSCore/Socket.php | Socket.send | protected function send(array $params)
{
$this->connect();
return $this->socket->send(join(Driver::SEP, array_map([$this->socket, 'encode'], $params)).Driver::EOL);
} | php | protected function send(array $params)
{
$this->connect();
return $this->socket->send(join(Driver::SEP, array_map([$this->socket, 'encode'], $params)).Driver::EOL);
} | [
"protected",
"function",
"send",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"return",
"$",
"this",
"->",
"socket",
"->",
"send",
"(",
"join",
"(",
"Driver",
"::",
"SEP",
",",
"array_map",
"(",
"[",
"$",
"this",
"->",
"socket",
",",
"'encode'",
"]",
",",
"$",
"params",
")",
")",
".",
"Driver",
"::",
"EOL",
")",
";",
"}"
] | Send command to server
@param array $params
@return string
@throws HSException | [
"Send",
"command",
"to",
"server"
] | train | https://github.com/husccexo/php-handlersocket-core/blob/aaeeece9c90a89bbc861a6fe390bc0c892496bf0/src/HSCore/Socket.php#L86-L90 |
husccexo/php-handlersocket-core | src/HSCore/Socket.php | Socket.parseResponse | protected function parseResponse($string)
{
$exp = explode(Driver::SEP, $string);
if ($exp[0] != 0) {
throw new HSException(isset($exp[2]) ? $exp[2] : '', $exp[0]);
}
array_shift($exp); // skip error code
$numCols = intval(array_shift($exp));
$exp = array_map([$this->socket, 'decode'], $exp);
return array_chunk($exp, $numCols);
} | php | protected function parseResponse($string)
{
$exp = explode(Driver::SEP, $string);
if ($exp[0] != 0) {
throw new HSException(isset($exp[2]) ? $exp[2] : '', $exp[0]);
}
array_shift($exp); // skip error code
$numCols = intval(array_shift($exp));
$exp = array_map([$this->socket, 'decode'], $exp);
return array_chunk($exp, $numCols);
} | [
"protected",
"function",
"parseResponse",
"(",
"$",
"string",
")",
"{",
"$",
"exp",
"=",
"explode",
"(",
"Driver",
"::",
"SEP",
",",
"$",
"string",
")",
";",
"if",
"(",
"$",
"exp",
"[",
"0",
"]",
"!=",
"0",
")",
"{",
"throw",
"new",
"HSException",
"(",
"isset",
"(",
"$",
"exp",
"[",
"2",
"]",
")",
"?",
"$",
"exp",
"[",
"2",
"]",
":",
"''",
",",
"$",
"exp",
"[",
"0",
"]",
")",
";",
"}",
"array_shift",
"(",
"$",
"exp",
")",
";",
"// skip error code",
"$",
"numCols",
"=",
"intval",
"(",
"array_shift",
"(",
"$",
"exp",
")",
")",
";",
"$",
"exp",
"=",
"array_map",
"(",
"[",
"$",
"this",
"->",
"socket",
",",
"'decode'",
"]",
",",
"$",
"exp",
")",
";",
"return",
"array_chunk",
"(",
"$",
"exp",
",",
"$",
"numCols",
")",
";",
"}"
] | Parse response from server
@param $string
@return array
@throws HSException | [
"Parse",
"response",
"from",
"server"
] | train | https://github.com/husccexo/php-handlersocket-core/blob/aaeeece9c90a89bbc861a6fe390bc0c892496bf0/src/HSCore/Socket.php#L100-L114 |
husccexo/php-handlersocket-core | src/HSCore/Socket.php | Socket.connect | private function connect()
{
if (!$this->socket->isOpened()) {
$this->socket->open();
if ($this->secret) {
$this->socket->send(join(Driver::SEP, ['A', 1, Driver::encode($this->secret)]).Driver::EOL);
}
}
} | php | private function connect()
{
if (!$this->socket->isOpened()) {
$this->socket->open();
if ($this->secret) {
$this->socket->send(join(Driver::SEP, ['A', 1, Driver::encode($this->secret)]).Driver::EOL);
}
}
} | [
"private",
"function",
"connect",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"socket",
"->",
"isOpened",
"(",
")",
")",
"{",
"$",
"this",
"->",
"socket",
"->",
"open",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"secret",
")",
"{",
"$",
"this",
"->",
"socket",
"->",
"send",
"(",
"join",
"(",
"Driver",
"::",
"SEP",
",",
"[",
"'A'",
",",
"1",
",",
"Driver",
"::",
"encode",
"(",
"$",
"this",
"->",
"secret",
")",
"]",
")",
".",
"Driver",
"::",
"EOL",
")",
";",
"}",
"}",
"}"
] | Connect to Handler Socket
@throws HSException | [
"Connect",
"to",
"Handler",
"Socket"
] | train | https://github.com/husccexo/php-handlersocket-core/blob/aaeeece9c90a89bbc861a6fe390bc0c892496bf0/src/HSCore/Socket.php#L122-L131 |
blast-project/BaseEntitiesBundle | src/Controller/SortableController.php | SortableController.moveSortableItemAction | public function moveSortableItemAction(Request $request)
{
$admin = $this->container->get('sonata.admin.pool')->getInstance($request->get('admin_code'));
$class = $admin->getClass();
$id = $request->get('id');
$prev_rank = (int) $request->get('prev_rank');
$next_rank = (int) $request->get('next_rank');
$em = $this->getDoctrine()->getEntityManager();
$meta = new ClassMetadata($class);
$repo = new SortableRepository($em, $meta);
if ($prev_rank) {
$new_rank = $repo->moveObjectAfter($id, $prev_rank);
} elseif ($next_rank) {
$new_rank = $repo->moveObjectBefore($id, $next_rank);
}
return new JsonResponse(array(
'status' => $new_rank ? 'OK' : 'KO',
'new_rank' => $new_rank,
'class' => $admin->getClass(),
));
} | php | public function moveSortableItemAction(Request $request)
{
$admin = $this->container->get('sonata.admin.pool')->getInstance($request->get('admin_code'));
$class = $admin->getClass();
$id = $request->get('id');
$prev_rank = (int) $request->get('prev_rank');
$next_rank = (int) $request->get('next_rank');
$em = $this->getDoctrine()->getEntityManager();
$meta = new ClassMetadata($class);
$repo = new SortableRepository($em, $meta);
if ($prev_rank) {
$new_rank = $repo->moveObjectAfter($id, $prev_rank);
} elseif ($next_rank) {
$new_rank = $repo->moveObjectBefore($id, $next_rank);
}
return new JsonResponse(array(
'status' => $new_rank ? 'OK' : 'KO',
'new_rank' => $new_rank,
'class' => $admin->getClass(),
));
} | [
"public",
"function",
"moveSortableItemAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"admin",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sonata.admin.pool'",
")",
"->",
"getInstance",
"(",
"$",
"request",
"->",
"get",
"(",
"'admin_code'",
")",
")",
";",
"$",
"class",
"=",
"$",
"admin",
"->",
"getClass",
"(",
")",
";",
"$",
"id",
"=",
"$",
"request",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"prev_rank",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"get",
"(",
"'prev_rank'",
")",
";",
"$",
"next_rank",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"get",
"(",
"'next_rank'",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"meta",
"=",
"new",
"ClassMetadata",
"(",
"$",
"class",
")",
";",
"$",
"repo",
"=",
"new",
"SortableRepository",
"(",
"$",
"em",
",",
"$",
"meta",
")",
";",
"if",
"(",
"$",
"prev_rank",
")",
"{",
"$",
"new_rank",
"=",
"$",
"repo",
"->",
"moveObjectAfter",
"(",
"$",
"id",
",",
"$",
"prev_rank",
")",
";",
"}",
"elseif",
"(",
"$",
"next_rank",
")",
"{",
"$",
"new_rank",
"=",
"$",
"repo",
"->",
"moveObjectBefore",
"(",
"$",
"id",
",",
"$",
"next_rank",
")",
";",
"}",
"return",
"new",
"JsonResponse",
"(",
"array",
"(",
"'status'",
"=>",
"$",
"new_rank",
"?",
"'OK'",
":",
"'KO'",
",",
"'new_rank'",
"=>",
"$",
"new_rank",
",",
"'class'",
"=>",
"$",
"admin",
"->",
"getClass",
"(",
")",
",",
")",
")",
";",
"}"
] | Move a sortable item.
@param Request $request
@return JsonResponse
@throws \RuntimeException
@throws AccessDeniedException | [
"Move",
"a",
"sortable",
"item",
"."
] | train | https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Controller/SortableController.php#L34-L57 |
gn36/phpbb-oo-posting-api | src/Gn36/OoPostingApi/topic.php | topic.submit | function submit($submit_posts = true)
{
global $config, $db, $auth, $user, $phpbb_container;
if (! $this->topic_id && count($this->posts) == 0)
{
trigger_error('cannot create a topic without posts', E_USER_ERROR);
}
if (! $this->topic_id)
{
// new post, set some default values if not set yet
if (! $this->topic_poster)
$this->topic_poster = $user->data['user_id'];
if (! $this->topic_time)
$this->topic_time = time();
$this->posts[0]->post_subject = $this->topic_title;
}
if ($this->forum_id == 0)
{
// no forum id known, can only insert as global announcement
$this->topic_type = POST_GLOBAL;
}
$this->topic_title = truncate_string($this->topic_title);
$sql_data = array(
'icon_id' => $this->icon_id,
'topic_attachment' => $this->topic_attachment ? 1 : 0,
// 'topic_visibility' => $this->topic_visibility, // This one will be set later
'topic_reported' => $this->topic_reported ? 1 : 0,
// 'topic_views' => $this->topic_views,
'topic_posts_approved' => $this->topic_posts_approved,
'topic_posts_unapproved' => $this->topic_posts_unapproved,
'topic_posts_softdeleted' => $this->topic_posts_softdeleted,
'topic_delete_time' => $this->topic_delete_time,
'topic_delete_reason' => $this->topic_delete_reason,
'topic_delete_user' => $this->topic_delete_user,
'topic_status' => $this->topic_status,
'topic_moved_id' => $this->topic_moved_id,
'topic_type' => $this->topic_type,
'topic_time_limit' => $this->topic_time_limit,
'topic_title' => $this->topic_title,
'topic_time' => $this->topic_time,
'topic_poster' => $this->topic_poster,
'topic_first_post_id' => $this->topic_first_post_id,
'topic_first_poster_name' => $this->topic_first_poster_name,
'topic_first_poster_colour' => $this->topic_first_poster_colour,
'topic_last_post_id' => $this->topic_last_post_id,
'topic_last_poster_id' => $this->topic_last_poster_id,
'topic_last_poster_name' => $this->topic_last_poster_name,
'topic_last_poster_colour' => $this->topic_last_poster_colour,
'topic_last_post_subject' => $this->topic_last_post_subject,
'topic_last_post_time' => $this->topic_last_post_time,
'topic_last_view_time' => $this->topic_last_view_time,
'topic_bumped' => $this->topic_bumped ? 1 : 0,
'topic_bumper' => $this->topic_bumper,
'poll_title' => $this->poll_title,
'poll_start' => $this->poll_start,
'poll_length' => $this->poll_length,
'poll_max_options' => $this->poll_max_options,
// 'poll_last_vote' => $this->poll_last_vote,
'poll_vote_change' => $this->poll_vote_change ? 1 : 0
);
$sync = new syncer();
if ($this->topic_id)
{
// edit
$sql = "SELECT *
FROM " . TOPICS_TABLE . "
WHERE topic_id=" . intval($this->topic_id);
$result = $db->sql_query($sql);
$topic_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (! $topic_data)
{
trigger_error("topic_id={$this->topic_id}, but that topic does not exist", E_USER_ERROR);
}
$db->sql_transaction('begin');
$sql = "UPDATE " . TOPICS_TABLE . " SET " . $db->sql_build_array('UPDATE', $sql_data) . " WHERE topic_id=" . $this->topic_id;
$db->sql_query($sql);
// move to another forum -> also move posts and update statistics
if ($this->forum_id != $topic_data['forum_id'])
{
$sql = "UPDATE " . POSTS_TABLE . " SET forum_id=" . $this->forum_id . " WHERE topic_id=" . $this->topic_id;
$db->sql_query($sql);
// old forum
if ($topic_data['forum_id'] != 0)
{
if ($topic_data['topic_visibility'] == ITEM_APPROVED)
{
$sync->add('forum', $topic_data['forum_id'], 'forum_topics_approved', - 1);
}
elseif ($topic_data['topic_visibility'] == ITEM_UNAPPROVED || $topic_data['topic_visibility'] == ITEM_REAPPROVE)
{
$sync->add('forum', $topic_data['forum_id'], 'forum_topics_unapproved', - 1);
}
elseif ($topic_data['topic_visibility'] == ITEM_DELETED)
{
$sync->add('forum', $topic_data['forum_id'], 'forum_topics_softdeleted', - 1);
}
$sync->add('forum', $topic_data['forum_id'], 'forum_posts_approved', - $topic_data['topic_posts_approved']);
$sync->add('forum', $topic_data['forum_id'], 'forum_posts_unapproved', - $topic_data['topic_posts_unapproved']);
$sync->add('forum', $topic_data['forum_id'], 'forum_posts_softdeleted', - $topic_data['topic_posts_softdeleted']);
$sync->forum_last_post($topic_data['forum_id']);
}
// new forum
if ($this->forum_id != 0)
{
if ($this->topic_visibility == ITEM_APPROVED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_approved', 1);
}
elseif ($this->topic_visibility == ITEM_UNAPPROVED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_unapproved', 1);
}
elseif ($this->topic_visibility == ITEM_DELETED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_deleted', 1);
}
$sync->add('forum', $this->forum_id, 'forum_posts_approved', $this->topic_posts_approved);
$sync->add('forum', $this->forum_id, 'forum_posts_unapproved', $this->topic_posts_unapproved);
$sync->add('forum', $this->forum_id, 'forum_posts_softdeleted', $this->topic_posts_softdeleted);
$sync->forum_last_post($this->forum_id);
}
}
// TODO
// Sync numbers:
$phpbb_content_visibility = $phpbb_container->get('content.visibility');
$phpbb_content_visibility->set_topic_visibility($this->topic_visibility, $this->topic_id, $this->forum_id, $this->topic_delete_user, $this->topic_delete_time, $this->topic_delete_reason);
// //same with total topics+posts
// if($topic_data['topic_visibility'] == ITEM_APPROVED)
// {
// set_config('num_topics', $config['num_topics'] - 1, true);
// set_config('num_posts', $config['num_posts'] - (1 + $this->topic_posts_approved), true);
// }
// elseif($this->topic_visibility == ITEM_APPROVED)
// {
// set_config('num_topics', $config['num_topics'] + 1, true);
// set_config('num_posts', $config['num_posts'] + (1 + $this->topic_posts_approved), true);
// }
// }
$db->sql_transaction('commit');
}
else
{
// new topic
$sql_data['forum_id'] = $this->forum_id;
$sql_data['topic_first_post_id'] = 0;
$sql_data['topic_last_post_id'] = 0;
$sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data);
$db->sql_query($sql);
$this->topic_id = $db->sql_nextid();
if ($this->forum_id != 0)
{
if ($this->topic_visibility == ITEM_APPROVED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_approved', 1);
}
elseif ($this->topic_visibility == ITEM_UNAPPROVED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_unapproved', 1);
}
elseif ($this->topic_visibility == ITEM_DELETED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_deleted', 1);
}
$sync->add('forum', $this->forum_id, 'forum_posts_approved', $this->topic_posts_approved);
$sync->add('forum', $this->forum_id, 'forum_posts_unapproved', $this->topic_posts_unapproved);
$sync->add('forum', $this->forum_id, 'forum_posts_softdeleted', $this->topic_posts_softdeleted);
$sync->forum_last_post($this->forum_id);
}
$phpbb_content_visibility = $phpbb_container->get('content.visibility');
$phpbb_content_visibility->set_topic_visibility($this->topic_visibility, $this->topic_id, $this->forum_id, $this->topic_delete_user, $this->topic_delete_time, $this->topic_delete_reason);
// total topics
if ($this->topic_visibility == ITEM_APPROVED)
{
set_config('num_topics', $config['num_topics'] + 1, true);
}
$sync->new_topic_flag = true;
}
// insert or update poll
if (isset($this->poll_options) && ! empty($this->poll_options))
{
$cur_poll_options = array();
if ($this->poll_start && isset($topic_data))
{
$sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . '
WHERE topic_id = ' . $this->topic_id . '
ORDER BY poll_option_id';
$result = $db->sql_query($sql);
$cur_poll_options = array();
while ($row = $db->sql_fetchrow($result))
{
$cur_poll_options[] = $row;
}
$db->sql_freeresult($result);
}
$sql_insert_ary = array();
for ($i = 0, $size = sizeof($this->poll_options); $i < $size; $i ++)
{
if (trim($this->poll_options[$i]))
{
if (empty($cur_poll_options[$i]))
{
$sql_insert_ary[] = array(
'poll_option_id' => (int) $i,
'topic_id' => (int) $this->topic_id,
'poll_option_text' => (string) $this->poll_options[$i]
);
}
else
if ($this->poll_options[$i] != $cur_poll_options[$i])
{
$sql = "UPDATE " . POLL_OPTIONS_TABLE . "
SET poll_option_text = '" . $db->sql_escape($this->poll_options[$i]) . "'
WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . "
AND topic_id = " . $this->topic_id;
$db->sql_query($sql);
}
}
}
$db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary);
if (sizeof($this->poll_options) < sizeof($cur_poll_options))
{
$sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . '
WHERE poll_option_id >= ' . sizeof($this->poll_options) . '
AND topic_id = ' . $this->topic_id;
$db->sql_query($sql);
}
}
// delete poll if we had one and poll_start is 0 now
if (isset($topic_data) && $topic_data['poll_start'] && $this->poll_start == 0)
{
$sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . '
WHERE topic_id = ' . $this->topic_id;
$db->sql_query($sql);
$sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
WHERE topic_id = ' . $this->topic_id;
$db->sql_query($sql);
}
// End poll
if ($submit_posts && count($this->posts))
{
// find and sync first post
if ($sync->new_topic_flag)
{
// test if var was not set in post
$first_post = $this->posts[0];
if ($first_post->post_subject == '')
{
$first_post->post_subject = $this->topic_title;
}
if (! $first_post->poster_id)
{
$first_post->poster_id = $this->topic_poster;
}
if ($this->topic_visibility != ITEM_APPROVED)
{
$first_post->post_visibility = ITEM_UNAPPROVED;
}
}
elseif ($topic_data && $this->topic_first_post_id != 0)
{
foreach ($this->posts as $post)
{
if ($post->post_id == $this->topic_first_post_id)
{
// test if var has been changed in topic. this is like the
// else($submit_posts) below, but the user might have changed the
// post object but not the topic, so we can't just overwrite them
$first_post = $post;
if ($this->topic_title != $topic_data['topic_title'])
{
$first_post->post_subject = $this->topic_title;
}
if ($this->topic_time != $topic_data['topic_time'])
{
$first_post->post_time = $this->topic_time;
}
if ($this->topic_poster != $topic_data['topic_poster'])
{
$first_post->poster_id = $this->topic_poster;
$first_post->post_username = ($this->topic_poster == ANONYMOUS) ? $this->topic_first_poster_name : '';
}
if ($this->topic_approved != $topic_data['topic_approved'])
{
$first_post->post_approved = $this->topic_approved;
}
break;
}
}
}
// TODO sort by post_time in case user messed with it
foreach ($this->posts as $post)
{
$post->_topic = $this;
$post->topic_id = $this->topic_id;
$post->forum_id = $this->forum_id;
// if(!$post->poster_id) $post->poster_id = $this->topic_poster;
$post->submit_without_sync($sync);
}
}
else
{
// sync first post if user edited topic only
$sync->set('post', $this->topic_first_post_id, array(
'post_subject' => $this->topic_title,
'post_time' => $this->topic_time,
'poster_id' => $this->topic_poster,
'post_username' => ($this->topic_poster == ANONYMOUS) ? $this->topic_first_poster_name : '',
'post_visibility' => $this->topic_visibility,
'post_reported' => $this->topic_reported
));
}
$sync->execute();
// refresh $this->topic_foo variables...
$this->refresh_statvars();
} | php | function submit($submit_posts = true)
{
global $config, $db, $auth, $user, $phpbb_container;
if (! $this->topic_id && count($this->posts) == 0)
{
trigger_error('cannot create a topic without posts', E_USER_ERROR);
}
if (! $this->topic_id)
{
// new post, set some default values if not set yet
if (! $this->topic_poster)
$this->topic_poster = $user->data['user_id'];
if (! $this->topic_time)
$this->topic_time = time();
$this->posts[0]->post_subject = $this->topic_title;
}
if ($this->forum_id == 0)
{
// no forum id known, can only insert as global announcement
$this->topic_type = POST_GLOBAL;
}
$this->topic_title = truncate_string($this->topic_title);
$sql_data = array(
'icon_id' => $this->icon_id,
'topic_attachment' => $this->topic_attachment ? 1 : 0,
// 'topic_visibility' => $this->topic_visibility, // This one will be set later
'topic_reported' => $this->topic_reported ? 1 : 0,
// 'topic_views' => $this->topic_views,
'topic_posts_approved' => $this->topic_posts_approved,
'topic_posts_unapproved' => $this->topic_posts_unapproved,
'topic_posts_softdeleted' => $this->topic_posts_softdeleted,
'topic_delete_time' => $this->topic_delete_time,
'topic_delete_reason' => $this->topic_delete_reason,
'topic_delete_user' => $this->topic_delete_user,
'topic_status' => $this->topic_status,
'topic_moved_id' => $this->topic_moved_id,
'topic_type' => $this->topic_type,
'topic_time_limit' => $this->topic_time_limit,
'topic_title' => $this->topic_title,
'topic_time' => $this->topic_time,
'topic_poster' => $this->topic_poster,
'topic_first_post_id' => $this->topic_first_post_id,
'topic_first_poster_name' => $this->topic_first_poster_name,
'topic_first_poster_colour' => $this->topic_first_poster_colour,
'topic_last_post_id' => $this->topic_last_post_id,
'topic_last_poster_id' => $this->topic_last_poster_id,
'topic_last_poster_name' => $this->topic_last_poster_name,
'topic_last_poster_colour' => $this->topic_last_poster_colour,
'topic_last_post_subject' => $this->topic_last_post_subject,
'topic_last_post_time' => $this->topic_last_post_time,
'topic_last_view_time' => $this->topic_last_view_time,
'topic_bumped' => $this->topic_bumped ? 1 : 0,
'topic_bumper' => $this->topic_bumper,
'poll_title' => $this->poll_title,
'poll_start' => $this->poll_start,
'poll_length' => $this->poll_length,
'poll_max_options' => $this->poll_max_options,
// 'poll_last_vote' => $this->poll_last_vote,
'poll_vote_change' => $this->poll_vote_change ? 1 : 0
);
$sync = new syncer();
if ($this->topic_id)
{
// edit
$sql = "SELECT *
FROM " . TOPICS_TABLE . "
WHERE topic_id=" . intval($this->topic_id);
$result = $db->sql_query($sql);
$topic_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (! $topic_data)
{
trigger_error("topic_id={$this->topic_id}, but that topic does not exist", E_USER_ERROR);
}
$db->sql_transaction('begin');
$sql = "UPDATE " . TOPICS_TABLE . " SET " . $db->sql_build_array('UPDATE', $sql_data) . " WHERE topic_id=" . $this->topic_id;
$db->sql_query($sql);
// move to another forum -> also move posts and update statistics
if ($this->forum_id != $topic_data['forum_id'])
{
$sql = "UPDATE " . POSTS_TABLE . " SET forum_id=" . $this->forum_id . " WHERE topic_id=" . $this->topic_id;
$db->sql_query($sql);
// old forum
if ($topic_data['forum_id'] != 0)
{
if ($topic_data['topic_visibility'] == ITEM_APPROVED)
{
$sync->add('forum', $topic_data['forum_id'], 'forum_topics_approved', - 1);
}
elseif ($topic_data['topic_visibility'] == ITEM_UNAPPROVED || $topic_data['topic_visibility'] == ITEM_REAPPROVE)
{
$sync->add('forum', $topic_data['forum_id'], 'forum_topics_unapproved', - 1);
}
elseif ($topic_data['topic_visibility'] == ITEM_DELETED)
{
$sync->add('forum', $topic_data['forum_id'], 'forum_topics_softdeleted', - 1);
}
$sync->add('forum', $topic_data['forum_id'], 'forum_posts_approved', - $topic_data['topic_posts_approved']);
$sync->add('forum', $topic_data['forum_id'], 'forum_posts_unapproved', - $topic_data['topic_posts_unapproved']);
$sync->add('forum', $topic_data['forum_id'], 'forum_posts_softdeleted', - $topic_data['topic_posts_softdeleted']);
$sync->forum_last_post($topic_data['forum_id']);
}
// new forum
if ($this->forum_id != 0)
{
if ($this->topic_visibility == ITEM_APPROVED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_approved', 1);
}
elseif ($this->topic_visibility == ITEM_UNAPPROVED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_unapproved', 1);
}
elseif ($this->topic_visibility == ITEM_DELETED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_deleted', 1);
}
$sync->add('forum', $this->forum_id, 'forum_posts_approved', $this->topic_posts_approved);
$sync->add('forum', $this->forum_id, 'forum_posts_unapproved', $this->topic_posts_unapproved);
$sync->add('forum', $this->forum_id, 'forum_posts_softdeleted', $this->topic_posts_softdeleted);
$sync->forum_last_post($this->forum_id);
}
}
// TODO
// Sync numbers:
$phpbb_content_visibility = $phpbb_container->get('content.visibility');
$phpbb_content_visibility->set_topic_visibility($this->topic_visibility, $this->topic_id, $this->forum_id, $this->topic_delete_user, $this->topic_delete_time, $this->topic_delete_reason);
// //same with total topics+posts
// if($topic_data['topic_visibility'] == ITEM_APPROVED)
// {
// set_config('num_topics', $config['num_topics'] - 1, true);
// set_config('num_posts', $config['num_posts'] - (1 + $this->topic_posts_approved), true);
// }
// elseif($this->topic_visibility == ITEM_APPROVED)
// {
// set_config('num_topics', $config['num_topics'] + 1, true);
// set_config('num_posts', $config['num_posts'] + (1 + $this->topic_posts_approved), true);
// }
// }
$db->sql_transaction('commit');
}
else
{
// new topic
$sql_data['forum_id'] = $this->forum_id;
$sql_data['topic_first_post_id'] = 0;
$sql_data['topic_last_post_id'] = 0;
$sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data);
$db->sql_query($sql);
$this->topic_id = $db->sql_nextid();
if ($this->forum_id != 0)
{
if ($this->topic_visibility == ITEM_APPROVED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_approved', 1);
}
elseif ($this->topic_visibility == ITEM_UNAPPROVED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_unapproved', 1);
}
elseif ($this->topic_visibility == ITEM_DELETED)
{
$sync->add('forum', $this->forum_id, 'forum_topics_deleted', 1);
}
$sync->add('forum', $this->forum_id, 'forum_posts_approved', $this->topic_posts_approved);
$sync->add('forum', $this->forum_id, 'forum_posts_unapproved', $this->topic_posts_unapproved);
$sync->add('forum', $this->forum_id, 'forum_posts_softdeleted', $this->topic_posts_softdeleted);
$sync->forum_last_post($this->forum_id);
}
$phpbb_content_visibility = $phpbb_container->get('content.visibility');
$phpbb_content_visibility->set_topic_visibility($this->topic_visibility, $this->topic_id, $this->forum_id, $this->topic_delete_user, $this->topic_delete_time, $this->topic_delete_reason);
// total topics
if ($this->topic_visibility == ITEM_APPROVED)
{
set_config('num_topics', $config['num_topics'] + 1, true);
}
$sync->new_topic_flag = true;
}
// insert or update poll
if (isset($this->poll_options) && ! empty($this->poll_options))
{
$cur_poll_options = array();
if ($this->poll_start && isset($topic_data))
{
$sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . '
WHERE topic_id = ' . $this->topic_id . '
ORDER BY poll_option_id';
$result = $db->sql_query($sql);
$cur_poll_options = array();
while ($row = $db->sql_fetchrow($result))
{
$cur_poll_options[] = $row;
}
$db->sql_freeresult($result);
}
$sql_insert_ary = array();
for ($i = 0, $size = sizeof($this->poll_options); $i < $size; $i ++)
{
if (trim($this->poll_options[$i]))
{
if (empty($cur_poll_options[$i]))
{
$sql_insert_ary[] = array(
'poll_option_id' => (int) $i,
'topic_id' => (int) $this->topic_id,
'poll_option_text' => (string) $this->poll_options[$i]
);
}
else
if ($this->poll_options[$i] != $cur_poll_options[$i])
{
$sql = "UPDATE " . POLL_OPTIONS_TABLE . "
SET poll_option_text = '" . $db->sql_escape($this->poll_options[$i]) . "'
WHERE poll_option_id = " . $cur_poll_options[$i]['poll_option_id'] . "
AND topic_id = " . $this->topic_id;
$db->sql_query($sql);
}
}
}
$db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary);
if (sizeof($this->poll_options) < sizeof($cur_poll_options))
{
$sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . '
WHERE poll_option_id >= ' . sizeof($this->poll_options) . '
AND topic_id = ' . $this->topic_id;
$db->sql_query($sql);
}
}
// delete poll if we had one and poll_start is 0 now
if (isset($topic_data) && $topic_data['poll_start'] && $this->poll_start == 0)
{
$sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . '
WHERE topic_id = ' . $this->topic_id;
$db->sql_query($sql);
$sql = 'DELETE FROM ' . POLL_VOTES_TABLE . '
WHERE topic_id = ' . $this->topic_id;
$db->sql_query($sql);
}
// End poll
if ($submit_posts && count($this->posts))
{
// find and sync first post
if ($sync->new_topic_flag)
{
// test if var was not set in post
$first_post = $this->posts[0];
if ($first_post->post_subject == '')
{
$first_post->post_subject = $this->topic_title;
}
if (! $first_post->poster_id)
{
$first_post->poster_id = $this->topic_poster;
}
if ($this->topic_visibility != ITEM_APPROVED)
{
$first_post->post_visibility = ITEM_UNAPPROVED;
}
}
elseif ($topic_data && $this->topic_first_post_id != 0)
{
foreach ($this->posts as $post)
{
if ($post->post_id == $this->topic_first_post_id)
{
// test if var has been changed in topic. this is like the
// else($submit_posts) below, but the user might have changed the
// post object but not the topic, so we can't just overwrite them
$first_post = $post;
if ($this->topic_title != $topic_data['topic_title'])
{
$first_post->post_subject = $this->topic_title;
}
if ($this->topic_time != $topic_data['topic_time'])
{
$first_post->post_time = $this->topic_time;
}
if ($this->topic_poster != $topic_data['topic_poster'])
{
$first_post->poster_id = $this->topic_poster;
$first_post->post_username = ($this->topic_poster == ANONYMOUS) ? $this->topic_first_poster_name : '';
}
if ($this->topic_approved != $topic_data['topic_approved'])
{
$first_post->post_approved = $this->topic_approved;
}
break;
}
}
}
// TODO sort by post_time in case user messed with it
foreach ($this->posts as $post)
{
$post->_topic = $this;
$post->topic_id = $this->topic_id;
$post->forum_id = $this->forum_id;
// if(!$post->poster_id) $post->poster_id = $this->topic_poster;
$post->submit_without_sync($sync);
}
}
else
{
// sync first post if user edited topic only
$sync->set('post', $this->topic_first_post_id, array(
'post_subject' => $this->topic_title,
'post_time' => $this->topic_time,
'poster_id' => $this->topic_poster,
'post_username' => ($this->topic_poster == ANONYMOUS) ? $this->topic_first_poster_name : '',
'post_visibility' => $this->topic_visibility,
'post_reported' => $this->topic_reported
));
}
$sync->execute();
// refresh $this->topic_foo variables...
$this->refresh_statvars();
} | [
"function",
"submit",
"(",
"$",
"submit_posts",
"=",
"true",
")",
"{",
"global",
"$",
"config",
",",
"$",
"db",
",",
"$",
"auth",
",",
"$",
"user",
",",
"$",
"phpbb_container",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"topic_id",
"&&",
"count",
"(",
"$",
"this",
"->",
"posts",
")",
"==",
"0",
")",
"{",
"trigger_error",
"(",
"'cannot create a topic without posts'",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"topic_id",
")",
"{",
"// new post, set some default values if not set yet",
"if",
"(",
"!",
"$",
"this",
"->",
"topic_poster",
")",
"$",
"this",
"->",
"topic_poster",
"=",
"$",
"user",
"->",
"data",
"[",
"'user_id'",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"topic_time",
")",
"$",
"this",
"->",
"topic_time",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"posts",
"[",
"0",
"]",
"->",
"post_subject",
"=",
"$",
"this",
"->",
"topic_title",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"forum_id",
"==",
"0",
")",
"{",
"// no forum id known, can only insert as global announcement",
"$",
"this",
"->",
"topic_type",
"=",
"POST_GLOBAL",
";",
"}",
"$",
"this",
"->",
"topic_title",
"=",
"truncate_string",
"(",
"$",
"this",
"->",
"topic_title",
")",
";",
"$",
"sql_data",
"=",
"array",
"(",
"'icon_id'",
"=>",
"$",
"this",
"->",
"icon_id",
",",
"'topic_attachment'",
"=>",
"$",
"this",
"->",
"topic_attachment",
"?",
"1",
":",
"0",
",",
"// 'topic_visibility' => $this->topic_visibility, // This one will be set later",
"'topic_reported'",
"=>",
"$",
"this",
"->",
"topic_reported",
"?",
"1",
":",
"0",
",",
"// 'topic_views' => $this->topic_views,",
"'topic_posts_approved'",
"=>",
"$",
"this",
"->",
"topic_posts_approved",
",",
"'topic_posts_unapproved'",
"=>",
"$",
"this",
"->",
"topic_posts_unapproved",
",",
"'topic_posts_softdeleted'",
"=>",
"$",
"this",
"->",
"topic_posts_softdeleted",
",",
"'topic_delete_time'",
"=>",
"$",
"this",
"->",
"topic_delete_time",
",",
"'topic_delete_reason'",
"=>",
"$",
"this",
"->",
"topic_delete_reason",
",",
"'topic_delete_user'",
"=>",
"$",
"this",
"->",
"topic_delete_user",
",",
"'topic_status'",
"=>",
"$",
"this",
"->",
"topic_status",
",",
"'topic_moved_id'",
"=>",
"$",
"this",
"->",
"topic_moved_id",
",",
"'topic_type'",
"=>",
"$",
"this",
"->",
"topic_type",
",",
"'topic_time_limit'",
"=>",
"$",
"this",
"->",
"topic_time_limit",
",",
"'topic_title'",
"=>",
"$",
"this",
"->",
"topic_title",
",",
"'topic_time'",
"=>",
"$",
"this",
"->",
"topic_time",
",",
"'topic_poster'",
"=>",
"$",
"this",
"->",
"topic_poster",
",",
"'topic_first_post_id'",
"=>",
"$",
"this",
"->",
"topic_first_post_id",
",",
"'topic_first_poster_name'",
"=>",
"$",
"this",
"->",
"topic_first_poster_name",
",",
"'topic_first_poster_colour'",
"=>",
"$",
"this",
"->",
"topic_first_poster_colour",
",",
"'topic_last_post_id'",
"=>",
"$",
"this",
"->",
"topic_last_post_id",
",",
"'topic_last_poster_id'",
"=>",
"$",
"this",
"->",
"topic_last_poster_id",
",",
"'topic_last_poster_name'",
"=>",
"$",
"this",
"->",
"topic_last_poster_name",
",",
"'topic_last_poster_colour'",
"=>",
"$",
"this",
"->",
"topic_last_poster_colour",
",",
"'topic_last_post_subject'",
"=>",
"$",
"this",
"->",
"topic_last_post_subject",
",",
"'topic_last_post_time'",
"=>",
"$",
"this",
"->",
"topic_last_post_time",
",",
"'topic_last_view_time'",
"=>",
"$",
"this",
"->",
"topic_last_view_time",
",",
"'topic_bumped'",
"=>",
"$",
"this",
"->",
"topic_bumped",
"?",
"1",
":",
"0",
",",
"'topic_bumper'",
"=>",
"$",
"this",
"->",
"topic_bumper",
",",
"'poll_title'",
"=>",
"$",
"this",
"->",
"poll_title",
",",
"'poll_start'",
"=>",
"$",
"this",
"->",
"poll_start",
",",
"'poll_length'",
"=>",
"$",
"this",
"->",
"poll_length",
",",
"'poll_max_options'",
"=>",
"$",
"this",
"->",
"poll_max_options",
",",
"// 'poll_last_vote' => $this->poll_last_vote,",
"'poll_vote_change'",
"=>",
"$",
"this",
"->",
"poll_vote_change",
"?",
"1",
":",
"0",
")",
";",
"$",
"sync",
"=",
"new",
"syncer",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"topic_id",
")",
"{",
"// edit",
"$",
"sql",
"=",
"\"SELECT *\n\t\t\t\t\tFROM \"",
".",
"TOPICS_TABLE",
".",
"\"\n\t\t\t\t\tWHERE topic_id=\"",
".",
"intval",
"(",
"$",
"this",
"->",
"topic_id",
")",
";",
"$",
"result",
"=",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"topic_data",
"=",
"$",
"db",
"->",
"sql_fetchrow",
"(",
"$",
"result",
")",
";",
"$",
"db",
"->",
"sql_freeresult",
"(",
"$",
"result",
")",
";",
"if",
"(",
"!",
"$",
"topic_data",
")",
"{",
"trigger_error",
"(",
"\"topic_id={$this->topic_id}, but that topic does not exist\"",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"db",
"->",
"sql_transaction",
"(",
"'begin'",
")",
";",
"$",
"sql",
"=",
"\"UPDATE \"",
".",
"TOPICS_TABLE",
".",
"\" SET \"",
".",
"$",
"db",
"->",
"sql_build_array",
"(",
"'UPDATE'",
",",
"$",
"sql_data",
")",
".",
"\" WHERE topic_id=\"",
".",
"$",
"this",
"->",
"topic_id",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"// move to another forum -> also move posts and update statistics",
"if",
"(",
"$",
"this",
"->",
"forum_id",
"!=",
"$",
"topic_data",
"[",
"'forum_id'",
"]",
")",
"{",
"$",
"sql",
"=",
"\"UPDATE \"",
".",
"POSTS_TABLE",
".",
"\" SET forum_id=\"",
".",
"$",
"this",
"->",
"forum_id",
".",
"\" WHERE topic_id=\"",
".",
"$",
"this",
"->",
"topic_id",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"// old forum",
"if",
"(",
"$",
"topic_data",
"[",
"'forum_id'",
"]",
"!=",
"0",
")",
"{",
"if",
"(",
"$",
"topic_data",
"[",
"'topic_visibility'",
"]",
"==",
"ITEM_APPROVED",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"topic_data",
"[",
"'forum_id'",
"]",
",",
"'forum_topics_approved'",
",",
"-",
"1",
")",
";",
"}",
"elseif",
"(",
"$",
"topic_data",
"[",
"'topic_visibility'",
"]",
"==",
"ITEM_UNAPPROVED",
"||",
"$",
"topic_data",
"[",
"'topic_visibility'",
"]",
"==",
"ITEM_REAPPROVE",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"topic_data",
"[",
"'forum_id'",
"]",
",",
"'forum_topics_unapproved'",
",",
"-",
"1",
")",
";",
"}",
"elseif",
"(",
"$",
"topic_data",
"[",
"'topic_visibility'",
"]",
"==",
"ITEM_DELETED",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"topic_data",
"[",
"'forum_id'",
"]",
",",
"'forum_topics_softdeleted'",
",",
"-",
"1",
")",
";",
"}",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"topic_data",
"[",
"'forum_id'",
"]",
",",
"'forum_posts_approved'",
",",
"-",
"$",
"topic_data",
"[",
"'topic_posts_approved'",
"]",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"topic_data",
"[",
"'forum_id'",
"]",
",",
"'forum_posts_unapproved'",
",",
"-",
"$",
"topic_data",
"[",
"'topic_posts_unapproved'",
"]",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"topic_data",
"[",
"'forum_id'",
"]",
",",
"'forum_posts_softdeleted'",
",",
"-",
"$",
"topic_data",
"[",
"'topic_posts_softdeleted'",
"]",
")",
";",
"$",
"sync",
"->",
"forum_last_post",
"(",
"$",
"topic_data",
"[",
"'forum_id'",
"]",
")",
";",
"}",
"// new forum",
"if",
"(",
"$",
"this",
"->",
"forum_id",
"!=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"topic_visibility",
"==",
"ITEM_APPROVED",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_topics_approved'",
",",
"1",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"topic_visibility",
"==",
"ITEM_UNAPPROVED",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_topics_unapproved'",
",",
"1",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"topic_visibility",
"==",
"ITEM_DELETED",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_topics_deleted'",
",",
"1",
")",
";",
"}",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_posts_approved'",
",",
"$",
"this",
"->",
"topic_posts_approved",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_posts_unapproved'",
",",
"$",
"this",
"->",
"topic_posts_unapproved",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_posts_softdeleted'",
",",
"$",
"this",
"->",
"topic_posts_softdeleted",
")",
";",
"$",
"sync",
"->",
"forum_last_post",
"(",
"$",
"this",
"->",
"forum_id",
")",
";",
"}",
"}",
"// TODO",
"// Sync numbers:",
"$",
"phpbb_content_visibility",
"=",
"$",
"phpbb_container",
"->",
"get",
"(",
"'content.visibility'",
")",
";",
"$",
"phpbb_content_visibility",
"->",
"set_topic_visibility",
"(",
"$",
"this",
"->",
"topic_visibility",
",",
"$",
"this",
"->",
"topic_id",
",",
"$",
"this",
"->",
"forum_id",
",",
"$",
"this",
"->",
"topic_delete_user",
",",
"$",
"this",
"->",
"topic_delete_time",
",",
"$",
"this",
"->",
"topic_delete_reason",
")",
";",
"// //same with total topics+posts",
"// if($topic_data['topic_visibility'] == ITEM_APPROVED)",
"// {",
"// set_config('num_topics', $config['num_topics'] - 1, true);",
"// set_config('num_posts', $config['num_posts'] - (1 + $this->topic_posts_approved), true);",
"// }",
"// elseif($this->topic_visibility == ITEM_APPROVED)",
"// {",
"// set_config('num_topics', $config['num_topics'] + 1, true);",
"// set_config('num_posts', $config['num_posts'] + (1 + $this->topic_posts_approved), true);",
"// }",
"// }",
"$",
"db",
"->",
"sql_transaction",
"(",
"'commit'",
")",
";",
"}",
"else",
"{",
"// new topic",
"$",
"sql_data",
"[",
"'forum_id'",
"]",
"=",
"$",
"this",
"->",
"forum_id",
";",
"$",
"sql_data",
"[",
"'topic_first_post_id'",
"]",
"=",
"0",
";",
"$",
"sql_data",
"[",
"'topic_last_post_id'",
"]",
"=",
"0",
";",
"$",
"sql",
"=",
"'INSERT INTO '",
".",
"TOPICS_TABLE",
".",
"' '",
".",
"$",
"db",
"->",
"sql_build_array",
"(",
"'INSERT'",
",",
"$",
"sql_data",
")",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"topic_id",
"=",
"$",
"db",
"->",
"sql_nextid",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"forum_id",
"!=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"topic_visibility",
"==",
"ITEM_APPROVED",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_topics_approved'",
",",
"1",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"topic_visibility",
"==",
"ITEM_UNAPPROVED",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_topics_unapproved'",
",",
"1",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"topic_visibility",
"==",
"ITEM_DELETED",
")",
"{",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_topics_deleted'",
",",
"1",
")",
";",
"}",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_posts_approved'",
",",
"$",
"this",
"->",
"topic_posts_approved",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_posts_unapproved'",
",",
"$",
"this",
"->",
"topic_posts_unapproved",
")",
";",
"$",
"sync",
"->",
"add",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
",",
"'forum_posts_softdeleted'",
",",
"$",
"this",
"->",
"topic_posts_softdeleted",
")",
";",
"$",
"sync",
"->",
"forum_last_post",
"(",
"$",
"this",
"->",
"forum_id",
")",
";",
"}",
"$",
"phpbb_content_visibility",
"=",
"$",
"phpbb_container",
"->",
"get",
"(",
"'content.visibility'",
")",
";",
"$",
"phpbb_content_visibility",
"->",
"set_topic_visibility",
"(",
"$",
"this",
"->",
"topic_visibility",
",",
"$",
"this",
"->",
"topic_id",
",",
"$",
"this",
"->",
"forum_id",
",",
"$",
"this",
"->",
"topic_delete_user",
",",
"$",
"this",
"->",
"topic_delete_time",
",",
"$",
"this",
"->",
"topic_delete_reason",
")",
";",
"// total topics",
"if",
"(",
"$",
"this",
"->",
"topic_visibility",
"==",
"ITEM_APPROVED",
")",
"{",
"set_config",
"(",
"'num_topics'",
",",
"$",
"config",
"[",
"'num_topics'",
"]",
"+",
"1",
",",
"true",
")",
";",
"}",
"$",
"sync",
"->",
"new_topic_flag",
"=",
"true",
";",
"}",
"// insert or update poll",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"poll_options",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"poll_options",
")",
")",
"{",
"$",
"cur_poll_options",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"poll_start",
"&&",
"isset",
"(",
"$",
"topic_data",
")",
")",
"{",
"$",
"sql",
"=",
"'SELECT * FROM '",
".",
"POLL_OPTIONS_TABLE",
".",
"'\n\t\t\t\t\tWHERE topic_id = '",
".",
"$",
"this",
"->",
"topic_id",
".",
"'\n\t\t\t\t\tORDER BY poll_option_id'",
";",
"$",
"result",
"=",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"cur_poll_options",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"db",
"->",
"sql_fetchrow",
"(",
"$",
"result",
")",
")",
"{",
"$",
"cur_poll_options",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"$",
"db",
"->",
"sql_freeresult",
"(",
"$",
"result",
")",
";",
"}",
"$",
"sql_insert_ary",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"size",
"=",
"sizeof",
"(",
"$",
"this",
"->",
"poll_options",
")",
";",
"$",
"i",
"<",
"$",
"size",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"this",
"->",
"poll_options",
"[",
"$",
"i",
"]",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"cur_poll_options",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"sql_insert_ary",
"[",
"]",
"=",
"array",
"(",
"'poll_option_id'",
"=>",
"(",
"int",
")",
"$",
"i",
",",
"'topic_id'",
"=>",
"(",
"int",
")",
"$",
"this",
"->",
"topic_id",
",",
"'poll_option_text'",
"=>",
"(",
"string",
")",
"$",
"this",
"->",
"poll_options",
"[",
"$",
"i",
"]",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"poll_options",
"[",
"$",
"i",
"]",
"!=",
"$",
"cur_poll_options",
"[",
"$",
"i",
"]",
")",
"{",
"$",
"sql",
"=",
"\"UPDATE \"",
".",
"POLL_OPTIONS_TABLE",
".",
"\"\n\t\t\t\t\t\t\tSET poll_option_text = '\"",
".",
"$",
"db",
"->",
"sql_escape",
"(",
"$",
"this",
"->",
"poll_options",
"[",
"$",
"i",
"]",
")",
".",
"\"'\n\t\t\t\t\t\t\tWHERE poll_option_id = \"",
".",
"$",
"cur_poll_options",
"[",
"$",
"i",
"]",
"[",
"'poll_option_id'",
"]",
".",
"\"\n\t\t\t\t\t\t\t\tAND topic_id = \"",
".",
"$",
"this",
"->",
"topic_id",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"}",
"}",
"}",
"$",
"db",
"->",
"sql_multi_insert",
"(",
"POLL_OPTIONS_TABLE",
",",
"$",
"sql_insert_ary",
")",
";",
"if",
"(",
"sizeof",
"(",
"$",
"this",
"->",
"poll_options",
")",
"<",
"sizeof",
"(",
"$",
"cur_poll_options",
")",
")",
"{",
"$",
"sql",
"=",
"'DELETE FROM '",
".",
"POLL_OPTIONS_TABLE",
".",
"'\n\t\t\t\t\tWHERE poll_option_id >= '",
".",
"sizeof",
"(",
"$",
"this",
"->",
"poll_options",
")",
".",
"'\n\t\t\t\t\t\tAND topic_id = '",
".",
"$",
"this",
"->",
"topic_id",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"}",
"}",
"// delete poll if we had one and poll_start is 0 now",
"if",
"(",
"isset",
"(",
"$",
"topic_data",
")",
"&&",
"$",
"topic_data",
"[",
"'poll_start'",
"]",
"&&",
"$",
"this",
"->",
"poll_start",
"==",
"0",
")",
"{",
"$",
"sql",
"=",
"'DELETE FROM '",
".",
"POLL_OPTIONS_TABLE",
".",
"'\n\t\t\t\tWHERE topic_id = '",
".",
"$",
"this",
"->",
"topic_id",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"sql",
"=",
"'DELETE FROM '",
".",
"POLL_VOTES_TABLE",
".",
"'\n\t\t\t\tWHERE topic_id = '",
".",
"$",
"this",
"->",
"topic_id",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"}",
"// End poll",
"if",
"(",
"$",
"submit_posts",
"&&",
"count",
"(",
"$",
"this",
"->",
"posts",
")",
")",
"{",
"// find and sync first post",
"if",
"(",
"$",
"sync",
"->",
"new_topic_flag",
")",
"{",
"// test if var was not set in post",
"$",
"first_post",
"=",
"$",
"this",
"->",
"posts",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"first_post",
"->",
"post_subject",
"==",
"''",
")",
"{",
"$",
"first_post",
"->",
"post_subject",
"=",
"$",
"this",
"->",
"topic_title",
";",
"}",
"if",
"(",
"!",
"$",
"first_post",
"->",
"poster_id",
")",
"{",
"$",
"first_post",
"->",
"poster_id",
"=",
"$",
"this",
"->",
"topic_poster",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"topic_visibility",
"!=",
"ITEM_APPROVED",
")",
"{",
"$",
"first_post",
"->",
"post_visibility",
"=",
"ITEM_UNAPPROVED",
";",
"}",
"}",
"elseif",
"(",
"$",
"topic_data",
"&&",
"$",
"this",
"->",
"topic_first_post_id",
"!=",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"posts",
"as",
"$",
"post",
")",
"{",
"if",
"(",
"$",
"post",
"->",
"post_id",
"==",
"$",
"this",
"->",
"topic_first_post_id",
")",
"{",
"// test if var has been changed in topic. this is like the",
"// else($submit_posts) below, but the user might have changed the",
"// post object but not the topic, so we can't just overwrite them",
"$",
"first_post",
"=",
"$",
"post",
";",
"if",
"(",
"$",
"this",
"->",
"topic_title",
"!=",
"$",
"topic_data",
"[",
"'topic_title'",
"]",
")",
"{",
"$",
"first_post",
"->",
"post_subject",
"=",
"$",
"this",
"->",
"topic_title",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"topic_time",
"!=",
"$",
"topic_data",
"[",
"'topic_time'",
"]",
")",
"{",
"$",
"first_post",
"->",
"post_time",
"=",
"$",
"this",
"->",
"topic_time",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"topic_poster",
"!=",
"$",
"topic_data",
"[",
"'topic_poster'",
"]",
")",
"{",
"$",
"first_post",
"->",
"poster_id",
"=",
"$",
"this",
"->",
"topic_poster",
";",
"$",
"first_post",
"->",
"post_username",
"=",
"(",
"$",
"this",
"->",
"topic_poster",
"==",
"ANONYMOUS",
")",
"?",
"$",
"this",
"->",
"topic_first_poster_name",
":",
"''",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"topic_approved",
"!=",
"$",
"topic_data",
"[",
"'topic_approved'",
"]",
")",
"{",
"$",
"first_post",
"->",
"post_approved",
"=",
"$",
"this",
"->",
"topic_approved",
";",
"}",
"break",
";",
"}",
"}",
"}",
"// TODO sort by post_time in case user messed with it",
"foreach",
"(",
"$",
"this",
"->",
"posts",
"as",
"$",
"post",
")",
"{",
"$",
"post",
"->",
"_topic",
"=",
"$",
"this",
";",
"$",
"post",
"->",
"topic_id",
"=",
"$",
"this",
"->",
"topic_id",
";",
"$",
"post",
"->",
"forum_id",
"=",
"$",
"this",
"->",
"forum_id",
";",
"// if(!$post->poster_id) $post->poster_id = $this->topic_poster;",
"$",
"post",
"->",
"submit_without_sync",
"(",
"$",
"sync",
")",
";",
"}",
"}",
"else",
"{",
"// sync first post if user edited topic only",
"$",
"sync",
"->",
"set",
"(",
"'post'",
",",
"$",
"this",
"->",
"topic_first_post_id",
",",
"array",
"(",
"'post_subject'",
"=>",
"$",
"this",
"->",
"topic_title",
",",
"'post_time'",
"=>",
"$",
"this",
"->",
"topic_time",
",",
"'poster_id'",
"=>",
"$",
"this",
"->",
"topic_poster",
",",
"'post_username'",
"=>",
"(",
"$",
"this",
"->",
"topic_poster",
"==",
"ANONYMOUS",
")",
"?",
"$",
"this",
"->",
"topic_first_poster_name",
":",
"''",
",",
"'post_visibility'",
"=>",
"$",
"this",
"->",
"topic_visibility",
",",
"'post_reported'",
"=>",
"$",
"this",
"->",
"topic_reported",
")",
")",
";",
"}",
"$",
"sync",
"->",
"execute",
"(",
")",
";",
"// refresh $this->topic_foo variables...",
"$",
"this",
"->",
"refresh_statvars",
"(",
")",
";",
"}"
] | TODO | [
"TODO"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/src/Gn36/OoPostingApi/topic.php#L232-L592 |
gn36/phpbb-oo-posting-api | src/Gn36/OoPostingApi/topic.php | topic.bump | function bump($user_id = 0)
{
global $db, $user;
$current_time = time();
if ($user_id == 0)
$user_id = $user->data['user_id'];
$db->sql_transaction('begin');
$sql = 'UPDATE ' . POSTS_TABLE . "
SET post_time = $current_time
WHERE post_id = {$this->topic_last_post_id}
AND topic_id = {$this->topic_id}";
$db->sql_query($sql);
$this->topic_bumped = 1;
$this->topic_bumper = $user_id;
$this->topic_last_post_time = $current_time;
$sql = 'UPDATE ' . TOPICS_TABLE . "
SET topic_last_post_time = $current_time,
topic_bumped = 1,
topic_bumper = $user_id
WHERE topic_id = $topic_id";
$db->sql_query($sql);
update_post_information('forum', $this->forum_id);
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_lastpost_time = $current_time
WHERE user_id = $user_id";
$db->sql_query($sql);
$db->sql_transaction('commit');
markread('post', $this->forum_id, $this->topic_id, $current_time, $user_id);
add_log('mod', $this->forum_id, $this->topic_id, 'LOG_BUMP_TOPIC', $this->topic_title);
} | php | function bump($user_id = 0)
{
global $db, $user;
$current_time = time();
if ($user_id == 0)
$user_id = $user->data['user_id'];
$db->sql_transaction('begin');
$sql = 'UPDATE ' . POSTS_TABLE . "
SET post_time = $current_time
WHERE post_id = {$this->topic_last_post_id}
AND topic_id = {$this->topic_id}";
$db->sql_query($sql);
$this->topic_bumped = 1;
$this->topic_bumper = $user_id;
$this->topic_last_post_time = $current_time;
$sql = 'UPDATE ' . TOPICS_TABLE . "
SET topic_last_post_time = $current_time,
topic_bumped = 1,
topic_bumper = $user_id
WHERE topic_id = $topic_id";
$db->sql_query($sql);
update_post_information('forum', $this->forum_id);
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_lastpost_time = $current_time
WHERE user_id = $user_id";
$db->sql_query($sql);
$db->sql_transaction('commit');
markread('post', $this->forum_id, $this->topic_id, $current_time, $user_id);
add_log('mod', $this->forum_id, $this->topic_id, 'LOG_BUMP_TOPIC', $this->topic_title);
} | [
"function",
"bump",
"(",
"$",
"user_id",
"=",
"0",
")",
"{",
"global",
"$",
"db",
",",
"$",
"user",
";",
"$",
"current_time",
"=",
"time",
"(",
")",
";",
"if",
"(",
"$",
"user_id",
"==",
"0",
")",
"$",
"user_id",
"=",
"$",
"user",
"->",
"data",
"[",
"'user_id'",
"]",
";",
"$",
"db",
"->",
"sql_transaction",
"(",
"'begin'",
")",
";",
"$",
"sql",
"=",
"'UPDATE '",
".",
"POSTS_TABLE",
".",
"\"\n\t\tSET post_time = $current_time\n\t\tWHERE post_id = {$this->topic_last_post_id}\n\t\tAND topic_id = {$this->topic_id}\"",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"topic_bumped",
"=",
"1",
";",
"$",
"this",
"->",
"topic_bumper",
"=",
"$",
"user_id",
";",
"$",
"this",
"->",
"topic_last_post_time",
"=",
"$",
"current_time",
";",
"$",
"sql",
"=",
"'UPDATE '",
".",
"TOPICS_TABLE",
".",
"\"\n\t\tSET topic_last_post_time = $current_time,\n\t\ttopic_bumped = 1,\n\t\ttopic_bumper = $user_id\n\t\tWHERE topic_id = $topic_id\"",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"update_post_information",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forum_id",
")",
";",
"$",
"sql",
"=",
"'UPDATE '",
".",
"USERS_TABLE",
".",
"\"\n\t\tSET user_lastpost_time = $current_time\n\t\tWHERE user_id = $user_id\"",
";",
"$",
"db",
"->",
"sql_query",
"(",
"$",
"sql",
")",
";",
"$",
"db",
"->",
"sql_transaction",
"(",
"'commit'",
")",
";",
"markread",
"(",
"'post'",
",",
"$",
"this",
"->",
"forum_id",
",",
"$",
"this",
"->",
"topic_id",
",",
"$",
"current_time",
",",
"$",
"user_id",
")",
";",
"add_log",
"(",
"'mod'",
",",
"$",
"this",
"->",
"forum_id",
",",
"$",
"this",
"->",
"topic_id",
",",
"'LOG_BUMP_TOPIC'",
",",
"$",
"this",
"->",
"topic_title",
")",
";",
"}"
] | bumps the topic
@param | [
"bumps",
"the",
"topic"
] | train | https://github.com/gn36/phpbb-oo-posting-api/blob/d0e19482a9e1e93a435c1758a66df9324145381a/src/Gn36/OoPostingApi/topic.php#L717-L755 |
FriendsOfApi/phraseapp | src/HttpClientConfigurator.php | HttpClientConfigurator.appendPlugin | public function appendPlugin(Plugin ...$plugin): HttpClientConfigurator
{
foreach ($plugin as $p) {
$this->appendPlugins[] = $p;
}
return $this;
} | php | public function appendPlugin(Plugin ...$plugin): HttpClientConfigurator
{
foreach ($plugin as $p) {
$this->appendPlugins[] = $p;
}
return $this;
} | [
"public",
"function",
"appendPlugin",
"(",
"Plugin",
"...",
"$",
"plugin",
")",
":",
"HttpClientConfigurator",
"{",
"foreach",
"(",
"$",
"plugin",
"as",
"$",
"p",
")",
"{",
"$",
"this",
"->",
"appendPlugins",
"[",
"]",
"=",
"$",
"p",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param Plugin $plugin
@return HttpClientConfigurator | [
"@param",
"Plugin",
"$plugin"
] | train | https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/HttpClientConfigurator.php#L104-L111 |
FriendsOfApi/phraseapp | src/HttpClientConfigurator.php | HttpClientConfigurator.prependPlugin | public function prependPlugin(Plugin ...$plugin): HttpClientConfigurator
{
$plugin = array_reverse($plugin);
foreach ($plugin as $p) {
array_unshift($this->prependPlugins, $p);
}
return $this;
} | php | public function prependPlugin(Plugin ...$plugin): HttpClientConfigurator
{
$plugin = array_reverse($plugin);
foreach ($plugin as $p) {
array_unshift($this->prependPlugins, $p);
}
return $this;
} | [
"public",
"function",
"prependPlugin",
"(",
"Plugin",
"...",
"$",
"plugin",
")",
":",
"HttpClientConfigurator",
"{",
"$",
"plugin",
"=",
"array_reverse",
"(",
"$",
"plugin",
")",
";",
"foreach",
"(",
"$",
"plugin",
"as",
"$",
"p",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"prependPlugins",
",",
"$",
"p",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param Plugin $plugin
@return HttpClientConfigurator | [
"@param",
"Plugin",
"$plugin"
] | train | https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/HttpClientConfigurator.php#L118-L126 |
Baachi/CouchDB | src/CouchDB/Connection.php | Connection.version | public function version()
{
$json = (string) $this->client->request('GET', '/')->getBody();
$value = JSONEncoder::decode($json);
return $value['version'];
} | php | public function version()
{
$json = (string) $this->client->request('GET', '/')->getBody();
$value = JSONEncoder::decode($json);
return $value['version'];
} | [
"public",
"function",
"version",
"(",
")",
"{",
"$",
"json",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"'GET'",
",",
"'/'",
")",
"->",
"getBody",
"(",
")",
";",
"$",
"value",
"=",
"JSONEncoder",
"::",
"decode",
"(",
"$",
"json",
")",
";",
"return",
"$",
"value",
"[",
"'version'",
"]",
";",
"}"
] | Get the couchdb version.
@return string | [
"Get",
"the",
"couchdb",
"version",
"."
] | train | https://github.com/Baachi/CouchDB/blob/6be364c2f3d9c7b1288b1c11115469c91819ff5c/src/CouchDB/Connection.php#L52-L58 |
Baachi/CouchDB | src/CouchDB/Connection.php | Connection.listDatabases | public function listDatabases()
{
$json = (string) $this->client->request('GET', '/_all_dbs')->getBody();
$databases = JSONEncoder::decode($json);
return $databases;
} | php | public function listDatabases()
{
$json = (string) $this->client->request('GET', '/_all_dbs')->getBody();
$databases = JSONEncoder::decode($json);
return $databases;
} | [
"public",
"function",
"listDatabases",
"(",
")",
"{",
"$",
"json",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"'GET'",
",",
"'/_all_dbs'",
")",
"->",
"getBody",
"(",
")",
";",
"$",
"databases",
"=",
"JSONEncoder",
"::",
"decode",
"(",
"$",
"json",
")",
";",
"return",
"$",
"databases",
";",
"}"
] | Show all databases.
@return array | [
"Show",
"all",
"databases",
"."
] | train | https://github.com/Baachi/CouchDB/blob/6be364c2f3d9c7b1288b1c11115469c91819ff5c/src/CouchDB/Connection.php#L65-L71 |
Baachi/CouchDB | src/CouchDB/Connection.php | Connection.dropDatabase | public function dropDatabase($name)
{
if ($this->eventManager->hasListeners(Events::PRE_DROP_DATABASE)) {
// @codeCoverageIgnoreStart
$this->eventManager->dispatchEvent(Events::PRE_DROP_DATABASE, new EventArgs($this, $name));
// @codeCoverageIgnoreEnd
}
$response = $this->client->request('DELETE', sprintf('/%s/', urlencode($name)));
if (404 === $response->getStatusCode()) {
throw new Exception(sprintf('The database "%s" does not exist', $name));
}
$json = (string) $response->getBody();
$status = JSONEncoder::decode($json);
if ($this->eventManager->hasListeners(Events::POST_DROP_DATABASE)) {
// @codeCoverageIgnoreStart
$this->eventManager->dispatchEvent(Events::POST_DROP_DATABASE, new EventArgs($this, $name));
// @codeCoverageIgnoreEnd
}
return isset($status['ok']) && $status['ok'] === true;
} | php | public function dropDatabase($name)
{
if ($this->eventManager->hasListeners(Events::PRE_DROP_DATABASE)) {
// @codeCoverageIgnoreStart
$this->eventManager->dispatchEvent(Events::PRE_DROP_DATABASE, new EventArgs($this, $name));
// @codeCoverageIgnoreEnd
}
$response = $this->client->request('DELETE', sprintf('/%s/', urlencode($name)));
if (404 === $response->getStatusCode()) {
throw new Exception(sprintf('The database "%s" does not exist', $name));
}
$json = (string) $response->getBody();
$status = JSONEncoder::decode($json);
if ($this->eventManager->hasListeners(Events::POST_DROP_DATABASE)) {
// @codeCoverageIgnoreStart
$this->eventManager->dispatchEvent(Events::POST_DROP_DATABASE, new EventArgs($this, $name));
// @codeCoverageIgnoreEnd
}
return isset($status['ok']) && $status['ok'] === true;
} | [
"public",
"function",
"dropDatabase",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"eventManager",
"->",
"hasListeners",
"(",
"Events",
"::",
"PRE_DROP_DATABASE",
")",
")",
"{",
"// @codeCoverageIgnoreStart",
"$",
"this",
"->",
"eventManager",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"PRE_DROP_DATABASE",
",",
"new",
"EventArgs",
"(",
"$",
"this",
",",
"$",
"name",
")",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"'DELETE'",
",",
"sprintf",
"(",
"'/%s/'",
",",
"urlencode",
"(",
"$",
"name",
")",
")",
")",
";",
"if",
"(",
"404",
"===",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'The database \"%s\" does not exist'",
",",
"$",
"name",
")",
")",
";",
"}",
"$",
"json",
"=",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"$",
"status",
"=",
"JSONEncoder",
"::",
"decode",
"(",
"$",
"json",
")",
";",
"if",
"(",
"$",
"this",
"->",
"eventManager",
"->",
"hasListeners",
"(",
"Events",
"::",
"POST_DROP_DATABASE",
")",
")",
"{",
"// @codeCoverageIgnoreStart",
"$",
"this",
"->",
"eventManager",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"POST_DROP_DATABASE",
",",
"new",
"EventArgs",
"(",
"$",
"this",
",",
"$",
"name",
")",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"return",
"isset",
"(",
"$",
"status",
"[",
"'ok'",
"]",
")",
"&&",
"$",
"status",
"[",
"'ok'",
"]",
"===",
"true",
";",
"}"
] | Drop a database.
@param string $name
@return bool | [
"Drop",
"a",
"database",
"."
] | train | https://github.com/Baachi/CouchDB/blob/6be364c2f3d9c7b1288b1c11115469c91819ff5c/src/CouchDB/Connection.php#L80-L104 |
Baachi/CouchDB | src/CouchDB/Connection.php | Connection.selectDatabase | public function selectDatabase($name)
{
$response = $this->client->request('GET', sprintf('/%s/', $name));
if (404 === $response->getStatusCode()) {
throw new Exception(sprintf('The database "%s" does not exist', $name));
}
return $this->wrapDatabase($name);
} | php | public function selectDatabase($name)
{
$response = $this->client->request('GET', sprintf('/%s/', $name));
if (404 === $response->getStatusCode()) {
throw new Exception(sprintf('The database "%s" does not exist', $name));
}
return $this->wrapDatabase($name);
} | [
"public",
"function",
"selectDatabase",
"(",
"$",
"name",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"'GET'",
",",
"sprintf",
"(",
"'/%s/'",
",",
"$",
"name",
")",
")",
";",
"if",
"(",
"404",
"===",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'The database \"%s\" does not exist'",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"wrapDatabase",
"(",
"$",
"name",
")",
";",
"}"
] | Select a database.
@param string $name
@throws Exception If the database doesn't exists.
@return Database | [
"Select",
"a",
"database",
"."
] | train | https://github.com/Baachi/CouchDB/blob/6be364c2f3d9c7b1288b1c11115469c91819ff5c/src/CouchDB/Connection.php#L115-L124 |
Baachi/CouchDB | src/CouchDB/Connection.php | Connection.hasDatabase | public function hasDatabase($name)
{
$response = $this->client->request(
'GET',
sprintf('/%s/', urlencode($name))
);
return 404 !== $response->getStatusCode();
} | php | public function hasDatabase($name)
{
$response = $this->client->request(
'GET',
sprintf('/%s/', urlencode($name))
);
return 404 !== $response->getStatusCode();
} | [
"public",
"function",
"hasDatabase",
"(",
"$",
"name",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"'GET'",
",",
"sprintf",
"(",
"'/%s/'",
",",
"urlencode",
"(",
"$",
"name",
")",
")",
")",
";",
"return",
"404",
"!==",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"}"
] | Check if a database exists.
@param string $name The database name
@return bool | [
"Check",
"if",
"a",
"database",
"exists",
"."
] | train | https://github.com/Baachi/CouchDB/blob/6be364c2f3d9c7b1288b1c11115469c91819ff5c/src/CouchDB/Connection.php#L133-L141 |
Baachi/CouchDB | src/CouchDB/Connection.php | Connection.createDatabase | public function createDatabase($name)
{
if (preg_match('@[^a-z0-9\_\$\(\)+\-]@', $name)) {
throw new InvalidDatabasenameException(sprintf(
'The database name %s is invalid. The database name must match the following pattern (a-z0-9_$()+-)',
$name
));
}
if ($this->eventManager->hasListeners(Events::PRE_CREATE_DATABASE)) {
// @codeCoverageIgnoreStart
$this->eventManager->dispatchEvent(Events::PRE_CREATE_DATABASE, new EventArgs($this, $name));
// @codeCoverageIgnoreEnd
}
$response = $this->client->request('PUT', sprintf('/%s', $name));
if (412 === $response->getStatusCode()) {
throw new Exception(sprintf('The database "%s" already exist', $name));
}
$json = (string) $response->getBody();
$value = JSONEncoder::decode($json);
if (isset($value['error'])) {
throw new Exception(sprintf('[%s] Failed to create database "%s". (%s)', $value['error'], $name, $value['reason']));
}
$database = $this->wrapDatabase($name);
if ($this->eventManager->hasListeners(Events::POST_CREATE_DATABASE)) {
// @codeCoverageIgnoreStart
$this->eventManager->dispatchEvent(Events::POST_CREATE_DATABASE, new EventArgs($database));
// @codeCoverageIgnoreEnd
}
return $database;
} | php | public function createDatabase($name)
{
if (preg_match('@[^a-z0-9\_\$\(\)+\-]@', $name)) {
throw new InvalidDatabasenameException(sprintf(
'The database name %s is invalid. The database name must match the following pattern (a-z0-9_$()+-)',
$name
));
}
if ($this->eventManager->hasListeners(Events::PRE_CREATE_DATABASE)) {
// @codeCoverageIgnoreStart
$this->eventManager->dispatchEvent(Events::PRE_CREATE_DATABASE, new EventArgs($this, $name));
// @codeCoverageIgnoreEnd
}
$response = $this->client->request('PUT', sprintf('/%s', $name));
if (412 === $response->getStatusCode()) {
throw new Exception(sprintf('The database "%s" already exist', $name));
}
$json = (string) $response->getBody();
$value = JSONEncoder::decode($json);
if (isset($value['error'])) {
throw new Exception(sprintf('[%s] Failed to create database "%s". (%s)', $value['error'], $name, $value['reason']));
}
$database = $this->wrapDatabase($name);
if ($this->eventManager->hasListeners(Events::POST_CREATE_DATABASE)) {
// @codeCoverageIgnoreStart
$this->eventManager->dispatchEvent(Events::POST_CREATE_DATABASE, new EventArgs($database));
// @codeCoverageIgnoreEnd
}
return $database;
} | [
"public",
"function",
"createDatabase",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'@[^a-z0-9\\_\\$\\(\\)+\\-]@'",
",",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidDatabasenameException",
"(",
"sprintf",
"(",
"'The database name %s is invalid. The database name must match the following pattern (a-z0-9_$()+-)'",
",",
"$",
"name",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"eventManager",
"->",
"hasListeners",
"(",
"Events",
"::",
"PRE_CREATE_DATABASE",
")",
")",
"{",
"// @codeCoverageIgnoreStart",
"$",
"this",
"->",
"eventManager",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"PRE_CREATE_DATABASE",
",",
"new",
"EventArgs",
"(",
"$",
"this",
",",
"$",
"name",
")",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"'PUT'",
",",
"sprintf",
"(",
"'/%s'",
",",
"$",
"name",
")",
")",
";",
"if",
"(",
"412",
"===",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'The database \"%s\" already exist'",
",",
"$",
"name",
")",
")",
";",
"}",
"$",
"json",
"=",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"$",
"value",
"=",
"JSONEncoder",
"::",
"decode",
"(",
"$",
"json",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'error'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'[%s] Failed to create database \"%s\". (%s)'",
",",
"$",
"value",
"[",
"'error'",
"]",
",",
"$",
"name",
",",
"$",
"value",
"[",
"'reason'",
"]",
")",
")",
";",
"}",
"$",
"database",
"=",
"$",
"this",
"->",
"wrapDatabase",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"this",
"->",
"eventManager",
"->",
"hasListeners",
"(",
"Events",
"::",
"POST_CREATE_DATABASE",
")",
")",
"{",
"// @codeCoverageIgnoreStart",
"$",
"this",
"->",
"eventManager",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"POST_CREATE_DATABASE",
",",
"new",
"EventArgs",
"(",
"$",
"database",
")",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"return",
"$",
"database",
";",
"}"
] | Creates a new database.
@param string $name The database name
@throws Exception If the database could not be created.
@return Database | [
"Creates",
"a",
"new",
"database",
"."
] | train | https://github.com/Baachi/CouchDB/blob/6be364c2f3d9c7b1288b1c11115469c91819ff5c/src/CouchDB/Connection.php#L152-L189 |
thienhungho/yii2-product-management | src/modules/ProductManage/search/ProductTypeSearch.php | ProductTypeSearch.search | public function search($params)
{
$query = ProductType::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'created_by' => $this->created_by,
'updated_by' => $this->updated_by,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'slug', $this->slug]);
return $dataProvider;
} | php | public function search($params)
{
$query = ProductType::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'created_by' => $this->created_by,
'updated_by' => $this->updated_by,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'slug', $this->slug]);
return $dataProvider;
} | [
"public",
"function",
"search",
"(",
"$",
"params",
")",
"{",
"$",
"query",
"=",
"ProductType",
"::",
"find",
"(",
")",
";",
"$",
"dataProvider",
"=",
"new",
"ActiveDataProvider",
"(",
"[",
"'query'",
"=>",
"$",
"query",
",",
"]",
")",
";",
"$",
"this",
"->",
"load",
"(",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"// uncomment the following line if you do not want to return any records when validation fails\r",
"// $query->where('0=1');\r",
"return",
"$",
"dataProvider",
";",
"}",
"$",
"query",
"->",
"andFilterWhere",
"(",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'created_at'",
"=>",
"$",
"this",
"->",
"created_at",
",",
"'updated_at'",
"=>",
"$",
"this",
"->",
"updated_at",
",",
"'created_by'",
"=>",
"$",
"this",
"->",
"created_by",
",",
"'updated_by'",
"=>",
"$",
"this",
"->",
"updated_by",
",",
"]",
")",
";",
"$",
"query",
"->",
"andFilterWhere",
"(",
"[",
"'like'",
",",
"'name'",
",",
"$",
"this",
"->",
"name",
"]",
")",
"->",
"andFilterWhere",
"(",
"[",
"'like'",
",",
"'slug'",
",",
"$",
"this",
"->",
"slug",
"]",
")",
";",
"return",
"$",
"dataProvider",
";",
"}"
] | Creates data provider instance with search query applied
@param array $params
@return ActiveDataProvider | [
"Creates",
"data",
"provider",
"instance",
"with",
"search",
"query",
"applied"
] | train | https://github.com/thienhungho/yii2-product-management/blob/72e1237bba123faf671e44491bd93077b50adde9/src/modules/ProductManage/search/ProductTypeSearch.php#L42-L70 |
antismok/domain-events-publisher | src/DomainEventPublisher.php | DomainEventPublisher.addListener | public function addListener(string $eventName, $listener, int $priority = 0): void
{
$this->dispatcher->addListener($eventName, $listener, $priority);
} | php | public function addListener(string $eventName, $listener, int $priority = 0): void
{
$this->dispatcher->addListener($eventName, $listener, $priority);
} | [
"public",
"function",
"addListener",
"(",
"string",
"$",
"eventName",
",",
"$",
"listener",
",",
"int",
"$",
"priority",
"=",
"0",
")",
":",
"void",
"{",
"$",
"this",
"->",
"dispatcher",
"->",
"addListener",
"(",
"$",
"eventName",
",",
"$",
"listener",
",",
"$",
"priority",
")",
";",
"}"
] | Adds an event listener that listens on the specified events.
@param string $eventName The event to listen on
@param callable $listener The listener
@param int $priority The higher this value, the earlier an event
listener will be triggered in the chain (defaults to 0)
@return void | [
"Adds",
"an",
"event",
"listener",
"that",
"listens",
"on",
"the",
"specified",
"events",
"."
] | train | https://github.com/antismok/domain-events-publisher/blob/3ce431a0b81b1de10cd189281b05b8084c42bc63/src/DomainEventPublisher.php#L62-L65 |
antismok/domain-events-publisher | src/DomainEventPublisher.php | DomainEventPublisher.removeListener | public function removeListener(string $eventName, $listener): void
{
$this->dispatcher->removeListener($eventName, $listener);
} | php | public function removeListener(string $eventName, $listener): void
{
$this->dispatcher->removeListener($eventName, $listener);
} | [
"public",
"function",
"removeListener",
"(",
"string",
"$",
"eventName",
",",
"$",
"listener",
")",
":",
"void",
"{",
"$",
"this",
"->",
"dispatcher",
"->",
"removeListener",
"(",
"$",
"eventName",
",",
"$",
"listener",
")",
";",
"}"
] | Remove event listener
@param string $eventName
@param type $listener
@return void | [
"Remove",
"event",
"listener"
] | train | https://github.com/antismok/domain-events-publisher/blob/3ce431a0b81b1de10cd189281b05b8084c42bc63/src/DomainEventPublisher.php#L75-L78 |
antismok/domain-events-publisher | src/DomainEventPublisher.php | DomainEventPublisher.removeListeners | public function removeListeners(string $eventName): void
{
foreach ($this->dispatcher->getListeners($eventName) as $listener) {
$this->removeListener($eventName, $listener);
}
} | php | public function removeListeners(string $eventName): void
{
foreach ($this->dispatcher->getListeners($eventName) as $listener) {
$this->removeListener($eventName, $listener);
}
} | [
"public",
"function",
"removeListeners",
"(",
"string",
"$",
"eventName",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dispatcher",
"->",
"getListeners",
"(",
"$",
"eventName",
")",
"as",
"$",
"listener",
")",
"{",
"$",
"this",
"->",
"removeListener",
"(",
"$",
"eventName",
",",
"$",
"listener",
")",
";",
"}",
"}"
] | Remove all event listeners
@param string $eventName
@return void | [
"Remove",
"all",
"event",
"listeners"
] | train | https://github.com/antismok/domain-events-publisher/blob/3ce431a0b81b1de10cd189281b05b8084c42bc63/src/DomainEventPublisher.php#L87-L92 |
antismok/domain-events-publisher | src/DomainEventPublisher.php | DomainEventPublisher.dispatch | protected function dispatch(string $eventName, DomainEvent $event): void
{
$listeners = $this->dispatcher->getListeners($eventName);
if (!empty($listeners)) {
$this->doDispatch($listeners, $eventName, $event);
}
} | php | protected function dispatch(string $eventName, DomainEvent $event): void
{
$listeners = $this->dispatcher->getListeners($eventName);
if (!empty($listeners)) {
$this->doDispatch($listeners, $eventName, $event);
}
} | [
"protected",
"function",
"dispatch",
"(",
"string",
"$",
"eventName",
",",
"DomainEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"listeners",
"=",
"$",
"this",
"->",
"dispatcher",
"->",
"getListeners",
"(",
"$",
"eventName",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"listeners",
")",
")",
"{",
"$",
"this",
"->",
"doDispatch",
"(",
"$",
"listeners",
",",
"$",
"eventName",
",",
"$",
"event",
")",
";",
"}",
"}"
] | Dispatches an event to all registered listeners.
@param string $eventName The name of the event to dispatch.
@param DomainEvent $event The event to pass to the event handlers/listeners
@return void | [
"Dispatches",
"an",
"event",
"to",
"all",
"registered",
"listeners",
"."
] | train | https://github.com/antismok/domain-events-publisher/blob/3ce431a0b81b1de10cd189281b05b8084c42bc63/src/DomainEventPublisher.php#L102-L109 |
antismok/domain-events-publisher | src/DomainEventPublisher.php | DomainEventPublisher.doDispatch | protected function doDispatch(array $listeners, string $eventName, DomainEvent $event): void
{
foreach ($listeners as $listener) {
call_user_func($listener, $event, $eventName, $this);
}
} | php | protected function doDispatch(array $listeners, string $eventName, DomainEvent $event): void
{
foreach ($listeners as $listener) {
call_user_func($listener, $event, $eventName, $this);
}
} | [
"protected",
"function",
"doDispatch",
"(",
"array",
"$",
"listeners",
",",
"string",
"$",
"eventName",
",",
"DomainEvent",
"$",
"event",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"listeners",
"as",
"$",
"listener",
")",
"{",
"call_user_func",
"(",
"$",
"listener",
",",
"$",
"event",
",",
"$",
"eventName",
",",
"$",
"this",
")",
";",
"}",
"}"
] | Triggers the listeners of an event.
This method can be overridden to add functionality that is executed
for each listener.
@param callable[] $listeners The event listeners
@param string $eventName The name of the event to dispatch
@param DomainEvent $event The event object to pass to the event handlers/listeners
@return void | [
"Triggers",
"the",
"listeners",
"of",
"an",
"event",
"."
] | train | https://github.com/antismok/domain-events-publisher/blob/3ce431a0b81b1de10cd189281b05b8084c42bc63/src/DomainEventPublisher.php#L123-L128 |
surebert/surebert-framework | src/sb/XMPP/Packet.php | Packet.setTo | public function setTo($to)
{
$attr = $this->createAttribute('to');
$this->doc->appendChild($attr);
$attr->appendChild($this->createTextNode($to));
} | php | public function setTo($to)
{
$attr = $this->createAttribute('to');
$this->doc->appendChild($attr);
$attr->appendChild($this->createTextNode($to));
} | [
"public",
"function",
"setTo",
"(",
"$",
"to",
")",
"{",
"$",
"attr",
"=",
"$",
"this",
"->",
"createAttribute",
"(",
"'to'",
")",
";",
"$",
"this",
"->",
"doc",
"->",
"appendChild",
"(",
"$",
"attr",
")",
";",
"$",
"attr",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createTextNode",
"(",
"$",
"to",
")",
")",
";",
"}"
] | Sets the to jid of the message
@param string $to e.g. [email protected] | [
"Sets",
"the",
"to",
"jid",
"of",
"the",
"message"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/XMPP/Packet.php#L62-L67 |
surebert/surebert-framework | src/sb/XMPP/Packet.php | Packet.setFrom | public function setFrom($from)
{
$attr = $this->createAttribute('from');
$this->doc->appendChild($attr);
$attr->appendChild($this->createTextNode($from));
} | php | public function setFrom($from)
{
$attr = $this->createAttribute('from');
$this->doc->appendChild($attr);
$attr->appendChild($this->createTextNode($from));
} | [
"public",
"function",
"setFrom",
"(",
"$",
"from",
")",
"{",
"$",
"attr",
"=",
"$",
"this",
"->",
"createAttribute",
"(",
"'from'",
")",
";",
"$",
"this",
"->",
"doc",
"->",
"appendChild",
"(",
"$",
"attr",
")",
";",
"$",
"attr",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createTextNode",
"(",
"$",
"from",
")",
")",
";",
"}"
] | Sets the from jid of the message
@param string $from e.g. [email protected] | [
"Sets",
"the",
"from",
"jid",
"of",
"the",
"message"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/XMPP/Packet.php#L73-L78 |
surebert/surebert-framework | src/sb/XMPP/Packet.php | Packet.addXML | public function addXML($xml)
{
$next_elem = $this->createDocumentFragment();
$next_elem->appendXML($xml);
$this->doc->appendChild($next_elem);
} | php | public function addXML($xml)
{
$next_elem = $this->createDocumentFragment();
$next_elem->appendXML($xml);
$this->doc->appendChild($next_elem);
} | [
"public",
"function",
"addXML",
"(",
"$",
"xml",
")",
"{",
"$",
"next_elem",
"=",
"$",
"this",
"->",
"createDocumentFragment",
"(",
")",
";",
"$",
"next_elem",
"->",
"appendXML",
"(",
"$",
"xml",
")",
";",
"$",
"this",
"->",
"doc",
"->",
"appendChild",
"(",
"$",
"next_elem",
")",
";",
"}"
] | Adds an arbitrary XML string to the packet's root node
@param string $xml | [
"Adds",
"an",
"arbitrary",
"XML",
"string",
"to",
"the",
"packet",
"s",
"root",
"node"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/XMPP/Packet.php#L104-L110 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Repository/AbstractRepository.php | AbstractRepository.findBy | public function findBy(array $conditions)
{
$s = $this->selector();
foreach ($conditions as $column => $value) {
$s->where($column, '=', $value);
}
return $s->execute();
} | php | public function findBy(array $conditions)
{
$s = $this->selector();
foreach ($conditions as $column => $value) {
$s->where($column, '=', $value);
}
return $s->execute();
} | [
"public",
"function",
"findBy",
"(",
"array",
"$",
"conditions",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"selector",
"(",
")",
";",
"foreach",
"(",
"$",
"conditions",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"s",
"->",
"where",
"(",
"$",
"column",
",",
"'='",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"s",
"->",
"execute",
"(",
")",
";",
"}"
] | Select entities matching an array of conditions.
@param array $conditions An array of the form 'column => value'
@return EntityCollection The selected entities | [
"Select",
"entities",
"matching",
"an",
"array",
"of",
"conditions",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Repository/AbstractRepository.php#L57-L65 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Repository/AbstractRepository.php | AbstractRepository.findOneBy | public function findOneBy(array $conditions)
{
$s = $this->selector()->one();
foreach ($conditions as $column => $value) {
$s->where($column, '=', $value);
}
return $s->execute();
} | php | public function findOneBy(array $conditions)
{
$s = $this->selector()->one();
foreach ($conditions as $column => $value) {
$s->where($column, '=', $value);
}
return $s->execute();
} | [
"public",
"function",
"findOneBy",
"(",
"array",
"$",
"conditions",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"selector",
"(",
")",
"->",
"one",
"(",
")",
";",
"foreach",
"(",
"$",
"conditions",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"s",
"->",
"where",
"(",
"$",
"column",
",",
"'='",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"s",
"->",
"execute",
"(",
")",
";",
"}"
] | Select a single entity matching an array of conditions.
@param array $conditions An array of the form 'column => value'
@return Entity|null The selected entity or null | [
"Select",
"a",
"single",
"entity",
"matching",
"an",
"array",
"of",
"conditions",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Repository/AbstractRepository.php#L73-L81 |
php-lug/lug | src/Component/Translation/Repository/Doctrine/MongoDB/TranslatableRepositoryFactory.php | TranslatableRepositoryFactory.createResourceRepository | protected function createResourceRepository(
$class,
DocumentManager $documentManager,
ClassMetadata $metadata,
ResourceInterface $resource = null
) {
if ($resource !== null && is_a($class, TranslatableRepository::class, true)) {
return new $class(
$documentManager,
$documentManager->getUnitOfWork(),
$metadata,
$resource,
$this->getLocaleContext()
);
}
return parent::createResourceRepository($class, $documentManager, $metadata, $resource);
} | php | protected function createResourceRepository(
$class,
DocumentManager $documentManager,
ClassMetadata $metadata,
ResourceInterface $resource = null
) {
if ($resource !== null && is_a($class, TranslatableRepository::class, true)) {
return new $class(
$documentManager,
$documentManager->getUnitOfWork(),
$metadata,
$resource,
$this->getLocaleContext()
);
}
return parent::createResourceRepository($class, $documentManager, $metadata, $resource);
} | [
"protected",
"function",
"createResourceRepository",
"(",
"$",
"class",
",",
"DocumentManager",
"$",
"documentManager",
",",
"ClassMetadata",
"$",
"metadata",
",",
"ResourceInterface",
"$",
"resource",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"resource",
"!==",
"null",
"&&",
"is_a",
"(",
"$",
"class",
",",
"TranslatableRepository",
"::",
"class",
",",
"true",
")",
")",
"{",
"return",
"new",
"$",
"class",
"(",
"$",
"documentManager",
",",
"$",
"documentManager",
"->",
"getUnitOfWork",
"(",
")",
",",
"$",
"metadata",
",",
"$",
"resource",
",",
"$",
"this",
"->",
"getLocaleContext",
"(",
")",
")",
";",
"}",
"return",
"parent",
"::",
"createResourceRepository",
"(",
"$",
"class",
",",
"$",
"documentManager",
",",
"$",
"metadata",
",",
"$",
"resource",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Translation/Repository/Doctrine/MongoDB/TranslatableRepositoryFactory.php#L44-L61 |
scherersoftware/cake-monitor | src/Error/SentryHandler.php | SentryHandler.handle | public function handle(Throwable $throwable)
{
if (!Configure::read('CakeMonitor.Sentry.enabled') || error_reporting() === 0) {
return false;
}
$errorHandler = new \Raven_ErrorHandler($this->_ravenClient);
$errorHandler->registerShutdownFunction();
$errorHandler->handleException($throwable);
} | php | public function handle(Throwable $throwable)
{
if (!Configure::read('CakeMonitor.Sentry.enabled') || error_reporting() === 0) {
return false;
}
$errorHandler = new \Raven_ErrorHandler($this->_ravenClient);
$errorHandler->registerShutdownFunction();
$errorHandler->handleException($throwable);
} | [
"public",
"function",
"handle",
"(",
"Throwable",
"$",
"throwable",
")",
"{",
"if",
"(",
"!",
"Configure",
"::",
"read",
"(",
"'CakeMonitor.Sentry.enabled'",
")",
"||",
"error_reporting",
"(",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"errorHandler",
"=",
"new",
"\\",
"Raven_ErrorHandler",
"(",
"$",
"this",
"->",
"_ravenClient",
")",
";",
"$",
"errorHandler",
"->",
"registerShutdownFunction",
"(",
")",
";",
"$",
"errorHandler",
"->",
"handleException",
"(",
"$",
"throwable",
")",
";",
"}"
] | Throwable Handler
@param Throwable $throwable Throwable to handle
@return void | [
"Throwable",
"Handler"
] | train | https://github.com/scherersoftware/cake-monitor/blob/dbe07a1aac41b3db15e631d9e59cf26214bf6938/src/Error/SentryHandler.php#L44-L53 |
scherersoftware/cake-monitor | src/Error/SentryHandler.php | SentryHandler.captureMessage | public function captureMessage($message, $params = [], $data = [], $stack = false, $vars = null)
{
if (!Configure::read('CakeMonitor.Sentry.enabled') || error_reporting() === 0) {
return false;
}
if (is_callable(Configure::read('CakeMonitor.Sentry.extraDataCallback'))) {
$data['extra']['extraDataCallback'] = call_user_func(Configure::read('CakeMonitor.Sentry.extraDataCallback'));
}
return $this->_ravenClient->captureMessage($message, $params, $data, $stack, $vars);
} | php | public function captureMessage($message, $params = [], $data = [], $stack = false, $vars = null)
{
if (!Configure::read('CakeMonitor.Sentry.enabled') || error_reporting() === 0) {
return false;
}
if (is_callable(Configure::read('CakeMonitor.Sentry.extraDataCallback'))) {
$data['extra']['extraDataCallback'] = call_user_func(Configure::read('CakeMonitor.Sentry.extraDataCallback'));
}
return $this->_ravenClient->captureMessage($message, $params, $data, $stack, $vars);
} | [
"public",
"function",
"captureMessage",
"(",
"$",
"message",
",",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"stack",
"=",
"false",
",",
"$",
"vars",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"Configure",
"::",
"read",
"(",
"'CakeMonitor.Sentry.enabled'",
")",
"||",
"error_reporting",
"(",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_callable",
"(",
"Configure",
"::",
"read",
"(",
"'CakeMonitor.Sentry.extraDataCallback'",
")",
")",
")",
"{",
"$",
"data",
"[",
"'extra'",
"]",
"[",
"'extraDataCallback'",
"]",
"=",
"call_user_func",
"(",
"Configure",
"::",
"read",
"(",
"'CakeMonitor.Sentry.extraDataCallback'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_ravenClient",
"->",
"captureMessage",
"(",
"$",
"message",
",",
"$",
"params",
",",
"$",
"data",
",",
"$",
"stack",
",",
"$",
"vars",
")",
";",
"}"
] | Capture a message via sentry
@param string $message The message (primary description) for the event.
@param array $params params to use when formatting the message.
@param array $data Additional attributes to pass with this event (see Sentry docs).
@param bool $stack Print stack trace
@param null $vars Variables
@return bool | [
"Capture",
"a",
"message",
"via",
"sentry"
] | train | https://github.com/scherersoftware/cake-monitor/blob/dbe07a1aac41b3db15e631d9e59cf26214bf6938/src/Error/SentryHandler.php#L65-L76 |
nabab/bbn | src/bbn/util/logger.php | logger.report | public function report($st)
{
if ( php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']) ){
if ( \is_string($st) ){
echo $st."\n";
}
else{
print_r($st,1)."\n";
}
}
else{
if ( \is_string($st) ){
array_push($this->reports,$st);
}
else{
array_push($this->reports,print_r($st,true));
}
}
return $this;
} | php | public function report($st)
{
if ( php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']) ){
if ( \is_string($st) ){
echo $st."\n";
}
else{
print_r($st,1)."\n";
}
}
else{
if ( \is_string($st) ){
array_push($this->reports,$st);
}
else{
array_push($this->reports,print_r($st,true));
}
}
return $this;
} | [
"public",
"function",
"report",
"(",
"$",
"st",
")",
"{",
"if",
"(",
"php_sapi_name",
"(",
")",
"==",
"'cli'",
"&&",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"st",
")",
")",
"{",
"echo",
"$",
"st",
".",
"\"\\n\"",
";",
"}",
"else",
"{",
"print_r",
"(",
"$",
"st",
",",
"1",
")",
".",
"\"\\n\"",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"st",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"reports",
",",
"$",
"st",
")",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"this",
"->",
"reports",
",",
"print_r",
"(",
"$",
"st",
",",
"true",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Add information to the $info array
@param string $st
@return null | [
"Add",
"information",
"to",
"the",
"$info",
"array"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/util/logger.php#L28-L47 |
nabab/bbn | src/bbn/util/logger.php | logger.log | public function log($st='',$file='misc')
{
if ( \defined('BBN_DATA_PATH') && is_dir(BBN_DATA_PATH.'logs') ){
$log_file = BBN_DATA_PATH.'logs/'.$file.'.log';
$r = "[".date('d/m/Y H:i:s')."]\t";
if ( empty($st) && \count($this->reports) > 0 ){
$st = implode("\n\n", $this->reports);
$this->reports = [];
}
else{
$i = debug_backtrace()[0];
$r .= $i['file']." - line ".$i['line'];
}
$r .= "\n".( \is_string($st) ? $st : print_r($st, true) )."\n\n";
$s = ( file_exists($log_file) ) ? filesize($log_file) : 0;
if ( $s > 1048576 ){
file_put_contents($log_file.'.old',file_get_contents($log_file),FILE_APPEND);
file_put_contents($log_file,$r);
}
else{
file_put_contents($log_file,$r,FILE_APPEND);
}
}
return $this;
} | php | public function log($st='',$file='misc')
{
if ( \defined('BBN_DATA_PATH') && is_dir(BBN_DATA_PATH.'logs') ){
$log_file = BBN_DATA_PATH.'logs/'.$file.'.log';
$r = "[".date('d/m/Y H:i:s')."]\t";
if ( empty($st) && \count($this->reports) > 0 ){
$st = implode("\n\n", $this->reports);
$this->reports = [];
}
else{
$i = debug_backtrace()[0];
$r .= $i['file']." - line ".$i['line'];
}
$r .= "\n".( \is_string($st) ? $st : print_r($st, true) )."\n\n";
$s = ( file_exists($log_file) ) ? filesize($log_file) : 0;
if ( $s > 1048576 ){
file_put_contents($log_file.'.old',file_get_contents($log_file),FILE_APPEND);
file_put_contents($log_file,$r);
}
else{
file_put_contents($log_file,$r,FILE_APPEND);
}
}
return $this;
} | [
"public",
"function",
"log",
"(",
"$",
"st",
"=",
"''",
",",
"$",
"file",
"=",
"'misc'",
")",
"{",
"if",
"(",
"\\",
"defined",
"(",
"'BBN_DATA_PATH'",
")",
"&&",
"is_dir",
"(",
"BBN_DATA_PATH",
".",
"'logs'",
")",
")",
"{",
"$",
"log_file",
"=",
"BBN_DATA_PATH",
".",
"'logs/'",
".",
"$",
"file",
".",
"'.log'",
";",
"$",
"r",
"=",
"\"[\"",
".",
"date",
"(",
"'d/m/Y H:i:s'",
")",
".",
"\"]\\t\"",
";",
"if",
"(",
"empty",
"(",
"$",
"st",
")",
"&&",
"\\",
"count",
"(",
"$",
"this",
"->",
"reports",
")",
">",
"0",
")",
"{",
"$",
"st",
"=",
"implode",
"(",
"\"\\n\\n\"",
",",
"$",
"this",
"->",
"reports",
")",
";",
"$",
"this",
"->",
"reports",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"i",
"=",
"debug_backtrace",
"(",
")",
"[",
"0",
"]",
";",
"$",
"r",
".=",
"$",
"i",
"[",
"'file'",
"]",
".",
"\" - line \"",
".",
"$",
"i",
"[",
"'line'",
"]",
";",
"}",
"$",
"r",
".=",
"\"\\n\"",
".",
"(",
"\\",
"is_string",
"(",
"$",
"st",
")",
"?",
"$",
"st",
":",
"print_r",
"(",
"$",
"st",
",",
"true",
")",
")",
".",
"\"\\n\\n\"",
";",
"$",
"s",
"=",
"(",
"file_exists",
"(",
"$",
"log_file",
")",
")",
"?",
"filesize",
"(",
"$",
"log_file",
")",
":",
"0",
";",
"if",
"(",
"$",
"s",
">",
"1048576",
")",
"{",
"file_put_contents",
"(",
"$",
"log_file",
".",
"'.old'",
",",
"file_get_contents",
"(",
"$",
"log_file",
")",
",",
"FILE_APPEND",
")",
";",
"file_put_contents",
"(",
"$",
"log_file",
",",
"$",
"r",
")",
";",
"}",
"else",
"{",
"file_put_contents",
"(",
"$",
"log_file",
",",
"$",
"r",
",",
"FILE_APPEND",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Add information to the $info array
@param string $st
@param string $file
@return null | [
"Add",
"information",
"to",
"the",
"$info",
"array"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/util/logger.php#L61-L85 |
oroinc/OroLayoutComponent | Loader/Generator/ConfigLayoutUpdateGenerator.php | ConfigLayoutUpdateGenerator.doGenerateBody | protected function doGenerateBody(GeneratorData $data)
{
$body = [];
$source = $data->getSource();
foreach ($source[self::NODE_ACTIONS] as $actionDefinition) {
$actionName = key($actionDefinition);
$arguments = isset($actionDefinition[$actionName]) && is_array($actionDefinition[$actionName])
? $actionDefinition[$actionName] : [];
$call = [];
$this->normalizeActionName($actionName);
$this->getHelper()->completeArguments($actionName, $arguments);
array_walk(
$arguments,
function (&$arg) {
$arg = var_export($arg, true);
}
);
$call[] = sprintf('$%s->%s(', self::PARAM_LAYOUT_MANIPULATOR, $actionName);
$call[] = implode(', ', $arguments);
$call[] = ');';
$body[] = implode(' ', $call);
}
return implode("\n", $body);
} | php | protected function doGenerateBody(GeneratorData $data)
{
$body = [];
$source = $data->getSource();
foreach ($source[self::NODE_ACTIONS] as $actionDefinition) {
$actionName = key($actionDefinition);
$arguments = isset($actionDefinition[$actionName]) && is_array($actionDefinition[$actionName])
? $actionDefinition[$actionName] : [];
$call = [];
$this->normalizeActionName($actionName);
$this->getHelper()->completeArguments($actionName, $arguments);
array_walk(
$arguments,
function (&$arg) {
$arg = var_export($arg, true);
}
);
$call[] = sprintf('$%s->%s(', self::PARAM_LAYOUT_MANIPULATOR, $actionName);
$call[] = implode(', ', $arguments);
$call[] = ');';
$body[] = implode(' ', $call);
}
return implode("\n", $body);
} | [
"protected",
"function",
"doGenerateBody",
"(",
"GeneratorData",
"$",
"data",
")",
"{",
"$",
"body",
"=",
"[",
"]",
";",
"$",
"source",
"=",
"$",
"data",
"->",
"getSource",
"(",
")",
";",
"foreach",
"(",
"$",
"source",
"[",
"self",
"::",
"NODE_ACTIONS",
"]",
"as",
"$",
"actionDefinition",
")",
"{",
"$",
"actionName",
"=",
"key",
"(",
"$",
"actionDefinition",
")",
";",
"$",
"arguments",
"=",
"isset",
"(",
"$",
"actionDefinition",
"[",
"$",
"actionName",
"]",
")",
"&&",
"is_array",
"(",
"$",
"actionDefinition",
"[",
"$",
"actionName",
"]",
")",
"?",
"$",
"actionDefinition",
"[",
"$",
"actionName",
"]",
":",
"[",
"]",
";",
"$",
"call",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"normalizeActionName",
"(",
"$",
"actionName",
")",
";",
"$",
"this",
"->",
"getHelper",
"(",
")",
"->",
"completeArguments",
"(",
"$",
"actionName",
",",
"$",
"arguments",
")",
";",
"array_walk",
"(",
"$",
"arguments",
",",
"function",
"(",
"&",
"$",
"arg",
")",
"{",
"$",
"arg",
"=",
"var_export",
"(",
"$",
"arg",
",",
"true",
")",
";",
"}",
")",
";",
"$",
"call",
"[",
"]",
"=",
"sprintf",
"(",
"'$%s->%s('",
",",
"self",
"::",
"PARAM_LAYOUT_MANIPULATOR",
",",
"$",
"actionName",
")",
";",
"$",
"call",
"[",
"]",
"=",
"implode",
"(",
"', '",
",",
"$",
"arguments",
")",
";",
"$",
"call",
"[",
"]",
"=",
"');'",
";",
"$",
"body",
"[",
"]",
"=",
"implode",
"(",
"' '",
",",
"$",
"call",
")",
";",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"body",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Loader/Generator/ConfigLayoutUpdateGenerator.php#L32-L60 |
oroinc/OroLayoutComponent | Loader/Generator/ConfigLayoutUpdateGenerator.php | ConfigLayoutUpdateGenerator.validate | protected function validate(GeneratorData $data)
{
$source = $data->getSource();
if (!(is_array($source) && isset($source[self::NODE_ACTIONS]) && is_array($source[self::NODE_ACTIONS]))) {
throw new SyntaxException(sprintf('expected array with "%s" node', self::NODE_ACTIONS), $source);
}
$actions = $source[self::NODE_ACTIONS];
foreach ($actions as $nodeNo => $actionDefinition) {
if (isset($actionDefinition[self::PATH_ATTR])) {
$path = $actionDefinition[self::PATH_ATTR];
unset($actionDefinition[self::PATH_ATTR]);
} else {
$path = self::NODE_ACTIONS . '.' . $nodeNo;
}
if (!is_array($actionDefinition)) {
throw new SyntaxException('expected array with action name as key', $actionDefinition, $path);
}
$actionName = key($actionDefinition);
$arguments = is_array($actionDefinition[$actionName])
? $actionDefinition[$actionName] : [$actionDefinition[$actionName]];
if (strpos($actionName, '@') !== 0) {
throw new SyntaxException(
sprintf('action name should start with "@" symbol, current name "%s"', $actionName),
$actionDefinition,
$path
);
}
$this->normalizeActionName($actionName);
if (!$this->getHelper()->hasMethod($actionName)) {
throw new SyntaxException(
sprintf('unknown action "%s", should be one of LayoutManipulatorInterface\'s methods', $actionName),
$actionDefinition,
$path
);
}
if (!$this->getHelper()->isValidArguments($actionName, $arguments)) {
throw new SyntaxException($this->getHelper()->getLastError(), $actionDefinition, $path);
}
}
} | php | protected function validate(GeneratorData $data)
{
$source = $data->getSource();
if (!(is_array($source) && isset($source[self::NODE_ACTIONS]) && is_array($source[self::NODE_ACTIONS]))) {
throw new SyntaxException(sprintf('expected array with "%s" node', self::NODE_ACTIONS), $source);
}
$actions = $source[self::NODE_ACTIONS];
foreach ($actions as $nodeNo => $actionDefinition) {
if (isset($actionDefinition[self::PATH_ATTR])) {
$path = $actionDefinition[self::PATH_ATTR];
unset($actionDefinition[self::PATH_ATTR]);
} else {
$path = self::NODE_ACTIONS . '.' . $nodeNo;
}
if (!is_array($actionDefinition)) {
throw new SyntaxException('expected array with action name as key', $actionDefinition, $path);
}
$actionName = key($actionDefinition);
$arguments = is_array($actionDefinition[$actionName])
? $actionDefinition[$actionName] : [$actionDefinition[$actionName]];
if (strpos($actionName, '@') !== 0) {
throw new SyntaxException(
sprintf('action name should start with "@" symbol, current name "%s"', $actionName),
$actionDefinition,
$path
);
}
$this->normalizeActionName($actionName);
if (!$this->getHelper()->hasMethod($actionName)) {
throw new SyntaxException(
sprintf('unknown action "%s", should be one of LayoutManipulatorInterface\'s methods', $actionName),
$actionDefinition,
$path
);
}
if (!$this->getHelper()->isValidArguments($actionName, $arguments)) {
throw new SyntaxException($this->getHelper()->getLastError(), $actionDefinition, $path);
}
}
} | [
"protected",
"function",
"validate",
"(",
"GeneratorData",
"$",
"data",
")",
"{",
"$",
"source",
"=",
"$",
"data",
"->",
"getSource",
"(",
")",
";",
"if",
"(",
"!",
"(",
"is_array",
"(",
"$",
"source",
")",
"&&",
"isset",
"(",
"$",
"source",
"[",
"self",
"::",
"NODE_ACTIONS",
"]",
")",
"&&",
"is_array",
"(",
"$",
"source",
"[",
"self",
"::",
"NODE_ACTIONS",
"]",
")",
")",
")",
"{",
"throw",
"new",
"SyntaxException",
"(",
"sprintf",
"(",
"'expected array with \"%s\" node'",
",",
"self",
"::",
"NODE_ACTIONS",
")",
",",
"$",
"source",
")",
";",
"}",
"$",
"actions",
"=",
"$",
"source",
"[",
"self",
"::",
"NODE_ACTIONS",
"]",
";",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"nodeNo",
"=>",
"$",
"actionDefinition",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"actionDefinition",
"[",
"self",
"::",
"PATH_ATTR",
"]",
")",
")",
"{",
"$",
"path",
"=",
"$",
"actionDefinition",
"[",
"self",
"::",
"PATH_ATTR",
"]",
";",
"unset",
"(",
"$",
"actionDefinition",
"[",
"self",
"::",
"PATH_ATTR",
"]",
")",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"self",
"::",
"NODE_ACTIONS",
".",
"'.'",
".",
"$",
"nodeNo",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"actionDefinition",
")",
")",
"{",
"throw",
"new",
"SyntaxException",
"(",
"'expected array with action name as key'",
",",
"$",
"actionDefinition",
",",
"$",
"path",
")",
";",
"}",
"$",
"actionName",
"=",
"key",
"(",
"$",
"actionDefinition",
")",
";",
"$",
"arguments",
"=",
"is_array",
"(",
"$",
"actionDefinition",
"[",
"$",
"actionName",
"]",
")",
"?",
"$",
"actionDefinition",
"[",
"$",
"actionName",
"]",
":",
"[",
"$",
"actionDefinition",
"[",
"$",
"actionName",
"]",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"actionName",
",",
"'@'",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"SyntaxException",
"(",
"sprintf",
"(",
"'action name should start with \"@\" symbol, current name \"%s\"'",
",",
"$",
"actionName",
")",
",",
"$",
"actionDefinition",
",",
"$",
"path",
")",
";",
"}",
"$",
"this",
"->",
"normalizeActionName",
"(",
"$",
"actionName",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"getHelper",
"(",
")",
"->",
"hasMethod",
"(",
"$",
"actionName",
")",
")",
"{",
"throw",
"new",
"SyntaxException",
"(",
"sprintf",
"(",
"'unknown action \"%s\", should be one of LayoutManipulatorInterface\\'s methods'",
",",
"$",
"actionName",
")",
",",
"$",
"actionDefinition",
",",
"$",
"path",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getHelper",
"(",
")",
"->",
"isValidArguments",
"(",
"$",
"actionName",
",",
"$",
"arguments",
")",
")",
"{",
"throw",
"new",
"SyntaxException",
"(",
"$",
"this",
"->",
"getHelper",
"(",
")",
"->",
"getLastError",
"(",
")",
",",
"$",
"actionDefinition",
",",
"$",
"path",
")",
";",
"}",
"}",
"}"
] | Validates given resource data, checks that "actions" node exists and consist valid actions.
{@inheritdoc}
@SuppressWarnings(PHPMD.NPathComplexity) | [
"Validates",
"given",
"resource",
"data",
"checks",
"that",
"actions",
"node",
"exists",
"and",
"consist",
"valid",
"actions",
"."
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Loader/Generator/ConfigLayoutUpdateGenerator.php#L68-L115 |
oroinc/OroLayoutComponent | Loader/Generator/ConfigLayoutUpdateGenerator.php | ConfigLayoutUpdateGenerator.prepare | protected function prepare(GeneratorData $data, VisitorCollection $visitorCollection)
{
foreach ($this->extensions as $extension) {
$extension->prepare($data, $visitorCollection);
}
} | php | protected function prepare(GeneratorData $data, VisitorCollection $visitorCollection)
{
foreach ($this->extensions as $extension) {
$extension->prepare($data, $visitorCollection);
}
} | [
"protected",
"function",
"prepare",
"(",
"GeneratorData",
"$",
"data",
",",
"VisitorCollection",
"$",
"visitorCollection",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"->",
"prepare",
"(",
"$",
"data",
",",
"$",
"visitorCollection",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Loader/Generator/ConfigLayoutUpdateGenerator.php#L120-L125 |
zhouyl/mellivora | Mellivora/Database/Query/Grammars/SQLiteGrammar.php | SQLiteGrammar.dateBasedWhere | protected function dateBasedWhere($type, Builder $query, $where)
{
$value = str_pad($where['value'], 2, '0', STR_PAD_LEFT);
$value = $this->parameter($value);
return "strftime('{$type}', {$this->wrap($where['column'])}) {$where['operator']} {$value}";
} | php | protected function dateBasedWhere($type, Builder $query, $where)
{
$value = str_pad($where['value'], 2, '0', STR_PAD_LEFT);
$value = $this->parameter($value);
return "strftime('{$type}', {$this->wrap($where['column'])}) {$where['operator']} {$value}";
} | [
"protected",
"function",
"dateBasedWhere",
"(",
"$",
"type",
",",
"Builder",
"$",
"query",
",",
"$",
"where",
")",
"{",
"$",
"value",
"=",
"str_pad",
"(",
"$",
"where",
"[",
"'value'",
"]",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"parameter",
"(",
"$",
"value",
")",
";",
"return",
"\"strftime('{$type}', {$this->wrap($where['column'])}) {$where['operator']} {$value}\"",
";",
"}"
] | Compile a date based where clause.
@param string $type
@param \Mellivora\Database\Query\Builder $query
@param array $where
@return string | [
"Compile",
"a",
"date",
"based",
"where",
"clause",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Grammars/SQLiteGrammar.php#L81-L88 |
nabab/bbn | src/bbn/appui/mapper.php | mapper.table_id | public function table_id($table, $db=false){
if ( substr_count($table, ".") === 1 ){
return $table;
}
else {
return ( $db ?: $this->client_db ).'.'.$table;
}
} | php | public function table_id($table, $db=false){
if ( substr_count($table, ".") === 1 ){
return $table;
}
else {
return ( $db ?: $this->client_db ).'.'.$table;
}
} | [
"public",
"function",
"table_id",
"(",
"$",
"table",
",",
"$",
"db",
"=",
"false",
")",
"{",
"if",
"(",
"substr_count",
"(",
"$",
"table",
",",
"\".\"",
")",
"===",
"1",
")",
"{",
"return",
"$",
"table",
";",
"}",
"else",
"{",
"return",
"(",
"$",
"db",
"?",
":",
"$",
"this",
"->",
"client_db",
")",
".",
"'.'",
".",
"$",
"table",
";",
"}",
"}"
] | Returns the ID of a table (db.table)
@param string $table The database table
@param bool|string $db The database
@return string | [
"Returns",
"the",
"ID",
"of",
"a",
"table",
"(",
"db",
".",
"table",
")"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mapper.php#L116-L123 |
nabab/bbn | src/bbn/appui/mapper.php | mapper.col_id | public function col_id($col, $table=false){
if ( substr_count($col, ".") === 2 ){
return $col;
}
else if ( substr_count($col, ".") === 1 ){
if ( $table ){
return $this->table_id($table).'.'.$this->simple_name($col);
}
else{
return $this->simple_name($this->client_db).'.'.$col;
}
}
else if ( $table ){
return $this->table_id($table).'.'.$col;
}
} | php | public function col_id($col, $table=false){
if ( substr_count($col, ".") === 2 ){
return $col;
}
else if ( substr_count($col, ".") === 1 ){
if ( $table ){
return $this->table_id($table).'.'.$this->simple_name($col);
}
else{
return $this->simple_name($this->client_db).'.'.$col;
}
}
else if ( $table ){
return $this->table_id($table).'.'.$col;
}
} | [
"public",
"function",
"col_id",
"(",
"$",
"col",
",",
"$",
"table",
"=",
"false",
")",
"{",
"if",
"(",
"substr_count",
"(",
"$",
"col",
",",
"\".\"",
")",
"===",
"2",
")",
"{",
"return",
"$",
"col",
";",
"}",
"else",
"if",
"(",
"substr_count",
"(",
"$",
"col",
",",
"\".\"",
")",
"===",
"1",
")",
"{",
"if",
"(",
"$",
"table",
")",
"{",
"return",
"$",
"this",
"->",
"table_id",
"(",
"$",
"table",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"simple_name",
"(",
"$",
"col",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"simple_name",
"(",
"$",
"this",
"->",
"client_db",
")",
".",
"'.'",
".",
"$",
"col",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"table",
")",
"{",
"return",
"$",
"this",
"->",
"table_id",
"(",
"$",
"table",
")",
".",
"'.'",
".",
"$",
"col",
";",
"}",
"}"
] | Returns the ID of a column (db.table.column)
@param string $col The table's column (can include the table)
@param type $table The table
@return string | [
"Returns",
"the",
"ID",
"of",
"a",
"column",
"(",
"db",
".",
"table",
".",
"column",
")"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/appui/mapper.php#L132-L148 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.