[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/ -> template-links.php (source)

   1  <?php
   2  /**
   3   * Link Template Functions
   4   *
   5   * @package GlotPress
   6   * @subpackage Template
   7   */
   8  
   9  /**
  10   * Creates a HTML link.
  11   *
  12   * @since 1.0.0
  13   *
  14   * @param string $url   The URL to link to.
  15   * @param string $text  The text to use for the link.
  16   * @param array  $attrs Optional. Additional attributes to use
  17   *                      to determine the classes for the link.
  18   * @return string The HTML link.
  19   */
  20  function gp_link_get( $url, $text, $attrs = array() ) {
  21      $before = '';
  22      $after  = '';
  23      foreach ( array( 'before', 'after' ) as $key ) {
  24          if ( isset( $attrs[ $key ] ) ) {
  25              $$key = $attrs[ $key ];
  26              unset( $attrs[ $key ] );
  27          }
  28      }
  29      $attributes = gp_html_attributes( $attrs );
  30      $attributes = $attributes ? " $attributes" : '';
  31  
  32      return sprintf( '%1$s<a href="%2$s"%3$s>%4$s</a>%5$s', $before, esc_url( $url ), $attributes, $text, $after );
  33  }
  34  
  35  /**
  36   * Creates a HTML link.
  37   *
  38   * @since 1.0.0
  39   *
  40   * @see gp_link_get()
  41   *
  42   * @param string $url   The URL to link to.
  43   * @param string $text  The text to use for the link.
  44   * @param array  $attrs Optional. Additional attributes to use
  45   *                      to determine the classes for the link.
  46   */
  47  function gp_link( $url, $text, $attrs = array() ) {
  48      echo gp_link_get( $url, $text, $attrs );
  49  }
  50  
  51  /**
  52   * Creates a HTML link with a confirmation request.
  53   *
  54   * Uses the `window.confirm()` method to display a modal dialog for confirmation.
  55   *
  56   * @since 1.0.0
  57   *
  58   * @param string $url   The URL to link to.
  59   * @param string $text  The text to use for the link.
  60   * @param array  $attrs Optional. Additional attributes to use
  61   *                      to determine the classes for the link.
  62   * @return string The HTML link.
  63   */
  64  function gp_link_with_ays_get( $url, $text, $attrs = array() ) {
  65      $ays_text = $attrs['ays-text'];
  66      unset( $attrs['ays-text'] );
  67      $attrs['onclick'] = "return confirm('" . esc_js( $ays_text ) . "');";
  68      return gp_link_get( $url, $text, $attrs );
  69  }
  70  
  71  /**
  72   * Creates a HTML link with a confirmation request.
  73   *
  74   * Uses the `window.confirm()` method to display a modal dialog for confirmation.
  75   *
  76   * @since 1.0.0
  77   *
  78   * @see gp_link_with_ays_get()
  79   *
  80   * @param string $url   The URL to link to.
  81   * @param string $text  The text to use for the link.
  82   * @param array  $attrs Optional. Additional attributes to use
  83   *                      to determine the classes for the link.
  84   */
  85  function gp_link_with_ays( $url, $text, $attrs = array() ) {
  86      echo gp_link_with_ays_get( $url, $text, $attrs );
  87  }
  88  
  89  /**
  90   * Creates a HTML link to the page of a project.
  91   *
  92   * @since 1.0.0
  93   *
  94   * @param GP_Project|string $project_or_path The project to link to.
  95   * @param string            $text            The text to use for the link.
  96   * @param array             $attrs           Optional. Additional attributes to use
  97   *                                           to determine the classes for the link.
  98   * @return string The HTML link.
  99   */
 100  function gp_link_project_get( $project_or_path, $text, $attrs = array() ) {
 101      return gp_link_get( gp_url_project( $project_or_path ), $text, $attrs );
 102  }
 103  
 104  /**
 105   * Outputs a HTML link to the page of a project.
 106   *
 107   * @since 1.0.0
 108   *
 109   * @see gp_link_project_get()
 110   *
 111   * @param GP_Project|string $project_or_path The project to link to.
 112   * @param string            $text            The text to use for the link.
 113   * @param array             $attrs           Optional. Additional attributes to use
 114   *                                           to determine the classes for the link.
 115   */
 116  function gp_link_project( $project_or_path, $text, $attrs = array() ) {
 117      echo gp_link_project_get( $project_or_path, $text, $attrs );
 118  }
 119  
 120  /**
 121   * Creates a HTML link to the edit page for projects.
 122   *
 123   * @since 1.0.0
 124   *
 125   * @param GP_Project $project The project to link to.
 126   * @param string     $text    Optional. The text to use for the link. Default 'Edit'.
 127   * @param array      $attrs   Optional. Additional attributes to use to determine the classes for the link.
 128   * @return string The HTML link.
 129   */
 130  function gp_link_project_edit_get( $project, $text = '', $attrs = array() ) {
 131      if ( ! GP::$permission->current_user_can( 'write', 'project', $project->id ) ) {
 132          return '';
 133      }
 134      $text = $text ? $text : __( 'Edit', 'glotpress' );
 135      return gp_link_get( gp_url_project( $project, '-edit' ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
 136  }
 137  
 138  /**
 139   * Outputs a HTML link to the edit page for projects.
 140   *
 141   * @since 1.0.0
 142   *
 143   * @see gp_link_project_edit_get()
 144   *
 145   * @param GP_Project $project The project to link to.
 146   * @param string     $text    Optional. The text to use for the link. Default 'Edit'.
 147   * @param array      $attrs   Optional. Additional attributes to use to determine the classes for the link.
 148   */
 149  function gp_link_project_edit( $project, $text = '', $attrs = array() ) {
 150      echo gp_link_project_edit_get( $project, $text, $attrs );
 151  }
 152  
 153  /**
 154   * Creates a HTML link to the delete page for projects.
 155   *
 156   * @since 1.0.0
 157   *
 158   * @param GP_Project $project The project to link to.
 159   * @param string     $text    Optional. The text to use for the link. Default 'Delete'.
 160   * @param array      $attrs   Optional. Additional attributes to use to determine the classes for the link.
 161   * @return string The HTML link.
 162   */
 163  function gp_link_project_delete_get( $project, $text = '', $attrs = array() ) {
 164      if ( ! GP::$permission->current_user_can( 'delete', 'project', $project->id ) ) {
 165          return '';
 166      }
 167      $text = $text ? $text : __( 'Delete', 'glotpress' );
 168      return gp_link_get( gp_url_project( $project, '-delete' ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
 169  }
 170  
 171  /**
 172   * Outputs a HTML link to the delete page for projects.
 173   *
 174   * @since 1.0.0
 175   *
 176   * @see gp_link_project_delete_get()
 177   *
 178   * @param GP_Project $project The project to link to.
 179   * @param string     $text    Optional. The text to use for the link.
 180   * @param array      $attrs   Optional. Additional attributes to use to determine the classes for the link.
 181   */
 182  function gp_link_project_delete( $project, $text = '', $attrs = array() ) {
 183      echo gp_link_project_delete_get( $project, $text, $attrs );
 184  }
 185  
 186  /**
 187   * Creates a HTML link to the home page of GlotPress.
 188   *
 189   * @since 1.0.0
 190   *
 191   * @return string The HTML link.
 192   */
 193  function gp_link_home_get() {
 194      return gp_link_get( gp_url( '/' ), __( 'Home', 'glotpress' ) );
 195  }
 196  
 197  /**
 198   * Outputs a HTML link to the home page of GlotPress.
 199   *
 200   * @since 1.0.0
 201   *
 202   * @see gp_link_home_get()
 203   */
 204  function gp_link_home() {
 205      echo gp_link_home_get();
 206  }
 207  
 208  /**
 209   * Creates a HTML link to the delete page for translations sets.
 210   *
 211   * @since 1.0.0
 212   *
 213   * @param GP_Translation_Set $set     The translation set to link to.
 214   * @param GP_Project         $project The project the translation set belongs to.
 215   * @param string             $text    Optional. The text to use for the link. Default 'Edit'.
 216   * @param array              $attrs   Optional. Additional attributes to use to determine the classes for the link.
 217   * @return string The HTML link.
 218   */
 219  function gp_link_set_edit_get( $set, $project, $text = '', $attrs = array() ) {
 220      if ( ! GP::$permission->current_user_can( 'write', 'project', $project->id ) ) {
 221          return '';
 222      }
 223  
 224      $text = $text ? $text : __( 'Edit', 'glotpress' );
 225      return gp_link_get( gp_url( gp_url_join( '/sets', $set->id, '-edit' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
 226  }
 227  
 228  /**
 229   * Outputs a HTML link to the edit page for translations sets.
 230   *
 231   * @since 1.0.0
 232   *
 233   * @see gp_link_set_edit_get()
 234   *
 235   * @param GP_Translation_Set $set     The translation set to link to.
 236   * @param GP_Project         $project The project the translation set belongs to.
 237   * @param string             $text    Optional. The text to use for the link. Default 'Edit'.
 238   * @param array              $attrs   Optional. Additional attributes to use to determine the classes for the link.
 239   */
 240  function gp_link_set_edit( $set, $project, $text = '', $attrs = array() ) {
 241      echo gp_link_set_edit_get( $set, $project, $text, $attrs );
 242  }
 243  
 244  /**
 245   * Creates a HTML link to the delete page for translations sets.
 246   *
 247   * @since 2.0.0
 248   *
 249   * @param GP_Translation_Set $set     The translation set to link to.
 250   * @param GP_Project         $project The project the translation set belongs to.
 251   * @param string             $text    Optional. The text to use for the link. Default 'Delete'.
 252   * @param array              $attrs   Optional. Additional attributes to use to determine the classes for the link.
 253   * @return string The HTML link.
 254   */
 255  function gp_link_set_delete_get( $set, $project, $text = '', $attrs = array() ) {
 256      if ( ! GP::$permission->current_user_can( 'delete', 'project', $project->id ) ) {
 257          return '';
 258      }
 259  
 260      $text = $text ? $text : __( 'Delete', 'glotpress' );
 261      return gp_link_get( gp_url( gp_url_join( '/sets', $set->id, '-delete' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
 262  }
 263  
 264  /**
 265   * Outputs a HTML link to the delete page for translations sets.
 266   *
 267   * @since 2.0.0
 268   *
 269   * @see gp_link_set_delete_get()
 270   *
 271   * @param GP_Translation_Set $set     The translation set to link to.
 272   * @param GP_Project         $project The project the translation set belongs to.
 273   * @param string             $text    Optional. The text to use for the link. Default 'Delete'.
 274   * @param array              $attrs   Optional. Additional attributes to use to determine the classes for the link.
 275   */
 276  function gp_link_set_delete( $set, $project, $text = '', $attrs = array() ) {
 277      echo gp_link_set_delete_get( $set, $project, $text, $attrs );
 278  }
 279  
 280  /**
 281   * Creates a HTML link to the edit page for glossaries.
 282   *
 283   * @since 1.0.0
 284   *
 285   * @param GP_Glossary        $glossary The glossary to link to.
 286   * @param GP_Translation_Set $set      The translation set the glossary is for.
 287   * @param string             $text     Optional. The text to use for the link. Default 'Edit'.
 288   * @param array              $attrs    Optional. Additional attributes to use to determine the classes for the link.
 289   * @return string The HTML link.
 290   */
 291  function gp_link_glossary_edit_get( $glossary, $set, $text = '', $attrs = array() ) {
 292      if ( ! GP::$permission->current_user_can( 'approve', 'translation-set', $set->id ) ) {
 293          return '';
 294      }
 295  
 296      $text = $text ? $text : __( 'Edit', 'glotpress' );
 297      return gp_link_get( gp_url( gp_url_join( '/glossaries', $glossary->id, '-edit' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
 298  }
 299  
 300  /**
 301   * Outputs a HTML link to the edit page for glossaries.
 302   *
 303   * @since 1.0.0
 304   *
 305   * @see gp_link_glossary_edit_get()
 306   *
 307   * @param GP_Glossary        $glossary The glossary to link to.
 308   * @param GP_Translation_Set $set      The translation set the glossary is for.
 309   * @param string             $text     Optional. The text to use for the link. Default 'Edit'.
 310   * @param array              $attrs    Optional. Additional attributes to use to determine the classes for the link.
 311   */
 312  function gp_link_glossary_edit( $glossary, $set, $text = '', $attrs = array() ) {
 313      echo gp_link_glossary_edit_get( $glossary, $set, $text, $attrs );
 314  }
 315  
 316  /**
 317   * Creates a HTML link to the delete page for glossaries.
 318   *
 319   * @since 2.0.0
 320   *
 321   * @param GP_Glossary        $glossary The glossary to link to.
 322   * @param GP_Translation_Set $set      The translation set the glossary is for.
 323   * @param string             $text     Optional. The text to use for the link. Default 'Delete'.
 324   * @param array              $attrs    Optional. Additional attributes to use to determine the classes for the link.
 325   * @return string The HTML link.
 326   */
 327  function gp_link_glossary_delete_get( $glossary, $set, $text = '', $attrs = array() ) {
 328      if ( ! GP::$permission->current_user_can( 'delete', 'translation-set', $set->id ) ) {
 329          return '';
 330      }
 331  
 332      $text = $text ? $text : __( 'Delete', 'glotpress' );
 333      return gp_link_get( gp_url( gp_url_join( '/glossaries', $glossary->id, '-delete' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
 334  }
 335  
 336  /**
 337   * Outputs a HTML link to the delete page for glossaries.
 338   *
 339   * @since 2.0.0
 340   *
 341   * @see gp_link_glossary_delete_get()
 342   *
 343   * @param GP_Glossary        $glossary The glossary to link to.
 344   * @param GP_Translation_Set $set      The translation set the glossary is for.
 345   * @param string             $text     Optional. The text to use for the link. Default 'Delete'.
 346   * @param array              $attrs    Optional. Additional attributes to use to determine the classes for the link.
 347   */
 348  function gp_link_glossary_delete( $glossary, $set, $text = '', $attrs = array() ) {
 349      echo gp_link_glossary_delete_get( $glossary, $set, $text, $attrs );
 350  }
 351  
 352  /**
 353   * Outputs a HTML link to a user profile page.
 354   *
 355   * @since 2.1.0
 356   *
 357   * @param WP_User $user A WP_User user object.
 358   */
 359  function gp_link_user( $user ) {
 360      if ( $user->display_name && $user->display_name !== $user->user_login ) {
 361          printf(
 362              '<a href="%s" tabindex="-1">%s (%s)</a>',
 363              esc_url( gp_url_profile( $user->user_nicename ) ),
 364              esc_html( $user->display_name ),
 365              esc_html( $user->user_login )
 366          );
 367      } else {
 368          printf(
 369              '<a href="%s" tabindex="-1">%s</a>',
 370              esc_url( gp_url_profile( $user->user_nicename ) ),
 371              esc_attr( $user->user_login )
 372          );
 373      }
 374  }


Generated: Sat Sep 26 01:01:49 2020 Cross-referenced by PHPXref 0.7.1