Beispiel #1
0
function awpcp_utf8_substr_pcre($string, $start, $length = null)
{
    if (is_null($length)) {
        $length = awpcp_utf8_strlen($string) - $start;
    }
    if (preg_match_all('/.{' . $start . '}(.{' . $length . '})/su', $string, $matches)) {
        return $matches[1][0];
    } else {
        return '';
    }
}
Beispiel #2
0
 protected function prepare_ad_details($details, $characters)
 {
     $allow_html = (bool) get_awpcp_option('allowhtmlinadtext');
     if (!$allow_html) {
         $details = esc_html($details);
     } else {
         $details = wp_kses_post($details);
     }
     if ($characters > 0 && awpcp_utf8_strlen($details) > $characters) {
         $details = awpcp_utf8_substr($details, 0, $characters);
     }
     if ($allow_html) {
         $details = force_balance_tags($details);
     }
     return $details;
 }
Beispiel #3
0
function awpcp_get_ad_share_info($id)
{
    global $wpdb;
    $ad = AWPCP_Ad::find_by_id($id);
    $info = array();
    if (is_null($ad)) {
        return null;
    }
    $info['url'] = url_showad($id);
    $info['title'] = stripslashes($ad->ad_title);
    $info['description'] = strip_tags(stripslashes($ad->ad_details));
    $info['description'] = str_replace("\n", " ", $info['description']);
    if (awpcp_utf8_strlen($info['description']) > 300) {
        $info['description'] = awpcp_utf8_substr($info['description'], 0, 300) . '...';
    }
    $info['images'] = array();
    $info['published-time'] = awpcp_datetime('Y-m-d', $ad->ad_postdate);
    $info['modified-time'] = awpcp_datetime('Y-m-d', $ad->ad_last_updated);
    $images = awpcp_media_api()->find_by_ad_id($ad->ad_id, array('enabled' => true));
    foreach ($images as $image) {
        $info['images'][] = $image->get_url('large');
    }
    return $info;
}