/** * Vrátí HTML strukturu pro zobrazní fieldu * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @return string */ public function getField() { if (KT::notIssetOrEmpty($this->getOptionsData())) { return "<span class=\"input-wrap checkbox\">" . KT_EMPTY_SYMBOL . "</span>"; } $data = $this->getValue(); $html = ""; foreach ($this->getOptionsData() as $key => $val) { $html .= "<span class=\"input-wrap\">"; $html .= "<input type=\"checkbox\" "; $html .= $this->getBasicHtml($key); $html .= " value=\"{$key}\" "; if (KT::issetAndNotEmpty($data) && is_array($data)) { if (in_array($key, array_keys($data))) { $html .= " checked=\"checked\""; } } $html .= "> <span class=\"desc-checkbox-{$this->getAttrValueByName("id")}\"><label for=\"{$this->getName()}-{$key}\">{$val}</label></span> "; if ($this->hasErrorMsg()) { $html .= parent::getHtmlErrorMsg(); } $html .= "</span>"; } return $html; }
/** * Přepis původní funkce getData za účelem inicializace dat * * @return array */ public function getData() { if (KT::notIssetOrEmpty(parent::getData())) { $this->dataInit(); } return parent::getData(); }
private function getAllUserRoles() { if (KT::notIssetOrEmpty($this->allUserRoles)) { $this->allUserRolesInit(); } return $this->allUserRoles; }
/** * Vrátí pole s metas * * @return array */ public final function getMetas() { if (KT::notIssetOrEmpty($this->metas)) { $this->initMetas(); } return $this->metas; }
function __construct($postType) { if (KT::notIssetOrEmpty($postType)) { throw new KT_Not_Set_Argument_Exception("postType"); } $this->postType = $postType; add_filter("manage_{$postType}_posts_columns", array($this, "addColumns"), 50); add_filter("manage_{$postType}_posts_columns", array($this, "removeColumns"), 60); add_action("manage_{$postType}_posts_custom_column", array($this, "customColumn"), 50, 2); add_filter("manage_edit-{$postType}_sortable_columns", array($this, "sortableColumns"), 50); add_filter("pre_get_posts", array($this, "orderbyColumn"), 50); }
/** * Vrátí HTML strukturu pro zobrazní fieldu * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @return string */ public function getField() { $html = ""; $value = htmlentities($this->getValue()); $html .= "<input type=\"text\" "; $html .= $this->getBasicHtml(); $html .= " value=\"{$value}\" "; if (KT::notIssetOrEmpty($this->getDefaultColor())) { $html .= " data-default-color=\"{$this->getDefaultColor()}\""; } $html .= "/>"; if ($this->hasErrorMsg()) { $html .= parent::getHtmlErrorMsg(); } return $html; }
/** * Metoda prověří, zda se jedná o funkci, která začíná znaky "get" pokud ano * provede vyčtení příslušné hodnoty constanty a vrátí její hodnotu na základě * volané třídy. * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @return string */ protected function getConstantValue($functionName) { $firstChars = substr($functionName, 0, 3); if ($firstChars != self::MAGIC_GETTER_KEY) { return null; } if (method_exists($this, $functionName)) { return null; } $configName = $this->getConfigFromModelName(); if (!class_exists($configName)) { return null; } $classRef = new ReflectionClass($configName); $constantName = $this->getConstantFromFunctionName($functionName); if (KT::notIssetOrEmpty($constantName)) { throw new KT_Not_Exist_Config_Constant_Exception($constantName); } return $constValue = $classRef->getConstant($constantName); }
/** * Akce vrátí do WP Front-endu příslušnou templatu z uvedené path URL objektu * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @global WP_Query $wp_query * @param string $template * @return string */ public function getCustomTemplate($template) { global $wp_query; $pagename = $wp_query->query_vars["pagename"]; if (KT::notIssetOrEmpty($pagename)) { return $template; } if (!in_array($pagename, array_keys($this->urls))) { return $template; } $wp_query->is_404 = ''; $wp_query->is_kt_template = 1; $url = $this->getUrlObject($pagename); $kt_template = $url->getFullFilePath(); if (is_file($kt_template)) { add_filter('wp_title', array($this, 'customUrlTitle'), 10, 1); return $kt_template; } return $template; }
/** * Připraví string se zadanými attributy * * @author Tomáš Kocifaj * * @return string */ protected function getAttributeString() { $html = ""; $attrCollection = $this->getAttributes(); if (KT::notIssetOrEmpty($attrCollection)) { return $html; } foreach ($attrCollection as $key => $value) { if ($key == self::CLASS_KEY) { continue; } if (KT::issetAndNotEmpty($value)) { $html .= $key . "=\"" . htmlspecialchars($value) . "\" "; } else { $html .= $key . " "; } } $html .= $this->getAttrClassString(); return $html; }
/** * Vrátí HTML strukturu pro zobrazní fieldu * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @return string */ public function getField() { $html = ""; if (KT::notIssetOrEmpty($this->getOptionsData())) { return $html = KT_EMPTY_SYMBOL; } foreach ($this->getOptionsData() as $key => $value) { $html .= "<span class=\"input-wrap radio\">"; $html .= "<input type=\"radio\" "; $html .= $this->getBasicHtml($key); $html .= " value=\"{$key}\" "; if ($key == $this->getValue() && $this->getValue() !== null) { $html .= "checked=\"checked\""; } $html .= "> <span class=\"radio radio-name-{$this->getAttrValueByName("id")} radio-key-{$key} \"><label for=\"{$this->getName()}-{$key}\">{$value}</label></span> "; $html .= "</span>"; } if ($this->hasErrorMsg()) { $html .= parent::getHtmlErrorMsg(); } return $html; }
/** * Zkontroluje, zda zadaný parametr je nastavený správně dle požadavků * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param string $paramName * @param string $paramValue * @return boolean */ private function isParamSet($paramName, $paramValue) { if (!isset($_GET[$paramName])) { return false; } if (KT::notIssetOrEmpty($paramValue)) { return true; } if ($_GET[$paramName] == $paramValue) { return true; } return false; }
/** * Provede vykreslení OG tagu na základě parametru a jeho obsahu * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param string $tagType * @param string $content */ private function renderMetaTag($tagType, $content) { if (KT::notIssetOrEmpty($content)) { return; } $content = strip_tags($content); echo "<meta property=\"{$tagType}\" content=\"{$content}\" />\n"; }
/** * Zjistí počet všech záznam, které odpovídají zadanému selectu * Používá se pro stránkování * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @global wpdb $wpdb * @return type */ private function getCoutOfAllItemsInDb() { global $wpdb; if (KT::notIssetOrEmpty($this->getQuery())) { $this->createQuery("COUNT(*)"); } $result = $wpdb->get_var($this->getQuery()); if ($result === false) { $this->addError("Při selekci dat se vyskytla chyba", $wpdb->last_error); } return $result; }
/** * Načte data uživatele na základě příspěvku a jeho přiřazeného autora * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param WP_Post $post * @return \KT_WP_User_Base_Model * @throws KT_Not_Supported_Exception */ public function wpUserInitByPostAuthor(WP_Post $post) { $userId = $post->post_author; if (KT::notIssetOrEmpty($userId)) { throw new KT_Not_Supported_Exception("Post has no post_author"); } if (KT::issetAndNotEmpty($userId)) { $this->wpUserInitById($userId); } return $this; }
/** * Vrátí titulek layoutu, pokud byl definován. * @author Tomáš Kocifaj * @link www.ktstduio.cz * * @return string */ protected function getTamplageTitleContent() { if (KT::notIssetOrEmpty($this->getTemplateTitle())) { return ""; } return $html = "<h2>" . $this->getTemplateTitle() . "</h2>"; }
/** * Provede povolení, resp. inicializaci proužku s potvrzením cookie (v patičce) * NENÍ POTŘEBA VOLAT VEŘEJNĚ * * @author Martin Hlaváč * @link http://www.ktstudio.cz */ public function renderCookieStatement() { $cookueStatementKey = KT::arrayTryGetValue($_COOKIE, self::COOKIE_STATEMENT_KEY); if (KT::notIssetOrEmpty($cookueStatementKey)) { $text = __("Tyto stránky využívají Cookies. Používáním těchto stránek vyjadřujete souhlas s používáním Cookies.", KT_DOMAIN); $moreInfoTitle = __("Zjistit více", KT_DOMAIN); $moreInfoUrl = apply_filters("kt_cookie_statement_more_info_url_filter", "https://www.google.com/policies/technologies/cookies/"); $confirmTitle = __("OK, rozumím", KT_DOMAIN); $content = "<span id=\"ktCookieStatementText\">{$text}</span>"; $content .= "<span id=\"ktCookieStatementMoreInfo\"><a href=\"{$moreInfoUrl}\" title=\"{$moreInfoTitle}\" target=\"_blank\">{$moreInfoTitle}</a></span>"; $content .= "<span id=\"ktCookieStatementConfirm\">{$confirmTitle}</span>"; echo "<!-- ktcookiestatement W3TC_DYNAMIC_SECURITY -->"; echo "<div id=\"ktCookieStatement\">"; echo apply_filters("kt_cookie_statement_content_filter", $content); echo "</div>"; echo "<noscript><style scoped>#ktCookieStatement { display:none; }</style></noscript>"; echo "<!-- /ktcookiestatement W3TC_DYNAMIC_SECURITY -->"; } }
/** * Vrátí HTML s celou galerií včetně obrázků, linků a atributů - viz parametry * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param type $id // html id containeru * @param type $class // html class containeru * @param type $imgClass // class pro img tag * @param type $attr // případný attribuy pro každý obrázek * @param type $withSelfLink // mají mít obrázky odkaz sami na sebe pro large velikost? * @return string */ public function getImageGallery($imgClass = null, $attr = array(), $withSelfLink = true) { $html = ""; if (KT::notIssetOrEmpty($this->getFiles())) { return $html; } if (KT::notIssetOrEmpty($this->getAttrValueByName("id"))) { $this->setAttrId("ktGalleryContainer"); } if (KT::notIssetOrEmpty($this->getAttrClassString())) { $this->addAttrClass("ktGallery"); } $this->addAttrClass("postGalleryId-" . $this->getPost()->ID)->addAttrClass($this->getPost()->post_type); $html .= $this->getContainerHeader(); $html .= "<div {$this->getAttributeString()}>"; foreach ($this->getFiles() as $image) { /* @var $image \WP_Post */ $thumbnail = wp_get_attachment_image_src($image->ID, $this->getThumbnailSize()); $large = wp_get_attachment_image_src($image->ID, $this->getLargeSize()); $html .= "<dl class=\"gallery-item\"><dt>"; if ($withSelfLink) { $html .= $this->getLinkTagToLargeImage($large, $attr, $image->post_title); } $html .= $this->getImageTag($image, $thumbnail, $imgClass); if ($withSelfLink) { $html .= "</a>"; } $html .= "</dt></dl>"; } $html .= "</div>"; return $html; }
/** * Sestaví jeden TR řádek v podobě Label -> value (saved). * Pokud je value prázdné, nebude ho vůbec zobrazovat. * Pokud má Field definovaný Unit zobrazí ho pouze v případě, že se value rovná KT_EMPTY_TEXT (---) * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param KT_Field $field * @return string */ private function getInputDataToTr(KT_Field $field, $exclude_keys = array()) { if (in_array($field->getName(), $exclude_keys)) { return; } if ($field->getFieldType() == KT_Hidden_Field::FIELD_TYPE) { return; } $value = $field->getValue(); if ($field->getFieldType() == KT_Select_Field::FIELD_TYPE || $field->getFieldType() == KT_Radio_Field::FIELD_TYPE) { $fieldOption = $field->getDataManager()->getData(); if (array_key_exists($field->getValue(), $fieldOption)) { $value = $fieldOption[$field->getValue()]; } } if ($field->getFieldType() == KT_Checkbox_Field::FIELD_TYPE) { $fieldOption = $field->getDataManager()->getData(); $fieldData = $field->getValue(); if (KT::issetAndNotEmpty($fieldOption) && KT::issetAndNotEmpty($fieldData)) { $value = ""; foreach ($fieldOption as $key => $optionText) { if (in_array($key, $fieldData)) { $value .= $optionText . ", "; } } } else { $value = ""; } } if (KT::notIssetOrEmpty($value)) { return; } $unit = $value == KT_EMPTY_SYMBOL ? "" : $field->getUnit(); $html = "<tr>"; $html .= "<td>{$field->getLabel()} </td>"; $html .= "<td>{$value} {$unit}</td>"; $html .= "</tr>"; return $html; }
/** * Nastaví data objektu ze všech sloupců v DB, které se u daného záznamu nacházejí * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param array $data * @return \KT_Crud */ public function setData($data = array()) { if (KT::notIssetOrEmpty($data) || !is_array($data)) { return; } $rowIdFromData = null; if (array_key_exists($this->getPrimaryKeyColumn(), $data)) { $rowIdFromData = $data[$this->getPrimaryKeyColumn()]; } if (KT::issetAndNotEmpty($rowIdFromData)) { $this->setId($rowIdFromData); } foreach ($this->getColumns() as $column) { if (array_key_exists($column->getName(), $data)) { $column->setValue($data[$column->getName()]); continue; } } return $this; }
/** * Vytvoří HTML content s výpisem všech souborů, které * * @param type $id * @param type $class * @return string */ public function getFileList() { if (!$this->hasFiles()) { return ""; } if (KT::notIssetOrEmpty($this->getAttrValueByName("id"))) { $this->setAttrId("ktFileListContainer"); } if (KT::notIssetOrEmpty($this->getAttrClassString())) { $this->addAttrClass("ktFiles"); } $this->addAttrClass("postFilesId-" . $this->getPost()->ID)->addAttrClass($this->getPost()->post_type); $html = $this->getContainerHeader(); $html .= "<ul {$this->getAttributeString()}>"; foreach ($this->getFiles() as $image) { /* @var $image \WP_Post */ $fileUrl = wp_get_attachment_url($image->ID); $html .= "<li class=\"file-item\">"; $html .= "<a href=\"{$fileUrl}\" title=\"{$image->post_title}\" target=\"_blank\">{$this->getFileIconContent()} <span class=\"file-title\">{$image->post_title}</span></a>"; $html .= "</li>"; } $html .= "</ul>"; return $html; }
/** * Funkce umístí hodnoty do fieldu fomuláře. Možné definovat pomocí fieldsetu nebo obyčejným polem * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param form_data array() - $fieldSet->name => array($field->name => $fieldValue) */ public function setFormData(array $fieldsetCollectionsData) { if (KT::notIssetOrEmpty($fieldsetCollectionsData) || !$this->hasFieldset()) { return $this; } foreach ($this->getFieldsets() as $fieldSet) { if ($fieldSet->hasFields()) { $fieldSet->setFieldsData($fieldsetCollectionsData[$fieldSet->getName()]); } } return $this; }
/** * Metoda prověří, zda se jedná o funkci, která začíná zadaným prefixem a pokud ano, tak provede * vyčtení příslušné hodnoty constanty a vrátí její hodnotu na základě volané třídy. * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param string $functionName * @param string $prefix * @return string * @throws KT_Not_Exist_Config_Constant_Exception */ private function getAutoMethodKey($functionName, $prefix) { $firstChars = substr($functionName, 0, strlen($prefix)); if ($firstChars !== $prefix) { return null; } if (method_exists($this, $functionName)) { return null; } $configName = $this->getConfigNameFromModel(); if (!class_exists($configName)) { return null; } $reflectionClass = new ReflectionClass($configName); $constantName = $this->getConstantNameFromFunction($functionName); $constantValue = $reflectionClass->getConstant($constantName); if (KT::notIssetOrEmpty($constantValue)) { throw new KT_Not_Exist_Config_Constant_Exception($constantName); } return $constantValue; }
/** * Zkontroluje, zda jsou všechny hodnoty nastavené. * Musí být nastaveno - recipients, content, sender_email, sender_name * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @throws KT_Not_Set_Argument_Exception */ private function validate() { $mustBeSetup = array("recipients", "content"); foreach ($mustBeSetup as $value) { if (KT::notIssetOrEmpty($this->{$value})) { throw new KT_Not_Set_Argument_Exception($value); } } }
/** * Stejně jako funkce get_terms vrátí kolekci všech termů ve formě stdClass, funkce * vrátí kolekci všech KT_WP_Term_Base_Modelů. * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * @link http://codex.wordpress.org/Function_Reference/get_terms * * @param string $taxonomy * @param array $args * @return array */ public static function getModels($taxonomy, $args) { $modelCollection = array(); $terms = get_terms($taxonomy, $args); if (KT::notIssetOrEmpty($terms)) { return $modelCollection; } foreach ($terms as $term) { array_push($modelCollection, new KT_WP_Term_Base_Model($term)); } return $modelCollection; }
/** * Vrátí kolekci všech termů, kam je post zařazen na základě zadané taxonomy * Pokud ještě nebyly načteny, uloží je do proměnné $this->data->{$taxonomy} a znovu se na ně nedotazuje * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param string $taxonomy * @param array $args // wp_get_object_terms * * @return mixed null|array */ public function getTerms($taxonomy, array $args = array()) { if (KT::notIssetOrEmpty($this->{$taxonomy})) { $termCollection = self::getTermCollectionByPost($this->getPost(), $taxonomy, $args); $this->{$taxonomy} = $termCollection; } return $this->{$taxonomy}; }
/** * Vrátí obsah buňky na základě předaných parametrů a nastaveného typu sloupce * * @param string $itemValue * @param int $itemId * @param string $className * @return string * @throws InvalidArgumentException */ public function getCellContent($item) { if (KT::notIssetOrEmpty($item)) { return ""; } $columnName = $this->getName(); $className = get_class($item); $itemId = $item->getId(); if ($this->getType() != self::CUSTOM_TYPE) { $itemValue = filter_var($item->{$columnName}, $this->getFilterSanitize()); } switch ($this->getType()) { case self::TEXT_TYPE: return $html = $this->getTextTypeContent($itemValue); case self::EDIT_LINK_TYPE: return $html = $this->getEditLinkTypeContent($itemValue, $itemId, $className); case self::IMAGE_TYPE: return $html = $this->getImageTypeContent($itemValue); case self::SWITCH_BUTTON_TYPE: return $html = $this->getSwitchButtonTypeContent($itemValue, $itemId, $className); case self::CUSTOM_TYPE: return $html = $this->getCustomTypeContent($item); default: throw new InvalidArgumentException("column type is an invalid value for CRUD Column"); } }
/** * Na základě definovaných parametrů vytvoří hlavičku - začátek - výpisu attachmentů * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @return string */ protected function getContainerHeader() { $html = ""; $title = $this->getGalleryTitle(); if (KT::notIssetOrEmpty($title)) { return null; } if (KT::issetAndNotEmpty($this->getGalleryTitleContainer())) { $galleryTitleContainer = $this->getGalleryTitleContainer(); $html .= "<{$galleryTitleContainer}>"; $html .= $title; $html .= "</{$galleryTitleContainer}>"; return $html; } return $title; }
/** * Provede validaci fieldu na základě zadaných podmínek * V případě, že se jedná o chybu, nastaví automaticky fieldu hlášku s errorem z validatoru * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @return boolean */ public function Validate() { if (KT::notIssetOrEmpty($this->getValidators())) { return true; } foreach ($this->getValidators() as $validator) { if (!$validator->validate($this->getValue())) { $this->setError($validator->getMessage()); return false; } } $this->setError(null); return true; }
/** * Vrátí obsah proužku s potvrzením cookie (v patičce) * NENÍ POTŘEBA VOLAT VEŘEJNĚ * * @author Martin Hlaváč * @link http://www.ktstudio.cz */ public static function getCookieStatementHtml() { $cookueStatementKey = KT::arrayTryGetValue($_COOKIE, self::COOKIE_STATEMENT_KEY); if (KT::notIssetOrEmpty($cookueStatementKey)) { $text = __("Tyto stránky využívají Cookies. Používáním těchto stránek vyjadřujete souhlas s používáním Cookies.", "KT_CORE_DOMAIN"); $moreInfoTitle = __("Zjistit více", "KT_CORE_DOMAIN"); $moreInfoUrl = apply_filters("kt_cookie_statement_more_info_url_filter", "https://www.google.com/policies/technologies/cookies/"); $confirmTitle = __("OK, rozumím", "KT_CORE_DOMAIN"); $html = "<span id=\"ktCookieStatementText\">{$text}</span>"; $html .= "<span id=\"ktCookieStatementMoreInfo\"><a href=\"{$moreInfoUrl}\" title=\"{$moreInfoTitle}\" target=\"_blank\">{$moreInfoTitle}</a></span>"; $html .= "<span id=\"ktCookieStatementConfirm\">{$confirmTitle}</span>"; $content = apply_filters("kt_cookie_statement_content_filter", $html); $output = "<div id=\"ktCookieStatement\">{$content}</div>"; $output .= "<noscript><style scoped>#ktCookieStatement { display:none; }</style></noscript>"; return $output; } return null; }
/** * Dojde k inicilizaci dat manageru dle nastavení argumentů pro WP_Query * Selekt probíhá pomocí get_posts @link http://codex.wordpress.org/Function_Reference/get_posts * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @return \KT_Post_Type_Select_Field */ public function dataInit() { if (KT::notIssetOrEmpty($this->getQueryArgs())) { return; } $postCollection = get_posts($this->getQueryArgs()); $options = null; if (KT::issetAndNotEmpty($postCollection)) { foreach ($postCollection as $postItem) { $options[$postItem->ID] = $this->getPrefixValue($postItem->ID) . " " . $postItem->post_title . " " . $this->getSuffixValue($postItem->ID); } } if (KT::issetAndNotEmpty($options)) { $this->setData($options); } return $this; }