public function getData() { $retval = $this->data; if (!empty_array($_FILES)) { foreach ($_FILES as $k => $data) { $retval[$k] = $data['name']; } } return $retval; }
function getOffers() { if (!class_exists('\\CCatalogSKU')) { \CModule::IncludeModule('catalog'); } $retval = array(); $arInfo = \CCatalogSKU::GetInfoByProductIBlock($this->iblock_id); if (is_array($arInfo)) { $retval = \Cpeople\Classes\Block\Getter::instance()->setFilter(array('IBLOCK_ID' => $arInfo['IBLOCK_ID'], 'PROPERTY_' . $arInfo['SKU_PROPERTY_ID'] => $this->id))->setClassName('\\Cpeople\\Classes\\Catalog\\Offer')->get(); } return empty_array($retval) ? false : $retval; }
/** * 得到树形class 2级 */ protected function getClassTree($class, $parent_id = 0, $deep = 1) { if (!empty_array($class)) { return array(); } $tree = array(); //返回数组 foreach ($class as $key => $value) { if ($value['parent_id'] == $parent_id) { } } }
/** * Displays the main form for inserting shortcodes / single images. * also handles attachments edit/delete/detach response * and displays atachment thumbnails on post edit screen in admin */ function file_gallery_main($ajax = true) { global $wpdb; check_ajax_referer('file-gallery'); $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : ''; $attachment_order = isset($_POST['attachment_order']) ? $_POST['attachment_order'] : ''; $attachment_orderby = isset($_POST['attachment_orderby']) ? $_POST['attachment_orderby'] : ''; $files_or_tags = isset($_POST['files_or_tags']) ? $_POST["files_or_tags"] : ''; $tags_from = isset($_POST['tags_from']) ? $_POST["tags_from"] : ''; $action = isset($_POST['action']) ? $_POST['action'] : ''; $attachment_ids = isset($_POST['attachment_ids']) ? $_POST['attachment_ids'] : ''; $attachment_data = isset($_POST['attachment_data']) ? $_POST['attachment_data'] : ''; $delete_what = isset($_POST['delete_what']) ? $_POST['delete_what'] : ''; $checked_attachments = isset($_POST['checked_attachments']) ? explode(',', $_POST['checked_attachments']) : array(); $normals = isset($_POST['normals']) ? $_POST['normals'] : ''; $copies = isset($_POST['copies']) ? $_POST['copies'] : ''; $originals = isset($_POST['originals']) ? $_POST['originals'] : ''; $fieldsets = isset($_POST['fieldsets']) ? $_POST['fieldsets'] : ''; $file_gallery_options = get_option('file_gallery'); $gallery_state = isset($file_gallery_options['insert_options_state']) && true == $file_gallery_options['insert_options_state'] ? true : false; $single_state = isset($file_gallery_options['insert_single_options_state']) && true == $file_gallery_options['insert_single_options_state'] ? true : false; $output = " "; $count_attachments = 0; $hide_form = ''; $sizes = file_gallery_get_intermediate_image_sizes(); $normals = explode(',', $normals); $copies = explode(',', $copies); $originals = explode(',', $originals); $attachment_ids = explode(',', $attachment_ids); if (empty_array($normals)) { $normals = array(); } if (empty_array($copies)) { $copies = array(); } if (empty_array($originals)) { $originals = array(); } if (empty_array($attachment_ids)) { $attachment_ids = array(); } if ('file_gallery_main_delete' == $action) { if (!empty($copies) && !empty($originals)) { $cpluso = array_merge($copies, $originals); $normals = array_xor((array) $attachment_ids, $cpluso); } elseif (!empty($copies)) { $normals = array_xor((array) $attachment_ids, $copies); } elseif (!empty($originals)) { $normals = array_xor((array) $attachment_ids, $originals); } else { $normals = $attachment_ids; } // cancel our own 'wp_delete_attachment' filter define("FILE_GALLERY_SKIP_DELETE_CANCEL", true); foreach ($normals as $normal) { if (current_user_can('delete_post', $normal)) { wp_delete_attachment($normal); $fully_deleted[] = $normal; } } foreach ($copies as $copy) { if (current_user_can('delete_post', $copy)) { file_gallery_delete_attachment($copy); $partially_deleted[] = $copy; } } foreach ($originals as $original) { if ("all" == $delete_what && current_user_can('delete_post', $original)) { file_gallery_delete_all_attachment_copies($original); wp_delete_attachment($original); $fully_deleted[] = $original; } elseif ("data_only" == $delete_what && current_user_can('delete_post', $original)) { file_gallery_promote_first_attachment_copy($original); file_gallery_delete_attachment($original); $partially_deleted[] = $original; } } if (empty($fully_deleted) && empty($partially_deleted)) { $output = __("No attachments were deleted (capabilities?)", "file-gallery"); } else { $output = __("Attachment(s) deleted", "file-gallery"); } } elseif ("file_gallery_main_detach" == $action) { foreach ($attachment_ids as $attachment_id) { if (false === $wpdb->query(sprintf("UPDATE {$wpdb->posts} SET `post_parent`='0' WHERE `ID`='%d'", $attachment_id))) { $detach_errors[] = $attachment_id; } } if (empty($detach_errors)) { $output = __("Attachment(s) detached", "file-gallery"); } else { $output = __("Error detaching attachment(s)", "file-gallery"); } } elseif ("file_gallery_main_update" == $action) { $attachment_id = (int) $_POST['attachment_id']; $attachment_data['ID'] = $attachment_id; $attachment_data['post_alt'] = $_POST['post_alt']; $attachment_data['post_title'] = $_POST['post_title']; $attachment_data['post_content'] = $_POST['post_content']; $attachment_data['post_excerpt'] = $_POST['post_excerpt']; $attachment_data['menu_order'] = $_POST['menu_order']; // attachment custom fields $custom = get_post_custom($attachment_id); $custom_fields = isset($_POST['custom_fields']) ? $_POST['custom_fields'] : ''; if (!empty($custom) && !empty($custom_fields)) { foreach ($custom_fields as $key => $val) { if (isset($custom[$key]) && $custom[$key][0] != $val) { update_post_meta($attachment_id, $key, $val); } } } // media_tag taxonomy - attachment tags $tax_input = ""; $old_media_tags = ""; $get_old_media_tags = wp_get_object_terms((int) $_POST['attachment_id'], FILE_GALLERY_MEDIA_TAG_NAME); if (!empty($get_old_media_tags)) { foreach ($get_old_media_tags as $mt) { $old_media_tags[] = $mt->name; } $old_media_tags = implode(", ", $old_media_tags); } if ("" != $_POST['tax_input'] && $old_media_tags != $_POST['tax_input']) { $tax_input = preg_replace("#\\s+#", " ", $_POST['tax_input']); $tax_input = preg_replace("#,+#", ",", $_POST['tax_input']); $tax_input = trim($tax_input, " "); $tax_input = trim($tax_input, ","); $tax_input = explode(", ", $tax_input); $media_tags_result = wp_set_object_terms($attachment_id, $tax_input, FILE_GALLERY_MEDIA_TAG_NAME); } elseif ("" == $_POST['tax_input']) { $media_tags_result = wp_set_object_terms($attachment_id, NULL, FILE_GALLERY_MEDIA_TAG_NAME); } // check if there were any changes $old_attachment_data = get_object_vars(get_post($attachment_id)); if (file_gallery_file_is_displayable_image(get_attached_file($attachment_id))) { $old_attachment_data['post_alt'] = get_post_meta($attachment_id, "_wp_attachment_image_alt", true); } if (isset($old_attachment_data['post_alt']) && $old_attachment_data['post_alt'] != $attachment_data['post_alt'] || $old_attachment_data['post_title'] != $attachment_data['post_title'] || $old_attachment_data['post_content'] != $attachment_data['post_content'] || $old_attachment_data['post_excerpt'] != $attachment_data['post_excerpt'] || $old_attachment_data['menu_order'] != $attachment_data['menu_order'] || is_array($tax_input)) { if (0 !== wp_update_post($attachment_data)) { update_post_meta($attachment_id, "_wp_attachment_image_alt", $attachment_data['post_alt']); $output = __("Attachment data updated", "file-gallery"); } else { $output = __("Error updating attachment data!", "file-gallery"); } } else { $output = __("No change.", "file-gallery"); } } elseif ("file_gallery_set_post_thumb" == $action) { update_post_meta($post_id, "_thumbnail_id", $attachment_ids[0]); exit(_wp_post_thumbnail_html($attachment_ids[0], $post_id)); } elseif ("file_gallery_unset_post_thumb" == $action) { exit; } include_once "main-form.php"; exit; }
function empty_array($array) { foreach ((array) $array as $k => $v) { if (is_array($v) && !empty_array($v)) { return false; } elseif (!empty($v)) { return false; } } return true; }
public function getRelated($key, $filter = array(), $order = array('SORT' => 'asc')) { $retval = false; if ($getter = $this->getRelatedGetter($key)) { $getter->setOrder($order)->setHydrationMode($getter::HYDRATION_MODE_OBJECTS_ARRAY); if (!empty_array($filter)) { $getter->addFilter($filter); } $retval = $getter->get(); } return $retval; }
/** * Фунцкция принимает список инфоблоков \Cpeople\Classes\Block\Object, * делает выборку разделов и возвращает список разделов \Cpeople\Classes\Section\Object * с полем elements, содержащим инфорблоки * * @param $iblocks * @return array */ function cp_group_by_section($iblocks, $level = 0) { if (empty($iblocks) || !is_array($iblocks)) { return false; } $sectionsIds = array(); $list = new \Cpeople\Classes\Block\Collection($iblocks); foreach ($list as $item) { $sectionsIds[] = $item->iblock_section_id; } if (empty_array($sectionsIds)) { return false; } $sections = \Cpeople\Classes\Section\Getter::instance()->setFilter(array('ID' => $sectionsIds))->checkPermissions(false)->get(); foreach ($sections as $section) { $section->elements = $list->getBy('iblock_section_id', $section->id); } return $sections; }
function new_multi_input($input_data = array(), $method = 'get') { $new_form = ''; if (!empty_array($input_data)) { $new_form = new_form($method, '', 'collect_form', 'navbar-form'); $multiple_input = get_input_multiple($input_data); append_form($multiple_input, $new_form); append_form(get_input_submit('submit'), $new_form); } return $new_form; }