public function get_tree_species($current_page = 0, $filters, $sort = null)
 {
     if ($current_page == 0) {
         $current_page = $this->current_page;
     } else {
         $this->current_page = $current_page;
     }
     $where = '';
     $filters = $this->check_filters($filters);
     if ($filters) {
         $where = $this->get_where('p', $filters);
     }
     //p is the table name in this query
     //use the ForestDbQuery get_default_sort() to create an empty sort
     $sort = $this->check_sort($sort);
     if ($sort) {
         $sort = $sort->sort_col_id . ' ' . $sort->sort_dir;
     } else {
         $sort = 'post_title ASC';
     }
     $limit = ' LIMIT ' . $this->item_per_page . ' OFFSET ' . ($current_page - 1) * $this->item_per_page;
     $sql = "SELECT SQL_CALC_FOUND_ROWS p.ID, p.post_title\n\t             \tFROM " . $this->table_name . ' p' . " WHERE p.post_status = 'publish' AND p.post_type='" . $this->tree_species_type . '\'' . $where . " ORDER BY " . $sort . $limit;
     ForestHelperSingleton::get_instance()->write_log($sql);
     $this->items = $this->select($sql);
     //get posts
     $this->rows_found = $this->get_var('SELECT FOUND_ROWS()');
     //get over all rows(pagination)
     $this->max_num_pages = ceil($this->rows_found / $this->item_per_page);
     //calc overall number of pages(pagination)
     return $this->formatted_items('tree-selection');
 }
Пример #2
0
 public function default_map_location()
 {
     //using an stdClass to be compatible with the db extraction method
     $defaults = new stdClass();
     $defaults->address = '';
     $defaults->lat = FOREST_LAT_DEFAULT;
     $defaults->lng = FOREST_LNG_DEFAULT;
     $location = self::get_default_option('forest_map_default_location', $defaults);
     try {
         //if we got a string representation from the db {"":,""} turn to php array
         if (!is_object($location)) {
             $location = json_decode($location);
         }
     } catch (Exception $e) {
         $location = null;
         ForestHelperSingleton::get_instance()->write_log('Error reading location option. Exception: ' . $e->getMessage());
     }
     return $location;
 }
Пример #3
0
 /**
  * Generate a where clause from the given arguments.
  * @param $post_types
  * @param $search_term
  *
  * @return string
  */
 protected function get_where($table_name, $filters)
 {
     $where = ' AND 1=1 ';
     if (is_array($filters)) {
         //check if an array, not empty and does not include empty strings.
         foreach ($filters as $filter) {
             if (!empty($filter['field_id']) && !empty($filter['value'])) {
                 $where .= 'AND ' . $table_name . '.' . $filter['field_id'] . ' LIKE \'%' . esc_sql($filter['value']) . '%\' ';
             } else {
                 ForestHelperSingleton::get_instance()->write_log(sprintf('Empty filter: The field_id or value were missing - function %s got fieldId:"%s" and value:"%s"', __FUNCTION__, $filter['field_id'], $filter['value']));
             }
         }
     }
     return $where;
 }
        public function tree_species_save_meta_box()
        {
            global $post;
            ?>

			<div class="publish">
				<div id="minor-publishing">
					<div class="form-inline">
						<div class="form-group">
							<label for="tree-lock" data-toggle="tooltip" data-placement="left"
							       title="<?php 
            _etts('Lock the tree card so only the owner can make changes');
            ?>
"
							       class="changecolor">
								<?php 
            ForestHelperSingleton::get_instance()->post_lock_icon($post->post_status);
            ?>
								<?php 
            _etts('Locked');
            ?>
:
							</label>

							<?php 
            ForestHelperSingleton::get_instance()->toogle_button('btn-success', 'btn-danger', $post->post_status == 'publish' ? false : true, 'post-lock-btn');
            ForestHelperSingleton::get_instance()->hidden_field('post_title', $post->post_title, array('data-id' => 'post_title'));
            ForestHelperSingleton::get_instance()->hidden_field('post_status', $post->post_status, array('data-id' => 'post_status'));
            ?>

						</div>
					</div>

					<div class="format-setting-label"></div>

					<label for="visibility" data-toggle="tooltip" data-placement="left"
					       title="<?php 
            _etts('Change visibility level');
            ?>
" class="changecolor"><i
							class="fa fa-eye text-danger"></i><?php 
            _etts('Visibility:');
            ?>
</label>
					<div class="form-inline">
						<div class="visibility-radio">
							<?php 
            ForestHelperSingleton::get_instance()->hidden_field('post_visibility', 'public', array('data-meta-id' => 'post_visibility'));
            ?>

							<label class="radio-inline">
								<input type="radio" name="lock-option" value="public" checked="checked"><?php 
            _etts('Public');
            ?>
							</label>
							<label class="radio-inline">
								<input type="radio" name="lock-option"
								       value="contributors"><?php 
            _etts('Contributors');
            ?>
							</label>
							<label class="radio-inline">
								<input type="radio" name="lock-option" value="editors"><?php 
            _etts('Editors');
            ?>
							</label>
						</div>
					</div>

					<div class="format-setting-label"></div>

				</div>
				<div id="major-publishing-actions">
					<div id="delete-action">
						<a class="submitdelete deletion"
						   href="<?php 
            echo get_delete_post_link($post->ID);
            ?>
">Move
							to Trash</a>
					</div>
					<div id="publishing-action">
						<span class="spinner"></span>
						<button id="save-btn" data-action="save" class="btn btn-primary btn-sm"
						        type="button"><?php 
            _etts('Save');
            ?>
</button>
					</div>
					<div class="clear"></div>
				</div>
			</div>
			<?php 
        }
Пример #5
0
 /**
  * Create an object or array from a json string. If an error is detected
  * false is returned and the error is logged if debug logging is enabled.
  *
  * @param $string string a jason string to be converted.
  *
  * @return array|mixed|object
  */
 public function json_decode($string)
 {
     //js adds escape slashes which php json_decode do not like one bit
     $obj = json_decode(stripslashes($string));
     if (json_last_error() !== JSON_ERROR_NONE) {
         ForestHelperSingleton::get_instance()->write_log(sprintf('Error decoding jason string %s. The jason error message was:%s', $string, json_last_error_msg()));
     }
     return $obj;
 }
Пример #6
0
 /**
  * Get a post data from the database.
  * @param bool $only_published
  *
  * @return bool
  */
 private function fetch_plan_from_db($only_published = false)
 {
     global $wpdb;
     if ($this->plan_id <= 0) {
         throw new Exception('Error: Plan id has not been set.');
     }
     if ($only_published) {
         $where = 'p.ID=' . $this->plan_id . ' AND p.post_status="publish"';
     } else {
         $where = 'p.ID=' . $this->plan_id;
     }
     $sql = "SELECT SQL_CALC_FOUND_ROWS *\n\t             \tFROM " . $wpdb->prefix . "posts p " . "WHERE " . $where;
     ForestHelperSingleton::get_instance()->write_log($sql);
     $this->plan = $this->select($sql);
     //get posts
     if (is_array($this->plan)) {
         $this->plan = $this->plan[0];
     }
     $this->rows_found = 1;
     $this->format_plan();
     $this->plan->meta = $this->get_plan_meta();
     return $this->plan;
 }
Пример #7
0
								<div class="col-sm-4 less-padding">
									<span class="help-block"><?php 
_etfm('the owner of this plan');
?>
</span>
								</div>
							</div>

							<div class="form-group">
								<label for="locked" class="col-sm-2 control-label"><?php 
_etfm('Locked');
?>
</label>
								<div class="col-sm-6 less-padding">
									<?php 
ForestHelperSingleton::get_instance()->toogle_button('btn-success', 'btn-danger', true);
?>
								</div>
								<div class="col-sm-4 less-padding">
									<span class="help-block"><?php 
_etfm('if not locked other managers can edit this plan');
?>
</span>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="tab-pane" id="data">