| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
$bb_languages=array('en', 'fr'); |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
function bb_get_the_language() |
|---|
| 53 |
{ |
|---|
| 54 |
$post_language=get_post_custom_values("language"); |
|---|
| 55 |
$language=$post_language['0']; |
|---|
| 56 |
return($language); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
function bb_get_the_other_language() |
|---|
| 61 |
{ |
|---|
| 62 |
global $bb_languages; |
|---|
| 63 |
if(bb_get_the_language()==$bb_languages[0]) |
|---|
| 64 |
{ |
|---|
| 65 |
$other_language=$bb_languages[1]; |
|---|
| 66 |
}else{ |
|---|
| 67 |
$other_language=$bb_languages[0]; |
|---|
| 68 |
} |
|---|
| 69 |
return($other_language); |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
function bb_the_time($format="%A %d.%m.%Y<br />%Hh%M") |
|---|
| 78 |
{ |
|---|
| 79 |
global $post; |
|---|
| 80 |
|
|---|
| 81 |
$language=bb_get_the_language(); |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
$code = $language . '_' . strtoupper($language); |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
setlocale(LC_TIME, $code); |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
$wp_time=$post->post_date; |
|---|
| 91 |
$timestamp=strtotime($wp_time); |
|---|
| 92 |
$result=strftime($format, $timestamp); |
|---|
| 93 |
print($result); |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
function bb_the_language() |
|---|
| 98 |
{ |
|---|
| 99 |
$language=bb_get_the_language(); |
|---|
| 100 |
print($language); |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
function bb_the_other_excerpt($before='<div class="other-excerpt" lang="%lg"><p>', $after='</p></div>') |
|---|
| 105 |
{ |
|---|
| 106 |
$post_other_excerpt=get_post_custom_values("other-excerpt"); |
|---|
| 107 |
$the_other_excerpt=$post_other_excerpt['0']; |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
if(!empty($the_other_excerpt)) |
|---|
| 111 |
{ |
|---|
| 112 |
|
|---|
| 113 |
$excerpt_language=bb_get_the_other_language(); |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
$before=str_replace('%lg', $excerpt_language, $before); |
|---|
| 117 |
$after=str_replace('%lg', $excerpt_language, $after); |
|---|
| 118 |
// stick everything together |
|---|
| 119 |
$the_other_excerpt = $before . $the_other_excerpt . $after; |
|---|
| 120 |
print($the_other_excerpt); |
|---|
| 121 |
} |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
function add_other_excerpt_textarea() { |
|---|
| 128 |
|
|---|
| 129 |
global $post; |
|---|
| 130 |
|
|---|
| 131 |
$excerpt = get_post_meta($post->ID, 'other-excerpt', true); |
|---|
| 132 |
|
|---|
| 133 |
echo '<fieldset id="postotherexcerpt" style="clear: both;"><legend>' . __('Other Language Excerpt', 'BasicBilingual') . '</legend>'; |
|---|
| 134 |
echo '<div><textarea rows="4" cols="80" name="other-excerpt" id="other-excerpt">'; |
|---|
| 135 |
print($excerpt); |
|---|
| 136 |
echo '</textarea></div></fieldset>'; |
|---|
| 137 |
|
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
function add_language_box() |
|---|
| 142 |
{ |
|---|
| 143 |
global $bb_languages; |
|---|
| 144 |
global $post; |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
$current_language=get_post_meta($post->ID, 'language', true); |
|---|
| 148 |
if(empty($current_language)) |
|---|
| 149 |
{ |
|---|
| 150 |
$current_language=$bb_languages[0]; |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
print('<fieldset id="languagediv" style="height: 3.5em; width: 5em; position: absolute; top: 10em; left: 42em;"> |
|---|
| 154 |
<legend>'); |
|---|
| 155 |
echo __('Language'); |
|---|
| 156 |
print('</legend> |
|---|
| 157 |
<div><input type="text" name="language" size="7" value="'); |
|---|
| 158 |
print($current_language); |
|---|
| 159 |
print('" id="language" /></div> |
|---|
| 160 |
</fieldset>'); |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
function bb_update_meta($id, $field) |
|---|
| 167 |
{ |
|---|
| 168 |
$setting = $_POST[$field]; |
|---|
| 169 |
$meta_exists=update_post_meta($id, $field, $setting); |
|---|
| 170 |
if(!$meta_exists) |
|---|
| 171 |
{ |
|---|
| 172 |
add_post_meta($id, $field, $setting); |
|---|
| 173 |
} |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
function bb_update_language($id) |
|---|
| 178 |
{ |
|---|
| 179 |
bb_update_meta($id, "language"); |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
function bb_update_other_excerpt($id) |
|---|
| 184 |
{ |
|---|
| 185 |
bb_update_meta($id, "other-excerpt"); |
|---|
| 186 |
} |
|---|
| 187 |
|
|---|
| 188 |
add_action('simple_edit_form', 'add_other_excerpt_textarea'); |
|---|
| 189 |
add_action('edit_form_advanced', 'add_other_excerpt_textarea'); |
|---|
| 190 |
add_action('simple_edit_form', 'add_language_box'); |
|---|
| 191 |
add_action('edit_form_advanced', 'add_language_box'); |
|---|
| 192 |
add_action('edit_page_form', 'add_language_box'); |
|---|
| 193 |
add_action('edit_page_form', 'add_other_excerpt_textarea'); |
|---|
| 194 |
|
|---|
| 195 |
add_action('edit_post', 'bb_update_language'); |
|---|
| 196 |
add_action('save_post', 'bb_update_language'); |
|---|
| 197 |
add_action('publish_post', 'bb_update_language'); |
|---|
| 198 |
|
|---|
| 199 |
add_action('edit_post', 'bb_update_other_excerpt'); |
|---|
| 200 |
add_action('save_post', 'bb_update_other_excerpt'); |
|---|
| 201 |
add_action('publish_post', 'bb_update_other_excerpt'); |
|---|
| 202 |
?> |
|---|