示例#1
0
 public static function get_edit_post_link($post_id)
 {
     static $caches = [];
     if (!isset($caches[$post_id])) {
         $caches[$post_id] = esc_url(theme_custom_contribution::get_tabs('post')['url'] . '&post=' . $post_id);
     }
     return $caches[$post_id];
 }
示例#2
0
/**
 * Post form
 *
 * @return 
 * @version 1.0.0
 */
function post_form($post_id = null)
{
    $edit = false;
    $post_title = null;
    $post_content = null;
    $post_excerpt = null;
    /**
     * edit
     */
    if (is_numeric($post_id)) {
        /**
         * check post exists
         */
        global $post;
        $post = theme_cache::get_post($post_id);
        if (!$post || !theme_custom_contribution::in_edit_post_status($post->post_status) || $post->post_type !== 'post') {
            ?>
			<div class="page-tip"><?php 
            echo status_tip('error', ___('Sorry, the post does not exist.'));
            ?>
</div>
			<?php 
            wp_reset_postdata();
            return false;
        }
        /**
         * check post category in collection category
         */
        if (class_exists('theme_custom_collection') && !empty(theme_custom_collection::get_cat_ids())) {
            foreach (get_the_category($post_id) as $v) {
                if (in_array($v->term_id, theme_custom_collection::get_cat_ids())) {
                    ?>
					<div class="page-tip"><?php 
                    echo status_tip('error', ___('Sorry, collection edits feature is not supported currently.'));
                    ?>
</div>
					<?php 
                    wp_reset_postdata();
                    return false;
                }
                break;
            }
        }
        /**
         * check author
         */
        if ($post->post_author != theme_cache::get_current_user_id()) {
            ?>
			<div class="page-tip"><?php 
            echo status_tip('error', ___('Sorry, you are not the post author, can not edit it.'));
            ?>
</div>
			<?php 
            return false;
            wp_reset_postdata();
        }
        setup_postdata($post);
        /**
         * check edit lock status
         */
        $lock_user_id = theme_custom_contribution::wp_check_post_lock($post_id);
        if ($lock_user_id) {
            ?>
			<div class="page-tip"><?php 
            echo status_tip('error', ___('Sorry, you can not edit this post now, because editor is editing. Please wait a minute...'));
            ?>
</div>
			<?php 
            return false;
        }
        $edit = true;
        $post_title = $post->post_title;
        $post_content = $post->post_content;
        $post_excerpt = stripslashes($post->post_excerpt);
    }
    ?>
	
	<?php 
    echo theme_custom_contribution::get_des();
    ?>
	<div id="fm-ctb-loading" class="page-tip"><?php 
    echo status_tip('loading', ___('Loading, please wait...'));
    ?>
</div>
	<form action="javascript:;" id="fm-ctb" class="form-horizontal" hidden>
		<div class="form-group">
			<label for="ctb-title" class="g-tablet-1-6 control-label">
				<?php 
    echo ___('Post title');
    ?>
			</label>
			<div class="g-tablet-5-6">
				<input 
					type="text" 
					name="ctb[post-title]"
					class="form-control" 
					id="ctb-title" 
					placeholder="<?php 
    echo ___('Post title (require)');
    ?>
" 
					title="<?php 
    echo ___('Post title must to write');
    ?>
" 
					value="<?php 
    echo esc_attr($post_title);
    ?>
" 
					required 
					autofocus
				>
			</div>
		</div>
		<!-- post excerpt -->
		<div class="form-group">
			<label for="ctb-excerpt" class="g-tablet-1-6 control-label">
				<?php 
    echo ___('Post excerpt');
    ?>
			</label>
			<div class="g-tablet-5-6">
				<textarea name="ctb[post-excerpt]" id="ctb-excerpt" rows="3" class="form-control" placeholder="<?php 
    echo ___('Your can write excerpt for describe the post, it will show every page nagination header.');
    ?>
"><?php 
    echo $post_excerpt;
    ?>
</textarea>
			</div>
		</div>
		<!-- post content -->
		<div class="form-group">
			<div class="g-tablet-1-1">
			<label for="ctb-content" >
				<?php 
    echo ___('Post content');
    ?>
			</label>
				<?php 
    wp_editor($post_content, 'ctb-content', ['textarea_name' => 'ctb[post-content]', 'drag_drop_upload' => false, 'teeny' => false, 'media_buttons' => false, 'editor_class' => 'form-control']);
    ?>
			</div>
		</div>
		
		
		<!-- upload image -->
		<div class="form-group">
			<div class="g-tablet-1-6 control-label">
				<i class="fa fa-image"></i>
				<?php 
    echo ___('Upload preview image');
    ?>
			</div>
			<div class="g-tablet-5-6">
				<div id="ctb-file-area">
					<div class="" id="ctb-file-btn">
						<i class="fa fa-upload"></i>
						<?php 
    echo ___('Select or Drag images');
    ?>
						<input type="file" id="ctb-file" multiple >
					</div>
				</div>
				<!-- upload progress -->
				<div id="ctb-file-progress-container" class="progress">
					<div id="ctb-file-progress" class="progress-bar progress-bar-success progress-bar-striped active"></div>
				</div>
				
				<!-- file tool -->
				<div id="ctb-file-tool" class="row">
					<div class="g-tablet-1-2">
					<!-- batch insert -->
						<a href="javascript:;" id="ctb-batch-insert-btn" class="btn btn-primary btn-block">
							<i class="fa fa-plug"></i> <?php 
    echo ___('Batch insert images to content');
    ?>
						</a>
					</div>
					<div class="g-tablet-1-2">
						<select id="ctb-split-number" class="form-control" title="<?php 
    echo ___('How many images to split with next-page tag?');
    ?>
">
							<option value="0"><?php 
    echo ___('Do not use next-page tag');
    ?>
</option>
							<?php 
    for ($i = 1; $i <= 10; ++$i) {
        ?>
								<option value="<?php 
        echo $i;
        ?>
"><?php 
        echo sprintf(___('%d image(s) / page'), $i);
        ?>
</option>
							<?php 
    }
    ?>
						</select>
					</div>
				</div>

				
				<!-- file completion -->
				<div id="ctb-file-completion"></div>

				
				<!-- files -->
				<div id="ctb-files" class="row"></div>
				
			</div>
		</div>

		
<!-- storage -->
<?php 
    if (class_exists('theme_custom_storage') && theme_custom_storage::is_enabled()) {
        ?>
	<div class="form-group theme_custom_storage-group">
		<div class="g-tablet-1-6 control-label">
			<i class="fa fa-cloud-download"></i>
			<?php 
        echo ___('Storage link');
        ?>
		</div>
		<div class="g-tablet-5-6">
			<?php 
        echo theme_custom_storage::display_frontend_contribution($post_id);
        ?>
		</div>
	</div>
<?php 
        /**
         * end theme_custom_storage
         */
    }
    ?>
		



		<!-- cats -->
		<div class="form-group">
			<div class="g-tablet-1-6 control-label">
				<i class="fa fa-folder-open"></i>
				<?php 
    echo ___('Category');
    ?>
			</div>
			<div class="g-tablet-5-6" id="ctb-cat-container">
				<?php 
    if ($edit) {
        $selected_cat_id = 0;
        $cats = get_the_category($post->ID);
        if (isset($cats[0]->term_id)) {
            $selected_cat_id = $cats[0]->term_id;
        }
        foreach ($cats as $cat) {
            if ($cat->parent != 0) {
                $selected_cat_id = $cat->term_id;
            }
        }
        wp_dropdown_categories(['id' => 'ctb-cat', 'name' => 'ctb[cat]', 'class' => 'form-control', 'selected' => $selected_cat_id, 'show_option_none' => ___('Select category'), 'hierarchical' => true, 'hide_empty' => false, 'include' => (array) theme_custom_contribution::get_cat_ids()]);
    }
    ?>
			</div>
		</div>





		
		<!-- tags -->
		<div class="form-group">
			<div class="g-tablet-1-6 control-label">
				<i class="fa fa-tags"></i> 
				<?php 
    echo ___('Pop. tags');
    ?>
			</div>
			<div class="g-tablet-5-6">
				<div class="checkbox-select">
					<?php 
    $tags_args = ['orderby' => 'count', 'order' => 'desc', 'hide_empty' => 0, 'number' => theme_custom_contribution::get_options('tags-number') ? theme_custom_contribution::get_options('tags-number') : 16];
    $tags_ids = theme_custom_contribution::get_options('tags');
    if (empty($tag_ids)) {
        $tags = get_tags($tags_args);
    } else {
        $tags = get_tags(['include' => implode($tags_ids), 'orderby' => 'count', 'order' => 'desc', 'hide_empty' => 0]);
    }
    /**
     * edit
     */
    if ($edit) {
        $exist_tags = [];
        $post_tags = get_the_tags($post->ID);
        if ($post_tags) {
            foreach ($post_tags as $v) {
                $v->selected = true;
                array_unshift($tags, $v);
            }
        }
    }
    foreach ($tags as $tag) {
        if ($edit) {
            if (isset($exist_tags[$tag->term_id])) {
                continue;
            } else {
                $exist_tags[$tag->term_id] = 1;
            }
        }
        $tag_name = esc_html($tag->name);
        ?>
						<label class="ctb-tag" for="ctb-tags-<?php 
        echo $tag->term_id;
        ?>
">
							<input 
								class="ctb-preset-tag" 
								type="checkbox" 
								id="ctb-tags-<?php 
        echo $tag->term_id;
        ?>
" 
								name="ctb[tags][]" 
								value="<?php 
        echo $tag_name;
        ?>
"
								hidden 
								<?php 
        echo isset($tag->selected) ? 'checked' : null;
        ?>
							>
							<span class="label label-default">
								<?php 
        echo $tag_name;
        ?>
							</span>
						</label>
						
					<?php 
    }
    ?>
				</div>
			</div>
		</div>
		
		<!-- custom tags -->
		<div class="form-group">
			<div class="g-tablet-1-6 control-label">
				<i class="fa fa-tag"></i> 
				<?php 
    echo ___('Custom tags');
    ?>
			</div>
			<div class="g-tablet-5-6">
				<div class="row">
					<?php 
    for ($i = 0; $i <= 3; ++$i) {
        ?>
						<div class="g-phone-1-2 g-tablet-1-4">
							<input id="ctb-custom-tag-<?php 
        echo $i;
        ?>
" class="ctb-custom-tag form-control" type="text" name="ctb[tags][]" placeholder="<?php 
        echo sprintf(___('Custom tag %d'), $i + 1);
        ?>
" >
						</div>
					<?php 
    }
    ?>
				</div>
			</div>
		</div>


		<!-- source -->
		<?php 
    if (class_exists('theme_custom_post_source') && theme_custom_post_source::is_enabled()) {
        if ($edit) {
            $post_source_meta = theme_custom_post_source::get_post_meta($post->ID);
        } else {
            $post_source_meta = null;
        }
        ?>
			<div class="form-group">
				<div class="g-tablet-1-6 control-label">
					<i class="fa fa-truck"></i> 
					<?php 
        echo ___('Source');
        ?>
				</div>
				<div class="g-tablet-5-6">
					<label class="radio-inline" for="theme_custom_post_source-source-original">
						<input 
							type="radio" 
							name="theme_custom_post_source[source]" 
							id="theme_custom_post_source-source-original" 
							value="original" 
							class="theme_custom_post_source-source-radio" 
							<?php 
        echo !isset($post_source_meta['source']) || $post_source_meta['source'] === 'original' ? 'checked' : null;
        ?>
 
							target="theme_custom_post_source-input-original" 
						>
						<?php 
        echo ___('Original');
        ?>
					</label>
					<label class="radio-inline" for="theme_custom_post_source-source-reprint">
						<input 
							type="radio" 
							name="theme_custom_post_source[source]" 
							id="theme_custom_post_source-source-reprint" 
							value="reprint" 
							class="theme_custom_post_source-source-radio" 
							<?php 
        echo isset($post_source_meta['source']) && $post_source_meta['source'] === 'reprint' ? 'checked' : null;
        ?>
 
							target="theme_custom_post_source-input-reprint" 
						>
						<?php 
        echo ___('Reprint');
        ?>
					</label>
					<div class="row theme_custom_post_source-inputs" id="theme_custom_post_source-input-reprint" >
						<div class="g-tablet-1-2">
							<div class="input-group">
								<label class="addon" for="theme_custom_post_source-reprint-url">
									<i class="fa fa-link"></i>
								</label>
								<input 
									type="url" 
									class="form-control" 
									name="theme_custom_post_source[reprint][url]" 
									id="theme_custom_post_source-reprint-url" 
									placeholder="<?php 
        echo ___('The source of work URL, includes http://');
        ?>
" 
									title="<?php 
        echo ___('The source of work URL, includes http://');
        ?>
"
									value="<?php 
        echo isset($post_source_meta['reprint']['url']) ? $post_source_meta['reprint']['url'] : null;
        ?>
"
								>
							</div>
						</div>
						<div class="g-tablet-1-2">
							<div class="input-group">
								<label class="addon" for="theme_custom_post_source-reprint-author">
									<i class="fa fa-user"></i>
								</label>
								<input 
									type="text" 
									class="form-control" 
									name="theme_custom_post_source[reprint][author]" 
									id="theme_custom_post_source-reprint-author" 
									placeholder="<?php 
        echo ___('Author');
        ?>
" 
									title="<?php 
        echo ___('Author');
        ?>
"
									value="<?php 
        echo isset($post_source_meta['reprint']['author']) ? esc_attr($post_source_meta['reprint']['author']) : null;
        ?>
"
								>
							</div>
						</div>
					</div>
				</div>
			</div>
		<?php 
    }
    /** end theme_custom_post_source */
    ?>

		
		<!-- submit -->
		<div class="form-group">
			<div class="g-tablet-1-6">
				<a href="javascript:;" id="ctb-quick-save" class="btn btn-block btn-default btn-lg" title="<?php 
    echo ___('The post data will be saved automatically per minute in your current borwser, you can also save it now manually.');
    ?>
">
					<i class="fa fa-save"></i> <?php 
    echo ___('Quick save');
    ?>
				</a>
			</div>
			<div class="g-tablet-5-6">
				
				<button type="submit" class="btn btn-lg btn-success btn-block submit" data-loading-text="<?php 
    echo ___('Sending, please wait...');
    ?>
">
					<i class="fa fa-check"></i> 
					<?php 
    echo $edit ? ___('Update') : ___('Submit');
    ?>
				</button>
				<input type="hidden" id="ctb-post-id" name="post-id" value="<?php 
    echo $edit ? $post->ID : 0;
    ?>
">
				<input type="hidden" name="type" value="post">
			</div>
		</div>
	</form>
	<?php 
    wp_reset_postdata();
}
示例#3
0
 /**
  * action_add_history_core_transition_post_status_post_publish
  *
  * @param int Post id
  * @param object Post
  * @version 1.0.1
  */
 public static function action_add_history_core_post_publish($post_id, $post)
 {
     /** if published, do not add point and history */
     if (class_exists('theme_custom_contribution') && theme_custom_contribution::is_once_published($edit_post_id)) {
         return false;
     }
     $meta = array('type' => 'post-publish', 'post-id' => $post_id, 'timestamp' => current_time('timestamp'));
     /**
      * add to history
      */
     self::add_history($post->post_author, $meta);
     /**
      * update point
      */
     /**
      * if is not post type, return false
      */
     if ($post->post_type !== 'post') {
         return false;
     }
     $old_point = self::get_point($post->post_author);
     update_user_meta($post->post_author, self::$user_meta_key['point'], $old_point + (int) theme_options::get_options(__CLASS__)['points']['post-publish']);
 }