[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

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

   1  <?php
   2  function gp_tmpl_load( $template, $args = array(), $template_path = null ) {
   3      $args = gp_tmpl_filter_args( $args );
   4  
   5      /**
   6       * Fires before a template is loaded.
   7       *
   8       * @since 1.0.0
   9       *
  10       * @param string $template The template name.
  11       * @param array  $args     Arguments passed to the template. Passed by reference.
  12       */
  13      do_action_ref_array( 'gp_pre_tmpl_load', array( $template, &$args ) );
  14      require_once GP_TMPL_PATH . 'helper-functions.php';
  15      $locations = array( GP_TMPL_PATH );
  16      if ( ! is_null( $template_path ) ) {
  17          array_unshift( $locations, untrailingslashit( $template_path ) . '/' );
  18      }
  19  
  20      /**
  21       * Filter the locations to load template files from.
  22       *
  23       * @since 1.0.0
  24       *
  25       * @param array       $locations     File paths of template locations.
  26       * @param string      $template      The template name.
  27       * @param array       $args          Arguments passed to the template.
  28       * @param string|null $template_path Priority template location, if any.
  29       */
  30      $locations = apply_filters( 'gp_tmpl_load_locations', $locations, $template, $args, $template_path );
  31      if ( isset( $args['http_status'] ) ) {
  32          status_header( $args['http_status'] );
  33      }
  34      foreach ( $locations as $location ) {
  35          $file = $location . "$template.php";
  36          if ( is_readable( $file ) ) {
  37              extract( $args, EXTR_SKIP );
  38              include $file;
  39              break;
  40          }
  41      }
  42  
  43      /**
  44       * Fires after a template was loaded.
  45       *
  46       * @since 1.0.0
  47       *
  48       * @param string $template The template name.
  49       * @param array  $args     Arguments passed to the template. Passed by reference.
  50       */
  51      do_action_ref_array( 'gp_post_tmpl_load', array( $template, &$args ) );
  52  }
  53  
  54  /**
  55   * Retrieves content of a template via output buffering.
  56   *
  57   * @since 1.0.0
  58   *
  59   * @see gp_tmpl_load()
  60   *
  61   * @param mixed ...$args Arguments to be passed to gp_tmpl_load().
  62   * @return string|false
  63   */
  64  function gp_tmpl_get_output( ...$args ) {
  65      ob_start();
  66      gp_tmpl_load( ...$args );
  67      return ob_get_clean();
  68  }
  69  
  70  function gp_tmpl_header( $args = array() ) {
  71      gp_tmpl_load( 'header', $args );
  72  }
  73  
  74  function gp_tmpl_footer( $args = array() ) {
  75      gp_tmpl_load( 'footer', $args );
  76  }
  77  
  78  function gp_head() {
  79      /**
  80       * Fires inside the head element on the header template.
  81       *
  82       * @since 1.0.0
  83       */
  84      do_action( 'gp_head' );
  85  }
  86  
  87  function gp_footer() {
  88      /**
  89       * Fires at the end of the page, on the footer template.
  90       *
  91       * @since 1.0.0
  92       */
  93      do_action( 'gp_footer' );
  94  }
  95  
  96  function gp_nav_menu( $location = 'main' ) {
  97      $html  = '';
  98      $items = gp_nav_menu_items( $location );
  99  
 100      // Get the current URI.
 101      $current_uri = str_replace( home_url(), '', gp_url_current() );
 102  
 103      foreach ( $items as $link => $title ) {
 104          // Check if the link matches the current URI base, if true, add 'current' class.
 105          $class = gp_startswith( $current_uri, $link ) ? 'current' : '';
 106          $html .= '<a class="' . $class . '" href="' . $link . '">' . $title . '</a>';
 107      }
 108  
 109      return $html;
 110  }
 111  
 112  function gp_nav_menu_items( $location = 'main' ) {
 113      $items = array();
 114  
 115      if ( 'main' === $location ) {
 116          $items[ gp_url( '/projects' ) ]  = __( 'Projects', 'glotpress' );
 117          $items[ gp_url( '/languages' ) ] = __( 'Locales', 'glotpress' );
 118      } elseif ( 'side' === $location ) {
 119          if ( is_user_logged_in() ) {
 120              $user = wp_get_current_user();
 121              $items[ gp_url_profile( $user->user_nicename ) ]       = __( 'Profile', 'glotpress' );
 122              $items[ gp_url( '/settings' ) ]                        = __( 'Settings', 'glotpress' );
 123              $items[ esc_url( wp_logout_url( gp_url_current() ) ) ] = __( 'Log out', 'glotpress' );
 124          } else {
 125              $items[ esc_url( wp_login_url( gp_url_current() ) ) ] = __( 'Log in', 'glotpress' );
 126          }
 127      }
 128  
 129      /**
 130       * Filter the list of navigation menu items.
 131       *
 132       * @since 1.0.0
 133       *
 134       * @param array  $items    Menu items. URL as the key, menu label as the value.
 135       * @param string $location Location of the menu.
 136       */
 137      return apply_filters( 'gp_nav_menu_items', $items, $location );
 138  }
 139  
 140  function gp_tmpl_filter_args( $args ) {
 141      $clean_args = array();
 142      foreach ( $args as $k => $v ) {
 143          if ( '_' != $k[0] && 'GLOBALS' != $k && ! gp_startswith( $k, 'HTTP' ) && ! gp_startswith( $k, 'PHP' ) ) {
 144              $clean_args[ $k ] = $v;
 145          }
 146      }
 147      return $clean_args;
 148  }
 149  
 150  function gp_tmpl_404( $args = array() ) {
 151      gp_tmpl_load(
 152          '404',
 153          $args + array(
 154              'title'       => __( 'Not Found', 'glotpress' ),
 155              'http_status' => 404,
 156          )
 157      );
 158      exit();
 159  }
 160  
 161  function gp_title( $title = null ) {
 162      if ( ! is_null( $title ) ) {
 163          add_filter(
 164              'gp_title',
 165              function() use ( $title ) {
 166                  return $title;
 167              },
 168              5
 169          );
 170      } else {
 171  
 172          /**
 173           * Filter the title of a page.
 174           *
 175           * @since 1.0.0
 176           *
 177           * @param string $title The title of a page.
 178           */
 179          return apply_filters( 'gp_title', '' );
 180      }
 181  }
 182  
 183  function gp_breadcrumb( $breadcrumb = null, $args = array() ) {
 184      if ( $breadcrumb ) {
 185          $breadcrumb = gp_array_flatten( $breadcrumb );
 186  
 187          add_filter(
 188              'gp_breadcrumb_items',
 189              function( $breadcrumbs ) use ( $breadcrumb ) {
 190                  return array_merge( $breadcrumbs, $breadcrumb );
 191              },
 192              1
 193          );
 194      } else {
 195  
 196          /**
 197           * Filter the list of breadcrumb navigation items.
 198           *
 199           * @since 1.0.0
 200           *
 201           * @param array $breadcrumb_items Breadcrumb items as HTML string.
 202           */
 203          $breadcrumbs = apply_filters( 'gp_breadcrumb_items', array() );
 204  
 205          if ( $breadcrumbs ) {
 206              $defaults = array(
 207                  /* translators: separates links in the navigation breadcrumb */
 208                  'before'              => '<li>',
 209                  'after'               => '</li>',
 210                  'breadcrumb-template' => '<ul class="breadcrumb">{breadcrumb}</ul>',
 211              );
 212  
 213              $args = array_merge( $defaults, $args );
 214  
 215              $whole_breadcrumb = '';
 216  
 217              foreach ( $breadcrumbs as $breadcrumb ) {
 218                  $whole_breadcrumb .= $args['before'] . $breadcrumb . $args['after'];
 219              }
 220  
 221              $whole_breadcrumb = str_replace( '{breadcrumb}', $whole_breadcrumb, $args['breadcrumb-template'] );
 222  
 223              /**
 224               * Filter the breadcrumb HTML output.
 225               *
 226               * @since 1.0.0
 227               *
 228               * @param string $whole_breadcrumb Breadcrumb HTML.
 229               */
 230              return apply_filters( 'gp_breadcrumb', $whole_breadcrumb );
 231          }
 232      }
 233  }
 234  
 235  function gp_project_names_from_root( $leaf_project ) {
 236      $names          = array();
 237      $path_from_root = array_reverse( $leaf_project->path_to_root() );
 238  
 239      foreach ( $path_from_root as $project ) {
 240          $names[] = esc_html( $project->name );
 241      }
 242  
 243      $project_path = implode( ' | ', $names );
 244  
 245      return $project_path;
 246  }
 247  
 248  function gp_project_links_from_root( $leaf_project ) {
 249      if ( 0 === $leaf_project->id ) {
 250          return array();
 251      }
 252      $links          = array();
 253      $path_from_root = array_reverse( $leaf_project->path_to_root() );
 254      $links[]        = empty( $path_from_root ) ? __( 'Projects', 'glotpress' ) : gp_link_get( gp_url( '/projects' ), __( 'Projects', 'glotpress' ) );
 255      foreach ( $path_from_root as $project ) {
 256          $links[] = gp_link_project_get( $project, esc_html( $project->name ) );
 257      }
 258      return $links;
 259  }
 260  
 261  function gp_breadcrumb_project( $project ) {
 262      return gp_breadcrumb( gp_project_links_from_root( $project ) );
 263  }
 264  
 265  function gp_js_focus_on( $html_id ) {
 266      return '<script type="text/javascript">document.getElementById(\'' . esc_js( $html_id ) . '\').focus();</script>';
 267  }
 268  
 269  function gp_select( $name_and_id, $options, $selected_key, $attrs = array() ) {
 270      $attributes = gp_html_attributes( $attrs );
 271      $attributes = $attributes ? " $attributes" : '';
 272      $res        = "<select name='" . esc_attr( $name_and_id ) . "' id='" . esc_attr( $name_and_id ) . "' $attributes>\n";
 273      $labels     = array(
 274          'hidden' => _x( 'hidden', 'Priority', 'glotpress' ),
 275          'low'    => _x( 'low', 'Priority', 'glotpress' ),
 276          'normal' => _x( 'normal', 'Priority', 'glotpress' ),
 277          'high'   => _x( 'high', 'Priority', 'glotpress' ),
 278      );
 279      foreach ( $options as $value => $label ) {
 280          if ( isset( $labels[ $label ] ) ) {
 281              $label = $labels[ $label ];
 282          }
 283          $selected = selected( $value, $selected_key, false );
 284          $res     .= "\t<option value='" . esc_attr( $value ) . "'$selected>" . esc_html( $label ) . "</option>\n";
 285      }
 286      $res .= "</select>\n";
 287      return $res;
 288  }
 289  
 290  function gp_radio_buttons( $name, $radio_buttons, $checked_key ) {
 291      $res = '';
 292      foreach ( $radio_buttons as $value => $label ) {
 293          $checked = checked( $value, $checked_key, false );
 294          // TODO: something more flexible than <br />
 295          $res .= "\t<input type='radio' id='" . esc_attr( "{$name}[{$value}]" ) . "' name='" . esc_attr( $name ) . "' value='" . esc_attr( $value ) . "'$checked/>&nbsp;";
 296          $res .= "<label for='" . esc_attr( "{$name}[{$value}]" ) . "'>" . esc_html( $label ) . "</label><br />\n";
 297      }
 298      return $res;
 299  }
 300  
 301  function gp_pagination( $page, $per_page, $objects ) {
 302      $surrounding = 2;
 303      $first       = $prev_dots = $prev_pages = $next_pages = $next_dots = $last = '';
 304      $page        = intval( $page ) ? intval( $page ) : 1;
 305      $pages       = ceil( $objects / $per_page );
 306      if ( $page > $pages ) {
 307          return '';
 308      }
 309  
 310      if ( $page > 1 ) {
 311          $prev = gp_link_get( add_query_arg( array( 'page' => $page - 1 ) ), '&larr;', array( 'class' => 'previous' ) );
 312      } else {
 313          $prev = '<span class="previous disabled">&larr;</span>';
 314      }
 315  
 316      if ( $page < $pages ) {
 317          $next = gp_link_get( add_query_arg( array( 'page' => $page + 1 ) ), '&rarr;', array( 'class' => 'next' ) );
 318      } else {
 319          $next = '<span class="next disabled">&rarr;</span>';
 320      }
 321  
 322      $current = '<span class="current">' . $page . '</span>';
 323      if ( $page > 1 ) {
 324          $prev_pages = array();
 325          foreach ( range( max( 1, $page - $surrounding ), $page - 1 ) as $prev_page ) {
 326              $prev_pages[] = gp_link_get( add_query_arg( array( 'page' => $prev_page ) ), $prev_page );
 327          }
 328          $prev_pages = implode( ' ', $prev_pages );
 329          if ( $page - $surrounding > 1 ) {
 330              $prev_dots = '<span class="dots">&hellip;</span>';
 331          }
 332      }
 333      if ( $page < $pages ) {
 334          $next_pages = array();
 335          foreach ( range( $page + 1, min( $pages, $page + $surrounding ) ) as $next_page ) {
 336              $next_pages[] = gp_link_get( add_query_arg( array( 'page' => $next_page ) ), $next_page );
 337          }
 338          $next_pages = implode( ' ', $next_pages );
 339          if ( $page + $surrounding < $pages ) {
 340              $next_dots = '<span class="dots">&hellip;</span>';
 341          }
 342      }
 343      if ( $prev_dots ) {
 344          $first = gp_link_get( add_query_arg( array( 'page' => 1 ) ), 1 );
 345      }
 346      if ( $next_dots ) {
 347          $last = gp_link_get( add_query_arg( array( 'page' => $pages ) ), $pages );
 348      }
 349  
 350      $html = <<<HTML
 351      <div class="paging">
 352          $prev
 353          $first
 354          $prev_dots
 355          $prev_pages
 356          $current
 357          $next_pages
 358          $next_dots
 359          $last
 360          $next
 361      </div>
 362  HTML;
 363  
 364      /**
 365       * Filter the pagination HTML output.
 366       *
 367       * @since 1.0.0
 368       *
 369       * @param string $html     The pagination HTML.
 370       * @param int    $page     Current page number.
 371       * @param int    $per_page Objects per page.
 372       * @param int    $objects  Total number of objects to page.
 373       */
 374      return apply_filters( 'gp_pagination', $html, $page, $per_page, $objects );
 375  }
 376  
 377  function gp_html_attributes( $attrs ) {
 378      $attrs   = wp_parse_args( $attrs );
 379      $strings = array();
 380      foreach ( $attrs as $key => $value ) {
 381          $strings[] = $key . '="' . esc_attr( $value ) . '"';
 382      }
 383      return implode( ' ', $strings );
 384  }
 385  
 386  function gp_attrs_add_class( $attrs, $class_name ) {
 387      $attrs['class'] = isset( $attrs['class'] ) ? $attrs['class'] . ' ' . $class_name : $class_name;
 388      return $attrs;
 389  }
 390  
 391  /**
 392   * Returns HTML markup for a select element for all locales of a project.
 393   *
 394   * @since 1.0.0
 395   *
 396   * @param int    $project_id    ID of a project.
 397   * @param string $name_and_id   Name and ID of the select element.
 398   * @param string $selected_slug Slug of the current selected locale.
 399   * @param array  $attrs         Extra attributes.
 400   *
 401   * @return string HTML markup for a select element.
 402   */
 403  function gp_locales_by_project_dropdown( $project_id, $name_and_id, $selected_slug = null, $attrs = array() ) {
 404      $locales = GP_Locales::locales();
 405      if ( null != $project_id ) {
 406          $sets = GP::$translation_set->by_project_id( $project_id );
 407  
 408          $temp_locales = array();
 409  
 410          foreach ( $sets as $set ) {
 411              $temp_locales[ $set->locale ] = $locales[ $set->locale ];
 412          }
 413  
 414          if ( count( $temp_locales ) > 0 ) {
 415              $locales = $temp_locales;
 416          }
 417      }
 418      ksort( $locales );
 419  
 420      $options = array( '' => __( '&mdash; Locale &mdash;', 'glotpress' ) );
 421      foreach ( $locales as $key => $locale ) {
 422          $options[ $key ] = sprintf( '%s &mdash; %s', $locale->slug, $locale->english_name );
 423      }
 424  
 425      return gp_select( $name_and_id, $options, $selected_slug, $attrs );
 426  }
 427  
 428  /**
 429   * Returns HTML markup for a select element for all locales.
 430   *
 431   * @since 1.0.0
 432   *
 433   * @param string $name_and_id   Name and ID of the select element.
 434   * @param string $selected_slug Slug of the current selected locale.
 435   * @param array  $attrs         Extra attributes.
 436   *
 437   * @return string HTML markup for a select element.
 438   */
 439  function gp_locales_dropdown( $name_and_id, $selected_slug = null, $attrs = array() ) {
 440      return gp_locales_by_project_dropdown( null, $name_and_id, $selected_slug, $attrs );
 441  }
 442  
 443  /**
 444   * Returns HTML markup for a select element for projects.
 445   *
 446   * @since 1.0.0
 447   *
 448   * @param string $name_and_id         Name and ID of the select element.
 449   * @param string $selected_project_id The project id to mark as the currently selected.
 450   * @param array  $attrs               Extra attributes.
 451   * @param array  $exclude             An array of project IDs to exclude from the list.
 452   * @param array  $exclude_no_parent   Exclude the "No Parent" option from the list of projects.
 453   *
 454   * @return string HTML markup for a select element.
 455   */
 456  function gp_projects_dropdown( $name_and_id, $selected_project_id = null, $attrs = array(), $exclude = array(), $exclude_no_parent = false ) {
 457      if ( ! is_array( $exclude ) ) {
 458          $exclude = array( $exclude );
 459      }
 460  
 461      $projects = GP::$project->all();
 462      // TODO: mark which nodes are editable by the current user
 463      $tree = array();
 464      $top  = array();
 465      foreach ( $projects as $p ) {
 466          $tree[ $p->id ]['self'] = $p;
 467          if ( $p->parent_project_id ) {
 468              $tree[ $p->parent_project_id ]['children'][] = $p->id;
 469          } else {
 470              $top[] = $p->id;
 471          }
 472      }
 473  
 474      if ( ! $exclude_no_parent ) {
 475          $options = array( '' => __( '&mdash; No parent &mdash;', 'glotpress' ) );
 476      } else {
 477          $options = array();
 478      }
 479  
 480      foreach ( $top as $top_id ) {
 481          $stack = array( $top_id );
 482  
 483          while ( ! empty( $stack ) ) {
 484              $id = array_pop( $stack );
 485  
 486              if ( in_array( $id, $exclude, true ) ) {
 487                  continue;
 488              }
 489  
 490              $tree[ $id ]['level'] = gp_array_get( $tree[ $id ], 'level', 0 );
 491              $options[ $id ]       = str_repeat( '-', $tree[ $id ]['level'] ) . $tree[ $id ]['self']->name;
 492              foreach ( gp_array_get( $tree[ $id ], 'children', array() ) as $child_id ) {
 493                  $stack[]                    = $child_id;
 494                  $tree[ $child_id ]['level'] = $tree[ $id ]['level'] + 1;
 495              }
 496          }
 497      }
 498  
 499      return gp_select( $name_and_id, $options, $selected_project_id, $attrs );
 500  }
 501  
 502  function gp_array_of_things_to_json( $array ) {
 503      return wp_json_encode(
 504          array_map(
 505              function( $thing ) {
 506                  return $thing->fields();
 507              },
 508              $array
 509          )
 510      );
 511  }
 512  
 513  function gp_array_of_array_of_things_to_json( $array ) {
 514      $map_to_fields = function( $array ) {
 515          return array_map(
 516              function( $thing ) {
 517                  return $thing->fields();
 518              },
 519              $array
 520          );
 521      };
 522  
 523      return wp_json_encode( array_map( $map_to_fields, $array ) );
 524  }
 525  
 526  function things_to_fields( $data ) {
 527      if ( is_array( $data ) ) {
 528          foreach ( $data as $item_id => $item ) {
 529              $data[ $item_id ] = things_to_fields( $item );
 530          }
 531      } elseif ( $data instanceof GP_Thing ) {
 532          $data = $data->fields();
 533      }
 534  
 535      return $data;
 536  }
 537  
 538  function gp_preferred_sans_serif_style_tag( $locale ) {
 539      if ( ! $locale->preferred_sans_serif_font_family ) {
 540          return;
 541      }
 542  
 543      ?>
 544  <style type="text/css">
 545      .foreign-text {
 546          font-family: "<?php echo esc_attr( $locale->preferred_sans_serif_font_family ); ?>", inherit;
 547      }
 548  </style>
 549      <?php
 550  }
 551  
 552  function gp_html_excerpt( $str, $count, $ellipsis = '&hellip;' ) {
 553      $excerpt = trim( wp_html_excerpt( $str, $count ) );
 554      if ( $str != $excerpt ) {
 555          $excerpt .= $ellipsis;
 556      }
 557      return $excerpt;
 558  }
 559  
 560  function gp_checked( $checked ) {
 561      if ( $checked ) {
 562          echo 'checked="checked"';
 563      }
 564  }
 565  
 566  function gp_project_actions( $project, $translation_sets ) {
 567      $actions = array(
 568          gp_link_get( gp_url_project( $project, 'import-originals' ), __( 'Import Originals', 'glotpress' ) ),
 569          gp_link_get( gp_url_project( $project, array( '-permissions' ) ), __( 'Permissions', 'glotpress' ) ),
 570          gp_link_get( gp_url_project( '', '-new', array( 'parent_project_id' => $project->id ) ), __( 'New Sub-Project', 'glotpress' ) ),
 571          gp_link_get( gp_url( '/sets/-new', array( 'project_id' => $project->id ) ), __( 'New Translation Set', 'glotpress' ) ),
 572          gp_link_get( gp_url_project( $project, array( '-mass-create-sets' ) ), __( 'Mass-create Translation Sets', 'glotpress' ) ),
 573          gp_link_get( gp_url_project( $project, '-branch' ), __( 'Branch project', 'glotpress' ) ),
 574          gp_link_get( gp_url_project( $project, '-delete' ), __( 'Delete project', 'glotpress' ) ),
 575      );
 576  
 577      /**
 578       * Project action links.
 579       *
 580       * @since 1.0.0
 581       *
 582       * @param array      $actions Links as HTML strings.
 583       * @param GP_Project $project The project.
 584       */
 585      $actions = apply_filters( 'gp_project_actions', $actions, $project );
 586  
 587      echo '<ul>';
 588  
 589      foreach ( $actions as $action ) {
 590          // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
 591          echo '<li>' . $action . '</li>';
 592      }
 593  
 594      if ( $translation_sets ) {
 595          echo '<li>' . gp_project_options_form( $project ) . '</li>';
 596      }
 597  
 598      echo '</ul>';
 599  }
 600  
 601  function gp_project_options_form( $project ) {
 602      return '
 603              <a href="#" class="personal-options" id="personal-options-toggle"> ' . __( 'Personal project options', 'glotpress' ) . ' &darr;</a>
 604              <div class="personal-options">
 605                  <form action="' . gp_url_project( $project, '-personal' ) . '" method="post">
 606                  <dl>
 607                      <dt><label for="source-url-template">' . __( 'Source file URL', 'glotpress' ) . '</label></dt>
 608                      <dd>
 609                          <input type="text" value="' . esc_html( $project->source_url_template() ) . '" name="source-url-template" id="source-url-template" />
 610                          <small>' . sprintf(
 611                              /* translators: 1: %file%, 2: %line%, 3: https://trac.example.org/browser/%file%#L%line% */
 612                              __( 'URL to a source file in the project. You can use %1$s and %2$s. Ex. %3$s', 'glotpress' ),
 613                              '<code>%file%</code>',
 614                              '<code>%line%</code>',
 615                              '<code>https://trac.example.org/browser/%file%#L%line%</code>'
 616                          ) . '</small>
 617                      </dd>
 618                  </dl>
 619                  <div class="button-group">
 620                      <input class="button is-primary" type="submit" name="submit" value="' . esc_attr__( 'Save', 'glotpress' ) . '" id="save" />
 621                      <a class="button is-link" href="#" onclick="jQuery(\'#personal-options-toggle\').click();return false;">' . __( 'Cancel', 'glotpress' ) . '</a>
 622                  </div>
 623                  ' . gp_route_nonce_field( 'set-personal-options_' . $project->id, false ) . '
 624                  </form>
 625              </div>';
 626  }
 627  
 628  function gp_entry_actions( $seperator = ' &bull; ' ) {
 629      $actions = array(
 630          '<div class="button-group entry-actions"><button type="button" class="button is-small copy" tabindex="-1" title="' . __( 'Copy the original string to the translation area (overwrites existing text).', 'glotpress' ) . '">' . __( 'Copy from original', 'glotpress' ) . '</button> ' .
 631          '<button type="button"  class="button is-small inserttab" tabindex="-1" title="' . __( 'Insert tab (\t) at the current cursor position.', 'glotpress' ) . '">' . __( 'Insert tab', 'glotpress' ) . '</button> ' .
 632          '<button type="button" class="button is-small insertnl" tabindex="-1" title="' . __( 'Insert newline (\n) at the current cursor position.', 'glotpress' ) . '">' . __( 'Insert newline', 'glotpress' ) . '</button></div>',
 633      );
 634  
 635      /**
 636       * Filters entry action links.
 637       *
 638       * @since 1.0.0
 639       *
 640       * @param array $actions Links as HTML strings.
 641       */
 642      $actions = apply_filters( 'gp_entry_actions', $actions );
 643  
 644      // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
 645      echo implode( $seperator, $actions );
 646  }
 647  
 648  /**
 649   * Generates a list of classes to be added to the translation row, based on translation entry properties.
 650   *
 651   * @since 2.2.0
 652   *
 653   * @param Translation_Entry $translation The translation entry object for the row.
 654   *
 655   * @return array
 656   */
 657  function gp_get_translation_row_classes( $translation ) {
 658      $classes   = array();
 659      $classes[] = $translation->translation_status ? 'status-' . $translation->translation_status : 'untranslated';
 660      $classes[] = 'priority-' . gp_array_get( GP::$original->get_static( 'priorities' ), $translation->priority );
 661      $classes[] = $translation->warnings ? 'has-warnings' : 'no-warnings';
 662      $classes[] = count( array_filter( $translation->translations, 'gp_is_not_null' ) ) > 0 ? 'has-translations' : 'no-translations';
 663  
 664      /**
 665       * Filters the list of CSS classes for a translation row
 666       *
 667       * @since 2.2.0
 668       *
 669       * @param array             $classes     An array of translation row classes.
 670       * @param Translation_Entry $translation The translation entry object.
 671       */
 672      $classes = apply_filters( 'gp_translation_row_classes', $classes, $translation );
 673  
 674      return $classes;
 675  }
 676  
 677  /**
 678   * Outputs space separated list of classes for the translation row, based on translation entry properties.
 679   *
 680   * @since 2.2.0
 681   *
 682   * @param Translation_Entry $translation The translation entry object for the row.
 683   *
 684   * @return void
 685   */
 686  function gp_translation_row_classes( $translation ) {
 687      $classes = gp_get_translation_row_classes( $translation );
 688      echo esc_attr( implode( ' ', $classes ) );
 689  }


Generated: Sun May 29 01:01:08 2022 Cross-referenced by PHPXref 0.7.1