Created
May 4, 2012 15:34
-
-
Save objectivehtml/2595553 to your computer and use it in GitHub Desktop.
Safecracker HTML5 Attributes Extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* ExpressionEngine - by EllisLab | |
* | |
* @package ExpressionEngine | |
* @author ExpressionEngine Dev Team | |
* @copyright Copyright (c) 2003 - 2011, EllisLab, Inc. | |
* @license http://expressionengine.com/user_guide/license.html | |
* @link http://expressionengine.com | |
* @since Version 2.0 | |
* @filesource | |
*/ | |
// ------------------------------------------------------------------------ | |
/** | |
* Safecracker HTML5 Attributes Extension | |
* | |
* @package ExpressionEngine | |
* @subpackage Addons | |
* @category Extension | |
* @author Justin Kimbrell | |
* @link http://www.objectivehtml.com | |
*/ | |
class Safecracker_attributes_ext { | |
public $settings = array(); | |
public $description = 'Add HTML5 form attributes to the available Safecracker Parameters.'; | |
public $docs_url = ''; | |
public $name = 'Safecracker Attributes'; | |
public $settings_exist = 'n'; | |
public $version = '1.0'; | |
private $EE, $obj, $params; | |
/** | |
* Constructor | |
* | |
* @param mixed Settings array or empty string if none exist. | |
*/ | |
public function __construct($settings = '') | |
{ | |
$this->EE =& get_instance(); | |
$this->settings = $settings; | |
}// ---------------------------------------------------------------------- | |
/** | |
* Activate Extension | |
* | |
* This function enters the extension into the exp_extensions table | |
* | |
* @see http://codeigniter.com/user_guide/database/index.html for | |
* more information on the db class. | |
* | |
* @return void | |
*/ | |
public function activate_extension() | |
{ | |
// Setup custom settings in this array. | |
$this->settings = array(); | |
$data = array( | |
'class' => __CLASS__, | |
'method' => 'safecracker_entry_form_tagdata_end', | |
'hook' => 'safecracker_entry_form_tagdata_end', | |
'settings' => serialize($this->settings), | |
'version' => $this->version, | |
'enabled' => 'y' | |
); | |
$this->EE->db->insert('extensions', $data); | |
} | |
// ---------------------------------------------------------------------- | |
/** | |
* Disable Extension | |
* | |
* This method removes information from the exp_extensions table | |
* | |
* @return void | |
*/ | |
function disable_extension() | |
{ | |
$this->EE->db->where('class', __CLASS__); | |
$this->EE->db->delete('extensions'); | |
} | |
// ---------------------------------------------------------------------- | |
/** | |
* Update Extension | |
* | |
* This function performs any necessary db updates when the extension | |
* page is visited | |
* | |
* @return mixed void on update / false if none | |
*/ | |
function update_extension($current = '') | |
{ | |
if ($current == '' OR $current == $this->version) | |
{ | |
return FALSE; | |
} | |
} | |
// ---------------------------------------------------------------------- | |
public function safecracker_entry_form_tagdata_end($tagdata, &$obj) | |
{ | |
$this->obj =& $obj; | |
$params = array( | |
'autocomplete', | |
'novalidate' | |
); | |
foreach($params as $param) | |
{ | |
if($value = $this->param($param, FALSE)) | |
{ | |
$tagdata = str_replace('<form ', '<form '.$param.'="'.$value.'" ', $tagdata); | |
} | |
} | |
return $tagdata; | |
} | |
private function param($param, $default = FALSE, $boolean = FALSE, $required = FALSE) | |
{ | |
$name = $param; | |
$param = $this->obj->EE->TMPL->fetch_param($param); | |
if($required && !$param) show_error('You must define a "'.$name.'" parameter in the '.__CLASS__.' tag.'); | |
if($param === FALSE && $default !== FALSE) | |
{ | |
$param = $default; | |
} | |
else | |
{ | |
if($boolean) | |
{ | |
$param = strtolower($param); | |
$param = ($param == 'true' || $param == 'yes') ? TRUE : FALSE; | |
} | |
} | |
return $param; | |
} | |
} | |
/* End of file ext.safecracker_attributes.php */ | |
/* Location: /system/expressionengine/third_party/safecracker_attributes/ext.safecracker_attributes.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment