jcheron /
phalcon-jquery
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Ajax\bootstrap\html; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Composant Twitter Bootstrap Tabs |
||
| 7 | * |
||
| 8 | * @author jc |
||
| 9 | * @version 1.001 |
||
| 10 | */ |
||
| 11 | use Ajax\bootstrap\html\content\HtmlTabItem; |
||
| 12 | use Ajax\JsUtils; |
||
| 13 | use Ajax\bootstrap\components\Tabs; |
||
| 14 | use Ajax\bootstrap\html\base\HtmlBsDoubleElement; |
||
| 15 | use Ajax\bootstrap\html\content\HtmlTabContent; |
||
| 16 | |||
| 17 | |||
| 18 | class HtmlTabs extends HtmlBsDoubleElement { |
||
| 19 | protected $tabs=array (); |
||
| 20 | protected $_tabsType="tabs"; |
||
| 21 | protected $stacked=""; |
||
| 22 | |||
| 23 | public function __construct($identifier, $tagName="ul") { |
||
| 24 | parent::__construct($identifier, $tagName); |
||
| 25 | $this->_template="<%tagName% %properties%>%tabs%</%tagName%>%content%"; |
||
| 26 | $this->setProperty("class", "nav nav-".$this->_tabsType); |
||
| 27 | } |
||
| 28 | |||
| 29 | protected function addTab_($tab, $index=null) { |
||
| 30 | if($tab instanceof HtmlDropdown){ |
||
| 31 | $tab->setMTagName("li"); |
||
| 32 | } |
||
| 33 | if (isset($index)) { |
||
| 34 | $inserted=array ( |
||
| 35 | $tab |
||
| 36 | ); |
||
| 37 | array_splice($this->tabs, $index, 0, $inserted); |
||
| 38 | } else |
||
| 39 | $this->tabs []=$tab; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function setActive($index){ |
||
| 43 | for ($i=0;$i<sizeof($this->tabs);$i++){ |
||
|
0 ignored issues
–
show
|
|||
| 44 | $this->tabs[$i]->setActive($i==$index); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | public function disable($index){ |
||
| 49 | $this->tabs[$index]->disable(); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function addTab($element, $index=null) { |
||
| 53 | $iid=$this->countTabs()+1; |
||
| 54 | $tab=$element; |
||
| 55 | if (is_string($element)) { |
||
| 56 | $tab=new HtmlTabItem("tab-".$this->identifier."-".$iid, $element); |
||
| 57 | $this->addTab_($tab, $index); |
||
| 58 | } elseif (is_array($element)) { |
||
| 59 | $tab=new HtmlTabItem("tab-".$this->identifier."-".$iid); |
||
| 60 | $tab->fromArray($element); |
||
| 61 | $this->addTab_($tab, $index); |
||
| 62 | } else { |
||
| 63 | $this->addTab_($tab, $index); |
||
| 64 | } |
||
| 65 | return $tab; |
||
| 66 | } |
||
| 67 | |||
| 68 | /* |
||
| 69 | * (non-PHPdoc) |
||
| 70 | * @see \Ajax\bootstrap\html\HtmlSingleElement::fromArray() |
||
| 71 | */ |
||
| 72 | public function fromArray($array) { |
||
| 73 | $array=parent::fromArray($array); |
||
| 74 | $this->addTabs($array); |
||
| 75 | return $array; |
||
| 76 | } |
||
| 77 | |||
| 78 | public function addTabs($tabs) { |
||
| 79 | foreach ( $tabs as $tab ) { |
||
| 80 | $this->addTab($tab); |
||
| 81 | } |
||
| 82 | return $this; |
||
| 83 | } |
||
| 84 | |||
| 85 | public function getTabstype() { |
||
| 86 | return $this->_tabsType; |
||
| 87 | } |
||
| 88 | |||
| 89 | public function setTabstype($_tabsType="tabs") { |
||
| 90 | $this->_tabsType=$_tabsType; |
||
| 91 | return $this; |
||
| 92 | } |
||
| 93 | |||
| 94 | /* |
||
| 95 | * (non-PHPdoc) |
||
| 96 | * @see \Ajax\bootstrap\html\BaseHtml::compile() |
||
| 97 | */ |
||
| 98 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
||
| 99 | $this->setProperty("class", "nav nav-".$this->_tabsType." ".$this->stacked); |
||
| 100 | return parent::compile($js, $view); |
||
| 101 | } |
||
| 102 | |||
| 103 | /* |
||
| 104 | * (non-PHPdoc) |
||
| 105 | * @see \Ajax\bootstrap\html\HtmlDoubleElement::run() |
||
| 106 | */ |
||
| 107 | public function run(JsUtils $js) { |
||
| 108 | $this->_bsComponent=new Tabs($js); |
||
| 109 | foreach ( $this->tabs as $tab ) { |
||
| 110 | $this->_bsComponent->addTab($tab->run($js)); |
||
| 111 | } |
||
| 112 | $this->addEventsOnRun($js); |
||
| 113 | return $this->_bsComponent; |
||
| 114 | } |
||
| 115 | |||
| 116 | public function createTabContents() { |
||
| 117 | $tabContent=new HtmlTabContent("tabcontent-".$this->identifier); |
||
| 118 | foreach ( $this->tabs as $tab ) { |
||
| 119 | if ($tab instanceof HtmlTabItem) |
||
| 120 | $tabContent->addTabItem($tab->getHref()); |
||
| 121 | elseif ($tab instanceof HtmlDropdown) { |
||
| 122 | foreach ( $tab->getItems() as $dropdownItem ) { |
||
| 123 | $tabContent->addTabItem($dropdownItem->getHref()); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 | return $tabContent; |
||
| 128 | } |
||
| 129 | |||
| 130 | public function addTabContents() { |
||
| 131 | $this->content=$this->createTabContents(); |
||
| 132 | } |
||
| 133 | |||
| 134 | public function getTabContent($index) { |
||
| 135 | $this->content->getTabItem($index); |
||
| 136 | } |
||
| 137 | |||
| 138 | public function setContentToTab($index, $text) { |
||
| 139 | $tabContentItem=$this->content->getTabItem($index); |
||
| 140 | if (isset($tabContentItem)) |
||
| 141 | $tabContentItem->setContent($text); |
||
| 142 | } |
||
| 143 | |||
| 144 | public function countTabs() { |
||
| 145 | return sizeof($this->tabs); |
||
| 146 | } |
||
| 147 | |||
| 148 | public function getTabItem($index) { |
||
| 149 | if ($index<sizeof($this->content->get)) |
||
| 150 | return $this->content; |
||
| 151 | } |
||
| 152 | |||
| 153 | public function fadeEffect() { |
||
| 154 | if (sizeof($this->content->getTabItems())>0) { |
||
| 155 | $this->content->getTabItem(0)->addToProperty("class", "fade in"); |
||
| 156 | $size=sizeof($this->tabs); |
||
| 157 | for($index=0; $index<$size; $index++) { |
||
| 158 | $this->content->getTabItem($index)->addToProperty("class", "fade"); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | public function on($event, $jsCode,$stopPropagation=false,$preventDefault=false){ |
||
| 164 | foreach ($this->tabs as $tab){ |
||
| 165 | $tab->on($event,$jsCode,$stopPropagation,$preventDefault); |
||
| 166 | } |
||
| 167 | return $this; |
||
| 168 | } |
||
| 169 | |||
| 170 | public function setStacked($stacked=true){ |
||
| 171 | if($stacked) |
||
| 172 | $this->stacked="nav-stacked"; |
||
| 173 | else $this->stacked=""; |
||
| 174 | } |
||
| 175 | |||
| 176 | /* (non-PHPdoc) |
||
| 177 | * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject() |
||
| 178 | */ |
||
| 179 | public function fromDatabaseObject($object, $function) { |
||
| 180 | $this->addTab($function($object)); |
||
| 181 | } |
||
| 182 | } |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: