function wppa_explode_csv($txt) { // Make local copy $temp = $txt; // Replace double double quotes $temp = str_replace('""', '&ddquote;', $temp); // See if double quotes in the text if (strpos($temp, '"')) { $temp = explode('"', $temp); $i = '1'; while (isset($temp[$i])) { // Replace embedded comma $temp[$i] = str_replace(',', ',', $temp[$i]); $i += '2'; } // Convert to string again $temp = implode('', $temp); } // Make to array $result = explode(',', $temp); // Repair embedded comma's and double quotes $i = '0'; while (isset($result[$i])) { $result[$i] = str_replace(',', ',', $result[$i]); $result[$i] = str_replace('&ddquote;', '"', $result[$i]); $i++; } // Sanitize array elements foreach (array_keys($result) as $key) { $result[$key] = wppa_sanitize_text($result[$key]); } // Done! return $result; }
function wppa_exif_html($photo) { global $wpdb; global $wppaexifdefaults; global $wppaexiflabels; // Get the default ( one time only ) if (!wppa('exif')) { $tmp = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_EXIF . "` WHERE `photo` = %s ORDER BY `tag`", '0'), "ARRAY_A"); wppa_dbg_q('Q-exif0'); if (!$tmp) { return ''; } // Nothing defined $wppaexifdefaults = false; // Init $wppaexiflabels = false; // Init foreach ($tmp as $t) { $wppaexifdefaults[$t['tag']] = $t['status']; $wppaexiflabels[$t['tag']] = $t['description']; } wppa('exif', true); } $count = 0; // Get the photo data $exifdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_EXIF . "` WHERE `photo`=%s ORDER BY `tag`", $photo), "ARRAY_A"); wppa_dbg_q('Q-exif'); if ($exifdata) { // Open the container content $result = '<div id="exifcontent-' . wppa('mocc') . '" >'; // Open or closed? $d1 = wppa_switch('show_exif_open') ? 'display:none;' : 'display:inline;'; $d2 = wppa_switch('show_exif_open') ? 'display:inline;' : 'display:none;'; // Process data $onclick = 'wppaStopShow( ' . wppa('mocc') . ' );' . 'jQuery( \'.wppa-exif-table-' . wppa('mocc') . '\' ).css( \'display\', \'\' );' . 'jQuery( \'.-wppa-exif-table-' . wppa('mocc') . '\' ).css( \'display\', \'none\' );'; $result .= '<a' . ' class="-wppa-exif-table-' . wppa('mocc') . '"' . ' onclick="' . esc_attr($onclick) . '"' . ' style="cursor:pointer;' . $d1 . '"' . ' >' . __('Show EXIF data', 'wp-photo-album-plus') . '</a>'; $onclick = 'jQuery( \'.wppa-exif-table-' . wppa('mocc') . '\' ).css( \'display\', \'none\' );' . 'jQuery( \'.-wppa-exif-table-' . wppa('mocc') . '\' ).css( \'display\', \'\' )'; $result .= '<a' . ' class="wppa-exif-table-switch wppa-exif-table-' . wppa('mocc') . '"' . ' onclick="' . esc_attr($onclick) . '"' . ' style="cursor:pointer;' . $d2 . '"' . ' >' . __('Hide EXIF data', 'wp-photo-album-plus') . '</a>'; $result .= '<div style="clear:both;" ></div>' . '<table' . ' class="wppa-exif-table-' . wppa('mocc') . ' wppa-detail"' . ' style="' . $d2 . ' border:0 none; margin:0;"' . ' >' . '<tbody>'; $oldtag = ''; foreach ($exifdata as $exifline) { if (!isset($wppaexifdefaults[$exifline['tag']])) { continue; } $exifline['description'] = trim($exifline['description'], ".. "); // Photo status is hide ? if ($exifline['status'] == 'hide') { continue; } // P s is default and default is hide if ($exifline['status'] == 'default' && $wppaexifdefaults[$exifline['tag']] == 'hide') { continue; } // P s is default and default is optional and field is empty if ($exifline['status'] == 'default' && $wppaexifdefaults[$exifline['tag']] == 'option' && !$exifline['description']) { continue; } $count++; $newtag = $exifline['tag']; if ($newtag != $oldtag && $oldtag != '') { $result .= '</td></tr>'; } // Close previous line if ($newtag == $oldtag) { $result .= '; '; // next item with same tag } else { $result .= '<tr style="border-bottom:0 none; border-top:0 none; border-left: 0 none; border-right: 0 none;" >' . '<td class="wppa-exif-label wppa-box-text wppa-td" style="' . __wcs('wppa-box-text') . __wcs('wppa-td') . '" >'; $result .= esc_js(__($wppaexiflabels[$newtag], 'wp-photo-album-plus')); $result .= '</td><td class="wppa-exif-value wppa-box-text wppa-td" style="' . __wcs('wppa-box-text') . __wcs('wppa-td') . '" >'; } $result .= esc_js(wppa_sanitize_text(__(wppa_format_exif($exifline['tag'], $exifline['description']), 'wp-photo-album-plus'))); $oldtag = $newtag; } if ($oldtag != '') { $result .= '</td></tr>'; } // Close last line $result .= '</tbody></table></div>'; } if (!$count) { $result = '<div id="exifcontent-' . wppa('mocc') . '" >' . __('No EXIF data', 'wp-photo-album-plus') . '</div>'; } return $result; }
function wppa_exif_html($photo) { global $wpdb; global $wppa_exif_labels; global $wppa_exif_cache; // Get tha labels if not yet present if (!is_array($wppa_exif_labels)) { $wppa_exif_labels = $wpdb->get_results("SELECT * FROM `" . WPPA_EXIF . "` WHERE `photo` = '0' ORDER BY `tag`", ARRAY_A); } $count = 0; // If in cache, use it $exifdata = false; if (is_array($wppa_exif_cache)) { if (isset($wppa_exif_cache[$photo])) { $exifdata = $wppa_exif_cache[$photo]; } } // Get the photo data if ($exifdata === false) { $exifdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_EXIF . "` WHERE `photo`=%s ORDER BY `tag`", $photo), "ARRAY_A"); // Save in cache, even when empty $wppa_exif_cache[$photo] = $exifdata; } // Create the output if (!empty($exifdata)) { // Open the container content $result = '<div id="exifcontent-' . wppa('mocc') . '" >'; // Open or closed? $d1 = wppa_switch('show_exif_open') ? 'display:none;' : 'display:inline;'; $d2 = wppa_switch('show_exif_open') ? 'display:inline;' : 'display:none;'; // Process data $onclick = 'wppaStopShow( ' . wppa('mocc') . ' );' . 'jQuery( \'.wppa-exif-table-' . wppa('mocc') . '\' ).css( \'display\', \'\' );' . 'jQuery( \'.-wppa-exif-table-' . wppa('mocc') . '\' ).css( \'display\', \'none\' );'; $result .= '<a' . ' class="-wppa-exif-table-' . wppa('mocc') . '"' . ' onclick="' . esc_attr($onclick) . '"' . ' style="cursor:pointer;' . $d1 . '"' . ' >' . __('Show EXIF data', 'wp-photo-album-plus') . '</a>'; $onclick = 'jQuery( \'.wppa-exif-table-' . wppa('mocc') . '\' ).css( \'display\', \'none\' );' . 'jQuery( \'.-wppa-exif-table-' . wppa('mocc') . '\' ).css( \'display\', \'\' )'; $result .= '<a' . ' class="wppa-exif-table-switch wppa-exif-table-' . wppa('mocc') . '"' . ' onclick="' . esc_attr($onclick) . '"' . ' style="cursor:pointer;' . $d2 . '"' . ' >' . __('Hide EXIF data', 'wp-photo-album-plus') . '</a>'; $result .= '<div style="clear:both;" ></div>' . '<table' . ' class="wppa-exif-table-' . wppa('mocc') . ' wppa-detail"' . ' style="' . $d2 . ' border:0 none; margin:0;"' . ' >' . '<tbody>'; $oldtag = ''; foreach ($exifdata as $exifline) { $default = 'default'; $label = ''; foreach ($wppa_exif_labels as $exif_label) { if ($exif_label['tag'] == $exifline['tag']) { $default = $exif_label['status']; $label = $exif_label['description']; } } // if ( ! isset( $wppa_exifdefaults[$exifline['tag']] ) ) continue; $exifline['description'] = trim($exifline['description'], ".. "); // Photo status is hide ? if ($exifline['status'] == 'hide') { continue; } // P s is default and default is hide if ($exifline['status'] == 'default' && $default == 'hide') { continue; } // P s is default and default is optional and field is empty if ($exifline['status'] == 'default' && $default == 'option' && !$exifline['description']) { continue; } $count++; $newtag = $exifline['tag']; if ($newtag != $oldtag && $oldtag != '') { $result .= '</td></tr>'; } // Close previous line if ($newtag == $oldtag) { $result .= '; '; // next item with same tag } else { $result .= '<tr style="border-bottom:0 none; border-top:0 none; border-left: 0 none; border-right: 0 none;" >' . '<td class="wppa-exif-label wppa-box-text wppa-td" style="' . __wcs('wppa-box-text') . __wcs('wppa-td') . '" >'; $result .= esc_js(__($label)); $result .= '</td><td class="wppa-exif-value wppa-box-text wppa-td" style="' . __wcs('wppa-box-text') . __wcs('wppa-td') . '" >'; } $result .= esc_js(wppa_sanitize_text(__(wppa_format_exif($exifline['tag'], $exifline['description']), 'wp-photo-album-plus'))); $oldtag = $newtag; } if ($oldtag != '') { $result .= '</td></tr>'; } // Close last line $result .= '</tbody></table></div>'; } if (!$count) { $result = '<div id="exifcontent-' . wppa('mocc') . '" >' . __('No EXIF data', 'wp-photo-album-plus') . '</div>'; } return $result; }