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

/auto_linker/pi.auto_linker.php

https://github.com/capeta/Auto-Linker
PHP | 150 lines | 69 code | 30 blank | 51 comment | 6 complexity | d3f37376cd8860727dfb9576cfd2fbf8 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /*
  3. Copyright (C) 2004 - 2012 EllisLab, Inc.
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. ELLISLAB, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. Except as contained in this notice, the name of EllisLab, Inc. shall not be
  19. used in advertising or otherwise to promote the sale, use or other dealings
  20. in this Software without prior written authorization from EllisLab, Inc.
  21. */
  22. $plugin_info = array(
  23. 'pi_name' => 'Auto Linker',
  24. 'pi_version' => '2.0',
  25. 'pi_author' => 'EllisLab',
  26. 'pi_author_url' => 'http://www.ellislab.com/',
  27. 'pi_description' => 'Automatically creates links from URLs and/or email addresses contained within the given text.',
  28. 'pi_usage' => Auto_linker::usage()
  29. );
  30. /**
  31. * Auto_linker Class
  32. *
  33. * @package ExpressionEngine
  34. * @category Plugin
  35. * @author ExpressionEngine Dev Team
  36. * @copyright Copyright (c) 2004 - 2011, EllisLab, Inc.
  37. * @link http://expressionengine.com/downloads/details/auto_linker/
  38. */
  39. class Auto_linker {
  40. var $return_data;
  41. /**
  42. * Constructor
  43. *
  44. * @access public
  45. * @return void
  46. */
  47. function Auto_linker($str = '')
  48. {
  49. $this->EE =& get_instance();
  50. $this->EE->load->helper('url');
  51. $str = ($str == '') ? $this->EE->TMPL->tagdata : $str;
  52. // Parameter to determine whether to convert only
  53. // URLs, email addresses, or both.
  54. $convert = ($this->EE->TMPL->fetch_param('convert') == 'url' OR $this->EE->TMPL->fetch_param('convert') == 'email') ? $this->EE->TMPL->fetch_param('convert') : 'both';
  55. // Parameter to determine whether link opens in a new window.
  56. $pop = ($this->EE->TMPL->fetch_param('target') == 'blank') ? TRUE : FALSE;
  57. $str = auto_link($str, $convert, $pop);
  58. $this->return_data = $str;
  59. }
  60. // --------------------------------------------------------------------
  61. /**
  62. * Usage
  63. *
  64. * Plugin Usage
  65. *
  66. * @access public
  67. * @return string
  68. */
  69. function usage()
  70. {
  71. ob_start();
  72. ?>
  73. =====================================================
  74. Example
  75. =====================================================
  76. Wrap the text to be formatted within the plugin tags, like so:
  77. {exp:auto_linker}
  78. text you want processed
  79. {/exp:auto_linker}
  80. or...
  81. {exp:auto_linker}
  82. {custom_field}
  83. {/exp:auto_linker}
  84. Note: Mailto links created for email addresses use an obfuscated version of the mailto tag containing ordinal numbers written with JavaScript to help prevent the email address from being harvested by spam bots.
  85. =====================================================
  86. Optional Parameters
  87. =====================================================
  88. target="blank"
  89. - Links will open in a new window.
  90. convert=""
  91. - Set to "url" to only convert URLs.
  92. - Set to "email" to only convert email addresses.
  93. Version 2.0
  94. ******************
  95. - Simplified plugin to use the auto_link() function from CodeIgniter's URL helper.
  96. - New optional parameter to choose to auto-link only URLs or email addresses.
  97. Version 1.1
  98. ******************
  99. - Updated plugin to be 2.0 compatible
  100. <?php
  101. $buffer = ob_get_contents();
  102. ob_end_clean();
  103. return $buffer;
  104. }
  105. // --------------------------------------------------------------------
  106. }
  107. // END CLASS
  108. /* End of file pi.auto_linker.php */
  109. /* Location: ./system/expressionengine/third_party/auto_linker/pi.auto_linker.php */