_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q258500
Translations.defineCategoryTranslations
test
public static function defineCategoryTranslations() { // Bail if translation plugin is not active if (!is_plugin_active('polylang-pro/polylang.php') || empty($apiUrl = get_field('event_api_url', 'option'))) { return; } // Build request URL $apiUrl = rtrim($apiUrl, '/').'/event_categories?per_page=100'; // Get categories from Event Manager API $result = \EventManagerIntegration\Parser::requestApi($apiUrl); if (!$result || is_wp_error($result) || !is_array($result)) { return; } // Lowercase term names $result = array_map( function ($category) { $category['name'] = strtolower($category['name']); return $category; }, $result ); // Get all local categories $categories = get_terms( array( 'taxonomy' => 'event_categories', 'hide_empty' => false, 'lang' => '', ) ); // Collect list of matched new and original term ID $categoryIds = array(); // Collect term IDs and set lang + translations to categories array foreach ($categories as &$category) { $category->lang = ''; $category->translations = array(); // See if the term exists in both(local and external API) lists if (false !== $key = array_search(strtolower($category->name), array_column($result, 'name'))) { $categoryIds[$result[$key]['id']] = $category->term_id; $category->lang = $result[$key]['lang'] ?? ''; $category->translations = $result[$key]['translations'] ?? array(); } } // Save term lang and define its translations foreach ($categories as $category) { // Save term lang if (!empty($category->lang)) { pll_set_term_language($category->term_id, $category->lang); } // Define translations if (!empty($category->translations)) { // Replace the original IDs from translations array with the local terms IDs $translations = array_filter( array_map( function ($lang) use ($categoryIds) { return array_key_exists($lang, $categoryIds) ? $categoryIds[$lang] : false; }, $category->translations ) ); if (empty($translations)) { continue; } // Save translations pll_save_term_translations($translations); } } return; }
php
{ "resource": "" }
q258501
Event.beforeSave
test
public function beforeSave() { $this->post_title = strip_tags(html_entity_decode($this->post_title)); $this->post_content = html_entity_decode($this->post_content); }
php
{ "resource": "" }
q258502
Event.afterSave
test
public function afterSave() { $this->saveOccasions(); $this->saveCategories(); $this->saveGroups(); $this->saveTags(); $this->saveLocation(); $this->saveAddLocations(); $this->saveLanguage(); if (!empty($this->gallery)) { foreach ($this->gallery as $key => $image) { $this->setFeaturedImageFromUrl($image['url'], false); } } return true; }
php
{ "resource": "" }
q258503
Event.saveLocation
test
public function saveLocation() { if ($this->location != null) { if (!empty($this->location['parent']) && $this->location['parent']['id'] > 0) { $this->location['title'] = $this->location['parent']['title'].', '.$this->location['title']; } if (!empty($location['latitude']) && !empty($location['longitude'])) { update_post_meta($this->ID, 'latitude', $location['latitude']); update_post_meta($this->ID, 'longitude', $location['longitude']); } update_post_meta($this->ID, 'location', $this->location); } }
php
{ "resource": "" }
q258504
Event.saveAddLocations
test
public function saveAddLocations() { if (is_array($this->additional_locations) && !empty($this->additional_locations)) { foreach ($this->additional_locations as &$location) { if (!empty($location['parent']) && $location['parent']['id'] > 0) { $location['title'] = $location['parent']['title'].', '.$location['title']; } } update_post_meta($this->ID, 'additional_locations', $this->additional_locations); } }
php
{ "resource": "" }
q258505
Event.saveCategories
test
public function saveCategories() { if (empty($this->categories)) { $terms = wp_get_post_terms($this->ID, 'event_categories', array('fields' => 'all')); if (!empty($terms)) { foreach ($terms as $term) { wp_remove_object_terms($this->ID, $term->term_id, 'event_categories'); } delete_post_meta($this->ID, 'categories'); } } else { wp_set_object_terms($this->ID, $this->categories, 'event_categories', false); } }
php
{ "resource": "" }
q258506
Event.saveGroups
test
public function saveGroups() { // Save group names as new array $event_groups = array(); if (!empty($this->groups) && is_array($this->groups)) { foreach ($this->groups as $group) { $event_groups[] .= $group['name']; } } wp_set_object_terms($this->ID, $event_groups, 'event_groups', false); }
php
{ "resource": "" }
q258507
Event.saveTags
test
public function saveTags() { if (empty($this->tags)) { $terms = wp_get_post_terms($this->ID, 'event_tags', array('fields' => 'all')); if (!empty($terms)) { foreach ($terms as $term) { wp_remove_object_terms($this->ID, $term->term_id, 'event_tags'); } delete_post_meta($this->ID, 'tags'); } } else { wp_set_object_terms($this->ID, $this->tags, 'event_tags', false); } }
php
{ "resource": "" }
q258508
Event.saveOccasions
test
public function saveOccasions() { global $wpdb; // Delete all occasions related to the event $db_table = $wpdb->prefix."integrate_occasions"; $wpdb->delete($db_table, array('event_id' => $this->ID), array('%d')); // Remove post if occasions is missing if ($this->occasions_complete == null || empty($this->occasions_complete)) { wp_delete_post($this->ID, true); return false; } // Loop through occasions for the event foreach ($this->occasions_complete as $o) { $start_date = !empty($o['start_date']) ? $o['start_date'] : null; $end_date = !empty($o['end_date']) ? $o['end_date'] : null; $door_time = !empty($o['door_time']) ? $o['door_time'] : null; $status = !empty($o['status']) ? $o['status'] : null; $occ_exeption_information = !empty($o['occ_exeption_information']) ? $o['occ_exeption_information'] : null; $content_mode = !empty($o['content_mode']) ? $o['content_mode'] : null; $content = !empty($o['content']) ? $o['content'] : null; $wpdb->insert( $db_table, array( 'event_id' => $this->ID, 'start_date' => $start_date, 'end_date' => $end_date, 'door_time' => $door_time, 'status' => $status, 'exception_information' => $occ_exeption_information, 'content_mode' => $content_mode, 'content' => ($content), ) ); } return true; }
php
{ "resource": "" }
q258509
Event.saveLanguage
test
public function saveLanguage() { // Bail if Polylang is not active if (!is_plugin_active('polylang-pro/polylang.php')) { return; } // Apply language to the event if (!empty($this->lang)) { pll_set_post_language($this->ID, $this->lang); } // Define which events are translations of each other if (!empty($this->translations)) { $translations = $this->translations; // Get locally installed languages $localLangs = pll_languages_list(); // Remove all languages that don't exist locally $translations = array_filter( $translations, function ($translation) use ($localLangs) { return in_array($translation, $localLangs); }, ARRAY_FILTER_USE_KEY ); // Replace the old IDs with new events IDs foreach ($translations as $key => &$id) { $id = $this->getEventByOriginalId($id); if (!$id) { // Remove if event cant't be found unset($translations[$key]); } } // Define event translations pll_save_post_translations($translations); } }
php
{ "resource": "" }
q258510
Event.getEventByOriginalId
test
public function getEventByOriginalId($id) { $args = array( 'meta_query' => array( array( 'key' => '_event_manager_id', 'value' => $id, ), ), 'post_type' => $this->post_type, 'posts_per_page' => '1', ); $events = get_posts($args); if (is_wp_error($events) || !isset($events[0]->ID)) { return false; } return $events[0]->ID; }
php
{ "resource": "" }
q258511
EventManagerApi.checkFilters
test
public function checkFilters($cat_filter, $tag_filter): bool { $tax_filter = (empty(get_field('event_filter_cat', 'options')) && empty( get_field( 'event_filter_tag', 'options' ) )) ? true : false; // Check category filters if (!empty(get_field('event_filter_cat', 'options'))) { $tax_filter = $cat_filter; } // Check tag filters if (!$tax_filter && !empty(get_field('event_filter_tag', 'options'))) { $tax_filter = $tag_filter; } return $tax_filter; }
php
{ "resource": "" }
q258512
EventManagerApi.removeExpiredOccasions
test
public function removeExpiredOccasions() { global $wpdb; $date_limit = strtotime("midnight now") - 1; // Get all occasions from database $db_table = $wpdb->prefix."integrate_occasions"; $occasions = $wpdb->get_results("SELECT * FROM $db_table ORDER BY start_date DESC", ARRAY_A); if (count($occasions) == 0) { return; } foreach ($occasions as $o) { // Delete the occasion if expired if (strtotime($o['end_date']) < $date_limit) { $id = $o['ID']; $wpdb->delete($db_table, array('ID' => $id)); } } return; }
php
{ "resource": "" }
q258513
EventManagerApi.removeDeletedEvents
test
public function removeDeletedEvents($ids) { global $wpdb; $table = $wpdb->prefix . "integrate_occasions"; // Get all locally stored events $localEvents = $wpdb->get_results("SELECT event_id FROM {$table} GROUP BY event_id", ARRAY_N); $localEvents = array_map(function($id) { return $id[0]; }, $localEvents); // Collect local IDs of the API events $apiEvents = array_map(function($id) { $post = get_posts(array( 'post_type' => 'event', 'post_status' => array('publish', 'draft'), 'meta_key' => '_event_manager_id', 'meta_value' => $id, 'posts_per_page' => 1 )); return $post[0]->ID ?? null; }, array_unique($ids)); $apiEvents = array_filter($apiEvents); // Collect events that is stored locally but is missing in the API $diffEvents = array_diff($localEvents, $apiEvents); // Loop through the diff and delete its occasions if (!empty($diffEvents)) { foreach ($diffEvents as $event) { $wpdb->delete($table, array('event_id' => $event)); } } }
php
{ "resource": "" }
q258514
EventManagerApi.removeExpiredEvents
test
public function removeExpiredEvents() { global $wpdb; $post_type = 'event'; // Get all events from databse $query = "SELECT ID FROM $wpdb->posts WHERE post_type = %s AND (post_status = %s or post_status = %s)"; $completeQuery = $wpdb->prepare($query, $post_type, 'publish', 'draft'); $events = $wpdb->get_results($completeQuery); if (count($events) == 0) { return; } $db_table = $wpdb->prefix."integrate_occasions"; $query = "SELECT ID, event_id FROM $db_table WHERE event_id = %s"; // Loop through events and check if occasions exist foreach ($events as $e) { $completeQuery = $wpdb->prepare($query, $e->ID); $results = $wpdb->get_results($completeQuery); // Delete event if occasions is empty if (count($results) == 0) { wp_delete_post($e->ID, true); } } return; }
php
{ "resource": "" }
q258515
EventManagerApi.filterTaxonomies
test
public function filterTaxonomies($taxonomies, $type) { $passes = true; $tax_array = ($type == 0) ? get_field('event_filter_cat', 'options') : get_field('event_filter_tag', 'options'); if (!empty($tax_array)) { $filters = array_map('trim', explode(',', $tax_array)); $taxLower = array_map('strtolower', $taxonomies); $passes = false; foreach ($filters as $filter) { if (in_array(strtolower($filter), $taxLower)) { $passes = true; } } } return $passes; }
php
{ "resource": "" }
q258516
EventManagerApi.deleteEmptyTaxonomies
test
public function deleteEmptyTaxonomies() { if (!empty(get_object_taxonomies('event'))) { foreach (get_object_taxonomies('event') as $taxonomy) { // Skip Event Groups and categories if ($taxonomy == 'event_groups' || $taxonomy == 'event_categories') { continue; } $terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => false, 'childless' => true, ) ); foreach ($terms as $term) { if ($term->count == 0) { wp_delete_term($term->term_id, $taxonomy); } } } } }
php
{ "resource": "" }
q258517
Location.renderLocationList
test
public function renderLocationList($post) { $api_url = get_field('event_api_url', 'option'); $location_endpoint = rtrim($api_url, '/') . '/location/complete'; @$json = file_get_contents($location_endpoint); if ($json == false) { $markup = '<em>' . __('Something went wrong, pleae check your API url.', 'event-integration') . '</em>'; } else { $locations = json_decode($json); $location_data = get_field('mod_location_data', $post->ID); $current = ($location_data) ? $location_data->id : false; if (!empty($locations)) { $markup = '<select name="mod_location">'; foreach ($locations as $location) { $selected = ($current == $location->id) ? 'selected' : ''; $markup .= '<option value="' . $location->id . '" ' . $selected . '>' . $location->title . '</option>'; } $markup .= '</select>'; } else { $markup = '<em>' . __('No locations found', 'event-integration') . '</em>'; } } echo $markup; }
php
{ "resource": "" }
q258518
Location.saveLocation
test
public function saveLocation($post_id, $post, $update) { $api_url = get_field('event_api_url', 'option'); $location_endpoint = rtrim($api_url, '/') . '/location/'; if (isset($_POST['mod_location'])) { $location_endpoint = rtrim($api_url, '/') . '/location/' . $_POST['mod_location'] . '?_embed'; @$json = file_get_contents($location_endpoint); if ($json != false) { $location = json_decode($json); update_post_meta($post_id, 'mod_location_data', $location); } } return; }
php
{ "resource": "" }
q258519
CacheBust.getRevManifest
test
public static function getRevManifest() { $jsonPath = EVENTMANAGERINTEGRATION_PATH . apply_filters('EventManagerIntegration/Helper/CacheBust/RevManifestPath', 'dist/rev-manifest.json'); if (file_exists($jsonPath)) { return json_decode(file_get_contents($jsonPath), true); } elseif (WP_DEBUG) { echo '<div style="color:red">Error: Assets not built. Go to ' . EVENTMANAGERINTEGRATION_PATH . ' and run gulp. See '. EVENTMANAGERINTEGRATION_PATH . 'README.md for more info.</div>'; } }
php
{ "resource": "" }
q258520
AdminDisplayEvent.removeMetaBoxes
test
public function removeMetaBoxes() { if (function_exists('get_field')) { if (get_field('event_update_button', 'option') == false) { remove_meta_box('submitdiv', $this->post_type, 'side'); } } remove_meta_box('acf-group_56c33cf1470dc', $this->post_type, 'side'); remove_meta_box('pageparentdiv', $this->post_type, 'side'); }
php
{ "resource": "" }
q258521
AdminDisplayEvent.outputMeta
test
public function outputMeta($data) { $unserialized = @unserialize($data); if ($unserialized !== false) { return $this->multiImplode($unserialized, ', '); } else { return $data; } }
php
{ "resource": "" }
q258522
AdminDisplayEvent.multiImplode
test
public function multiImplode($array, $glue) { $string = ''; foreach ($array as $key => $item) { if (empty($item)) { continue; } if (is_array($item)) { $string .= '<p>' . $this->multiImplode($item, $glue) . '</p>'; } else { $string .= $item . $glue; } } $string = substr($string, 0, 0-strlen($glue)); return $string; }
php
{ "resource": "" }
q258523
CustomPostType.registerPostType
test
public function registerPostType() { $labels = array( 'name' => $this->nameSingular, 'singular_name' => $this->nameSingular, 'add_new' => sprintf(__('Add new %s', 'event-manager'), $this->nameSingular), 'add_new_item' => sprintf(__('Add new %s', 'event-manager'), $this->nameSingular), 'edit_item' => sprintf(__('Edit %s', 'event-manager'), $this->nameSingular), 'new_item' => sprintf(__('New %s', 'event-manager'), $this->nameSingular), 'view_item' => sprintf(__('View %s', 'event-manager'), $this->nameSingular), 'search_items' => sprintf(__('Search %s', 'event-manager'), $this->namePlural), 'not_found' => sprintf(__('No %s found', 'event-manager'), $this->namePlural), 'not_found_in_trash' => sprintf(__('No %s found in trash', 'event-manager'), $this->namePlural), 'parent_item_colon' => sprintf(__('Parent %s:', 'event-manager'), $this->nameSingular), 'menu_name' => $this->namePlural, ); $this->args['labels'] = $labels; register_post_type($this->slug, $this->args); return $this->slug; }
php
{ "resource": "" }
q258524
CustomPostType.addTableColumn
test
public function addTableColumn($key, $title, $sortable = false, $contentCallback = false) { $this->tableColumns[$key] = $title; if ($sortable === true) { $this->tableSortableColumns[$key] = $key; } if ($contentCallback !== false) { $this->tableColumnsContentCallback[$key] = $contentCallback; } }
php
{ "resource": "" }
q258525
CustomPostType.tableColumns
test
public function tableColumns($columns) { if (!empty($this->tableColumns) && is_array($this->tableColumns)) { $columns = $this->tableColumns; } return $columns; }
php
{ "resource": "" }
q258526
CustomPostType.tableSortableColumns
test
public function tableSortableColumns($columns) { if (!empty($this->tableSortableColumns) && is_array($this->tableSortableColumns)) { $columns = $this->tableColumns; } function arraytolower(array $columns, $round = 0) { return unserialize(strtolower(serialize($columns))); } return arraytolower($columns); }
php
{ "resource": "" }
q258527
CustomPostType.tableColumnsContent
test
public function tableColumnsContent($column, $postId) { if (!isset($this->tableColumnsContentCallback[$column])) { return; } call_user_func_array($this->tableColumnsContentCallback[$column], array($column, $postId)); }
php
{ "resource": "" }
q258528
EventManagerGroups.saveTerms
test
public function saveTerms($name, $slug, $taxonomy, $parent = 0) { $term = get_term_by('slug', $slug, $taxonomy); if ($term == false) { $new_term = wp_insert_term($name, $taxonomy, array('slug' => $slug, 'parent' => $parent)); $term_id = $new_term['term_id']; $this->activateNewGroup($term_id, $parent); } else { wp_update_term($term->term_id, $taxonomy, array('name' => $name, 'parent' => $parent)); $term_id = $term->term_id; } return $term_id; }
php
{ "resource": "" }
q258529
EventManagerGroups.activateNewGroup
test
public function activateNewGroup($termId, $parentId) { $selectedGroups = get_option('options_event_filter_group', false); if (is_array($selectedGroups) && !empty($selectedGroups)) { if (in_array($parentId, $selectedGroups)) { // Add children to option array $selectedGroups[] = (int) $termId; update_field('event_filter_group', $selectedGroups, 'option'); } } }
php
{ "resource": "" }
q258530
PostManager.removeEmpty
test
public function removeEmpty($metaValue) { if (is_array($metaValue)) { return $metaValue; } return ($metaValue !== null && $metaValue !== false && $metaValue !== ''); }
php
{ "resource": "" }
q258531
PostManager.getEmptyValues
test
public function getEmptyValues($metaValue) { if (is_array($metaValue) && empty($metaValue)) { return $metaValue; } return ($metaValue == null || $metaValue == false || $metaValue == ''); }
php
{ "resource": "" }
q258532
PostManager.removeEmptyMeta
test
public function removeEmptyMeta($meta, $post_id) { foreach ($meta as $key => $value) { $meta = get_post_meta($post_id, $key, true); if ($meta) { delete_post_meta($post_id, $key); } } }
php
{ "resource": "" }
q258533
PostManager.save
test
public function save() { $this->beforeSave(); // Arrays for holding save data $post = array(); $meta = array(); $post['post_status'] = $this->post_status; // Get the default class variables and set it's keys to forbiddenKeys $defaultData = get_class_vars(get_class($this)); $forbiddenKeys = array_keys($defaultData); $data = array_filter(get_object_vars($this), function ($item) use ($forbiddenKeys) { return !in_array($item, $forbiddenKeys); }, ARRAY_FILTER_USE_KEY); // If data key is allowed post field add to $post else add to $meta foreach ($data as $key => $value) { if (in_array($key, $this->allowedPostFields)) { $post[$key] = $value; continue; } $meta[$key] = $value; } // Save empty meta to array $empty_meta_values = array_filter($meta, array($this, 'getEmptyValues')); // Do not include null values in meta $meta = array_filter($meta, array($this, 'removeEmpty')); $post['post_type'] = $this->post_type; $post['meta_input'] = $meta; // Check if duplicate by matching "_event_manager_id" meta value if (isset($meta['_event_manager_id'])) { $duplicate = self::get( 1, array( 'relation' => 'AND', array( 'key' => '_event_manager_id', 'value' => $meta['_event_manager_id'], 'compare' => '=' ) ), $this->post_type ); } // Update if duplicate if (isset($duplicate->ID)) { //Check if event needs to be updated if (get_post_meta($duplicate->ID, 'last_update', true) != $meta['last_update']) { $post['ID'] = $duplicate->ID; $this->ID = wp_update_post($post); $isDuplicate = true; } else { return false; } } else { // Create if not duplicate $this->ID = wp_insert_post($post, true); } // Remove empty meta values from db $this->removeEmptyMeta($empty_meta_values, $this->ID); return $this->afterSave(); }
php
{ "resource": "" }
q258534
PostManager.attachmentExists
test
private function attachmentExists($src) { global $wpdb; $query = "SELECT ID FROM {$wpdb->posts} WHERE guid = '$src'"; $id = $wpdb->get_var($query); if (!empty($id) && $id > 0) { return $id; } return false; }
php
{ "resource": "" }
q258535
SubmitForm.submitFormCallback
test
public function submitFormCallback($atts = [], $content = null, $tag = '') { // Normalize attribute keys, lowercase $atts = array_change_key_case((array)$atts, CASE_LOWER); // Override default attributes with user attributes $data = shortcode_atts([ 'user_groups' => '', ], $atts, $tag); $data = array_merge($data, \EventManagerIntegration\Helper\SubmitEvent::geFields()); return \EventManagerIntegration\Helper\RenderBlade::blade( 'formfields', $data, EVENTMANAGERINTEGRATION_PATH . 'source/php/Module/SubmitForm/views/' ); }
php
{ "resource": "" }
q258536
EventArchive.addEventDateArgsToPermalinks
test
public function addEventDateArgsToPermalinks($permalink, $post, $leavename) { if (!isset($post->start_date) || $post->post_type != $this->eventPostType) { return $permalink; } return esc_url(add_query_arg('date', preg_replace('/\D/', '', $post->start_date), $permalink)); }
php
{ "resource": "" }
q258537
EventArchive.eventFilterWhere
test
public function eventFilterWhere($where) { $from = null; $to = null; if (isset($_GET['from']) && !empty($_GET['from'])) { $from = sanitize_text_field($_GET['from']); } if (isset($_GET['to']) && !empty($_GET['to'])) { $to = date('Y-m-d', strtotime("+1 day", strtotime(sanitize_text_field($_GET['to'])))); } if (!is_null($from) && !is_null($to)) { // USE BETWEEN ON START DATE $where = str_replace( "{$this->db->posts}.post_date >= '{$from}'", "{$this->dbTable}.start_date BETWEEN CAST('{$from}' AS DATE) AND CAST('{$to}' AS DATE)", $where ); $where = str_replace( "AND {$this->db->posts}.post_date <= '{$to}'", "", $where ); } elseif (!is_null($from) || !is_null($to)) { // USE FROM OR TO $where = str_replace("{$this->db->posts}.post_date >=", "{$this->dbTable}.start_date >=", $where); $where = str_replace("{$this->db->posts}.post_date <=", "{$this->dbTable}.end_date <=", $where); } return $where; }
php
{ "resource": "" }
q258538
SingleEventData.singleEventDate
test
public static function singleEventDate() { global $post; $singleOccasion = array(); $get_date = (!empty(get_query_var('date'))) ? get_query_var('date') : false; $occasions = QueryEvents::getEventOccasions($post->ID); //Get nearest occasions from time if no date arg if (!$get_date) { $get_date = self::getNextOccasionDate($occasions); } if (is_array($occasions) && count($occasions) == 1) { $singleOccasion = (array)$occasions[0]; $singleOccasion['formatted'] = \EventManagerIntegration\App::formatEventDate($singleOccasion['start_date'], $singleOccasion['end_date']); $singleOccasion['date_parts'] = self::dateParts($singleOccasion['start_date']); } elseif (is_array($occasions) && $get_date != false) { foreach ($occasions as $occasion) { $occasion = (array)$occasion; $event_date = preg_replace('/\D/', '', $occasion['start_date']); if ($get_date == $event_date) { $singleOccasion = $occasion; $singleOccasion['formatted'] = \EventManagerIntegration\App::formatEventDate($occasion['start_date'], $occasion['end_date']); $singleOccasion['date_parts'] = self::dateParts($occasion['start_date']); } } } return $singleOccasion; }
php
{ "resource": "" }
q258539
SingleEventData.getNextOccasionDate
test
public static function getNextOccasionDate($occasions, $dateFormat = 'YmdHis') { if (!is_array($occasions) || empty($occasions)) { return false; } $startDates = array(); foreach ($occasions as $occasion) { //Skip if event has ended if (time() > strtotime($occasion->end_date) || !isset($occasion->start_date) || !isset($occasion->end_date)) { continue; } $startDates[] = strtotime($occasion->start_date); } return date($dateFormat, self::getClosest(time(), $startDates)); }
php
{ "resource": "" }
q258540
SingleEventData.getClosest
test
public static function getClosest($search, $arr) { $closest = null; foreach ($arr as $item) { if ($closest === null || abs($search - $closest) > abs($item - $search)) { $closest = $item; } } return $closest; }
php
{ "resource": "" }
q258541
SingleEventData.dateParts
test
public static function dateParts($start_date) { $start = date('Y-m-d H:i:s', strtotime($start_date)); $date = array( 'date' => mysql2date('j', $start, true), 'month' => mysql2date('F', $start, true), 'month_short' => substr(mysql2date('F', $start, true), 0, 3), 'year' => mysql2date('Y', $start, true), 'time' => mysql2date('H:i', $start, true), ); return $date; }
php
{ "resource": "" }
q258542
Options.saveDrawPoints
test
public function saveDrawPoints() { if (!isset($_POST['coordinates']) && !empty($_POST['coordinates'])) { wp_send_json_error("Missing coordinates"); } $points = $_POST['coordinates']; // Convert coordinates to float foreach ($points as &$point) { $point = array_map('floatval', $point); } update_option('event_import_area', $points); wp_send_json_success($points); }
php
{ "resource": "" }
q258543
App.enqueueAdmin
test
public function enqueueAdmin() { // Styles wp_register_style('event-integration-admin', EVENTMANAGERINTEGRATION_URL . '/dist/' . Helper\CacheBust::name('css/event-manager-integration-admin.css')); wp_enqueue_style('event-integration-admin'); // Scripts wp_register_script('event-integration-admin', EVENTMANAGERINTEGRATION_URL . '/dist/' . Helper\CacheBust::name('js/event-integration-admin.js'), true); wp_localize_script('event-integration-admin', 'eventintegration', array( 'ajaxurl' => admin_url('admin-ajax.php') )); wp_localize_script('event-integration-admin', 'eventIntegrationAdmin', array( 'loading' => __("Loading", 'event-integration'), 'options' => array( 'areaCoordinates' => get_option('event_import_area') ? get_option('event_import_area') : null ) )); wp_enqueue_script('event-integration-admin'); // Re-enqueue Google Maps JS Api with additional libraries: Places, Drawing if (isset($_GET['page']) && $_GET['page'] === 'event-options' && $googleApiKey = get_field('google_geocode_key', 'option')) { wp_enqueue_script('google-maps-api', '//maps.googleapis.com/maps/api/js?key=' . $googleApiKey . '&libraries=places,drawing', array(), '', true); } }
php
{ "resource": "" }
q258544
App.enqueueFront
test
public function enqueueFront() { // Styles wp_enqueue_style( 'event-integration', EVENTMANAGERINTEGRATION_URL . '/dist/' . Helper\CacheBust::name('css/event-manager-integration.css')); // Scripts // Google Maps JS Api if ($googleApiKey = get_field('google_geocode_key', 'option')) { wp_enqueue_script('google-maps-api', '//maps.googleapis.com/maps/api/js?key=' . $googleApiKey . '', array(), '', true); } wp_register_script('auto-complete', EVENTMANAGERINTEGRATION_URL . '/source/js/vendor/auto-complete/auto-complete.min.js', 'jquery', false, true); wp_enqueue_script('auto-complete'); wp_register_script('event-integration', EVENTMANAGERINTEGRATION_URL . '/dist/' . Helper\CacheBust::name('js/event-integration-front.js'), 'jquery', false, true); wp_localize_script('event-integration', 'eventintegration', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'apiurl' => get_field('event_api_url', 'option'), )); wp_localize_script('event-integration', 'eventIntegrationFront', array( 'event_pagination_error' => __("Something went wrong, please try again later.", 'event-integration'), 'email_not_matching' => __("The email addresses does not match.", 'event-integration'), 'must_upload_image' => __("You must upload an image.", 'event-integration'), )); wp_enqueue_script('event-integration'); }
php
{ "resource": "" }
q258545
App.formatShortDate
test
public static function formatShortDate($start_date) { $start = date('Y-m-d H:i:s', strtotime($start_date)); $today = (date('Ymd') == date('Ymd', strtotime($start_date))) ? true : false; $date = array( 'today' => $today, 'date' => mysql2date('j', $start, true), 'month' => substr(mysql2date('F', $start, true), 0, 3), 'time' => mysql2date('H:i', $start, true), ); return $date; }
php
{ "resource": "" }
q258546
App.importEventsCron
test
public function importEventsCron() { if (get_field('event_daily_import', 'option') == true && $apiUrl = Helper\ApiUrl::buildApiUrl()) { new Parser\EventManagerApi($apiUrl); } }
php
{ "resource": "" }
q258547
App.importPublishingGroups
test
public static function importPublishingGroups() { $api_url = get_field('event_api_url', 'option'); if ($api_url) { $api_url = rtrim($api_url, '/') . '/user_groups'; new Parser\EventManagerGroups($api_url); } }
php
{ "resource": "" }
q258548
App.checkDatabaseTable
test
public static function checkDatabaseTable() { global $wpdb; $table_name = $wpdb->prefix . 'integrate_occasions'; if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { self::databaseCreation(); } return; }
php
{ "resource": "" }
q258549
App.databaseCreation
test
public static function databaseCreation() { global $wpdb; global $event_db_version; $table_name = $wpdb->prefix . 'integrate_occasions'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, event_id BIGINT(20) UNSIGNED NOT NULL, start_date DATETIME NOT NULL, end_date DATETIME NOT NULL, door_time DATETIME DEFAULT NULL, status VARCHAR(50) DEFAULT NULL, exception_information VARCHAR(400) DEFAULT NULL, content_mode VARCHAR(50) DEFAULT NULL, content LONGTEXT DEFAULT NULL, PRIMARY KEY (ID) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); add_option('event_db_version', $event_db_version); }
php
{ "resource": "" }
q258550
Parser.checkIfEventExists
test
public function checkIfEventExists($event_manager_id) { global $wpdb; $results = $wpdb->get_results( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_event_manager_id' AND meta_value = $event_manager_id LIMIT 1", ARRAY_A ); if (!empty($results[0]['post_id'])) { return $results[0]['post_id']; } else { return false; } }
php
{ "resource": "" }
q258551
Parser.requestApi
test
public static function requestApi($url) { // Dont verify ssl cert in dev mode $args = array( 'timeout' => 120, 'sslverify' => defined('DEV_MODE') && DEV_MODE == true ? false : true, 'headers' => array( 'ClientSolution' => 'WordPress Integration '.EVENTMANAGERINTEGRATION_ID, 'PhpVersion' => phpversion(), 'referrer' => get_home_url(), ), ); $request = wp_remote_get($url, $args); $responseCode = wp_remote_retrieve_response_code($request); $body = wp_remote_retrieve_body($request); // Decode JSON $body = json_decode($body, true); // Return null if the request was successful but result is empty if (isset($body['code']) && $body['code'] === 'empty_result') { return null; } // Return WP_Error if response code is not 200 OK or result is empty if ($responseCode !== 200 || !is_array($body) || empty($body)) { return new \WP_Error('error', __('API request failed.', 'event-integration')); } return $body; }
php
{ "resource": "" }
q258552
QueryEvents.getEventOccasions
test
public static function getEventOccasions($post_id, $custom = false) { global $wpdb; $db_table = $wpdb->prefix."integrate_occasions"; $query = " SELECT * FROM $db_table WHERE $db_table.event_id = %d "; $query .= ($custom == true) ? "AND $db_table.content_mode = 'custom'" : ''; $query .= "ORDER BY $db_table.start_date ASC"; $completeQuery = $wpdb->prepare($query, $post_id); $occasions = $wpdb->get_results($completeQuery); return $occasions; }
php
{ "resource": "" }
q258553
QueryEvents.getEventMeta
test
public static function getEventMeta($post_id) { global $wpdb; $query = " SELECT * FROM $wpdb->postmeta WHERE $wpdb->postmeta.post_id = %s "; $completeQuery = $wpdb->prepare($query, $post_id); $event_meta = $wpdb->get_results($completeQuery); return $event_meta; }
php
{ "resource": "" }
q258554
QueryEvents.stringLimiter
test
public static function stringLimiter($string, $limit) { if (strlen($string) <= $limit || $limit == -1) { return $string; } else { $y = mb_substr($string, 0, $limit, "utf-8").'...'; return $y; } }
php
{ "resource": "" }
q258555
QueryEvents.getNearbyLocations
test
public static function getNearbyLocations($lat, $lng, $distance = 0) { global $wpdb; // Radius of the earth in kilometers. $earth_radius = 6371; $sql = $wpdb->prepare( " SELECT DISTINCT latitude.post_id, post.post_title, latitude.meta_value as lat, longitude.meta_value as lng, (%s * ACOS( COS(RADIANS( %s )) * COS(RADIANS(latitude.meta_value)) * COS( RADIANS(longitude.meta_value) - RADIANS( %s ) ) + SIN(RADIANS( %s )) * SIN(RADIANS(latitude.meta_value)) )) AS distance FROM $wpdb->posts post INNER JOIN $wpdb->postmeta latitude ON post.ID = latitude.post_id INNER JOIN $wpdb->postmeta longitude ON post.ID = longitude.post_id AND post.post_type = 'event' AND post.post_status = 'publish' AND latitude.meta_key = 'latitude' AND longitude.meta_key = 'longitude' HAVING distance <= %s ORDER BY distance ASC", $earth_radius, $lat, $lng, $lat, $distance ); $nearby_locations = $wpdb->get_results($sql, ARRAY_A); if ($nearby_locations) { return $nearby_locations; } }
php
{ "resource": "" }
q258556
DisplayEvents.update
test
public function update($new_instance, $old_instance) { $instance = array(); $instance['title'] = (! empty($new_instance['title'])) ? strip_tags($new_instance['title']) : ''; $instance['limit'] = absint($new_instance['limit']); $instance['days_ahead'] = absint($new_instance['days_ahead']); $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false; $instance['show_location'] = isset( $new_instance['show_location'] ) ? (bool) $new_instance['show_location'] : false; $instance['show_image'] = isset( $new_instance['show_image'] ) ? (bool) $new_instance['show_image'] : false; $instance['show_content'] = isset( $new_instance['show_content'] ) ? (bool) $new_instance['show_content'] : false; $instance['content_limit'] = $new_instance['content_limit']; return $instance; }
php
{ "resource": "" }
q258557
Event.ajaxPagination
test
public function ajaxPagination() { echo \EventManagerIntegration\Helper\RenderBlade::blade( 'partials/list', $this->data(), $this->templateDir ); wp_die(); }
php
{ "resource": "" }
q258558
Event.getEvents
test
public function getEvents($module_id, $page = 1, $useLimit = true) { $fields = json_decode(json_encode(get_fields($module_id))); $display_limit = ($useLimit == true && isset($fields->mod_event_limit)) ? $fields->mod_event_limit : -1; $days_ahead = isset($fields->mod_event_interval) ? $fields->mod_event_interval : 0; // Set start and end date $start_date = date('Y-m-d H:i:s', strtotime("today midnight")); $end_date = date('Y-m-d H:i:s', strtotime("tomorrow midnight +$days_ahead days") - 1); // Save categories, groups and tags IDs as arrays $categories = $this->getModuleCategories($module_id); $tags = $this->getModuleTags($module_id); $groups = $this->getModuleGroups($module_id); $taxonomies = (!empty($taxonomies)) ? $taxonomies : null; $params = array( 'start_date' => $start_date, 'end_date' => $end_date, 'display_limit' => $display_limit, 'categories' => $categories, 'tags' => $tags, 'groups' => $groups, 'location' => (isset($fields->mod_event_geographic)) ? $fields->mod_event_geographic : null, 'distance' => (isset($fields->mod_event_distance)) ? $fields->mod_event_distance : null, 'lang' => $this->lang, ); $events = \EventManagerIntegration\Helper\QueryEvents::getEventsByInterval($params, $page); return $events; }
php
{ "resource": "" }
q258559
Event.getModuleCategories
test
public function getModuleCategories($moduleId): array { $categories = array(); $showAllCategories = get_field('mod_event_categories_show', $moduleId); $moduleCategories = get_field('mod_event_categories_list', $moduleId); if ($showAllCategories === false && !empty($moduleCategories) && is_array($moduleCategories)) { $categories = $moduleCategories; } return $categories; }
php
{ "resource": "" }
q258560
Event.getFilterableCategories
test
public function getFilterableCategories($moduleId): array { $categories = array(); $showAllCategories = get_field('mod_event_categories_show', $moduleId); $moduleCategories = get_field('mod_event_categories_list', $moduleId); if ($showAllCategories === false && !empty($moduleCategories) && is_array($moduleCategories)) { $categories = $moduleCategories; foreach ($categories as $key => &$category) { $category = get_term($category, 'event_categories'); // If category is missing, remove it from the list if (!$category) { unset($categories[$key]); } } } else { $categories = get_terms( 'event_categories', array( 'hide_empty' => false, ) ); } $categories = \EventManagerIntegration\Helper\Translations::filterTermsByLanguage($categories); foreach ($categories as &$category) { $category = array( 'id' => $category->term_id, 'title' => $category->name, 'checked' => false, ); } return $categories; }
php
{ "resource": "" }
q258561
Event.getModuleGroups
test
public function getModuleGroups($moduleId): array { $groups = array(); $showAllGroups = get_field('mod_event_groups_show', $moduleId); $moduleGroups = get_field('mod_event_groups_list', $moduleId); if ($showAllGroups === false && !empty($moduleGroups) && is_array($moduleGroups)) { $groups = $moduleGroups; } return $groups; }
php
{ "resource": "" }
q258562
Event.getModuleTags
test
public function getModuleTags($moduleId): array { $tags = array(); $showAllTags = get_field('mod_event_tags_show', $moduleId); $moduleTags = get_field('mod_event_tags_list', $moduleId); if ($showAllTags === false && !empty($moduleTags) && is_array($moduleTags)) { $tags = $moduleTags; } return $tags; }
php
{ "resource": "" }
q258563
Event.getAgeFilterRange
test
public function getAgeFilterRange($moduleId): array { $years = array(); $from = (int)get_field('mod_event_filter_age_range_from', $moduleId); $to = (int)get_field('mod_event_filter_age_range_to', $moduleId); if ($from < $to) { foreach (range($from, $to) as $value) { $years[] = array( 'value' => $value, 'checked' => false, ); } } return $years; }
php
{ "resource": "" }
q258564
OAuthAdmin.oauthRequestCallback
test
public function oauthRequestCallback() { ?> <div class="wrap"> <h1><?php _e('API authentication', 'event-integration' ); ?></h1> </div> <div class="error notice hidden"></div> <div class="updated notice hidden"></div> <?php if (get_option('_event_authorized') == false): ?> <div class="wrap oauth-request"> <h3><?php _e('Request authorization', 'event-integration'); ?></h3> <p><?php _e('To publish events from this client to the API you need authentication. Enter your given client keys and send request.', 'event-integration' ); ?></p> <form method="post" id="oauth-request" action="/wp-admin/admin-ajax.php"> <table class="form-table"> <tr> <th scope="row"> <label for="client-key"><?php _e( 'Client key', 'event-integration' )?></label> </th> <td> <input type="text" class="client-key" name="client-key" id="client-key" value="<?php echo esc_attr(get_option('_event_client')); ?>" /> </td> </tr> <tr> <th scope="row"> <label for="client-secret"><?php _e( 'Client secret', 'event-integration' )?></label> </th> <td> <input type="text" class="client-secret" name="client-secret" id="client-secret" value="<?php echo esc_attr(get_option('_event_secret')); ?>" /> </td> </tr> </table> <p class="submit"> <input name='submit' type='submit' id='oauth-request-submit' class='button-primary' value='<?php _e('Send request', 'event-integration') ?>' /> </p> </form> </div> <div class="wrap oauth-access"> <h3><?php _e('Enter verification token', 'event-integration'); ?></h3> <form method="post" id="oauth-access" action="/wp-admin/admin-ajax.php"> <table class="form-table"> <tr> <th scope="row"> <label for="verification-token"><?php _e('Verification token', 'event-integration'); ?></label> </th> <td> <input type="text" class="verification-token" name="verification-token" id="verification-token"/> </td> </tr> </table> <p class="submit"> <input name='submit' type='submit' class='button-primary' value='<?php _e('Grant access', 'event-integration'); ?>' /> </p> </form> </div> <?php endif ?> <?php if (get_option('_event_authorized') == true): ?> <div class="wrap oauth-authorized"> <h3 class="message-success"><?php _e('Authorized', 'event-integration' ); ?></h3> <p><?php _e('This client is authorized to submit events to the API.', 'event-integration' ); ?></p> <form method="post" id="oauth-authorized" action="/wp-admin/admin-ajax.php"> <table class="form-table"> <tr> <th scope="row"> <?php _e( 'Client key', 'event-integration' ); ?> </th> <td> <code> <?php echo get_option('_event_client'); ?> </code> </td> </tr> </table> <p class="submit"> <input name='submit' type='submit' class='button' value='<?php _e('Remove client', 'event-integration') ?>' /> </p> </form> </div> <?php endif ?> <?php }
php
{ "resource": "" }
q258565
OAuthRequests.sanitizeInput
test
public function sanitizeInput(&$array) { foreach ($array as $key => &$value) { if(!is_array($value)) { if ($key == 'content') { $value = sanitize_textarea_field($value); } else { $value = sanitize_text_field($value); } } else { $this->sanitizeInput($value); } } return $array; }
php
{ "resource": "" }
q258566
Events.singleViewData
test
public function singleViewData($data) { // Bail if not event if (get_post_type() !== self::$postTypeSlug || is_archive()) { return $data; } global $post; // Gather event data $eventData = array(); $eventData['occasion'] = \EventManagerIntegration\Helper\SingleEventData::singleEventDate(); $eventData['cancelled'] = !empty($eventData['occasion']['status']) && $eventData['occasion']['status'] === 'cancelled' ? __('Cancelled', 'event-integration') : null; $eventData['rescheduled'] = !empty($eventData['occasion']['status']) && $eventData['occasion']['status'] === 'rescheduled' ? __('Rescheduled', 'event-integration') : null; $eventData['exception_information'] = !empty($eventData['occasion']['exception_information']) ? $eventData['occasion']['exception_information'] : null; if (function_exists('municipio_get_thumbnail_source')) { $eventData['image_src'] = municipio_get_thumbnail_source( null, array(750, 750), '16:9' ); } else { $thumbnailId = get_post_thumbnail_id($post->ID); $image = wp_get_attachment_image_src($thumbnailId, 'medium'); $eventData['image_src'] = $image[0] ?? null; } $location = get_post_meta($post->ID, 'location', true); $eventData['location'] = !empty($location['title']) ? $location : null; $bookingLink = get_post_meta($post->ID, 'booking_link', true); $eventData['booking_link'] = !empty($bookingLink) ? $bookingLink : null; $ageGroupFrom = get_post_meta($post->ID, 'age_group_from', true); $ageGroupTo = get_post_meta($post->ID, 'age_group_to', true); $eventData['age_group'] = null; if (!empty($ageGroupFrom) && !empty($ageGroupTo)) { $eventData['age_group'] = sprintf('%s-%s %s', $ageGroupFrom, $ageGroupTo, __('years', 'event-integration')); } elseif(!empty($ageGroupFrom)) { $eventData['age_group'] = sprintf('%s %s %s', __('From', 'event-integration'), $ageGroupFrom, __('years', 'event-integration')); } elseif(!empty($ageGroupTo)) { $eventData['age_group'] = sprintf('%s %s %s', __('Up to', 'event-integration'), $ageGroupTo, __('years', 'event-integration')); } $data['post'] = $post; $data['event'] = $eventData; return $data; }
php
{ "resource": "" }
q258567
Events.getUserGroups
test
public function getUserGroups($value, $post_id, $field) { if (!empty($value)) { \EventManagerIntegration\App::importPublishingGroups(); } return $value; }
php
{ "resource": "" }
q258568
Events.updateGroupValue
test
public function updateGroupValue($value, $post_id, $field) { // Get old value if ($post_id === 'options') { $selectedGroups = get_field('event_filter_group', 'options'); } else { $selectedGroups = get_field('mod_event_groups_list', $post_id); } // Return if settings value is empty to only auto-activate children on first save if (!empty($selectedGroups)) { return $value; } if (!empty($value)) { foreach ($value as $v) { $term_children = get_term_children($v, 'event_groups'); if ($term_children) { $value = array_merge($value, $term_children); } } $value = array_unique($value); } return $value; }
php
{ "resource": "" }
q258569
Events.eventContent
test
public function eventContent($content) { if (!is_singular($this->slug)) { return $content; } $custom_content = $this->getCustomContent(); if ($custom_content) { $content = $custom_content; } return $content; }
php
{ "resource": "" }
q258570
Events.eventContentLead
test
public function eventContentLead($lead) { if (!is_singular($this->slug)) { return $lead; } $custom_content = $this->getCustomContent(); if ($custom_content) { $lead = null; } return $lead; }
php
{ "resource": "" }
q258571
Events.getCustomContent
test
public function getCustomContent() { global $post; $get_date = (!empty(get_query_var('date'))) ? get_query_var('date') : false; if ($get_date != false) { $occasions = \EventManagerIntegration\Helper\QueryEvents::getEventOccasions($post->ID, false); foreach ($occasions as $o) { $event_date = preg_replace('/\D/', '', $o->start_date); // Replace content with occasion custom content if ($get_date == $event_date && !empty($o->content) && $o->content_mode == 'custom') { return $o->content; } } } }
php
{ "resource": "" }
q258572
Events.registerEventCategories
test
public function registerEventCategories() { $labels = array( 'name' => _x('Event categories', 'Taxonomy plural name', 'event-integration'), 'singular_name' => _x('Event category', 'Taxonomy singular name', 'event-integration'), 'search_items' => __('Search categories', 'event-integration'), 'popular_items' => __('Popular categories', 'event-integration'), 'all_items' => __('All categories', 'event-integration'), 'parent_item' => __('Parent category', 'event-integration'), 'parent_item_colon' => __('Parent category', 'event-integration'), 'edit_item' => __('Edit category', 'event-integration'), 'update_item' => __('Update category', 'event-integration'), 'add_new_item' => __('Add new category', 'event-integration'), 'new_item_name' => __('New category', 'event-integration'), 'add_or_remove_items' => __('Add or remove categories', 'event-integration'), 'choose_from_most_used' => __('Choose from most used categories', 'event-integration'), 'menu_name' => __('Categories', 'event-integration'), ); $args = array( 'labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_admin_column' => true, 'hierarchical' => true, 'show_tagcloud' => true, 'show_ui' => false, 'query_var' => true, 'rewrite' => true ); register_taxonomy('event_categories', array('event'), $args); }
php
{ "resource": "" }
q258573
Events.registerEventTags
test
public function registerEventTags() { $labels = array( 'name' => _x('Event tags', 'Taxonomy plural name', 'event-integration'), 'singular_name' => _x('Event tag', 'Taxonomy singular name', 'event-integration'), 'search_items' => __('Search tags', 'event-integration'), 'popular_items' => __('Popular tags', 'event-integration'), 'all_items' => __('All tags', 'event-integration'), 'parent_item' => __('Parent', 'event-integration'), 'parent_item_colon' => __('Parent', 'event-integration'), 'edit_item' => __('Edit tag', 'event-integration'), 'update_item' => __('Update', 'event-integration'), 'add_new_item' => __('Add new tag', 'event-integration'), 'new_item_name' => __('New tag', 'event-integration'), 'add_or_remove_items' => __('Add or remove tags', 'event-integration'), 'choose_from_most_used' => __('Choose from most used tags', 'event-integration'), 'menu_name' => __('Tags', 'event-integration'), ); $args = array( 'labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_admin_column' => true, 'hierarchical' => false, 'show_tagcloud' => true, 'show_ui' => false, 'query_var' => true, 'rewrite' => true ); register_taxonomy('event_tags', array('event'), $args); }
php
{ "resource": "" }
q258574
Events.registerEventGroups
test
public function registerEventGroups() { $labels = array( 'name' => _x('Event groups', 'Taxonomy plural name', 'event-integration'), 'singular_name' => _x('Event group', 'Taxonomy singular name', 'event-integration'), 'search_items' => __('Search groups', 'event-integration'), 'popular_items' => __('Popular groups', 'event-integration'), 'all_items' => __('All groups', 'event-integration'), 'parent_item' => __('Parent group', 'event-integration'), 'parent_item_colon' => __('Parent group', 'event-integration'), 'edit_item' => __('Edit group', 'event-integration'), 'update_item' => __('Update group', 'event-integration'), 'add_new_item' => __('Add new group', 'event-integration'), 'new_item_name' => __('New group', 'event-integration'), 'add_or_remove_items' => __('Add or remove groups', 'event-integration'), 'choose_from_most_used' => __('Choose from most used groups', 'event-integration'), 'menu_name' => __('Groups', 'event-integration'), ); $args = array( 'labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_admin_column' => true, 'hierarchical' => true, 'show_tagcloud' => true, 'show_ui' => false, 'query_var' => true, 'rewrite' => true ); register_taxonomy('event_groups', array('event'), $args); }
php
{ "resource": "" }
q258575
Events.addImportButtons
test
public function addImportButtons($views) { if (current_user_can('administrator') || current_user_can('editor')) { $button = '<div class="import-buttons actions" style="position: relative;">'; if (get_field('event_api_url', 'option')) { $button .= '<div id="importevents" class="button-primary">' . __('Import events', 'event-integration') . '</div>'; } $button .= '</div>'; $views['import-buttons'] = $button; } return $views; }
php
{ "resource": "" }
q258576
Events.importEvents
test
public function importEvents() { if ($apiUrl = \EventManagerIntegration\Helper\ApiUrl::buildApiUrl()) { $importer = new \EventManagerIntegration\Parser\EventManagerApi($apiUrl); $data = $importer->getCreatedData(); wp_send_json($data); } wp_die(); }
php
{ "resource": "" }
q258577
Events.acceptOrDeny
test
public function acceptOrDeny() { if (!isset($_POST['postId']) || !isset($_POST['value'])) { echo _e('Something went wrong!', 'event-integration'); die(); } $postId = $_POST['postId']; $value = $_POST['value']; $post = get_post($postId); if ($value == 0) { $post->post_status = 'draft'; } if ($value == 1) { $post->post_status = 'publish'; } $update = wp_update_post($post, true); if (is_wp_error($update)) { echo _e('Error', 'event-integration'); die(); } echo $value; die(); }
php
{ "resource": "" }
q258578
CreateTunnel.createTunnel
test
protected function createTunnel() { $this->runCommand(sprintf('%s %s >> %s 2>&1 &', config('tunneler.nohup_path'), $this->sshCommand, config('tunneler.nohup_log') )); // Ensure we wait long enough for it to actually connect. usleep(config('tunneler.wait')); }
php
{ "resource": "" }
q258579
CreateTunnel.verifyTunnel
test
protected function verifyTunnel() { if (config('tunneler.verify_process') == 'bash') { return $this->runCommand($this->bashCommand); } return $this->runCommand($this->ncCommand); }
php
{ "resource": "" }
q258580
CreateTunnel.runCommand
test
protected function runCommand($command) { $return_var = 1; exec($command, $this->output, $return_var); return (bool)($return_var === 0); }
php
{ "resource": "" }
q258581
Listener.setSignalHandler
test
public function setSignalHandler(int $signal, callable $closure = null){ if (empty($closure)){ return pcntl_signal($signal, array($this, 'sigHandler')); } return pcntl_signal($signal, $closure); }
php
{ "resource": "" }
q258582
Listener.sigHandler
test
public function sigHandler( int $signo ){ $this->handleWorkerOutput('warn', sprintf("Signal %d Caught, asking the daemon to stop gracefully.", $signo)); $this->stopGracefully = true; }
php
{ "resource": "" }
q258583
Listener.runProcess
test
public function runProcess(Process $process, $memory) { try { $process->run(function ($type, $line) { $this->handleWorkerOutput($type, $line); }); }catch (\Exception $e){ dd($e); } // If we caught a signal and need to stop gracefully, this is the place to // do it. pcntl_signal_dispatch(); if ($this->stopGracefully){ $this->gracefulStop(); } // Once we have run the job we'll go check if the memory limit has been // exceeded for the script. If it has, we will kill this script so a // process manager will restart this with a clean slate of memory. if ($this->memoryExceeded($memory)) { $this->stop(); } }
php
{ "resource": "" }
q258584
FrontendEditor.editFor
test
public function editFor($containerName, $defaultAction = 'showAll'): string { $environment = $this->createDcGeneral($containerName); $actionName = $environment->getInputProvider()->getParameter('act') ?: $defaultAction; $action = new Action($actionName); $event = new ActionEvent($environment, $action); $this->dispatcher->dispatch(DcGeneralEvents::ACTION, $event); if (!$result = $event->getResponse()) { return 'Action ' . $action->getName() . ' is not supported yet.'; } return $result; }
php
{ "resource": "" }
q258585
FrontendEditor.createDcGeneral
test
public function createDcGeneral($containerName): EnvironmentInterface { if (!array_key_exists($containerName, self::$environments)) { $dcGeneral = (new DcGeneralFactory()) ->setContainerName($containerName) ->setEventDispatcher($this->dispatcher) ->setTranslator($this->translator) ->createDcGeneral(); self::$environments[$containerName] = $dcGeneral->getEnvironment(); } return self::$environments[$containerName]; }
php
{ "resource": "" }
q258586
WidgetManager.getWidget
test
public function getWidget($property, PropertyValueBag $valueBag = null) { $environment = $this->getEnvironment(); $dispatcher = $environment->getEventDispatcher(); $propertyDefinitions = $environment->getDataDefinition()->getPropertiesDefinition(); if (!$propertyDefinitions->hasProperty($property)) { throw new DcGeneralInvalidArgumentException( 'Property ' . $property . ' is not defined in propertyDefinitions.' ); } $model = clone $this->model; $model->setId($this->model->getId()); if ($valueBag) { $values = new PropertyValueBag($valueBag->getArrayCopy()); $this->environment->getController()->updateModelFromPropertyBag($model, $values); } $propertyDefinition = $propertyDefinitions->getProperty($property); $event = new BuildWidgetEvent($environment, $model, $propertyDefinition); $dispatcher->dispatch(DcGeneralFrontendEvents::BUILD_WIDGET, $event); if (!$event->getWidget()) { throw new DcGeneralRuntimeException( sprintf('Widget was not build for property %s::%s.', $this->model->getProviderName(), $property) ); } return $event->getWidget(); }
php
{ "resource": "" }
q258587
WidgetManager.renderWidget
test
public function renderWidget($property, $ignoreErrors = false, PropertyValueBag $valueBag = null) { $widget = $this->getWidget($property, $valueBag); if (!$widget) { throw new DcGeneralRuntimeException('No widget for property ' . $property); } if ($ignoreErrors) { // Clean the errors array and fix up the CSS class. $reflection = new \ReflectionProperty(get_class($widget), 'arrErrors'); $reflection->setAccessible(true); $reflection->setValue($widget, []); $reflection = new \ReflectionProperty(get_class($widget), 'strClass'); $reflection->setAccessible(true); $reflection->setValue($widget, str_replace('error', '', $reflection->getValue($widget))); } else { if ($valueBag && $valueBag->hasPropertyValue($property) && $valueBag->isPropertyValueInvalid($property) ) { foreach ($valueBag->getPropertyValueErrors($property) as $error) { $widget->addError($error); } } } return $widget->parse(); }
php
{ "resource": "" }
q258588
WidgetManager.processInput
test
public function processInput(PropertyValueBag $valueBag) { $post = $this->hijackPost($valueBag); // Now get and validate the widgets. foreach (array_keys($valueBag->getArrayCopy()) as $property) { $this->processProperty($valueBag, $property); } $this->restorePost($post); }
php
{ "resource": "" }
q258589
WidgetManager.processProperty
test
private function processProperty(PropertyValueBag $valueBag, $property) { // NOTE: the passed input values are RAW DATA from the input provider - aka widget known values and not // native data as in the model. // Therefore we do not need to decode them but MUST encode them. $widget = $this->getWidget($property, $valueBag); $widget->validate(); if ($widget->hasErrors()) { foreach ($widget->getErrors() as $error) { $valueBag->markPropertyValueAsInvalid($property, $error); } return; } if (!$widget->submitInput()) { // Handle as abstaining property. $valueBag->removePropertyValue($property); return; } try { $valueBag->setPropertyValue($property, $this->encodeValue($property, $widget->value, $valueBag)); } catch (\Exception $e) { $widget->addError($e->getMessage()); foreach ($widget->getErrors() as $error) { $valueBag->markPropertyValueAsInvalid($property, $error); } } }
php
{ "resource": "" }
q258590
WidgetManager.hijackPost
test
private function hijackPost(PropertyValueBag $valueBag) { $post = $_POST; $_POST = []; Input::resetCache(); // Set all POST data, these get used within the Widget::validate() method. foreach ($valueBag as $property => $value) { $_POST[$property] = $value; } return $post; }
php
{ "resource": "" }
q258591
DeleteHandler.handleEvent
test
public function handleEvent(ActionEvent $event): void { if (!$this->scopeDeterminator->currentScopeIsFrontend()) { return; } $action = $event->getAction(); // Only handle if we do not have a manual sorting or we know where to insert. // Manual sorting is handled by clipboard. if ('delete' !== $action->getName()) { return; } // Only run when no response given yet. if (null !== $event->getResponse()) { return; } $this->process($event->getEnvironment()); }
php
{ "resource": "" }
q258592
ImagineFactory.create
test
public function create($className = 'Imagine') { $this->configureDriverSpecificSettings(); $className = 'Imagine\\' . $this->settings['driver'] . '\\' . $className; $arguments = array_slice(func_get_args(), 1); switch (count($arguments)) { case 0: $object = new $className(); break; case 1: $object = new $className($arguments[0]); break; case 2: $object = new $className($arguments[0], $arguments[1]); break; case 3: $object = new $className($arguments[0], $arguments[1], $arguments[2]); break; case 4: $object = new $className($arguments[0], $arguments[1], $arguments[2], $arguments[3]); break; case 5: $object = new $className($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]); break; case 6: $object = new $className($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]); break; default: $class = new \ReflectionClass($className); $object = $class->newInstanceArgs($arguments); } return $object; }
php
{ "resource": "" }
q258593
ImagineFactory.configureImagickSettings
test
protected function configureImagickSettings() { if (!isset($this->settings['driverSpecific']['Imagick'])) { return; } $limits = $this->settings['driverSpecific']['Imagick']['limits'] ? $this->settings['driverSpecific']['Imagick']['limits'] : []; foreach ($limits as $resourceType => $limit) { \Imagick::setResourceLimit($resourceType, $limit); } }
php
{ "resource": "" }
q258594
AbstractImagineFactory.injectSettings
test
public function injectSettings(array $settings) { $this->settings = $settings; if (!isset($settings['enabledDrivers'])) { // FIXME: This is a hotfix and should actually be fixed in the Neos setup step. As soon as it is fixed there, this condition can be removed. return; } if (!in_array($settings['driver'], array_keys(array_filter($settings['enabledDrivers'])), true)) { throw new \InvalidArgumentException('The "driver" for Imagine must be enabled by settings, check Neos.Imagine.enabledDrivers.', 1515402616); } }
php
{ "resource": "" }
q258595
DefaultWidgetBuilder.handleEvent
test
public function handleEvent(BuildWidgetEvent $event) { // Only run in the frontend or when the widget is not build yet if (false === $this->scopeDeterminator->currentScopeIsFrontend() || null !== $event->getWidget()) { return; } $widget = $this->buildWidget($event->getEnvironment(), $event->getProperty(), $event->getModel()); $event->setWidget($widget); }
php
{ "resource": "" }
q258596
DefaultWidgetBuilder.getWidgetClass
test
private function getWidgetClass(PropertyInterface $property) { if (!isset($GLOBALS['TL_FFL'][$property->getWidgetType()])) { return null; } $className = $GLOBALS['TL_FFL'][$property->getWidgetType()]; if (!class_exists($className)) { return null; } return $className; }
php
{ "resource": "" }
q258597
DefaultWidgetBuilder.getOptionsForWidget
test
private function getOptionsForWidget( EnvironmentInterface $environment, PropertyInterface $propInfo, ModelInterface $model ) { $dispatcher = $environment->getEventDispatcher(); $options = $propInfo->getOptions(); $event = new GetPropertyOptionsEvent($environment, $model); $event->setPropertyName($propInfo->getName()); $event->setOptions($options); $dispatcher->dispatch(GetPropertyOptionsEvent::NAME, $event); if ($event->getOptions() !== $options) { return $event->getOptions(); } return $options; }
php
{ "resource": "" }
q258598
EditMask.execute
test
public function execute() { $inputProvider = $this->environment->getInputProvider(); $palettesDefinition = $this->definition->getPalettesDefinition(); $isSubmitted = ($inputProvider->getValue('FORM_SUBMIT') === $this->definition->getName()); $isAutoSubmit = ($inputProvider->getValue('SUBMIT_TYPE') === 'auto'); $widgetManager = new WidgetManager($this->environment, $this->model); $this->dispatcher->dispatch(PreEditModelEvent::NAME, new PreEditModelEvent($this->environment, $this->model)); $this->enforceModelRelationship(); // Pass 1: Get the palette for the values stored in the model. $palette = $palettesDefinition->findPalette($this->model); $propertyValues = $this->processInput($widgetManager); if ($isSubmitted && $propertyValues) { // Pass 2: Determine the real palette we want to work on if we have some data submitted. $palette = $palettesDefinition->findPalette($this->model, $propertyValues); // Update the model - the model might add some more errors to the propertyValueBag via exceptions. $this->environment->getController()->updateModelFromPropertyBag($this->model, $propertyValues); } $fieldSets = $this->buildFieldSet($widgetManager, $palette, $propertyValues); $buttons = $this->getEditButtons(); if ((!$isAutoSubmit) && $isSubmitted && empty($this->errors)) { $this->doPersist(); $this->handleSubmit($buttons); } $template = new ViewTemplate('dcfe_general_edit'); $template->setData( [ 'fieldsets' => $fieldSets, 'subHeadline' => $this->getHeadline(), 'table' => $this->definition->getName(), 'enctype' => 'multipart/form-data', 'error' => $this->errors, 'editButtons' => $buttons ] ); return $template->parse(); }
php
{ "resource": "" }
q258599
EditMask.enforceModelRelationship
test
private function enforceModelRelationship() { $event = new EnforceModelRelationshipEvent($this->environment, $this->model); $this->dispatcher->dispatch(DcGeneralEvents::ENFORCE_MODEL_RELATIONSHIP, $event); }
php
{ "resource": "" }