function kt_zzz_load_more_posts_callback() { if (KT::arrayIssetAndNotEmpty($_REQUEST)) { $presenter = new KT_ZZZ_Posts_Presenter(); die($presenter->getPostsOutput()); } die(false); }
function __construct($taxonomy = null, $args = null) { if (KT::arrayIssetAndNotEmpty($args)) { $this->setArgs($args); } if (KT::issetAndNotEmpty($taxonomy)) { $this->setTaxonomy($taxonomy); } }
/** * Na základě odřádkování (tzn. po řádcích) rozdělí zadaný text a vrátí jako HTML seznam zadaného tagu * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @param string $format @see sprintf() * @return string (HTML) */ public function getList($format = "%s", $unsafe = false) { $lines = $this->getLinesArray($unsafe); if (!KT::arrayIssetAndNotEmpty($lines)) { return; } $output = ""; foreach ($lines as $line) { $output .= sprintf($format, $line); } return $output; }
private function initPosts() { $args = array("post_type" => KT_WP_POST_KEY, "post_status" => "publish", "posts_per_page" => self::DEFAULT_COUNT, "orderby" => "date", "order" => KT_Repository::ORDER_DESC, "cat" => KT_ZZZ::getThemeModel()->getCategoryNewsId()); $query = new WP_Query(); $posts = $query->query($args); if (KT::arrayIssetAndNotEmpty($posts)) { $this->posts = $posts; $this->postsCount = count($posts); } else { $this->posts = array(); $this->postsCount = 0; } }
/** * Funkce obslouží ajax dotaz, který má provést uložení pořadí itemů po Sortable * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz */ function kt_edit_sorting_crud_list_callback() { $itemCollection = $_REQUEST["data"]; $className = $_REQUEST["class_name"]; if (KT::arrayIssetAndNotEmpty($itemCollection)) { foreach ($itemCollection as $index => $itemId) { $crudClassObject = new $className($itemId); if ($crudClassObject->isInDatabase()) { $crudClassObject->setMenuOrder($index)->saveRow(); } } } }
private function initPosts() { $args = array("post_type" => KT_ZZZ_SLIDER_KEY, "post_status" => "publish", "posts_per_page" => self::DEFAULT_COUNT, "orderby" => "menu_order title", "order" => KT_Repository::ORDER_ASC); $query = new WP_Query(); $posts = $query->query($args); if (KT::arrayIssetAndNotEmpty($posts)) { $this->posts = $posts; $this->postsCount = count($posts); } else { $this->posts = array(); $this->postsCount = 0; } }
function kt_cron_schedules_metabox_callback() { $schedules = wp_get_schedules(); if (KT::arrayIssetAndNotEmpty($schedules)) { echo "<ol>"; foreach ($schedules as $key => $values) { if (KT::arrayIssetAndNotEmpty($values)) { $interval = KT::arrayTryGetValue($values, "interval"); $display = KT::arrayTryGetValue($values, "display"); echo "<li><b>{$key}</b> (<i>{$display}</i>) - {$interval} [s]</li>"; } } echo "</ol>"; } }
/** * Výpis postů podle zadané query v zadané loopě * * @param WP_Query $query * @param string $loopName * @param mixed int|null $count * @param mixed int|null $offset */ protected function theItemsLoops(array $items, $loopName, $count = null, $offset = null) { if (KT::arrayIssetAndNotEmpty($items)) { $index = 0; if (KT::tryGetInt($offset) > 0) { $items = array_slice($items, $offset); } if (KT::tryGetInt($count) > 0) { $items = array_slice($items, 0, $count); } foreach ($items as $item) { global $post; $post = $item; include locate_template("loops/loop-{$loopName}.php"); $index++; } wp_reset_postdata(); } }
/** * Uloží fieldset * VOLÁ SE V HOOCE * * @author Jan Pokorný * @param int $user_id */ public function saveFieldset($user_id) { if (get_current_user_id() != $user_id && !current_user_can('edit_users')) { return; } $fieldset = $this->getFieldset(); $form = new KT_form(); $form->addFieldSetByObject($fieldset); $form->validate(); if ($form->hasError()) { // TODO has error } if ($fieldset->getSerializeSave()) { $fieldsetData = $form->getSavableFieldsetGroupValue($fieldset); if (KT::arrayIssetAndNotEmpty($fieldsetData)) { update_user_meta($user_id, $fieldset->getName(), $fieldsetData); } else { delete_user_meta($user_id, $fieldset->getName()); } } else { foreach ($fieldset->getFields() as $field) { $fieldValue = $form->getSavableFieldValue($field); if ($field && $fieldValue !== "") { update_user_meta($user_id, $field->getName(), $fieldValue); } else { delete_user_meta($user_id, $field->getName()); } } } }
/** @return KT_ZZZ_Sidebar_Presenter */ private function initCurrentSidebar() { global $wp_registered_sidebars; $sidebarKey = KT_ZZZ_SIDEBAR_DEFAULT; if (KT::arrayIssetAndNotEmpty($wp_registered_sidebars)) { foreach ($wp_registered_sidebars as $key => $values) { if ($key === $sidebarKey) { $this->setCurrentSidebarName(KT::arrayTryGetValue($values, "name")); break; } } } return $this->setCurrentSidebarKey($sidebarKey); }
/** * Vrátí URL pro odkaz na obrázek (thumb) * Defaultní velikost - Large * * @return string (URL) */ public function getThumbnailImagePermalink($size = KT_WP_IMAGE_SIZE_LARGE) { if (KT::issetAndNotEmpty($this->thumbnailImagePermalink)) { return $this->thumbnailImagePermalink; } $src = wp_get_attachment_image_src($this->getModel()->getThumbnailId(), $size); if (KT::arrayIssetAndNotEmpty($src)) { return $this->thumbnailImagePermalink = $src[0]; } return $this->thumbnailImagePermalink = null; }
/** * Výpis postů podle zadané query v zadané loopě * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @param array $items * @param string $loopName * @param mixed int|null $count * @param mixed int|null $offset * @param array $clearfixes pole clearfixů k printu podle klíče (modulo) */ public static function theItemsLoops(array $items, $loopName, $count = null, $offset = null, array $clearfixes = null) { if (KT::arrayIssetAndNotEmpty($items)) { $isClearfixes = KT::arrayIssetAndNotEmpty($clearfixes); self::$currentItemsLoopIndex = 0; if (KT::tryGetInt($offset) > 0) { $items = array_slice($items, $offset); } if (KT::tryGetInt($count) > 0) { $items = array_slice($items, 0, $count); } foreach ($items as $item) { global $post; $post = $item; include locate_template("loops/loop-{$loopName}.php"); self::$currentItemsLoopIndex++; if ($isClearfixes) { self::theClearfixes($clearfixes, self::$currentItemsLoopIndex); } } self::$currentItemsLoopIndex = null; wp_reset_postdata(); } }
/** * Vrátí pole ve tvaru term ID => slug pro zadanou taxonomii a podle parametrů * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @param string $taxonomy * @param array $args // wp_get_object_terms * * @return array */ public function getTermsSlugs($taxonomy, array $args = array()) { $terms = $this->getTerms($taxonomy, $args); $termsNames = array(); if (KT::arrayIssetAndNotEmpty($terms)) { foreach ($terms as $term) { $termsNames[$term->term_id] = $term->slug; } } return $termsNames; }
/** * Provede inicializaci a načtení všech obrázků dle zadaného Post objektu a nastavení * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @return \KT_WP_Post_Gallery */ protected function initialize() { $queryArgs = array("post_type" => KT_WP_ATTACHMENT_KEY, "post_status" => "inherit", "posts_per_page" => $this->getNumberFiles(), "post_mime_type" => "image", "orderby" => $this->getOrderby(), "order" => $this->getOrder()); $customImageIds = $this->getCustomImageIds(); $isCustomImageIds = KT::arrayIssetAndNotEmpty($customImageIds); if ($this->getExcludeThumbnail()) { $thumbnailId = get_post_thumbnail_id($this->getPost()->ID); $queryArgs["post__not_in"] = array($thumbnailId); if ($isCustomImageIds) { $customImageIds = KT::arrayRemoveByValue($customImageIds, $thumbnailId); } } if ($isCustomImageIds) { $queryArgs["post__in"] = $customImageIds; } else { $queryArgs["post_parent"] = $this->getPost()->ID; } $images = new WP_Query($queryArgs); $this->setFiles($images->posts); return $this; }
/** * Přiřadí novou sadu sloupců do kolekce stávajících dat. * Nepřepíše původní, provede merge dat. Přepíše hodnoty stejných sloupců * které jsou již v kolekci přiřazeny * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param array $columns */ public function addNewColumnsToValue(array $columns) { if (!KT::arrayIssetAndNotEmpty($columns)) { return $this; } foreach ($columns as $columnName => $columnValue) { $this->addNewColumnValue($columnName, $columnValue); } return $this; }
/** * Vrátí obsah s daty pro field v případě, že je attachment nastaven * V případě obrázku vrátí jeho thumbnail v případě souboru pouze název * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @return string */ private function getFullSpanUrl() { $html = null; $value = $this->getValue(); if (KT::issetAndNotEmpty($value)) { $html .= "<span class=\"{$this->getAttrValueByName("id")} span-url full\">"; $ids = $this->getValues(); if (KT::arrayIssetAndNotEmpty($ids)) { foreach ($ids as $id) { $attachment = get_post($id); if (KT::issetAndNotEmpty($attachment)) { if (self::isFileImageType($attachment)) { $imageData = wp_get_attachment_image_src($attachment->ID, KT_WP_IMAGE_SIZE_THUBNAIL); $fileTag = "<img class=\"file\" src=\"{$imageData[0]}\">"; } if (!isset($fileTag)) { $fileTag = "<span class=\"file\">{$attachment->post_title}</span>"; } $removeFileTag = "<a class=\"remove-file\" data-id=\"{$attachment->ID}\"><span class=\"dashicons dashicons-no\"></span></a>"; $html .= "{$fileTag} {$removeFileTag}"; } else { $html .= "<span class=\"file\">" . __("Soubor byl smazán", "KT_CORE_DOMAIN") . "</span>"; } } } else { $html = "<span class=\"file\">" . __("Soubor(y) byl(y) smazán(y)", "KT_CORE_DOMAIN") . "</span>"; } $html .= "</span>"; } else { $html = "<span class=\"{$this->getAttrValueByName("id")} span-url\"></span>"; } return $html; }
/** * @return string */ public function getAutoVersion() { if (KT::issetAndNotEmpty($this->autoVersion)) { return $this->autoVersion; } $autoVersionExpiration = $this->getAutoVersionExpiration(); $isAutoVersionExpiration = $autoVersionExpiration > 0; if ($isAutoVersionExpiration) { $cachedAutoVersionKey = self::VERSION_CACHE_PREFIX . $this->getId(); $cachedAutoVersion = KT::arrayTryGetValue($_COOKIE, $cachedAutoVersionKey); if (KT::issetAndNotEmpty($cachedAutoVersion)) { return $this->autoVersion = $cachedAutoVersion; } } $source = $this->getSource(); if (KT::issetAndNotEmpty($source)) { $sourceHeaders = get_headers($source, 1); if (KT::arrayIssetAndNotEmpty($sourceHeaders)) { if (stristr($sourceHeaders[0], "200")) { $lastModified = KT::arrayTryGetValue($sourceHeaders, "Last-Modified"); if (KT::issetAndNotEmpty($lastModified)) { $lastModifiedDateTime = new \DateTime($lastModified); $autoVersion = $lastModifiedDateTime->getTimestamp(); if ($isAutoVersionExpiration) { setcookie($cachedAutoVersionKey, "{$autoVersion}", time() + $autoVersionExpiration, "/"); } return $this->autoVersion = $autoVersion; } } } } return null; }
/** * Vrátí hodnotu pro zadaný název (klíč) pokud existuje ve výčtu získaných options hodnot (podle dříve zadaného případného prefixu) * Pozn.: načtení options hodnot (na prefixu) se provádí až při prvním volání * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @param string $name * @return string|null */ public function getOption($name) { $options = $this->getOptions(); if (KT::arrayIssetAndNotEmpty($options)) { foreach ($options as $optionName => $optionValue) { if ($optionName == $name) { $optionValue = is_serialized($optionValue) ? unserialize($optionValue) : $optionValue; return apply_filters('option_' . $name, $optionValue, $name); } } } return null; }
private function initPosts() { $args = array("post_type" => KT_WP_POST_KEY, "post_status" => "publish", "posts_per_page" => $this->getMaxCount(), "orderby" => "date", "order" => KT_Repository::ORDER_DESC); // except himself if (is_single()) { $args["post__not_in"] = array(get_the_ID()); } // offset if ($this->isOffset()) { $args["offset"] = $this->getOffset(); } // category $taxQuery = array("relation" => "AND"); if ($this->isCategoryId()) { array_push($taxQuery, array("taxonomy" => KT_WP_CATEGORY_KEY, "field" => "term_id", "terms" => array($this->getCategoryId()))); } $args["tax_query"] = $taxQuery; $query = new WP_Query(); $posts = $query->query($args); if (KT::arrayIssetAndNotEmpty($posts)) { $this->posts = $posts; $this->postsCount = count($posts); } else { $this->posts = array(); $this->postsCount = 0; } }
/** * Načte data k fieldům na zakladě předaného pole $field->getName() => $value * * @author Tomáš Kocifaj * @link http://www.ktstudio.cz * * @param array $fieldsData */ public function setFieldsData($fieldsData) { if (KT::arrayIssetAndNotEmpty($fieldsData)) { foreach ($this->getFields() as $field) { /** @var $field \KT_Field */ if (!array_key_exists($field->getName(), $fieldsData)) { continue; } $value = $fieldsData[$field->getName()]; if ($value !== "" && isset($value)) { $field->setValue($this->convertFieldValue($field, $value)); } } } return $this; }
/** * Inicializuje pole (post) metas na základě prefixu nebo všechny * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @return \KT_Post_Type_Presenter_Base */ private function initMetas() { $metas = self::getTermsMetas($this->getId(), $this->getMetaPrefix()); if (KT::arrayIssetAndNotEmpty($metas)) { $this->setMetas($metas); } else { $this->setMetas(array()); } return $this; }
/** * Uloží data poslané postem do tabulky kt_termmeta - celý fieldset jako realizované pole fieldů ($fieldName => $fieldValue) * @see saveFieldsToTermmetaTable * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @param int $termId * @param \KT_Form_Fieldset $fieldset * @param array $excludeFields * @return \KT_Form */ private function saveFieldsetToTermMetaByGroup($termId, KT_Form_Fieldset $fieldset, array $excludeFields = array()) { $fieldsetData = $this->getSavableFieldsetGroupValue($fieldset, $excludeFields); if (KT::arrayIssetAndNotEmpty($fieldsetData)) { update_term_meta($termId, $fieldset->getName(), $fieldsetData); } else { delete_term_meta($termId, $fieldset->getName()); } return $this; }
/** * Vrátí defaultní hodnotu * * @return array */ public function getDefaultValue() { if (KT::arrayIssetAndNotEmpty($this->defaultValue)) { return $this->defaultValue; } else { return $this->getPredefinedValue(); } }
/** * Interní zalogování do DB * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @global \WPDB $wpdb * @param int $level * @param string $message * @return boolean */ private static function log($level, $message) { if ($level >= self::getMinLevel()) { // kontrola minimální povolené úrovně logování $user = wp_get_current_user(); $isUserSigned = $user->exists(); if (self::getOnlyForSignedUsers() && !$isUserSigned) { return null; // uživatel není přihlášen a je to požadováno } if (KT::issetAndNotEmpty($message)) { $args = array(KT_Log_Model::LEVEL_ID_COLUMN => $level, KT_Log_Model::MESSAGE_COLUMN => filter_var($message, FILTER_SANITIZE_FULL_SPECIAL_CHARS), KT_Log_Model::DATE_COLUMN => KT::dateNow()); if ($isUserSigned) { $args[KT_Log_Model::LOGGED_USER_NAME_COLUMN] = $user->user_login; } $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); if (KT::arrayIssetAndNotEmpty($backtrace)) { $lastBacktrace = $backtrace[1]; // první index je vždy právě KT_Logger $args[KT_Log_Model::FILE_COLUMN] = $lastBacktrace["file"]; $args[KT_Log_Model::LINE_COLUMN] = $lastBacktrace["line"]; } /* @var $wpdb \WPDB */ global $wpdb; $logId = $wpdb->insert(KT_Log_Model::TABLE, $args); return $logId > 0; } } return null; }
/** * Kontrola a zpracování (odeslaných) dat (z POSTu), pokud je to možné, je třeba v rámci hlavičky stránky * * @author Martin Hlaváč * @link http://www.ktstudio.cz */ public function process() { if (KT::arrayIssetAndNotEmpty($_POST)) { $form = $this->getForm(); if (!$form->nonceValidate()) { wp_die(__("Chyba zpracování zdrojové adresy...", "KT_CORE_DOMAIN")); exit; } $form->validate(); if (!$form->hasError()) { $allValues = array(); foreach ($_POST as $key => $values) { if (KT::stringStartsWith($key, KT_User_Profile_Config::FORM_PREFIX)) { if (KT::arrayIssetAndNotEmpty($values)) { $allValues = array_merge($allValues, $values); } } } if (KT::arrayIssetAndNotEmpty($allValues)) { $result = $this->checkPostParams($allValues) || $this->checkPostPassword($allValues); if (!$result) { $form->setErrorMessage(__("Chyba při ukládání uživatelského profilu...", "KT_CORE_DOMAIN")); $form->setError(true); } else { wp_redirect(add_query_arg(self::PROCESSED_PARAM, "1", KT::getRequestUrl())); exit; } } } add_action(KT_PROJECT_NOTICES_ACTION, array(&$this, "renderErrorNotice")); } }
/** * Na základě odřádkování (tzn. po řádcích) rozdělí zadaný text a vrátí jako HTML seznam zadaného tagu * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @param string $text * @param string $tag HTML tag pro jednotlivé řádky * @param string $class CSS třída pro jednotlivé HTML tagy * @return string (HTML) */ public static function textLinesToHtml($text, $tag, $class = null) { $lines = self::textLinesToArray($text); if (KT::arrayIssetAndNotEmpty($lines)) { $classPart = null; if (KT::issetAndNotEmpty($class)) { $classPart = " class=\"{$class}\""; } $output = null; foreach ($lines as $line) { $output .= "<{$tag}{$classPart}>{$line}</{$tag}>"; } return $output; } return null; }
/** * Vrátí HTML se skupinou (<optgroup>) všech options, které do skupiny patří * Jedna z položek $optionGroupData musí mít klíč self::OPTION_GROUP_KEY * hodnota na tomto klíči bude použitá jako label celé kolekce * * @author Tomáš Kocifaj * @link http:://www.ktstudio.cz * * @param array $optionGroupData * @return string */ protected function getOptionsGroupContent(array $optionGroupData = array()) { $html = ""; if (!KT::arrayIssetAndNotEmpty($optionGroupData)) { return $html; } if (array_key_exists(self::OPTION_GROUP_NAME, $optionGroupData)) { $groupLable = $optionGroupData[self::OPTION_GROUP_NAME]; unset($optionGroupData[self::OPTION_GROUP_NAME]); } else { return $html; } $html .= "<optgroup label=\"{$groupLable}\">"; foreach ($optionGroupData as $optionKey => $optionValue) { $html .= $this->getSignleOptionItem($optionKey, $optionValue); } $html .= "</optgroup>"; return $html; }
function __construct(array $queryArgs = null) { if (KT::arrayIssetAndNotEmpty($queryArgs)) { $this->setQueryArgs($queryArgs); } }
/** * Filter metaboxu pro archivy post typů v menu * NENÍ POTŘEBA VOLAT VEŘEJNĚ * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @param array $items */ public function postArchivesMenuFilter($items) { if (KT::arrayIssetAndNotEmpty($items)) { foreach ($items as $item) { if ($item->object === self::POST_TYPE_ARCHIVE_OBJECT_KEY) { $item->url = get_post_type_archive_link($item->type); if (get_query_var("post_type") == $item->type) { $item->classes[] = "current-menu-item"; $item->current = true; } } } } return $items; }
/** * Kontrola a zpracování (odeslaných) dat (z POSTu), pokud je to možné * * @author Martin Hlaváč * @link http://www.ktstudio.cz */ public function process() { if (KT::arrayIssetAndNotEmpty($_POST) && array_key_exists(KT_Contact_Form_Base_Config::FORM_PREFIX, $_POST)) { $form = $this->getForm(); if (!$form->nonceValidate()) { wp_die(__("Chyba zpracování zdrojové adresy...", "KT_CORE_DOMAIN")); exit; } $form->validate(); if (!$form->hasError()) { $values = filter_input(INPUT_POST, KT_Contact_Form_Base_Config::FORM_PREFIX, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); if (KT::arrayIssetAndNotEmpty($values)) { $spam = KT::arrayTryGetValue($values, KT_Contact_Form_Base_Config::FAVOURITE); if (KT::issetAndNotEmpty($spam)) { wp_die(__("Vyplnili jste nepovolený kontrolní prvek...", "KT_CORE_DOMAIN")); exit; } if ($this->processMail($values)) { wp_redirect(add_query_arg($this->getProcessdParam(), "1", KT::getRequestUrl())); exit; } } } add_action(KT_PROJECT_NOTICES_ACTION, array(&$this, "renderErrorNotice")); } }