[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

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

   1  <?php
   2  
   3  function gp_link_get( $url, $text, $attrs = array() ) {
   4      $before = $after = '';
   5      foreach ( array('before', 'after') as $key ) {
   6          if ( isset( $attrs[$key] ) ) {
   7              $$key = $attrs[$key];
   8              unset( $attrs[$key] );
   9          }
  10      }
  11      $attributes = gp_html_attributes( $attrs );
  12      $attributes = $attributes? " $attributes" : '';
  13  
  14      return sprintf('%1$s<a href="%2$s"%3$s>%4$s</a>%5$s', $before, esc_url( $url ), $attributes, $text, $after );
  15  }
  16  
  17  function gp_link() {
  18      $args = func_get_args();
  19      echo call_user_func_array('gp_link_get', $args);
  20  }
  21  
  22  function gp_link_with_ays_get( $url, $text, $attrs = array() ) {
  23      $ays_text = $attrs['ays-text'];
  24      unset( $attrs['ays-text'] );
  25      $attrs['onclick'] = "return confirm('".esc_js( $ays_text )."');";
  26      return gp_link_get( $url, $text, $attrs );
  27  }
  28  
  29  function gp_link_with_ays() {
  30      $args = func_get_args();
  31      echo call_user_func_array('gp_link_with_ays_get', $args);
  32  }
  33  
  34  function gp_link_project_get( $project_or_path, $text, $attrs = array() ) {
  35      $attrs = array_merge( array( 'title' => 'Project: '.$text ), $attrs );
  36      return gp_link_get( gp_url_project( $project_or_path ), $text, $attrs );
  37  }
  38  
  39  function gp_link_project() {
  40      $args = func_get_args();
  41      echo call_user_func_array('gp_link_project_get', $args);
  42  }
  43  
  44  function gp_link_project_edit_get( $project, $text = null, $attrs = array() ) {
  45      if ( ! GP::$permission->current_user_can( 'write', 'project', $project->id ) ) {
  46          return '';
  47      }
  48      $text = $text? $text : __( 'Edit', 'glotpress' );
  49      return gp_link_get( gp_url_project( $project, '-edit' ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
  50  }
  51  
  52  function gp_link_project_edit() {
  53      $args = func_get_args();
  54      echo call_user_func_array('gp_link_project_edit_get', $args);
  55  }
  56  
  57  function gp_link_project_delete_get( $project, $text = false, $attrs = array() ) {
  58      if ( ! GP::$permission->current_user_can( 'delete', 'project', $project->id ) ) {
  59          return '';
  60      }
  61      $text = $text? $text : __( 'Delete', 'glotpress' );
  62      return gp_link_get( gp_url_project( $project, '-delete' ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
  63  }
  64  
  65  function gp_link_project_delete() {
  66      $args = func_get_args();
  67      echo call_user_func_array('gp_link_project_delete_get', $args);
  68  }
  69  
  70  function gp_link_home_get() {
  71      return gp_link_get( gp_url( '/' ), __( 'Home', 'glotpress' ), array( 'title' => __( 'Home Is Where The Heart Is', 'glotpress' ) ) );
  72  }
  73  
  74  function gp_link_home() {
  75      $args = func_get_args();
  76      echo call_user_func_array('gp_link_home_get', $args);
  77  }
  78  
  79  function gp_link_set_edit_get( $set, $project, $text = false, $attrs = array() ) {
  80      if ( ! GP::$permission->current_user_can( 'write', 'project', $project->id ) ) {
  81          return '';
  82      }
  83      $text = $text? $text : __( 'Edit', 'glotpress' );
  84      return gp_link_get( gp_url( gp_url_join( '/sets', $set->id, '-edit' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
  85  }
  86  
  87  function gp_link_set_edit() {
  88      $args = func_get_args();
  89      echo call_user_func_array('gp_link_set_edit_get', $args);
  90  }
  91  
  92  /**
  93   * Creates a HTML link to the delete page for translations sets.
  94   *
  95   * Does the heavy lifting for gp_link_set_delete().
  96   *
  97   * @since 2.0.0
  98   *
  99   * @param GP_Translation_Set $set     The translation set to link to.
 100   * @param GP_Project         $project The project the translation set belongs to.
 101   * @param string             $text    The text to use for the link.
 102   * @param array              $attrs   Additional attributes to use to determine the classes for the link.
 103   *
 104   * @return string $link
 105   */
 106  function gp_link_set_delete_get( $set, $project, $text = false, $attrs = array() ) {
 107      if ( ! GP::$permission->current_user_can( 'delete', 'project', $project->id ) ) {
 108          return '';
 109      }
 110  
 111      if ( false === $text ) {
 112          $text = __( 'Delete', 'glotpress' );
 113      }
 114  
 115      return gp_link_get( gp_url( gp_url_join( '/sets', $set->id, '-delete' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
 116  }
 117  
 118  /**
 119   * Outputs a HTML link to the delete page for translations sets.
 120   *
 121   * Does the heavy lifting for gp_link_set_delete().
 122   *
 123   * @since 2.0.0
 124   *
 125   * @param GP_Translation_Set $set     The translation set to link to.
 126   * @param GP_Project         $project The project the translation set belongs to.
 127   * @param string             $text    The text to use for the link.
 128   * @param array              $attrs   Additional attributes to use to determine the classes for the link.
 129   */
 130  function gp_link_set_delete( $set, $project, $text = false, $attrs = array() ) {
 131      echo gp_link_set_delete_get( $set, $project, $text, $attrs );
 132  }
 133  
 134  /**
 135   * Creates a HTML link to the delete page for translations sets.
 136   *
 137   * Does the heavy lifting for gp_link_glossary_delete.
 138   *
 139   * @since 1.0.0
 140   *
 141   * @param GP_Glossary        $glossary The glossary to link to.
 142   * @param GP_Translation_Set $set      The translation set the glossary is for.
 143   * @param string             $text     The text to use for the link.
 144   * @param array              $attrs    Additional attributes to use to determine the classes for the link.
 145   * @return string The HTML link.
 146   */
 147  function gp_link_glossary_edit_get( $glossary, $set, $text = false, $attrs = array() ) {
 148      if ( ! GP::$permission->current_user_can( 'approve', 'translation-set', $set->id ) ) {
 149          return '';
 150      }
 151  
 152      $text = $text? $text : __( 'Edit', 'glotpress' );
 153      return gp_link_get( gp_url( gp_url_join( '/glossaries', $glossary->id, '-edit' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
 154  }
 155  
 156  function gp_link_glossary_edit() {
 157      $args = func_get_args();
 158      echo call_user_func_array('gp_link_glossary_edit_get', $args);
 159  }
 160  
 161  /**
 162   * Creates a HTML link to the delete page for translations sets.
 163   *
 164   * Does the heavy lifting for gp_link_glossary_delete.
 165   *
 166   * @since 2.0.0
 167   *
 168   * @param GP_Glossary        $glossary The glossary to link to.
 169   * @param GP_Translation_Set $set      The translation set the glossary is for.
 170   * @param string             $text     The text to use for the link.
 171   * @param array              $attrs    Additional attributes to use to determine the classes for the link.
 172   * @return string The HTML link.
 173   */
 174  function gp_link_glossary_delete_get( $glossary, $set, $text = false, $attrs = array() ) {
 175      if ( ! GP::$permission->current_user_can( 'delete', 'translation-set', $set->id ) ) {
 176          return '';
 177      }
 178  
 179      $text = $text? $text : __( 'Delete', 'glotpress' );
 180      return gp_link_get( gp_url( gp_url_join( '/glossaries', $glossary->id, '-delete' ) ), $text, gp_attrs_add_class( $attrs, 'action edit' ) );
 181  }
 182  
 183  /**
 184   * Outputs a HTML link to the delete page for glossaries.
 185   *
 186   * @since 2.0.0
 187   *
 188   * @param GP_Glossary        $glossary The glossary to link to.
 189   * @param GP_Translation_Set $set      The translation set the glossary is for.
 190   * @param string             $text     The text to use for the link.
 191   * @param array              $attrs    Additional attributes to use to determine the classes for the link.
 192   */
 193  function gp_link_glossary_delete( $glossary, $set, $text = false, $attrs = array() ) {
 194      echo gp_link_glossary_delete_get( $glossary, $set, $text, $attrs );
 195  }
 196  
 197  /**
 198   * Outputs a HTML link to a user profile page.
 199   *
 200   * @since 2.1.0
 201   *
 202   * @param WP_User $user A WP_User user object.
 203   */
 204  function gp_link_user( $user ) {
 205      if ( $user->display_name && $user->display_name !== $user->user_login ) {
 206          printf( '<a href="%s" tabindex="-1">%s (%s)</a>',
 207              esc_url( gp_url_profile( $user->user_nicename ) ),
 208              esc_html( $user->display_name ),
 209              esc_html( $user->user_login )
 210          );
 211      } else {
 212          printf( '<a href="%s" tabindex="-1">%s</a>',
 213              esc_url( gp_url_profile( $user->user_nicename ) ),
 214              esc_attr( $user->user_login )
 215          );
 216      }
 217  }


Generated: Fri Aug 23 01:02:17 2019 Cross-referenced by PHPXref 0.7.1