Beispiel #1
0
 public static function prepare_cta_dataset($cta_display_list, $variation_id = null)
 {
     global $CTA_Variations;
     if (!$cta_display_list) {
         return array();
     }
     foreach ($cta_display_list as $key => $cta_id) {
         $url = get_permalink($cta_id);
         $cta_obj[$cta_id]['id'] = $cta_id;
         $cta_obj[$cta_id]['url'] = $url;
         /* If variation is predefined load only that variations data else load all variation data for a given cta */
         if ($variation_id !== null) {
             $cta_obj[$cta_id]['variations'] = $CTA_Variations->get_variations($cta_id, $variation_id);
         } else {
             $cta_obj[$cta_id]['variations'] = $CTA_Variations->get_variations($cta_id);
         }
         $meta = get_post_meta($cta_id);
         // move to ext
         if (!$meta) {
             return;
         }
         foreach ($cta_obj[$cta_id]['variations'] as $vid => $variation) {
             if (!isset($meta['wp-cta-selected-template-' . $vid][0])) {
                 unset($cta_obj[$cta_id]['variations'][$vid]);
                 continue;
             }
             if ($variation['status'] == 'paused' && !isset($_GET['wp-cta-variation-id'])) {
                 unset($cta_obj[$cta_id]['variations'][$vid]);
                 continue;
             }
             $template_slug = $meta['wp-cta-selected-template-' . $vid][0];
             $cta_obj[$cta_id]['templates'][$vid]['slug'] = $template_slug;
             $cta_obj[$cta_id]['meta'][$vid]['wp-cta-selected-template-' . $vid] = $template_slug;
             /* determin where template exists for asset loading	*/
             if (file_exists(WP_CTA_PATH . 'templates/' . $template_slug . '/index.php')) {
                 $cta_obj[$cta_id]['templates'][$vid]['path'] = WP_CTA_PATH . 'templates/' . $template_slug . '/';
                 $cta_obj[$cta_id]['templates'][$vid]['urlpath'] = WP_CTA_URLPATH . 'templates/' . $template_slug . '/';
             } else {
                 //query_posts ($query_string . '&showposts=1');
                 $cta_obj[$cta_id]['templates'][$vid]['path'] = WP_CTA_UPLOADS_PATH . $template_slug . '/';
                 $cta_obj[$cta_id]['templates'][$vid]['urlpath'] = WP_CTA_UPLOADS_URLPATH . $template_slug . '/';
             }
             /* get variation meta */
             $cta_obj[$cta_id]['meta'][$vid] = CTA_Variations::get_variation_meta($cta_id, $vid);
         }
     }
     $cta_obj = apply_filters('wp_cta_obj', $cta_obj);
     /* return one cta out of list of available ctas */
     $key = array_rand($cta_obj);
     return $cta_obj[$key];
 }
 /**
  *  Generate a set of data related to CTA(s)
  *  @param ARRAY $cta_display_list array of cta id(s)
  */
 public static function prepare_cta_dataset($cta_display_list, $variation_id = null)
 {
     global $CTA_Variations;
     if (!$cta_display_list) {
         return array();
     }
     foreach ($cta_display_list as $key => $cta_id) {
         $url = get_permalink($cta_id);
         $cta_obj[$cta_id]['id'] = $cta_id;
         $cta_obj[$cta_id]['url'] = $url;
         /* If variation is predefined load only that variations data else load all variation data for a given cta */
         if ($variation_id !== null) {
             $cta_obj[$cta_id]['variations'] = $CTA_Variations->get_variations($cta_id, $variation_id);
         } else {
             $cta_obj[$cta_id]['variations'] = $CTA_Variations->get_variations($cta_id);
         }
         /* Get meta of cta */
         $meta = get_post_meta($cta_id);
         // move to ext
         /* if no meta then bail, this is an unprepared CTA */
         if (!$meta) {
             return;
         }
         /* Loop through cta variations and improve data set */
         foreach ($cta_obj[$cta_id]['variations'] as $vid => $variation) {
             /* if variation does not have a selected template then treat as broken and unset from dataset */
             if (!isset($meta['wp-cta-selected-template-' . $vid][0])) {
                 unset($cta_obj[$cta_id]['variations'][$vid]);
                 continue;
             }
             /* if cta is paused and not in preview mode then unset from dataset */
             if ($variation['status'] == 'paused' && !isset($_GET['wp-cta-variation-id'])) {
                 unset($cta_obj[$cta_id]['variations'][$vid]);
                 continue;
             }
             $template_slug = $meta['wp-cta-selected-template-' . $vid][0];
             $cta_obj[$cta_id]['templates'][$vid]['slug'] = $template_slug;
             $cta_obj[$cta_id]['meta'][$vid]['wp-cta-selected-template-' . $vid] = $template_slug;
             /* determine where template exists for asset loading	*/
             if (file_exists(WP_CTA_PATH . 'templates/' . $template_slug)) {
                 $cta_obj[$cta_id]['templates'][$vid]['path'] = WP_CTA_PATH . 'templates/' . $template_slug . '/';
                 $cta_obj[$cta_id]['templates'][$vid]['urlpath'] = WP_CTA_URLPATH . 'templates/' . $template_slug . '/';
             } else {
                 //query_posts ($query_string . '&showposts=1');
                 $cta_obj[$cta_id]['templates'][$vid]['path'] = WP_CTA_UPLOADS_PATH . $template_slug . '/';
                 $cta_obj[$cta_id]['templates'][$vid]['urlpath'] = WP_CTA_UPLOADS_URLPATH . $template_slug . '/';
             }
             /* get variation meta */
             $cta_obj[$cta_id]['meta'][$vid] = CTA_Variations::get_variation_meta($cta_id, $vid);
         }
     }
     /* let them improve or alter the dataset */
     $cta_obj = apply_filters('wp_cta_obj', $cta_obj);
     /* return one cta out of list of available ctas */
     $key = array_rand($cta_obj);
     return $cta_obj[$key];
 }