function wiziapp_do_content_get_post_headers()
{
    global $post, $wp_query;
    if (isset($wp_query->posts[$wp_query->current_post + 1])) {
        $nextPost = $wp_query->posts[$wp_query->current_post + 1];
        $nextURL = wiziapp_buildPostLink($nextPost->ID);
    }
    if (isset($wp_query->posts[$wp_query->current_post - 1])) {
        $prevPost = $wp_query->posts[$wp_query->current_post - 1];
        $prevURL = wiziapp_buildPostLink($prevPost->ID);
    }
    $authorId = $post->post_author;
    $authorInfo = get_userdata($authorId);
    $authorName = $authorInfo->display_name;
    if (strlen($authorName) > 15) {
        $authorName = substr($authorName, 0, 12) . '...';
    }
    $totalComments = $post->comment_count;
    $postDate = wiziapp_formatDate(strip_tags($post->post_date));
    //$meta = "nextURL={$nextURL}&prevURL={$prevURL}&postID={$post->ID}&numOfComments={$totalComments}&author={$authorName}&newCommentURL=".wiziapp_buildPostNewCommentLink($post->ID);
    $limitSize = WiziappConfig::getInstance()->getImageSize('limit_post_thumb');
    $size = WiziappConfig::getInstance()->getImageSize('posts_thumb');
    $imageURL = wiziapp_getPostThumbnail($post, $size, $limitSize, FALSE);
    $c = new WiziappPostDescriptionCellItem('L1', array(), FALSE);
    $default_class = $c->getDefaultClass();
    $showCommentsIcon = TRUE;
    if ($totalComments == 0 && 'open' != $post->comment_status) {
        $showCommentsIcon = FALSE;
    } else {
        // Might be turned off due to the theme settings
        if (isset($c->themeRemoveAttr)) {
            if (in_array('numOfComments', $c->themeRemoveAttr)) {
                $showCommentsIcon = FALSE;
            }
        }
    }
    $header = array("layout" => "L0", "class" => "{$default_class}", "nextURL" => "{$nextURL}", "prevURL" => "{$prevURL}", "postID" => $post->ID, "title" => strip_tags($post->post_title), 'screenTitle' => WiziappConfig::getInstance()->app_name, "imageURL" => $imageURL, "canComment" => 'open' == $post->comment_status, "showCommentsIcon" => $showCommentsIcon);
    if (isset($c->themeRemoveAttr)) {
        if (!in_array('author', $c->themeRemoveAttr)) {
            $header['author'] = "{$authorName}";
        }
        if (!in_array('date', $c->themeRemoveAttr)) {
            $header['date'] = "{$postDate}";
        }
        if (!in_array('numOfComments', $c->themeRemoveAttr)) {
            $header['numOfComments'] = $totalComments;
        }
    }
    return $header;
}
 /**
  * Handle the links converting, will convert images and post links according to
  * the app protocol.
  *     
  * @param array $matches the array returned from preg_replace_callback
  * @return string the link found after converting to the app format
  */
 function _handle_links_converting($matches)
 {
     $link = $matches[0];
     $url = $matches[2];
     $post_id = url_to_postid($url);
     if ($post_id) {
         $newUrl = wiziapp_buildPostLink($post_id);
         $link = str_replace($url, $newUrl, $link);
     } else {
         // If it is an image, convert to open image
         if (strpos($url, '.png') !== FALSE || strpos($url, '.gif') !== FALSE || strpos($url, '.jpg') !== FALSE || strpos($url, '.jpeg') !== FALSE) {
             $newUrl = wiziapp_buildLinkToImage($url);
             $partLink = substr($link, 0, strpos($link, '>'));
             $secondPartLink = substr($link, strpos($link, '>'));
             $link = str_replace($url, $newUrl, $partLink) . $secondPartLink;
         }
     }
     return $link;
 }
 /**
  * Attribute getter method
  * 
  * @return the actionURL of the component
  */
 function get_actionURL_attr()
 {
     $post_id = $this->data[0];
     return wiziapp_buildPostLink($post_id);
 }
 /**
  * Attribute getter method
  * 
  * @return the relatedPostsURL of the component
  */
 function get_relatedPostsURL_attr()
 {
     $url = '';
     if (!empty($this->image->relatedPost)) {
         $url = wiziapp_buildPostLink($this->image->relatedPost);
     }
     if (empty($url)) {
         // Try to get a page link
         $GLOBALS['WiziappLog']->write('info', "The image is: " . print_r($this->image, TRUE), 'imageGalleryCellItem.get_relatedPostsURL_attr');
         $url = wiziapp_buildPageLink($this->image->relatedPost);
     }
     $GLOBALS['WiziappLog']->write('info', "The url for the related posts is: {$url}", 'imageGalleryCellItem.get_relatedPostsURL_attr');
     return $url;
 }
Example #5
0
/**
* Web service that allows the application to add a comment to another comment or a post
* if the application is sending the cms user id, the web service will connect the comment 
* to the right user, to get the user ID see the WebServices::logic method
* the webservice response is in JSON format and includes the usual header,
* plus a message indicating if the comment entered a moderation queue or submitted successfully
* the application should show the returning message to the user
* 
* @param array $request the array containing the request
*/
function wiziapp_add_comment($request)
{
    @header('Content-Type: application/json');
    $name = $_POST['name'];
    $email = $_POST['email'];
    $content = $_POST['content'];
    $user_id = $_POST['cms_user_id'];
    $post_id = $_POST['post_id'];
    $comment_id = $_POST['comment_id'];
    if (empty($comment_id)) {
        $comment_id = 0;
    }
    $appToken = $_SERVER['HTTP_APPLICATION'];
    $udid = $_SERVER['HTTP_UDID'];
    //$GLOBALS['WiziappLog']->write('info', 'The server vars are '.print_r($_SERVER, true), 'remote');
    //$GLOBALS['WiziappLog']->write('info', 'The post vars are '.print_r($_POST, true), 'remote');
    // if the request doesn't contain all that we need - leave
    if (!empty($appToken) && !empty($udid) && !empty($content) && !empty($post_id)) {
        //is_wp_error
        $result = array();
        $commentData = array('comment_post_ID' => $post_id, 'comment_content' => $content, 'comment_author' => $name, 'comment_author_email' => $email, 'comment_parent' => $comment_id);
        if (!empty($user_id)) {
            $commentData['user_ID'] = $user_id;
            $user = get_userdata($user_id);
            $commentData['comment_author_email'] = $user->user_email;
        }
        if (!empty($_POST['parent_id'])) {
            $commentData['comment_parent'] = $_POST['parent_id'];
        }
        $header = array('action' => 'add_comment');
        $result = array();
        /** 
         * Wordpress will kill the script if the comment is a duplicated... 
         * so we better perform this check before moving to wordpress
         */
        $dup = wiziapp_simulate_wp_dup_check($commentData);
        if (!$dup) {
            $comment_id = wp_new_comment($commentData);
            // Check the comment status
            $comment = get_comment($comment_id);
            $moderated = TRUE;
            $message = '';
            if ($comment->comment_approved == 1) {
                $moderated = FALSE;
                $message = __('The comment was submitted successfully', 'wiziapp');
            } else {
                $message = __('The comment entered the moderation queue', 'wiziapp');
            }
            $result = array("comment" => array("commentsURL" => wiziapp_buildPostCommentsLink($post_id), "postURL" => wiziapp_buildPostLink($post_id), "message" => $message));
            $status = TRUE;
            $header['message'] = '';
            $header['code'] = 200;
        } else {
            $status = FALSE;
            $result = array('message' => __('Duplicate comment detected; it looks as though you have already said that!', 'wiziapp'));
            $header['message'] = __('Duplicate comment detected;', 'wiziapp');
            $header['code'] = 5001;
        }
        $header['status'] = $status;
        echo json_encode(array_merge(array('header' => $header), $result));
        exit;
    } else {
        $GLOBALS['WiziappLog']->write('error', "Something in the request was missing: !empty({$appToken}) && !empty({$udid}) && !empty({$content}) && !empty({$post_id})", "remote");
    }
}
Example #6
0
<?php

wiziapp_get_header();
// Before handing the content, make sure this post is scanned
$processed = get_post_meta($post->ID, 'wiziapp_processed');
if (empty($processed)) {
    wiziapp_save_post($post);
}
?>
        <div class="page_content">
            <div class="post">
                <?php 
$pLink = wiziapp_buildPostLink($post->ID);
?>
                <h2 class="pageitem">
                    <a id="post_title" href="<?php 
echo $pLink;
?>
" rel="bookmark" title="<?php 
the_title();
?>
">
                        <?php 
the_title();
?>
                    </a>
                </h2>
                <div class="pageitem">
                    <div class="single-post-meta-top">
                        <div id="author_and_date"><span class="postDescriptionCellItem_author">By
                            <a href="<?php 
function wiziapp_getPostNavigation($post_id)
{
    /**
     * Navigation template tags works inside templates,
     * but since we could really use the great work 
     * wordpress team made there we should fake the
     * loop so we can reuse the code. It will require manually
     * settings the is_single attribute of the global wp_query 
     * to true, so wordpress will think there is a point in showing
     * the navigation links...
     */
    global $post, $wp_query;
    $wp_query->is_single = TRUE;
    $post = get_post($post_id);
    setup_postdata($post);
    $nav = array();
    $navLinks = array();
    // Get the prev/next posts links
    $prevPost = get_adjacent_post(FALSE, '', TRUE);
    if ($prevPost) {
        $navLinks[] = array("link" => array("text" => wiziapp_formatComponentText(str_replace('&amp;', '&', $prevPost->post_title), __("Previous Post")), "image" => wiziapp_getPrevPostImage(), "link" => wiziapp_buildPostLink($prevPost->ID)));
    }
    $nextPost = get_adjacent_post(FALSE, '', FALSE);
    if ($nextPost) {
        $navLinks[] = array("link" => array("text" => wiziapp_formatComponentText(str_replace('&amp;', '&', $nextPost->post_title), __("Next Post")), "image" => wiziapp_getNextPostImage(), "link" => wiziapp_buildPostLink($nextPost->ID)));
    }
    $nav = array("navigation" => array("links" => $navLinks));
    return wiziapp_specialComponent("navigation", $nav);
}