first commit
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class WPML_TM_Post_Edit_Link_Anchor
|
||||
*
|
||||
* Creates post links with a given anchor text, pointing at the back-end
|
||||
* post edit view
|
||||
*/
|
||||
class WPML_TM_Post_Edit_Link_Anchor extends WPML_TM_Post_Link_Anchor {
|
||||
|
||||
protected function link_target() {
|
||||
|
||||
return $this->sitepress->get_wp_api()->get_edit_post_link( $this->post_id );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
abstract class WPML_TM_Post_Link_Anchor extends WPML_TM_Post_Link {
|
||||
|
||||
/** @var string $anchor */
|
||||
private $anchor;
|
||||
|
||||
/** @var string $target */
|
||||
private $target;
|
||||
|
||||
/**
|
||||
* WPML_TM_Post_Link_Anchor constructor.
|
||||
*
|
||||
* @param SitePress $sitepress
|
||||
* @param int $post_id
|
||||
* @param string $anchor
|
||||
* @param string $target
|
||||
*/
|
||||
public function __construct( SitePress $sitepress, $post_id, $anchor, $target = '' ) {
|
||||
parent::__construct( $sitepress, $post_id );
|
||||
$this->anchor = $anchor;
|
||||
$this->target = $target;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$post = $this->sitepress->get_wp_api()->get_post( $this->post_id );
|
||||
|
||||
return ! $post
|
||||
|| ( in_array( $post->post_status,
|
||||
array( 'draft', 'private', 'trash' ), true )
|
||||
&& $post->post_author != $this->sitepress->get_wp_api()
|
||||
->get_current_user_id() )
|
||||
? '' : sprintf( '<a href="%s"%s>%s</a>',
|
||||
esc_url( $this->link_target() ),
|
||||
$this->target ? ' target="' . $this->target . '"' : '',
|
||||
esc_html( $this->anchor ) );
|
||||
}
|
||||
|
||||
protected abstract function link_target();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class WPML_TM_Post_Link_Factory
|
||||
*
|
||||
* Creates post links for the TM dashboard and the translation queue
|
||||
*/
|
||||
class WPML_TM_Post_Link_Factory {
|
||||
|
||||
/** @var SitePress $sitepress */
|
||||
private $sitepress;
|
||||
|
||||
public function __construct( SitePress $sitepress ) {
|
||||
$this->sitepress = $sitepress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the front end, link text is the post title
|
||||
*
|
||||
* @param int $post_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function view_link( $post_id ) {
|
||||
|
||||
return (string) ( new WPML_TM_Post_View_Link_Title( $this->sitepress,
|
||||
(int) $post_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the front end, link text is given by the anchor
|
||||
*
|
||||
* @param int $post_id
|
||||
* @param string $anchor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function view_link_anchor( $post_id, $anchor, $target = '' ) {
|
||||
|
||||
return (string) ( new WPML_TM_Post_View_Link_Anchor( $this->sitepress,
|
||||
(int) $post_id, $anchor, $target ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the backend, link text is given by the anchor
|
||||
*
|
||||
* @param int $post_id
|
||||
* @param string $anchor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function edit_link_anchor( $post_id, $anchor ) {
|
||||
|
||||
return (string) ( new WPML_TM_Post_Edit_Link_Anchor( $this->sitepress,
|
||||
(int) $post_id, $anchor ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
abstract class WPML_TM_Post_Link {
|
||||
|
||||
/** @var SitePress $sitepress */
|
||||
protected $sitepress;
|
||||
|
||||
/** @var int $post */
|
||||
protected $post_id;
|
||||
|
||||
/**
|
||||
* WPML_TM_Post_Link constructor.
|
||||
*
|
||||
* @param SitePress $sitepress
|
||||
* @param int $post_id
|
||||
*/
|
||||
public function __construct( $sitepress, $post_id ) {
|
||||
$this->sitepress = $sitepress;
|
||||
$this->post_id = $post_id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class WPML_TM_Post_View_Link_Anchor
|
||||
*
|
||||
* Creates post links with a given anchor text, pointing at the front-end
|
||||
* post view
|
||||
*/
|
||||
class WPML_TM_Post_View_Link_Anchor extends WPML_TM_Post_Link_Anchor {
|
||||
|
||||
protected function link_target() {
|
||||
|
||||
return $this->sitepress->get_wp_api()->get_permalink( $this->post_id );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class WPML_TM_Post_View_Link_Title
|
||||
*
|
||||
* Creates post links with the post title as anchor text, pointing at the front-end
|
||||
* post view
|
||||
*/
|
||||
class WPML_TM_Post_View_Link_Title extends WPML_TM_Post_View_Link_Anchor {
|
||||
|
||||
public function __construct( &$sitepress, $post_id ) {
|
||||
parent::__construct( $sitepress, $post_id,
|
||||
$sitepress->get_wp_api()->get_the_title( $post_id ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user