|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file contains miscellaneous admin-functions. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Wordlift |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
// Add the Admin menu. |
|
9
|
|
|
require_once( 'wordlift_admin_menu.php' ); |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Serialize an entity post. |
|
13
|
|
|
* |
|
14
|
|
|
* @param array $entity The entity post or the entity post id. |
|
15
|
|
|
* |
|
16
|
|
|
* @return array mixed The entity data array. |
|
17
|
|
|
*/ |
|
18
|
|
|
function wl_serialize_entity( $entity ) { |
|
19
|
|
|
|
|
20
|
|
|
$entity = ( is_numeric( $entity ) ) ? get_post( $entity ) : $entity; |
|
21
|
|
|
|
|
22
|
|
|
// Bail if the entity doesn't exists. |
|
23
|
|
|
// In some cases we have `wl_topic` meta |
|
24
|
|
|
// pointing to an entity that has been deleted. |
|
25
|
|
|
if ( empty( $entity ) ) { |
|
26
|
|
|
return; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$type = Wordlift_Entity_Type_Service::get_instance()->get( $entity->ID ); |
|
30
|
|
|
$images = wl_get_image_urls( $entity->ID ); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
return array( |
|
33
|
|
|
'id' => wl_get_entity_uri( $entity->ID ), |
|
|
|
|
|
|
34
|
|
|
'label' => $entity->post_title, |
|
35
|
|
|
'description' => $entity->post_content, |
|
36
|
|
|
'sameAs' => wl_schema_get_value( $entity->ID, 'sameAs' ), |
|
37
|
|
|
'mainType' => str_replace( 'wl-', '', $type['css_class'] ), |
|
38
|
|
|
'types' => wl_get_entity_rdf_types( $entity->ID ), |
|
39
|
|
|
'images' => $images, |
|
40
|
|
|
|
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Removes empty text annotations from the post content. |
|
46
|
|
|
* |
|
47
|
|
|
* @since 1.0.0 |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $data The post data. |
|
50
|
|
|
* |
|
51
|
|
|
* @return array mixed The post data array. |
|
52
|
|
|
*/ |
|
53
|
|
|
function wl_remove_text_annotations( $data ) { |
|
54
|
|
|
|
|
55
|
|
|
// Remove blank elements that can interfere with annotations removing |
|
56
|
|
|
// See https://github.com/insideout10/wordlift-plugin/issues/234 |
|
57
|
|
|
// Just blank attributes without any attributes are cleaned up. |
|
58
|
|
|
$pattern = '/<(\w+)><\/\1>/im'; |
|
59
|
|
|
// Remove the pattern while it is found (match nested annotations). |
|
60
|
|
View Code Duplication |
while ( 1 === preg_match( $pattern, $data['post_content'] ) ) { |
|
|
|
|
|
|
61
|
|
|
$data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], -1, $count ); |
|
62
|
|
|
} |
|
63
|
|
|
// Remove text annotations |
|
64
|
|
|
// <span class="textannotation" id="urn:enhancement-777cbed4-b131-00fb-54a4-ed9b26ae57ea">. |
|
65
|
|
|
|
|
66
|
|
|
// @see https://github.com/insideout10/wordlift-plugin/issues/771 |
|
67
|
|
|
// Changing this: |
|
68
|
|
|
// $pattern = '/<(\w+)[^>]*\sclass=\\\"textannotation(?![^\\"]*\sdisambiguated)[^\\"]*\\\"[^>]*>([^<]+)<\/\1>/im'; |
|
|
|
|
|
|
69
|
|
|
// to: |
|
70
|
|
|
$pattern = '/<(\w+)[^>]*\sclass=\\\"textannotation(?![^\\"]*\sdisambiguated)[^\\"]*\\\"[^>]*>(.*?)<\/\1>/im'; |
|
71
|
|
|
// Remove the pattern while it is found (match nested annotations). |
|
72
|
|
View Code Duplication |
while ( 1 === preg_match( $pattern, $data['post_content'] ) ) { |
|
|
|
|
|
|
73
|
|
|
$data['post_content'] = preg_replace( $pattern, '$2', $data['post_content'], -1, $count ); |
|
74
|
|
|
} |
|
75
|
|
|
return $data; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
add_filter( 'wp_insert_post_data', 'wl_remove_text_annotations', '98', 1 ); |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Adds wl-metabox CSS class to a metabox. |
|
82
|
|
|
* |
|
83
|
|
|
* @since 3.2.0 |
|
84
|
|
|
* |
|
85
|
|
|
* @param array $classes List of CSS classes already assigned to the metabox. |
|
86
|
|
|
* |
|
87
|
|
|
* @return array The updated list of CSS classes. |
|
88
|
|
|
*/ |
|
89
|
|
|
function wl_admin_metaboxes_add_css_class( $classes = array() ) { |
|
90
|
|
|
|
|
91
|
|
|
return array_merge( $classes, array( 'wl-metabox' ) ); |
|
92
|
|
|
} |
|
93
|
|
|
|
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.