PageRenderTime 66ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/html/AppCode/expressionengine/models/design_model.php

https://github.com/w3bg/www.hsifin.com
PHP | 160 lines | 81 code | 34 blank | 45 comment | 20 complexity | ab8bc170de27db4ad5668db126810f74 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author ExpressionEngine Dev Team
  7. * @copyright Copyright (c) 2003 - 2010, EllisLab, Inc.
  8. * @license http://expressionengine.com/user_guide/license.html
  9. * @link http://expressionengine.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Design Model
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Core
  19. * @category Model
  20. * @author ExpressionEngine Dev Team
  21. * @link http://expressionengine.com
  22. */
  23. class Design_model extends CI_Model {
  24. function Design_model()
  25. {
  26. parent::CI_Model();
  27. $this->EE =& get_instance();
  28. }
  29. // ------------------------------------------------------------------------
  30. function fetch_templates()
  31. {
  32. $this->db->select(array('t.template_id', 't.group_id', 't.template_name', 't.template_type', 't.cache', 't.refresh', 't.no_auth_bounce', 't.enable_http_auth', 't.allow_php', 't.php_parse_location', 't.hits', 'tg.group_name'));
  33. $this->db->from('templates AS t');
  34. $this->db->join('template_groups AS tg', 'tg.group_id = t.group_id');
  35. $this->db->where('t.site_id', $this->config->item('site_id'));
  36. $this->db->order_by('t.group_id, t.template_name', 'ASC');
  37. // add in search terms if necessary
  38. if (($keywords = trim($this->input->post('template_keywords'))) != FALSE)
  39. {
  40. // note that search helper sanitize_search_terms() is intentionally not used here
  41. // since users may want to search for tags, javascript etc. Terms are escaped
  42. // before used in queries, and are converted to entities for display
  43. $terms = array();
  44. if (preg_match_all("/\-*\"(.*?)\"/", $keywords, $matches))
  45. {
  46. for($m=0; $m < sizeof($matches['1']); $m++)
  47. {
  48. $terms[] = trim(str_replace('"','',$matches['0'][$m]));
  49. $keywords = str_replace($matches['0'][$m],'', $keywords);
  50. }
  51. }
  52. if (trim($keywords) != '')
  53. {
  54. $terms = array_merge($terms, preg_split("/\s+/", trim($keywords)));
  55. }
  56. rsort($terms);
  57. $not_and = (sizeof($terms) > 2) ? ') AND (' : 'AND';
  58. $criteria = 'AND';
  59. $mysql_function = (substr($terms['0'], 0,1) == '-') ? 'NOT LIKE' : 'LIKE';
  60. $search_term = (substr($terms['0'], 0,1) == '-') ? substr($terms['0'], 1) : $terms['0'];
  61. // We have two parentheses in the beginning in case
  62. // there are any NOT LIKE's being used
  63. $sql = "\n (t.template_data $mysql_function '%".$this->db->escape_like_str($search_term)."%' ";
  64. for ($i=1; $i < sizeof($terms); $i++)
  65. {
  66. if (trim($terms[$i]) == '') continue;
  67. $mysql_criteria = ($mysql_function == 'NOT LIKE' OR substr($terms[$i], 0,1) == '-') ? $not_and : $criteria;
  68. $mysql_function = (substr($terms[$i], 0,1) == '-') ? 'NOT LIKE' : 'LIKE';
  69. $search_term = (substr($terms[$i], 0,1) == '-') ? substr($terms[$i], 1) : $terms[$i];
  70. $sql .= "$mysql_criteria t.template_data $mysql_function '%".$this->db->escape_like_str($search_term)."%' ";
  71. }
  72. $sql .= ") \n";
  73. $this->db->where($sql, NULL, FALSE);
  74. }
  75. $vars['search_terms'] = ($keywords == '') ? FALSE : htmlentities(implode(',', $terms));
  76. $vars['no_results'] = FALSE;
  77. $this->load->vars($vars);
  78. return $this->db->get();
  79. }
  80. // ------------------------------------------------------------------------
  81. /**
  82. * Fetch Templates in a specified group
  83. *
  84. *
  85. *
  86. *
  87. *
  88. */
  89. function export_tmpl_group($tmpl_group = FALSE)
  90. {
  91. $this->db->select('template_groups.group_name, templates.template_name,
  92. templates.template_data, templates.template_type, templates.edit_date');
  93. $this->db->from('templates');
  94. $this->db->join('template_groups', 'template_groups.group_id = templates.group_id');
  95. if ($tmpl_group)
  96. {
  97. $this->db->where('template_groups.group_id', str_replace('template_group_', '', $tmpl_group));
  98. }
  99. $this->db->where('templates.site_id', $this->config->item('site_id'));
  100. $query = $this->db->get();
  101. if ($query->num_rows() == 0)
  102. {
  103. return FALSE;
  104. }
  105. return $query->result_array();
  106. }
  107. // ------------------------------------------------------------------------
  108. /**
  109. * Template Access Restrictions
  110. *
  111. * @return array
  112. */
  113. function template_access_restrictions()
  114. {
  115. $this->db->select('member_group, template_id');
  116. $no_access = $this->db->get('template_no_access');
  117. $denied_groups = array();
  118. foreach($no_access->result() as $row)
  119. {
  120. $denied_groups[$row->template_id][$row->member_group] = TRUE;
  121. }
  122. return $denied_groups;
  123. }
  124. }
  125. /* End of file design_model.php */
  126. /* Location: ./system/expressionengine/models/design_model.php */