PageRenderTime 53ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/contentmanager/code/trunk/administrator/components/com_contentmanager/libraries/jxtended/form/helper.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 135 lines | 75 code | 16 blank | 44 comment | 13 complexity | 17ac00261a80ffc0d0378954c7a194ea MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: helper.php 160 2009-07-09 00:06:09Z eddieajau $
  4. * @package JXtended.Libraries
  5. * @subpackage Form
  6. * @copyright Copyright (C) 2008 - 2009 JXtended, LLC. All rights reserved.
  7. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  8. * @link http://jxtended.com
  9. */
  10. defined('JPATH_BASE') or die;
  11. if (!defined('JPATH_JXPRO_FORMS')) {
  12. define('JPATH_JXPRO_FORMS', dirname(__FILE__));
  13. }
  14. /**
  15. * @package JXtended.Libraries
  16. * @subpackage Forms
  17. */
  18. class JXFormHelper
  19. {
  20. /**
  21. * Add a directory where Formilo should search for additional resources
  22. *
  23. * @access public
  24. * @param string A path to search.
  25. * @return array An array with directory elements
  26. * @since 1.5
  27. */
  28. function addIncludePath($path=null)
  29. {
  30. static $paths;
  31. if (!isset($paths)) {
  32. $paths = array(JPATH_JXPRO_FORMS);
  33. }
  34. // just force path to array
  35. settype($path, 'array');
  36. if (!empty($path) && !in_array($path, $paths))
  37. {
  38. // loop through the path directories
  39. foreach ($path as $dir)
  40. {
  41. // no surrounding spaces allowed!
  42. $dir = trim($dir);
  43. // add to the top of the search dirs
  44. //array_unshift($paths, $dir);
  45. $paths[] = $dir;
  46. }
  47. }
  48. return $paths;
  49. }
  50. /**
  51. * @param string A file name
  52. * @param string An optional subfolder
  53. */
  54. function find($file, $subfolder='')
  55. {
  56. foreach (JXFormHelper::addIncludePath() as $path)
  57. {
  58. $path .= $subfolder.DS.$file;
  59. if (file_exists($path)) {
  60. return $path;
  61. }
  62. }
  63. return null;
  64. }
  65. /**
  66. * @param string The form id
  67. */
  68. function &getView($id = '')
  69. {
  70. static $instances = null;
  71. if ($instances == null) {
  72. $instances = array();
  73. }
  74. if (!isset($instances[$id]))
  75. {
  76. // load the dependancies
  77. require_once(JPATH_JXPRO_FORMS.DS.'view.php');
  78. $instances[$id] = new JXFormView();
  79. if ($file = JXFormHelper::find($id.'.xml', DS.'forms'))
  80. {
  81. $instances[$id]->loadFormFile($file);
  82. $instances[$id]->setId($id);
  83. }
  84. foreach (JXFormHelper::addIncludePath() as $path) {
  85. // TODO: This is a bit dickie
  86. $instances[$id]->addFieldFolder($path.DS.'fields');
  87. }
  88. //else {
  89. // $instances[$id] = JError::raiseWarning(404, 'Form '.$id.' not found');
  90. //}
  91. }
  92. return $instances[$id];
  93. }
  94. /**
  95. * @param string The form id
  96. */
  97. function &getModel($id='')
  98. {
  99. static $instances = null;
  100. if ($instances == null) {
  101. $instances = array();
  102. }
  103. if (!isset($instances[$id]))
  104. {
  105. // load the dependancies
  106. require_once(JPATH_JXPRO_FORMS.DS.'model.php');
  107. $instances[$id] = new JXFormModel();
  108. if ($file = JXFormHelper::find($id.'.xml', DS.'forms'))
  109. {
  110. $instances[$id]->loadFormFile($file);
  111. $instances[$id]->setId($id);
  112. }
  113. //else {
  114. // $instances[$id] = JError::raiseWarning(404, 'Form '.$id.' not found');
  115. //}
  116. }
  117. return $instances[$id];
  118. }
  119. }