PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/system/cms/modules/streams_core/controllers/ajax.php

https://github.com/gsake/pyrocms
PHP | 172 lines | 84 code | 34 blank | 54 comment | 6 complexity | b3f0b1b611f5e36c32edfe9d0ad860ce MD5 | raw file
Possible License(s): CC-BY-3.0, BSD-3-Clause, CC0-1.0, MIT
  1. <?php defined('BASEPATH') or exit('No direct script access allowed');
  2. /**
  3. * PyroStreams AJAX Controller
  4. *
  5. * @package PyroCMS\Core\Modules\Streams Core\Controllers
  6. * @author Parse19
  7. * @copyright Copyright (c) 2011 - 2012, Parse19
  8. * @license http://parse19.com/pyrostreams/docs/license
  9. * @link http://parse19.com/pyrostreams
  10. */
  11. class Ajax extends Admin_Controller {
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. // No matter what we don't show the profiler
  16. // in our AJAX calls.
  17. $this->output->enable_profiler(FALSE);
  18. // We need this for all of the variable setups in
  19. // the Type library __construct
  20. $this->load->library('streams_core/Type');
  21. // Only AJAX gets through!
  22. if ( ! $this->input->is_ajax_request())
  23. {
  24. die('Invalid request.');
  25. }
  26. }
  27. // --------------------------------------------------------------------------
  28. /**
  29. * Get our build params
  30. *
  31. * Accessed via AJAX
  32. *
  33. * @access public
  34. * @return void
  35. */
  36. public function build_parameters()
  37. {
  38. // Out for certain characters
  39. if ($this->input->post('data') == '-') return null;
  40. $this->load->language('streams_core/pyrostreams');
  41. $type = $this->input->post('data');
  42. $namespace = $this->input->post('namespace');
  43. // Load paramaters
  44. require_once(APPPATH.'modules/streams_core/libraries/Parameter_fields.php');
  45. $parameters = new Parameter_fields();
  46. // Load the proper class
  47. $field_type = $this->type->load_single_type($type);
  48. // I guess we don't have any to show.
  49. if ( ! isset($field_type->custom_parameters)) return null;
  50. // Otherwise, the beat goes on.
  51. $extra_fields = $field_type->custom_parameters;
  52. $data['count'] = 0;
  53. //Echo them out
  54. foreach ($extra_fields as $field)
  55. {
  56. // Check to see if it is a standard one or a custom one
  57. // from the field type
  58. if (method_exists($parameters, $field))
  59. {
  60. $data['input'] = $parameters->$field();
  61. $data['input_name'] = $this->lang->line('streams.'.$field);
  62. }
  63. elseif (method_exists($field_type, 'param_'.$field))
  64. {
  65. $call = 'param_'.$field;
  66. $input = $field_type->$call(null, $namespace);
  67. if (is_array($input))
  68. {
  69. $data['input'] = $input['input'];
  70. $data['instructions'] = $input['instructions'];
  71. }
  72. else
  73. {
  74. $data['input'] = $input;
  75. $data['instructions'] = null;
  76. }
  77. $data['input_name'] = $this->lang->line('streams.'.$field_type->field_type_slug.'.'.$field);
  78. }
  79. else
  80. {
  81. return false;
  82. }
  83. $data['input_slug'] = $field;
  84. echo $this->load->view('extra_field', $data, true);
  85. $data['count']++;
  86. }
  87. }
  88. // --------------------------------------------------------------------------
  89. /**
  90. * Update the field order
  91. *
  92. * Accessed via AJAX
  93. *
  94. * @access public
  95. * @return void
  96. */
  97. public function update_field_order()
  98. {
  99. $ids = explode(',', $this->input->post('order'));
  100. // Set the count by the offset for
  101. // paginated lists
  102. $order_count = $this->input->post('offset')+1;
  103. foreach ($ids as $id)
  104. {
  105. $this->db
  106. ->where('id', $id)
  107. ->update('data_field_assignments', array('sort_order' => $order_count));
  108. $order_count++;
  109. }
  110. }
  111. // --------------------------------------------------------------------------
  112. /**
  113. * Update the entries order
  114. *
  115. * Accessed via AJAX
  116. *
  117. * @access public
  118. * @return void
  119. */
  120. public function ajax_entry_order_update()
  121. {
  122. // Get the stream from the ID
  123. $this->load->model('streams_core/streams_m');
  124. $stream = $this->streams_m->get_stream($this->input->post('stream_id'));
  125. $ids = explode(',', $this->input->post('order'));
  126. // Set the count by the offset for
  127. // paginated lists
  128. $order_count = $this->input->post('offset')+1;
  129. foreach ($ids as $id)
  130. {
  131. $this->db
  132. ->limit(1)
  133. ->where('id', $id)
  134. ->update($stream->stream_prefix.$stream->stream_slug, array('ordering_count' => $order_count));
  135. ++$order_count;
  136. }
  137. }
  138. }