/**
  * Creates a patchchat post by
  *   creating a user,
  *   creating a new patchchat post,
  *   creating first comment to post,
  *   adding an 'instant reply' comment from admin,
  *   building a new transient,
  *   return new transient to new user
  *
  * @author  caseypatrickdriscoll
  *
  * @edited 2015-08-03 16:32:16 - Adds user signon after creation
  * @edited 2015-08-28 20:11:39 - Adds PatchChat_Settings::instant_reply
  * @edited 2015-08-28 20:19:22 - Adds PatchChat_Settings::bot
  */
 public static function create($patchchat)
 {
     $email = $patchchat['email'];
     $text = $patchchat['text'];
     $username = substr($email, 0, strpos($email, "@"));
     $password = wp_generate_password(10, false);
     $title = substr($text, 0, 40);
     $time = current_time('mysql');
     $text = wp_strip_all_tags($text);
     /* Create User */
     $user_id = wp_create_user($username, $password, $email);
     // TODO: Add the user's name to the user
     // TODO: Check to see if user logged in, no need to create again
     wp_new_user_notification($user_id, $password);
     $user = get_user_by('id', $user_id);
     $creds = array('user_login' => $user->user_login, 'user_password' => $password, 'remember' => true);
     $user_signon = wp_signon($creds, false);
     /* Create PatchChat Post */
     $post = array('post_title' => $title, 'post_type' => 'patchchat', 'post_author' => $user_id, 'post_status' => 'new', 'post_date' => $time);
     $post_id = wp_insert_post($post);
     /* Create First Comment */
     $comment = array('comment_post_ID' => $post_id, 'user_id' => $user_id, 'comment_content' => $text, 'comment_date' => $time, 'comment_author_IP' => $_SERVER['REMOTE_ADDR'], 'comment_agent' => $_SERVER['HTTP_USER_AGENT']);
     $comment_id = wp_insert_comment($comment);
     /* Insert default action comment reply */
     $options = array('chatid' => $post_id, 'displayname' => $user->display_name);
     $comment = array('comment_post_ID' => $post_id, 'user_id' => PatchChat_Settings::bot(), 'comment_content' => PatchChat_Settings::instant_reply($options), 'comment_type' => 'auto', 'comment_date' => current_time('mysql'));
     $comment_id = wp_insert_comment($comment);
     // Will build the Transient
     PatchChat_Transient::get($post_id);
     return PatchChat_Controller::get_user_state($user_id);
 }
Beispiel #2
0
function fb_strip_and_format_desc($post)
{
    $desc_no_html = "";
    $desc_no_html = strip_shortcodes($desc_no_html);
    // Strip shortcodes first in case there is HTML inside the shortcode
    $desc_no_html = wp_strip_all_tags($desc_no_html);
    // Strip all html
    $desc_no_html = trim($desc_no_html);
    // Trim the final string, we may have stripped everything out of the post so this will make the value empty if that's the case
    // Check if empty, may be that the strip functions above made excerpt empty, doubhtful but we want to be 100% sure.
    if (empty($desc_no_html)) {
        $desc_no_html = $post->post_content;
        // Start over, this time with the post_content
        $desc_no_html = strip_shortcodes($desc_no_html);
        // Strip shortcodes first in case there is HTML inside the shortcode
        $desc_no_html = str_replace(']]>', ']]>', $desc_no_html);
        // Angelo Recommendation, if for some reason ]]> happens to be in the_content, rare but We've seen it happen
        $desc_no_html = wp_strip_all_tags($desc_no_html);
        $excerpt_length = apply_filters('excerpt_length', 55);
        $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
        $desc_no_html = wp_trim_words($desc_no_html, $excerpt_length, $excerpt_more);
        $desc_no_html = trim($desc_no_html);
        // Trim the final string, we may have stripped everything out of the post so this will make the value empty if that's the case
    }
    $desc_no_html = str_replace(array("\r\n", "\r", "\n"), ' ', $desc_no_html);
    // I take it Facebook doesn't like new lines?
    return $desc_no_html;
}
function sm_blockquotes_insert($atts, $content = null)
{
    $atts = shortcode_atts(array('cite' => 'Citation', 'type' => 'left', 'content' => !empty($content) ? $content : 'Content Goes Here'), $atts);
    extract($atts);
    $shape = '';
    $cite = wp_strip_all_tags($cite);
    $content = wp_strip_all_tags($content);
    /*
     * Blockquotes
     */
    if (strtolower($type) == 'left') {
        $shape .= "<div class = 'sm_blockquote left_text'> {$content} ";
        $shape .= "<cite class = 'sm_blockquote_cite' >- {$cite}</cite></div>";
        return $shape;
    }
    if (strtolower($type) == 'center') {
        $shape .= "<div class = 'sm_blockquote center_text'> {$content} ";
        $shape .= "<cite class = 'sm_blockquote_cite' >- {$cite}</cite></div>";
        return $shape;
    }
    if (strtolower($type) == 'right') {
        $shape .= "<div class = 'sm_blockquote right_text'> {$content} ";
        $shape .= "<cite class = 'sm_blockquote_cite' >- {$cite}</cite></div>";
        return $shape;
    }
}
Beispiel #4
0
/**
 * Smart Excerpt
 *
 * Returns an excerpt which is not longer than the given length and always
 * ends with a complete sentence. If first sentence is longer than length,
 * it will add the standard ellipsis… Length is the number of characters.
 *
 * Usage: <?php smart_excerpt(450); >
 *
 * http://www.distractedbysquirrels.com/blog/wordpress-improved-dynamic-excerpt
 */
function smart_excerpt($length, $postId = false)
{
    if ($postId) {
        $post = get_post($postId);
        $text = $post->post_excerpt;
    } else {
        global $post;
        $text = $post->post_excerpt;
    }
    if ('' == $text) {
        if ($postId) {
            $text = $post->post_content;
        } else {
            $text = get_the_content('');
        }
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]>', $text);
    }
    $text = strip_shortcodes($text);
    $text = wp_strip_all_tags($text, true);
    if (empty($length)) {
        $length = 300;
    }
    $text = substr($text, 0, $length);
    $excerpt = nucleus_reverse_strrchr($text, '.', 1);
    if ($excerpt) {
        echo apply_filters('the_excerpt', $excerpt);
    } else {
        echo apply_filters('the_excerpt', $text . '…');
    }
}
Beispiel #5
0
 /**
  * Change the comment form defaults.
  *
  * @since  1.0.
  *
  * @param  array    $defaults    The default values.
  * @return array                 The modified defaults.
  */
 function oxford_comment_form_defaults($defaults)
 {
     $input_size = 22;
     // Comment form title
     $defaults['title_reply'] = __('Leave a comment', 'oxford');
     // Comment form notes
     $defaults['comment_notes_before'] = '';
     $defaults['comment_notes_after'] = '';
     // Comment Author
     $comment_author = isset($_POST['author']) ? wp_strip_all_tags($_POST['author'], true) : null;
     $author_field = sprintf('<p class="comment-form-author"><input class="text-input respond-type" type="text" name="%1$s" id="%1$s" value="%3$s" size="%4$d" aria-required="true" tabindex="%5$d" placeholder="%2$s" /></p>', 'author', esc_attr_x('Name', 'comment field placeholder', 'oxford'), esc_attr($comment_author), $input_size, 1);
     // Comment Author Email
     $comment_author_email = isset($_POST['email']) ? trim($_POST['email']) : null;
     $email_field = sprintf('<p class="comment-form-email"><input class="text-input respond-type" type="email" name="%1$s" id="%1$s" value="%3$s" size="%4$d" aria-required="true" tabindex="%5$d" placeholder="%2$s" /></p>', 'email', esc_attr_x('Email', 'comment field placeholder', 'oxford'), esc_attr($comment_author_email), $input_size, 2);
     // Comment Author URL
     $comment_author_url = isset($_POST['url']) ? trim($_POST['url']) : null;
     $url_field = sprintf('<p class="comment-form-url"><input class="text-input respond-type" type="url" name="%1$s" id="%1$s" value="%3$s" size="%4$d" tabindex="%5$d" placeholder="%2$s" /></p>', 'url', esc_attr_x('Website', 'comment field placeholder', 'oxford'), esc_attr($comment_author_url), $input_size, 3);
     // Set the fields in the $defaults array
     $defaults['fields'] = array('author' => $author_field, 'email' => $email_field, 'url' => $url_field);
     // Comment Form
     $defaults['comment_field'] = sprintf('<p class="comment-form-comment"><textarea id="comment" class="blog-textarea respond-type" name="comment" cols="58" rows="10" aria-required="true" tabindex="4" placeholder="%s"></textarea></p>', esc_attr_x('Type reply here&hellip;', 'comment field placeholder', 'oxford'));
     // Submit label
     $defaults['label_submit'] = __('Post comment', 'oxford');
     return $defaults;
 }
Beispiel #6
0
 /**
  * Truncates a string to be shorter than or equal to the length specified
  * Attempts to truncate on word boundaries
  *
  * @param string $string
  * @param int $length
  * @return string
  */
 function crop_str($string, $length = 256)
 {
     $string = wp_strip_all_tags((string) $string, true);
     // true: collapse Linear Whitespace into " "
     $length = absint($length);
     if (mb_strlen($string, 'UTF-8') <= $length) {
         return $string;
     }
     // @see wp_trim_words()
     if ('characters' == _x('words', 'word count: words or characters?', 'jetpack')) {
         return trim(mb_substr($string, 0, $length - 1, 'UTF-8')) . "…";
         // ellipsis
     }
     $words = explode(' ', $string);
     $return = '';
     while (strlen($word = array_shift($words))) {
         $new_return = $return ? "{$return} {$word}" : $word;
         $new_return_length = mb_strlen($new_return, 'UTF-8');
         if ($new_return_length < $length - 1) {
             $return = $new_return;
             continue;
         } elseif ($new_return_length == $length - 1) {
             $return = $new_return;
             break;
         }
         if (!$return) {
             $return = mb_substr($new_return, 0, $length - 1, 'UTF-8');
         }
         break;
     }
     return "{$return}…";
     // ellipsis
 }
function ty_save_post_data()
{
    if (empty($_POST) || !wp_verify_nonce($_POST['name_of_nonce_field'], 'name_of_my_action')) {
        print 'Sorry, your nonce did not verify.';
        exit;
    } else {
        // Do some minor form validation to make sure there is content
        if (isset($_POST['title'])) {
            $title = $_POST['title'];
        } else {
            echo 'Please enter a title';
            exit;
        }
        if (isset($_POST['description'])) {
            $description = $_POST['description'];
        } else {
            echo 'Please enter the content';
            exit;
        }
        if (isset($_POST['post_tags'])) {
            $tags = $_POST['post_tags'];
        } else {
            $tags = "";
        }
        // Add the content of the form to $post as an array
        $post = array('post_title' => wp_strip_all_tags($title), 'post_content' => $description, 'post_category' => $_POST['cat'], 'tags_input' => $tags, 'post_status' => 'publish', 'post_type' => $_POST['post-type']);
        wp_insert_post($post);
        // http://codex.wordpress.org/Function_Reference/wp_insert_post
        $location = home_url();
        // redirect location, should be login page
        echo "<meta http-equiv='refresh' content='0;url={$location}' />";
        exit;
    }
    // end IF
}
/**
 * Serialize an entity post.
 *
 * @param array $entity The entity post or the entity post id.
 *
 * @return array mixed The entity data array.
 */
function wl_serialize_entity($entity)
{
    $entity = is_numeric($entity) ? get_post($entity) : $entity;
    $type = wl_entity_type_taxonomy_get_type($entity->ID);
    $images = wl_get_image_urls($entity->ID);
    return array('id' => wl_get_entity_uri($entity->ID), 'label' => $entity->post_title, 'description' => wp_strip_all_tags($entity->post_content), 'sameAs' => wl_schema_get_value($entity->ID, 'sameAs'), 'mainType' => str_replace('wl-', '', $type['css_class']), 'types' => wl_get_entity_rdf_types($entity->ID), 'images' => $images);
}
 function update_collection($collectionId, $collection)
 {
     global $wplr;
     $id = $wplr->get_meta("cosmothemes_gallery_id", $collectionId);
     $post = array('ID' => $id, 'post_title' => wp_strip_all_tags($collection['name']));
     wp_update_post($post);
 }
        /**
         * import function.
         *
         * @access public
         * @param array $array
         * @param array $columns
         * @return void
         */
        function import($array = array(), $columns = array('post_title'))
        {
            $this->imported = $this->skipped = 0;
            if (!is_array($array) || !sizeof($array)) {
                $this->footer();
                die;
            }
            $rows = array_chunk($array, sizeof($columns));
            foreach ($rows as $row) {
                $row = array_filter($row);
                if (empty($row)) {
                    continue;
                }
                $meta = array();
                foreach ($columns as $index => $key) {
                    $meta[$key] = sp_array_value($row, $index);
                }
                $name = sp_array_value($meta, 'post_title');
                if (!$name) {
                    $this->skipped++;
                    continue;
                }
                $args = array('post_type' => 'sp_sponsor', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags($name));
                $id = wp_insert_post($args);
                // Update URL
                update_post_meta($id, 'sp_url', sp_array_value($meta, 'sp_url'));
                $this->imported++;
            }
            // Show Result
            echo '<div class="updated settings-error below-h2"><p>
				' . sprintf(__('Import complete - imported <strong>%s</strong> sponsors and skipped <strong>%s</strong>.', 'sportspress'), $this->imported, $this->skipped) . '
			</p></div>';
            $this->import_end();
        }
Beispiel #11
0
 /**
  * Trigger the tickets email
  *
  * @param int $payment_id
  *
  * @return string
  */
 public function trigger($payment_id = 0)
 {
     global $edd_options;
     $payment_data = edd_get_payment_meta($payment_id);
     $user_id = edd_get_payment_user_id($payment_id);
     $user_info = maybe_unserialize($payment_data['user_info']);
     $email = edd_get_payment_user_email($payment_id);
     if (isset($user_id) && $user_id > 0) {
         $user_data = get_userdata($user_id);
         $name = $user_data->display_name;
     } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) {
         $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
     } else {
         $name = $email;
     }
     $message = $this->get_content_html($payment_id);
     $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
     $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
     $subject = !empty($edd_options['ticket_subject']) ? wp_strip_all_tags($edd_options['ticket_subject'], true) : $this->default_subject;
     $subject = apply_filters('edd_ticket_receipt_subject', $subject, $payment_id);
     $subject = edd_email_template_tags($subject, $payment_data, $payment_id);
     $headers = 'From: ' . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
     $headers .= 'Reply-To: ' . $from_email . "\r\n";
     $headers .= "Content-Type: text/html; charset=utf-8\r\n";
     $headers = apply_filters('edd_ticket_receipt_headers', $headers, $payment_id, $payment_data);
     // Allow add-ons to add file attachments
     $attachments = apply_filters('edd_ticket_receipt_attachments', array(), $payment_id, $payment_data);
     if (apply_filters('edd_email_ticket_receipt', true)) {
         wp_mail($email, $subject, $message, $headers, $attachments);
     }
 }
Beispiel #12
0
 /**
  * Display or return a formatted output for WP_Error object. For each error in WP_Error object a formatted
  * output is done with code error and error data.
  *
  * @brief Display ot return output
  *
  * @param bool         $echo TRUE to display or FALSE to get output
  * @param WPDKWatchDog $log  A WPDKWatchDog object to log the display
  *
  * @return string|void Formatted output if $echo is FALSE
  */
 public function display($echo = true, $log = null)
 {
     $content = '<div class="wpdk-watchdog-wp-error">';
     foreach ($this->errors as $code => $single) {
         $content .= sprintf('<code>Code: 0x%x, Description: %s</code>', $code, $single[0]);
         $error_data = $this->get_error_data($code);
         if (!empty($error_data)) {
             if (is_array($error_data)) {
                 foreach ($error_data as $key => $data) {
                     $content .= sprintf('<code>Key: %s, Data: %s</code>', $key, urldecode($data));
                 }
             } else {
                 $content .= sprintf('<code>Data: %s</code>', urldecode($error_data));
             }
         }
     }
     // log to file if enabled
     if (!is_null($log)) {
         $log->log(esc_attr(wp_strip_all_tags($content)));
     }
     $content .= '</div>';
     if ($echo) {
         echo $content;
         return true;
     }
     return $content;
 }
Beispiel #13
0
/**
 * Returns a trimmed reply content string.
 * Works for replies as well as topics.
 * Must be used while inside the loop
 */
function buddyboss_global_search_reply_intro($character_limit = 50)
{
    $content = '';
    switch (get_post_type(get_the_ID())) {
        case 'topic':
            $reply_content = bbp_get_topic_content(get_the_ID());
            break;
        case 'reply':
            $reply_content = bbp_get_reply_content(get_the_ID());
            break;
        default:
            $reply_content = get_the_content();
            break;
    }
    if ($reply_content) {
        $content = wp_strip_all_tags($reply_content, true);
        $search_term = buddyboss_global_search()->search->get_search_term();
        $search_term_position = strpos($content, $search_term);
        if ($search_term_position !== false) {
            $shortened_content = '...' . substr($content, $search_term_position, $character_limit);
            //highlight search keyword
            $shortened_content = str_replace($search_term, "<strong>" . $search_term . "</strong>", $shortened_content);
        } else {
            $shortened_content = substr($content, 0, $character_limit);
        }
        if (strlen($content) > $character_limit) {
            $shortened_content .= '...';
        }
        $content = $shortened_content;
    }
    return apply_filters('buddyboss_global_search_reply_intro', $content);
}
Beispiel #14
0
 function get_shares()
 {
     global $post;
     $perm = get_permalink($post->ID);
     $title = wp_strip_all_tags(get_the_title($post->ID));
     $thumb = has_post_thumbnail($post->ID) ? pl_the_thumbnail_url($post->ID) : '';
     $desc = wp_strip_all_tags(pl_short_excerpt($post->ID, 10, ''));
     $out = '';
     if (ploption('share_google')) {
         $out .= self::google(array('permalink' => $perm));
     }
     if (ploption('share_twitter')) {
         $out .= self::twitter(array('permalink' => $perm, 'title' => $title));
     }
     if (ploption('share_facebook')) {
         $out .= self::facebook(array('permalink' => $perm));
     }
     if (ploption('share_linkedin')) {
         $out .= self::linkedin(array('permalink' => $perm, 'title' => $title));
     }
     if (ploption('share_pinterest')) {
         $out .= self::pinterest(array('permalink' => $perm, 'image' => $thumb, 'desc' => $desc));
     }
     if (ploption('share_buffer')) {
         $out .= self::buffer(array('permalink' => $perm, 'title' => $title));
     }
     if (ploption('share_stumble')) {
         $out .= self::stumbleupon(array('permalink' => $perm, 'title' => $title));
     }
     return $out;
 }
/**
 * Caption/WP-Caption Shortcode. Based on the built in caption shortcode
 * @param  array     $attr      Array of attributes passed to shortcode.
 * @param  string    $content   The content passed to the shortcode.
 * @return string    $output    The generated content.
*/
function instant_articles_shortcode_handler_caption($attr, $content = null)
{
    // New-style shortcode with the caption inside the shortcode with the link and image tags.
    if (!isset($attr['caption'])) {
        if (preg_match('#((?:<a [^>]+>\\s*)?<img [^>]+>(?:\\s*</a>)?)(.*)#is', $content, $matches)) {
            $content = $matches[1];
            $attr['caption'] = trim($matches[2]);
        }
    }
    $atts = shortcode_atts(array('figcaptionclass' => '', 'caption' => '', 'cite' => '', 'subtitle' => ''), $attr, 'caption');
    if (!strlen(trim($atts['caption']))) {
        return '';
    }
    $output = '';
    $content = do_shortcode($content);
    $doc = new DOMDocument();
    $doc->loadHTML('<html><body>' . $content . '</body></html>');
    $imgs = $doc->getElementsByTagName('img');
    if ($imgs->length > 0) {
        $img_src = $imgs->item(0)->getAttribute('src');
        if ($img_src) {
            $alt = $imgs->item(0)->getAttribute('alt');
            $classes = array();
            $classes = trim($atts['figcaptionclass']);
            $class_attr = strlen($classes) ? ' class="' . esc_attr($classes) . '"' : '';
            $caption = wp_strip_all_tags($atts['caption'], true);
            $subtitle = strlen($atts['subtitle']) ? '<h2>' . esc_html($atts['subtitle']) . '</h2>' : '';
            $cite = strlen($atts['cite']) ? '<cite>' . esc_html($atts['cite']) . '</cite>' : '';
            $output = '<figure><img src="' . esc_url($img_src) . '" alt="' . esc_attr($alt) . '"><figcaption' . $class_attr . '><h1>' . esc_html($caption) . '</h1>' . $subtitle . $cite . '</figcaption></figure>';
        }
    }
    return $output;
}
Beispiel #16
0
function smamo_booking_form()
{
    $navn = isset($_POST['navn']) ? wp_strip_all_tags($_POST['navn']) : false;
    $email = isset($_POST['email']) ? wp_strip_all_tags($_POST['email']) : false;
    $firma = isset($_POST['firma']) ? wp_strip_all_tags($_POST['firma']) : false;
    $telefon = isset($_POST['telefon']) ? wp_strip_all_tags($_POST['telefon']) : false;
    $budget = isset($_POST['budget']) ? wp_strip_all_tags($_POST['budget']) : false;
    $about = isset($_POST['about']) ? $_POST['about'] : false;
    if (!$navn || !$email) {
        $response['error'] = 'Mangler vigtige oplysninger';
        wp_die(json_encode($response));
    }
    // Indstil about
    $about_string = '';
    $i = 0;
    if (is_array($about)) {
        foreach ($about as $a) {
            $i++;
            $about_string .= $i === 1 ? $a : ', ' . $a;
        }
    }
    if (function_exists('slack')) {
        $text = $navn . ' har lige sendt en anmodning om et møde!';
        $attachments = array(array('pretext' => '', 'color' => '#669999', 'fields' => array(array('title' => 'Navn', 'value' => $navn, 'short' => false), array('title' => 'Firma', 'value' => $firma, 'short' => false), array('title' => 'Email', 'value' => '<mailto:' . $email . '|' . $email . '>', 'short' => false), array('title' => 'Telefon', 'value' => '<tel:' . $telefon . '|' . $telefon . '>', 'short' => false), array('title' => 'Vil gerne holde møde om', 'value' => $about_string, 'short' => false), array('title' => 'Budget ca.', 'value' => $budget, 'short' => false))));
        // Send
        $response['slack_curl'] = slack($text, $attachments);
    }
    wp_die(json_encode($response));
}
Beispiel #17
0
function post_acme_article($post)
{
    //if($post['post_title']) {
    $post_data = array('post_title' => wp_strip_all_tags($post['post_title']), 'post_content' => $post['post_desc'], 'tax_input' => array('article_country_cat' => $post['post_country'], 'article_cat' => $post['post_category']), 'post_status' => $post['save'] != '' ? 'draft' : 'publish', 'post_type' => $post['custom_post_type'], 'post_author' => get_current_user_id());
    $post_id = wp_insert_post($post_data);
    // add_post_meta( $post_id, '_custom_image_link', $post['paste_featured_img'], true );
    if (!empty($_FILES['post_featured_img']['name'])) {
        $uploaddir = wp_upload_dir();
        $file = $_FILES["post_featured_img"]["name"];
        $uploadfile = $uploaddir['path'] . '/' . basename($file);
        move_uploaded_file($file, $uploadfile);
        $filename = basename($uploadfile);
        $wp_filetype = wp_check_filetype(basename($filename), null);
        $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', $filename), 'post_content' => '', 'post_status' => 'inherit');
        foreach ($_FILES as $file => $value) {
            require_once ABSPATH . "wp-admin" . '/includes/image.php';
            require_once ABSPATH . "wp-admin" . '/includes/file.php';
            require_once ABSPATH . "wp-admin" . '/includes/media.php';
            $attach_id = media_handle_upload($file, $post_id);
            set_post_thumbnail($post_id, $attach_id);
            update_post_meta($post_id, '_thumbnail_id', $attach_id);
        }
        $image_url = wp_get_attachment_url(get_post_thumbnail_id($post_id));
    } else {
        $image_url = '';
    }
    $result = array('status' => 'success', 'post_id' => $post_id, 'image_url' => $image_url, 'featured_img' => $image_url, 'msg' => 'Post Save.');
    // }
    // }  else {
    //   $result = array( 'status' => 'error', 'post_id' => $post_id, 'image_url' => $image_url, 'featured_img' => $image_url, 'msg' => 'Please fill-up the required fields.');
    // }
    return $result;
}
function smamo_filter_image()
{
    $response = array();
    // Masser af logik om filstier mv.
    // Hvis du kigger for længe på det, brænder dine øjne ud af hovedet, så pas på!
    // Vi skal dybest set bare bruge filens navn og dens placering og den slags.
    // Vi skal kunne skifte mellem basedir og baseurl, fordi det er vigtigt.
    // huskeregel: "baseurl" er en sti på internettet, "basedir" er en sti lokalt på serveren
    // Dvs. "baseurl til javascript", "basedir" til PHP
    /* SWEET HEAVENS, HERE GOES */
    $upload_dir = wp_upload_dir();
    $imgPath = wp_strip_all_tags($_POST['img']);
    $file = explode('?', basename($imgPath));
    $file = $file[0];
    $imgPath = str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $imgPath);
    if (file_exists($upload_dir['basedir'] . '/filtered/' . $file)) {
        $response['img'] = $upload_dir['baseurl'] . '/filtered/' . $file;
        $response['exist'] = true;
    } else {
        require_once get_template_directory() . '/PHPImageWorkshop/ImageWorkshop.php';
        /* OPRET BILLEDE FRA FIL */
        $image = ImageWorkshop::initFromPath($imgPath);
        /* KLON, FILTRER, LÆG OVENPÅ */
        $gray = clone $image;
        $gray->applyFilter(IMG_FILTER_CONTRAST, -35, null, null, null, true);
        // Kontrast
        $gray->applyFilter(IMG_FILTER_GRAYSCALE);
        // Gråtone
        $gray->applyFilter(IMG_FILTER_COLORIZE, 0, 43, 127, 80);
        // Kolorisering, cirka blålig
        $gray->opacity(40);
        // Gennemsigtighed
        $image->addLayerOnTop($gray, 0, 0, "LT");
        // Læg ovenpå original
        /* TILFØJ RIDSER */
        // Først skal vi vælge en ridse, baseret på billedets størrelse
        $imageWidth = $image->getWidth();
        $gunk = 'noise-4.png';
        if ($imageWidth > 800) {
            $gunk = 'noise-1.png';
        }
        if ($imageWidth > 600) {
            $gunk = 'noise-3.png';
        }
        if ($imageWidth > 400) {
            $gunk = 'noise-2.png';
        }
        $noise = ImageWorkshop::initFromPath($upload_dir['basedir'] . '/filtered/colors/' . $gunk);
        // Så bestemmer vi tilfældigt hvor ridsen placeres
        $filterpos = array('LT', 'RT', 'LB', 'RB');
        $pos = $filterpos[array_rand($filterpos)];
        // Og lægger ovenpå
        $image->addLayerOnTop($noise, 0, 0, $pos);
        /* GEM BILLEDE, TILFØJ STI TIL RESPONSE */
        $image->save($upload_dir['basedir'] . '/filtered/', $file, true, null, 100);
        $response['img'] = $upload_dir['baseurl'] . '/filtered/' . $file;
        $response['exist'] = false;
    }
    wp_die(json_encode($response));
}
 /**
  * Removes potentially harmful tags from user input and makes sure the entered value is what it is supposed to be.
  *
  * @var array $items The items to be validated
  * @return array An updated array of items.
  **/
 public function validate($items)
 {
     if (is_array($items)) {
         foreach ($items as $key => $item) {
             if (!is_array($item)) {
                 $items[$key] = $item;
             } elseif ($item['val'] == '') {
                 $items[$key] = $item['val'];
             } else {
                 switch ($item['type']) {
                     case 'int':
                         $items[$key] = intval($item['val']);
                         break;
                     case 'bool':
                         $items[$key] = (bool) $item['val'];
                         break;
                     case 'text':
                         $items[$key] = stripslashes(wp_strip_all_tags($item['val']));
                         break;
                     case 'roles':
                     case 'multicheckbox':
                         unset($items[$key]);
                         foreach ($item['val'] as $subitem_key => $subitem) {
                             $items[$key][$subitem_key] = (bool) $subitem;
                         }
                         break;
                     default:
                         $items[$key] = stripslashes($item['val']);
                         break;
                 }
             }
         }
     }
     return $items;
 }
Beispiel #20
0
function sm_alert_insert($atts, $content = null)
{
    $atts = shortcode_atts(array('title' => 'Title Goes Here', 'type' => 'round', 'color' => 'red', 'order' => '1', 'text' => 'Click Here', 'content' => !empty($content) ? $content : 'Content Goes Here'), $atts);
    extract($atts);
    $shape = '';
    $content = wp_strip_all_tags($content);
    /*
     * Alerts Check
     */
    if (strtolower($type) == 'alerts' && strtolower($color) == 'red') {
        $shape .= "<p class='sm_alerts sm_color1'> {$content} </p>";
        return $shape;
    }
    if (strtolower($type) == 'alerts' && strtolower($color) == 'green') {
        $shape .= "<p class='sm_alerts sm_color2'> {$content} </p>";
        return $shape;
    }
    if (strtolower($type) == 'alerts' && strtolower($color) == 'purple') {
        $shape .= "<p class='sm_alerts sm_color3'> {$content} </p>";
        return $shape;
    }
    if (strtolower($type) == 'alerts' && strtolower($color) == 'blue') {
        $shape .= "<p class='sm_alerts sm_color4'> {$content} </p>";
        return $shape;
    }
    if (strtolower($type) == 'alerts' && strtolower($color) == 'yellow') {
        $shape .= "<p class='sm_alerts sm_color5'> {$content} </p>";
        return $shape;
    }
}
Beispiel #21
0
 /**
  * Get info about the fonts available in the current kit
  *
  * @param  string        $kit_id    The id of the kit.
  * @param  bool          $force     True to ignore cached info.
  * @return array|bool               An array of font information, or false if the kit ID is invalid.
  */
 function glyphs_get_typekit_fonts($kit_id = null, $force = false)
 {
     if (null === $kit_id) {
         $kit_id = get_theme_mod('typekit-id', false);
     }
     if (!$kit_id) {
         return false;
     }
     // Get cached font info
     $fonts = get_transient('glyphs-typekit-fonts');
     if (empty($fonts) || true === $force) {
         $fonts = array();
         // Look up the font kit
         $response = wp_remote_get('https://typekit.com/api/v1/json/kits/' . $kit_id . '/published');
         $response_code = wp_remote_retrieve_response_code($response);
         $response_body = json_decode(wp_remote_retrieve_body($response));
         // If the font kit returns a valid response, parse the font info
         if (200 === (int) $response_code && is_object($response_body) && isset($response_body->kit) && isset($response_body->kit->families) && is_array($response_body->kit->families)) {
             foreach ($response_body->kit->families as $family) {
                 $fonts[sanitize_title_with_dashes($family->slug)] = array('label' => wp_strip_all_tags($family->name), 'stack' => isset($family->css_stack) ? wp_strip_all_tags($family->css_stack) : '');
             }
         }
         // Cache the font info
         set_transient('glyphs-typekit-fonts', $fonts, DAY_IN_SECONDS);
     }
     return $fonts;
 }
 function awp_sanitize_data($input)
 {
     if (!isset($input['stylesheet_load']) || $input['stylesheet_load'] != '1') {
         $input['stylesheet_load'] = 0;
     } else {
         $input['stylesheet_load'] = 1;
     }
     // check to make sure the fields are not empty - if they are - fill with defaults
     if (empty($input['singular_name'])) {
         $input['singular_name'] = 'Community';
     }
     if (empty($input['plural_name'])) {
         $input['plural_name'] = 'Communities';
     }
     if (empty($input['slug'])) {
         $input['slug'] = 'communities';
     }
     if (empty($input['num_posts']) || !is_numeric($input['num_posts'])) {
         $input['num_posts'] = '8';
     }
     //if ( $input['order_by'] =='rand')  $input['num_posts'] = '999';
     // sanitize the fields
     $input['singular_name'] = wp_strip_all_tags($input['singular_name']);
     $input['plural_name'] = wp_strip_all_tags($input['plural_name']);
     $input['slug'] = sanitize_title($input['slug']);
     return $input;
 }
Beispiel #23
0
 private static function insertSamplePost($args = [])
 {
     $faker = FakerFactory::create();
     $defaults = array('post_title' => wp_strip_all_tags($faker->text(32)), 'post_content' => $faker->text, 'post_status' => 'publish', 'post_author' => 1);
     $args = wp_parse_args($args, $defaults);
     return wp_insert_post($args, true);
 }
function sp_opt_do_action()
{
    if (!isset($_REQUEST['sp_action'])) {
        return;
    }
    //no action requested
    if (!current_user_can('manage_options')) {
        wp_die('Insufficient privileges!');
    }
    //check user permissions
    $sp_target = $_REQUEST['sp-target'];
    //Request Link Target
    $sp_style = $_REQUEST['sp-style'];
    //Request List Style
    $sp_custom = $_REQUEST['sp-custom'];
    //Request Custom CSS
    $sp_display = $_REQUEST['sp-display'];
    //Request Custom CSS
    $action = $_REQUEST['sp-action'];
    //Reuest Action
    update_option('sp-display', $sp_display);
    //Update db option display
    update_option('sp-target', $sp_target);
    //Update db option target
    update_option('sp-style', $sp_style);
    //Update db option style
    update_option('sp-custom', wp_strip_all_tags($sp_custom));
    //update db option custom
    if ($action == 'update') {
        add_action('admin_notices', 'sp_opt_message');
        return;
    }
    //Confirmation of update notification
}
function insert_contact_info()
{
    //get the five variables
    //prepare variables
    //wp_strip_all_tags will remove spaces and illegal characters
    $fname = wp_strip_all_tags($_POST['fname']);
    $lname = wp_strip_all_tags($_POST['lname']);
    $email = wp_strip_all_tags($_POST['email']);
    $phone = trim($_POST['phone']);
    // two parameters of any name of the filter and what you want to filter
    //define the filter
    $message = wp_strip_all_tags($_POST['message']);
    $fullname = $lname . ' ' . $fname;
    // Create post object
    $contact_post = array('post_title' => $fullname, 'post_status' => 'publish', 'post_type' => 'contact');
    // Insert the post into the wp_post table and get the id
    $post_id = wp_insert_post($contact_post);
    //Insert into the postmeta table
    add_post_meta($post_id, 'first_name', $fname);
    add_post_meta($post_id, 'last_name', $lname);
    add_post_meta($post_id, 'email', $email);
    add_post_meta($post_id, 'telephone', $phone);
    $message = apply_filters('clean_message', $message);
    add_post_meta($post_id, 'message', $message);
}
function smamo_instagram()
{
    // Klargør svar
    $response = array();
    $num = isset($_POST['num']) ? 4 * wp_strip_all_tags($_POST['num']) : 4;
    // vi skal bruge et hashtag, ellers die();
    if (!isset($_POST['hash'])) {
        $response['code'] = '400';
        $response['error'] = 'No hashtag received';
        wp_die(json_encode($response));
    }
    // Indstil $tag
    $tag = wp_strip_all_tags($_POST['hash']);
    // Inkluder instagram class
    require get_template_directory() . '/functions/instagram/instagram.class.php';
    // Opret ny instance
    $instagram = new Instagram(array('apiKey' => 'dd36cc7a7be445c8a00d9f383e49f8c8', 'apiSecret' => 'e750735ffba74f8a8ed753a33c7351da', 'apiCallback' => 'http://faaborg-gym.dk'));
    $response['images'] = array();
    $inst_obj = $instagram->getTagMedia($tag, $num);
    $next_page = $instagram->pagination($inst_obj);
    $response['next'] = $next_page;
    foreach ($inst_obj->data as $key => $val) {
        $response['images'][] = $val;
    }
    wp_die(json_encode($response));
}
 /**
  * removes all tags when setting
  * @param string $value_inputted_for_field_on_model_object
  * @return string
  */
 function prepare_for_set($value_inputted_for_field_on_model_object)
 {
     if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
         $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
     }
     return strtoupper(wp_strip_all_tags($value_inputted_for_field_on_model_object));
 }
 /**
  * Pre-process footnote shortcode
  *
  * @param array   $atts
  * @param string  $content
  *
  * @return string
  */
 function shortcodeHandler($atts, $content = '')
 {
     global $id;
     $a = shortcode_atts(array('numbered' => 'yes', 'symbol' => '*', 'suptext' => ' '), $atts);
     if (!$content) {
         return '';
     }
     if (!isset($this->footnotes[$id])) {
         $this->footnotes[$id] = array();
         if ($a['numbered'] == 'no') {
             $this->numbered[$id] = false;
         } else {
             $this->numbered[$id] = true;
         }
     }
     $this->footnotes[$id][] = $content;
     $footnotes = $this->footnotes[$id];
     $num = count($footnotes);
     $numlabel = "{$id}-{$num}";
     $retval = '<a class="footnote" title="' . \PressBooks\Sanitize\sanitize_xml_attribute(wp_strip_all_tags($content)) . '" id="return-footnote-' . $numlabel . '" href="#footnote-' . $numlabel . '"><sup class="footnote">[';
     if ($this->numbered[$id]) {
         $retval .= $num;
     } else {
         $retval .= $a['symbol'];
     }
     if (trim($a['suptext'])) {
         if ($this->numbered[$id]) {
             $retval .= '. ';
         }
         $retval .= $a['suptext'];
     }
     $retval .= ']</sup></a>';
     return $retval;
 }
Beispiel #29
0
 public static function process($data, $params)
 {
     if (isset($_GET['pal'])) {
         echo '<br /><br /><i><b>File</b> ' . __FILE__ . ' <b>Line</b> ' . __LINE__ . "</i><br />\n";
         echo '<pre>';
         echo 'Params: ';
         print_r($params);
         echo 'Data: ';
         print_r($data);
         echo '</pre>';
     }
     $res = new stdClass();
     $res->slug = '';
     if ($data->text == '') {
         return $res;
     }
     $slug = $data->text;
     $slug = self::replace_chars($slug, $params);
     if (isset($_GET['pslug'])) {
         echo '<br /><br /><i><b>File</b> ' . __FILE__ . ' <b>Line</b> ' . __LINE__ . "</i><br />\n";
         echo 'Alias: ' . $slug . '<br />';
     }
     $slug = wp_strip_all_tags($slug);
     /*$slug = preg_replace( '/[^a-zA-Z0-9\-\s]/', '', $slug );
     		$slug = preg_replace( '/\s+/', '-', $slug );
     		$slug = preg_replace( '/\-+/', '-', trim( $slug ) );*/
     $slug = sanitize_title($slug);
     $slug = strtolower($slug);
     if (isset($_GET['pslug'])) {
         echo '<br /><br /><i><b>File</b> ' . __FILE__ . ' <b>Line</b> ' . __LINE__ . "</i><br />\n";
         echo 'Alias: ' . $slug . '<br />';
     }
     $res->slug = $slug;
     return $res;
 }
function ajax_contact_form()
{
    $response = array();
    $navn = isset($_POST['navn']) ? wp_strip_all_tags($_POST['navn']) : false;
    $email = isset($_POST['email']) ? wp_strip_all_tags($_POST['email']) : false;
    $firma = isset($_POST['firma']) ? wp_strip_all_tags($_POST['firma']) : false;
    $telefon = isset($_POST['telefon']) ? wp_strip_all_tags($_POST['telefon']) : false;
    $about = isset($_POST['about']) ? wp_strip_all_tags($_POST['about']) : false;
    $kommentar = isset($_POST['kommentar']) ? esc_textarea($_POST['kommentar']) : false;
    if (!$navn) {
        $response['error'] = 'Indtast et navn';
    } else {
        if (!$email) {
            $response['error'] = 'Indtast en email';
        }
    }
    if (!isset($response['error'])) {
        $post_vars = array('post_title' => $navn . ' [' . $email . ']', 'post_status' => 'publish', 'post_type' => 'form');
        $response['post_id'] = wp_insert_post($post_vars, true);
        if (is_wp_error($response['post_id'])) {
            $response['error'] = $return->get_error_message();
        }
    }
    if (!isset($response['error'])) {
        update_post_meta($response['post_id'], 'form_navn', $navn);
        update_post_meta($response['post_id'], 'form_email', $email);
        update_post_meta($response['post_id'], 'form_firma', $firma);
        update_post_meta($response['post_id'], 'form_telefon', $telefon);
        update_post_meta($response['post_id'], 'form_about', $about);
        update_post_meta($response['post_id'], 'form_kommentar', $kommentar);
        $response['success'] = '<article><h2>Tak for din henvendelse</h2><p>Vi vil besvare den hurtigst muligt.</p><article>';
        sendEmail(get_theme_mod('info_name'), get_theme_mod('info_email'), get_theme_mod('info_email'), 'Ny henvendelse fra ' . $navn, $kommentar);
    }
    wp_die(json_encode($response));
}