Exemplo n.º 1
0
 public function enter_title($input)
 {
     global $post_type;
     if (is_admin() && self::$post_type == $post_type) {
         return _tfm('Enter Plan name here', 'forest-manager');
     }
     return $input;
 }
 /**
  * PostSelectionModalGenerator init: We have to initiate alll the paramters here and NOT in the constractor
  * because the contractor needs to be called early so the admin_enqueue_scripts fire. Best way is to
  * call the constructor in an admin_init action hook, then when needed fir init.
  *
  * @param $columns array of column 'id' => 'title'
  * @param int $current_page
  * @param array $sort_by array of sorted columns 'column_id' => 'ASC || DESC'
  * @param $post_types array or string of post_types to search from
  * @param $attr array id=>'the modal id', 'row_id'=>'ID by default', 'title' => 'modal title', 'has_filter'=>'show the filter toolbar and call the action - bool'
  *
  * @throws Exception
  */
 public function __construct($columns, $current_page = 1, $sort_by = array('modified' => 'DESC'), $post_types, $attr)
 {
     $defaults = array('id' => 'post-selection-modal', 'row_id' => 'ID', 'title' => _tfm('Title'), 'has_filter' => false, 'ajax' => array('action' => '', 'nounce_id' => ''));
     $defaults = wp_parse_args($attr, $defaults);
     $this->id = $defaults['id'];
     $this->row_id = $defaults['row_id'];
     //need this so we can select a row identifier
     $this->max_num_pages = 0;
     //provided later after the rows where given and the user's query fired.
     $this->current_page = $current_page;
     $this->columns = $columns;
     $this->sort_by = $sort_by;
     //New posts first by default
     $this->has_filter = $defaults['has_filter'];
     $this->title = $defaults['title'];
     $this->post_types = is_string($post_types) ? array($post_types) : $post_types;
     $this->ajax = $attr['ajax'];
     if (empty($this->ajax['action']) || empty($this->ajax['nounce_id'])) {
         throw new Exception('Missing one or more ajax arguments');
     }
 }
Exemplo n.º 3
0
 public function save_tree_card()
 {
     //check nounce and clear buffer
     $data = $this->start_ajax('tree_card_metabox', '_tree-card-nounce');
     try {
         $arguments = array_key_exists('data', $_POST) ? $_POST['data'] : null;
         if ($arguments) {
             $arguments = ForestUtils::get_instance()->json_decode($arguments);
             $arguments = $this->parse_tree_args($arguments);
             $tree_card_id = $arguments['tree_card_id'];
             //2 stdClasses
             $values = $arguments['values'];
             for ($i = 0; $i < count($values); $i++) {
                 if (is_object($values[$i])) {
                     $values[$i] = ForestUtils::get_instance()->objectToArray($values[$i]);
                 }
             }
             $query = new TreeCardDbQuery($tree_card_id);
             $query_result = $query->update_tree_card($values);
             if ($query_result) {
                 $data['message'] = _tfm('Tree card updated');
                 $data['type'] = 'success';
                 $data['action'] = $this->get_ajax_action(__FUNCTION__);
                 //has to match the html tab id
             } else {
                 $data['message'] = _tfm('Tree Card was not updated:') . $query->errors;
                 $data['type'] = 'error';
                 $data['action'] = $this->get_ajax_action(__FUNCTION__);
             }
         } else {
             $data['type'] = 'error';
             $data['message'] = _tfm('Error saving plan');
         }
     } catch (Exception $e) {
         $data['type'] = 'error';
         $data['message'] = _tfm('Error saving plan. Server error was:') . $e->getMessage();
     }
     //add error bufferd to data and json encode
     echo $this->end_ajax($data);
     die;
     // this is required to return a proper result
 }
 private function get_post_status_icon($post_status)
 {
     switch ($post_status) {
         case 'publish':
             return sprintf('<i class="fa fa-unlock text-info" title="%s"></i>', _tfm('Unlocked'));
         case 'pending':
             return sprintf('<i class="fa fa-lock text-danger" title="%s"></i>', _tfm('Locked'));
         case 'draft':
             return sprintf('<i class="fa fa-lock text-danger" title="%s"></i>', _tfm('Locked'));
         default:
             return $post_status;
     }
 }
Exemplo n.º 5
0
 /**
  * Default post types for plan item allowed
  * @return mixed
  */
 public function default_plan_item_post_types()
 {
     $default_post_types = array('tree_card' => _tfm('Tree'), 'street_objects' => _tfm('Street Object'));
     return self::get_default_option('plan_item_post_types', $default_post_types);
 }
        public function tree_card_meta_box()
        {
            global $post;
            //output the nounce field
            wp_nonce_field('tree_card_metabox', '_tree-card-nounce');
            //get tree post meta fields
            $default_meta = array('post_tree_species' => '', 'post_location' => '{"lat":' . FOREST_LAT_DEFAULT . ', "lng":' . FOREST_LNG_DEFAULT . ',"address":"Tel Aviv Israel"}');
            $tree_meta_fields = wp_parse_args(get_post_custom($post->ID), $default_meta);
            //create the tree identification fields
            ?>
			<div id="tree_card_wrapper">

				<!-- Nav tabs -->
				<ul id="tree-card-tabs" class="nav nav-tabs" role="tablist">
					<li role="presentation">&nbsp;</li>
					<li role="presentation" class="active"><a href="#overview"  aria-controls="overview" role="tab" data-toggle="tab"><?php 
            _etfm('Overview');
            ?>
</a></li>
					<li role="presentation"><a href="#activity" aria-controls="activity" role="tab" data-toggle="tab"><?php 
            _etfm('Activity');
            ?>
&nbsp;<span class="badge badge-alert">5</span></a></li>
				</ul>

				<!-- Tab panes -->
				<div class="tab-content">

					<!-- OVERVIEW -->
					<div role="tabpanel" class="tab-pane active in" id="overview">

						<div class="page-header">
							<h1><?php 
            _etfm('Tree Properties');
            ?>
</h1>
						</div>
						<div class="inside">
							<div class="form-horizontal row">
								<!--Tree Species-->
								<div class="form-group">
									<label for="tree-species" class="col-sm-2 control-label"><?php 
            _etfm('Tree Species');
            ?>
</label>
									<div class="col-sm-6 less-padding">
										<div class="input-group">
											<input id="tree-species-name" type="text" class="form-control input-sm" aria-label="..." value="<?php 
            $this->the_display_value('post_tree_species', $tree_meta_fields);
            ?>
">
											<?php 
            ForestHelperSingleton::get_instance()->hidden_field('post_tree_species', $this->get_meta_value('post_tree_species', $tree_meta_fields), array('data-meta-id' => 'post_tree_species'));
            ?>
											<span class="input-group-addon">
												<a data-toggle="modal" data-target="#tree-species-post-selection"><i class="fa fa-list"></i></a>
										    </span>
										</div><!-- input-group -->
									</div>
									<div class="col-sm-4 less-padding">
							            <span class="text-muted help-txt">
							                <?php 
            _etfm('Tree species');
            ?>
							            </span>
									</div>
								</div>

								<!--Location-->
								<div class="form-group">
									<label for="tree-location-select" class="col-sm-2 control-label"><?php 
            _etfm('Location');
            ?>
</label>
									<div class="col-sm-6 less-padding">
										<input id="tree-location-select" type="text" class="form-control input-sm" value="<?php 
            $this->the_display_value('post_location', $tree_meta_fields);
            ?>
"
										       placeholder="<?php 
            _etfm('Tree location');
            ?>
">
										<?php 
            //using id for the google selection to work, and data-meta-id for the value collection to work.
            ForestHelperSingleton::get_instance()->hidden_field('post_location', $this->get_meta_value('post_location', $tree_meta_fields), array('data-meta-id' => 'post_location'));
            ?>
									</div>
									<div class="col-sm-4 less-padding">
										<span class="text-muted help-txt"><?php 
            _etfm('Street address');
            ?>
</span>
									</div>
								</div>

								<!--Serial Number-->
								<div class="form-group">
									<label for="post_tree_number" class="col-sm-2 control-label"><?php 
            _etfm('ID Number');
            ?>
</label>
									<div class="col-sm-6 less-padding">
										<input id="post_tree_number" type="text" class="form-control input-sm" value="<?php 
            $this->the_display_value('post_tree_number', $tree_meta_fields);
            ?>
"
										       placeholder="<?php 
            _etfm('Tree number');
            ?>
">
									</div>
									<div class="col-sm-4 less-padding">
										<span class="text-muted help-txt"><?php 
            _etfm('Your identifier');
            ?>
</span>
									</div>
								</div>

								<!--Year Planted-->
								<div class="form-group">
									<label for="post_tree_year_planted" class="col-sm-2 control-label"><?php 
            _etfm('Year Planted');
            ?>
</label>
									<div class="col-sm-6 less-padding">
										<div class="input-group">
											<input id="post_tree_year_planted" type="text" class="form-control input-sm" value="<?php 
            $this->the_display_value('post_tree_year_planted', $tree_meta_fields);
            ?>
"
										           placeholder="<?php 
            _etfm('Tree planting year');
            ?>
">
											<div class="input-group-addon"><?php 
            _etfm('yyyy');
            ?>
</div>
										</div>
									</div>
									<div class="col-sm-4 less-padding">
										<span class="text-muted help-txt"><?php 
            _etfm('For age estimation');
            ?>
</span>
									</div>
								</div>

								<!--Height-->
								<div class="form-group">
									<label for="post_tree_height" class="col-sm-2 control-label"><?php 
            _etfm('Height');
            ?>
</label>
									<div class="col-sm-6 less-padding">
										<div class="input-group">
											<input id="post_tree_height" type="text" class="form-control input-sm" value="<?php 
            $this->the_display_value('post_tree_height', $tree_meta_fields);
            ?>
"
										           placeholder="<?php 
            _etfm('Tree height');
            ?>
">
											<div class="input-group-addon"><?php 
            _etfm('m');
            ?>
</div>
										</div>
									</div>
									<div class="col-sm-4 less-padding">
										<span class="text-muted help-txt"><?php 
            _etfm('Tree height');
            ?>
</span>
									</div>
								</div>

								<!--Diameter-->
								<div class="form-group">
									<label for="post_tree_diameter" class="col-sm-2 control-label"><?php 
            _etfm('Diameter');
            ?>
</label>
									<div class="col-sm-6 less-padding">
										<div class="input-group">
											<input id="post_tree_diameter" type="text" class="form-control input-sm" value="<?php 
            $this->the_display_value('post_tree_diameter', $tree_meta_fields);
            ?>
"
											       placeholder="<?php 
            _etfm('Tree Diamter');
            ?>
">
											<div class="input-group-addon"><?php 
            _etfm('cm');
            ?>
</div>
										</div>
									</div>
									<div class="col-sm-4 less-padding">
										<span class="text-muted help-txt"><?php 
            _etfm(sprintf('Trunk diameter in %s', _tfm('cm')));
            ?>
</span>
									</div>
								</div>
							</div>

							<div class="page-header">
								<h1><?php 
            _etfm('Description');
            ?>
</h1>
							</div>

							<div class="padded">
								<?php 
            wp_editor($post->post_content, 'post_content', $settings = array());
            ?>
							</div>
						</div>
					</div><!--end overview panel-->

					<div role="tabpanel" class="tab-pane" id="activity">
						<div class="page-header">
							<h1><?php 
            _etfm('Activity');
            ?>
</h1>
						</div>
						<div class="inside">

							<div class="panel-group" id="accordion">
								<div class="panel panel-default">
									<div class="panel-heading">
										<h4 class="panel-title">
											<a data-toggle="collapse" data-parent="#accordion" href="#collapse1">
												Collapsible Group 1</a>
										</h4>
									</div>
									<div id="collapse1" class="panel-collapse collapse in">
										<div class="panel-body">Lorem ipsum dolor sit amet, consectetur adipisicing elit,
											sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
											minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
											commodo consequat.</div>
									</div>
								</div>
								<div class="panel panel-default">
									<div class="panel-heading">
										<h4 class="panel-title">
											<a data-toggle="collapse" data-parent="#accordion" href="#collapse2">
												Collapsible Group 2</a>
										</h4>
									</div>
									<div id="collapse2" class="panel-collapse collapse">
										<div class="panel-body">Lorem ipsum dolor sit amet, consectetur adipisicing elit,
											sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
											minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
											commodo consequat.</div>
									</div>
								</div>
								<div class="panel panel-default">
									<div class="panel-heading">
										<h4 class="panel-title">
											<a data-toggle="collapse" data-parent="#accordion" href="#collapse3">
												Collapsible Group 3</a>
										</h4>
									</div>
									<div id="collapse3" class="panel-collapse collapse">
										<div class="panel-body">Lorem ipsum dolor sit amet, consectetur adipisicing elit,
											sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
											minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
											commodo consequat.</div>
									</div>
								</div>
							</div>

						</div>
					</div>

				</div><!--end tab-content-->
			</div><!--end wrapper-->

			<?php 
            //region -- Create the Modal Dialog for tree type selection
            add_filter('get_modal_post_selection_rows', array($this, 'get_post_selection_rows'), 1);
            add_filter('get_post_selection_modal_page_count', array($this, 'get_post_selection_page_count'));
            add_filter('modal_post_selection_filter', array($this, 'get_modal_post_selection_filter'));
            $columns = array('post_title' => _tfm('Title'), 'img' => _tfm('Image'));
            //parameters for the ajax call needed by the dialog
            $ajax = array('action' => 'tree_species_fetch', 'nounce_id' => '_tree-card-nounce');
            //note that the id needs to be the same as the button data-target attribute above.
            $attr = array('id' => 'tree-species-post-selection', 'row_id' => 'ID', 'title' => _tfm('Select Tree Species'), 'has_filter' => true, 'ajax' => $ajax);
            ForestHelperSingleton::get_instance()->post_selection_modal($columns, 1, array('post_title' => 'ASC'), 'tree_species', $attr);
            remove_filter('get_modal_post_selection_rows', array($this, 'get_post_selection_rows'));
            remove_filter('get_post_selection_modal_page_count', array($this, 'get_post_selection_page_count'));
            remove_filter('modal_post_selection_filter', array($this, 'get_modal_post_selection_filter'));
            //endregion
            //labels for the js client side
            $labels = array('Loading' => _tfm('Loading'), 'Saving' => _tfm('Saving...'));
            //the link back to plan if this tree card was called from a plan
            $plan_id = array_key_exists('plan_id', $_REQUEST) ? $_REQUEST['plan_id'] : '';
            $editPlanUrl = !empty($plan_id) ? get_edit_post_link($plan_id, 'edit') : '';
            ?>

			<script type="application/javascript">
				jQuery(document).ready(function(){
					try {
						var googleAddressBox = new ForestAddressBox('tree-location-select', 'post_location');
						googleAddressBox.init();

						var treeCardMetaBox = new TreeCardMetaboxClass(<?php 
            echo $post->ID;
            ?>
, '<?php 
            echo $editPlanUrl;
            ?>
', <?php 
            echo json_encode($labels);
            ?>
);

						treeCardMetaBox.init();
					}
					catch(e){
						console.log(e.message);
					}
				});
			</script>
			<?php 
        }