_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q256900 | Papi_Entry_Type.convert_properties | test | protected function convert_properties( $properties ) {
if ( is_array( $properties ) ) {
if ( isset( $properties['type'] ) ) {
$properties = [$properties];
} else if ( isset( $properties[0] ) && $properties[0] instanceof Papi_Core_Tab ) {
foreach ( $properties as $items ) {
$items->properties = array_map( 'papi_get_property_type', $items->properties );
}
return $properties;
}
}
if ( is_object( $properties ) ) {
$properties = papi_get_property_type( $properties );
}
if ( papi_is_property( $properties ) ) {
$properties = [$properties];
}
$properties = is_array( $properties ) ? $properties : [];
$properties = array_map( 'papi_get_property_type', $properties );
return array_filter( $properties, 'papi_is_property' );
} | php | {
"resource": ""
} |
q256901 | Papi_Entry_Type.get_body_classes | test | public function get_body_classes() {
$arr = $this->body_classes();
$arr = is_string( $arr ) ? [$arr] : $arr;
$arr = is_array( $arr ) ? $arr : [];
return array_merge( $arr, [] );
} | php | {
"resource": ""
} |
q256902 | Papi_Entry_Type.get_boxes | test | public function get_boxes() {
if ( empty( $this->boxes ) && $this->load_boxes === false ) {
if ( ! method_exists( $this, 'register' ) ) {
return [];
}
$this->load_boxes = true;
$this->call_parent_register();
$this->register();
}
// Merge boxes, e.g a parent box with a child box.
$this->boxes = $this->merge_boxes( $this->boxes );
/**
* Modify boxes array.
*
* @param array $boxes
* @param string $id
*/
$this->boxes = apply_filters( 'papi/get_boxes', $this->boxes, $this->get_id() );
$this->boxes = is_array( $this->boxes ) ? $this->boxes : [];
// Go through all boxes and only add boxes
// that is a array and remove boxes that isn't
// a instance of core box class.
foreach ( $this->boxes as $index => $box ) {
if ( is_array( $box ) ) {
if ( is_string( $index ) ) {
$box['title'] = $index;
}
$this->box( $box );
unset( $this->boxes[$index] );
continue;
}
// Remove boxes that isn't a instanceof core box class.
if ( $box instanceof Papi_Core_Box === false ) {
unset( $this->boxes[$index] );
continue;
}
// Remove box if site id isn't zero and isn't the current blog id.
if ( $box->site_id !== 0 && $box->site_id !== get_current_blog_id() ) {
unset( $this->boxes[$index] );
continue;
}
}
return papi_sort_order( array_reverse( $this->boxes ) );
} | php | {
"resource": ""
} |
q256903 | Papi_Entry_Type.get_property | test | public function get_property( $slug, $child_slug = '' ) {
$boxes = $this->get_boxes();
$parts = preg_match( '/\[\d+\]/', $slug ) ? preg_split( '/\[\d+\]/', $slug ) : explode( '[', $slug );
$parts = array_map( function ( $part ) {
return preg_replace( '/(\[|\])/', '', $part );
}, $parts );
if ( count( $parts ) > 1 ) {
$property = null;
for ( $i = 0, $l = count( $parts ); $i < $l; $i++ ) {
$child = isset( $parts[$i + 1] ) ? $parts[$i + 1] : '';
$property = $this->get_property( $parts[$i], $child );
if ( isset( $parts[$i + 1] ) ) {
$i++;
}
}
/**
* Modify property.
*
* @param Papi_Core_Property $property
*/
return apply_filters( 'papi/get_property', $property );
}
foreach ( $boxes as $box ) {
foreach ( $box->properties as $property ) {
$property = papi_get_property_type( $property );
if ( papi_is_property( $property ) && $property->match_slug( $slug ) ) {
if ( empty( $child_slug ) ) {
/**
* Modify property.
*
* @param Papi_Core_Property $property
*/
return apply_filters( 'papi/get_property', $property );
}
$property = $property->get_child_property( $child_slug );
if ( papi_is_property( $property ) ) {
/**
* Modify property.
*
* @param Papi_Core_Property $property
*/
return apply_filters( 'papi/get_property', $property );
}
}
}
}
} | php | {
"resource": ""
} |
q256904 | Papi_Entry_Type.get_properties | test | public function get_properties() {
$boxes = $this->get_boxes();
$list = [];
foreach ( $boxes as $box ) {
foreach ( $box->properties as $property ) {
$list[] = $property;
}
}
return $list;
} | php | {
"resource": ""
} |
q256905 | Papi_Entry_Type.merge_boxes | test | protected function merge_boxes( array $boxes ) {
$result = [];
foreach ( $boxes as $box ) {
if ( ! isset( $result[$box->id] ) ) {
$result[$box->id] = $box;
continue;
}
foreach ( $box->properties as $property ) {
$result[$box->id]->properties[] = $property;
}
$result[$box->id]->properties = array_unique( $result[$box->id]->properties );
}
return array_values( $result );
} | php | {
"resource": ""
} |
q256906 | Papi_Entry_Type.setup | test | public function setup() {
add_action( 'in_admin_header', [$this, 'add_help_tabs'] );
add_filter( 'screen_options_show_screen', function () {
return $this->show_screen_options;
} );
// @codeCoverageIgnoreStart
if ( ! method_exists( $this, 'register' ) ) {
return;
}
// @codeCoverageIgnoreEnd
$this->register();
foreach ( $this->get_boxes() as $box ) {
new Papi_Admin_Meta_Box( $box );
}
} | php | {
"resource": ""
} |
q256907 | Papi_Entry_Type.tab | test | protected function tab( $file_or_options = [], $properties = [] ) {
if ( ! is_string( $file_or_options ) && ! is_array( $file_or_options ) ) {
return;
}
return papi_tab( $file_or_options, $properties );
} | php | {
"resource": ""
} |
q256908 | Papi_Property_Link.load_value | test | public function load_value( $value, $slug, $post_id ) {
if ( is_array( $value ) || is_object( $value ) ) {
$values = $value;
} else {
$values = $this->link_fields;
foreach ( $values as $index => $key ) {
$values[$key] = papi_data_get(
$post_id,
sprintf( '%s_%s', $slug, $key ),
$this->get_meta_type()
);
unset( $values[$index] );
}
}
return (object) $this->prepare_link_array( $values, $slug );
} | php | {
"resource": ""
} |
q256909 | Papi_Property_Link.prepare_link_array | test | protected function prepare_link_array( $link, $slug ) {
$array = is_array( $link );
$values = (array) $link;
foreach ( $values as $key => $val ) {
unset( $values[$key] );
$key = preg_replace( '/^' . $slug . '\_/', '', $key );
$values[$key] = $val;
}
$link = (object) $values;
// Don't continue without a url.
if ( ! isset( $link->url ) || empty( $link->url ) ) {
return $array ? (array) $link : $link;
}
// Don't overwrite existing post id.
if ( ! isset( $link->post_id ) || empty( $link->post_id ) ) {
$link->post_id = url_to_postid( $link->url );
}
// If empty target set `_self` as default target.
if ( empty( $link->target ) ) {
$link->target = '_self';
}
// Remove slug if it exists.
if ( isset( $link->$slug ) && is_numeric( $link->$slug ) ) {
unset( $link->$slug );
}
return $array ? (array) $link : $link;
} | php | {
"resource": ""
} |
q256910 | Papi_Property_Link.update_value | test | public function update_value( $values, $slug, $post_id ) {
if ( is_object( $values ) ) {
$values = (array) $values;
}
if ( ! isset( $values['url'] ) ) {
$values = $this->link_fields;
foreach ( $values as $index => $key ) {
$values[sprintf( '%s_%s', $slug, $key )] = '';
unset( $values[$index] );
}
// Delete the required field.
$values[$slug] = '';
return $values;
}
// If a url exists we can continue making the meta fields
// that should be saved.
$values = $this->prepare_link_array( $values, $slug );
foreach ( $values as $key => $val ) {
$values[sprintf( '%s_%s', $slug, $key )] = $val;
unset( $values[$key] );
}
// Required field so Papi can load a value from the
// original property slug.
$values[$slug] = 1;
return $values;
} | php | {
"resource": ""
} |
q256911 | Papi_Taxonomy_Type.allowed | test | public function allowed() {
$args = func_get_args();
if ( empty( $args ) ) {
return parent::allowed();
}
return isset( $args[0] ) && in_array( $args[0], $this->taxonomy, true );
} | php | {
"resource": ""
} |
q256912 | Papi_Taxonomy_Type.edit_form | test | public function edit_form() {
?>
<div id="papi-hidden-editor" class="hide-if-js">
<?php wp_editor( '', 'papiHiddenEditor' ); ?>
</div>
<div id="poststuff">
<div id="post-body">
<?php
foreach ( $this->boxes as $box ) {
do_meta_boxes(
$box->id,
'normal',
null
);
}
?>
</div>
</div>
<?php
} | php | {
"resource": ""
} |
q256913 | Papi_REST_API_Post.get_post | test | public function get_post( WP_Post $post ) {
if ( ! ( $page_type = papi_get_entry_type_by_meta_id( $post->ID ) ) ) {
return $post;
}
// Register all properties fields with register meta.
foreach ( $page_type->get_properties() as $property ) {
$property->register();
}
// Add filter to prepare the response for a post type.
add_filter( 'rest_prepare_' . $post->post_type, [$this, 'prepare_response'] );
return $post;
} | php | {
"resource": ""
} |
q256914 | Papi_REST_API_Post.prepare_response | test | public function prepare_response( $response ) {
if ( ! isset( $response->data['meta'] ) ) {
return $response;
}
foreach ( $response->data['meta'] as $key => $value ) {
$response->data['meta'][$key] = papi_get_field( $key, $value, 'post' );
}
return $response;
} | php | {
"resource": ""
} |
q256915 | Papi_REST_API_Post.setup_fields | test | public function setup_fields() {
if ( ! function_exists( 'register_rest_field' ) ) {
return;
}
$post_types = papi_get_post_types();
foreach ( $post_types as $post_type ) {
register_rest_field( $post_type, 'page_type', [
'get_callback' => [$this, 'get_page_type']
] );
}
} | php | {
"resource": ""
} |
q256916 | Papi_CLI_Command.get_format_args | test | protected function get_format_args( $assoc_args ) {
$format_args = [
'fields' => $this->get_default_format_fields(),
'field' => null,
'format' => 'table',
];
if ( isset( $assoc_args['fields'] ) ) {
$format_args['fields'] = $assoc_args['fields'];
}
if ( isset( $assoc_args['field'] ) ) {
$format_args['field'] = $assoc_args['field'];
}
if ( ! empty( $assoc_args['format'] ) && in_array( $assoc_args['format'], ['count', 'ids', 'table', 'csv', 'json'], true ) ) {
$format_args['format'] = $assoc_args['format'];
}
return $format_args;
} | php | {
"resource": ""
} |
q256917 | Papi_Admin_View.render | test | public function render( $file ) {
if ( ! empty( $file ) && $this->exists( $file ) ) {
require $this->file( $file );
}
} | php | {
"resource": ""
} |
q256918 | Papi_Core_Box.get_option | test | public function get_option( $key ) {
return isset( $this->options[$key] ) ? $this->options[$key] : null;
} | php | {
"resource": ""
} |
q256919 | Papi_Core_Conditional_Rules.convert_prop | test | protected function convert_prop( $value, Papi_Core_Conditional_Rule $rule ) {
$meta_id = papi_get_meta_id();
$meta_type = papi_get_meta_type();
$entry_type = papi_get_entry_type_by_meta_id( $meta_id, $meta_type );
if ( ! papi_is_empty( $value ) && $entry_type instanceof Papi_Entry_Type !== false ) {
$property = $entry_type->get_property( $rule->slug );
if ( papi_is_property( $property ) ) {
$prop_value = $property->format_value(
$value,
$property->slug,
$meta_id
);
$prop_value = papi_filter_format_value(
$property->type,
$prop_value,
$property->slug,
$meta_id,
$meta_type
);
$prop_value = $this->get_deep_value(
$rule->slug,
$prop_value
);
if ( gettype( $prop_value ) === gettype( $rule->value ) ) {
return $prop_value;
}
}
return $value;
}
return $value;
} | php | {
"resource": ""
} |
q256920 | Papi_Core_Conditional_Rules.get_converted_value | test | protected function get_converted_value( Papi_Core_Conditional_Rule $rule ) {
$value = $this->get_value( $rule );
// Convert numeric values.
if ( is_numeric( $value ) && is_numeric( $rule->value ) ) {
return [
$this->convert_number( $value ),
$this->convert_number( $rule->value )
];
}
// Convert bool value if it a string bool or return value.
$value = $this->convert_bool( $value );
$rule->value = $this->convert_bool( $rule->value );
// Try to convert the property to the same value as the rule value.
return [
$this->convert_prop( $value, $rule ),
$rule->value
];
} | php | {
"resource": ""
} |
q256921 | Papi_Core_Conditional_Rules.get_deep_value | test | protected function get_deep_value( $slug, $value ) {
$slugs = explode( '.', $slug );
array_shift( $slugs );
return papi_field_value( $slugs, $value, $value );
} | php | {
"resource": ""
} |
q256922 | Papi_Core_Conditional_Rules.get_value | test | protected function get_value( Papi_Core_Conditional_Rule $rule ) {
if ( papi_doing_ajax() ) {
$source = $rule->get_source();
$meta_id = papi_get_meta_id();
$entry_type = papi_get_entry_type_by_meta_id( $meta_id );
if ( ! papi_is_empty( $source ) && $entry_type instanceof Papi_Entry_Type !== false ) {
if ( papi_is_property( $entry_type->get_property( $rule->slug ) ) ) {
return $this->get_deep_value( $rule->slug, $source );
}
}
}
if ( ! papi_is_empty( $rule->get_source() ) ) {
return $this->get_deep_value( $rule->slug, $rule->get_source() );
}
$slug = $rule->get_field_slug();
$type = papi_get_meta_type();
$value = papi_get_field( $slug, null, $type );
return $this->get_deep_value( $slug, $value );
} | php | {
"resource": ""
} |
q256923 | Papi_Core_Conditional_Rules.rule_equal | test | public function rule_equal( Papi_Core_Conditional_Rule $rule ) {
list( $value, $rule_value ) = $this->get_converted_value( $rule );
return $value === $rule_value;
} | php | {
"resource": ""
} |
q256924 | Papi_Core_Conditional_Rules.rule_not_equal | test | public function rule_not_equal( Papi_Core_Conditional_Rule $rule ) {
list( $value, $rule_value ) = $this->get_converted_value( $rule );
return $value !== $rule_value;
} | php | {
"resource": ""
} |
q256925 | Papi_Core_Conditional_Rules.rule_greater_then | test | public function rule_greater_then( Papi_Core_Conditional_Rule $rule ) {
$value = $this->get_value( $rule );
if ( is_array( $value ) ) {
$value = count( $value );
}
if ( ! is_numeric( $value ) || ! is_numeric( $rule->value ) ) {
return false;
}
return $this->convert_number( $value ) >
$this->convert_number( $rule->value );
} | php | {
"resource": ""
} |
q256926 | Papi_Core_Conditional_Rules.rule_not_in | test | public function rule_not_in( Papi_Core_Conditional_Rule $rule ) {
list( $value, $rule_value ) = $this->get_converted_value( $rule );
if ( ! is_array( $rule_value ) ) {
return false;
}
return ! in_array( $value, $rule_value, true );
} | php | {
"resource": ""
} |
q256927 | Papi_Core_Conditional_Rules.rule_like | test | public function rule_like( Papi_Core_Conditional_Rule $rule ) {
$value = $this->get_value( $rule );
if ( ! is_string( $value ) ) {
$value = papi_convert_to_string( $value );
}
if ( papi_is_empty( $value ) ) {
return false;
}
return strpos(
strtolower( $value ),
strtolower( $rule->value )
) !== false;
} | php | {
"resource": ""
} |
q256928 | Papi_Core_Conditional_Rules.get_between_values | test | protected function get_between_values( Papi_Core_Conditional_Rule $rule ) {
$value = $this->get_value( $rule );
if ( ! is_array( $rule->value ) ) {
return [$rule, false];
}
foreach ( $rule->value as $index => $v ) {
$v = $this->convert_number( $v );
if ( is_numeric( $v ) ) {
$rule->value[$index] = $v;
} else {
unset( $rule->value[$index] );
}
}
if ( ! is_numeric( $value ) || count( $rule->value ) !== 2 ) {
return [$rule, false];
}
return [$rule, $this->convert_number( $value )];
} | php | {
"resource": ""
} |
q256929 | Papi_Core_Conditional_Rules.rule_between | test | public function rule_between( Papi_Core_Conditional_Rule $rule ) {
list( $rule, $value ) = $this->get_between_values( $rule );
if ( $value === false ) {
return false;
}
return $rule->value[0] <= $value && $value <= $rule->value[1];
} | php | {
"resource": ""
} |
q256930 | Papi_Core_Conditional_Rules.rule_not_between | test | public function rule_not_between( Papi_Core_Conditional_Rule $rule ) {
list( $rule, $value ) = $this->get_between_values( $rule );
if ( $value === false ) {
return false;
}
return ! ( $rule->value[0] <= $value && $value <= $rule->value[1] );
} | php | {
"resource": ""
} |
q256931 | Papi_Property_Relationship.get_sort_option | test | public function get_sort_option( $post_id ) {
$slug = $this->html_id( 'sort_option' );
$slug = str_replace( '][', '_', $slug );
$slug = str_replace( '[', '_', $slug );
$slug = str_replace( ']', '', $slug );
return papi_data_get( $post_id, $slug, $this->get_meta_type() );
} | php | {
"resource": ""
} |
q256932 | Papi_Property_Relationship.get_sort_options | test | public static function get_sort_options() {
$sort_options = [];
$sort_options[__( 'Select', 'papi' )] = null;
$sort_options[__( 'Name (alphabetically)', 'papi' )] = function ( $a, $b ) {
// Backwards compatibility with both `post_title` and `title`.
return strcmp(
strtolower( isset( $a->post_title ) ? $a->post_title : $a->title ),
strtolower( isset( $b->post_title ) ? $b->post_title : $b->title )
);
};
$sort_options[__( 'Post created date (ascending)', 'papi' )] = function ( $a, $b ) {
return strtotime( $a->post_date ) > strtotime( $b->post_date );
};
$sort_options[__( 'Post created date (descending)', 'papi' )] = function ( $a, $b ) {
return strtotime( $a->post_date ) < strtotime( $b->post_date );
};
$sort_options[__( 'Post id (ascending)', 'papi' )] = function ( $a, $b ) {
// Backwards compatibility with both `ID` and `id`.
return isset( $a->ID ) ? $a->ID > $b->ID : $a->id > $b->id;
};
$sort_options[__( 'Post id (descending)', 'papi' )] = function ( $a, $b ) {
// Backwards compatibility with both `ID` and `id`.
return isset( $a->ID ) ? $a->ID < $b->ID : $a->id < $b->id;
};
$sort_options[__( 'Post order value (ascending)', 'papi' )] = function ( $a, $b ) {
return $a->menu_order > $b->menu_order;
};
$sort_options[__( 'Post order value (descending)', 'papi' )] = function ( $a, $b ) {
return $a->menu_order < $b->menu_order;
};
$sort_options[__( 'Post modified date (ascending)', 'papi' )] = function ( $a, $b ) {
return strtotime( $a->post_modified ) > strtotime( $b->post_modified );
};
$sort_options[__( 'Post modified date (descending)', 'papi' )] = function ( $a, $b ) {
return strtotime( $a->post_modified ) < strtotime( $b->post_modified );
};
return apply_filters( 'papi/property/relationship/sort_options', $sort_options );
} | php | {
"resource": ""
} |
q256933 | Papi_Property_Relationship.get_items | test | protected function get_items( $settings ) {
if ( is_array( $settings->items ) && ! empty( $settings->items ) ) {
$mapping = function ( $item ) {
return is_array( $item ) ?
isset( $item['id'], $item['title'] ) :
isset( $item->id, $item->title );
};
return array_map(
'papi_maybe_convert_to_object',
array_filter( $settings->items, $mapping )
);
}
// By default we add posts per page key with the value -1 (all).
if ( ! isset( $settings->query['posts_per_page'] ) ) {
$settings->query['posts_per_page'] = -1;
}
// Prepare arguments for WP_Query.
$args = array_merge( [
'post_status' => 'any',
'post_type' => papi_to_array( $settings->post_type ),
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false
], $settings->query );
$items = ( new WP_Query( $args ) )->posts;
return array_map( [$this, 'convert_post_to_item'], papi_get_only_objects( $items ) );
} | php | {
"resource": ""
} |
q256934 | Papi_Property_Relationship.sort_value | test | public function sort_value( $values, $slug, $post_id ) {
$sort_option = $this->get_sort_option( $post_id );
$sort_options = static::get_sort_options();
if ( empty( $sort_option ) || ! isset( $sort_options[$sort_option] ) || is_null( $sort_options[$sort_option] ) ) {
return $values;
}
usort( $values, $sort_options[$sort_option] );
return $values;
} | php | {
"resource": ""
} |
q256935 | Papi_Property_Relationship.update_value | test | public function update_value( $values, $slug, $post_id ) {
$values = $this->format_value( $values, $slug, $post_id );
$values = array_map( function ( $item ) {
if ( $item instanceof WP_Post ) {
$item = $this->convert_post_to_item( $item );
}
if ( isset( $item->title ) ) {
unset( $item->title );
}
return $item;
}, $values );
return papi_maybe_json_decode( $values );
} | php | {
"resource": ""
} |
q256936 | Papi_CLI_Type_Command.get_meta_type_value | test | protected function get_meta_type_value( $entry_type ) {
if ( in_array( $entry_type->get_type(), ['attachment'], true ) ) {
return $entry_type->get_type();
}
switch ( papi_get_meta_type( $entry_type->get_type() ) ) {
case 'post':
return implode( ', ', $entry_type->post_type );
case 'term':
return implode( ', ', $entry_type->taxonomy );
default:
return 'n/a';
}
} | php | {
"resource": ""
} |
q256937 | Papi_CLI_Type_Command.list_ | test | public function list_( $args, $assoc_args ) {
// Get all entry types.
$entry_types = papi_get_all_entry_types();
if ( empty( $entry_types ) ) {
WP_CLI::error( 'No Papi types exists.' );
}
// Create type item with the fields that
// will be displayed.
$entry_types = array_map( function( $entry_type ) {
return [
'id' => $entry_type->get_id(),
'name' => $entry_type->name,
'meta type value' => $this->get_meta_type_value( $entry_type ),
'template' => empty( $entry_type->template ) ? 'n/a' : $entry_type->template,
'type' => $entry_type->get_type(),
'db count' => $entry_type->get_type() === 'option' ? 'n/a' : papi_get_entry_type_count( $entry_type )
];
}, $entry_types );
// Render types as a table.
$formatter = $this->get_formatter( $assoc_args );
$formatter->display_items( $entry_types );
} | php | {
"resource": ""
} |
q256938 | Papi_Admin_Meta_Box_Tabs.html | test | protected function html() {
?>
<div class="papi-tabs-wrapper">
<div class="papi-tabs-table-back"></div>
<div class="papi-tabs-back"></div>
<ul class="papi-tabs">
<?php
foreach ( $this->tabs as $tab ):
$css_classes = $this->tabs[0] === $tab ? 'active ' : '';
if ( empty( $tab->background ) ) {
// Find out if the first property has a sidebar or not. If the first property
// don't have a sidebar the tab background should be white since it looks better.
$no_sidebar = empty( $tab->properties ) ? false : $tab->properties[0]->sidebar;
$css_classes .= ! empty( $tab->properties ) && $no_sidebar ? '' : 'white-tab';
} else {
$css_classes .= $tab->background === 'white' ? 'white-tab' : '';
}
?>
<li class="<?php echo esc_attr( $css_classes ); ?>">
<a href="#" data-papi-tab="<?php echo esc_attr( $tab->id ); ?>">
<?php if ( ! empty( $tab->icon ) ): ?>
<img src="<?php echo esc_attr( $tab->icon ); ?>" alt="<?php echo esc_attr( $tab->title ); ?>" />
<?php endif;
echo esc_html( $tab->title ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<div class="papi-tabs-content">
<?php
foreach ( $this->tabs as $tab ):
?>
<div class="<?php echo $this->tabs[0] === $tab ? 'active' : ''; ?>" data-papi-tab="<?php echo esc_attr( $tab->id ); ?>">
<?php papi_render_properties( $tab->properties ); ?>
</div>
<?php
endforeach;
?>
</div>
</div>
<div class="papi-clear"></div>
<?php
} | php | {
"resource": ""
} |
q256939 | Papi_Property_Flexible.get_json_id | test | protected function get_json_id( $key, $extra = '' ) {
return $this->get_slug() . '_' . papi_slugify( $key ) . ( empty( $extra ) ? '' : '_' . $extra );
} | php | {
"resource": ""
} |
q256940 | Papi_Property_Flexible.get_layout | test | protected function get_layout( $slug ) {
$layouts = $this->get_settings_layouts();
foreach ( $layouts as $layout ) {
if ( $layout['slug'] === $slug ) {
return $layout;
}
}
return [];
} | php | {
"resource": ""
} |
q256941 | Papi_Property_Flexible.load_value | test | public function load_value( $value, $repeater_slug, $post_id ) {
if ( is_array( $value ) ) {
return $value;
}
list( $results, $trash ) = $this->get_results( $value, $repeater_slug, $post_id );
// Will not need this array.
unset( $trash );
$store = $this->get_store();
$results = papi_property_from_array_slugs( $results, unpapify( $repeater_slug ) );
if ( is_null( $store ) ) {
return $this->default_value;
}
return $this->load_child_properties( $results, $this );
} | php | {
"resource": ""
} |
q256942 | Papi_Property_Flexible.prepare_properties | test | protected function prepare_properties( $layouts ) {
$layouts = array_map( function ( $layout ) {
return (array) $layout;
}, $layouts );
foreach ( $layouts as $index => $layout ) {
if ( ! $this->valid_layout( $layout ) ) {
if ( is_array( $layout ) ) {
unset( $layout[$index] );
} else {
unset( $layouts[$index] );
}
continue;
}
if ( ! isset( $layout['slug'] ) ) {
$layout['slug'] = $layout['title'];
}
if ( ! isset( $layout['row_label'] ) ) {
$layout['row_label'] = $layout['title'];
}
if ( ! isset( $layout['show_label'] ) ) {
$layout['show_label'] = true;
}
$layouts[$index] = array_merge( $layouts[$index], $layout );
$layouts[$index]['slug'] = papi_slugify( $layout['slug'] );
$layouts[$index]['slug'] = $this->get_layout_value( $layouts[$index]['slug'] );
$layouts[$index]['items'] = parent::prepare_properties( $layout['items'] );
}
return array_filter( $layouts );
} | php | {
"resource": ""
} |
q256943 | Papi_Property_Flexible.render_layout_input | test | protected function render_layout_input( $value ) {
$slug = sprintf( '%s[%d][%s]', $this->get_slug(), $this->counter, $this->layout_key );
?>
<input type="hidden" name="<?php echo esc_attr( $slug ); ?>" value="<?php echo esc_attr( $value ); ?>" />
<?php
} | php | {
"resource": ""
} |
q256944 | Papi_Property_Flexible.render_repeater_row | test | protected function render_repeater_row() {
$layouts = $this->get_settings_layouts();
$values = $this->get_value();
// Fetch all slugs in all layouts.
$slugs = [];
foreach ( $layouts as $index => $layout ) {
foreach ( $layout['items'] as $item ) {
$slugs[] = unpapify( $item->slug );
}
}
// Remove values that don't exists in the slugs array.
foreach ( $values as $index => $row ) {
$keys = array_keys( $row );
foreach ( array_keys( $row ) as $slug ) {
if ( in_array( $slug, $keys, true ) || papi_is_property_type_key( $slug ) || $this->is_layout_key( $slug ) ) {
continue;
}
unset( $values[$index][$slug] );
}
}
$values = array_filter( $values );
$closed_rows = $this->get_setting( 'closed_rows', true );
foreach ( $values as $index => $row ):
?>
<tr <?php echo $closed_rows ? 'class="closed"' : ''; ?>>
<td class="handle">
<span class="toggle"></span>
<span class="count"><?php echo esc_html( $this->counter + 1 ); ?></span>
</td>
<?php
foreach ( $layouts as $layout ) {
// Don't render layouts that don't have a valid value in the database.
if ( ! isset( $row[$this->layout_key] ) || $layout['slug'] !== $this->get_layout_value( $row[$this->layout_key] ) ) {
continue;
}
// Render all properties in the layout
$this->render_properties( $layout['items'], $row );
}
$this->counter ++;
?>
<td class="last">
<span>
<a title="<?php esc_html_e( 'Remove', 'papi' ); ?>" href="#" class="repeater-remove-item">x</a>
</span>
</td>
</tr>
<?php
endforeach;
} | php | {
"resource": ""
} |
q256945 | Papi_Admin_Entry_Taxonomy.add_form_fields | test | public function add_form_fields() {
$html_name = esc_attr( papi_get_page_type_key() );
$taxonomy = papi_get_qs( 'taxonomy' );
$taxonomy_object = get_taxonomy( $taxonomy );
// Get only the taxonomy types that has the taxonomy.
$taxonomy_types = array_filter( $this->taxonomy_types, function ( $taxonomy_type ) use ( $taxonomy ) {
return in_array( $taxonomy, $taxonomy_type->taxonomy, true ) && $taxonomy_type->display( $taxonomy );
} );
$taxonomy_types = array_values( $taxonomy_types );
// Do not display empty select if no taxonomy types.
if ( empty( $taxonomy_types ) ) {
return;
}
// Prepare taxonomy types with standard taxonomy type.
$taxonomy_types = $this->prepare_taxonomy_types( $taxonomy_types );
// Render a dropdown if more than one taxonomy types
// exists on the taxonomy.
if ( count( $taxonomy_types ) > 1 ):
?>
<div class="form-field">
<label for="<?php echo esc_attr( $html_name ); ?>">
<?php echo esc_html( sprintf( __( '%s type', 'papi' ), $taxonomy_object->labels->singular_name ) ); ?>
</label>
<select name="<?php echo esc_attr( $html_name ); ?>" id="<?php echo esc_attr( $html_name ); ?>" data-papi-page-type-key="true">
<?php
foreach ( $taxonomy_types as $taxonomy_type ) {
papi_render_html_tag( 'option', [
'data-redirect' => $taxonomy_type->redirect_after_create,
'value' => esc_attr( $taxonomy_type->get_id() ),
esc_html( $taxonomy_type->name )
] );
}
?>
</select>
</div>
<?php
else:
papi_render_html_tag( 'input', [
'data-redirect' => $taxonomy_types[0]->redirect_after_create,
'data-papi-page-type-key' => true,
'name' => esc_attr( $html_name ),
'type' => 'hidden',
'value' => esc_attr( $taxonomy_types[0]->get_id() )
] );
endif;
} | php | {
"resource": ""
} |
q256946 | Papi_Admin_Entry_Taxonomy.prepare_taxonomy_types | test | protected function prepare_taxonomy_types( array $taxonomy_types ) {
$taxonomy = papi_get_qs( 'taxonomy' );
if ( papi_filter_settings_show_standard_taxonomy_type( $taxonomy ) ) {
$id = sprintf( 'papi-standard-%s-type', $taxonomy );
$taxonomy_type = new Papi_Taxonomy_Type( $id );
$taxonomy_type->id = $id;
$taxonomy_type->name = papi_filter_settings_standard_taxonomy_type_name( $taxonomy );
$taxonomy_type->taxonomy = [$taxonomy];
$taxonomy_types[] = $taxonomy_type;
}
usort( $taxonomy_types, function ( $a, $b ) {
return strcmp( $a->name, $b->name );
} );
return papi_sort_order( array_reverse( $taxonomy_types ) );
} | php | {
"resource": ""
} |
q256947 | Papi_Admin_Entry_Taxonomy.setup_taxonomies_hooks | test | public function setup_taxonomies_hooks() {
$this->taxonomy_types = papi_get_all_entry_types( [
'types' => 'taxonomy'
] );
$taxonomies = array_reduce( $this->taxonomy_types, function ( $taxonomies, $taxonomy_type ) {
return array_merge( $taxonomies, $taxonomy_type->taxonomy );
}, [] );
$taxonomies = array_unique( $taxonomies );
foreach ( $taxonomies as $taxonomy ) {
if ( is_string( $taxonomy ) && taxonomy_exists( $taxonomy ) ) {
add_action( $taxonomy . '_add_form_fields', [$this, 'add_form_fields'] );
}
}
} | php | {
"resource": ""
} |
q256948 | Papi_Admin_Ajax.ajax_url | test | public function ajax_url() {
if ( empty( $this->structure ) ) {
$url = esc_url( home_url( 'index.php', is_ssl() ? 'https' : 'http' ) );
} else {
$url = esc_url( home_url( '/papi-ajax/', is_ssl() ? 'https' : 'http' ) );
}
?>
<script type="text/javascript">
var papi = papi || {};
papi.ajaxUrl = '<?php echo esc_html( $url ); ?>';
</script>
<?php
} | php | {
"resource": ""
} |
q256949 | Papi_Admin_Ajax.handle_papi_ajax | test | public function handle_papi_ajax() {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
$ajax_action = '';
if ( ! empty( $_GET['action'] ) ) {
$ajax_action = sanitize_text_field( $_GET['action'] );
}
if ( is_user_logged_in() && has_action( $this->action_prefix . $ajax_action ) !== false ) {
if ( ! defined( 'DOING_AJAX' ) ) {
define( 'DOING_AJAX', true );
}
if ( ! defined( 'DOING_PAPI_AJAX' ) ) {
define( 'DOING_PAPI_AJAX', true );
}
status_header( 200 );
do_action( $this->action_prefix . $ajax_action );
wp_die();
}
} | php | {
"resource": ""
} |
q256950 | Papi_Admin_Ajax.get_entry_type | test | public function get_entry_type() {
$entry_type_id = papi_get_qs( 'entry_type' );
$entry_type = papi_get_entry_type_by_id( $entry_type_id );
if ( empty( $entry_type ) ) {
$this->render_error( 'No entry type found' );
return;
}
wp_send_json( $entry_type );
} | php | {
"resource": ""
} |
q256951 | Papi_Admin_Ajax.get_posts | test | public function get_posts() {
$args = papi_get_qs( 'query' ) ?: [];
$args = is_array( $args ) ? $args : [];
$fields = papi_get_qs( 'fields' ) ?: [];
$fields = is_array( $fields ) ? $fields : [];
$posts = ( new WP_Query( array_merge( [
'posts_per_page' => -1,
'post_status' => 'any',
'post_type' => ['post'],
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false
], $args ) ) )->posts;
$posts = array_filter( $posts, function ( $post ) {
return ! empty( $post->post_title );
} );
usort( $posts, function ( $a, $b ) {
return strcmp( strtolower( $a->post_title ), strtolower( $b->post_title ) );
} );
if ( ! empty( $fields ) ) {
foreach ( $posts as $index => $post ) {
$item = [];
foreach ( $fields as $field ) {
$item[$field] = $post->$field;
}
$posts[$index] = $item;
}
}
wp_send_json( $posts );
} | php | {
"resource": ""
} |
q256952 | Papi_Admin_Ajax.get_property | test | public function get_property() {
$default_options = Papi_Core_Property::factory()->get_options();
$keys = array_keys( get_object_vars( $default_options ) );
$options = papi_get_qs( $keys, true );
if ( $property = papi_property( $options ) ) {
ob_start();
$property->render_ajax_request();
$html = ob_get_clean();
wp_send_json( [
'html' => utf8_encode( $html )
] );
return;
}
$this->render_error( 'No property found' );
} | php | {
"resource": ""
} |
q256953 | Papi_Admin_Ajax.get_properties | test | public function get_properties() {
if ( ! papi_get_sanitized_post( 'properties' ) ) {
$this->render_error( 'No properties found' );
return;
}
$items = json_decode( stripslashes( $_POST['properties'] ), true );
if ( empty( $items ) || ! is_array( $items ) ) {
$this->render_error( 'No properties found' );
return;
}
foreach ( $items as $key => $item ) {
$property = papi_property( (array) $item );
if ( ! papi_is_property( $property ) ) {
unset( $items[$key] );
continue;
}
ob_start();
$property->render_ajax_request();
$items[$key] = trim( ob_get_clean() );
}
$items = array_filter( $items );
if ( empty( $items ) ) {
$this->render_error( 'No properties found' );
return;
}
wp_send_json( [
'html' => $items
] );
} | php | {
"resource": ""
} |
q256954 | Papi_Admin_Ajax.get_rules_result | test | public function get_rules_result() {
if ( ! papi_get_sanitized_post( 'data' ) ) {
$this->render_error( 'No rule found' );
return;
}
$data = json_decode( stripslashes( papi_get_sanitized_post( 'data' ) ), true );
if ( empty( $data ) || ! is_array( $data ) || ! isset( $data['slug'] ) ) {
$this->render_error( 'No rule found' );
return;
}
$entry_type = papi_get_entry_type_by_meta_id();
if ( empty( $entry_type ) ) {
$entry_type_id = papi_get_qs( 'entry_type' );
$entry_type = papi_get_entry_type_by_id( $entry_type_id );
}
if ( $entry_type instanceof Papi_Entry_Type === false ) {
$this->render_error( 'No rule found' );
return;
}
if ( preg_match( '/\[\]$/', $data['slug'] ) ) {
$data['slug'] = preg_replace( '/\[\]$/', '', $data['slug'] );
}
if ( $property = $entry_type->get_property( $data['slug'] ) ) {
wp_send_json( [
'render' => $property->render_is_allowed_by_rules( $data['rules'] )
] );
return;
}
$this->render_error( 'No rule found' );
} | php | {
"resource": ""
} |
q256955 | Papi_Admin_Ajax.get_shortcode | test | public function get_shortcode() {
$shortcode = papi_get_qs( 'shortcode' ) ?: '';
$shortcode = html_entity_decode( $shortcode );
$shortcode = wp_unslash( $shortcode );
wp_send_json( [
'html' => do_shortcode( $shortcode )
] );
} | php | {
"resource": ""
} |
q256956 | Papi_Admin_Ajax.get_terms | test | public function get_terms() {
$query = papi_get_qs( 'query' ) ?: [];
$query = is_array( $query ) ? $query : [];
$taxonomy = papi_get_qs( 'taxonomy' ) ?: '';
$args = array_merge( $query, [
'fields' => 'id=>name'
] );
$terms = [];
if ( taxonomy_exists( $taxonomy ) ) {
$terms = get_terms( $taxonomy, $args );
}
wp_send_json( $terms );
} | php | {
"resource": ""
} |
q256957 | Papi_CLI_Term_Command.get | test | public function get( $args, $assoc_args ) {
try {
// Set query string that we need.
$_GET['meta_type'] = 'term';
// Get the taxonomy type that the term has.
$entry_type = papi_get_entry_type_by_meta_id( $args[0] );
if ( empty( $entry_type ) || $entry_type instanceof Papi_Taxonomy_Type === false ) {
WP_CLI::error( 'No taxonomy type exists on the term' );
}
$properties = [];
foreach ( $entry_type->get_boxes() as $box ) {
foreach ( $box->properties as $property ) {
$properties[] = [
'slug' => $property->get_slug( true ),
'type' => $property->type,
'has value' => $property->get_value() !== null ? 'true' : 'false',
'box' => $box->title
];
}
}
// Render types as a table.
$formatter = $this->get_formatter( $assoc_args );
$formatter->display_items( $properties );
} catch ( WC_CLI_Exception $e ) {
WP_CLI::error( $e->getMessage() );
}
} | php | {
"resource": ""
} |
q256958 | Papi_CLI_Term_Command.rename | test | public function rename( $args, $assoc_args ) {
$type = $args[0];
$old_key = $args[1];
$new_key = $args[2];
$terms = ( new Papi_Query( [
'entry_type' => $type,
'fields' => 'ids'
] ) )->get_result();
if ( empty( $terms ) ) {
WP_CLI::error( 'No terms found' );
}
foreach ( $terms as $term ) {
$meta = get_term_meta( $term, $old_key, true );
if ( papi_is_empty( $meta ) ) {
continue;
}
if ( delete_term_meta( $term, $old_key ) === false ) {
WP_CLI::error( 'Could not delete term meta with key: ' . $old_key );
}
if ( update_term_meta( $term, $new_key, $meta ) === false ) {
WP_CLI::error( 'Could not update term meta with key: ' . $new_key );
}
}
WP_CLI::success( 'Done' );
} | php | {
"resource": ""
} |
q256959 | Papi_Admin_Columns.manage_page_type_posts_columns | test | public function manage_page_type_posts_columns( array $defaults = [] ) {
if ( ! in_array( $this->post_type, papi_get_post_types(), true ) && ! in_array( $this->taxonomy, papi_get_taxonomies(), true ) ) {
return $defaults;
}
/**
* Hide column for post or taxonomy type. Default is false.
*
* @param string $post_type
*/
if ( apply_filters( 'papi/settings/column_hide_' . $this->get_meta_type_value(), false ) ) {
return $defaults;
}
/**
* Change column title for entry type column.
*
* @param string $post_type
*/
$defaults['entry_type'] = apply_filters(
'papi/settings/column_title_' . $this->get_meta_type_value(),
esc_html__( 'Type', 'papi' )
);
return $defaults;
} | php | {
"resource": ""
} |
q256960 | Papi_Admin_Columns.manage_page_type_posts_custom_column | test | public function manage_page_type_posts_custom_column( $column_name, $post_id, $term_id = null ) {
if ( ! in_array( $this->post_type, papi_get_post_types(), true ) && ! in_array( $this->taxonomy, papi_get_taxonomies(), true ) ) {
return;
}
/**
* Hide column for post type. Default is false.
*
* @param string $post_type
*/
if ( apply_filters( 'papi/settings/column_hide_' . $this->get_meta_type_value(), false ) ) {
return;
}
// Column name most be `entry_type`. On taxomy the column name is `post_id` variable.
if ( $column_name !== 'entry_type' && $post_id !== 'entry_type' ) {
return;
}
// Get the entry type for the post or term.
$entry_type = papi_get_entry_type_by_meta_id(
is_numeric( $post_id ) ? $post_id : $term_id,
papi_get_meta_type()
);
$post = ! empty( $this->post_type ) && empty( $this->taxonomy );
$type = $post ? 'page' : 'taxonomy';
$arg = $post ? papi_get_post_type() : papi_get_taxonomy();
$show = call_user_func_array( "papi_filter_settings_show_standard_{$type}_type", [$arg] );
if ( ! is_null( $entry_type ) && ( $show === false || get_metadata( papi_get_meta_type( $type ), ( is_numeric( $post_id ) ? $post_id : $term_id ), papi_get_page_type_key(), true ) === $entry_type->get_id() ) ) {
echo esc_html( $entry_type->name );
} else {
echo esc_html( call_user_func_array( "papi_filter_settings_standard_{$type}_type_name", [$arg] ) );
}
} | php | {
"resource": ""
} |
q256961 | Papi_Admin_Columns.manage_page_type_sortable_columns | test | public function manage_page_type_sortable_columns( $columns ) {
if ( in_array( $this->post_type, papi_get_post_types(), true ) || in_array( $this->taxonomy, papi_get_taxonomies(), true ) ) {
$columns['entry_type'] = 'entry_type';
}
return $columns;
} | php | {
"resource": ""
} |
q256962 | Papi_Admin_Columns.pre_get_posts | test | public function pre_get_posts( WP_Query $query ) {
global $pagenow;
if ( $pagenow === 'edit.php' && ! is_null( papi_get_qs( 'page_type' ) ) ) {
if ( papi_get_qs( 'page_type' ) === 'papi-standard-page' ) {
$query->set( 'meta_query', [
[
'key' => papi_get_page_type_key(),
'compare' => 'NOT EXISTS'
]
] );
} else {
$query->set( 'meta_key', papi_get_page_type_key() );
$query->set( 'meta_value', papi_get_qs( 'page_type' ) );
}
}
// Order query result by entry type.
if ( $query->get( 'orderby' ) === 'entry_type' ) {
$query->set( 'meta_key', papi_get_page_type_key() );
$query->set( 'orderby', 'meta_value' );
}
return $query;
} | php | {
"resource": ""
} |
q256963 | Papi_Admin_Columns.restrict_page_types | test | public function restrict_page_types() {
$post_types = papi_get_post_types();
if ( in_array( $this->post_type, $post_types, true ) ) {
$page_types = papi_get_all_page_types( $this->post_type );
$page_types = array_map( function ( $page_type ) {
return [
'name' => $page_type->name,
'value' => $page_type->get_id()
];
}, $page_types );
// Add the standard page that isn't a real page type.
if ( papi_filter_settings_show_standard_page_type_in_filter( $this->post_type ) ) {
$page_types[] = [
'name' => papi_filter_settings_standard_page_type_name( $this->post_type ),
'value' => 'papi-standard-page'
];
}
usort( $page_types, function ( $a, $b ) {
return strcmp(
strtolower( $a['name'] ),
strtolower( $b['name'] )
);
} );
?>
<select name="page_type" class="postform">
<option value="0" selected><?php esc_html_e( 'All types', 'papi' ); ?></option>
<?php
foreach ( $page_types as $page_type ) {
printf(
'<option value="%s" %s>%s</option>',
esc_attr( $page_type['value'] ),
papi_get_qs( 'page_type' ) === $page_type['value'] ? ' selected' : '',
esc_html( $page_type['name'] )
);
}
?>
</select>
<?php
}
} | php | {
"resource": ""
} |
q256964 | Papi_Property_Term.format_value | test | public function format_value( $value, $slug, $term_id ) {
$meta_key = $this->get_setting( 'meta_key' );
if ( empty( $meta_key ) ) {
if ( is_numeric( $value ) && intval( $value ) !== 0 ) {
$term_id = $value;
}
} else {
$args = [
'fields' => 'ids',
'meta_key' => $meta_key,
'meta_value' => $value,
'hide_empty' => false,
'taxonomy' => $this->get_setting( 'taxonomy' ),
'number' => 1
];
$terms = get_terms( $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$term_id = $terms[0];
}
}
// Allow only id to be returned.
if ( ! papi_is_admin() && $this->get_setting( 'fields' ) === 'ids' ) {
$term = $this->get_term_value( $term_id );
} elseif ( ! empty( $term_id ) ) {
$term = get_term( $term_id );
}
if ( empty( $term ) || is_wp_error( $term ) ) {
$term = $this->default_value;
}
return $term;
} | php | {
"resource": ""
} |
q256965 | Papi_Property_Term.get_labels | test | protected function get_labels() {
$results = [];
foreach ( $this->get_taxonomies() as $taxonomy ) {
if ( taxonomy_exists( $taxonomy ) ) {
$taxonomy_object = get_taxonomy( $taxonomy );
$results[$taxonomy] = $taxonomy_object->labels->name;
}
}
return $results;
} | php | {
"resource": ""
} |
q256966 | Papi_Property_Term.get_terms | test | protected function get_terms( $taxonomy ) {
// Prepare arguments for get_terms.
$query = $this->get_setting( 'query' );
$args = array_merge( $query, [
'fields' => 'id=>name'
] );
$terms = [];
if ( taxonomy_exists( $taxonomy ) ) {
$terms = get_terms( $taxonomy, $args );
}
return $terms;
} | php | {
"resource": ""
} |
q256967 | Papi_Property_Term.get_term_value | test | protected function get_term_value( $term ) {
$meta_key = $this->get_setting( 'meta_key' );
if ( is_numeric( $term ) ) {
$term_id = $term;
} else {
$term = get_term( $term );
if ( $term instanceof WP_Term === false ) {
return 0;
}
$term_id = $term->term_id;
}
if ( ! empty( $meta_key ) ) {
$value = get_term_meta( $term_id, $meta_key, true );
} else {
$value = $term_id;
}
return $value;
} | php | {
"resource": ""
} |
q256968 | Papi_Property_Bool.prepare_value | test | protected function prepare_value( $value ) {
if ( is_string( $value ) && ( $value === 'true' || $value === 'on' ) || $value === true ) {
return true;
}
return null;
} | php | {
"resource": ""
} |
q256969 | ApiClient.search | test | public function search($searchTerm)
{
$url = 'https://finance.yahoo.com/_finance_doubledown/api/resource/searchassist;gossipConfig=%7B%22queryKey%22:%22query%22,%22resultAccessor%22:%22ResultSet.Result%22,%22suggestionTitleAccessor%22:%22symbol%22,%22suggestionMeta%22:[%22symbol%22],%22url%22:%7B%22query%22:%7B%22region%22:%22US%22,%22lang%22:%22en-US%22%7D%7D%7D;searchTerm='
.urlencode($searchTerm)
.'?bkt=[%22findd-ctrl%22,%22fin-strm-test1%22,%22fndmtest%22,%22finnossl%22]&device=desktop&feature=canvassOffnet,finGrayNav,newContentAttribution,relatedVideoFeature,videoNativePlaylist,livecoverage&intl=us&lang=en-US&partner=none&prid=eo2okrhcni00f®ion=US&site=finance&tz=UTC&ver=0.102.432&returnMeta=true';
$responseBody = (string) $this->client->request('GET', $url)->getBody();
return $this->resultDecoder->transformSearchResult($responseBody);
} | php | {
"resource": ""
} |
q256970 | ApiClient.getHistoricalData | test | public function getHistoricalData($symbol, $interval, \DateTime $startDate, \DateTime $endDate)
{
$allowedIntervals = [self::INTERVAL_1_DAY, self::INTERVAL_1_WEEK, self::INTERVAL_1_MONTH];
if (!in_array($interval, $allowedIntervals)) {
throw new \InvalidArgumentException('Interval must be one of: '.implode(', ', $allowedIntervals));
}
if ($startDate > $endDate) {
throw new \InvalidArgumentException('Start date must be before end date');
}
$cookieJar = new CookieJar();
$initialUrl = 'https://finance.yahoo.com/quote/'.urlencode($symbol).'/history?p='.urlencode($symbol);
$responseBody = (string) $this->client->request('GET', $initialUrl, ['cookies' => $cookieJar])->getBody();
$crumb = $this->resultDecoder->extractCrumb($responseBody);
$dataUrl = 'https://query1.finance.yahoo.com/v7/finance/download/'.urlencode($symbol).'?period1='.$startDate->getTimestamp().'&period2='.$endDate->getTimestamp().'&interval='.$interval.'&events=history&crumb='.urlencode($crumb);
$responseBody = (string) $this->client->request('GET', $dataUrl, ['cookies' => $cookieJar])->getBody();
return $this->resultDecoder->transformHistoricalDataResult($responseBody);
} | php | {
"resource": ""
} |
q256971 | ApiClient.getQuote | test | public function getQuote($symbol)
{
$list = $this->fetchQuotes([$symbol]);
return isset($list[0]) ? $list[0] : null;
} | php | {
"resource": ""
} |
q256972 | ApiClient.getExchangeRate | test | public function getExchangeRate($currency1, $currency2)
{
$list = $this->getExchangeRates([[$currency1, $currency2]]);
return isset($list[0]) ? $list[0] : null;
} | php | {
"resource": ""
} |
q256973 | ApiClient.getExchangeRates | test | public function getExchangeRates(array $currencyPairs)
{
$currencySymbols = array_map(function (array $currencies) {
return implode($currencies).self::CURRENCY_SYMBOL_SUFFIX; // Currency pairs are suffixed with "=X"
}, $currencyPairs);
return $this->fetchQuotes($currencySymbols);
} | php | {
"resource": ""
} |
q256974 | ApiClient.fetchQuotes | test | private function fetchQuotes(array $symbols)
{
$url = 'https://query1.finance.yahoo.com/v7/finance/quote?symbols='.urlencode(implode(',', $symbols));
$responseBody = (string) $this->client->request('GET', $url)->getBody();
return $this->resultDecoder->transformQuotes($responseBody);
} | php | {
"resource": ""
} |
q256975 | BaseColumn.getAttributesForHeader | test | protected function getAttributesForHeader()
{
$attributes = [];
if ( ! $this->isSortable())
{
$attributes['data-sortable'] = 'false';
}
if ($this->isSortableDefault())
{
$attributes['data-sortable-default'] = $this->sortableDest;
}
$attributes['style'] = 'width:10px;';
return $attributes;
} | php | {
"resource": ""
} |
q256976 | BaseColumn.render | test | public function render($instance, $totalCount, $content = null)
{
if (is_null($content))
{
$content = $this->valueFromInstance($instance, $this->name);
}
$content = $this->renderAppends($instance, $totalCount, $content);
return $this->htmlBuilder->tag('td', $this->getAttributesForCell($instance), $content);
} | php | {
"resource": ""
} |
q256977 | BaseColumn.renderAppends | test | protected function renderAppends($instance, $totalCount, $content)
{
$appends = [$content];
foreach ($this->appends as $append)
{
$appends[] = $append->render($instance, $totalCount);
}
return implode(' ', $appends);
} | php | {
"resource": ""
} |
q256978 | ImagesController.getAll | test | public function getAll()
{
$files = $this->getAllFiles();
$result = [];
foreach ($files as $file)
{
$result[] = $this->createImageObject($file);
}
return $result;
} | php | {
"resource": ""
} |
q256979 | ModelItem.with | test | public function with($params = null)
{
if ( ! is_array($params))
{
$params = func_get_args();
}
$this->with = $params;
return $this;
} | php | {
"resource": ""
} |
q256980 | Form.setDefaults | test | public function setDefaults()
{
foreach ($this->items as $item)
{
$name = $item->getName();
if ( ! is_null($name) && ! isset($this->instance->$name))
{
$this->instance->$name = $item->getDefault();
}
}
} | php | {
"resource": ""
} |
q256981 | Title.get | test | public function get($parameter)
{
if ( ! is_null($this->staticTitle)) return $this->staticTitle;
if (is_null($this->from))
{
throw new TitleNotFormattedException;
}
$from = $this->from;
$property = $this->field;
$model = new $this->from;
$model = $this->getInstance($parameter, $model);
if (isset($model->$property))
{
return $model->$property;
}
throw new ModelAttributeNotFoundException($from, $property);
} | php | {
"resource": ""
} |
q256982 | FormBuilder.makeGroup | test | protected function makeGroup($name, $label, $formElement)
{
$content = '';
$content .= $this->label($name, $label);
$content .= $formElement;
return $this->wrapContent($name, $content);
} | php | {
"resource": ""
} |
q256983 | FormBuilder.wrapContent | test | protected function wrapContent($name, $content)
{
$content .= $this->errors->first($name, $this->getErrorTemplate());
$class = $this->getErrorClass($name);
return $this->wrapGroup($content, compact('class'));
} | php | {
"resource": ""
} |
q256984 | FormBuilder.wrapGroup | test | protected function wrapGroup($content, array $options = [])
{
$options = $this->addClassToOptions($this->getFormGroupClass(), $options);
return $this->html->tag('div', $options, $content);
} | php | {
"resource": ""
} |
q256985 | FormBuilder.addClassToOptions | test | protected function addClassToOptions($classToAdd, array $options = [])
{
$class = array_get($options, 'class', '');
if (is_array($class))
{
$class[] = $classToAdd;
} elseif ( ! empty($class))
{
$class .= ' ' . $classToAdd;
} else
{
$class = $classToAdd;
}
array_set($options, 'class', $class);
return $options;
} | php | {
"resource": ""
} |
q256986 | Router.registerRoutes | test | public function registerRoutes()
{
$this->registerAssetsRoutes();
$this->registerAuthRoutes();
$this->registerImageCacheRoute();
$models = Admin::instance()->models->getAllAliases();
$this->laravelRouter->group([
'prefix' => $this->prefix,
'before' => $this->getBeforeFilters(),
'namespace' => 'SleepingOwl\Admin\Controllers',
], function () use ($models)
{
if (empty($models)) $models = ['__empty_models__'];
$this->laravelRouter->group([
'where' => ['model' => implode('|', $models)]
], function ()
{
foreach (static::$modelRoutes as $route)
{
$url = $route['url'];
$action = $route['action'];
$method = $route['method'];
$controller = isset($route['controller']) ? $route['controller'] : 'AdminController';
$this->laravelRouter->$method($url, [
'as' => $this->routePrefix . '.table.' . $action,
'uses' => $controller . '@' . $action
]);
}
});
$wildcardRoute = $this->laravelRouter->any('{wildcard?}', [
'as' => $this->routePrefix . '.wildcard',
'uses' => 'AdminController@getWildcard'
])->where('wildcard', '.*');
$this->setRoutePriority($wildcardRoute, 0);
});
} | php | {
"resource": ""
} |
q256987 | Router.registerAssetsRoutes | test | protected function registerAssetsRoutes()
{
# CKEditor file listing and upload
$this->laravelRouter->group([
'before' => $this->getBeforeFilters(),
'prefix' => 'images',
'namespace' => 'SleepingOwl\Admin\Controllers'
], function ()
{
$this->laravelRouter->get('all', 'ImagesController@getAll');
$this->laravelRouter->post('upload', 'ImagesController@postUpload');
});
$this->laravelRouter->get('js/{locale}/lang.js', [
'prefix' => $this->prefix,
'as' => $this->routePrefix . '.lang',
'uses' => 'SleepingOwl\Admin\Controllers\LangController@getAll'
]);
} | php | {
"resource": ""
} |
q256988 | Router.registerAuthRoutes | test | protected function registerAuthRoutes()
{
$this->laravelRouter->group([
'prefix' => $this->prefix,
'namespace' => 'SleepingOwl\Admin\Controllers'
], function ()
{
$this->laravelRouter->get('login', [
'as' => $this->routePrefix . '.login',
'uses' => 'AuthController@getLogin'
]);
$this->laravelRouter->post('login', [
'as' => $this->routePrefix . '.login.post',
'uses' => 'AuthController@postLogin'
])->before('csrf');
$this->laravelRouter->get('logout', [
'as' => $this->routePrefix . '.logout',
'uses' => 'AuthController@getLogout'
]);
});
} | php | {
"resource": ""
} |
q256989 | ProcessSet.add | test | public function add(ProcessWrapper $processWrapper): void
{
$className = $processWrapper->getClassName();
if (isset($this->processes[$className])) {
throw new \InvalidArgumentException(
sprintf(
'Testcase with name "%s" was already added, make sure you don\'t have duplicate class names.',
$className
)
);
}
$this->processes[$className] = $processWrapper;
$this->graph->createVertex($className);
if ($this->publisher) {
$this->publisher->publishResults($className, ProcessWrapper::PROCESS_STATUS_QUEUED, null);
}
} | php | {
"resource": ""
} |
q256990 | ProcessSet.get | test | public function get(string $status): array
{
Assertion::choice($status, ProcessWrapper::PROCESS_STATUSES);
$return = [];
foreach ($this->processes as $className => $processWrapper) {
if ($processWrapper->getStatus() === $status) {
$return[$className] = $processWrapper;
}
}
return $return;
} | php | {
"resource": ""
} |
q256991 | ProcessSet.buildTree | test | public function buildTree(): OutTree
{
if ($this->tree === null) {
$root = $this->graph->createVertex(0);
// Create edges directed from the root node
foreach ($this->processes as $className => $processWrapper) {
$vertex = $this->graph->getVertex($className);
if ($processWrapper->getDelayMinutes() === null) { // doesn't depend on anything => link it to the root
$root->createEdgeTo($vertex)->setWeight(0);
} else { // is dependant => link it to its dependency
// Throw error if dependency is to not existing vertex
if (!$this->graph->hasVertex($processWrapper->getDelayAfter())) {
throw new \InvalidArgumentException(
sprintf(
'Testcase "%s" has @delayAfter dependency on "%s", but this testcase was not defined.',
$className,
$processWrapper->getDelayAfter()
)
);
}
$this->graph->getVertex($processWrapper->getDelayAfter())
->createEdgeTo($vertex)
->setWeight($processWrapper->getDelayMinutes());
}
}
}
$this->tree = new OutTree($this->graph);
if (!$this->tree->isTree()) {
throw new \InvalidArgumentException(
sprintf('Cannot build tree graph from tests dependencies. Probably some cyclic dependency is present.')
);
}
return $this->tree;
} | php | {
"resource": ""
} |
q256992 | ProcessSet.optimizeOrder | test | public function optimizeOrder(OptimizeOrderInterface $optimizeStrategy): void
{
$optimizedOrder = $optimizeStrategy->optimize($this->buildTree());
// Sort the $optimizedOrder array to have the same order as corresponding array of processes
// (so that the array could be passed to array_multisort())
$sortingArray = [];
foreach ($this->processes as $processClassName => $processObject) {
$sortingArray[$processClassName] = $optimizedOrder[$processClassName];
}
// Sort processes descending according to corresponding values in $sortingArray
array_multisort($sortingArray, SORT_DESC, SORT_NUMERIC, $this->processes);
} | php | {
"resource": ""
} |
q256993 | ProcessSet.countStatuses | test | public function countStatuses(): array
{
$statusesCount = [];
foreach (ProcessWrapper::PROCESS_STATUSES as $status) {
$statusesCount[$status] = count($this->get($status));
}
return $statusesCount;
} | php | {
"resource": ""
} |
q256994 | ProcessSet.countResults | test | public function countResults(): array
{
$done = $this->get(ProcessWrapper::PROCESS_STATUS_DONE);
$doneClasses = [];
$resultsCount = [
ProcessWrapper::PROCESS_RESULT_PASSED => 0,
ProcessWrapper::PROCESS_RESULT_FAILED => 0,
ProcessWrapper::PROCESS_RESULT_FATAL => 0,
];
// Retrieve names of done processes and count their results
foreach ($done as $className => $processObject) {
$doneClasses[] = $className;
$resultsCount[$processObject->getResult()]++;
}
return $resultsCount;
} | php | {
"resource": ""
} |
q256995 | ProcessSet.failDependants | test | public function failDependants(string $className): array
{
$descendantProcesses = $this->getDependencyTree($className);
$failedProcesses = [];
foreach ($descendantProcesses as $processClassName => $processWrapper) {
$failedProcesses[$processClassName] = $processWrapper;
$processWrapper->setStatus(ProcessWrapper::PROCESS_STATUS_DONE);
}
return $failedProcesses;
} | php | {
"resource": ""
} |
q256996 | ProcessSet.getDependencyTree | test | protected function getDependencyTree(string $className): array
{
Assertion::notEmpty($this->tree, 'Cannot get dependency tree - the tree was not yet build using buildTree()');
$descendants = $this->tree->getVerticesDescendant($this->graph->getVertex($className));
/** @var ProcessWrapper[] $descendantProcesses */
$descendantProcesses = [];
/** @var Vertex $descendant */
foreach ($descendants as $descendant) {
$descendantProcesses[$descendant->getId()] = $this->processes[$descendant->getId()];
}
return $descendantProcesses;
} | php | {
"resource": ""
} |
q256997 | StewardStyle.output | test | public function output(string $output, string $identifier): void
{
if (empty($output)) {
return;
}
$lines = explode("\n", $output);
foreach ($lines as $line) {
// color lines containing "[WARN]" or "[DEBUG]"
if (mb_strpos($line, '[WARN]') !== false) {
$line = '<fg=black;bg=yellow>' . $line . '</fg=black;bg=yellow>';
} elseif (mb_strpos($line, '[DEBUG]') !== false) {
$line = '<comment>' . $line . '</comment>';
}
$this->write($identifier . '> ');
$this->writeln($line);
}
} | php | {
"resource": ""
} |
q256998 | StewardStyle.errorOutput | test | public function errorOutput(string $output, string $identifier): void
{
$output = rtrim($output);
if (empty($output)) {
return;
}
$lines = explode("\n", $output);
foreach ($lines as $line) {
$this->write('<error>' . $identifier . ' ERR> ');
$this->writeln($line . '</>');
}
} | php | {
"resource": ""
} |
q256999 | RunCommand.initialize | test | protected function initialize(InputInterface $input, OutputInterface $output): void
{
parent::initialize($input, $output);
$output->writeln(
sprintf(
'<info>Steward</info> <comment>%s</comment> is running the tests...%s',
$this->getApplication()->getVersion(),
(!(new CiDetector())->isCiDetected() ? ' Just for you <fg=red><3</fg=red>!' : '')
)
);
// If browser name or env is empty, ends initialization and let the Console/Command fail on input validation
if (empty($input->getArgument(self::ARGUMENT_BROWSER))
|| empty($input->getArgument(self::ARGUMENT_ENVIRONMENT))
) {
return;
}
// Browser name is case insensitive, normalize it to lower case
$browserNormalized = mb_strtolower($input->getArgument(self::ARGUMENT_BROWSER));
// Check if browser is supported
if (!isset($this->supportedBrowsers[$browserNormalized])) {
throw new \RuntimeException(
sprintf(
'Browser "%s" is not supported (use one of: %s)',
$browserNormalized,
implode(', ', array_keys($this->supportedBrowsers))
)
);
}
// Set WebDriver browser identifier back to the argument value
$input->setArgument(self::ARGUMENT_BROWSER, $this->supportedBrowsers[$browserNormalized]);
if ($output->isVerbose()) {
$output->writeln(sprintf('Browser: %s', $input->getArgument(self::ARGUMENT_BROWSER)));
$output->writeln(sprintf('Environment: %s', $input->getArgument(self::ARGUMENT_ENVIRONMENT)));
}
// Initialize Selenium server adapter and normalize server URL
$seleniumAdapter = $this->getSeleniumAdapter($input->getOption(self::OPTION_SERVER_URL));
$input->setOption(self::OPTION_SERVER_URL, $seleniumAdapter->getServerUrl());
// Make sure parallel-limit is greater than 0
$parallelLimit = (int) $input->getOption(self::OPTION_PARALLEL_LIMIT);
if ($parallelLimit === 0) {
throw new \RuntimeException('Parallel limit must be a whole number greater than 0');
}
$input->setOption(self::OPTION_PARALLEL_LIMIT, $parallelLimit);
$this->getDispatcher()->dispatch(
CommandEvents::RUN_TESTS_INIT,
new ExtendedConsoleEvent($this, $input, $output)
);
if ($output->isVeryVerbose()) {
$output->writeln(
sprintf('Path to logs: %s', $this->config[ConfigOptions::LOGS_DIR])
);
$output->writeln(
sprintf('Ignore delays: %s', ($input->getOption(self::OPTION_IGNORE_DELAYS)) ? 'yes' : 'no')
);
$output->writeln(
sprintf('Parallel limit: %d', $input->getOption(self::OPTION_PARALLEL_LIMIT))
);
}
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.