function wppa_sanitize_custom_field($txt)
{
    if (wppa_switch('allow_html_custom')) {
        $result = wppa_strip_tags($txt, 'script&style');
    } else {
        $result = strip_tags($txt);
    }
    return $result;
}
Example #2
0
function wppa_get_share_html($id, $key = '', $js = true)
{
    global $wppa_locale;
    $do_it = false;
    if (!wppa('is_slideonly') || $key == 'lightbox') {
        if (wppa_switch('share_on') && !wppa_in_widget()) {
            $do_it = true;
        }
        if (wppa_switch('share_on_widget') && wppa_in_widget()) {
            $do_it = true;
        }
        if (wppa_switch('share_on_lightbox')) {
            $do_it = true;
        }
    }
    if (!$do_it) {
        return '';
    }
    // The share url
    if (wppa_in_widget()) {
        if (wppa_opt('widget_sm_linktype') == 'home') {
            $share_url = home_url();
        } else {
            $share_url = get_permalink(wppa_get_the_landing_page('wppa_widget_sm_linkpage', __('Social media landing page', 'wp-photo-album-plus')));
            $alb = wppa_get_photo_item($id, 'album');
            $oc = wppa_opt('widget_sm_linkpage_oc');
            $share_url .= '?wppa-album=' . $alb . '&wppa-photo=' . $id . '&wppa-cover=0&wppa-occur=' . $oc;
            if (wppa_switch('share_single_image')) {
                $share_url .= '&wppa-single=1';
            }
        }
    } else {
        $share_url = wppa_get_image_page_url_by_id($id, wppa_switch('share_single_image'));
        $share_url = str_replace('&', '&', $share_url);
    }
    // The share title
    $photo_name = wppa_get_photo_name($id);
    // The share description
    $photo_desc = wppa_html(wppa_get_photo_desc($id));
    $photo_desc = strip_shortcodes(wppa_strip_tags($photo_desc, 'all'));
    // The default description
    $site = str_replace('&', __('and', 'wp-photo-album-plus'), get_bloginfo('name'));
    $see_on_site = sprintf(__('See this image on %s', 'wp-photo-album-plus'), $site);
    // The share image. Must be the fullsize image for facebook.
    // If you take the thumbnail, facebook takes a different image at random.
    $share_img = wppa_get_photo_url($id);
    // The icon size
    if (wppa_in_widget() && $key != 'lightbox' || $key == 'thumb') {
        $s = '16';
    } else {
        $s = wppa_opt('share_size');
    }
    // qr code
    if (wppa_switch('share_qr') && $key != 'thumb') {
        $src = 'http://api.qrserver.com/v1/create-qr-code/' . '?data=' . urlencode($share_url) . '&size=80x80' . '&color=' . trim(wppa_opt('qr_color'), '#') . '&bgcolor=' . trim(wppa_opt('qr_bgcolor'), '#');
        $qr = '<div style="float:left; padding:2px;" >' . '<img' . ' src="' . $src . '"' . ' title="' . esc_attr($share_url) . '"' . ' alt="' . __('QR code', 'wp-photo-album-plus') . '"' . ' />' . '</div>';
    } else {
        $qr = '';
    }
    // twitter share button
    if (wppa_switch('share_twitter')) {
        $tweet = urlencode($see_on_site) . ': ';
        $tweet_len = strlen($tweet) + '1';
        $tweet .= urlencode($share_url);
        // find first '/' after 'http( s )://' rest doesnt count for twitter chars
        $url_len = strpos($share_url, '/', 8) + 1;
        $tweet_len += $url_len > 1 ? $url_len : strlen($share_url);
        $rest_len = 140 - $tweet_len;
        if (wppa_switch('show_full_name')) {
            if ($rest_len > strlen($photo_name)) {
                $tweet .= ' ' . urlencode($photo_name);
                $rest_len -= strlen($photo_name);
                $rest_len -= '2';
            } else {
                $tweet .= ' ' . urlencode(substr($photo_name, 0, $rest_len)) . '...';
                $rest_len -= strlen(substr($photo_name, 0, $rest_len));
                $rest_len -= '5';
            }
        }
        if ($photo_desc) {
            if ($rest_len > strlen($photo_desc)) {
                $tweet .= ': ' . urlencode($photo_desc);
            } elseif ($rest_len > 8) {
                $tweet .= ': ' . urlencode(substr($photo_desc, 0, $rest_len)) . '...';
            }
        }
        $tw = '<div style="float:left; padding:0 2px;" >' . '<a' . ' title="' . sprintf(__('Tweet %s on Twitter', 'wp-photo-album-plus'), esc_attr($photo_name)) . '"' . ' href="https://twitter.com/intent/tweet?text=' . $tweet . '"' . ' target="_blank"' . ' >' . '<img' . ' src="' . wppa_get_imgdir() . 'twitter.png"' . ' style="height:' . $s . 'px;vertical-align:top;"' . ' alt="' . esc_attr(__('Share on Twitter', 'wp-photo-album-plus')) . '"' . ' />' . '</a>' . '</div>';
    } else {
        $tw = '';
    }
    // Google
    if (wppa_switch('share_google')) {
        $go = '<div style="float:left; padding:0 2px;" >' . '<a' . ' title="' . sprintf(__('Share %s on Google+', 'wp-photo-album-plus'), esc_attr($photo_name)) . '"' . ' href="https://plus.google.com/share?url=' . urlencode($share_url) . '"' . ' onclick="javascript:window.open( this.href, \\"\\", \\"menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600\\" );return false;"' . ' target="_blank"' . ' >' . '<img' . ' src="' . wppa_get_imgdir() . 'google.png"' . ' style="height:' . $s . 'px;vertical-align:top;"' . ' alt="' . esc_attr(__('Share on Google+', 'wp-photo-album-plus')) . '"' . ' />' . '</a>' . '</div>';
    } else {
        $go = '';
    }
    // Pinterest
    $desc = urlencode($see_on_site) . ': ' . urlencode($photo_desc);
    if (strlen($desc) > 500) {
        $desc = substr($desc, 0, 495) . '...';
    }
    if (wppa_switch('share_pinterest')) {
        $pi = '<div style="float:left; padding:0 2px;" >' . '<a' . ' title="' . sprintf(__('Share %s on Pinterest', 'wp-photo-album-plus'), esc_attr($photo_name)) . '"' . ' href="http://pinterest.com/pin/create/button/?url=' . urlencode($share_url) . '&media=' . urlencode(str_replace('/thumbs/', '/', $share_img)) . '&description=' . $desc . '"' . ' target="_blank"' . ' >' . '<img' . ' src="' . wppa_get_imgdir() . 'pinterest.png" style="height:' . $s . 'px;vertical-align:top;"' . ' alt="' . esc_attr(__('Share on Pinterest', 'wp-photo-album-plus')) . '"' . ' />' . '</a>' . '</div>';
    } else {
        $pi = '';
    }
    // LinkedIn
    if (wppa_switch('share_linkedin') && $key != 'thumb' && $key != 'lightbox') {
        $li = '<script' . ' type="text/javascript"' . ' src="//platform.linkedin.com/in.js"' . ' >' . 'lang: ' . $wppa_locale . '</script>' . '<script' . ' type="IN/Share"' . ' data-url="' . urlencode($share_url) . '"' . ' data-counter="top"' . ' >' . '</script>';
        if ($js) {
            $li = str_replace('<', '[', $li);
        }
    } else {
        $li = '';
    }
    // Facebook
    $fb = '';
    $need_fb_init = false;
    $small = 'thumb' == $key;
    if ('lightbox' == $key) {
        if (wppa_switch('facebook_like') && wppa_switch('share_facebook')) {
            $lbs = 'max-width:62px; max-height:96px; overflow:show;';
        } else {
            $lbs = 'max-width:62px; max-height:64px; overflow:show;';
        }
    } else {
        $lbs = '';
    }
    // Share
    if (wppa_switch('share_facebook') && !wppa_switch('facebook_like')) {
        if ($small) {
            $fb .= '<div' . ' class="fb-share-button"' . ' style="float:left;"' . ' data-href="' . $share_url . '"' . ' data-type="icon"' . ' >' . '</div>';
        } else {
            $disp = wppa_opt('fb_display');
            if ('standard' == $disp) {
                $disp = 'button';
            }
            $fb .= '<div' . ' class="fb-share-button"' . ' style="float:left; ' . $lbs . '"' . ' data-width="200"' . ' data-href="' . $share_url . '"' . ' data-type="' . $disp . '"' . ' >' . '</div>';
        }
        $need_fb_init = true;
    }
    // Like
    if (wppa_switch('facebook_like') && !wppa_switch('share_facebook')) {
        if ($small) {
            $fb .= '<div' . ' class="fb-like"' . ' style="float:left;"' . ' data-href="' . $share_url . '"' . ' data-layout="button"' . ' >' . '</div>';
        } else {
            $fb .= '<div' . ' class="fb-like"' . ' style="float:left; ' . $lbs . '"' . ' data-width="200"' . ' data-href="' . $share_url . '"' . ' data-layout="' . wppa_opt('fb_display') . '"' . ' >' . '</div>';
        }
        $need_fb_init = true;
    }
    // Like and share
    if (wppa_switch('facebook_like') && wppa_switch('share_facebook')) {
        if ($small) {
            $fb .= '<div' . ' class="fb-like"' . ' style="float:left;"' . ' data-href="' . $share_url . '"' . ' data-layout="button"' . ' data-action="like"' . ' data-show-faces="false"' . ' data-share="true"' . ' >' . '</div>';
        } else {
            $fb .= '<div' . ' class="fb-like"' . ' style="float:left; ' . $lbs . '"' . ' data-width="200"' . ' data-href="' . $share_url . '"' . ' data-layout="' . wppa_opt('fb_display') . '"' . ' data-action="like"' . ' data-show-faces="false"' . ' data-share="true"' . ' >' . '</div>';
        }
        $need_fb_init = true;
    }
    // Comments
    if (wppa_switch('facebook_comments') && !wppa_in_widget() && $key != 'thumb' && $key != 'lightbox') {
        $width = wppa('auto_colwidth') ? '100%' : wppa_get_container_width(true);
        if (wppa_switch('facebook_comments')) {
            $fb .= '<div style="color:blue;clear:both" >' . __('Comment on Facebook:', 'wp-photo-album-plus') . '</div>';
            $fb .= '<div class="fb-comments" data-href="' . $share_url . '" data-width=' . $width . '></div>';
            $need_fb_init = true;
        }
    }
    // Need init?
    if ($need_fb_init) {
        if ($js && $key != 'thumb') {
            $fb .= '[script>wppaFbInit();[/script>';
        } else {
            $fb .= '<script>wppaFbInit();</script>';
        }
    }
    return $qr . $tw . $go . $pi . $li . $fb . '<div style="clear:both"></div>';
}
function wppa_get_imgevents($type = '', $id = '', $no_popup = false, $idx = '')
{
    global $wpdb;
    $result = '';
    $perc = '';
    if ($type == 'thumb' || $type == 'film') {
        if (wppa_switch('use_thumb_opacity') || wppa_switch('use_thumb_popup')) {
            if (wppa_switch('use_thumb_opacity')) {
                $perc = wppa_opt('thumb_opacity');
                $result = ' onmouseout="jQuery( this ).fadeTo( 400, ' . $perc / 100 . ' )" onmouseover="jQuery( this ).fadeTo( 400, 1.0 );';
            } else {
                $result = ' onmouseover="';
            }
            if ($type == 'film' && wppa_switch('film_hover_goto')) {
                $result .= 'wppaGotoFilmNoMove( ' . wppa('mocc') . ', ' . $idx . ' );';
            }
            if (!$no_popup && wppa_switch('use_thumb_popup')) {
                if (wppa_opt('thumb_linktype') != 'lightbox') {
                    $name = wppa_switch('popup_text_name') || wppa_switch('popup_text_owner') ? wppa_get_photo_name($id, wppa_switch('popup_text_owner'), false, false, wppa_switch('popup_text_name')) : '';
                    $name = esc_js($name);
                    $desc = wppa_switch('popup_text_desc') ? wppa_get_photo_desc($id) : '';
                    if (wppa_switch('popup_text_desc_strip')) {
                        $desc = wppa_strip_tags($desc);
                    }
                    $desc = esc_js($desc);
                    $rating = wppa_switch('popup_text_rating') ? wppa_get_rating_by_id($id) : '';
                    if ($rating && wppa_switch('show_rating_count')) {
                        $rating .= ' ( ' . wppa_get_rating_count_by_id($id) . ' )';
                    }
                    $rating = esc_js($rating);
                    if (wppa_switch('popup_text_ncomments')) {
                        $ncom = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s AND `status` = 'approved'", $id));
                    } else {
                        $ncom = '0';
                    }
                    if ($ncom) {
                        $ncom = sprintf(_n('1 Comment', '%s Comments', $ncom, 'wp-photo-album-plus'), $ncom);
                    } else {
                        $ncom = '';
                    }
                    $ncom = esc_js($ncom);
                    $x = wppa_get_imagex($id, 'thumb');
                    $y = wppa_get_imagey($id, 'thumb');
                    /*
                    if ( wppa_is_video( $id ) ) {
                    	$x = wppa_get_videox( $id );
                    	$y = wppa_get_videoy( $id );
                    }
                    else {
                    	$x = wppa_get_thumbx( $id );
                    	$y = wppa_get_thumby( $id );
                    }
                    */
                    if ($x > $y) {
                        $w = wppa_opt('popupsize');
                        $h = round($w * $y / $x);
                    } else {
                        $h = wppa_opt('popupsize');
                        $w = round($h * $x / $y);
                    }
                    if (wppa_is_video($id)) {
                        $video_args = array('id' => $id, 'controls' => false, 'tagid' => 'wppa-img-' . wppa('mocc'), 'width' => $w, 'height' => $h);
                        if (wppa_opt('thumb_linktype') == 'fullpopup') {
                            $video_args['events'] = 'onclick="alert( \'' . esc_attr(__('A video can not be printed or downloaded', 'wp-photo-album-plus')) . '\' );"';
                        }
                        $videohtml = wppa_get_video_html($video_args);
                    } else {
                        $videohtml = '';
                    }
                    $result .= 'wppaPopUp( ' . wppa('mocc') . ', this, ' . $id . ', \'' . $name . '\', \'' . $desc . '\', \'' . $rating . '\', \'' . $ncom . '\', \'' . esc_js($videohtml) . '\', \'' . $w . '\', \'' . $h . '\' );" ';
                } else {
                    // Popup and lightbox on thumbs are incompatible. skip popup.
                    $result .= '" ';
                }
            } else {
                $result .= '" ';
            }
        }
    } elseif ($type == 'cover') {
        if (wppa_switch('use_cover_opacity')) {
            $perc = wppa_opt('cover_opacity');
            $result = ' onmouseover="jQuery( this ).fadeTo( 400, 1.0 )" onmouseout="jQuery( this ).fadeTo( 400, ' . $perc / 100 . ' )" ';
        }
    }
    return $result;
}
function wppa_create_textual_watermark_file($args)
{
    // See what we have
    $args = wp_parse_args((array) $args, array('content' => '---preview---', 'pos' => 'cencen', 'id' => '', 'font' => wppa_opt('wppa_textual_watermark_font'), 'text' => '', 'style' => wppa_opt('wppa_textual_watermark_type'), 'filebasename' => 'dummy', 'url' => false, 'width' => '', 'height' => '', 'transp' => '0'));
    // We may have been called from wppa_get_water_file_and_pos() just to find the settings
    // In this case there is no id given.
    $id = $args['id'];
    if (!$id && $args['content'] != '---preview---') {
        return false;
    }
    if ($id && wppa_is_video($id)) {
        //		return false;
    }
    // Set special values in case of preview
    if ($args['content'] == '---preview---') {
        $preview = true;
        $fontsize = $args['font'] == 'system' ? 5 : 12;
        $padding = 6;
        $linespacing = ceil($fontsize * 2 / 3);
    } else {
        $preview = false;
        $fontsize = wppa_opt('wppa_textual_watermark_size');
        if ($args['font'] == 'system') {
            $fontsize = min($fontsize, 5);
        }
        $padding = 12;
        $linespacing = ceil($fontsize * 2 / 3);
    }
    // Set font specific vars
    $fontfile = $args['font'] == 'system' ? '' : WPPA_UPLOAD_PATH . '/fonts/' . $args['font'] . '.ttf';
    // Output file
    if ($preview) {
        $filename = WPPA_UPLOAD_PATH . '/fonts/wmf' . $args['filebasename'] . '.png';
    } else {
        $filename = WPPA_UPLOAD_PATH . '/temp/wmf' . $args['filebasename'] . '.png';
    }
    // Preprocess the text
    if (!$args['text']) {
        switch ($args['content']) {
            case '---preview---':
                $text = strtoupper(substr($args['font'], 0, 1)) . strtolower(substr($args['font'], 1));
                break;
            case '---filename---':
                $text = wppa_get_photo_item($id, 'filename');
                break;
            case '---name---':
                $text = wppa_get_photo_name($id);
                break;
            case '---description---':
                $text = strip_tags(wppa_strip_tags(wppa_get_photo_desc($id), 'style&script'));
                break;
            case '---predef---':
                $text = wppa_opt('wppa_textual_watermark_text');
                if ($args['font'] != 'system') {
                    $text = str_replace('( c )', '&copy;', $text);
                    $text = str_replace('( R )', '&reg;', $text);
                }
                $text = html_entity_decode($text);
                $text = str_replace('w#site', get_bloginfo('url'), $text);
                $text = str_replace('w#owner', wppa_get_photo_item($id, 'owner'), $text);
                $text = str_replace('w#id', $id, $text);
                $text = str_replace('w#name', wppa_get_photo_name($id), $text);
                $text = str_replace('w#filename', wppa_get_photo_item($id, 'filename'), $text);
                $text = str_replace('w#timestamp', wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), wppa_get_photo_item($id, 'timestamp')), $text);
                $text = trim($text);
                break;
            default:
                wppa_log('Error', 'Unimplemented arg ' . $arg . ' in wppa_create_textual_watermark_file()');
                return false;
        }
    } else {
        $text = $args['text'];
    }
    // Any text anyway?
    if (!strlen($text)) {
        wppa_log('Error', 'No text for textual watermark. photo=' . $id);
        return false;
        // No text -> no watermark
    }
    // Split text on linebreaks
    $text = str_replace("\n", '\\n', $text);
    $lines = explode('\\n', $text);
    // Trim and remove empty lines
    $temp = $lines;
    $lines = array();
    foreach ($temp as $line) {
        $line = trim($line);
        if ($line) {
            $lines[] = $line;
        }
    }
    // Find image width
    if ($args['width']) {
        $image_width = $args['width'];
    } else {
        $image_width = '';
    }
    if ($args['height']) {
        $image_height = $args['height'];
    } else {
        $image_height = '';
    }
    if ($preview) {
        if (!$image_width) {
            $image_width = 2000;
        }
        if (!$image_height) {
            $image_height = 1000;
        }
    } else {
        //		$temp = getimagesize( wppa_get_photo_path( $id ) );
        $temp = wppa_get_imagexy($id);
        if (!is_array($temp)) {
            wppa_log('Error', 'Trying to apply a watermark on a non image file. Id = ' . $id);
            return false;
            // not an image
        }
        if (!$image_width) {
            $image_width = $temp[0];
        }
        if (!$image_height) {
            $image_height = $temp[1];
        }
    }
    $width_fits = false;
    while (!$width_fits) {
        // Find pixel linelengths
        foreach (array_keys($lines) as $key) {
            $lines[$key] = trim($lines[$key]);
            if ($args['font'] == 'system') {
                $lengths[$key] = strlen($lines[$key]) * imagefontwidth($fontsize);
            } else {
                $temp = imagettfbbox($fontsize, 0.0, $fontfile, $lines[$key]);
                $lengths[$key] = $temp[2] - $temp[0];
            }
        }
        $maxlen = wppa_array_max($lengths);
        // Find canvas size
        $nlines = count($lines);
        if ($args['font'] == 'system') {
            $lineheight = imagefontheight($fontsize);
        } else {
            $temp = imagettfbbox($fontsize, 0.0, $fontfile, $lines[0]);
            $lineheight = $temp[3] - $temp[7];
        }
        $canvas_width = wppa_array_max($lengths) + 4 * $padding;
        $canvas_height = ($lineheight + $linespacing) * count($lines) + 2 * $padding;
        // Does it fit?
        if ($canvas_width > $image_width) {
            // Break the longest line into two sublines. There should be a space in the right half, if not: fail
            $i = 0;
            $l = 0;
            foreach (array_keys($lines) as $key) {
                if (strlen($lines[$key]) > $l) {
                    $i = $key;
                    $l = strlen($lines[$key]);
                }
            }
            $temp = $lines;
            $lines = array();
            $j = 0;
            while ($j < $i) {
                $lines[$j] = $temp[$j];
                $j++;
            }
            //
            $j = $i;
            $llen = strlen($temp[$i]);
            $spos = floor($llen / 2);
            while ($spos < $llen && substr($temp[$i], $spos, 1) != ' ') {
                $spos++;
            }
            if ($spos == $llen) {
                // Unable to find a space, give up
                wppa_log('Error', 'Trying to apply a watermark that is too wide for the image. Id = ' . $id);
                return false;
                // too wide
            }
            $lines[$j] = substr($temp[$i], 0, $spos);
            $lines[$j + 1] = trim(str_replace($lines[$j], '', $temp[$i]));
            $i++;
            //
            $j = $i + 1;
            while ($j <= count($temp)) {
                $lines[$j] = $temp[$i];
                $j++;
            }
        } else {
            $width_fits = true;
        }
        if ($canvas_height > $image_height) {
            wppa_log('Error', 'Trying to apply a watermark that is too high for the image. Id = ' . $id);
            return false;
            // not an image
        }
    }
    // Create canvas
    $canvas = imagecreatetruecolor($canvas_width, $canvas_height);
    $bgcolor = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
    // Transparent
    $white = imagecolorallocatealpha($canvas, 255, 255, 255, $args['transp']);
    $black = imagecolorallocatealpha($canvas, 0, 0, 0, $args['transp']);
    imagefill($canvas, 0, 0, $bgcolor);
    //	imagerectangle( $canvas, 0, 0, $canvas_width-1, $canvas_height-1, $white );	// debug
    // Define the text colors
    switch ($args['style']) {
        case 'tvstyle':
        case 'whiteonblack':
            $fg = $white;
            $bg = $black;
            break;
        case 'utopia':
        case 'blackonwhite':
            $fg = $black;
            $bg = $white;
            break;
        case 'white':
            $fg = $white;
            $bg = $bgcolor;
            break;
        case 'black':
            $fg = $black;
            $bg = $bgcolor;
            break;
    }
    // Plot the text
    foreach (array_keys($lines) as $lineno) {
        if (strpos($args['pos'], 'lft') !== false) {
            $indent = 0;
        } elseif (strpos($args['pos'], 'rht') !== false) {
            $indent = $maxlen - $lengths[$lineno];
        } else {
            $indent = floor(($maxlen - $lengths[$lineno]) / 2);
        }
        switch ($args['style']) {
            case 'tvstyle':
            case 'utopia':
                for ($i = -1; $i <= 1; $i++) {
                    for ($j = -1; $j <= 1; $j++) {
                        if ($args['font'] == 'system') {
                            imagestring($canvas, $fontsize, 2 * $padding + $i + $indent, $padding + $lineno * ($lineheight + $linespacing) + $j, $lines[$lineno], $bg);
                        } else {
                            imagettftext($canvas, $fontsize, 0, 2 * $padding + $i + $indent, $padding + ($lineno + 1) * $lineheight + $lineno * $linespacing + $j, $bg, $fontfile, $lines[$lineno]);
                        }
                    }
                }
                if ($args['font'] == 'system') {
                    imagestring($canvas, $fontsize, 2 * $padding + $indent, $padding + $lineno * ($lineheight + $linespacing), $lines[$lineno], $fg);
                } else {
                    imagettftext($canvas, $fontsize, 0, 2 * $padding + $indent, $padding + ($lineno + 1) * $lineheight + $lineno * $linespacing, $fg, $fontfile, $lines[$lineno]);
                }
                break;
            case 'blackonwhite':
            case 'whiteonblack':
            case 'white':
            case 'black':
                $lft = $padding + $indent;
                $rht = 3 * $padding + $indent + $lengths[$lineno];
                $top = $lineno * ($lineheight + $linespacing) + $padding;
                $bot = ($lineno + 1) * ($lineheight + $linespacing) + $padding;
                imagefilledrectangle($canvas, $lft, $top + 1, $rht, $bot, $bg);
                //				imagerectangle( $canvas, $lft, $top, $rht, $bot, $fg );	// debug
                $top = $padding + $lineno * ($lineheight + $linespacing) + floor($linespacing / 2);
                $lft = 2 * $padding + $indent;
                $bot = $padding + ($lineno + 1) * ($lineheight + $linespacing) - ceil($linespacing / 2);
                if ($args['font'] == 'system') {
                    imagestring($canvas, $fontsize, $lft, $top, $lines[$lineno], $fg);
                } else {
                    imagettftext($canvas, $fontsize, 0, $lft, $bot - 1, $fg, $fontfile, $lines[$lineno]);
                }
                break;
        }
    }
    imagesavealpha($canvas, true);
    imagepng($canvas, $filename);
    imagedestroy($canvas);
    if ($preview || $args['url']) {
        $url = str_replace(WPPA_UPLOAD_PATH, WPPA_UPLOAD_URL, $filename);
        return $url;
    } else {
        return $filename;
    }
}
function wppa_index_raw_to_words($xtext, $noskips = false)
{
    $ignore = array('"', "'", '`', '\\', '>', '<', ',', ':', ';', '!', '?', '=', '_', '[', ']', '(', ')', '{', '}', '..', '...', '....', "\n", "\r", "\t", '.jpg', '.png', '.gif', '&#039', '&amp', 'w#cc0', 'w#cc1', 'w#cc2', 'w#cc3', 'w#cc4', 'w#cc5', 'w#cc6', 'w#cc7', 'w#cc8', 'w#cc9');
    if ($noskips) {
        $skips = array();
    } else {
        $skips = get_option('wppa_index_skips', array());
    }
    $result = array();
    if ($xtext) {
        $text = strtolower($xtext);
        $text = html_entity_decode($text);
        $text = wppa_strip_tags($text, 'script&style');
        // strip style and script tags inclusive content
        $text = str_replace('>', '> ', $text);
        // Make sure <td>word1</td><td>word2</td> will not endup in 'word1word2', but in 'word1' 'word2'
        $text = strip_tags($text);
        // Now strip the tags
        $text = str_replace($ignore, ' ', $text);
        // Remove funny chars
        $text = trim($text);
        $text = trim($text, " ./-");
        while (strpos($text, '  ')) {
            $text = str_replace('  ', ' ', $text);
        }
        // Compress spaces
        $words = explode(' ', $text);
        foreach ($words as $word) {
            $word = trim($word);
            $word = trim($word, " ./-");
            if (strlen($word) > '1' && !in_array($word, $skips)) {
                $result[] = $word;
            }
            if (strpos($word, '-') !== false) {
                $fracts = explode('-', $word);
                foreach ($fracts as $fract) {
                    $fract = trim($fract);
                    $fract = trim($fract, " ./-");
                    if (strlen($fract) > '1' && !in_array($fract, $skips)) {
                        $result[] = $fract;
                    }
                }
            }
        }
    }
    // sort
    sort($result);
    // Remove dups
    $start = 0;
    foreach (array_keys($result) as $key) {
        if ($key > 0) {
            if ($result[$key] == $result[$start]) {
                unset($result[$key]);
            } else {
                $start = $key;
            }
        }
    }
    return $result;
}
Example #6
0
function wppa_get_og_desc($id)
{
    global $thumb;
    wppa_cache_thumb($id);
    $result = sprintf(__a('See this image on %s'), str_replace('&amp;', __a('and'), get_bloginfo('name'))) . ': ' . strip_shortcodes(wppa_strip_tags(wppa_html(wppa_get_photo_desc($id)), 'all'));
    $result = apply_filters('wppa_get_og_desc', $result);
    return $result;
}
function wppa_update_photo($args)
{
    global $wpdb;
    if (!is_array($args)) {
        return false;
    }
    if (!$args['id']) {
        return false;
    }
    $thumb = wppa_cache_thumb($args['id']);
    if (!$thumb) {
        return false;
    }
    $id = $args['id'];
    // If Timestamp update, make sure modified is updated to now
    if (isset($args['timestamp'])) {
        $args['modified'] = time();
    }
    foreach (array_keys($args) as $itemname) {
        $itemvalue = $args[$itemname];
        $doit = false;
        // Sanitize input
        switch ($itemname) {
            case 'id':
                break;
            case 'name':
                $itemvalue = wppa_strip_tags($itemvalue, 'all');
                $doit = true;
                break;
            case 'description':
                $itemvalue = balanceTags($itemvalue, true);
                $itemvalue = wppa_strip_tags($itemvalue, 'script&style');
                $doit = true;
                break;
            case 'timestamp':
            case 'modified':
                if (!$itemvalue) {
                    $itemvalue = time();
                }
                $doit = true;
                break;
            case 'scheduledtm':
            case 'exifdtm':
            case 'page_id':
                $doit = true;
                break;
            case 'status':
                $doit = true;
                break;
            case 'tags':
                $itemvalue = wppa_sanitize_tags($itemvalue);
                $doit = true;
                break;
            case 'thumbx':
            case 'thumby':
            case 'photox':
            case 'photoy':
            case 'videox':
            case 'videoy':
                $itemvalue = intval($itemvalue);
                $doit = true;
                break;
            case 'ext':
                $doit = true;
                break;
            case 'filename':
                $itemvalue = wppa_sanitize_file_name($itemvalue);
                $doit = true;
                break;
            case 'custom':
            case 'stereo':
                $doit = true;
                break;
            default:
                wppa_log('Error', 'Not implemented in wppa_update_photo(): ' . $itemname);
                return false;
        }
        if ($doit) {
            if ($wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `" . $itemname . "` = %s WHERE `id` = %s LIMIT 1", $itemvalue, $id))) {
                wppa_cache_photo('invalidate', $id);
            }
        }
    }
    return true;
}
function wppa_get_og_desc($id)
{
    $result = sprintf(__('See this image on %s', 'wp-photo-album-plus'), str_replace('&amp;', __('and', 'wp-photo-album-plus'), get_bloginfo('name'))) . ': ' . strip_shortcodes(wppa_strip_tags(wppa_html(wppa_get_photo_desc($id)), 'all'));
    $result = apply_filters('wppa_get_og_desc', $result);
    return $result;
}