public static function get_components_synchro_data($app_id) { $components = array(); $components_data = array(); WpakAddons::require_app_addons_php_files($app_id); $components_raw = WpakComponentsStorage::get_components($app_id); if (!empty($components_raw)) { $globals = array(); foreach ($components_raw as $component) { $component_data = WpakComponentsTypes::get_component_data($component, $globals); // // Don't include null component into the webservice's return // Component data could be null if an addon's component has been added to the app and the addon isn't activated anymore // An addon could be seen as deactivated either if the corresponding plugin is deactivated, or if the corresponding checkbox is unchecked for the given app // if (null === $component_data) { continue; } $globals = $component_data['globals']; $components[$component->slug] = $component_data['specific']; } $navigation_items = WpakNavigationItemsStorage::get_navigation_indexed_by_components_slugs($app_id, true); $navigation_items = apply_filters('wpak_navigation_items', $navigation_items, WpakApps::get_app_slug($app_id)); $components_data['navigation'] = $navigation_items; $components_data['components'] = $components; $components_data['globals'] = $globals; $components_data['addons'] = WpakAddons::get_app_addons_dynamic_data($app_id); } return $components_data; }
public static function get_app_navigation($app_post_id) { return WpakNavigationItemsStorage::get_navigation_items($app_post_id); }
public static function ajax_wpak_edit_navigation() { $answer = array('ok' => 0, 'message' => '', 'type' => 'error', 'html' => '', 'data' => ''); if (empty($_POST['post_id']) || !is_numeric($_POST['post_id']) || empty($_POST['nonce']) || !check_admin_referer('wpak-navigation-data-' . $_POST['post_id'], 'nonce')) { exit; } $post_id = $_POST['post_id']; $action = $_POST['wpak_action']; $data = $_POST['data']; if ($action == 'add_or_update') { $post_id = $data['navigation_post_id']; $nav_item_component_id = $data['component_id']; $new_item_position = WpakNavigationItemsStorage::get_nb_navigation_items($post_id) + 1; $nav_item_position = !empty($data['position']) && is_numeric($data['position']) ? $data['position'] : $new_item_position; if (empty($nav_item_component_id)) { $answer['message'] = __('You must choose a component!', WpAppKit::i18n_domain); self::exit_sending_json($answer); } if (!WpakComponentsStorage::component_exists($post_id, $nav_item_component_id)) { $answer['message'] = __("This component doesn't exist!", WpAppKit::i18n_domain); self::exit_sending_json($answer); } if (WpakNavigationItemsStorage::navigation_item_exists_by_component($post_id, $nav_item_component_id)) { $answer['message'] = __('This component is already in navigation!', WpAppKit::i18n_domain); self::exit_sending_json($answer); } $navigation_item = new WpakNavigationItem($nav_item_component_id, $nav_item_position); $navigation_item_id = WpakNavigationItemsStorage::add_or_update_navigation_item($post_id, $navigation_item); $answer['html'] = self::get_navigation_row($post_id, WpakNavigationItemsStorage::get_nb_navigation_items($post_id), $navigation_item_id, $navigation_item); $answer['ok'] = 1; $answer['type'] = 'updated'; $answer['message'] = __('New navigation item created successfuly', WpAppKit::i18n_domain); self::exit_sending_json($answer); } elseif ($action == 'delete') { $nav_item_id = $data['navigation_item_id']; $post_id = $data['post_id']; if (WpakNavigationItemsStorage::navigation_item_exists($post_id, $nav_item_id)) { if (!WpakNavigationItemsStorage::delete_navigation_item($post_id, $nav_item_id)) { $answer['message'] = __('Could not delete navigation item', WpAppKit::i18n_domain); } else { $answer['ok'] = 1; $answer['type'] = 'updated'; $answer['message'] = __('Navigation item deleted successfuly', WpAppKit::i18n_domain); } } else { $answer['message'] = __('Navigation item to delete not found', WpAppKit::i18n_domain); } self::exit_sending_json($answer); } elseif ($action == 'move') { if (!empty($data['positions']) && is_array($data['positions'])) { WpakNavigationItemsStorage::update_items_positions($data['post_id'], $data['positions']); $answer['message'] = __('Navigation order updated successfuly', WpAppKit::i18n_domain); $answer['ok'] = 1; $answer['type'] = 'updated'; } } elseif ($action == 'edit_option') { if (!empty($data['navigation_item_id']) && !empty($data['option'])) { $value = $data['value']; if ($data['option'] == 'icon_slug') { $value = sanitize_file_name(remove_accents($value)); } WpakNavigationItemsStorage::update_item_option($post_id, $data['navigation_item_id'], $data['option'], $value); $answer['message'] = __('Navigation item updated successfuly', WpAppKit::i18n_domain); $answer['ok'] = 1; $answer['type'] = 'updated'; $answer['data'] = $value; } } //We should not arrive here, but just in case : self::exit_sending_json($answer); }
public static function ajax_wpak_edit_component() { $answer = array('ok' => 0, 'message' => '', 'type' => 'error', 'html' => '', 'component' => array()); if (empty($_POST['post_id']) || empty($_POST['nonce']) || !check_admin_referer('wpak-component-data-' . $_POST['post_id'], 'nonce')) { exit('bad nonce'); } $action = $_POST['wpak_action']; $data = $_POST['data']; WpakAddons::require_app_addons_php_files(intval($_POST['post_id'])); if ($action == 'add_or_update') { // Unslash POST data before manipulating DB $data = wp_unslash($data); $post_id = $data['component_post_id']; if (empty($post_id)) { $answer['message'] = __("Application not found.", WpAppKit::i18n_domain); self::exit_sending_json($answer); } $edit = !empty($data['component_id']); $edit_id = $edit ? intval($data['component_id']) : 0; $component_label = trim($data['component_label']); $component_type = $data['component_type']; if (empty($component_label)) { $answer['message'] = __('You must provide a label for the component!', WpAppKit::i18n_domain); self::exit_sending_json($answer); } if (is_numeric($component_label)) { $answer['message'] = __("The component label can't be numeric.", WpAppKit::i18n_domain); self::exit_sending_json($answer); } $component_slug = $edit ? trim($data['component_slug']) : $component_label; $component_slug = sanitize_title_with_dashes(remove_accents($component_slug)); if (empty($component_slug)) { $answer['message'] = __("You must provide a slug for the component.", WpAppKit::i18n_domain); self::exit_sending_json($answer); } if (is_numeric($component_slug)) { $answer['message'] = __("The component slug can't be numeric.", WpAppKit::i18n_domain); self::exit_sending_json($answer); } if (WpakComponentsStorage::component_exists($post_id, $component_slug, $edit_id)) { $i = 0; do { $component_index = intval(preg_replace('/.*-(\\d+)$/', '$1', $component_slug)); $component_index++; $component_slug = preg_replace('/-(\\d+)$/', '', $component_slug) . '-' . $component_index; if ($i++ > 100) { break; } } while (WpakComponentsStorage::component_exists($post_id, $component_slug, $edit_id)); } $component_options = WpakComponentsTypes::get_component_type_options_from_posted_form($component_type, $data); $component = new WpakComponent($component_slug, $component_label, $component_type, $component_options); $component_id = WpakComponentsStorage::add_or_update_component($post_id, $component, $edit_id); $answer['component'] = array('id' => $component_id, 'slug' => $component_slug, 'label' => $component_label); $answer['html'] = self::get_component_row($post_id, WpakComponentsStorage::get_nb_components($post_id), $component_id, $component); if ($edit) { $answer['ok'] = 1; $answer['type'] = 'updated'; $answer['message'] = sprintf(__('Component "%s" updated successfuly', WpAppKit::i18n_domain), $component_label); } else { $answer['ok'] = 1; $answer['type'] = 'updated'; $answer['message'] = sprintf(__('Component "%s" created successfuly', WpAppKit::i18n_domain), $component_label); } self::exit_sending_json($answer); } elseif ($action == 'delete') { $id = $data['component_id']; $post_id = $data['post_id']; if (is_numeric($id) && is_numeric($post_id)) { if ($component_id = WpakComponentsStorage::component_exists($post_id, $id)) { if (WpakNavigationItemsStorage::navigation_item_exists_by_component($post_id, $component_id)) { $answer['message'] = __('The component to delete is in the app navigation. Please remove the component from app navigation before deleting it.', WpAppKit::i18n_domain); } else { if (!WpakComponentsStorage::delete_component($post_id, $id)) { $answer['message'] = __('Could not delete component', WpAppKit::i18n_domain); } else { $answer['ok'] = 1; $answer['type'] = 'updated'; $answer['message'] = __('Component deleted successfuly', WpAppKit::i18n_domain); } } } else { $answer['message'] = __('Component to delete not found', WpAppKit::i18n_domain); } } self::exit_sending_json($answer); } //We should not arrive here, but just in case : self::exit_sending_json($answer); }