repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.verify_email | private function verify_email() {
$this->_handle_account_user_sync();
if ( $this->_user->is_verified() ) {
return;
}
$api = $this->get_api_site_scope();
$result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
'after_email_confirm_url' => $this->_get_admin_page_url(
'account',
array( 'fs_action' => 'sync_user' )
)
) );
if ( ! isset( $result->error ) ) {
$this->_admin_notices->add( sprintf(
$this->get_text_inline( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'verification-email-sent-message' ),
sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
) );
} else {
// handle different error cases.
}
} | php | private function verify_email() {
$this->_handle_account_user_sync();
if ( $this->_user->is_verified() ) {
return;
}
$api = $this->get_api_site_scope();
$result = $api->call( "/users/{$this->_user->id}/verify.json", 'put', array(
'after_email_confirm_url' => $this->_get_admin_page_url(
'account',
array( 'fs_action' => 'sync_user' )
)
) );
if ( ! isset( $result->error ) ) {
$this->_admin_notices->add( sprintf(
$this->get_text_inline( 'Verification mail was just sent to %s. If you can\'t find it after 5 min, please check your spam box.', 'verification-email-sent-message' ),
sprintf( '<a href="mailto:%1s">%2s</a>', esc_url( $this->_user->email ), $this->_user->email )
) );
} else {
// handle different error cases.
}
} | [
"private",
"function",
"verify_email",
"(",
")",
"{",
"$",
"this",
"->",
"_handle_account_user_sync",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_user",
"->",
"is_verified",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"api",
"=",
"$",
"this",
"->... | Verify user email.
@author Vova Feldman (@svovaf)
@since 1.0.3
@uses FS_Api | [
"Verify",
"user",
"email",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L18646-L18670 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.get_after_activation_url | function get_after_activation_url( $filter, $params = array(), $network = null ) {
if ( $this->is_free_wp_org_theme() &&
( fs_request_has( 'pending_activation' ) ||
// For cases when the first time path is set, even though it's a WP.org theme.
fs_request_get_bool( $this->get_unique_affix() . '_show_optin' ) )
) {
$first_time_path = '';
} else {
$first_time_path = $this->_menu->get_first_time_path();
}
if ( $this->_is_network_active &&
fs_is_network_admin() &&
! $this->_menu->has_network_menu() &&
$this->is_network_registered()
) {
$target_url = $this->get_account_url();
} else {
// Default plugin's page.
$target_url = $this->_get_admin_page_url( '', array(), $network );
}
return add_query_arg( $params, $this->apply_filters(
$filter,
empty( $first_time_path ) ?
$target_url :
$first_time_path
) );
} | php | function get_after_activation_url( $filter, $params = array(), $network = null ) {
if ( $this->is_free_wp_org_theme() &&
( fs_request_has( 'pending_activation' ) ||
// For cases when the first time path is set, even though it's a WP.org theme.
fs_request_get_bool( $this->get_unique_affix() . '_show_optin' ) )
) {
$first_time_path = '';
} else {
$first_time_path = $this->_menu->get_first_time_path();
}
if ( $this->_is_network_active &&
fs_is_network_admin() &&
! $this->_menu->has_network_menu() &&
$this->is_network_registered()
) {
$target_url = $this->get_account_url();
} else {
// Default plugin's page.
$target_url = $this->_get_admin_page_url( '', array(), $network );
}
return add_query_arg( $params, $this->apply_filters(
$filter,
empty( $first_time_path ) ?
$target_url :
$first_time_path
) );
} | [
"function",
"get_after_activation_url",
"(",
"$",
"filter",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"network",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_free_wp_org_theme",
"(",
")",
"&&",
"(",
"fs_request_has",
"(",
"'pendin... | Get the URL of the page that should be loaded after the user connect
or skip in the opt-in screen.
@author Vova Feldman (@svovaf)
@since 1.1.3
@param string $filter Filter name.
@param array $params Since 1.2.2.7
@param bool|null $network
@return string | [
"Get",
"the",
"URL",
"of",
"the",
"page",
"that",
"should",
"be",
"loaded",
"after",
"the",
"user",
"connect",
"or",
"skip",
"in",
"the",
"opt",
"-",
"in",
"screen",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L18721-L18749 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._account_page_load | function _account_page_load() {
$this->_logger->entrance();
$this->_logger->info( var_export( $_REQUEST, true ) );
fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
if ( $this->has_addons() ) {
wp_enqueue_script( 'plugin-install' );
add_thickbox();
function fs_addons_body_class( $classes ) {
$classes .= ' plugins-php';
return $classes;
}
add_filter( 'admin_body_class', 'fs_addons_body_class' );
}
if ( $this->has_paid_plan() &&
! $this->has_any_license() &&
! $this->is_sync_executed() &&
$this->is_tracking_allowed()
) {
/**
* If no licenses found and no sync job was executed during the last 24 hours,
* just execute the sync job right away (blocking execution).
*
* @since 1.1.7.3
*/
$this->run_manual_sync();
}
$this->_handle_account_edits();
$this->do_action( 'account_page_load_before_departure' );
} | php | function _account_page_load() {
$this->_logger->entrance();
$this->_logger->info( var_export( $_REQUEST, true ) );
fs_enqueue_local_style( 'fs_account', '/admin/account.css' );
if ( $this->has_addons() ) {
wp_enqueue_script( 'plugin-install' );
add_thickbox();
function fs_addons_body_class( $classes ) {
$classes .= ' plugins-php';
return $classes;
}
add_filter( 'admin_body_class', 'fs_addons_body_class' );
}
if ( $this->has_paid_plan() &&
! $this->has_any_license() &&
! $this->is_sync_executed() &&
$this->is_tracking_allowed()
) {
/**
* If no licenses found and no sync job was executed during the last 24 hours,
* just execute the sync job right away (blocking execution).
*
* @since 1.1.7.3
*/
$this->run_manual_sync();
}
$this->_handle_account_edits();
$this->do_action( 'account_page_load_before_departure' );
} | [
"function",
"_account_page_load",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"this",
"->",
"_logger",
"->",
"info",
"(",
"var_export",
"(",
"$",
"_REQUEST",
",",
"true",
")",
")",
";",
"fs_enqueue_local_style",
"("... | Account page resources load.
@author Vova Feldman (@svovaf)
@since 1.0.6 | [
"Account",
"page",
"resources",
"load",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19097-L19134 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._affiliation_page_render | function _affiliation_page_render() {
$this->_logger->entrance();
$this->fetch_affiliate_and_terms();
fs_enqueue_local_style( 'fs_affiliation', '/admin/affiliation.css' );
$vars = array( 'id' => $this->_module_id );
echo $this->apply_filters( "/forms/affiliation.php", fs_get_template( '/forms/affiliation.php', $vars ) );
} | php | function _affiliation_page_render() {
$this->_logger->entrance();
$this->fetch_affiliate_and_terms();
fs_enqueue_local_style( 'fs_affiliation', '/admin/affiliation.css' );
$vars = array( 'id' => $this->_module_id );
echo $this->apply_filters( "/forms/affiliation.php", fs_get_template( '/forms/affiliation.php', $vars ) );
} | [
"function",
"_affiliation_page_render",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"this",
"->",
"fetch_affiliate_and_terms",
"(",
")",
";",
"fs_enqueue_local_style",
"(",
"'fs_affiliation'",
",",
"'/admin/affiliation.css'",
... | Renders the "Affiliation" page.
@author Leo Fajardo (@leorw)
@since 1.2.3 | [
"Renders",
"the",
"Affiliation",
"page",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19142-L19151 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._account_page_render | function _account_page_render() {
$this->_logger->entrance();
$template = 'account.php';
$vars = array( 'id' => $this->_module_id );
/**
* Added filter to the template to allow developers wrapping the template
* in custom HTML (e.g. within a wizard/tabs).
*
* @author Vova Feldman (@svovaf)
* @since 1.2.1.6
*/
echo $this->apply_filters( "templates/{$template}", fs_get_template( $template, $vars ) );
} | php | function _account_page_render() {
$this->_logger->entrance();
$template = 'account.php';
$vars = array( 'id' => $this->_module_id );
/**
* Added filter to the template to allow developers wrapping the template
* in custom HTML (e.g. within a wizard/tabs).
*
* @author Vova Feldman (@svovaf)
* @since 1.2.1.6
*/
echo $this->apply_filters( "templates/{$template}", fs_get_template( $template, $vars ) );
} | [
"function",
"_account_page_render",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"template",
"=",
"'account.php'",
";",
"$",
"vars",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"_module_id",
")",
";",
"/**\... | Render account page.
@author Vova Feldman (@svovaf)
@since 1.0.0 | [
"Render",
"account",
"page",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19160-L19174 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._connect_page_render | function _connect_page_render() {
$this->_logger->entrance();
$vars = array( 'id' => $this->_module_id );
/**
* Added filter to the template to allow developers wrapping the template
* in custom HTML (e.g. within a wizard/tabs).
*
* @author Vova Feldman (@svovaf)
* @since 1.2.1.6
*/
echo $this->apply_filters( 'templates/connect.php', fs_get_template( 'connect.php', $vars ) );
} | php | function _connect_page_render() {
$this->_logger->entrance();
$vars = array( 'id' => $this->_module_id );
/**
* Added filter to the template to allow developers wrapping the template
* in custom HTML (e.g. within a wizard/tabs).
*
* @author Vova Feldman (@svovaf)
* @since 1.2.1.6
*/
echo $this->apply_filters( 'templates/connect.php', fs_get_template( 'connect.php', $vars ) );
} | [
"function",
"_connect_page_render",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"vars",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"_module_id",
")",
";",
"/**\r\n * Added filter to the template to allo... | Render account connect page.
@author Vova Feldman (@svovaf)
@since 1.0.7 | [
"Render",
"account",
"connect",
"page",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19182-L19195 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._addons_page_load | function _addons_page_load() {
$this->_logger->entrance();
fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
wp_enqueue_script( 'plugin-install' );
add_thickbox();
function fs_addons_body_class( $classes ) {
$classes .= ' plugins-php';
return $classes;
}
add_filter( 'admin_body_class', 'fs_addons_body_class' );
if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
$this->_admin_notices->add(
sprintf( $this->get_text_inline( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'addons-info-external-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
$this->get_text_x_inline( 'Heads up', 'advance notice of something that will need attention.', 'heads-up' ),
'update-nag'
);
}
} | php | function _addons_page_load() {
$this->_logger->entrance();
fs_enqueue_local_style( 'fs_addons', '/admin/add-ons.css' );
wp_enqueue_script( 'plugin-install' );
add_thickbox();
function fs_addons_body_class( $classes ) {
$classes .= ' plugins-php';
return $classes;
}
add_filter( 'admin_body_class', 'fs_addons_body_class' );
if ( ! $this->is_registered() && $this->is_org_repo_compliant() ) {
$this->_admin_notices->add(
sprintf( $this->get_text_inline( 'Just letting you know that the add-ons information of %s is being pulled from an external server.', 'addons-info-external-message' ), '<b>' . $this->get_plugin_name() . '</b>' ),
$this->get_text_x_inline( 'Heads up', 'advance notice of something that will need attention.', 'heads-up' ),
'update-nag'
);
}
} | [
"function",
"_addons_page_load",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"fs_enqueue_local_style",
"(",
"'fs_addons'",
",",
"'/admin/add-ons.css'",
")",
";",
"wp_enqueue_script",
"(",
"'plugin-install'",
")",
";",
"add_thickbo... | Load required resources before add-ons page render.
@author Vova Feldman (@svovaf)
@since 1.0.6 | [
"Load",
"required",
"resources",
"before",
"add",
"-",
"ons",
"page",
"render",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19203-L19226 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._addons_page_render | function _addons_page_render() {
$this->_logger->entrance();
$vars = array( 'id' => $this->_module_id );
/**
* Added filter to the template to allow developers wrapping the template
* in custom HTML (e.g. within a wizard/tabs).
*
* @author Vova Feldman (@svovaf)
* @since 1.2.1.6
*/
echo $this->apply_filters( 'templates/add-ons.php', fs_get_template( 'add-ons.php', $vars ) );
} | php | function _addons_page_render() {
$this->_logger->entrance();
$vars = array( 'id' => $this->_module_id );
/**
* Added filter to the template to allow developers wrapping the template
* in custom HTML (e.g. within a wizard/tabs).
*
* @author Vova Feldman (@svovaf)
* @since 1.2.1.6
*/
echo $this->apply_filters( 'templates/add-ons.php', fs_get_template( 'add-ons.php', $vars ) );
} | [
"function",
"_addons_page_render",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"vars",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"_module_id",
")",
";",
"/**\r\n * Added filter to the template to allow... | Render add-ons page.
@author Vova Feldman (@svovaf)
@since 1.0.6 | [
"Render",
"add",
"-",
"ons",
"page",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19234-L19247 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._pricing_page_render | function _pricing_page_render() {
$this->_logger->entrance();
$vars = array( 'id' => $this->_module_id );
if ( 'true' === fs_request_get( 'checkout', false ) ) {
echo $this->apply_filters( 'templates/checkout.php', fs_get_template( 'checkout.php', $vars ) );
} else {
echo $this->apply_filters( 'templates/pricing.php', fs_get_template( 'pricing.php', $vars ) );
}
} | php | function _pricing_page_render() {
$this->_logger->entrance();
$vars = array( 'id' => $this->_module_id );
if ( 'true' === fs_request_get( 'checkout', false ) ) {
echo $this->apply_filters( 'templates/checkout.php', fs_get_template( 'checkout.php', $vars ) );
} else {
echo $this->apply_filters( 'templates/pricing.php', fs_get_template( 'pricing.php', $vars ) );
}
} | [
"function",
"_pricing_page_render",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"vars",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"_module_id",
")",
";",
"if",
"(",
"'true'",
"===",
"fs_request_get",
"("... | Render pricing page.
@author Vova Feldman (@svovaf)
@since 1.0.0 | [
"Render",
"pricing",
"page",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19257-L19267 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._contact_page_render | function _contact_page_render() {
$this->_logger->entrance();
$vars = array( 'id' => $this->_module_id );
/**
* Added filter to the template to allow developers wrapping the template
* in custom HTML (e.g. within a wizard/tabs).
*
* @author Vova Feldman (@svovaf)
* @since 2.1.3
*/
echo $this->apply_filters( 'templates/contact.php', fs_get_template( 'contact.php', $vars ) );
} | php | function _contact_page_render() {
$this->_logger->entrance();
$vars = array( 'id' => $this->_module_id );
/**
* Added filter to the template to allow developers wrapping the template
* in custom HTML (e.g. within a wizard/tabs).
*
* @author Vova Feldman (@svovaf)
* @since 2.1.3
*/
echo $this->apply_filters( 'templates/contact.php', fs_get_template( 'contact.php', $vars ) );
} | [
"function",
"_contact_page_render",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"vars",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"_module_id",
")",
";",
"/**\r\n * Added filter to the template to allo... | Render contact-us page.
@author Vova Feldman (@svovaf)
@since 1.0.3 | [
"Render",
"contact",
"-",
"us",
"page",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19279-L19292 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.get_api_plugin_scope | function get_api_plugin_scope() {
if ( ! isset( $this->_plugin_api ) ) {
$this->_plugin_api = FS_Api::instance(
$this->_module_id,
'plugin',
$this->_plugin->id,
$this->_plugin->public_key,
! $this->is_live()
);
}
return $this->_plugin_api;
} | php | function get_api_plugin_scope() {
if ( ! isset( $this->_plugin_api ) ) {
$this->_plugin_api = FS_Api::instance(
$this->_module_id,
'plugin',
$this->_plugin->id,
$this->_plugin->public_key,
! $this->is_live()
);
}
return $this->_plugin_api;
} | [
"function",
"get_api_plugin_scope",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_plugin_api",
")",
")",
"{",
"$",
"this",
"->",
"_plugin_api",
"=",
"FS_Api",
"::",
"instance",
"(",
"$",
"this",
"->",
"_module_id",
",",
"'plugin'",
... | Get plugin public API scope.
@author Vova Feldman (@svovaf)
@since 1.0.7
@return FS_Api | [
"Get",
"plugin",
"public",
"API",
"scope",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19444-L19456 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.hook_plugin_action_links | private function hook_plugin_action_links() {
$this->_logger->entrance();
$this->_action_links_hooked = true;
$this->_logger->log( 'Adding action links hooks.' );
// Add action link to settings page.
add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
&$this,
'_modify_plugin_action_links_hook'
), WP_FS__DEFAULT_PRIORITY, 2 );
add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
&$this,
'_modify_plugin_action_links_hook'
), WP_FS__DEFAULT_PRIORITY, 2 );
} | php | private function hook_plugin_action_links() {
$this->_logger->entrance();
$this->_action_links_hooked = true;
$this->_logger->log( 'Adding action links hooks.' );
// Add action link to settings page.
add_filter( 'plugin_action_links_' . $this->_plugin_basename, array(
&$this,
'_modify_plugin_action_links_hook'
), WP_FS__DEFAULT_PRIORITY, 2 );
add_filter( 'network_admin_plugin_action_links_' . $this->_plugin_basename, array(
&$this,
'_modify_plugin_action_links_hook'
), WP_FS__DEFAULT_PRIORITY, 2 );
} | [
"private",
"function",
"hook_plugin_action_links",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"this",
"->",
"_action_links_hooked",
"=",
"true",
";",
"$",
"this",
"->",
"_logger",
"->",
"log",
"(",
"'Adding action link... | Hook to plugin action links filter.
@author Vova Feldman (@svovaf)
@since 1.0.0 | [
"Hook",
"to",
"plugin",
"action",
"links",
"filter",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19810-L19826 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.add_plugin_action_link | function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
$this->_logger->entrance();
if ( ! isset( $this->_action_links[ $priority ] ) ) {
$this->_action_links[ $priority ] = array();
}
if ( false === $key ) {
$key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
}
$this->_action_links[ $priority ][] = array(
'label' => $label,
'href' => $url,
'key' => $key,
'external' => $external
);
} | php | function add_plugin_action_link( $label, $url, $external = false, $priority = WP_FS__DEFAULT_PRIORITY, $key = false ) {
$this->_logger->entrance();
if ( ! isset( $this->_action_links[ $priority ] ) ) {
$this->_action_links[ $priority ] = array();
}
if ( false === $key ) {
$key = preg_replace( "/[^A-Za-z0-9 ]/", '', strtolower( $label ) );
}
$this->_action_links[ $priority ][] = array(
'label' => $label,
'href' => $url,
'key' => $key,
'external' => $external
);
} | [
"function",
"add_plugin_action_link",
"(",
"$",
"label",
",",
"$",
"url",
",",
"$",
"external",
"=",
"false",
",",
"$",
"priority",
"=",
"WP_FS__DEFAULT_PRIORITY",
",",
"$",
"key",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"... | Add plugin action link.
@author Vova Feldman (@svovaf)
@since 1.0.0
@param $label
@param $url
@param bool $external
@param int $priority
@param bool $key | [
"Add",
"plugin",
"action",
"link",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19840-L19857 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._add_upgrade_action_link | function _add_upgrade_action_link() {
$this->_logger->entrance();
if ( ! $this->is_paying() && $this->has_paid_plan() ) {
$this->add_plugin_action_link(
$this->get_text_inline( 'Upgrade', 'upgrade' ),
$this->get_upgrade_url(),
false,
7,
'upgrade'
);
}
if ( $this->has_addons() ) {
$this->add_plugin_action_link(
$this->get_text_inline( 'Add-Ons', 'add-ons' ),
$this->_get_admin_page_url( 'addons' ),
false,
9,
'addons'
);
}
} | php | function _add_upgrade_action_link() {
$this->_logger->entrance();
if ( ! $this->is_paying() && $this->has_paid_plan() ) {
$this->add_plugin_action_link(
$this->get_text_inline( 'Upgrade', 'upgrade' ),
$this->get_upgrade_url(),
false,
7,
'upgrade'
);
}
if ( $this->has_addons() ) {
$this->add_plugin_action_link(
$this->get_text_inline( 'Add-Ons', 'add-ons' ),
$this->_get_admin_page_url( 'addons' ),
false,
9,
'addons'
);
}
} | [
"function",
"_add_upgrade_action_link",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_paying",
"(",
")",
"&&",
"$",
"this",
"->",
"has_paid_plan",
"(",
")",
")",
"{",
"$",
"this",... | Adds Upgrade and Add-Ons links to the main Plugins page link actions collection.
@author Vova Feldman (@svovaf)
@since 1.0.0 | [
"Adds",
"Upgrade",
"and",
"Add",
"-",
"Ons",
"links",
"to",
"the",
"main",
"Plugins",
"page",
"link",
"actions",
"collection",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19865-L19887 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._add_license_action_link | function _add_license_action_link() {
$this->_logger->entrance();
if ( ! self::is_ajax() ) {
// Inject license activation dialog UI and client side code.
add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
}
$link_text = $this->is_free_plan() ?
$this->get_text_inline( 'Activate License', 'activate-license' ) :
$this->get_text_inline( 'Change License', 'change-license' );
$this->add_plugin_action_link(
$link_text,
'#',
false,
11,
( 'activate-license ' . $this->get_unique_affix() )
);
} | php | function _add_license_action_link() {
$this->_logger->entrance();
if ( ! self::is_ajax() ) {
// Inject license activation dialog UI and client side code.
add_action( 'admin_footer', array( &$this, '_add_license_activation_dialog_box' ) );
}
$link_text = $this->is_free_plan() ?
$this->get_text_inline( 'Activate License', 'activate-license' ) :
$this->get_text_inline( 'Change License', 'change-license' );
$this->add_plugin_action_link(
$link_text,
'#',
false,
11,
( 'activate-license ' . $this->get_unique_affix() )
);
} | [
"function",
"_add_license_action_link",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"if",
"(",
"!",
"self",
"::",
"is_ajax",
"(",
")",
")",
"{",
"// Inject license activation dialog UI and client side code.\r",
"add_action",
"(",
... | Adds "Activate License" or "Change License" link to the main Plugins page link actions collection.
@author Leo Fajardo (@leorw)
@since 1.1.9 | [
"Adds",
"Activate",
"License",
"or",
"Change",
"License",
"link",
"to",
"the",
"main",
"Plugins",
"page",
"link",
"actions",
"collection",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19895-L19914 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._add_tracking_links | function _add_tracking_links() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$this->_logger->entrance();
/**
* If the activation has been delegated to site admins, no tracking-related actions for now.
*
* @author Leo Fajardo (@leorw)
*/
if ( $this->_is_network_active && $this->is_network_delegated_connection() ) {
return;
}
if ( fs_request_is_action_secure( $this->get_unique_affix() . '_reconnect' ) ) {
if ( ! $this->is_registered() && $this->is_anonymous() ) {
$this->connect_again();
return;
}
}
if ( ( $this->is_plugin() && ! self::is_plugins_page() ) ||
( $this->is_theme() && ! self::is_themes_page() )
) {
// Only show tracking links on the plugins and themes pages.
return;
}
if ( ! $this->is_enable_anonymous() ) {
// Don't allow to opt-out if anonymous mode is disabled.
return;
}
if ( ! $this->is_free_plan() ) {
// Don't allow to opt-out if running in paid plan.
return;
}
if ( $this->add_ajax_action( 'stop_tracking', array( &$this, '_stop_tracking_callback' ) ) ) {
return;
}
if ( $this->add_ajax_action( 'allow_tracking', array( &$this, '_allow_tracking_callback' ) ) ) {
return;
}
$url = '#';
if ( $this->is_registered() ) {
if ( $this->is_tracking_allowed() ) {
$link_text_id = $this->get_text_inline( 'Opt Out', 'opt-out' );
} else {
$link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
}
add_action( 'admin_footer', array( &$this, '_add_optout_dialog' ) );
} else {
$link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
$params = ! $this->is_anonymous() ?
array() :
array(
'nonce' => wp_create_nonce( $this->get_unique_affix() . '_reconnect' ),
'fs_action' => ( $this->get_unique_affix() . '_reconnect' ),
);
$url = $this->get_activation_url( $params );
}
if ( $this->is_plugin() && self::is_plugins_page() ) {
$this->add_plugin_action_link(
$link_text_id,
$url,
false,
13,
"opt-in-or-opt-out {$this->_slug}"
);
}
} | php | function _add_tracking_links() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$this->_logger->entrance();
/**
* If the activation has been delegated to site admins, no tracking-related actions for now.
*
* @author Leo Fajardo (@leorw)
*/
if ( $this->_is_network_active && $this->is_network_delegated_connection() ) {
return;
}
if ( fs_request_is_action_secure( $this->get_unique_affix() . '_reconnect' ) ) {
if ( ! $this->is_registered() && $this->is_anonymous() ) {
$this->connect_again();
return;
}
}
if ( ( $this->is_plugin() && ! self::is_plugins_page() ) ||
( $this->is_theme() && ! self::is_themes_page() )
) {
// Only show tracking links on the plugins and themes pages.
return;
}
if ( ! $this->is_enable_anonymous() ) {
// Don't allow to opt-out if anonymous mode is disabled.
return;
}
if ( ! $this->is_free_plan() ) {
// Don't allow to opt-out if running in paid plan.
return;
}
if ( $this->add_ajax_action( 'stop_tracking', array( &$this, '_stop_tracking_callback' ) ) ) {
return;
}
if ( $this->add_ajax_action( 'allow_tracking', array( &$this, '_allow_tracking_callback' ) ) ) {
return;
}
$url = '#';
if ( $this->is_registered() ) {
if ( $this->is_tracking_allowed() ) {
$link_text_id = $this->get_text_inline( 'Opt Out', 'opt-out' );
} else {
$link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
}
add_action( 'admin_footer', array( &$this, '_add_optout_dialog' ) );
} else {
$link_text_id = $this->get_text_inline( 'Opt In', 'opt-in' );
$params = ! $this->is_anonymous() ?
array() :
array(
'nonce' => wp_create_nonce( $this->get_unique_affix() . '_reconnect' ),
'fs_action' => ( $this->get_unique_affix() . '_reconnect' ),
);
$url = $this->get_activation_url( $params );
}
if ( $this->is_plugin() && self::is_plugins_page() ) {
$this->add_plugin_action_link(
$link_text_id,
$url,
false,
13,
"opt-in-or-opt-out {$this->_slug}"
);
}
} | [
"function",
"_add_tracking_links",
"(",
")",
"{",
"if",
"(",
"!",
"current_user_can",
"(",
"'manage_options'",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"/**\r\n * If the activation has been deleg... | Adds "Opt in" or "Opt out" link to the main "Plugins" page link actions collection.
@author Leo Fajardo (@leorw)
@since 1.2.1.5 | [
"Adds",
"Opt",
"in",
"or",
"Opt",
"out",
"link",
"to",
"the",
"main",
"Plugins",
"page",
"link",
"actions",
"collection",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L19934-L20015 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.get_after_plugin_activation_redirect_url | function get_after_plugin_activation_redirect_url() {
$url = false;
if ( ! $this->is_addon() || ! $this->has_free_plan() ) {
$first_time_path = $this->_menu->get_first_time_path();
if ( $this->is_activation_mode() ) {
$url = $this->get_activation_url();
} else if ( ! empty( $first_time_path ) ) {
$url = $first_time_path;
} else {
$page = '';
if ( ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
if ( $this->is_network_registered() ) {
$page = 'account';
} else if ( $this->is_network_anonymous() ) {
$this->maybe_set_slug_and_network_menu_exists_flag();
}
}
$url = $this->_get_admin_page_url( $page );
}
} else {
$plugin_fs = false;
if ( $this->is_parent_plugin_installed() ) {
$plugin_fs = self::get_parent_instance();
}
if ( is_object( $plugin_fs ) ) {
if ( ! $plugin_fs->is_registered() ) {
// Forward to parent plugin connect when parent not registered.
$url = $plugin_fs->get_activation_url();
} else {
// Forward to account page.
$url = $plugin_fs->_get_admin_page_url( 'account' );
}
}
}
return $url;
} | php | function get_after_plugin_activation_redirect_url() {
$url = false;
if ( ! $this->is_addon() || ! $this->has_free_plan() ) {
$first_time_path = $this->_menu->get_first_time_path();
if ( $this->is_activation_mode() ) {
$url = $this->get_activation_url();
} else if ( ! empty( $first_time_path ) ) {
$url = $first_time_path;
} else {
$page = '';
if ( ! empty( $this->_dynamically_added_top_level_page_hook_name ) ) {
if ( $this->is_network_registered() ) {
$page = 'account';
} else if ( $this->is_network_anonymous() ) {
$this->maybe_set_slug_and_network_menu_exists_flag();
}
}
$url = $this->_get_admin_page_url( $page );
}
} else {
$plugin_fs = false;
if ( $this->is_parent_plugin_installed() ) {
$plugin_fs = self::get_parent_instance();
}
if ( is_object( $plugin_fs ) ) {
if ( ! $plugin_fs->is_registered() ) {
// Forward to parent plugin connect when parent not registered.
$url = $plugin_fs->get_activation_url();
} else {
// Forward to account page.
$url = $plugin_fs->_get_admin_page_url( 'account' );
}
}
}
return $url;
} | [
"function",
"get_after_plugin_activation_redirect_url",
"(",
")",
"{",
"$",
"url",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_addon",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"has_free_plan",
"(",
")",
")",
"{",
"$",
"first_time_path",
"=",... | Get the URL of the page that should be loaded right after the plugin activation.
@author Vova Feldman (@svovaf)
@since 1.1.7.4
@return string | [
"Get",
"the",
"URL",
"of",
"the",
"page",
"that",
"should",
"be",
"loaded",
"right",
"after",
"the",
"plugin",
"activation",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20025-L20066 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._modify_plugin_action_links_hook | function _modify_plugin_action_links_hook( $links, $file ) {
$this->_logger->entrance();
$passed_deactivate = false;
$deactivate_link = '';
$before_deactivate = array();
$after_deactivate = array();
foreach ( $links as $key => $link ) {
if ( 'deactivate' === $key ) {
$deactivate_link = $link;
$passed_deactivate = true;
continue;
}
if ( ! $passed_deactivate ) {
$before_deactivate[ $key ] = $link;
} else {
$after_deactivate[ $key ] = $link;
}
}
ksort( $this->_action_links );
foreach ( $this->_action_links as $new_links ) {
foreach ( $new_links as $link ) {
$before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
}
}
if ( ! empty( $deactivate_link ) ) {
/**
* This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
*
* @since 1.2.1.6 Always show the deactivation feedback form since we added automatic free version deactivation upon premium code activation.
*/
$deactivate_link .= '<i class="fs-module-id" data-module-id="' . $this->_module_id . '"></i>';
// Append deactivation link.
$before_deactivate['deactivate'] = $deactivate_link;
}
return array_merge( $before_deactivate, $after_deactivate );
} | php | function _modify_plugin_action_links_hook( $links, $file ) {
$this->_logger->entrance();
$passed_deactivate = false;
$deactivate_link = '';
$before_deactivate = array();
$after_deactivate = array();
foreach ( $links as $key => $link ) {
if ( 'deactivate' === $key ) {
$deactivate_link = $link;
$passed_deactivate = true;
continue;
}
if ( ! $passed_deactivate ) {
$before_deactivate[ $key ] = $link;
} else {
$after_deactivate[ $key ] = $link;
}
}
ksort( $this->_action_links );
foreach ( $this->_action_links as $new_links ) {
foreach ( $new_links as $link ) {
$before_deactivate[ $link['key'] ] = '<a href="' . $link['href'] . '"' . ( $link['external'] ? ' target="_blank"' : '' ) . '>' . $link['label'] . '</a>';
}
}
if ( ! empty( $deactivate_link ) ) {
/**
* This HTML element is used to identify the correct plugin when attaching an event to its Deactivate link.
*
* @since 1.2.1.6 Always show the deactivation feedback form since we added automatic free version deactivation upon premium code activation.
*/
$deactivate_link .= '<i class="fs-module-id" data-module-id="' . $this->_module_id . '"></i>';
// Append deactivation link.
$before_deactivate['deactivate'] = $deactivate_link;
}
return array_merge( $before_deactivate, $after_deactivate );
} | [
"function",
"_modify_plugin_action_links_hook",
"(",
"$",
"links",
",",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"passed_deactivate",
"=",
"false",
";",
"$",
"deactivate_link",
"=",
"''",
";",
"$",
"before_... | Modify plugin's page action links collection.
@author Vova Feldman (@svovaf)
@since 1.0.0
@param array $links
@param $file
@return array | [
"Modify",
"plugin",
"s",
"page",
"action",
"links",
"collection",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20093-L20135 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.add_admin_message | function add_admin_message( $message, $title = '', $type = 'success' ) {
$this->_admin_notices->add( $message, $title, $type );
} | php | function add_admin_message( $message, $title = '', $type = 'success' ) {
$this->_admin_notices->add( $message, $title, $type );
} | [
"function",
"add_admin_message",
"(",
"$",
"message",
",",
"$",
"title",
"=",
"''",
",",
"$",
"type",
"=",
"'success'",
")",
"{",
"$",
"this",
"->",
"_admin_notices",
"->",
"add",
"(",
"$",
"message",
",",
"$",
"title",
",",
"$",
"type",
")",
";",
... | Adds admin message.
@author Vova Feldman (@svovaf)
@since 1.0.4
@param string $message
@param string $title
@param string $type | [
"Adds",
"admin",
"message",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20147-L20149 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.add_sticky_admin_message | function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
$this->_admin_notices->add_sticky( $message, $id, $title, $type );
} | php | function add_sticky_admin_message( $message, $id, $title = '', $type = 'success' ) {
$this->_admin_notices->add_sticky( $message, $id, $title, $type );
} | [
"function",
"add_sticky_admin_message",
"(",
"$",
"message",
",",
"$",
"id",
",",
"$",
"title",
"=",
"''",
",",
"$",
"type",
"=",
"'success'",
")",
"{",
"$",
"this",
"->",
"_admin_notices",
"->",
"add_sticky",
"(",
"$",
"message",
",",
"$",
"id",
",",
... | Adds sticky admin message.
@author Vova Feldman (@svovaf)
@since 1.1.0
@param string $message
@param string $id
@param string $title
@param string $type | [
"Adds",
"sticky",
"admin",
"message",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20162-L20164 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.is_premium_version_installed | private function is_premium_version_installed() {
$premium_plugin_basename = $this->premium_plugin_basename();
$premium_plugin = get_plugins( '/' . dirname( $premium_plugin_basename ) );
return ! empty( $premium_plugin );
} | php | private function is_premium_version_installed() {
$premium_plugin_basename = $this->premium_plugin_basename();
$premium_plugin = get_plugins( '/' . dirname( $premium_plugin_basename ) );
return ! empty( $premium_plugin );
} | [
"private",
"function",
"is_premium_version_installed",
"(",
")",
"{",
"$",
"premium_plugin_basename",
"=",
"$",
"this",
"->",
"premium_plugin_basename",
"(",
")",
";",
"$",
"premium_plugin",
"=",
"get_plugins",
"(",
"'/'",
".",
"dirname",
"(",
"$",
"premium_plugin... | Check if the paid version of the module is installed.
@author Vova Feldman (@svovaf)
@since 2.2.0
@return bool | [
"Check",
"if",
"the",
"paid",
"version",
"of",
"the",
"module",
"is",
"installed",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20174-L20179 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.get_complete_upgrade_instructions | private function get_complete_upgrade_instructions( $plan_title = '' ) {
$this->_logger->entrance();
$activate_license_string = $this->get_license_network_activation_notice();
if ( ! $this->has_premium_version() || $this->is_premium() ) {
return '' . $activate_license_string;
}
if ( empty( $plan_title ) ) {
$plan_title = $this->get_plan_title();
}
if ( $this->is_premium_version_installed() ) {
/**
* If the premium version is already installed, instead of showing the installation instructions,
* tell the current user to activate it.
*
* @author Leo Fajardo (@leorw)
* @since 2.2.1
*/
$premium_plugin_basename = $this->premium_plugin_basename();
return sprintf(
/* translators: %1s: Product title; %2s: Plan title */
$this->get_text_inline( ' The paid version of %1s is already installed. Please activate it to start benefiting the %2s features. %3s', 'activate-premium-version' ),
sprintf( '<em>%s</em>', esc_html( $this->get_plugin_title() ) ),
$plan_title,
sprintf(
'<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s</button></a>',
wp_nonce_url( 'plugins.php?action=activate&plugin=' . $premium_plugin_basename, 'activate-plugin_' . $premium_plugin_basename ),
esc_html( sprintf(
/* translators: %s: Plan title */
$this->get_text_inline( 'Activate %s features', 'activate-x-features' ),
$plan_title
) )
)
);
} else {
// @since 1.2.1.5 The free version is auto deactivated.
$deactivation_step = version_compare( $this->version, '1.2.1.5', '<' ) ?
( '<li>' . $this->esc_html_inline( 'Deactivate the free version', 'deactivate-free-version' ) . '.</li>' ) :
'';
return sprintf(
' %s: <ol><li>%s.</li>%s<li>%s (<a href="%s" target="_blank">%s</a>).</li></ol>',
$this->get_text_inline( 'Please follow these steps to complete the upgrade', 'follow-steps-to-complete-upgrade' ),
( empty( $activate_license_string ) ? '' : $activate_license_string . '</li><li>' ) .
$this->get_latest_download_link( sprintf(
/* translators: %s: Plan title */
$this->get_text_inline( 'Download the latest %s version', 'download-latest-x-version' ),
$plan_title
) ),
$deactivation_step,
$this->get_text_inline( 'Upload and activate the downloaded version', 'upload-and-activate' ),
'//bit.ly/upload-wp-' . $this->_module_type . 's',
$this->get_text_inline( 'How to upload and activate?', 'howto-upload-activate' )
);
}
} | php | private function get_complete_upgrade_instructions( $plan_title = '' ) {
$this->_logger->entrance();
$activate_license_string = $this->get_license_network_activation_notice();
if ( ! $this->has_premium_version() || $this->is_premium() ) {
return '' . $activate_license_string;
}
if ( empty( $plan_title ) ) {
$plan_title = $this->get_plan_title();
}
if ( $this->is_premium_version_installed() ) {
/**
* If the premium version is already installed, instead of showing the installation instructions,
* tell the current user to activate it.
*
* @author Leo Fajardo (@leorw)
* @since 2.2.1
*/
$premium_plugin_basename = $this->premium_plugin_basename();
return sprintf(
/* translators: %1s: Product title; %2s: Plan title */
$this->get_text_inline( ' The paid version of %1s is already installed. Please activate it to start benefiting the %2s features. %3s', 'activate-premium-version' ),
sprintf( '<em>%s</em>', esc_html( $this->get_plugin_title() ) ),
$plan_title,
sprintf(
'<a style="margin-left: 10px;" href="%s"><button class="button button-primary">%s</button></a>',
wp_nonce_url( 'plugins.php?action=activate&plugin=' . $premium_plugin_basename, 'activate-plugin_' . $premium_plugin_basename ),
esc_html( sprintf(
/* translators: %s: Plan title */
$this->get_text_inline( 'Activate %s features', 'activate-x-features' ),
$plan_title
) )
)
);
} else {
// @since 1.2.1.5 The free version is auto deactivated.
$deactivation_step = version_compare( $this->version, '1.2.1.5', '<' ) ?
( '<li>' . $this->esc_html_inline( 'Deactivate the free version', 'deactivate-free-version' ) . '.</li>' ) :
'';
return sprintf(
' %s: <ol><li>%s.</li>%s<li>%s (<a href="%s" target="_blank">%s</a>).</li></ol>',
$this->get_text_inline( 'Please follow these steps to complete the upgrade', 'follow-steps-to-complete-upgrade' ),
( empty( $activate_license_string ) ? '' : $activate_license_string . '</li><li>' ) .
$this->get_latest_download_link( sprintf(
/* translators: %s: Plan title */
$this->get_text_inline( 'Download the latest %s version', 'download-latest-x-version' ),
$plan_title
) ),
$deactivation_step,
$this->get_text_inline( 'Upload and activate the downloaded version', 'upload-and-activate' ),
'//bit.ly/upload-wp-' . $this->_module_type . 's',
$this->get_text_inline( 'How to upload and activate?', 'howto-upload-activate' )
);
}
} | [
"private",
"function",
"get_complete_upgrade_instructions",
"(",
"$",
"plan_title",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"activate_license_string",
"=",
"$",
"this",
"->",
"get_license_network_activation_notice",
... | Helper function that returns the final steps for the upgrade completion.
If the module is already running the premium code, returns an empty string.
@author Vova Feldman (@svovaf)
@since 1.2.1
@param string $plan_title
@return string | [
"Helper",
"function",
"that",
"returns",
"the",
"final",
"steps",
"for",
"the",
"upgrade",
"completion",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20193-L20252 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.is_permission_requested | function is_permission_requested( $permission ) {
return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
} | php | function is_permission_requested( $permission ) {
return isset( $this->_permissions[ $permission ] ) && ( true === $this->_permissions[ $permission ] );
} | [
"function",
"is_permission_requested",
"(",
"$",
"permission",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_permissions",
"[",
"$",
"permission",
"]",
")",
"&&",
"(",
"true",
"===",
"$",
"this",
"->",
"_permissions",
"[",
"$",
"permission",
"]",
... | Check if specific permission requested.
@author Vova Feldman (@svovaf)
@since 1.1.6
@param string $permission
@return bool | [
"Check",
"if",
"specific",
"permission",
"requested",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20509-L20511 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._install_premium_version_ajax_action | function _install_premium_version_ajax_action() {
$this->_logger->entrance();
$this->check_ajax_referer( 'install_premium_version' );
if ( ! $this->is_registered() ) {
// Not registered.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Auto installation only works for opted-in users.', 'auto-install-error-not-opted-in' ),
'code' => 'premium_installed',
) );
}
$plugin_id = fs_request_get( 'target_module_id', $this->get_id() );
if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
// Invalid ID.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
'code' => 'invalid_module_id',
) );
}
if ( $plugin_id == $this->get_id() ) {
if ( $this->is_premium() ) {
// Already using the premium code version.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Premium version already active.', 'auto-install-error-premium-activated' ),
'code' => 'premium_installed',
) );
}
if ( ! $this->can_use_premium_code() ) {
// Don't have access to the premium code.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'You do not have a valid license to access the premium version.', 'auto-install-error-invalid-license' ),
'code' => 'invalid_license',
) );
}
if ( ! $this->has_release_on_freemius() ) {
// Plugin is a serviceware, no premium code version.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Plugin is a "Serviceware" which means it does not have a premium code version.', 'auto-install-error-serviceware' ),
'code' => 'premium_version_missing',
) );
}
} else {
$addon = $this->get_addon( $plugin_id );
if ( ! is_object( $addon ) ) {
// Invalid add-on ID.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
'code' => 'invalid_module_id',
) );
}
if ( $this->is_addon_activated( $plugin_id, true ) ) {
// Premium add-on version is already activated.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Premium add-on version already installed.', 'auto-install-error-premium-addon-activated' ),
'code' => 'premium_installed',
) );
}
}
$this->_isAutoInstall = true;
// Try to install and activate.
$updater = FS_Plugin_Updater::instance( $this );
$result = $updater->install_and_activate_plugin( $plugin_id );
if ( is_array( $result ) && ! empty( $result['message'] ) ) {
self::shoot_ajax_failure( array(
'message' => $result['message'],
'code' => $result['code'],
) );
}
self::shoot_ajax_success( $result );
} | php | function _install_premium_version_ajax_action() {
$this->_logger->entrance();
$this->check_ajax_referer( 'install_premium_version' );
if ( ! $this->is_registered() ) {
// Not registered.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Auto installation only works for opted-in users.', 'auto-install-error-not-opted-in' ),
'code' => 'premium_installed',
) );
}
$plugin_id = fs_request_get( 'target_module_id', $this->get_id() );
if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
// Invalid ID.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
'code' => 'invalid_module_id',
) );
}
if ( $plugin_id == $this->get_id() ) {
if ( $this->is_premium() ) {
// Already using the premium code version.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Premium version already active.', 'auto-install-error-premium-activated' ),
'code' => 'premium_installed',
) );
}
if ( ! $this->can_use_premium_code() ) {
// Don't have access to the premium code.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'You do not have a valid license to access the premium version.', 'auto-install-error-invalid-license' ),
'code' => 'invalid_license',
) );
}
if ( ! $this->has_release_on_freemius() ) {
// Plugin is a serviceware, no premium code version.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Plugin is a "Serviceware" which means it does not have a premium code version.', 'auto-install-error-serviceware' ),
'code' => 'premium_version_missing',
) );
}
} else {
$addon = $this->get_addon( $plugin_id );
if ( ! is_object( $addon ) ) {
// Invalid add-on ID.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Invalid module ID.', 'auto-install-error-invalid-id' ),
'code' => 'invalid_module_id',
) );
}
if ( $this->is_addon_activated( $plugin_id, true ) ) {
// Premium add-on version is already activated.
self::shoot_ajax_failure( array(
'message' => $this->get_text_inline( 'Premium add-on version already installed.', 'auto-install-error-premium-addon-activated' ),
'code' => 'premium_installed',
) );
}
}
$this->_isAutoInstall = true;
// Try to install and activate.
$updater = FS_Plugin_Updater::instance( $this );
$result = $updater->install_and_activate_plugin( $plugin_id );
if ( is_array( $result ) && ! empty( $result['message'] ) ) {
self::shoot_ajax_failure( array(
'message' => $result['message'],
'code' => $result['code'],
) );
}
self::shoot_ajax_success( $result );
} | [
"function",
"_install_premium_version_ajax_action",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"$",
"this",
"->",
"check_ajax_referer",
"(",
"'install_premium_version'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_regist... | After upgrade callback to install and auto activate a plugin.
This code will only be executed on explicit request from the user,
following the practice Jetpack are using with their theme installations.
@link https://make.wordpress.org/plugins/2017/03/16/clarification-of-guideline-8-executable-code-and-installs/
@author Vova Feldman (@svovaf)
@since 1.2.1.7 | [
"After",
"upgrade",
"callback",
"to",
"install",
"and",
"auto",
"activate",
"a",
"plugin",
".",
"This",
"code",
"will",
"only",
"be",
"executed",
"on",
"explicit",
"request",
"from",
"the",
"user",
"following",
"the",
"practice",
"Jetpack",
"are",
"using",
"... | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20536-L20615 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._add_auto_installation_dialog_box | function _add_auto_installation_dialog_box() {
$this->_logger->entrance();
if ( ! $this->is_registered() ) {
// Not registered.
return;
}
$plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
// Invalid module ID.
return;
}
if ( $plugin_id == $this->get_id() ) {
if ( $this->is_premium() ) {
// Already using the premium code version.
return;
}
if ( ! $this->can_use_premium_code() ) {
// Don't have access to the premium code.
return;
}
if ( ! $this->has_release_on_freemius() ) {
// Plugin is a serviceware, no premium code version.
return;
}
} else {
$addon = $this->get_addon( $plugin_id );
if ( ! is_object( $addon ) ) {
// Invalid add-on ID.
return;
}
if ( $this->is_addon_activated( $plugin_id, true ) ) {
// Premium add-on version is already activated.
return;
}
}
$vars = array(
'id' => $this->_module_id,
'target_module_id' => $plugin_id,
'slug' => $this->_slug,
);
fs_require_template( 'auto-installation.php', $vars );
} | php | function _add_auto_installation_dialog_box() {
$this->_logger->entrance();
if ( ! $this->is_registered() ) {
// Not registered.
return;
}
$plugin_id = fs_request_get( 'plugin_id', $this->get_id() );
if ( ! FS_Plugin::is_valid_id( $plugin_id ) ) {
// Invalid module ID.
return;
}
if ( $plugin_id == $this->get_id() ) {
if ( $this->is_premium() ) {
// Already using the premium code version.
return;
}
if ( ! $this->can_use_premium_code() ) {
// Don't have access to the premium code.
return;
}
if ( ! $this->has_release_on_freemius() ) {
// Plugin is a serviceware, no premium code version.
return;
}
} else {
$addon = $this->get_addon( $plugin_id );
if ( ! is_object( $addon ) ) {
// Invalid add-on ID.
return;
}
if ( $this->is_addon_activated( $plugin_id, true ) ) {
// Premium add-on version is already activated.
return;
}
}
$vars = array(
'id' => $this->_module_id,
'target_module_id' => $plugin_id,
'slug' => $this->_slug,
);
fs_require_template( 'auto-installation.php', $vars );
} | [
"function",
"_add_auto_installation_dialog_box",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_registered",
"(",
")",
")",
"{",
"// Not registered.\r",
"return",
";",
"}",
"$",
"plugin_... | Displays module activation dialog box after a successful upgrade
where the user explicitly requested to auto download and install
the premium version.
@author Vova Feldman (@svovaf)
@since 1.2.1.7 | [
"Displays",
"module",
"activation",
"dialog",
"box",
"after",
"a",
"successful",
"upgrade",
"where",
"the",
"user",
"explicitly",
"requested",
"to",
"auto",
"download",
"and",
"install",
"the",
"premium",
"version",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20625-L20674 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._tabs_capture | function _tabs_capture() {
$this->_logger->entrance();
if ( ! $this->is_theme_settings_page() ||
! $this->is_matching_url( $this->main_menu_url() )
) {
return;
}
$params = array(
'id' => $this->_module_id,
);
fs_require_once_template( 'tabs-capture-js.php', $params );
} | php | function _tabs_capture() {
$this->_logger->entrance();
if ( ! $this->is_theme_settings_page() ||
! $this->is_matching_url( $this->main_menu_url() )
) {
return;
}
$params = array(
'id' => $this->_module_id,
);
fs_require_once_template( 'tabs-capture-js.php', $params );
} | [
"function",
"_tabs_capture",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_theme_settings_page",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"is_matching_url",
"(",
"$",
"this",
"->",
... | Inject a JavaScript logic to capture the theme tabs HTML.
@author Vova Feldman (@svovaf)
@since 1.2.2.7 | [
"Inject",
"a",
"JavaScript",
"logic",
"to",
"capture",
"the",
"theme",
"tabs",
"HTML",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20690-L20704 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.should_page_include_tabs | private function should_page_include_tabs() {
if ( ! $this->has_settings_menu() ) {
// Don't add tabs if no settings at all.
return false;
}
if ( ! $this->is_theme() ) {
// Only add tabs to themes for now.
return false;
}
if ( ! $this->has_paid_plan() && ! $this->has_addons() ) {
// Only add tabs to monetizing themes.
return false;
}
if ( ! $this->is_theme_settings_page() ) {
// Only add tabs if browsing one of the theme's setting pages.
return false;
}
if ( $this->is_admin_page( 'pricing' ) && fs_request_get_bool( 'checkout' ) ) {
// Don't add tabs on checkout page, we want to reduce distractions
// as much as possible.
return false;
}
return true;
} | php | private function should_page_include_tabs() {
if ( ! $this->has_settings_menu() ) {
// Don't add tabs if no settings at all.
return false;
}
if ( ! $this->is_theme() ) {
// Only add tabs to themes for now.
return false;
}
if ( ! $this->has_paid_plan() && ! $this->has_addons() ) {
// Only add tabs to monetizing themes.
return false;
}
if ( ! $this->is_theme_settings_page() ) {
// Only add tabs if browsing one of the theme's setting pages.
return false;
}
if ( $this->is_admin_page( 'pricing' ) && fs_request_get_bool( 'checkout' ) ) {
// Don't add tabs on checkout page, we want to reduce distractions
// as much as possible.
return false;
}
return true;
} | [
"private",
"function",
"should_page_include_tabs",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has_settings_menu",
"(",
")",
")",
"{",
"// Don't add tabs if no settings at all.\r",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"is_them... | Check if page should include tabs.
@author Vova Feldman (@svovaf)
@since 1.2.2.7
@return bool | [
"Check",
"if",
"page",
"should",
"include",
"tabs",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20816-L20844 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._add_tabs_before_content | function _add_tabs_before_content() {
$this->_logger->entrance();
if ( ! $this->should_page_include_tabs() ) {
return false;
}
/**
* Enqueue the original stylesheets that are included in the
* theme settings page. That way, if the theme settings has
* some custom _styled_ content above the tabs UI, this
* will make sure that the styling is preserved.
*/
$stylesheets = $this->_cache->get( 'tabs_stylesheets', array() );
if ( is_array( $stylesheets ) ) {
for ( $i = 0, $len = count( $stylesheets ); $i < $len; $i ++ ) {
wp_enqueue_style( "fs_{$this->_module_id}_tabs_{$i}", $stylesheets[ $i ] );
}
}
// Cut closing </div> tag.
echo substr( trim( $this->get_tabs_html() ), 0, - 6 );
return true;
} | php | function _add_tabs_before_content() {
$this->_logger->entrance();
if ( ! $this->should_page_include_tabs() ) {
return false;
}
/**
* Enqueue the original stylesheets that are included in the
* theme settings page. That way, if the theme settings has
* some custom _styled_ content above the tabs UI, this
* will make sure that the styling is preserved.
*/
$stylesheets = $this->_cache->get( 'tabs_stylesheets', array() );
if ( is_array( $stylesheets ) ) {
for ( $i = 0, $len = count( $stylesheets ); $i < $len; $i ++ ) {
wp_enqueue_style( "fs_{$this->_module_id}_tabs_{$i}", $stylesheets[ $i ] );
}
}
// Cut closing </div> tag.
echo substr( trim( $this->get_tabs_html() ), 0, - 6 );
return true;
} | [
"function",
"_add_tabs_before_content",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"should_page_include_tabs",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"/**\r\n * Enque... | Add the tabs HTML before the setting's page content and
enqueue any required stylesheets.
@author Vova Feldman (@svovaf)
@since 1.2.2.7
@return bool If tabs were included. | [
"Add",
"the",
"tabs",
"HTML",
"before",
"the",
"setting",
"s",
"page",
"content",
"and",
"enqueue",
"any",
"required",
"stylesheets",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20855-L20879 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius._add_freemius_tabs | function _add_freemius_tabs() {
$this->_logger->entrance();
if ( ! $this->should_page_include_tabs() ) {
return;
}
$params = array( 'id' => $this->_module_id );
fs_require_once_template( 'tabs.php', $params );
} | php | function _add_freemius_tabs() {
$this->_logger->entrance();
if ( ! $this->should_page_include_tabs() ) {
return;
}
$params = array( 'id' => $this->_module_id );
fs_require_once_template( 'tabs.php', $params );
} | [
"function",
"_add_freemius_tabs",
"(",
")",
"{",
"$",
"this",
"->",
"_logger",
"->",
"entrance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"should_page_include_tabs",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"params",
"=",
"array",
"(",
"... | Add in-page JavaScript to inject the Freemius tabs into
the module's setting tabs section.
@author Vova Feldman (@svovaf)
@since 1.2.2.7 | [
"Add",
"in",
"-",
"page",
"JavaScript",
"to",
"inject",
"the",
"Freemius",
"tabs",
"into",
"the",
"module",
"s",
"setting",
"tabs",
"section",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L20910-L20919 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.fetch_remote_icon_url | function fetch_remote_icon_url() {
$info = $this->fetch_module_info();
return ( $this->is_api_result_object( $info, 'icon' ) && is_string( $info->icon ) ) ?
$info->icon :
'';
} | php | function fetch_remote_icon_url() {
$info = $this->fetch_module_info();
return ( $this->is_api_result_object( $info, 'icon' ) && is_string( $info->icon ) ) ?
$info->icon :
'';
} | [
"function",
"fetch_remote_icon_url",
"(",
")",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"fetch_module_info",
"(",
")",
";",
"return",
"(",
"$",
"this",
"->",
"is_api_result_object",
"(",
"$",
"info",
",",
"'icon'",
")",
"&&",
"is_string",
"(",
"$",
"inf... | Fetch module's remote icon URL.
@author Vova Feldman (@svovaf)
@since 2.0.0
@return string | [
"Fetch",
"module",
"s",
"remote",
"icon",
"URL",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L21175-L21181 | train |
Freemius/wordpress-sdk | includes/class-freemius.php | Freemius.fetch_user_marketing_flag_status_by_plugins | private function fetch_user_marketing_flag_status_by_plugins( $user_email, $license_key, $plugin_ids ) {
$request = array(
'method' => 'POST',
'body' => array(),
'timeout' => WP_FS__DEBUG_SDK ? 60 : 30,
);
if ( is_string( $user_email ) ) {
$request['body']['email'] = $user_email;
} else {
$request['body']['license_key'] = $license_key;
}
$result = array();
$url = WP_FS__ADDRESS . '/action/service/user_plugin/';
$total_plugin_ids = count( $plugin_ids );
$plugin_ids_count_per_request = 10;
for ( $i = 1; $i <= $total_plugin_ids; $i += $plugin_ids_count_per_request ) {
$plugin_ids_set = array_slice( $plugin_ids, $i - 1, $plugin_ids_count_per_request );
$request['body']['plugin_ids'] = $plugin_ids_set;
$response = self::safe_remote_post(
$url,
$request,
WP_FS__TIME_24_HOURS_IN_SEC,
WP_FS__TIME_12_HOURS_IN_SEC
);
if ( ! is_wp_error( $response ) ) {
$decoded = is_string( $response['body'] ) ?
json_decode( $response['body'] ) :
null;
if (
!is_object($decoded) ||
!isset($decoded->success) ||
true !== $decoded->success ||
!isset( $decoded->data ) ||
!is_array( $decoded->data )
) {
return false;
}
$result = array_merge( $result, $decoded->data );
}
}
return $result;
} | php | private function fetch_user_marketing_flag_status_by_plugins( $user_email, $license_key, $plugin_ids ) {
$request = array(
'method' => 'POST',
'body' => array(),
'timeout' => WP_FS__DEBUG_SDK ? 60 : 30,
);
if ( is_string( $user_email ) ) {
$request['body']['email'] = $user_email;
} else {
$request['body']['license_key'] = $license_key;
}
$result = array();
$url = WP_FS__ADDRESS . '/action/service/user_plugin/';
$total_plugin_ids = count( $plugin_ids );
$plugin_ids_count_per_request = 10;
for ( $i = 1; $i <= $total_plugin_ids; $i += $plugin_ids_count_per_request ) {
$plugin_ids_set = array_slice( $plugin_ids, $i - 1, $plugin_ids_count_per_request );
$request['body']['plugin_ids'] = $plugin_ids_set;
$response = self::safe_remote_post(
$url,
$request,
WP_FS__TIME_24_HOURS_IN_SEC,
WP_FS__TIME_12_HOURS_IN_SEC
);
if ( ! is_wp_error( $response ) ) {
$decoded = is_string( $response['body'] ) ?
json_decode( $response['body'] ) :
null;
if (
!is_object($decoded) ||
!isset($decoded->success) ||
true !== $decoded->success ||
!isset( $decoded->data ) ||
!is_array( $decoded->data )
) {
return false;
}
$result = array_merge( $result, $decoded->data );
}
}
return $result;
} | [
"private",
"function",
"fetch_user_marketing_flag_status_by_plugins",
"(",
"$",
"user_email",
",",
"$",
"license_key",
",",
"$",
"plugin_ids",
")",
"{",
"$",
"request",
"=",
"array",
"(",
"'method'",
"=>",
"'POST'",
",",
"'body'",
"=>",
"array",
"(",
")",
",",... | This method is called for opted-in users to fetch the is_marketing_allowed flag of the user for all the
plugins and themes they've opted in to.
@author Leo Fajardo (@leorw)
@since 2.1.0
@param string $user_email
@param string $license_key
@param array $plugin_ids
@param string|null $license_key
@return array|false | [
"This",
"method",
"is",
"called",
"for",
"opted",
"-",
"in",
"users",
"to",
"fetch",
"the",
"is_marketing_allowed",
"flag",
"of",
"the",
"user",
"for",
"all",
"the",
"plugins",
"and",
"themes",
"they",
"ve",
"opted",
"in",
"to",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-freemius.php#L21343-L21394 | train |
Freemius/wordpress-sdk | includes/class-fs-logger.php | FS_Logger.init | private static function init() {
self::$_ownerName = function_exists( 'get_current_user' ) ?
get_current_user() :
'unknown';
self::$_isStorageLoggingOn = ( 1 == get_option( 'fs_storage_logger', 0 ) );
self::$_abspathLength = strlen( ABSPATH );
self::$_processID = mt_rand( 0, 32000 );
// Process ID may be `false` on errors.
if ( ! is_numeric( self::$_processID ) ) {
self::$_processID = 0;
}
} | php | private static function init() {
self::$_ownerName = function_exists( 'get_current_user' ) ?
get_current_user() :
'unknown';
self::$_isStorageLoggingOn = ( 1 == get_option( 'fs_storage_logger', 0 ) );
self::$_abspathLength = strlen( ABSPATH );
self::$_processID = mt_rand( 0, 32000 );
// Process ID may be `false` on errors.
if ( ! is_numeric( self::$_processID ) ) {
self::$_processID = 0;
}
} | [
"private",
"static",
"function",
"init",
"(",
")",
"{",
"self",
"::",
"$",
"_ownerName",
"=",
"function_exists",
"(",
"'get_current_user'",
")",
"?",
"get_current_user",
"(",
")",
":",
"'unknown'",
";",
"self",
"::",
"$",
"_isStorageLoggingOn",
"=",
"(",
"1"... | Initialize logging global info.
@author Vova Feldman (@svovaf)
@since 1.2.1.6 | [
"Initialize",
"logging",
"global",
"info",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-logger.php#L87-L99 | train |
Freemius/wordpress-sdk | includes/class-fs-logger.php | FS_Logger.api_error | function api_error( $api_result, $wrapper = false ) {
$message = '';
if ( is_object( $api_result ) &&
! empty( $api_result->error ) &&
! empty( $api_result->error->message )
) {
$message = $api_result->error->message;
} else if ( is_object( $api_result ) ) {
$message = var_export( $api_result, true );
} else if ( is_string( $api_result ) ) {
$message = $api_result;
} else if ( empty( $api_result ) ) {
$message = 'Empty API result.';
}
$message = 'API Error: ' . $message;
$this->_log( $message, 'error', $wrapper );
} | php | function api_error( $api_result, $wrapper = false ) {
$message = '';
if ( is_object( $api_result ) &&
! empty( $api_result->error ) &&
! empty( $api_result->error->message )
) {
$message = $api_result->error->message;
} else if ( is_object( $api_result ) ) {
$message = var_export( $api_result, true );
} else if ( is_string( $api_result ) ) {
$message = $api_result;
} else if ( empty( $api_result ) ) {
$message = 'Empty API result.';
}
$message = 'API Error: ' . $message;
$this->_log( $message, 'error', $wrapper );
} | [
"function",
"api_error",
"(",
"$",
"api_result",
",",
"$",
"wrapper",
"=",
"false",
")",
"{",
"$",
"message",
"=",
"''",
";",
"if",
"(",
"is_object",
"(",
"$",
"api_result",
")",
"&&",
"!",
"empty",
"(",
"$",
"api_result",
"->",
"error",
")",
"&&",
... | Log API error.
@author Vova Feldman (@svovaf)
@since 1.2.1.5
@param mixed $api_result
@param bool $wrapper | [
"Log",
"API",
"error",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-logger.php#L221-L239 | train |
Freemius/wordpress-sdk | includes/fs-plugin-info-dialog.php | FS_Plugin_Info_Dialog.get_cta | private function get_cta(
$label,
$is_primary = true,
$is_disabled = false,
$href = '',
$target = '_blank'
) {
$classes = array();
if ( ! $is_primary ) {
$classes[] = 'left';
} else {
$classes[] = 'button-primary';
$classes[] = 'right';
}
if ( $is_disabled ) {
$classes[] = 'disabled';
}
return sprintf(
'<a %s class="button %s">%s</a>',
empty( $href ) ? '' : 'href="' . $href . '" target="' . $target . '"',
implode( ' ', $classes ),
$label
);
} | php | private function get_cta(
$label,
$is_primary = true,
$is_disabled = false,
$href = '',
$target = '_blank'
) {
$classes = array();
if ( ! $is_primary ) {
$classes[] = 'left';
} else {
$classes[] = 'button-primary';
$classes[] = 'right';
}
if ( $is_disabled ) {
$classes[] = 'disabled';
}
return sprintf(
'<a %s class="button %s">%s</a>',
empty( $href ) ? '' : 'href="' . $href . '" target="' . $target . '"',
implode( ' ', $classes ),
$label
);
} | [
"private",
"function",
"get_cta",
"(",
"$",
"label",
",",
"$",
"is_primary",
"=",
"true",
",",
"$",
"is_disabled",
"=",
"false",
",",
"$",
"href",
"=",
"''",
",",
"$",
"target",
"=",
"'_blank'",
")",
"{",
"$",
"classes",
"=",
"array",
"(",
")",
";"... | Helper method to get a CTA button HTML.
@author Vova Feldman (@svovaf)
@since 2.0.0
@param string $label
@param bool $is_primary
@param bool $is_disabled
@param string $href
@param string $target
@return string | [
"Helper",
"method",
"to",
"get",
"a",
"CTA",
"button",
"HTML",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/fs-plugin-info-dialog.php#L482-L508 | train |
Freemius/wordpress-sdk | includes/entities/class-fs-pricing.php | FS_Pricing.is_multi_cycle | function is_multi_cycle() {
$cycles = 0;
if ( $this->has_monthly() ) {
$cycles ++;
}
if ( $this->has_annual() ) {
$cycles ++;
}
if ( $this->has_lifetime() ) {
$cycles ++;
}
return $cycles > 1;
} | php | function is_multi_cycle() {
$cycles = 0;
if ( $this->has_monthly() ) {
$cycles ++;
}
if ( $this->has_annual() ) {
$cycles ++;
}
if ( $this->has_lifetime() ) {
$cycles ++;
}
return $cycles > 1;
} | [
"function",
"is_multi_cycle",
"(",
")",
"{",
"$",
"cycles",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"has_monthly",
"(",
")",
")",
"{",
"$",
"cycles",
"++",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"has_annual",
"(",
")",
")",
"{",
"$",
"cyc... | Check if pricing has more than one billing cycle.
@author Vova Feldman (@svovaf)
@since 1.1.8
@return bool | [
"Check",
"if",
"pricing",
"has",
"more",
"than",
"one",
"billing",
"cycle",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/entities/class-fs-pricing.php#L102-L115 | train |
Freemius/wordpress-sdk | includes/entities/class-fs-pricing.php | FS_Pricing.annual_discount_percentage | function annual_discount_percentage() {
return floor( $this->annual_savings() / ( $this->monthly_price * 12 * ( $this->is_unlimited() ? 1 : $this->licenses ) ) * 100 );
} | php | function annual_discount_percentage() {
return floor( $this->annual_savings() / ( $this->monthly_price * 12 * ( $this->is_unlimited() ? 1 : $this->licenses ) ) * 100 );
} | [
"function",
"annual_discount_percentage",
"(",
")",
"{",
"return",
"floor",
"(",
"$",
"this",
"->",
"annual_savings",
"(",
")",
"/",
"(",
"$",
"this",
"->",
"monthly_price",
"*",
"12",
"*",
"(",
"$",
"this",
"->",
"is_unlimited",
"(",
")",
"?",
"1",
":... | Get annual over monthly discount.
@author Vova Feldman (@svovaf)
@since 1.1.8
@return int | [
"Get",
"annual",
"over",
"monthly",
"discount",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/entities/class-fs-pricing.php#L125-L127 | train |
Freemius/wordpress-sdk | includes/class-fs-user-lock.php | FS_User_Lock.try_lock | function try_lock( $expiration = 0 ) {
if ( $this->is_locked() ) {
// Already locked.
return false;
}
set_site_transient( "locked_{$this->_wp_user_id}", $this->_thread_id, $expiration );
if ( $this->has_lock() ) {
set_site_transient( "locked_{$this->_wp_user_id}", true, $expiration );
return true;
}
return false;
} | php | function try_lock( $expiration = 0 ) {
if ( $this->is_locked() ) {
// Already locked.
return false;
}
set_site_transient( "locked_{$this->_wp_user_id}", $this->_thread_id, $expiration );
if ( $this->has_lock() ) {
set_site_transient( "locked_{$this->_wp_user_id}", true, $expiration );
return true;
}
return false;
} | [
"function",
"try_lock",
"(",
"$",
"expiration",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_locked",
"(",
")",
")",
"{",
"// Already locked.",
"return",
"false",
";",
"}",
"set_site_transient",
"(",
"\"locked_{$this->_wp_user_id}\"",
",",
"$",
"thi... | Try to acquire lock. If the lock is already set or is being acquired by another locker, don't do anything.
@author Vova Feldman (@svovaf)
@since 2.1.0
@param int $expiration
@return bool TRUE if successfully acquired lock. | [
"Try",
"to",
"acquire",
"lock",
".",
"If",
"the",
"lock",
"is",
"already",
"set",
"or",
"is",
"being",
"acquired",
"by",
"another",
"locker",
"don",
"t",
"do",
"anything",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-user-lock.php#L67-L82 | train |
Freemius/wordpress-sdk | includes/class-fs-options.php | FS_Options.set_site_blog_context | function set_site_blog_context( $blog_id ) {
$this->_blog_id = $blog_id;
$this->_options = FS_Option_Manager::get_manager( $this->_id, false, $this->_blog_id );
} | php | function set_site_blog_context( $blog_id ) {
$this->_blog_id = $blog_id;
$this->_options = FS_Option_Manager::get_manager( $this->_id, false, $this->_blog_id );
} | [
"function",
"set_site_blog_context",
"(",
"$",
"blog_id",
")",
"{",
"$",
"this",
"->",
"_blog_id",
"=",
"$",
"blog_id",
";",
"$",
"this",
"->",
"_options",
"=",
"FS_Option_Manager",
"::",
"get_manager",
"(",
"$",
"this",
"->",
"_id",
",",
"false",
",",
"... | Switch the context of the site level options manager.
@author Vova Feldman (@svovaf)
@since 2.0.0
@param $blog_id | [
"Switch",
"the",
"context",
"of",
"the",
"site",
"level",
"options",
"manager",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-options.php#L101-L105 | train |
Freemius/wordpress-sdk | includes/class-fs-options.php | FS_Options.should_use_network_storage | private function should_use_network_storage( $option, $network_level_or_blog_id = null ) {
if ( ! $this->_is_multisite ) {
// Not a multisite environment.
return false;
}
if ( is_numeric( $network_level_or_blog_id ) ) {
// Explicitly asked to use a specified blog storage.
return false;
}
if ( is_bool( $network_level_or_blog_id ) ) {
// Explicitly specified whether should use the network or blog level storage.
return $network_level_or_blog_id;
}
// Determine which storage to use based on the option.
return ! $this->is_site_option( $option );
} | php | private function should_use_network_storage( $option, $network_level_or_blog_id = null ) {
if ( ! $this->_is_multisite ) {
// Not a multisite environment.
return false;
}
if ( is_numeric( $network_level_or_blog_id ) ) {
// Explicitly asked to use a specified blog storage.
return false;
}
if ( is_bool( $network_level_or_blog_id ) ) {
// Explicitly specified whether should use the network or blog level storage.
return $network_level_or_blog_id;
}
// Determine which storage to use based on the option.
return ! $this->is_site_option( $option );
} | [
"private",
"function",
"should_use_network_storage",
"(",
"$",
"option",
",",
"$",
"network_level_or_blog_id",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_is_multisite",
")",
"{",
"// Not a multisite environment.\r",
"return",
"false",
";",
"}",
... | Check if an option should be stored on the MS network storage.
@author Vova Feldman (@svovaf)
@since 2.0.0
@param string $option
@param null|bool|int $network_level_or_blog_id When an integer, use the given blog storage. When `true` use the multisite storage (if there's a network). When `false`, use the current context blog storage. When `null`, the decision which storage to use (MS vs. Current S) will be handled internally and determined based on the $option (based on self::$_SITE_LEVEL_PARAMS).
@return bool | [
"Check",
"if",
"an",
"option",
"should",
"be",
"stored",
"on",
"the",
"MS",
"network",
"storage",
"."
] | a4cc02a705639bcc64b5b55b8732432986b1b228 | https://github.com/Freemius/wordpress-sdk/blob/a4cc02a705639bcc64b5b55b8732432986b1b228/includes/class-fs-options.php#L410-L428 | train |
yiisoft/yii2-imagine | src/BaseImage.php | BaseImage.ensureImageInterfaceInstance | protected static function ensureImageInterfaceInstance($image)
{
if ($image instanceof ImageInterface) {
return $image;
}
if (is_resource($image)) {
return static::getImagine()->read($image);
}
if (is_string($image)) {
return static::getImagine()->open(Yii::getAlias($image));
}
throw new InvalidParamException('File should be either ImageInterface, resource or a string containing file path.');
} | php | protected static function ensureImageInterfaceInstance($image)
{
if ($image instanceof ImageInterface) {
return $image;
}
if (is_resource($image)) {
return static::getImagine()->read($image);
}
if (is_string($image)) {
return static::getImagine()->open(Yii::getAlias($image));
}
throw new InvalidParamException('File should be either ImageInterface, resource or a string containing file path.');
} | [
"protected",
"static",
"function",
"ensureImageInterfaceInstance",
"(",
"$",
"image",
")",
"{",
"if",
"(",
"$",
"image",
"instanceof",
"ImageInterface",
")",
"{",
"return",
"$",
"image",
";",
"}",
"if",
"(",
"is_resource",
"(",
"$",
"image",
")",
")",
"{",... | Takes either file path or ImageInterface. In case of file path, creates an instance of ImageInterface from it.
@param string|resource|ImageInterface $image
@return ImageInterface
@throws \yii\base\InvalidParamException
@since 2.1.0 | [
"Takes",
"either",
"file",
"path",
"or",
"ImageInterface",
".",
"In",
"case",
"of",
"file",
"path",
"creates",
"an",
"instance",
"of",
"ImageInterface",
"from",
"it",
"."
] | c36ef495c4db346f0b15624a3f06943b73205ab3 | https://github.com/yiisoft/yii2-imagine/blob/c36ef495c4db346f0b15624a3f06943b73205ab3/src/BaseImage.php#L133-L148 | train |
yiisoft/yii2-imagine | src/BaseImage.php | BaseImage.thumbnail | public static function thumbnail($image, $width, $height, $mode = ManipulatorInterface::THUMBNAIL_OUTBOUND)
{
$img = self::ensureImageInterfaceInstance($image);
/** @var BoxInterface $sourceBox */
$sourceBox = $img->getSize();
$thumbnailBox = static::getThumbnailBox($sourceBox, $width, $height);
if (self::isUpscaling($sourceBox, $thumbnailBox)) {
return $img->copy();
}
$img = $img->thumbnail($thumbnailBox, $mode);
if ($mode == ManipulatorInterface::THUMBNAIL_OUTBOUND) {
return $img;
}
$size = $img->getSize();
if ($size->getWidth() == $width && $size->getHeight() == $height) {
return $img;
}
$palette = new RGB();
$color = $palette->color(static::$thumbnailBackgroundColor, static::$thumbnailBackgroundAlpha);
// create empty image to preserve aspect ratio of thumbnail
$thumb = static::getImagine()->create($thumbnailBox, $color);
// calculate points
$startX = 0;
$startY = 0;
if ($size->getWidth() < $width) {
$startX = ceil(($width - $size->getWidth()) / 2);
}
if ($size->getHeight() < $height) {
$startY = ceil(($height - $size->getHeight()) / 2);
}
$thumb->paste($img, new Point($startX, $startY));
return $thumb;
} | php | public static function thumbnail($image, $width, $height, $mode = ManipulatorInterface::THUMBNAIL_OUTBOUND)
{
$img = self::ensureImageInterfaceInstance($image);
/** @var BoxInterface $sourceBox */
$sourceBox = $img->getSize();
$thumbnailBox = static::getThumbnailBox($sourceBox, $width, $height);
if (self::isUpscaling($sourceBox, $thumbnailBox)) {
return $img->copy();
}
$img = $img->thumbnail($thumbnailBox, $mode);
if ($mode == ManipulatorInterface::THUMBNAIL_OUTBOUND) {
return $img;
}
$size = $img->getSize();
if ($size->getWidth() == $width && $size->getHeight() == $height) {
return $img;
}
$palette = new RGB();
$color = $palette->color(static::$thumbnailBackgroundColor, static::$thumbnailBackgroundAlpha);
// create empty image to preserve aspect ratio of thumbnail
$thumb = static::getImagine()->create($thumbnailBox, $color);
// calculate points
$startX = 0;
$startY = 0;
if ($size->getWidth() < $width) {
$startX = ceil(($width - $size->getWidth()) / 2);
}
if ($size->getHeight() < $height) {
$startY = ceil(($height - $size->getHeight()) / 2);
}
$thumb->paste($img, new Point($startX, $startY));
return $thumb;
} | [
"public",
"static",
"function",
"thumbnail",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"mode",
"=",
"ManipulatorInterface",
"::",
"THUMBNAIL_OUTBOUND",
")",
"{",
"$",
"img",
"=",
"self",
"::",
"ensureImageInterfaceInstance",
"(",
"$... | Creates a thumbnail image.
If one of thumbnail dimensions is set to `null`, another one is calculated automatically based on aspect ratio of
original image. Note that calculated thumbnail dimension may vary depending on the source image in this case.
If both dimensions are specified, resulting thumbnail would be exactly the width and height specified. How it's
achieved depends on the mode.
If `ImageInterface::THUMBNAIL_OUTBOUND` mode is used, which is default, then the thumbnail is scaled so that
its smallest side equals the length of the corresponding side in the original image. Any excess outside of
the scaled thumbnail’s area will be cropped, and the returned thumbnail will have the exact width and height
specified.
If thumbnail mode is `ImageInterface::THUMBNAIL_INSET`, the original image is scaled down so it is fully
contained within the thumbnail dimensions. The rest is filled with background that could be configured via
[[Image::$thumbnailBackgroundColor]] and [[Image::$thumbnailBackgroundAlpha]].
@param string|resource|ImageInterface $image either ImageInterface, resource or a string containing file path
@param int $width the width in pixels to create the thumbnail
@param int $height the height in pixels to create the thumbnail
@param string $mode mode of resizing original image to use in case both width and height specified
@return ImageInterface | [
"Creates",
"a",
"thumbnail",
"image",
"."
] | c36ef495c4db346f0b15624a3f06943b73205ab3 | https://github.com/yiisoft/yii2-imagine/blob/c36ef495c4db346f0b15624a3f06943b73205ab3/src/BaseImage.php#L217-L260 | train |
yiisoft/yii2-imagine | src/BaseImage.php | BaseImage.getBox | protected static function getBox(BoxInterface $sourceBox, $width, $height, $keepAspectRatio = true)
{
if ($width === null && $height === null) {
throw new InvalidParamException('Width and height cannot be null at same time.');
}
$ratio = $sourceBox->getWidth() / $sourceBox->getHeight();
if ($keepAspectRatio === false) {
if ($height === null) {
$height = ceil($width / $ratio);
} elseif ($width === null) {
$width = ceil($height * $ratio);
}
} else {
if ($height === null) {
$height = ceil($width / $ratio);
} elseif ($width === null) {
$width = ceil($height * $ratio);
} elseif ($width / $height > $ratio) {
$width = $height * $ratio;
} else {
$height = $width / $ratio;
}
}
return new Box($width, $height);
} | php | protected static function getBox(BoxInterface $sourceBox, $width, $height, $keepAspectRatio = true)
{
if ($width === null && $height === null) {
throw new InvalidParamException('Width and height cannot be null at same time.');
}
$ratio = $sourceBox->getWidth() / $sourceBox->getHeight();
if ($keepAspectRatio === false) {
if ($height === null) {
$height = ceil($width / $ratio);
} elseif ($width === null) {
$width = ceil($height * $ratio);
}
} else {
if ($height === null) {
$height = ceil($width / $ratio);
} elseif ($width === null) {
$width = ceil($height * $ratio);
} elseif ($width / $height > $ratio) {
$width = $height * $ratio;
} else {
$height = $width / $ratio;
}
}
return new Box($width, $height);
} | [
"protected",
"static",
"function",
"getBox",
"(",
"BoxInterface",
"$",
"sourceBox",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"keepAspectRatio",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"width",
"===",
"null",
"&&",
"$",
"height",
"===",
"null",
"... | Returns box for an image to be created.
If one of the dimensions is set to `null`, another one is calculated automatically based on width to height ratio
of original image box.
If both of the dimensions are set then new dimensions are calculated so that image keeps aspect ratio.
You can set $keepAspectRatio to false if you want to force fixed width and height.
@param BoxInterface $sourceBox original image box
@param int $width new image width
@param int $height new image height
@param bool $keepAspectRatio should we keep aspect ratio even if both with and height are set
@return BoxInterface new image box
@since 2.1.1 | [
"Returns",
"box",
"for",
"an",
"image",
"to",
"be",
"created",
"."
] | c36ef495c4db346f0b15624a3f06943b73205ab3 | https://github.com/yiisoft/yii2-imagine/blob/c36ef495c4db346f0b15624a3f06943b73205ab3/src/BaseImage.php#L419-L445 | train |
yiisoft/yii2-imagine | src/BaseImage.php | BaseImage.isUpscaling | protected static function isUpscaling(BoxInterface $sourceBox, BoxInterface $destinationBox)
{
return ($sourceBox->getWidth() <= $destinationBox->getWidth() && $sourceBox->getHeight() <= $destinationBox->getHeight()) || (!$destinationBox->getWidth() && !$destinationBox->getHeight());
} | php | protected static function isUpscaling(BoxInterface $sourceBox, BoxInterface $destinationBox)
{
return ($sourceBox->getWidth() <= $destinationBox->getWidth() && $sourceBox->getHeight() <= $destinationBox->getHeight()) || (!$destinationBox->getWidth() && !$destinationBox->getHeight());
} | [
"protected",
"static",
"function",
"isUpscaling",
"(",
"BoxInterface",
"$",
"sourceBox",
",",
"BoxInterface",
"$",
"destinationBox",
")",
"{",
"return",
"(",
"$",
"sourceBox",
"->",
"getWidth",
"(",
")",
"<=",
"$",
"destinationBox",
"->",
"getWidth",
"(",
")",... | Checks if upscaling is going to happen
@param BoxInterface $sourceBox
@param BoxInterface $destinationBox
@return bool | [
"Checks",
"if",
"upscaling",
"is",
"going",
"to",
"happen"
] | c36ef495c4db346f0b15624a3f06943b73205ab3 | https://github.com/yiisoft/yii2-imagine/blob/c36ef495c4db346f0b15624a3f06943b73205ab3/src/BaseImage.php#L454-L457 | train |
nettrine/dbal | src/Utils/QueryUtils.php | QueryUtils.highlight | public static function highlight(string $sql): string
{
static $keywords1 = 'SELECT|(?:ON\s+DUPLICATE\s+KEY)?UPDATE|INSERT(?:\s+INTO)?|REPLACE(?:\s+INTO)?|SHOW|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|LIMIT|OFFSET|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN|TRUNCATE|START\s+TRANSACTION|COMMIT|ROLLBACK|(?:RELEASE\s+|ROLLBACK\s+TO\s+)?SAVEPOINT';
static $keywords2 = 'ALL|DISTINCT|DISTINCTROW|IGNORE|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|[RI]?LIKE|REGEXP|TRUE|FALSE';
$sql = ' ' . $sql . ' ';
$sql = htmlspecialchars($sql, ENT_IGNORE, 'UTF-8');
$sql = preg_replace_callback(sprintf('#(/\\*.+?\\*/)|(?<=[\\s,(])(%s)(?=[\\s,)])|(?<=[\\s,(=])(%s)(?=[\\s,)=])#is', $keywords1, $keywords2), function ($matches) {
if (!empty($matches[1])) { // comment
return '<em style="color:gray">' . $matches[1] . '</em>';
}
if (!empty($matches[2])) { // most important keywords
return '<strong style="color:#2D44AD">' . $matches[2] . '</strong>';
}
if (!empty($matches[3])) { // other keywords
return '<strong>' . $matches[3] . '</strong>';
}
}, $sql);
return trim((string) $sql);
} | php | public static function highlight(string $sql): string
{
static $keywords1 = 'SELECT|(?:ON\s+DUPLICATE\s+KEY)?UPDATE|INSERT(?:\s+INTO)?|REPLACE(?:\s+INTO)?|SHOW|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|LIMIT|OFFSET|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN|TRUNCATE|START\s+TRANSACTION|COMMIT|ROLLBACK|(?:RELEASE\s+|ROLLBACK\s+TO\s+)?SAVEPOINT';
static $keywords2 = 'ALL|DISTINCT|DISTINCTROW|IGNORE|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|[RI]?LIKE|REGEXP|TRUE|FALSE';
$sql = ' ' . $sql . ' ';
$sql = htmlspecialchars($sql, ENT_IGNORE, 'UTF-8');
$sql = preg_replace_callback(sprintf('#(/\\*.+?\\*/)|(?<=[\\s,(])(%s)(?=[\\s,)])|(?<=[\\s,(=])(%s)(?=[\\s,)=])#is', $keywords1, $keywords2), function ($matches) {
if (!empty($matches[1])) { // comment
return '<em style="color:gray">' . $matches[1] . '</em>';
}
if (!empty($matches[2])) { // most important keywords
return '<strong style="color:#2D44AD">' . $matches[2] . '</strong>';
}
if (!empty($matches[3])) { // other keywords
return '<strong>' . $matches[3] . '</strong>';
}
}, $sql);
return trim((string) $sql);
} | [
"public",
"static",
"function",
"highlight",
"(",
"string",
"$",
"sql",
")",
":",
"string",
"{",
"static",
"$",
"keywords1",
"=",
"'SELECT|(?:ON\\s+DUPLICATE\\s+KEY)?UPDATE|INSERT(?:\\s+INTO)?|REPLACE(?:\\s+INTO)?|SHOW|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\\s+BY|ORDER\\s+BY|LIMIT... | Highlight given SQL parts
@copyright https://github.com/nextras/dbal/blob/master/src/Bridges/NetteTracy/ConnectionPanel.php#L112
@copyright Nextras DBAL | [
"Highlight",
"given",
"SQL",
"parts"
] | 28e099dea09a8f4cb857a956e771c6639ac4d5df | https://github.com/nettrine/dbal/blob/28e099dea09a8f4cb857a956e771c6639ac4d5df/src/Utils/QueryUtils.php#L14-L35 | train |
nettrine/dbal | src/DI/DbalExtension.php | DbalExtension.loadDoctrineConfiguration | public function loadDoctrineConfiguration(): void
{
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults['configuration'], $this->config['configuration']);
$logger = $builder->addDefinition($this->prefix('logger'))
->setType(LoggerChain::class)
->setAutowired('self');
$configuration = $builder->addDefinition($this->prefix('configuration'));
$configuration->setFactory(Configuration::class)
->setAutowired(false)
->addSetup('setSQLLogger', [$this->prefix('@logger')]);
// SqlLogger (append to chain)
if ($config['sqlLogger'] !== null) {
$logger->addSetup('addLogger', [$config['sqlLogger']]);
}
// ResultCacheImpl
if ($config['resultCacheImpl'] !== null) {
$configuration->addSetup('setResultCacheImpl', [$config['resultCacheImpl']]);
}
// FilterSchemaAssetsExpression
if ($config['filterSchemaAssetsExpression'] !== null) {
$configuration->addSetup('setFilterSchemaAssetsExpression', [$config['filterSchemaAssetsExpression']]);
}
// AutoCommit
Validators::assert($config['autoCommit'], 'bool', 'configuration.autoCommit');
$configuration->addSetup('setAutoCommit', [$config['autoCommit']]);
} | php | public function loadDoctrineConfiguration(): void
{
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults['configuration'], $this->config['configuration']);
$logger = $builder->addDefinition($this->prefix('logger'))
->setType(LoggerChain::class)
->setAutowired('self');
$configuration = $builder->addDefinition($this->prefix('configuration'));
$configuration->setFactory(Configuration::class)
->setAutowired(false)
->addSetup('setSQLLogger', [$this->prefix('@logger')]);
// SqlLogger (append to chain)
if ($config['sqlLogger'] !== null) {
$logger->addSetup('addLogger', [$config['sqlLogger']]);
}
// ResultCacheImpl
if ($config['resultCacheImpl'] !== null) {
$configuration->addSetup('setResultCacheImpl', [$config['resultCacheImpl']]);
}
// FilterSchemaAssetsExpression
if ($config['filterSchemaAssetsExpression'] !== null) {
$configuration->addSetup('setFilterSchemaAssetsExpression', [$config['filterSchemaAssetsExpression']]);
}
// AutoCommit
Validators::assert($config['autoCommit'], 'bool', 'configuration.autoCommit');
$configuration->addSetup('setAutoCommit', [$config['autoCommit']]);
} | [
"public",
"function",
"loadDoctrineConfiguration",
"(",
")",
":",
"void",
"{",
"$",
"builder",
"=",
"$",
"this",
"->",
"getContainerBuilder",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"validateConfig",
"(",
"$",
"this",
"->",
"defaults",
"[",
... | Register Doctrine Configuration | [
"Register",
"Doctrine",
"Configuration"
] | 28e099dea09a8f4cb857a956e771c6639ac4d5df | https://github.com/nettrine/dbal/blob/28e099dea09a8f4cb857a956e771c6639ac4d5df/src/DI/DbalExtension.php#L89-L121 | train |
nettrine/dbal | src/DI/DbalExtension.php | DbalExtension.afterCompile | public function afterCompile(ClassType $class): void
{
$config = $this->validateConfig($this->defaults);
if ($config['debugger']['panel'] === true) {
$initialize = $class->getMethod('initialize');
$initialize->addBody(
'$this->getService(?)->addPanel($this->getService(?));',
['tracy.bar', $this->prefix('queryPanel')]
);
$initialize->addBody(
'$this->getService(?)->getConfiguration()->getSqlLogger()->addLogger($this->getService(?));',
[$this->prefix('connection'), $this->prefix('queryPanel')]
);
$initialize->addBody(
'$this->getService(?)->addPanel(new ?);',
['tracy.blueScreen', ContainerBuilder::literal(DbalBlueScreen::class)]
);
}
} | php | public function afterCompile(ClassType $class): void
{
$config = $this->validateConfig($this->defaults);
if ($config['debugger']['panel'] === true) {
$initialize = $class->getMethod('initialize');
$initialize->addBody(
'$this->getService(?)->addPanel($this->getService(?));',
['tracy.bar', $this->prefix('queryPanel')]
);
$initialize->addBody(
'$this->getService(?)->getConfiguration()->getSqlLogger()->addLogger($this->getService(?));',
[$this->prefix('connection'), $this->prefix('queryPanel')]
);
$initialize->addBody(
'$this->getService(?)->addPanel(new ?);',
['tracy.blueScreen', ContainerBuilder::literal(DbalBlueScreen::class)]
);
}
} | [
"public",
"function",
"afterCompile",
"(",
"ClassType",
"$",
"class",
")",
":",
"void",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"validateConfig",
"(",
"$",
"this",
"->",
"defaults",
")",
";",
"if",
"(",
"$",
"config",
"[",
"'debugger'",
"]",
"[",
... | Update initialize method | [
"Update",
"initialize",
"method"
] | 28e099dea09a8f4cb857a956e771c6639ac4d5df | https://github.com/nettrine/dbal/blob/28e099dea09a8f4cb857a956e771c6639ac4d5df/src/DI/DbalExtension.php#L189-L208 | train |
nettrine/dbal | src/Tracy/QueryPanel/QueryPanel.php | QueryPanel.getTab | public function getTab(): string
{
$count = count($this->queries);
$iconNoQuery = '<img style="height: 16px; width: auto;" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeD0iMHB4IiB5PSIwcHgiIHZpZXdCb3g9IjAgMCAyODAuMDI3IDI4MC4wMjciIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDI4MC4wMjcgMjgwLjAyNzsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHdpZHRoPSI1MTJweCIgaGVpZ2h0PSI1MTJweCI+CjxnPgoJPHBhdGggc3R5bGU9ImZpbGw6I0NDRDBEMjsiIGQ9Ik0xNy41MDIsNTIuNTA1djE3NS4wMTdjMCwyOC45ODMsNTQuODUsNTIuNTA1LDEyMi41MTIsNTIuNTA1czEyMi41MTItMjMuNTIyLDEyMi41MTItNTIuNTA1VjUyLjUwNSAgIEgxNy41MDJ6Ii8+Cgk8cGF0aCBzdHlsZT0iZmlsbDojQURCMEIyOyIgZD0iTTIyNy41MjIsMTIyLjUxMmM0LjgzOSwwLDguNzUxLTMuOTEyLDguNzUxLTguNzUxYzAtNC44My0zLjkxMi04Ljc1MS04Ljc1MS04Ljc1MSAgIGMtNC44MzksMC04Ljc1MSwzLjkyLTguNzUxLDguNzUxQzIxOC43NzEsMTE4LjYsMjIyLjY4MiwxMjIuNTEyLDIyNy41MjIsMTIyLjUxMnogTTIyNy41MjIsMTY2LjI2NiAgIGMtNC44MzksMC04Ljc1MSwzLjkyLTguNzUxLDguNzUxYzAsNC44MzksMy45MTIsOC43NTEsOC43NTEsOC43NTFjNC44MzksMCw4Ljc1MS0zLjkxMiw4Ljc1MS04Ljc1MSAgIEMyMzYuMjcyLDE3MC4xODcsMjMyLjM1MywxNjYuMjY2LDIyNy41MjIsMTY2LjI2NnogTTIyNy41MjIsMjI3LjUyMmMtNC44MzksMC04Ljc1MSwzLjkxMi04Ljc1MSw4Ljc1MXMzLjkxMiw4Ljc1MSw4Ljc1MSw4Ljc1MSAgIGM0LjgzOSwwLDguNzUxLTMuOTEyLDguNzUxLTguNzUxUzIzMi4zNTMsMjI3LjUyMiwyMjcuNTIyLDIyNy41MjJ6Ii8+Cgk8cGF0aCBzdHlsZT0iZmlsbDojQjdCQkJEOyIgZD0iTTE0MC4wMTQsMTY2LjI3NWM2Ny42NjIsMCwxMjIuNTEyLTI1LjM0MiwxMjIuNTEyLTU2LjYwOWMwLTEuNTkzLTAuMjM2LTMuMTUtMC41MTYtNC43MTcgICBjLTUuMTk4LDI5LjA1My01Ny43ODIsNTEuODkzLTEyMS45OTYsNTEuODkzUzIzLjIyNSwxMzQuMDExLDE4LjAxOCwxMDQuOTQ5Yy0wLjI4LDEuNTY2LTAuNTE2LDMuMTI0LTAuNTE2LDQuNzE3ICAgQzE3LjUwMiwxNDAuOTI0LDcyLjM0MywxNjYuMjc1LDE0MC4wMTQsMTY2LjI3NXogTTE0MC4wMTQsMjE4LjA5OGMtNjQuMjE0LDAtMTE2Ljc4OS0yMi44MjItMTIxLjk5Ni01MS44OTMgICBjLTAuMjgsMS41NjYtMC41MTYsMy4xMjQtMC41MTYsNC43MTdjMCwzMS4yNDksNTQuODUsNTYuNjA5LDEyMi41MTIsNTYuNjA5czEyMi41MTItMjUuMzQyLDEyMi41MTItNTYuNjA5ICAgYzAtMS42MDEtMC4yMzYtMy4xNS0wLjUxNi00LjcxN0MyNTYuODIsMTk1LjI0OSwyMDQuMjM2LDIxOC4wOTgsMTQwLjAxNCwyMTguMDk4eiIvPgoJPHBhdGggc3R5bGU9ImZpbGw6I0MyQzVDNzsiIGQ9Ik00My43NTQsMjU5LjkzNVY1Mi41MDVIMTcuNTAydjE3NS4wMTdDMTcuNTAyLDIzOS43NTYsMjcuMzU1LDI1MS4wMSw0My43NTQsMjU5LjkzNXoiLz4KCTxnPgoJCTxwYXRoIHN0eWxlPSJmaWxsOiNCMkI1Qjc7IiBkPSJNNDMuNzU0LDIwNS44NjR2LTkuNDg2Yy0xNC4zNjktOC40NjItMjMuNjk3LTE4LjgyMy0yNS43MzYtMzAuMTczICAgIGMtMC4yOCwxLjU2Ni0wLjUxNiwzLjEyNC0wLjUxNiw0LjcxN0MxNy41MDIsMTg0LjEyNywyNy4zNTUsMTk2LjIzOCw0My43NTQsMjA1Ljg2NHogTTQzLjc1NCwxNDQuNjA4di05LjQ3NyAgICBjLTE0LjM2OS04LjQ2Mi0yMy42OTctMTguODMyLTI1LjczNi0zMC4xOWMtMC4yOCwxLjU3NS0wLjUxNiwzLjEzMy0wLjUxNiw0LjcyNUMxNy41MDIsMTIyLjg3MSwyNy4zNTUsMTM0Ljk4Miw0My43NTQsMTQ0LjYwOHoiLz4KCTwvZz4KCTxwYXRoIHN0eWxlPSJmaWxsOiNFNEU3RTc7IiBkPSJNMTQwLjAxNCwwYzY3LjY2MiwwLDEyMi41MTIsMjMuNTE0LDEyMi41MTIsNTIuNTA1cy01NC44NSw1Mi41MDUtMTIyLjUxMiw1Mi41MDUgICBTMTcuNTAyLDgxLjQ5NywxNy41MDIsNTIuNTA1UzcyLjM0MywwLDE0MC4wMTQsMHoiLz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />';
$iconQuery = '<img style="height: 16px; width: auto;" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDUzIDUzIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MyA1MzsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHdpZHRoPSI1MTJweCIgaGVpZ2h0PSI1MTJweCI+CjxwYXRoIHN0eWxlPSJmaWxsOiM0MjRBNjA7IiBkPSJNNTAuNDU1LDhMNTAuNDU1LDhDNDkuNzI0LDMuNTM4LDM5LjI4MSwwLDI2LjUsMFMzLjI3NiwzLjUzOCwyLjU0NSw4bDAsMEgyLjV2MC41VjIwdjAuNVYyMXYxMXYwLjUgIFYzM3YxMmgwLjA0NWMwLjczMSw0LjQ2MSwxMS4xNzUsOCwyMy45NTUsOHMyMy4yMjQtMy41MzksMjMuOTU1LThINTAuNVYzM3YtMC41VjMyVjIxdi0wLjVWMjBWOC41VjhINTAuNDU1eiIvPgo8Zz4KCTxwYXRoIHN0eWxlPSJmaWxsOiM0MjRBNjA7IiBkPSJNMjYuNSw0MWMtMTMuMjU1LDAtMjQtMy44MDYtMjQtOC41VjQ1aDAuMDQ1YzAuNzMxLDQuNDYxLDExLjE3NSw4LDIzLjk1NSw4czIzLjIyNC0zLjUzOSwyMy45NTUtOCAgIEg1MC41VjMyLjVDNTAuNSwzNy4xOTQsMzkuNzU1LDQxLDI2LjUsNDF6Ii8+Cgk8cGF0aCBzdHlsZT0iZmlsbDojNDI0QTYwOyIgZD0iTTIuNSwzMnYwLjVjMC0wLjE2OCwwLjAxOC0wLjMzNCwwLjA0NS0wLjVIMi41eiIvPgoJPHBhdGggc3R5bGU9ImZpbGw6IzQyNEE2MDsiIGQ9Ik01MC40NTUsMzJjMC4wMjcsMC4xNjYsMC4wNDUsMC4zMzIsMC4wNDUsMC41VjMySDUwLjQ1NXoiLz4KPC9nPgo8Zz4KCTxwYXRoIHN0eWxlPSJmaWxsOiNFRkNFNEE7IiBkPSJNMjYuNSwyOWMtMTMuMjU1LDAtMjQtMy44MDYtMjQtOC41VjMzaDAuMDQ1YzAuNzMxLDQuNDYxLDExLjE3NSw4LDIzLjk1NSw4czIzLjIyNC0zLjUzOSwyMy45NTUtOCAgIEg1MC41VjIwLjVDNTAuNSwyNS4xOTQsMzkuNzU1LDI5LDI2LjUsMjl6Ii8+Cgk8cGF0aCBzdHlsZT0iZmlsbDojRUZDRTRBOyIgZD0iTTIuNSwyMHYwLjVjMC0wLjE2OCwwLjAxOC0wLjMzNCwwLjA0NS0wLjVIMi41eiIvPgoJPHBhdGggc3R5bGU9ImZpbGw6I0VGQ0U0QTsiIGQ9Ik01MC40NTUsMjBjMC4wMjcsMC4xNjYsMC4wNDUsMC4zMzIsMC4wNDUsMC41VjIwSDUwLjQ1NXoiLz4KPC9nPgo8ZWxsaXBzZSBzdHlsZT0iZmlsbDojN0ZBQkRBOyIgY3g9IjI2LjUiIGN5PSI4LjUiIHJ4PSIyNCIgcnk9IjguNSIvPgo8Zz4KCTxwYXRoIHN0eWxlPSJmaWxsOiM3MzgzQkY7IiBkPSJNMjYuNSwxN2MtMTMuMjU1LDAtMjQtMy44MDYtMjQtOC41VjIxaDAuMDQ1YzAuNzMxLDQuNDYxLDExLjE3NSw4LDIzLjk1NSw4czIzLjIyNC0zLjUzOSwyMy45NTUtOCAgIEg1MC41VjguNUM1MC41LDEzLjE5NCwzOS43NTUsMTcsMjYuNSwxN3oiLz4KCTxwYXRoIHN0eWxlPSJmaWxsOiM3MzgzQkY7IiBkPSJNMi41LDh2MC41YzAtMC4xNjgsMC4wMTgtMC4zMzQsMC4wNDUtMC41SDIuNXoiLz4KCTxwYXRoIHN0eWxlPSJmaWxsOiM3MzgzQkY7IiBkPSJNNTAuNDU1LDhDNTAuNDgyLDguMTY2LDUwLjUsOC4zMzIsNTAuNSw4LjVWOEg1MC40NTV6Ii8+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPC9zdmc+Cg==" />';
return '<span title="dbal">'
. '<span class="tracy-label">'
. ($count > 0 ? $iconQuery : $iconNoQuery)
. ' '
. $count . ' queries'
. ($this->totalTime ? ' / ' . sprintf('%0.2fms', $this->totalTime * 1000) : '')
. '</span>'
. '</span>';
} | php | public function getTab(): string
{
$count = count($this->queries);
$iconNoQuery = '<img style="height: 16px; width: auto;" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeD0iMHB4IiB5PSIwcHgiIHZpZXdCb3g9IjAgMCAyODAuMDI3IDI4MC4wMjciIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDI4MC4wMjcgMjgwLjAyNzsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHdpZHRoPSI1MTJweCIgaGVpZ2h0PSI1MTJweCI+CjxnPgoJPHBhdGggc3R5bGU9ImZpbGw6I0NDRDBEMjsiIGQ9Ik0xNy41MDIsNTIuNTA1djE3NS4wMTdjMCwyOC45ODMsNTQuODUsNTIuNTA1LDEyMi41MTIsNTIuNTA1czEyMi41MTItMjMuNTIyLDEyMi41MTItNTIuNTA1VjUyLjUwNSAgIEgxNy41MDJ6Ii8+Cgk8cGF0aCBzdHlsZT0iZmlsbDojQURCMEIyOyIgZD0iTTIyNy41MjIsMTIyLjUxMmM0LjgzOSwwLDguNzUxLTMuOTEyLDguNzUxLTguNzUxYzAtNC44My0zLjkxMi04Ljc1MS04Ljc1MS04Ljc1MSAgIGMtNC44MzksMC04Ljc1MSwzLjkyLTguNzUxLDguNzUxQzIxOC43NzEsMTE4LjYsMjIyLjY4MiwxMjIuNTEyLDIyNy41MjIsMTIyLjUxMnogTTIyNy41MjIsMTY2LjI2NiAgIGMtNC44MzksMC04Ljc1MSwzLjkyLTguNzUxLDguNzUxYzAsNC44MzksMy45MTIsOC43NTEsOC43NTEsOC43NTFjNC44MzksMCw4Ljc1MS0zLjkxMiw4Ljc1MS04Ljc1MSAgIEMyMzYuMjcyLDE3MC4xODcsMjMyLjM1MywxNjYuMjY2LDIyNy41MjIsMTY2LjI2NnogTTIyNy41MjIsMjI3LjUyMmMtNC44MzksMC04Ljc1MSwzLjkxMi04Ljc1MSw4Ljc1MXMzLjkxMiw4Ljc1MSw4Ljc1MSw4Ljc1MSAgIGM0LjgzOSwwLDguNzUxLTMuOTEyLDguNzUxLTguNzUxUzIzMi4zNTMsMjI3LjUyMiwyMjcuNTIyLDIyNy41MjJ6Ii8+Cgk8cGF0aCBzdHlsZT0iZmlsbDojQjdCQkJEOyIgZD0iTTE0MC4wMTQsMTY2LjI3NWM2Ny42NjIsMCwxMjIuNTEyLTI1LjM0MiwxMjIuNTEyLTU2LjYwOWMwLTEuNTkzLTAuMjM2LTMuMTUtMC41MTYtNC43MTcgICBjLTUuMTk4LDI5LjA1My01Ny43ODIsNTEuODkzLTEyMS45OTYsNTEuODkzUzIzLjIyNSwxMzQuMDExLDE4LjAxOCwxMDQuOTQ5Yy0wLjI4LDEuNTY2LTAuNTE2LDMuMTI0LTAuNTE2LDQuNzE3ICAgQzE3LjUwMiwxNDAuOTI0LDcyLjM0MywxNjYuMjc1LDE0MC4wMTQsMTY2LjI3NXogTTE0MC4wMTQsMjE4LjA5OGMtNjQuMjE0LDAtMTE2Ljc4OS0yMi44MjItMTIxLjk5Ni01MS44OTMgICBjLTAuMjgsMS41NjYtMC41MTYsMy4xMjQtMC41MTYsNC43MTdjMCwzMS4yNDksNTQuODUsNTYuNjA5LDEyMi41MTIsNTYuNjA5czEyMi41MTItMjUuMzQyLDEyMi41MTItNTYuNjA5ICAgYzAtMS42MDEtMC4yMzYtMy4xNS0wLjUxNi00LjcxN0MyNTYuODIsMTk1LjI0OSwyMDQuMjM2LDIxOC4wOTgsMTQwLjAxNCwyMTguMDk4eiIvPgoJPHBhdGggc3R5bGU9ImZpbGw6I0MyQzVDNzsiIGQ9Ik00My43NTQsMjU5LjkzNVY1Mi41MDVIMTcuNTAydjE3NS4wMTdDMTcuNTAyLDIzOS43NTYsMjcuMzU1LDI1MS4wMSw0My43NTQsMjU5LjkzNXoiLz4KCTxnPgoJCTxwYXRoIHN0eWxlPSJmaWxsOiNCMkI1Qjc7IiBkPSJNNDMuNzU0LDIwNS44NjR2LTkuNDg2Yy0xNC4zNjktOC40NjItMjMuNjk3LTE4LjgyMy0yNS43MzYtMzAuMTczICAgIGMtMC4yOCwxLjU2Ni0wLjUxNiwzLjEyNC0wLjUxNiw0LjcxN0MxNy41MDIsMTg0LjEyNywyNy4zNTUsMTk2LjIzOCw0My43NTQsMjA1Ljg2NHogTTQzLjc1NCwxNDQuNjA4di05LjQ3NyAgICBjLTE0LjM2OS04LjQ2Mi0yMy42OTctMTguODMyLTI1LjczNi0zMC4xOWMtMC4yOCwxLjU3NS0wLjUxNiwzLjEzMy0wLjUxNiw0LjcyNUMxNy41MDIsMTIyLjg3MSwyNy4zNTUsMTM0Ljk4Miw0My43NTQsMTQ0LjYwOHoiLz4KCTwvZz4KCTxwYXRoIHN0eWxlPSJmaWxsOiNFNEU3RTc7IiBkPSJNMTQwLjAxNCwwYzY3LjY2MiwwLDEyMi41MTIsMjMuNTE0LDEyMi41MTIsNTIuNTA1cy01NC44NSw1Mi41MDUtMTIyLjUxMiw1Mi41MDUgICBTMTcuNTAyLDgxLjQ5NywxNy41MDIsNTIuNTA1UzcyLjM0MywwLDE0MC4wMTQsMHoiLz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8Zz4KPC9nPgo8L3N2Zz4K" />';
$iconQuery = '<img style="height: 16px; width: auto;" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDUzIDUzIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MyA1MzsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHdpZHRoPSI1MTJweCIgaGVpZ2h0PSI1MTJweCI+CjxwYXRoIHN0eWxlPSJmaWxsOiM0MjRBNjA7IiBkPSJNNTAuNDU1LDhMNTAuNDU1LDhDNDkuNzI0LDMuNTM4LDM5LjI4MSwwLDI2LjUsMFMzLjI3NiwzLjUzOCwyLjU0NSw4bDAsMEgyLjV2MC41VjIwdjAuNVYyMXYxMXYwLjUgIFYzM3YxMmgwLjA0NWMwLjczMSw0LjQ2MSwxMS4xNzUsOCwyMy45NTUsOHMyMy4yMjQtMy41MzksMjMuOTU1LThINTAuNVYzM3YtMC41VjMyVjIxdi0wLjVWMjBWOC41VjhINTAuNDU1eiIvPgo8Zz4KCTxwYXRoIHN0eWxlPSJmaWxsOiM0MjRBNjA7IiBkPSJNMjYuNSw0MWMtMTMuMjU1LDAtMjQtMy44MDYtMjQtOC41VjQ1aDAuMDQ1YzAuNzMxLDQuNDYxLDExLjE3NSw4LDIzLjk1NSw4czIzLjIyNC0zLjUzOSwyMy45NTUtOCAgIEg1MC41VjMyLjVDNTAuNSwzNy4xOTQsMzkuNzU1LDQxLDI2LjUsNDF6Ii8+Cgk8cGF0aCBzdHlsZT0iZmlsbDojNDI0QTYwOyIgZD0iTTIuNSwzMnYwLjVjMC0wLjE2OCwwLjAxOC0wLjMzNCwwLjA0NS0wLjVIMi41eiIvPgoJPHBhdGggc3R5bGU9ImZpbGw6IzQyNEE2MDsiIGQ9Ik01MC40NTUsMzJjMC4wMjcsMC4xNjYsMC4wNDUsMC4zMzIsMC4wNDUsMC41VjMySDUwLjQ1NXoiLz4KPC9nPgo8Zz4KCTxwYXRoIHN0eWxlPSJmaWxsOiNFRkNFNEE7IiBkPSJNMjYuNSwyOWMtMTMuMjU1LDAtMjQtMy44MDYtMjQtOC41VjMzaDAuMDQ1YzAuNzMxLDQuNDYxLDExLjE3NSw4LDIzLjk1NSw4czIzLjIyNC0zLjUzOSwyMy45NTUtOCAgIEg1MC41VjIwLjVDNTAuNSwyNS4xOTQsMzkuNzU1LDI5LDI2LjUsMjl6Ii8+Cgk8cGF0aCBzdHlsZT0iZmlsbDojRUZDRTRBOyIgZD0iTTIuNSwyMHYwLjVjMC0wLjE2OCwwLjAxOC0wLjMzNCwwLjA0NS0wLjVIMi41eiIvPgoJPHBhdGggc3R5bGU9ImZpbGw6I0VGQ0U0QTsiIGQ9Ik01MC40NTUsMjBjMC4wMjcsMC4xNjYsMC4wNDUsMC4zMzIsMC4wNDUsMC41VjIwSDUwLjQ1NXoiLz4KPC9nPgo8ZWxsaXBzZSBzdHlsZT0iZmlsbDojN0ZBQkRBOyIgY3g9IjI2LjUiIGN5PSI4LjUiIHJ4PSIyNCIgcnk9IjguNSIvPgo8Zz4KCTxwYXRoIHN0eWxlPSJmaWxsOiM3MzgzQkY7IiBkPSJNMjYuNSwxN2MtMTMuMjU1LDAtMjQtMy44MDYtMjQtOC41VjIxaDAuMDQ1YzAuNzMxLDQuNDYxLDExLjE3NSw4LDIzLjk1NSw4czIzLjIyNC0zLjUzOSwyMy45NTUtOCAgIEg1MC41VjguNUM1MC41LDEzLjE5NCwzOS43NTUsMTcsMjYuNSwxN3oiLz4KCTxwYXRoIHN0eWxlPSJmaWxsOiM3MzgzQkY7IiBkPSJNMi41LDh2MC41YzAtMC4xNjgsMC4wMTgtMC4zMzQsMC4wNDUtMC41SDIuNXoiLz4KCTxwYXRoIHN0eWxlPSJmaWxsOiM3MzgzQkY7IiBkPSJNNTAuNDU1LDhDNTAuNDgyLDguMTY2LDUwLjUsOC4zMzIsNTAuNSw4LjVWOEg1MC40NTV6Ii8+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPC9zdmc+Cg==" />';
return '<span title="dbal">'
. '<span class="tracy-label">'
. ($count > 0 ? $iconQuery : $iconNoQuery)
. ' '
. $count . ' queries'
. ($this->totalTime ? ' / ' . sprintf('%0.2fms', $this->totalTime * 1000) : '')
. '</span>'
. '</span>';
} | [
"public",
"function",
"getTab",
"(",
")",
":",
"string",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"this",
"->",
"queries",
")",
";",
"$",
"iconNoQuery",
"=",
"'<img style=\"height: 16px; width: auto;\" src=\"data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmN... | HTML for tab | [
"HTML",
"for",
"tab"
] | 28e099dea09a8f4cb857a956e771c6639ac4d5df | https://github.com/nettrine/dbal/blob/28e099dea09a8f4cb857a956e771c6639ac4d5df/src/Tracy/QueryPanel/QueryPanel.php#L105-L120 | train |
nettrine/dbal | src/Tracy/QueryPanel/QueryPanel.php | QueryPanel.getPanel | public function getPanel(): string
{
ob_start();
$parameters = $this->connection->getParams();
$parameters['password'] = '****';
$connected = $this->connection->isConnected();
$queries = $this->queries;
$queriesNum = count($this->queries);
$totalTime = $this->totalTime;
require __DIR__ . '/templates/panel.phtml';
return (string) ob_get_clean();
} | php | public function getPanel(): string
{
ob_start();
$parameters = $this->connection->getParams();
$parameters['password'] = '****';
$connected = $this->connection->isConnected();
$queries = $this->queries;
$queriesNum = count($this->queries);
$totalTime = $this->totalTime;
require __DIR__ . '/templates/panel.phtml';
return (string) ob_get_clean();
} | [
"public",
"function",
"getPanel",
"(",
")",
":",
"string",
"{",
"ob_start",
"(",
")",
";",
"$",
"parameters",
"=",
"$",
"this",
"->",
"connection",
"->",
"getParams",
"(",
")",
";",
"$",
"parameters",
"[",
"'password'",
"]",
"=",
"'****'",
";",
"$",
... | HTML for panel | [
"HTML",
"for",
"panel"
] | 28e099dea09a8f4cb857a956e771c6639ac4d5df | https://github.com/nettrine/dbal/blob/28e099dea09a8f4cb857a956e771c6639ac4d5df/src/Tracy/QueryPanel/QueryPanel.php#L125-L137 | train |
deanblackborough/php-quill-renderer | src/Renderer/Html.php | Html.render | public function render(bool $trim = false): string
{
$this->output = '';
$block_open = false;
foreach ($this->deltas as $i => $delta) {
if (
$delta->displayType() === Delta::DISPLAY_INLINE &&
$block_open === false
) {
$block_open = true;
$this->output .= '<p>';
}
if ($delta->isChild() === true && $delta->isFirstChild() === true) {
if (
$block_open === true &&
$this->deltas[$i - 1]->displayType() === Delta::DISPLAY_INLINE
) {
$this->output .= "</p>\n";
$block_open = false;
}
$this->output .= '<' . $delta->parentTag() . ">\n";
}
if (
$delta->displayType() === Delta::DISPLAY_BLOCK &&
$block_open === true
) {
$block_open = false;
$this->output .= "</p>\n";
}
$this->output .= $delta->render();
if (
$delta->displayType() === Delta::DISPLAY_INLINE &&
(
$block_open === true &&
$delta->close() === true
)
) {
$this->output .= "</p>\n";
$block_open = false;
}
if ($delta->isChild() === true && $delta->isLastChild() === true) {
$this->output .= '</' . $delta->parentTag() . ">\n";
}
if (
$i === count($this->deltas) - 1 &&
$delta->displayType() === Delta::DISPLAY_INLINE && $block_open === true
) {
$this->output .= "</p>\n";
}
}
if ($trim === false) {
return $this->output;
} else {
return trim($this->output);
}
} | php | public function render(bool $trim = false): string
{
$this->output = '';
$block_open = false;
foreach ($this->deltas as $i => $delta) {
if (
$delta->displayType() === Delta::DISPLAY_INLINE &&
$block_open === false
) {
$block_open = true;
$this->output .= '<p>';
}
if ($delta->isChild() === true && $delta->isFirstChild() === true) {
if (
$block_open === true &&
$this->deltas[$i - 1]->displayType() === Delta::DISPLAY_INLINE
) {
$this->output .= "</p>\n";
$block_open = false;
}
$this->output .= '<' . $delta->parentTag() . ">\n";
}
if (
$delta->displayType() === Delta::DISPLAY_BLOCK &&
$block_open === true
) {
$block_open = false;
$this->output .= "</p>\n";
}
$this->output .= $delta->render();
if (
$delta->displayType() === Delta::DISPLAY_INLINE &&
(
$block_open === true &&
$delta->close() === true
)
) {
$this->output .= "</p>\n";
$block_open = false;
}
if ($delta->isChild() === true && $delta->isLastChild() === true) {
$this->output .= '</' . $delta->parentTag() . ">\n";
}
if (
$i === count($this->deltas) - 1 &&
$delta->displayType() === Delta::DISPLAY_INLINE && $block_open === true
) {
$this->output .= "</p>\n";
}
}
if ($trim === false) {
return $this->output;
} else {
return trim($this->output);
}
} | [
"public",
"function",
"render",
"(",
"bool",
"$",
"trim",
"=",
"false",
")",
":",
"string",
"{",
"$",
"this",
"->",
"output",
"=",
"''",
";",
"$",
"block_open",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"deltas",
"as",
"$",
"i",
"=>",
... | Generate the final HTML, calls the render method on each object
@param boolean $trim Optionally trim the output
@return string | [
"Generate",
"the",
"final",
"HTML",
"calls",
"the",
"render",
"method",
"on",
"each",
"object"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Renderer/Html.php#L39-L105 | train |
deanblackborough/php-quill-renderer | src/Delta/Html/ListItem.php | ListItem.parentTag | public function parentTag(): ?string
{
switch ($this->attributes['list']) {
case Options::ATTRIBUTE_LIST_ORDERED:
return Options::HTML_TAG_LIST_ORDERED;
break;
case Options::ATTRIBUTE_LIST_BULLET:
return Options::HTML_TAG_LIST_UNORDERED;
break;
default:
return Options::HTML_TAG_LIST_UNORDERED;
break;
}
} | php | public function parentTag(): ?string
{
switch ($this->attributes['list']) {
case Options::ATTRIBUTE_LIST_ORDERED:
return Options::HTML_TAG_LIST_ORDERED;
break;
case Options::ATTRIBUTE_LIST_BULLET:
return Options::HTML_TAG_LIST_UNORDERED;
break;
default:
return Options::HTML_TAG_LIST_UNORDERED;
break;
}
} | [
"public",
"function",
"parentTag",
"(",
")",
":",
"?",
"string",
"{",
"switch",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'list'",
"]",
")",
"{",
"case",
"Options",
"::",
"ATTRIBUTE_LIST_ORDERED",
":",
"return",
"Options",
"::",
"HTML_TAG_LIST_ORDERED",
";... | If the delta is a child, what type of tag is the parent
@return string|null | [
"If",
"the",
"delta",
"is",
"a",
"child",
"what",
"type",
"of",
"tag",
"is",
"the",
"parent"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Delta/Html/ListItem.php#L57-L71 | train |
deanblackborough/php-quill-renderer | src/Renderer/Markdown.php | Markdown.render | public function render(bool $trim = false): string
{
$this->output = '';
foreach ($this->deltas as $i => $delta) {
$this->output .= $delta->render();
}
if ($trim === false) {
return $this->output;
} else {
return trim($this->output);
}
} | php | public function render(bool $trim = false): string
{
$this->output = '';
foreach ($this->deltas as $i => $delta) {
$this->output .= $delta->render();
}
if ($trim === false) {
return $this->output;
} else {
return trim($this->output);
}
} | [
"public",
"function",
"render",
"(",
"bool",
"$",
"trim",
"=",
"false",
")",
":",
"string",
"{",
"$",
"this",
"->",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"deltas",
"as",
"$",
"i",
"=>",
"$",
"delta",
")",
"{",
"$",
"this",
... | Generate the final Markdown, calls the render method on each object
@param boolean $trim Optionally trim the output
@return string | [
"Generate",
"the",
"final",
"Markdown",
"calls",
"the",
"render",
"method",
"on",
"each",
"object"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Renderer/Markdown.php#L39-L52 | train |
deanblackborough/php-quill-renderer | src/Delta/Html/Compound.php | Compound.setAttribute | public function setAttribute($attribute, $value): Compound
{
if ($attribute !== 'link') {
$this->attributes[$attribute] = $value;
} else {
$this->isLink = true;
$this->link = $value;
}
return $this;
} | php | public function setAttribute($attribute, $value): Compound
{
if ($attribute !== 'link') {
$this->attributes[$attribute] = $value;
} else {
$this->isLink = true;
$this->link = $value;
}
return $this;
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"attribute",
",",
"$",
"value",
")",
":",
"Compound",
"{",
"if",
"(",
"$",
"attribute",
"!==",
"'link'",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"$",
"attribute",
"]",
"=",
"$",
"value",
";",
"}... | Pass in an attribute value for conversion
@param string $attribute Attribute name
@param string $value Attribute value to assign
@return Compound | [
"Pass",
"in",
"an",
"attribute",
"value",
"for",
"conversion"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Delta/Html/Compound.php#L99-L109 | train |
deanblackborough/php-quill-renderer | src/Delta/Html/Compound.php | Compound.getAttributes | public function getAttributes(): array
{
if ($this->isLink === false) {
return $this->attributes;
} else {
return array_merge(
['link' => $this->link],
$this->attributes
);
}
} | php | public function getAttributes(): array
{
if ($this->isLink === false) {
return $this->attributes;
} else {
return array_merge(
['link' => $this->link],
$this->attributes
);
}
} | [
"public",
"function",
"getAttributes",
"(",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"isLink",
"===",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"attributes",
";",
"}",
"else",
"{",
"return",
"array_merge",
"(",
"[",
"'link'",
"=>",
... | Override the method to include the link in the attributes array if
necessary as it will have be striped
@return array | [
"Override",
"the",
"method",
"to",
"include",
"the",
"link",
"in",
"the",
"attributes",
"array",
"if",
"necessary",
"as",
"it",
"will",
"have",
"be",
"striped"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Delta/Html/Compound.php#L160-L170 | train |
deanblackborough/php-quill-renderer | src/Parser/Markdown.php | Markdown.compoundInsert | public function compoundInsert(array $quill)
{
if (count($quill['attributes']) > 0) {
if (is_array($quill['insert']) === false) {
$delta = new Compound($quill['insert']);
foreach ($quill['attributes'] as $attribute => $value) {
$delta->setAttribute($attribute, $value);
}
$this->deltas[] = $delta;
}
}
} | php | public function compoundInsert(array $quill)
{
if (count($quill['attributes']) > 0) {
if (is_array($quill['insert']) === false) {
$delta = new Compound($quill['insert']);
foreach ($quill['attributes'] as $attribute => $value) {
$delta->setAttribute($attribute, $value);
}
$this->deltas[] = $delta;
}
}
} | [
"public",
"function",
"compoundInsert",
"(",
"array",
"$",
"quill",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"quill",
"[",
"'attributes'",
"]",
")",
">",
"0",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"quill",
"[",
"'insert'",
"]",
")",
"===",
"fal... | Multiple attributes set, handle accordingly
@param array $quill
@return void | [
"Multiple",
"attributes",
"set",
"handle",
"accordingly"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Markdown.php#L191-L204 | train |
deanblackborough/php-quill-renderer | src/Parser/Markdown.php | Markdown.extendedInsert | public function extendedInsert(array $quill)
{
if (preg_match("/[\n]{2,}/", $quill['insert']) !== 0) {
$sub_inserts = preg_split("/[\n]{2,}/", $quill['insert']);
$i = 0;
foreach ($sub_inserts as $match) {
$append = "\n\n";
if ($i === (count($sub_inserts)-1)) {
$append = null;
}
$this->deltas[] = new Insert($match . $append);
$i++;
}
} else {
if (preg_match("/[\n]{1}/", $quill['insert']) !== 0) {
$sub_inserts = preg_split("/[\n]{1}/", $quill['insert']);
$i = 0;
foreach ($sub_inserts as $match) {
$append = "\n";
if ($i === (count($sub_inserts)-1)) {
$append = null;
}
$this->deltas[] = new Insert($match . $append);
$i++;
}
} else {
$this->deltas[] = new Insert($quill['insert']);
}
}
} | php | public function extendedInsert(array $quill)
{
if (preg_match("/[\n]{2,}/", $quill['insert']) !== 0) {
$sub_inserts = preg_split("/[\n]{2,}/", $quill['insert']);
$i = 0;
foreach ($sub_inserts as $match) {
$append = "\n\n";
if ($i === (count($sub_inserts)-1)) {
$append = null;
}
$this->deltas[] = new Insert($match . $append);
$i++;
}
} else {
if (preg_match("/[\n]{1}/", $quill['insert']) !== 0) {
$sub_inserts = preg_split("/[\n]{1}/", $quill['insert']);
$i = 0;
foreach ($sub_inserts as $match) {
$append = "\n";
if ($i === (count($sub_inserts)-1)) {
$append = null;
}
$this->deltas[] = new Insert($match . $append);
$i++;
}
} else {
$this->deltas[] = new Insert($quill['insert']);
}
}
} | [
"public",
"function",
"extendedInsert",
"(",
"array",
"$",
"quill",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/[\\n]{2,}/\"",
",",
"$",
"quill",
"[",
"'insert'",
"]",
")",
"!==",
"0",
")",
"{",
"$",
"sub_inserts",
"=",
"preg_split",
"(",
"\"/[\\n]{2,}/\""... | Extended Quill insert, insert will need to be split before creation
of Deltas
@param array $quill
@return void | [
"Extended",
"Quill",
"insert",
"insert",
"will",
"need",
"to",
"be",
"split",
"before",
"creation",
"of",
"Deltas"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Markdown.php#L214-L243 | train |
deanblackborough/php-quill-renderer | src/Delta/Markdown/Header.php | Header.render | public function render(): string
{
$string = str_repeat('#', intval($this->attributes['header'])) . ' ';
if ($this->hasChildren() === true) {
foreach ($this->children() as $child) {
$string .= $child->render();
}
}
$string .= "{$this->escape($this->insert)}";
return $string;
/*return str_repeat('#', intval($this->attributes['header'])) .
" {$this->escape($this->insert)}";*/
} | php | public function render(): string
{
$string = str_repeat('#', intval($this->attributes['header'])) . ' ';
if ($this->hasChildren() === true) {
foreach ($this->children() as $child) {
$string .= $child->render();
}
}
$string .= "{$this->escape($this->insert)}";
return $string;
/*return str_repeat('#', intval($this->attributes['header'])) .
" {$this->escape($this->insert)}";*/
} | [
"public",
"function",
"render",
"(",
")",
":",
"string",
"{",
"$",
"string",
"=",
"str_repeat",
"(",
"'#'",
",",
"intval",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'header'",
"]",
")",
")",
".",
"' '",
";",
"if",
"(",
"$",
"this",
"->",
"hasChil... | Render the Markdown string
@return string | [
"Render",
"the",
"Markdown",
"string"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Delta/Markdown/Header.php#L47-L64 | train |
deanblackborough/php-quill-renderer | src/Parser/Html.php | Html.attributeColor | public function attributeColor(array $quill)
{
if (strlen($quill['attributes'][OPTIONS::ATTRIBUTE_COLOR]) > 0) {
$this->deltas[] = new $this->class_delta_color($quill['insert'], $quill['attributes']);
}
} | php | public function attributeColor(array $quill)
{
if (strlen($quill['attributes'][OPTIONS::ATTRIBUTE_COLOR]) > 0) {
$this->deltas[] = new $this->class_delta_color($quill['insert'], $quill['attributes']);
}
} | [
"public",
"function",
"attributeColor",
"(",
"array",
"$",
"quill",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"quill",
"[",
"'attributes'",
"]",
"[",
"OPTIONS",
"::",
"ATTRIBUTE_COLOR",
"]",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"deltas",
"[",
"... | Color Quill attribute, assign the relevant Delta class and set up the data
@param array $quill
@return void | [
"Color",
"Quill",
"attribute",
"assign",
"the",
"relevant",
"Delta",
"class",
"and",
"set",
"up",
"the",
"data"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Html.php#L238-L243 | train |
deanblackborough/php-quill-renderer | src/Parser/Html.php | Html.attributeScript | public function attributeScript(array $quill)
{
if ($quill['attributes'][OPTIONS::ATTRIBUTE_SCRIPT] === Options::ATTRIBUTE_SCRIPT_SUB) {
$this->deltas[] = new SubScript($quill['insert'], $quill['attributes']);
}
if ($quill['attributes'][OPTIONS::ATTRIBUTE_SCRIPT] === Options::ATTRIBUTE_SCRIPT_SUPER) {
$this->deltas[] = new SuperScript($quill['insert'], $quill['attributes']);
}
} | php | public function attributeScript(array $quill)
{
if ($quill['attributes'][OPTIONS::ATTRIBUTE_SCRIPT] === Options::ATTRIBUTE_SCRIPT_SUB) {
$this->deltas[] = new SubScript($quill['insert'], $quill['attributes']);
}
if ($quill['attributes'][OPTIONS::ATTRIBUTE_SCRIPT] === Options::ATTRIBUTE_SCRIPT_SUPER) {
$this->deltas[] = new SuperScript($quill['insert'], $quill['attributes']);
}
} | [
"public",
"function",
"attributeScript",
"(",
"array",
"$",
"quill",
")",
"{",
"if",
"(",
"$",
"quill",
"[",
"'attributes'",
"]",
"[",
"OPTIONS",
"::",
"ATTRIBUTE_SCRIPT",
"]",
"===",
"Options",
"::",
"ATTRIBUTE_SCRIPT_SUB",
")",
"{",
"$",
"this",
"->",
"d... | Script Quill attribute, assign the relevant Delta class and set up
the data, script could be sub or super
@param array $quill
@return void | [
"Script",
"Quill",
"attribute",
"assign",
"the",
"relevant",
"Delta",
"class",
"and",
"set",
"up",
"the",
"data",
"script",
"could",
"be",
"sub",
"or",
"super"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Html.php#L253-L261 | train |
deanblackborough/php-quill-renderer | src/Parser/Html.php | Html.attributeUnderline | public function attributeUnderline(array $quill)
{
if ($quill['attributes'][OPTIONS::ATTRIBUTE_UNDERLINE] === true) {
$this->deltas[] = new Underline($quill['insert'], $quill['attributes']);
}
} | php | public function attributeUnderline(array $quill)
{
if ($quill['attributes'][OPTIONS::ATTRIBUTE_UNDERLINE] === true) {
$this->deltas[] = new Underline($quill['insert'], $quill['attributes']);
}
} | [
"public",
"function",
"attributeUnderline",
"(",
"array",
"$",
"quill",
")",
"{",
"if",
"(",
"$",
"quill",
"[",
"'attributes'",
"]",
"[",
"OPTIONS",
"::",
"ATTRIBUTE_UNDERLINE",
"]",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"deltas",
"[",
"]",
"=",
... | Underline Quill attribute, assign the relevant Delta class and set up
the data
@param array $quill
@return void | [
"Underline",
"Quill",
"attribute",
"assign",
"the",
"relevant",
"Delta",
"class",
"and",
"set",
"up",
"the",
"data"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Html.php#L271-L276 | train |
deanblackborough/php-quill-renderer | src/Delta/Markdown/Compound.php | Compound.tokens | private function tokens(): void
{
foreach ($this->attributes as $attribute => $value) {
switch ($attribute) {
case Options::ATTRIBUTE_BOLD:
$this->tokens[] = Options::MARKDOWN_TOKEN_BOLD;
break;
case Options::ATTRIBUTE_ITALIC:
$this->tokens[] = Options::MARKDOWN_TOKEN_ITALIC;
break;
default:
break;
}
}
} | php | private function tokens(): void
{
foreach ($this->attributes as $attribute => $value) {
switch ($attribute) {
case Options::ATTRIBUTE_BOLD:
$this->tokens[] = Options::MARKDOWN_TOKEN_BOLD;
break;
case Options::ATTRIBUTE_ITALIC:
$this->tokens[] = Options::MARKDOWN_TOKEN_ITALIC;
break;
default:
break;
}
}
} | [
"private",
"function",
"tokens",
"(",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"attribute",
")",
"{",
"case",
"Options",
"::",
"ATTRIBUTE_BOLD",
":... | Convert attributes to tokens | [
"Convert",
"attributes",
"to",
"tokens"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Delta/Markdown/Compound.php#L57-L73 | train |
deanblackborough/php-quill-renderer | src/Parser/Parse.php | Parse.splitInsertsByNewline | public function splitInsertsByNewline(array $inserts): array
{
$new_deltas = [];
foreach ($inserts as $insert) {
if ($insert['insert'] !== null) {
// Check to see if we are dealing with a media based insert
if (is_array($insert['insert']) === false) {
// We only want to split if there are no attributes
if (array_key_exists('attributes', $insert) === false) {
// First check for multiple newlines
if (preg_match("/[\n]{2,}/", $insert['insert']) !== 0) {
$multiple_matches = preg_split("/[\n]{2,}/", $insert['insert']);
foreach ($multiple_matches as $k => $match) {
$newlines = true;
if ($k === count($multiple_matches) - 1) {
$newlines = false;
}
// Now check for single new matches
if (preg_match("/[\n]{1}/", $match) !== 0) {
$new_deltas = array_merge(
$new_deltas,
$this->splitOnSingleNewlineOccurrences($match, $newlines)
);
} else {
$new_deltas[] = ['insert' => $match . ($newlines === true ? "\n\n" : null)];
}
}
} else {
// No multiple newlines detected, check for single new line matches
if (preg_match("/[\n]{1}/", $insert['insert']) !== 0) {
$new_deltas = array_merge(
$new_deltas,
$this->splitOnSingleNewlineOccurrences($insert['insert'])
);
} else {
$new_deltas[] = $insert;
}
}
} else {
// Attributes, for now return unaffected
$new_deltas[] = $insert;
}
} else {
// Media based insert, return unaffected
$new_deltas[] = $insert;
}
}
}
return $new_deltas;
} | php | public function splitInsertsByNewline(array $inserts): array
{
$new_deltas = [];
foreach ($inserts as $insert) {
if ($insert['insert'] !== null) {
// Check to see if we are dealing with a media based insert
if (is_array($insert['insert']) === false) {
// We only want to split if there are no attributes
if (array_key_exists('attributes', $insert) === false) {
// First check for multiple newlines
if (preg_match("/[\n]{2,}/", $insert['insert']) !== 0) {
$multiple_matches = preg_split("/[\n]{2,}/", $insert['insert']);
foreach ($multiple_matches as $k => $match) {
$newlines = true;
if ($k === count($multiple_matches) - 1) {
$newlines = false;
}
// Now check for single new matches
if (preg_match("/[\n]{1}/", $match) !== 0) {
$new_deltas = array_merge(
$new_deltas,
$this->splitOnSingleNewlineOccurrences($match, $newlines)
);
} else {
$new_deltas[] = ['insert' => $match . ($newlines === true ? "\n\n" : null)];
}
}
} else {
// No multiple newlines detected, check for single new line matches
if (preg_match("/[\n]{1}/", $insert['insert']) !== 0) {
$new_deltas = array_merge(
$new_deltas,
$this->splitOnSingleNewlineOccurrences($insert['insert'])
);
} else {
$new_deltas[] = $insert;
}
}
} else {
// Attributes, for now return unaffected
$new_deltas[] = $insert;
}
} else {
// Media based insert, return unaffected
$new_deltas[] = $insert;
}
}
}
return $new_deltas;
} | [
"public",
"function",
"splitInsertsByNewline",
"(",
"array",
"$",
"inserts",
")",
":",
"array",
"{",
"$",
"new_deltas",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"inserts",
"as",
"$",
"insert",
")",
"{",
"if",
"(",
"$",
"insert",
"[",
"'insert'",
"]",
... | Iterate over the deltas, create new deltas each time a new line is found,
this should make it simpler o work out which delta belongs to which attribute
@param array $inserts
@return array | [
"Iterate",
"over",
"the",
"deltas",
"create",
"new",
"deltas",
"each",
"time",
"a",
"new",
"line",
"is",
"found",
"this",
"should",
"make",
"it",
"simpler",
"o",
"work",
"out",
"which",
"delta",
"belongs",
"to",
"which",
"attribute"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Parse.php#L138-L197 | train |
deanblackborough/php-quill-renderer | src/Parser/Parse.php | Parse.splitOnSingleNewlineOccurrences | public function splitOnSingleNewlineOccurrences(string $insert, bool $newlines = false): array
{
$new_deltas = [];
$single_matches = preg_split("/[\n]{1,}/", $insert);
foreach ($single_matches as $k => $sub_match) {
$final_append = null;
if ($k === count($single_matches) - 1 && $newlines === true) {
$final_append = "\n\n";
}
$append = null;
if ($k !== count($single_matches) - 1) {
$append = "\n";
}
$new_deltas[] = [
'insert' => $sub_match . ($final_append !== null ? $final_append : $append)
];
}
return $new_deltas;
} | php | public function splitOnSingleNewlineOccurrences(string $insert, bool $newlines = false): array
{
$new_deltas = [];
$single_matches = preg_split("/[\n]{1,}/", $insert);
foreach ($single_matches as $k => $sub_match) {
$final_append = null;
if ($k === count($single_matches) - 1 && $newlines === true) {
$final_append = "\n\n";
}
$append = null;
if ($k !== count($single_matches) - 1) {
$append = "\n";
}
$new_deltas[] = [
'insert' => $sub_match . ($final_append !== null ? $final_append : $append)
];
}
return $new_deltas;
} | [
"public",
"function",
"splitOnSingleNewlineOccurrences",
"(",
"string",
"$",
"insert",
",",
"bool",
"$",
"newlines",
"=",
"false",
")",
":",
"array",
"{",
"$",
"new_deltas",
"=",
"[",
"]",
";",
"$",
"single_matches",
"=",
"preg_split",
"(",
"\"/[\\n]{1,}/\"",
... | Check and split on single new line occurrences
@param string $insert
@param boolean $newlines Append multiple new lines
@return array | [
"Check",
"and",
"split",
"on",
"single",
"new",
"line",
"occurrences"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Parse.php#L207-L231 | train |
deanblackborough/php-quill-renderer | src/Parser/Parse.php | Parse.attributeBold | public function attributeBold(array $quill)
{
if ($quill['attributes'][OPTIONS::ATTRIBUTE_BOLD] === true) {
$this->deltas[] = new $this->class_delta_bold($quill['insert'], $quill['attributes']);
}
} | php | public function attributeBold(array $quill)
{
if ($quill['attributes'][OPTIONS::ATTRIBUTE_BOLD] === true) {
$this->deltas[] = new $this->class_delta_bold($quill['insert'], $quill['attributes']);
}
} | [
"public",
"function",
"attributeBold",
"(",
"array",
"$",
"quill",
")",
"{",
"if",
"(",
"$",
"quill",
"[",
"'attributes'",
"]",
"[",
"OPTIONS",
"::",
"ATTRIBUTE_BOLD",
"]",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"deltas",
"[",
"]",
"=",
"new",
"... | Bold Quill attribute, assign the relevant Delta class and set up the data
@param array $quill
@return void | [
"Bold",
"Quill",
"attribute",
"assign",
"the",
"relevant",
"Delta",
"class",
"and",
"set",
"up",
"the",
"data"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Parse.php#L384-L389 | train |
deanblackborough/php-quill-renderer | src/Parser/Parse.php | Parse.attributeItalic | public function attributeItalic(array $quill)
{
if ($quill['attributes'][OPTIONS::ATTRIBUTE_ITALIC] === true) {
$this->deltas[] = new $this->class_delta_italic($quill['insert'], $quill['attributes']);
}
} | php | public function attributeItalic(array $quill)
{
if ($quill['attributes'][OPTIONS::ATTRIBUTE_ITALIC] === true) {
$this->deltas[] = new $this->class_delta_italic($quill['insert'], $quill['attributes']);
}
} | [
"public",
"function",
"attributeItalic",
"(",
"array",
"$",
"quill",
")",
"{",
"if",
"(",
"$",
"quill",
"[",
"'attributes'",
"]",
"[",
"OPTIONS",
"::",
"ATTRIBUTE_ITALIC",
"]",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"deltas",
"[",
"]",
"=",
"new",... | Italic Quill attribute, assign the relevant Delta class and set up the data
@param array $quill
@return void | [
"Italic",
"Quill",
"attribute",
"assign",
"the",
"relevant",
"Delta",
"class",
"and",
"set",
"up",
"the",
"data"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Parse.php#L424-L429 | train |
deanblackborough/php-quill-renderer | src/Parser/Parse.php | Parse.attributeLink | public function attributeLink(array $quill)
{
if (strlen($quill['attributes'][OPTIONS::ATTRIBUTE_LINK]) > 0) {
$this->deltas[] = new $this->class_delta_link(
$quill['insert'],
$quill['attributes']
);
}
} | php | public function attributeLink(array $quill)
{
if (strlen($quill['attributes'][OPTIONS::ATTRIBUTE_LINK]) > 0) {
$this->deltas[] = new $this->class_delta_link(
$quill['insert'],
$quill['attributes']
);
}
} | [
"public",
"function",
"attributeLink",
"(",
"array",
"$",
"quill",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"quill",
"[",
"'attributes'",
"]",
"[",
"OPTIONS",
"::",
"ATTRIBUTE_LINK",
"]",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"deltas",
"[",
"]"... | Link Quill attribute, assign the relevant Delta class and set up the data
@param array $quill
@return void | [
"Link",
"Quill",
"attribute",
"assign",
"the",
"relevant",
"Delta",
"class",
"and",
"set",
"up",
"the",
"data"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Parse.php#L438-L446 | train |
deanblackborough/php-quill-renderer | src/Parser/Parse.php | Parse.attributeStrike | public function attributeStrike(array $quill)
{
if ($quill['attributes'][OPTIONS::ATTRIBUTE_STRIKE] === true) {
$this->deltas[] = new $this->class_delta_strike($quill['insert'], $quill['attributes']);
}
} | php | public function attributeStrike(array $quill)
{
if ($quill['attributes'][OPTIONS::ATTRIBUTE_STRIKE] === true) {
$this->deltas[] = new $this->class_delta_strike($quill['insert'], $quill['attributes']);
}
} | [
"public",
"function",
"attributeStrike",
"(",
"array",
"$",
"quill",
")",
"{",
"if",
"(",
"$",
"quill",
"[",
"'attributes'",
"]",
"[",
"OPTIONS",
"::",
"ATTRIBUTE_STRIKE",
"]",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"deltas",
"[",
"]",
"=",
"new",... | Strike Quill attribute, assign the relevant Delta class and set up the data
@param array $quill
@return void | [
"Strike",
"Quill",
"attribute",
"assign",
"the",
"relevant",
"Delta",
"class",
"and",
"set",
"up",
"the",
"data"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Parse.php#L455-L460 | train |
deanblackborough/php-quill-renderer | src/Parser/Parse.php | Parse.insert | public function insert(array $quill)
{
$this->deltas[] = new $this->class_delta_insert(
$quill['insert'],
(array_key_exists('attributes', $quill) ? $quill['attributes'] : [])
);
} | php | public function insert(array $quill)
{
$this->deltas[] = new $this->class_delta_insert(
$quill['insert'],
(array_key_exists('attributes', $quill) ? $quill['attributes'] : [])
);
} | [
"public",
"function",
"insert",
"(",
"array",
"$",
"quill",
")",
"{",
"$",
"this",
"->",
"deltas",
"[",
"]",
"=",
"new",
"$",
"this",
"->",
"class_delta_insert",
"(",
"$",
"quill",
"[",
"'insert'",
"]",
",",
"(",
"array_key_exists",
"(",
"'attributes'",
... | Basic Quill insert
@param array $quill
@return void | [
"Basic",
"Quill",
"insert"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Parse.php#L481-L487 | train |
deanblackborough/php-quill-renderer | src/Parser/Parse.php | Parse.isValidDeltaJson | private function isValidDeltaJson($quill_json): bool
{
if (is_array($quill_json) === false) {
return false;
}
if (count($quill_json) === 0) {
return false;
}
if (array_key_exists('ops', $quill_json) === false) {
return false;
}
return true;
} | php | private function isValidDeltaJson($quill_json): bool
{
if (is_array($quill_json) === false) {
return false;
}
if (count($quill_json) === 0) {
return false;
}
if (array_key_exists('ops', $quill_json) === false) {
return false;
}
return true;
} | [
"private",
"function",
"isValidDeltaJson",
"(",
"$",
"quill_json",
")",
":",
"bool",
"{",
"if",
"(",
"is_array",
"(",
"$",
"quill_json",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"quill_json",
")",
"===",... | Checks the delta json is valid and can be decoded
@param $quill_json Quill json string
@return boolean | [
"Checks",
"the",
"delta",
"json",
"is",
"valid",
"and",
"can",
"be",
"decoded"
] | 78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da | https://github.com/deanblackborough/php-quill-renderer/blob/78bb8bb80ca8d7f6613c7b41a6e1adf104e5c7da/src/Parser/Parse.php#L508-L521 | train |
Happyr/LinkedIn-API-client | src/Authenticator.php | Authenticator.getCode | protected function getCode()
{
$storage = $this->getStorage();
if (!GlobalVariableGetter::has('code')) {
return;
}
if ($storage->get('code') === GlobalVariableGetter::get('code')) {
//we have already validated this code
return;
}
// if stored state does not exists
if (null === $state = $storage->get('state')) {
throw new LinkedInException('Could not find a stored CSRF state token.');
}
// if state not exists in the request
if (!GlobalVariableGetter::has('state')) {
throw new LinkedInException('Could not find a CSRF state token in the request.');
}
// if state exists in session and in request and if they are not equal
if ($state !== GlobalVariableGetter::get('state')) {
throw new LinkedInException('The CSRF state token from the request does not match the stored token.');
}
// CSRF state has done its job, so clear it
$storage->clear('state');
return GlobalVariableGetter::get('code');
} | php | protected function getCode()
{
$storage = $this->getStorage();
if (!GlobalVariableGetter::has('code')) {
return;
}
if ($storage->get('code') === GlobalVariableGetter::get('code')) {
//we have already validated this code
return;
}
// if stored state does not exists
if (null === $state = $storage->get('state')) {
throw new LinkedInException('Could not find a stored CSRF state token.');
}
// if state not exists in the request
if (!GlobalVariableGetter::has('state')) {
throw new LinkedInException('Could not find a CSRF state token in the request.');
}
// if state exists in session and in request and if they are not equal
if ($state !== GlobalVariableGetter::get('state')) {
throw new LinkedInException('The CSRF state token from the request does not match the stored token.');
}
// CSRF state has done its job, so clear it
$storage->clear('state');
return GlobalVariableGetter::get('code');
} | [
"protected",
"function",
"getCode",
"(",
")",
"{",
"$",
"storage",
"=",
"$",
"this",
"->",
"getStorage",
"(",
")",
";",
"if",
"(",
"!",
"GlobalVariableGetter",
"::",
"has",
"(",
"'code'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"storage",
... | Get the authorization code from the query parameters, if it exists,
and otherwise return null to signal no authorization code was
discovered.
@return string|null The authorization code, or null if the authorization code not exists.
@throws LinkedInException on invalid CSRF tokens | [
"Get",
"the",
"authorization",
"code",
"from",
"the",
"query",
"parameters",
"if",
"it",
"exists",
"and",
"otherwise",
"return",
"null",
"to",
"signal",
"no",
"authorization",
"code",
"was",
"discovered",
"."
] | 58bb3bca346e2c709f5aa474c75a9bca6d91ad9a | https://github.com/Happyr/LinkedIn-API-client/blob/58bb3bca346e2c709f5aa474c75a9bca6d91ad9a/src/Authenticator.php#L188-L220 | train |
Happyr/LinkedIn-API-client | src/LinkedIn.php | LinkedIn.filterRequestOption | protected function filterRequestOption(array &$options)
{
if (isset($options['json'])) {
$options['format'] = 'json';
$options['body'] = json_encode($options['json']);
} elseif (!isset($options['format'])) {
// Make sure we always have a format
$options['format'] = $this->getFormat();
}
// Set correct headers for this format
switch ($options['format']) {
case 'xml':
$options['headers']['Content-Type'] = 'text/xml';
break;
case 'json':
$options['headers']['Content-Type'] = 'application/json';
$options['headers']['x-li-format'] = 'json';
$options['query']['format'] = 'json';
break;
default:
// Do nothing
}
return $options['format'];
} | php | protected function filterRequestOption(array &$options)
{
if (isset($options['json'])) {
$options['format'] = 'json';
$options['body'] = json_encode($options['json']);
} elseif (!isset($options['format'])) {
// Make sure we always have a format
$options['format'] = $this->getFormat();
}
// Set correct headers for this format
switch ($options['format']) {
case 'xml':
$options['headers']['Content-Type'] = 'text/xml';
break;
case 'json':
$options['headers']['Content-Type'] = 'application/json';
$options['headers']['x-li-format'] = 'json';
$options['query']['format'] = 'json';
break;
default:
// Do nothing
}
return $options['format'];
} | [
"protected",
"function",
"filterRequestOption",
"(",
"array",
"&",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'json'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'format'",
"]",
"=",
"'json'",
";",
"$",
"options",
"[",
"'... | Modify and filter the request options. Make sure we use the correct query parameters and headers.
@param array &$options
@return string the request format to use | [
"Modify",
"and",
"filter",
"the",
"request",
"options",
".",
"Make",
"sure",
"we",
"use",
"the",
"correct",
"query",
"parameters",
"and",
"headers",
"."
] | 58bb3bca346e2c709f5aa474c75a9bca6d91ad9a | https://github.com/Happyr/LinkedIn-API-client/blob/58bb3bca346e2c709f5aa474c75a9bca6d91ad9a/src/LinkedIn.php#L143-L168 | train |
Happyr/LinkedIn-API-client | src/Storage/BaseDataStorage.php | BaseDataStorage.validateKey | protected function validateKey($key)
{
if (!in_array($key, self::$validKeys)) {
throw new InvalidArgumentException('Unsupported key "%s" passed to LinkedIn data storage. Valid keys are: %s', $key, implode(', ', self::$validKeys));
}
} | php | protected function validateKey($key)
{
if (!in_array($key, self::$validKeys)) {
throw new InvalidArgumentException('Unsupported key "%s" passed to LinkedIn data storage. Valid keys are: %s', $key, implode(', ', self::$validKeys));
}
} | [
"protected",
"function",
"validateKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"self",
"::",
"$",
"validKeys",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Unsupported key \"%s\" passed to LinkedIn data ... | Validate key. Throws an exception if key is not valid.
@param string $key
@throws InvalidArgumentException | [
"Validate",
"key",
".",
"Throws",
"an",
"exception",
"if",
"key",
"is",
"not",
"valid",
"."
] | 58bb3bca346e2c709f5aa474c75a9bca6d91ad9a | https://github.com/Happyr/LinkedIn-API-client/blob/58bb3bca346e2c709f5aa474c75a9bca6d91ad9a/src/Storage/BaseDataStorage.php#L31-L36 | train |
Happyr/LinkedIn-API-client | src/Http/ResponseConverter.php | ResponseConverter.convert | public static function convert(ResponseInterface $response, $requestFormat, $dataType)
{
if (($requestFormat === 'json' && $dataType === 'simple_xml') ||
($requestFormat === 'xml' && $dataType === 'array')) {
throw new InvalidArgumentException('Can not use reponse data format "%s" with the request format "%s".', $dataType, $requestFormat);
}
switch ($dataType) {
case 'array':
return self::convertToArray($response);
case 'string':
return $response->getBody()->__toString();
case 'simple_xml':
return self::convertToSimpleXml($response);
case 'stream':
return $response->getBody();
case 'psr7':
return $response;
default:
throw new InvalidArgumentException('Format "%s" is not supported', $dataType);
}
} | php | public static function convert(ResponseInterface $response, $requestFormat, $dataType)
{
if (($requestFormat === 'json' && $dataType === 'simple_xml') ||
($requestFormat === 'xml' && $dataType === 'array')) {
throw new InvalidArgumentException('Can not use reponse data format "%s" with the request format "%s".', $dataType, $requestFormat);
}
switch ($dataType) {
case 'array':
return self::convertToArray($response);
case 'string':
return $response->getBody()->__toString();
case 'simple_xml':
return self::convertToSimpleXml($response);
case 'stream':
return $response->getBody();
case 'psr7':
return $response;
default:
throw new InvalidArgumentException('Format "%s" is not supported', $dataType);
}
} | [
"public",
"static",
"function",
"convert",
"(",
"ResponseInterface",
"$",
"response",
",",
"$",
"requestFormat",
",",
"$",
"dataType",
")",
"{",
"if",
"(",
"(",
"$",
"requestFormat",
"===",
"'json'",
"&&",
"$",
"dataType",
"===",
"'simple_xml'",
")",
"||",
... | Convert a PSR-7 response to a data type you want to work with.
@param ResponseInterface $response
@param string $requestFormat
@param string $dataType
@return ResponseInterface|\Psr\Http\Message\StreamInterface|\SimpleXMLElement|string
@throws InvalidArgumentException
@throws LinkedInTransferException | [
"Convert",
"a",
"PSR",
"-",
"7",
"response",
"to",
"a",
"data",
"type",
"you",
"want",
"to",
"work",
"with",
"."
] | 58bb3bca346e2c709f5aa474c75a9bca6d91ad9a | https://github.com/Happyr/LinkedIn-API-client/blob/58bb3bca346e2c709f5aa474c75a9bca6d91ad9a/src/Http/ResponseConverter.php#L23-L44 | train |
Happyr/LinkedIn-API-client | src/Http/UrlGenerator.php | UrlGenerator.getHttpProtocol | protected function getHttpProtocol()
{
if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
return 'https';
}
return 'http';
}
/*apache + variants specific way of checking for https*/
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) {
return 'https';
}
/*nginx way of checking for https*/
if (isset($_SERVER['SERVER_PORT']) &&
($_SERVER['SERVER_PORT'] === '443')) {
return 'https';
}
return 'http';
} | php | protected function getHttpProtocol()
{
if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
return 'https';
}
return 'http';
}
/*apache + variants specific way of checking for https*/
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) {
return 'https';
}
/*nginx way of checking for https*/
if (isset($_SERVER['SERVER_PORT']) &&
($_SERVER['SERVER_PORT'] === '443')) {
return 'https';
}
return 'http';
} | [
"protected",
"function",
"getHttpProtocol",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"trustForwarded",
"&&",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_PROTO'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_PROTO'",
"]... | Get the protocol.
@return string | [
"Get",
"the",
"protocol",
"."
] | 58bb3bca346e2c709f5aa474c75a9bca6d91ad9a | https://github.com/Happyr/LinkedIn-API-client/blob/58bb3bca346e2c709f5aa474c75a9bca6d91ad9a/src/Http/UrlGenerator.php#L144-L167 | train |
sabre-io/event | lib/Promise.php | Promise.then | public function then(callable $onFulfilled = null, callable $onRejected = null): Promise
{
// This new subPromise will be returned from this function, and will
// be fulfilled with the result of the onFulfilled or onRejected event
// handlers.
$subPromise = new self();
switch ($this->state) {
case self::PENDING:
// The operation is pending, so we keep a reference to the
// event handlers so we can call them later.
$this->subscribers[] = [$subPromise, $onFulfilled, $onRejected];
break;
case self::FULFILLED:
// The async operation is already fulfilled, so we trigger the
// onFulfilled callback asap.
$this->invokeCallback($subPromise, $onFulfilled);
break;
case self::REJECTED:
// The async operation failed, so we call the onRejected
// callback asap.
$this->invokeCallback($subPromise, $onRejected);
break;
}
return $subPromise;
} | php | public function then(callable $onFulfilled = null, callable $onRejected = null): Promise
{
// This new subPromise will be returned from this function, and will
// be fulfilled with the result of the onFulfilled or onRejected event
// handlers.
$subPromise = new self();
switch ($this->state) {
case self::PENDING:
// The operation is pending, so we keep a reference to the
// event handlers so we can call them later.
$this->subscribers[] = [$subPromise, $onFulfilled, $onRejected];
break;
case self::FULFILLED:
// The async operation is already fulfilled, so we trigger the
// onFulfilled callback asap.
$this->invokeCallback($subPromise, $onFulfilled);
break;
case self::REJECTED:
// The async operation failed, so we call the onRejected
// callback asap.
$this->invokeCallback($subPromise, $onRejected);
break;
}
return $subPromise;
} | [
"public",
"function",
"then",
"(",
"callable",
"$",
"onFulfilled",
"=",
"null",
",",
"callable",
"$",
"onRejected",
"=",
"null",
")",
":",
"Promise",
"{",
"// This new subPromise will be returned from this function, and will",
"// be fulfilled with the result of the onFulfill... | This method allows you to specify the callback that will be called after
the promise has been fulfilled or rejected.
Both arguments are optional.
This method returns a new promise, which can be used for chaining.
If either the onFulfilled or onRejected callback is called, you may
return a result from this callback.
If the result of this callback is yet another promise, the result of
_that_ promise will be used to set the result of the returned promise.
If either of the callbacks return any other value, the returned promise
is automatically fulfilled with that value.
If either of the callbacks throw an exception, the returned promise will
be rejected and the exception will be passed back. | [
"This",
"method",
"allows",
"you",
"to",
"specify",
"the",
"callback",
"that",
"will",
"be",
"called",
"after",
"the",
"promise",
"has",
"been",
"fulfilled",
"or",
"rejected",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Promise.php#L88-L114 | train |
sabre-io/event | lib/Promise.php | Promise.fulfill | public function fulfill($value = null)
{
if (self::PENDING !== $this->state) {
throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once');
}
$this->state = self::FULFILLED;
$this->value = $value;
foreach ($this->subscribers as $subscriber) {
$this->invokeCallback($subscriber[0], $subscriber[1]);
}
} | php | public function fulfill($value = null)
{
if (self::PENDING !== $this->state) {
throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once');
}
$this->state = self::FULFILLED;
$this->value = $value;
foreach ($this->subscribers as $subscriber) {
$this->invokeCallback($subscriber[0], $subscriber[1]);
}
} | [
"public",
"function",
"fulfill",
"(",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"PENDING",
"!==",
"$",
"this",
"->",
"state",
")",
"{",
"throw",
"new",
"PromiseAlreadyResolvedException",
"(",
"'This promise is already resolved, and you\\'re not... | Marks this promise as fulfilled and sets its return value.
@param mixed $value | [
"Marks",
"this",
"promise",
"as",
"fulfilled",
"and",
"sets",
"its",
"return",
"value",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Promise.php#L132-L142 | train |
sabre-io/event | lib/Promise.php | Promise.reject | public function reject(Throwable $reason)
{
if (self::PENDING !== $this->state) {
throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once');
}
$this->state = self::REJECTED;
$this->value = $reason;
foreach ($this->subscribers as $subscriber) {
$this->invokeCallback($subscriber[0], $subscriber[2]);
}
} | php | public function reject(Throwable $reason)
{
if (self::PENDING !== $this->state) {
throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once');
}
$this->state = self::REJECTED;
$this->value = $reason;
foreach ($this->subscribers as $subscriber) {
$this->invokeCallback($subscriber[0], $subscriber[2]);
}
} | [
"public",
"function",
"reject",
"(",
"Throwable",
"$",
"reason",
")",
"{",
"if",
"(",
"self",
"::",
"PENDING",
"!==",
"$",
"this",
"->",
"state",
")",
"{",
"throw",
"new",
"PromiseAlreadyResolvedException",
"(",
"'This promise is already resolved, and you\\'re not a... | Marks this promise as rejected, and set it's rejection reason. | [
"Marks",
"this",
"promise",
"as",
"rejected",
"and",
"set",
"it",
"s",
"rejection",
"reason",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Promise.php#L147-L157 | train |
sabre-io/event | lib/Promise.php | Promise.wait | public function wait()
{
$hasEvents = true;
while (self::PENDING === $this->state) {
if (!$hasEvents) {
throw new \LogicException('There were no more events in the loop. This promise will never be fulfilled.');
}
// As long as the promise is not fulfilled, we tell the event loop
// to handle events, and to block.
$hasEvents = Loop\tick(true);
}
if (self::FULFILLED === $this->state) {
// If the state of this promise is fulfilled, we can return the value.
return $this->value;
} else {
// If we got here, it means that the asynchronous operation
// errored. Therefore we need to throw an exception.
throw $this->value;
}
} | php | public function wait()
{
$hasEvents = true;
while (self::PENDING === $this->state) {
if (!$hasEvents) {
throw new \LogicException('There were no more events in the loop. This promise will never be fulfilled.');
}
// As long as the promise is not fulfilled, we tell the event loop
// to handle events, and to block.
$hasEvents = Loop\tick(true);
}
if (self::FULFILLED === $this->state) {
// If the state of this promise is fulfilled, we can return the value.
return $this->value;
} else {
// If we got here, it means that the asynchronous operation
// errored. Therefore we need to throw an exception.
throw $this->value;
}
} | [
"public",
"function",
"wait",
"(",
")",
"{",
"$",
"hasEvents",
"=",
"true",
";",
"while",
"(",
"self",
"::",
"PENDING",
"===",
"$",
"this",
"->",
"state",
")",
"{",
"if",
"(",
"!",
"$",
"hasEvents",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
... | Stops execution until this promise is resolved.
This method stops execution completely. If the promise is successful with
a value, this method will return this value. If the promise was
rejected, this method will throw an exception.
This effectively turns the asynchronous operation into a synchronous
one. In PHP it might be useful to call this on the last promise in a
chain.
@return mixed | [
"Stops",
"execution",
"until",
"this",
"promise",
"is",
"resolved",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Promise.php#L172-L193 | train |
sabre-io/event | lib/Promise.php | Promise.invokeCallback | private function invokeCallback(Promise $subPromise, callable $callBack = null)
{
// We use 'nextTick' to ensure that the event handlers are always
// triggered outside of the calling stack in which they were originally
// passed to 'then'.
//
// This makes the order of execution more predictable.
Loop\nextTick(function () use ($callBack, $subPromise) {
if (is_callable($callBack)) {
try {
$result = $callBack($this->value);
if ($result instanceof self) {
// If the callback (onRejected or onFulfilled)
// returned a promise, we only fulfill or reject the
// chained promise once that promise has also been
// resolved.
$result->then([$subPromise, 'fulfill'], [$subPromise, 'reject']);
} else {
// If the callback returned any other value, we
// immediately fulfill the chained promise.
$subPromise->fulfill($result);
}
} catch (Throwable $e) {
// If the event handler threw an exception, we need to make sure that
// the chained promise is rejected as well.
$subPromise->reject($e);
}
} else {
if (self::FULFILLED === $this->state) {
$subPromise->fulfill($this->value);
} else {
$subPromise->reject($this->value);
}
}
});
} | php | private function invokeCallback(Promise $subPromise, callable $callBack = null)
{
// We use 'nextTick' to ensure that the event handlers are always
// triggered outside of the calling stack in which they were originally
// passed to 'then'.
//
// This makes the order of execution more predictable.
Loop\nextTick(function () use ($callBack, $subPromise) {
if (is_callable($callBack)) {
try {
$result = $callBack($this->value);
if ($result instanceof self) {
// If the callback (onRejected or onFulfilled)
// returned a promise, we only fulfill or reject the
// chained promise once that promise has also been
// resolved.
$result->then([$subPromise, 'fulfill'], [$subPromise, 'reject']);
} else {
// If the callback returned any other value, we
// immediately fulfill the chained promise.
$subPromise->fulfill($result);
}
} catch (Throwable $e) {
// If the event handler threw an exception, we need to make sure that
// the chained promise is rejected as well.
$subPromise->reject($e);
}
} else {
if (self::FULFILLED === $this->state) {
$subPromise->fulfill($this->value);
} else {
$subPromise->reject($this->value);
}
}
});
} | [
"private",
"function",
"invokeCallback",
"(",
"Promise",
"$",
"subPromise",
",",
"callable",
"$",
"callBack",
"=",
"null",
")",
"{",
"// We use 'nextTick' to ensure that the event handlers are always",
"// triggered outside of the calling stack in which they were originally",
"// p... | This method is used to call either an onFulfilled or onRejected callback.
This method makes sure that the result of these callbacks are handled
correctly, and any chained promises are also correctly fulfilled or
rejected.
@param Promise $subPromise
@param callable $callBack | [
"This",
"method",
"is",
"used",
"to",
"call",
"either",
"an",
"onFulfilled",
"or",
"onRejected",
"callback",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Promise.php#L223-L258 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.setTimeout | public function setTimeout(callable $cb, float $timeout)
{
$triggerTime = microtime(true) + ($timeout);
if (!$this->timers) {
// Special case when the timers array was empty.
$this->timers[] = [$triggerTime, $cb];
return;
}
// We need to insert these values in the timers array, but the timers
// array must be in reverse-order of trigger times.
//
// So here we search the array for the insertion point.
$index = count($this->timers) - 1;
while (true) {
if ($triggerTime < $this->timers[$index][0]) {
array_splice(
$this->timers,
$index + 1,
0,
[[$triggerTime, $cb]]
);
break;
} elseif (0 === $index) {
array_unshift($this->timers, [$triggerTime, $cb]);
break;
}
--$index;
}
} | php | public function setTimeout(callable $cb, float $timeout)
{
$triggerTime = microtime(true) + ($timeout);
if (!$this->timers) {
// Special case when the timers array was empty.
$this->timers[] = [$triggerTime, $cb];
return;
}
// We need to insert these values in the timers array, but the timers
// array must be in reverse-order of trigger times.
//
// So here we search the array for the insertion point.
$index = count($this->timers) - 1;
while (true) {
if ($triggerTime < $this->timers[$index][0]) {
array_splice(
$this->timers,
$index + 1,
0,
[[$triggerTime, $cb]]
);
break;
} elseif (0 === $index) {
array_unshift($this->timers, [$triggerTime, $cb]);
break;
}
--$index;
}
} | [
"public",
"function",
"setTimeout",
"(",
"callable",
"$",
"cb",
",",
"float",
"$",
"timeout",
")",
"{",
"$",
"triggerTime",
"=",
"microtime",
"(",
"true",
")",
"+",
"(",
"$",
"timeout",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"timers",
")",
"{... | Executes a function after x seconds. | [
"Executes",
"a",
"function",
"after",
"x",
"seconds",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L25-L56 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.setInterval | public function setInterval(callable $cb, float $timeout): array
{
$keepGoing = true;
$f = null;
$f = function () use ($cb, &$f, $timeout, &$keepGoing) {
if ($keepGoing) {
$cb();
$this->setTimeout($f, $timeout);
}
};
$this->setTimeout($f, $timeout);
// Really the only thing that matters is returning the $keepGoing
// boolean value.
//
// We need to pack it in an array to allow returning by reference.
// Because I'm worried people will be confused by using a boolean as a
// sort of identifier, I added an extra string.
return ['I\'m an implementation detail', &$keepGoing];
} | php | public function setInterval(callable $cb, float $timeout): array
{
$keepGoing = true;
$f = null;
$f = function () use ($cb, &$f, $timeout, &$keepGoing) {
if ($keepGoing) {
$cb();
$this->setTimeout($f, $timeout);
}
};
$this->setTimeout($f, $timeout);
// Really the only thing that matters is returning the $keepGoing
// boolean value.
//
// We need to pack it in an array to allow returning by reference.
// Because I'm worried people will be confused by using a boolean as a
// sort of identifier, I added an extra string.
return ['I\'m an implementation detail', &$keepGoing];
} | [
"public",
"function",
"setInterval",
"(",
"callable",
"$",
"cb",
",",
"float",
"$",
"timeout",
")",
":",
"array",
"{",
"$",
"keepGoing",
"=",
"true",
";",
"$",
"f",
"=",
"null",
";",
"$",
"f",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"cb",
","... | Executes a function every x seconds.
The value this function returns can be used to stop the interval with
clearInterval. | [
"Executes",
"a",
"function",
"every",
"x",
"seconds",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L64-L84 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.addReadStream | public function addReadStream($stream, callable $cb)
{
$this->readStreams[(int) $stream] = $stream;
$this->readCallbacks[(int) $stream] = $cb;
} | php | public function addReadStream($stream, callable $cb)
{
$this->readStreams[(int) $stream] = $stream;
$this->readCallbacks[(int) $stream] = $cb;
} | [
"public",
"function",
"addReadStream",
"(",
"$",
"stream",
",",
"callable",
"$",
"cb",
")",
"{",
"$",
"this",
"->",
"readStreams",
"[",
"(",
"int",
")",
"$",
"stream",
"]",
"=",
"$",
"stream",
";",
"$",
"this",
"->",
"readCallbacks",
"[",
"(",
"int",... | Adds a read stream.
The callback will be called as soon as there is something to read from
the stream.
You MUST call removeReadStream after you are done with the stream, to
prevent the eventloop from never stopping.
@param resource $stream | [
"Adds",
"a",
"read",
"stream",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L113-L117 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.addWriteStream | public function addWriteStream($stream, callable $cb)
{
$this->writeStreams[(int) $stream] = $stream;
$this->writeCallbacks[(int) $stream] = $cb;
} | php | public function addWriteStream($stream, callable $cb)
{
$this->writeStreams[(int) $stream] = $stream;
$this->writeCallbacks[(int) $stream] = $cb;
} | [
"public",
"function",
"addWriteStream",
"(",
"$",
"stream",
",",
"callable",
"$",
"cb",
")",
"{",
"$",
"this",
"->",
"writeStreams",
"[",
"(",
"int",
")",
"$",
"stream",
"]",
"=",
"$",
"stream",
";",
"$",
"this",
"->",
"writeCallbacks",
"[",
"(",
"in... | Adds a write stream.
The callback will be called as soon as the system reports it's ready to
receive writes on the stream.
You MUST call removeWriteStream after you are done with the stream, to
prevent the eventloop from never stopping.
@param resource $stream | [
"Adds",
"a",
"write",
"stream",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L130-L134 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.removeReadStream | public function removeReadStream($stream)
{
unset(
$this->readStreams[(int) $stream],
$this->readCallbacks[(int) $stream]
);
} | php | public function removeReadStream($stream)
{
unset(
$this->readStreams[(int) $stream],
$this->readCallbacks[(int) $stream]
);
} | [
"public",
"function",
"removeReadStream",
"(",
"$",
"stream",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"readStreams",
"[",
"(",
"int",
")",
"$",
"stream",
"]",
",",
"$",
"this",
"->",
"readCallbacks",
"[",
"(",
"int",
")",
"$",
"stream",
"]",
")",
... | Stop watching a stream for reads.
@param resource $stream | [
"Stop",
"watching",
"a",
"stream",
"for",
"reads",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L141-L147 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.removeWriteStream | public function removeWriteStream($stream)
{
unset(
$this->writeStreams[(int) $stream],
$this->writeCallbacks[(int) $stream]
);
} | php | public function removeWriteStream($stream)
{
unset(
$this->writeStreams[(int) $stream],
$this->writeCallbacks[(int) $stream]
);
} | [
"public",
"function",
"removeWriteStream",
"(",
"$",
"stream",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"writeStreams",
"[",
"(",
"int",
")",
"$",
"stream",
"]",
",",
"$",
"this",
"->",
"writeCallbacks",
"[",
"(",
"int",
")",
"$",
"stream",
"]",
")... | Stop watching a stream for writes.
@param resource $stream | [
"Stop",
"watching",
"a",
"stream",
"for",
"writes",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L154-L160 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.run | public function run()
{
$this->running = true;
do {
$hasEvents = $this->tick(true);
} while ($this->running && $hasEvents);
$this->running = false;
} | php | public function run()
{
$this->running = true;
do {
$hasEvents = $this->tick(true);
} while ($this->running && $hasEvents);
$this->running = false;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"this",
"->",
"running",
"=",
"true",
";",
"do",
"{",
"$",
"hasEvents",
"=",
"$",
"this",
"->",
"tick",
"(",
"true",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"running",
"&&",
"$",
"hasEvents... | Runs the loop.
This function will run continuously, until there's no more events to
handle. | [
"Runs",
"the",
"loop",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L168-L176 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.tick | public function tick(bool $block = false): bool
{
$this->runNextTicks();
$nextTimeout = $this->runTimers();
// Calculating how long runStreams should at most wait.
if (!$block) {
// Don't wait
$streamWait = 0;
} elseif ($this->nextTick) {
// There's a pending 'nextTick'. Don't wait.
$streamWait = 0;
} elseif (is_numeric($nextTimeout)) {
// Wait until the next Timeout should trigger.
$streamWait = $nextTimeout;
} else {
// Wait indefinitely
$streamWait = null;
}
$this->runStreams($streamWait);
return $this->readStreams || $this->writeStreams || $this->nextTick || $this->timers;
} | php | public function tick(bool $block = false): bool
{
$this->runNextTicks();
$nextTimeout = $this->runTimers();
// Calculating how long runStreams should at most wait.
if (!$block) {
// Don't wait
$streamWait = 0;
} elseif ($this->nextTick) {
// There's a pending 'nextTick'. Don't wait.
$streamWait = 0;
} elseif (is_numeric($nextTimeout)) {
// Wait until the next Timeout should trigger.
$streamWait = $nextTimeout;
} else {
// Wait indefinitely
$streamWait = null;
}
$this->runStreams($streamWait);
return $this->readStreams || $this->writeStreams || $this->nextTick || $this->timers;
} | [
"public",
"function",
"tick",
"(",
"bool",
"$",
"block",
"=",
"false",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"runNextTicks",
"(",
")",
";",
"$",
"nextTimeout",
"=",
"$",
"this",
"->",
"runTimers",
"(",
")",
";",
"// Calculating how long runStreams shou... | Executes all pending events.
If $block is turned true, this function will block until any event is
triggered.
If there are now timeouts, nextTick callbacks or events in the loop at
all, this function will exit immediately.
This function will return true if there are _any_ events left in the
loop after the tick. | [
"Executes",
"all",
"pending",
"events",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L190-L213 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.runNextTicks | protected function runNextTicks()
{
$nextTick = $this->nextTick;
$this->nextTick = [];
foreach ($nextTick as $cb) {
$cb();
}
} | php | protected function runNextTicks()
{
$nextTick = $this->nextTick;
$this->nextTick = [];
foreach ($nextTick as $cb) {
$cb();
}
} | [
"protected",
"function",
"runNextTicks",
"(",
")",
"{",
"$",
"nextTick",
"=",
"$",
"this",
"->",
"nextTick",
";",
"$",
"this",
"->",
"nextTick",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"nextTick",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"(",
")",
... | Executes all 'nextTick' callbacks.
return void | [
"Executes",
"all",
"nextTick",
"callbacks",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L228-L236 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.runTimers | protected function runTimers()
{
$now = microtime(true);
while (($timer = array_pop($this->timers)) && $timer[0] < $now) {
$timer[1]();
}
// Add the last timer back to the array.
if ($timer) {
$this->timers[] = $timer;
return max(0, $timer[0] - microtime(true));
}
} | php | protected function runTimers()
{
$now = microtime(true);
while (($timer = array_pop($this->timers)) && $timer[0] < $now) {
$timer[1]();
}
// Add the last timer back to the array.
if ($timer) {
$this->timers[] = $timer;
return max(0, $timer[0] - microtime(true));
}
} | [
"protected",
"function",
"runTimers",
"(",
")",
"{",
"$",
"now",
"=",
"microtime",
"(",
"true",
")",
";",
"while",
"(",
"(",
"$",
"timer",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"timers",
")",
")",
"&&",
"$",
"timer",
"[",
"0",
"]",
"<",
"$",
... | Runs all pending timers.
After running the timer callbacks, this function returns the number of
seconds until the next timer should be executed.
If there's no more pending timers, this function returns null.
@return float|null | [
"Runs",
"all",
"pending",
"timers",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L248-L260 | train |
sabre-io/event | lib/Loop/Loop.php | Loop.runStreams | protected function runStreams($timeout)
{
if ($this->readStreams || $this->writeStreams) {
$read = $this->readStreams;
$write = $this->writeStreams;
$except = null;
if (stream_select($read, $write, $except, (null === $timeout) ? null : 0, $timeout ? (int) ($timeout * 1000000) : 0)) {
// See PHP Bug https://bugs.php.net/bug.php?id=62452
// Fixed in PHP7
foreach ($read as $readStream) {
$readCb = $this->readCallbacks[(int) $readStream];
$readCb();
}
foreach ($write as $writeStream) {
$writeCb = $this->writeCallbacks[(int) $writeStream];
$writeCb();
}
}
} elseif ($this->running && ($this->nextTick || $this->timers)) {
usleep(null !== $timeout ? intval($timeout * 1000000) : 200000);
}
} | php | protected function runStreams($timeout)
{
if ($this->readStreams || $this->writeStreams) {
$read = $this->readStreams;
$write = $this->writeStreams;
$except = null;
if (stream_select($read, $write, $except, (null === $timeout) ? null : 0, $timeout ? (int) ($timeout * 1000000) : 0)) {
// See PHP Bug https://bugs.php.net/bug.php?id=62452
// Fixed in PHP7
foreach ($read as $readStream) {
$readCb = $this->readCallbacks[(int) $readStream];
$readCb();
}
foreach ($write as $writeStream) {
$writeCb = $this->writeCallbacks[(int) $writeStream];
$writeCb();
}
}
} elseif ($this->running && ($this->nextTick || $this->timers)) {
usleep(null !== $timeout ? intval($timeout * 1000000) : 200000);
}
} | [
"protected",
"function",
"runStreams",
"(",
"$",
"timeout",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"readStreams",
"||",
"$",
"this",
"->",
"writeStreams",
")",
"{",
"$",
"read",
"=",
"$",
"this",
"->",
"readStreams",
";",
"$",
"write",
"=",
"$",
"th... | Runs all pending stream events.
If $timeout is 0, it will return immediately. If $timeout is null, it
will wait indefinitely.
@param float|null timeout | [
"Runs",
"all",
"pending",
"stream",
"events",
"."
] | 09c9c03c9b8f6917257cf4bed40b0dc49743ded9 | https://github.com/sabre-io/event/blob/09c9c03c9b8f6917257cf4bed40b0dc49743ded9/lib/Loop/Loop.php#L270-L291 | train |
JorgenPhi/php-snapchat | src/snapchat_agent.php | SnapchatAgent.pad | public function pad($data, $blocksize = 16) {
$pad = $blocksize - (strlen($data) % $blocksize);
return $data . str_repeat(chr($pad), $pad);
} | php | public function pad($data, $blocksize = 16) {
$pad = $blocksize - (strlen($data) % $blocksize);
return $data . str_repeat(chr($pad), $pad);
} | [
"public",
"function",
"pad",
"(",
"$",
"data",
",",
"$",
"blocksize",
"=",
"16",
")",
"{",
"$",
"pad",
"=",
"$",
"blocksize",
"-",
"(",
"strlen",
"(",
"$",
"data",
")",
"%",
"$",
"blocksize",
")",
";",
"return",
"$",
"data",
".",
"str_repeat",
"(... | Pads data using PKCS5.
@param data $data
The data to be padded.
@param int $blocksize
The block size to pad to. Defaults to 16.
@return data
The padded data. | [
"Pads",
"data",
"using",
"PKCS5",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat_agent.php#L81-L84 | train |
JorgenPhi/php-snapchat | src/snapchat_agent.php | SnapchatAgent.decryptECB | public function decryptECB($data) {
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, self::BLOB_ENCRYPTION_KEY, self::pad($data), MCRYPT_MODE_ECB);
} | php | public function decryptECB($data) {
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, self::BLOB_ENCRYPTION_KEY, self::pad($data), MCRYPT_MODE_ECB);
} | [
"public",
"function",
"decryptECB",
"(",
"$",
"data",
")",
"{",
"return",
"mcrypt_decrypt",
"(",
"MCRYPT_RIJNDAEL_128",
",",
"self",
"::",
"BLOB_ENCRYPTION_KEY",
",",
"self",
"::",
"pad",
"(",
"$",
"data",
")",
",",
"MCRYPT_MODE_ECB",
")",
";",
"}"
] | Decrypts blob data for standard images and videos.
@param data $data
The data to decrypt.
@return data
The decrypted data. | [
"Decrypts",
"blob",
"data",
"for",
"standard",
"images",
"and",
"videos",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat_agent.php#L95-L97 | train |
JorgenPhi/php-snapchat | src/snapchat_agent.php | SnapchatAgent.encryptECB | public function encryptECB($data) {
return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, self::BLOB_ENCRYPTION_KEY, self::pad($data), MCRYPT_MODE_ECB);
} | php | public function encryptECB($data) {
return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, self::BLOB_ENCRYPTION_KEY, self::pad($data), MCRYPT_MODE_ECB);
} | [
"public",
"function",
"encryptECB",
"(",
"$",
"data",
")",
"{",
"return",
"mcrypt_encrypt",
"(",
"MCRYPT_RIJNDAEL_128",
",",
"self",
"::",
"BLOB_ENCRYPTION_KEY",
",",
"self",
"::",
"pad",
"(",
"$",
"data",
")",
",",
"MCRYPT_MODE_ECB",
")",
";",
"}"
] | Encrypts blob data for standard images and videos.
@param data $data
The data to encrypt.
@return data
The encrypted data. | [
"Encrypts",
"blob",
"data",
"for",
"standard",
"images",
"and",
"videos",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat_agent.php#L108-L110 | train |
JorgenPhi/php-snapchat | src/snapchat_agent.php | SnapchatAgent.decryptCBC | public function decryptCBC($data, $key, $iv) {
// Decode the key and IV.
$iv = base64_decode($iv);
$key = base64_decode($key);
// Decrypt the data.
$data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);
$padding = ord($data[strlen($data) - 1]);
return substr($data, 0, -$padding);
} | php | public function decryptCBC($data, $key, $iv) {
// Decode the key and IV.
$iv = base64_decode($iv);
$key = base64_decode($key);
// Decrypt the data.
$data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);
$padding = ord($data[strlen($data) - 1]);
return substr($data, 0, -$padding);
} | [
"public",
"function",
"decryptCBC",
"(",
"$",
"data",
",",
"$",
"key",
",",
"$",
"iv",
")",
"{",
"// Decode the key and IV.",
"$",
"iv",
"=",
"base64_decode",
"(",
"$",
"iv",
")",
";",
"$",
"key",
"=",
"base64_decode",
"(",
"$",
"key",
")",
";",
"// ... | Decrypts blob data for stories.
@param data $data
The data to decrypt.
@param string $key
The base64-encoded key.
@param string $iv
$iv The base64-encoded IV.
@return data
The decrypted data. | [
"Decrypts",
"blob",
"data",
"for",
"stories",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat_agent.php#L125-L135 | train |
JorgenPhi/php-snapchat | src/snapchat_agent.php | SnapchatAgent.hash | public function hash($first, $second) {
// Append the secret to the values.
$first = self::SECRET . $first;
$second = $second . self::SECRET;
// Hash the values.
$hash = hash_init('sha256');
hash_update($hash, $first);
$hash1 = hash_final($hash);
$hash = hash_init('sha256');
hash_update($hash, $second);
$hash2 = hash_final($hash);
// Create a new hash with pieces of the two we just made.
$result = '';
for ($i = 0; $i < strlen(self::HASH_PATTERN); $i++) {
$result .= substr(self::HASH_PATTERN, $i, 1) ? $hash2[$i] : $hash1[$i];
}
return $result;
} | php | public function hash($first, $second) {
// Append the secret to the values.
$first = self::SECRET . $first;
$second = $second . self::SECRET;
// Hash the values.
$hash = hash_init('sha256');
hash_update($hash, $first);
$hash1 = hash_final($hash);
$hash = hash_init('sha256');
hash_update($hash, $second);
$hash2 = hash_final($hash);
// Create a new hash with pieces of the two we just made.
$result = '';
for ($i = 0; $i < strlen(self::HASH_PATTERN); $i++) {
$result .= substr(self::HASH_PATTERN, $i, 1) ? $hash2[$i] : $hash1[$i];
}
return $result;
} | [
"public",
"function",
"hash",
"(",
"$",
"first",
",",
"$",
"second",
")",
"{",
"// Append the secret to the values.",
"$",
"first",
"=",
"self",
"::",
"SECRET",
".",
"$",
"first",
";",
"$",
"second",
"=",
"$",
"second",
".",
"self",
"::",
"SECRET",
";",
... | Implementation of Snapchat's hashing algorithm.
@param string $first
The first value to use in the hash.
@param string $second
The second value to use in the hash.
@return string
The generated hash. | [
"Implementation",
"of",
"Snapchat",
"s",
"hashing",
"algorithm",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat_agent.php#L148-L168 | train |
JorgenPhi/php-snapchat | src/snapchat_agent.php | SnapchatAgent.isMedia | function isMedia($data) {
// Check for a JPG header.
if ($data[0] == chr(0xFF) && $data[1] == chr(0xD8)) {
return TRUE;
}
// Check for a MP4 header.
if ($data[0] == chr(0x00) && $data[1] == chr(0x00)) {
return TRUE;
}
return FALSE;
} | php | function isMedia($data) {
// Check for a JPG header.
if ($data[0] == chr(0xFF) && $data[1] == chr(0xD8)) {
return TRUE;
}
// Check for a MP4 header.
if ($data[0] == chr(0x00) && $data[1] == chr(0x00)) {
return TRUE;
}
return FALSE;
} | [
"function",
"isMedia",
"(",
"$",
"data",
")",
"{",
"// Check for a JPG header.",
"if",
"(",
"$",
"data",
"[",
"0",
"]",
"==",
"chr",
"(",
"0xFF",
")",
"&&",
"$",
"data",
"[",
"1",
"]",
"==",
"chr",
"(",
"0xD8",
")",
")",
"{",
"return",
"TRUE",
";... | Checks to see if a blob looks like a media file.
@param data $data
The blob data (or just the header).
@return bool
TRUE if the blob looks like a media file, FALSE otherwise. | [
"Checks",
"to",
"see",
"if",
"a",
"blob",
"looks",
"like",
"a",
"media",
"file",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat_agent.php#L179-L191 | train |
JorgenPhi/php-snapchat | src/snapchat_agent.php | SnapchatAgent.post | public function post($endpoint, $data, $params, $multipart = FALSE) {
$ch = curl_init();
$data['req_token'] = self::hash($params[0], $params[1]);
$data['version'] = self::VERSION;
if (!$multipart) {
$data = http_build_query($data);
}
$options = self::$CURL_OPTIONS + array(
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $data,
CURLOPT_URL => self::URL . $endpoint,
CURLOPT_HTTPHEADER => array(
'Accept-Language: en-GB;q=1, en;q=0.9',
'Accept-Locale: en'
),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
// If cURL doesn't have a bundle of root certificates handy, we provide
// ours (see http://curl.haxx.se/docs/sslcerts.html).
if (curl_errno($ch) == 60) {
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ca_bundle.crt');
$result = curl_exec($ch);
}
// If the cURL request fails, return FALSE. Also check the status code
// since the API generally won't return friendly errors.
if ($result === FALSE || curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200) {
curl_close($ch);
return FALSE;
}
curl_close($ch);
if ($endpoint == '/blob') {
return $result;
}
// Add support for foreign characters in the JSON response.
$result = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($result));
$data = json_decode($result);
return json_last_error() == JSON_ERROR_NONE ? $data : FALSE;
} | php | public function post($endpoint, $data, $params, $multipart = FALSE) {
$ch = curl_init();
$data['req_token'] = self::hash($params[0], $params[1]);
$data['version'] = self::VERSION;
if (!$multipart) {
$data = http_build_query($data);
}
$options = self::$CURL_OPTIONS + array(
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $data,
CURLOPT_URL => self::URL . $endpoint,
CURLOPT_HTTPHEADER => array(
'Accept-Language: en-GB;q=1, en;q=0.9',
'Accept-Locale: en'
),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
// If cURL doesn't have a bundle of root certificates handy, we provide
// ours (see http://curl.haxx.se/docs/sslcerts.html).
if (curl_errno($ch) == 60) {
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ca_bundle.crt');
$result = curl_exec($ch);
}
// If the cURL request fails, return FALSE. Also check the status code
// since the API generally won't return friendly errors.
if ($result === FALSE || curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200) {
curl_close($ch);
return FALSE;
}
curl_close($ch);
if ($endpoint == '/blob') {
return $result;
}
// Add support for foreign characters in the JSON response.
$result = iconv('UTF-8', 'UTF-8//IGNORE', utf8_encode($result));
$data = json_decode($result);
return json_last_error() == JSON_ERROR_NONE ? $data : FALSE;
} | [
"public",
"function",
"post",
"(",
"$",
"endpoint",
",",
"$",
"data",
",",
"$",
"params",
",",
"$",
"multipart",
"=",
"FALSE",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"$",
"data",
"[",
"'req_token'",
"]",
"=",
"self",
"::",
"hash",
... | Performs a POST request. Used for pretty much everything.
@todo
Replace the blob endpoint check with a more robust check for
application/octet-stream.
@param string $endpoint
The address of the resource being requested (e.g. '/update_snaps' or
'/friend').
@param array $data
An dictionary of values to send to the API. A request token is added
automatically.
@param array $params
An array containing the parameters used to generate the request token.
@param bool $multipart
If TRUE, sends the request as multipart/form-data. Defaults to FALSE.
@return mixed
The data returned from the API (decoded if JSON). Returns FALSE if
the request failed. | [
"Performs",
"a",
"POST",
"request",
".",
"Used",
"for",
"pretty",
"much",
"everything",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat_agent.php#L285-L333 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.login | public function login($username, $password) {
$timestamp = parent::timestamp();
$result = parent::post(
'/login',
array(
'username' => $username,
'password' => $password,
'timestamp' => $timestamp,
),
array(
parent::STATIC_TOKEN,
$timestamp,
)
);
// If the login is successful, set the username and auth_token.
if (isset($result->logged) && $result->logged) {
$this->auth_token = $result->auth_token;
$this->username = $result->username;
$this->cache = new SnapchatCache();
$this->cache->set('updates', $result);
return $result;
}
else {
return FALSE;
}
} | php | public function login($username, $password) {
$timestamp = parent::timestamp();
$result = parent::post(
'/login',
array(
'username' => $username,
'password' => $password,
'timestamp' => $timestamp,
),
array(
parent::STATIC_TOKEN,
$timestamp,
)
);
// If the login is successful, set the username and auth_token.
if (isset($result->logged) && $result->logged) {
$this->auth_token = $result->auth_token;
$this->username = $result->username;
$this->cache = new SnapchatCache();
$this->cache->set('updates', $result);
return $result;
}
else {
return FALSE;
}
} | [
"public",
"function",
"login",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"$",
"timestamp",
"=",
"parent",
"::",
"timestamp",
"(",
")",
";",
"$",
"result",
"=",
"parent",
"::",
"post",
"(",
"'/login'",
",",
"array",
"(",
"'username'",
"=>",
... | Handles login.
@param string $username
The username for the Snapchat account.
@param string $password
The password associated with the username.
@return mixed
The data returned by the service or FALSE if the request failed.
Generally, returns the same result as self::getUpdates(). | [
"Handles",
"login",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L93-L121 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.register | public function register($username, $password, $email, $birthday) {
$timestamp = parent::timestamp();
$result = parent::post(
'/register',
array(
'birthday' => $birthday,
'password' => $password,
'email' => $email,
'timestamp' => $timestamp,
),
array(
parent::STATIC_TOKEN,
$timestamp,
)
);
if (!isset($result->token)) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/registeru',
array(
'email' => $email,
'username' => $username,
'timestamp' => $timestamp,
),
array(
parent::STATIC_TOKEN,
$timestamp,
)
);
// If registration is successful, set the username and auth_token.
if (isset($result->logged) && $result->logged) {
$this->auth_token = $result->auth_token;
$this->username = $result->username;
$this->cache = new SnapchatCache();
$this->cache->set('updates', $result);
return $result;
}
else {
return FALSE;
}
} | php | public function register($username, $password, $email, $birthday) {
$timestamp = parent::timestamp();
$result = parent::post(
'/register',
array(
'birthday' => $birthday,
'password' => $password,
'email' => $email,
'timestamp' => $timestamp,
),
array(
parent::STATIC_TOKEN,
$timestamp,
)
);
if (!isset($result->token)) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/registeru',
array(
'email' => $email,
'username' => $username,
'timestamp' => $timestamp,
),
array(
parent::STATIC_TOKEN,
$timestamp,
)
);
// If registration is successful, set the username and auth_token.
if (isset($result->logged) && $result->logged) {
$this->auth_token = $result->auth_token;
$this->username = $result->username;
$this->cache = new SnapchatCache();
$this->cache->set('updates', $result);
return $result;
}
else {
return FALSE;
}
} | [
"public",
"function",
"register",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"email",
",",
"$",
"birthday",
")",
"{",
"$",
"timestamp",
"=",
"parent",
"::",
"timestamp",
"(",
")",
";",
"$",
"result",
"=",
"parent",
"::",
"post",
"(",
"'/re... | Creates a user account.
@todo
Add better validation.
@param string $username
The desired username.
@param string $password
The password to associate with the account.
@param string $email
The email address to associate with the account.
@param $birthday string
The user's birthday (yyyy-mm-dd).
@return mixed
The data returned by the service or FALSE if registration failed.
Generally, returns the same result as calling self::getUpdates(). | [
"Creates",
"a",
"user",
"account",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L173-L220 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.getUpdates | public function getUpdates($force = FALSE) {
if (!$force) {
$result = $this->cache->get('updates');
if ($result) {
return $result;
}
}
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/all_updates',
array(
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
if (!empty($result->updates_response)) {
$this->auth_token = $result->updates_response->auth_token;
$this->cache->set('updates', $result->updates_response);
return $result->updates_response;
}
return $result;
} | php | public function getUpdates($force = FALSE) {
if (!$force) {
$result = $this->cache->get('updates');
if ($result) {
return $result;
}
}
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/all_updates',
array(
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
if (!empty($result->updates_response)) {
$this->auth_token = $result->updates_response->auth_token;
$this->cache->set('updates', $result->updates_response);
return $result->updates_response;
}
return $result;
} | [
"public",
"function",
"getUpdates",
"(",
"$",
"force",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"force",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"'updates'",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
... | Retrieves general user, friend, and snap updates.
@param bool $force
Forces an update even if there's fresh data in the cache. Defaults
to FALSE.
@return mixed
The data returned by the service or FALSE on failure. | [
"Retrieves",
"general",
"user",
"friend",
"and",
"snap",
"updates",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L232-L265 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.getSnaps | public function getSnaps() {
$updates = $this->getUpdates();
if (empty($updates)) {
return FALSE;
}
// We'll make these a little more readable.
$snaps = array();
foreach ($updates->snaps as $snap) {
$snaps[] = (object) array(
'id' => $snap->id,
'media_id' => empty($snap->c_id) ? FALSE : $snap->c_id,
'media_type' => $snap->m,
'time' => empty($snap->t) ? FALSE : $snap->t,
'sender' => empty($snap->sn) ? $this->username : $snap->sn,
'recipient' => empty($snap->rp) ? $this->username : $snap->rp,
'status' => $snap->st,
'screenshot_count' => empty($snap->c) ? 0 : $snap->c,
'sent' => $snap->sts,
'opened' => $snap->ts,
'broadcast' => empty($snap->broadcast) ? FALSE : (object) array(
'url' => $snap->broadcast_url,
'action_text' => $snap->broadcast_action_text,
'hide_timer' => $snap->broadcast_hide_timer,
),
);
}
return $snaps;
} | php | public function getSnaps() {
$updates = $this->getUpdates();
if (empty($updates)) {
return FALSE;
}
// We'll make these a little more readable.
$snaps = array();
foreach ($updates->snaps as $snap) {
$snaps[] = (object) array(
'id' => $snap->id,
'media_id' => empty($snap->c_id) ? FALSE : $snap->c_id,
'media_type' => $snap->m,
'time' => empty($snap->t) ? FALSE : $snap->t,
'sender' => empty($snap->sn) ? $this->username : $snap->sn,
'recipient' => empty($snap->rp) ? $this->username : $snap->rp,
'status' => $snap->st,
'screenshot_count' => empty($snap->c) ? 0 : $snap->c,
'sent' => $snap->sts,
'opened' => $snap->ts,
'broadcast' => empty($snap->broadcast) ? FALSE : (object) array(
'url' => $snap->broadcast_url,
'action_text' => $snap->broadcast_action_text,
'hide_timer' => $snap->broadcast_hide_timer,
),
);
}
return $snaps;
} | [
"public",
"function",
"getSnaps",
"(",
")",
"{",
"$",
"updates",
"=",
"$",
"this",
"->",
"getUpdates",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"updates",
")",
")",
"{",
"return",
"FALSE",
";",
"}",
"// We'll make these a little more readable.",
"$",
... | Gets the user's snaps.
@return mixed
An array of snaps or FALSE on failure. | [
"Gets",
"the",
"user",
"s",
"snaps",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L273-L303 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.