Exemplo n.º 1
0
 /**
  * Generate the Regular expression that matches embedded entries.
  *
  * Generates different regex if using permalinks and if not using permalinks
  *
  * @since 1.6
  *
  * @return string Regex code
  */
 private function get_handler_regex()
 {
     $entry_var_name = GravityView_Post_Types::get_entry_var_name();
     $rewrite_slug = apply_filters('gravityview_slug', 'view');
     // Only support embeds for current site
     $prefix = trailingslashit(home_url());
     // Using permalinks
     $using_permalinks = $prefix . "(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$";
     // Not using permalinks
     $not_using_permalinks = $prefix . "(?:index.php)?\\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$";
     // Catch either
     $match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
     return '#' . $match_regex . '#i';
 }
Exemplo n.º 2
0
 /**
  * Generate the Regular expression that matches embedded entries.
  *
  * Generates different regex if using permalinks and if not using permalinks
  *
  * @since 1.6
  *
  * @return string Regex code
  */
 private function get_handler_regex()
 {
     $entry_var_name = GravityView_Post_Types::get_entry_var_name();
     /**
      * @filter `gravityview_slug` Modify the url part for a View. [Read the doc](http://docs.gravityview.co/article/62-changing-the-view-slug)
      * @param string $rewrite_slug The slug shown in the URL
      */
     $rewrite_slug = apply_filters('gravityview_slug', 'view');
     // Only support embeds for current site
     $prefix = trailingslashit(home_url());
     // Using permalinks
     $using_permalinks = $prefix . "(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$";
     // Not using permalinks
     $not_using_permalinks = $prefix . "(?:index.php)?\\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$";
     // Catch either
     $match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
     return '#' . $match_regex . '#i';
 }
Exemplo n.º 3
0
 /**
  * return href for single entry
  * @param  array|int $entry   Entry array or entry ID
  * @param  int|null $post_id If wanting to define the parent post, pass a post ID
  * @param boolean $add_directory_args True: Add args to help return to directory; False: only include args required to get to entry {@since 1.7.3}
  * @return string          Link to the entry with the directory parent slug
  */
 public static function entry_link($entry, $post_id = NULL, $add_directory_args = true)
 {
     if (!empty($entry) && !is_array($entry)) {
         $entry = GVCommon::get_entry($entry);
     } else {
         if (empty($entry)) {
             $entry = GravityView_frontend::getInstance()->getEntry();
         }
     }
     // Second parameter used to be passed as $field; this makes sure it's not an array
     if (!is_numeric($post_id)) {
         $post_id = NULL;
     }
     // Get the permalink to the View
     $directory_link = self::directory_link($post_id, false);
     // No post ID? Get outta here.
     if (empty($directory_link)) {
         return '';
     }
     $query_arg_name = GravityView_Post_Types::get_entry_var_name();
     $entry_slug = self::get_entry_slug($entry['id'], $entry);
     if (get_option('permalink_structure') && !is_preview()) {
         $args = array();
         $directory_link = trailingslashit($directory_link) . $query_arg_name . '/' . $entry_slug . '/';
     } else {
         $args = array($query_arg_name => $entry_slug);
     }
     /**
      * @since 1.7.3
      */
     if ($add_directory_args) {
         if (!empty($_GET['pagenum'])) {
             $args['pagenum'] = intval($_GET['pagenum']);
         }
         /**
          * @since 1.7
          */
         if ($sort = rgget('sort')) {
             $args['sort'] = $sort;
             $args['dir'] = rgget('dir');
         }
     }
     /**
      * Check if we have multiple views embedded in the same page and in that case make sure the single entry link
      * has the view id so that Advanced Filters can be applied correctly when rendering the single view
      * @see GravityView_frontend::get_context_view_id()
      */
     if (class_exists('GravityView_View_Data') && GravityView_View_Data::getInstance()->has_multiple_views()) {
         $args['gvid'] = gravityview_get_view_id();
     }
     return add_query_arg($args, $directory_link);
 }
Exemplo n.º 4
0
 /**
  * Verify if user requested a single entry view
  * @return boolean|string false if not, single entry slug if true
  */
 public static function is_single_entry()
 {
     $var_name = GravityView_Post_Types::get_entry_var_name();
     $single_entry = get_query_var($var_name);
     /**
      * Modify the entry that is being displayed.
      *
      * @internal Should only be used by things like the oEmbed functionality.
      * @since 1.6
      */
     $single_entry = apply_filters('gravityview/is_single_entry', $single_entry);
     if (empty($single_entry)) {
         return false;
     } else {
         return $single_entry;
     }
 }