if (!empty($_POST['shortname']) && !empty($_POST['name']) && !empty($_POST['desc']) && !empty($_POST['price'])) {
    $shortname = $_POST['shortname'];
    $name = $_POST['name'];
    $desc = $_POST['desc'];
    $price = $_POST['price'];
    $temparray = array('shortname' => $shortname, 'name' => $name, 'desc' => $desc, 'price' => $price);
    if (!in_array($temparray, $_SESSION['CartElements'])) {
        array_push($_SESSION['CartElements'], $temparray);
    }
    echo json_encode($_SESSION['CartElements']);
}
// remove element
if (isset($_POST['remove']) && !empty($_POST['remove'])) {
    $remove = $_POST['remove'];
    $sendarray = $_SESSION['CartElements'];
    removeElementWithValue($sendarray, 'shortname', $remove);
}
function removeElementWithValue($array, $key, $value)
{
    foreach ($array as $subKey => $subArray) {
        if ($subArray[$key] == $value) {
            unset($array[$subKey]);
        }
    }
    $_SESSION['CartElements'] = array_values($array);
    $sendarray = $_SESSION['CartElements'];
    echo json_encode($sendarray);
}
// empty array
if (isset($_POST['empty']) && !empty($_POST['empty'])) {
    $_SESSION['CartElements'] = array();
Example #2
0
function launch_campaign_query($q)
{
    if (MAD_CACHE_CAMPAIGN_QUERIES) {
        $cache_result = get_cache($q);
        if ($cache_result) {
            return $cache_result;
        }
    }
    global $maindb;
    $campaignarray = array();
    $usrres = mysql_query($q, $maindb);
    while ($campaign_detail = mysql_fetch_array($usrres)) {
        $add = array('campaign_id' => $campaign_detail['campaign_id'], 'priority' => $campaign_detail['campaign_priority'], 'type' => $campaign_detail['campaign_type'], 'network_id' => $campaign_detail['campaign_networkid']);
        array_push($campaignarray, $add);
    }
    if (count($campaignarray) < 1) {
        return false;
    }
    foreach ($campaignarray as $key => $row) {
        $campaign_id[$key] = $row['campaign_id'];
        $priority[$key] = $row['priority'];
        $type[$key] = $row['type'];
        $network_id[$key] = $row['network_id'];
    }
    // Sort the data with volume descending, edition ascending
    // Add $data as the last parameter, to sort by the common key
    array_multisort($priority, SORT_DESC, $campaignarray);
    $highest_priority = $campaignarray[0]['priority'];
    $final_ads = array();
    foreach (range($highest_priority, 1) as $number) {
        unset($val);
        $val = removeElementWithValue($campaignarray, "priority", $number);
        shuffle($val);
        foreach ($val as $value) {
            array_push($final_ads, $value);
        }
    }
    if (MAD_CACHE_CAMPAIGN_QUERIES) {
        set_cache($q, $final_ads, 100);
    }
    return $final_ads;
}
function netsposts_shortcode($atts)
{
    /* below is my updates */
    extract(shortcode_atts(array('limit' => '', 'days' => 0, 'page_title_style' => '', 'title' => '', 'titles_only' => false, 'wrap_start' => null, 'wrap_end' => null, 'thumbnail' => false, 'post_type' => 'post', 'include_blog' => null, 'exclude_blog' => null, 'exclude_post' => null, 'include_post' => null, 'title_length' => 999, 'taxonomy' => '', 'paginate' => false, 'pages' => null, 'list' => 10, 'excerpt_length' => 400, 'auto_excerpt' => false, 'show_author' => false, 'full_text' => false, 'size' => 'thumbnail', 'image_class' => 'post-thumbnail', 'date_format' => 'n/j/Y', 'end_size' => '', 'mid_size' => '', 'prev_next' => false, 'prev' => '&laquo; Previous', 'next' => 'Next &raquo;', 'column' => '1', 'column_width' => '200', 'title_color' => '', 'text_color' => '', 'meta_info' => 'true', 'wrap_title_start' => '', 'wrap_title_end' => '', 'wrap_image_start' => '', 'wrap_image_end' => '', 'wrap_text_start' => '', 'wrap_text_end' => '', 'meta_width' => '100%', 'menu_name' => '', 'menu_class' => '', 'container_class' => '', 'post_height' => null, 'manual_excerpt_length' => null, 'random' => false, 'order_post_by' => ''), $atts));
    /* my updates are finished here */
    ########  OUTPUT STAFF  ####################
    $titles_only = strtolower($titles_only) == 'true' ? true : false;
    $thumbnail = strtolower($thumbnail) == 'true' ? true : false;
    $paginate = strtolower($paginate) == 'true' ? true : false;
    $auto_excerpt = strtolower($auto_excerpt) == 'true' ? true : false;
    $show_author = strtolower($show_author) == 'true' ? true : false;
    $full_text = strtolower($full_text) == 'true' ? true : false;
    $prev_next = strtolower($prev_next) == 'true' ? true : false;
    /* below is my updates */
    $random = strtolower($random) == 'true' ? true : false;
    /* my updates are finished here */
    global $wpdb;
    global $table_prefix;
    if ($limit) {
        $limit = " LIMIT 0,{$limit} ";
    }
    ## Params for taxonomy
    if ($cat) {
        if ($tag) {
            implode(',', $cat, $tag);
        }
    } else {
        $cat = $tag;
    }
    ## Include blogs
    if ($include_blog) {
        $include_arr = explode(",", $include_blog);
        $include = " AND (";
        foreach ($include_arr as $included_blog) {
            $include .= " blog_id = {$included_blog}  OR";
        }
        $include = substr($include, 0, strlen($include) - 2);
        $include .= ")";
    } else {
        if ($exclude_blog) {
            $exclude_arr = explode(",", $exclude_blog);
            foreach ($exclude_arr as $exclude_blog) {
                $exclude .= "AND blog_id != {$exclude_blog}  ";
            }
        }
    }
    $BlogsTable = $wpdb->base_prefix . 'blogs';
    /* below is my updates */
    if ($random) {
        $page = get_query_var('paged');
        if (!$page) {
            $page = get_query_var('page');
        }
        if (!$page) {
            $page = 1;
        }
        if ($page > 1 && $paginate) {
            $blogs = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM {$BlogsTable} WHERE public = %d AND archived = %d AND mature = %d AND spam = %d AND deleted = %d {$include} {$exclude}  ", 1, 0, 0, 0, 0));
        } else {
            $blogs = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM {$BlogsTable} WHERE public = %d AND archived = %d AND mature = %d AND spam = %d AND deleted = %d {$include} {$exclude} ORDER BY RAND() ", 1, 0, 0, 0, 0));
        }
    } else {
        $blogs = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM {$BlogsTable} WHERE public = %d AND archived = %d AND mature = %d AND spam = %d AND deleted = %d {$include} {$exclude}  ", 1, 0, 0, 0, 0));
    }
    /* my updates are finished here */
    ## Getting posts
    $postdata = array();
    if ($blogs) {
        foreach ($blogs as $blog_id) {
            if ($blog_id == 1) {
                $OptionsTable = $wpdb->base_prefix . "options";
                $PostsTable = $wpdb->base_prefix . "posts";
                $TermRelationshipTable = $wpdb->base_prefix . "term_relationships";
                $TermTaxonomyTable = $wpdb->base_prefix . "term_taxonomy";
                $TermsTable = $wpdb->base_prefix . "terms";
            } else {
                $OptionsTableTable = $wpdb->base_prefix . $blog_id . "_options";
                $PostsTable = $wpdb->base_prefix . $blog_id . "_posts";
                $TermRelationshipTable = $wpdb->base_prefix . $blog_id . "_term_relationships";
                $TermTaxonomyTable = $wpdb->base_prefix . $blog_id . "_term_taxonomy";
                $TermsTable = $wpdb->base_prefix . $blog_id . "_terms";
            }
            if ($days > 0) {
                $old = "AND {$PostsTable}.post_date >= DATE_SUB(CURRENT_DATE(), INTERVAL {$days} DAY)";
            } else {
                $old = "";
            }
            ## Taxonomy
            if ($taxonomy) {
                $categories = explode(',', $taxonomy);
                $cat_arr = array();
                foreach ($categories as $category) {
                    $cat_id = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM {$TermsTable} WHERE slug = '{$category}' "));
                    if ($cat_id) {
                        $cat_arr[] = $cat_id;
                    }
                }
                $taxonomy_arr = array();
                foreach ($cat_arr as $cat_id) {
                    $tax_id = $wpdb->get_var($wpdb->prepare("SELECT term_taxonomy_id FROM {$TermTaxonomyTable} WHERE  term_id = {$cat_id}"));
                    if ($tax_id) {
                        $taxonomy_arr[] = $tax_id;
                    }
                }
                foreach ($taxonomy_arr as $tax_id) {
                    $post_ids = $wpdb->get_results($wpdb->prepare("SELECT object_id FROM {$TermRelationshipTable} WHERE term_taxonomy_id = {$tax_id}"), ARRAY_A);
                    if (!empty($post_ids)) {
                        foreach ($post_ids as $key => $object_id) {
                            $ids .= " {$PostsTable}.ID = " . $object_id['object_id'] . ' OR';
                        }
                    }
                }
            }
            if ($ids) {
                $ids = ' AND  (' . substr($ids, 0, strlen($ids) - 2) . ')';
            } else {
                if ($taxonomy) {
                    $ids = ' AND  ID=null';
                }
            }
            /* below is my updates */
            $order_by = "";
            $aorder = array();
            $aorder1 = array();
            if ($order_post_by) {
                $tab_order_by1 = explode(" ", $order_post_by);
                if (($tab_order_by1[0] == "page_order" || $tab_order_by1[0] == "alphabetical_order" || $tab_order_by1[0] == "date_order") && (trim($tab_order_by1[1]) == "" || strtoupper($tab_order_by1[1]) == "DESC" || strtoupper($tab_order_by1[1]) == "ASC")) {
                    $order_by .= " ORDER BY " . $PostsTable . "." . $order_post_by;
                    $ordad = $tab_order_by1[1] ? $tab_order_by1[1] : "ASC";
                    $aorder = array_merge($aorder, array($tab_order_by1[0] => $ordad));
                    $ordad0 = "ID";
                    if ($tab_order_by1[0] == "date_order") {
                        $ordad0 = "post_date";
                    } else {
                        if ($tab_order_by1[0] == "alphabetical_order") {
                            $ordad0 = "post_title";
                        }
                    }
                    if (strtoupper($tab_order_by1[1]) == "DESC") {
                        $ordad1 = SORT_DESC;
                    } else {
                        $ordad1 = SORT_ASC;
                    }
                    $aorder1 = array_merge($aorder1, array($ordad0 => $ordad1));
                }
            }
            if ($random) {
                if ($page > 1 && $paginate) {
                    $the_post = $wpdb->get_results($wpdb->prepare("SELECT {$PostsTable}.ID, {$PostsTable}.post_title, {$PostsTable}.post_excerpt, {$PostsTable}.post_content, {$PostsTable}.post_author, {$PostsTable}.post_date, {$PostsTable}.guid, {$BlogsTable}.blog_id\n\t\t\t\t\t\tFROM {$PostsTable}, {$BlogsTable} WHERE {$BlogsTable}.blog_id  =  {$blog_id}  AND {$PostsTable}.post_status = %s {$ids}  AND {$PostsTable}.post_type = '{$post_type}'  {$old}  {$limit}", 'publish'), ARRAY_A);
                } else {
                    $the_post = $wpdb->get_results($wpdb->prepare("SELECT {$PostsTable}.ID, {$PostsTable}.post_title, {$PostsTable}.post_excerpt, {$PostsTable}.post_content, {$PostsTable}.post_author, {$PostsTable}.post_date, {$PostsTable}.guid, {$BlogsTable}.blog_id\n\t\t\t\t\t\tFROM {$PostsTable}, {$BlogsTable} WHERE {$BlogsTable}.blog_id  =  {$blog_id}  AND {$PostsTable}.post_status = %s {$ids}  AND {$PostsTable}.post_type = '{$post_type}'  {$old} ORDER BY RAND() {$limit}", 'publish'), ARRAY_A);
                }
            } else {
                $the_post = $wpdb->get_results($wpdb->prepare("SELECT {$PostsTable}.ID, {$PostsTable}.post_title, {$PostsTable}.post_excerpt, {$PostsTable}.post_content, {$PostsTable}.post_author, {$PostsTable}.post_date, {$PostsTable}.guid, {$BlogsTable}.blog_id\n\t\t\t\t\tFROM {$PostsTable}, {$BlogsTable} WHERE {$BlogsTable}.blog_id  =  {$blog_id}  AND {$PostsTable}.post_status = %s {$ids}  AND {$PostsTable}.post_type = '{$post_type}'  {$old}    {$limit}", 'publish'), ARRAY_A);
            }
            /* my updates are finished here */
            $postdata = array_merge_recursive($postdata, $the_post);
            $ids = '';
        }
    }
    /* below is my updates */
    if (!$random) {
        if ($order_by == "") {
            usort($postdata, "custom_sort");
        } else {
            $postdata = array_msort($postdata, $aorder1);
        }
    }
    /* my updates are finished here */
    /* below is my updates */
    $exclude_post2 = explode(",", $exclude_post);
    foreach ($exclude_post2 as $row) {
        $postdata = removeElementWithValue($postdata, "ID", $row);
    }
    /* my updates are finished here */
    if (isset($include_post)) {
        $include_post2 = explode(",", $include_post);
        foreach ($postdata as $postX) {
            if (in_array($postX['ID'], $include_post2)) {
                $newPostdata[] = $postX;
            }
        }
        $postdata = $newPostdata;
    }
    if ($paginate) {
        if ($column > 1) {
            $column_list = ceil($list / $column);
            $list = $column_list * $column;
            if (!$list) {
                $list = $column;
                $column_list = 1;
            }
        }
        $page = get_query_var('paged');
        if (!$page) {
            $page = get_query_var('page');
        }
        if (!$page) {
            $page = 1;
        }
        /* below is my updates */
        //$postdata = super_unique($postdata,"ID");
        /* my updates are finished here */
        /* below is my updates */
        /*$exclude_post2 = explode(",",$exclude_post);
        
                foreach($exclude_post2 as $row){
        
                    $postdata = removeElementWithValue($postdata, "ID", $row);
        
                }*/
        /* my updates are finished here */
        //if(!in_array($the_post['ID'], $exclude_post2)){
        $total_records = count($postdata);
        $total_pages = ceil($total_records / $list);
        $postdata = array_slice($postdata, ($page - 1) * $list, $list);
    } else {
        $postdata = array_slice($postdata, 0, $list);
    }
    /* my updates are finished here */
    if ($column > 1) {
        $count = count($postdata);
        if (!$paginate) {
            $column_list = ceil($count / $column);
        }
        for ($i = 0; $i < $column; ++$i) {
            if ($count < $column_list * $column) {
                $column_list = ceil($count / $column);
            }
            $colomn_data[$i] = array_slice($postdata, $i * $column_list, $column_list);
        }
    } else {
        $colomn_data[0] = $postdata;
    }
    ## OUTPUT
    if ($page_title_style) {
        ?>
	
	<style type="text/css">
	h2.pagetitle
	{
        <?php 
        echo $page_title_style;
        ?>
        <?php 
        echo get_option('net-style');
        ?>
	}
	</style>
	<?php 
    }
    $html = '<div id="netsposts-menu">';
    if ($menu_name) {
        $menu = array('menu' => $menu_name, 'menu_class' => $menu_class, 'container_class' => $container_class);
        wp_nav_menu($menu);
    }
    $html .= '</div>';
    if ($postdata) {
        $html .= "<style>";
        $html .= get_option('net-style');
        $html .= "</style>";
        $html .= '<div id="block-wrapper">';
        if (isset($post_height)) {
            $height_content = "height: " . $post_height . "px;";
        } else {
            $height_content = "";
        }
        if ($title) {
            $html .= '<span class="netsposts-title">' . $title . '</span><br />';
        }
        foreach ($colomn_data as $data) {
            if ($column > 1) {
                $html .= '<div class ="netsposts-column" style="width: ' . $column_width . 'px;">';
            }
            foreach ($data as $key => $the_post) {
                $blog_details = get_blog_details($the_post['blog_id']);
                $blog_name = $blog_details->blogname;
                $blog_url = $blog_details->siteurl;
                if ($titles_only) {
                    $title_class = 'netsposts-post-titles-only';
                } else {
                    $title_class = 'netsposts-posttitle';
                }
                $html .= html_entity_decode($wrap_start) . '<div class="netsposts-content" style="' . $height_content . '">';
                $html .= htmlspecialchars_decode($wrap_title_start);
                $html .= '<span class="' . $title_class . '" style="color: ' . $title_color . ';"><a href="' . $the_post['guid'] . '"> ' . ShortenText($the_post['post_title'], $title_length) . ' </a></span>';
                $html .= htmlspecialchars_decode($wrap_title_end);
                if (!$titles_only) {
                    $date = new DateTime(trim($the_post['post_date']));
                    $date_post = $date->format($date_format);
                    if ($meta_info != "false") {
                        if ($meta_width == "100%") {
                            $width = 'width: 100%;';
                        } else {
                            $width = "width: " . $meta_width . "px;";
                        }
                        $html .= '<span class="netsposts-source" style="height: 24px; margin-bottom: 5px; overflow: hidden; ' . $width . '"> ' . __('Published', 'netsposts') . ' ' . $date_post . ' ' . __('in', 'netsposts') . '  <a href="' . $blog_url . '">' . $blog_name . '</a>';
                    }
                    ##  Full metadata
                    if ($show_author) {
                        if ($column > 1) {
                            $html .= '<br />';
                        }
                        $html .= ' ' . __('Author', 'netsposts') . ' ' . '<a href="' . $blog_url . '?author=' . $the_post['post_author'] . '">' . get_the_author_meta('display_name', $the_post['post_author']) . ' </a>';
                    }
                    $html .= '</span>';
                    if ($thumbnail) {
                        $html .= htmlspecialchars_decode($wrap_image_start);
                        $html .= '<a href="' . $the_post['guid'] . '">' . get_thumbnail_by_blog($the_post['blog_id'], $the_post['ID'], $size, $image_class, $column) . '</a>';
                        $html .= htmlspecialchars_decode($wrap_image_end);
                        $html .= htmlspecialchars_decode($wrap_text_start);
                        $html .= '<p class="netsposts-excerpt" style="color: ' . $text_color . ';">';
                        $the_post['post_content'] = preg_replace("/<img[^>]+\\>/i", "", $the_post['post_content']);
                    }
                    if ($auto_excerpt) {
                        $exerpt = get_excerpt($excerpt_length, $the_post['post_content'], $the_post['guid']);
                    } else {
                        $exerpt = $the_post['post_excerpt'];
                    }
                    if ($full_text) {
                        $text = $the_post['post_content'];
                    } else {
                        if ($manual_excerpt_length) {
                            $text = get_excerpt($manual_excerpt_length, $exerpt, $the_post['guid']);
                        } else {
                            $text = $exerpt;
                        }
                    }
                    $html .= strip_shortcodes($text);
                    $html .= ' <a class="netsposts-read-more-link" href="' . $the_post['guid'] . '">read more&rarr;</a></p>';
                    $html .= htmlspecialchars_decode($wrap_text_end);
                }
                $html .= "</div>";
                $html .= "";
                $html .= html_entity_decode($wrap_end);
                $html .= "";
            }
            if ($column > 1) {
                $html .= '</div>';
            }
        }
        $html .= '<div class="clear"></div>';
        if ($paginate and $total_pages > 1) {
            $html .= '<div id="netsposts-paginate">';
            $big = 999999999;
            $html .= paginate_links(array('base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 'format' => '?paged=%#%', 'current' => $page, 'total' => $total_pages, 'prev_text' => __($prev), 'next_text' => __($next), 'end_size' => $end_size, 'mid_size' => $mid_size));
            $html .= '</div>';
        }
        $html .= '</div>';
    }
    return $html;
}