| Server IP : 157.230.181.24 / Your IP : 216.73.217.11 Web Server : Apache/2.4.58 (Ubuntu) System : Linux conductive 6.8.0-117-generic #117-Ubuntu SMP PREEMPT_DYNAMIC Tue May 5 19:26:24 UTC 2026 x86_64 User : ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/vhosts/conductivemarketing/app/helpers/ |
Upload File : |
<?php
/**
* Returns location to asset inside of theme folder
*
* @param string $path Path to asset
*
* @return string Full URL to the asset in the theme directory
*/
/**
* Get a url for the site
*
* @param string $uri
* @return string
*/
function url($uri = '')
{
return stripos($_SERVER['SERVER_PROTOCOL'], 'https') === TRUE ? 'https://' : 'http://' . $_SERVER["HTTP_HOST"] . $uri;
}
/**
* Return the current URL
*
* @param string $uri
* @param bool $stripQuery
* @return string
*/
function current_url($uri = '', $stripQuery = FALSE)
{
$str = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === TRUE ? 'https://' : 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
if ($stripQuery) {
$str = preg_replace('/\?.*/', '', $str);
}
$str .= $uri;
return $str;
}
/**
* Redirect to another url. This maybe should be done with Redirect::to() instead of WP's function
*
* @param $url
*/
function redirect($url)
{
wp_redirect($url);
}
/**
* Link to asset
*
* @param $path
* @return string
*/
function asset($path)
{
if ($path{0} !== '/') {
$path = "/$path";
}
$path = preg_replace('/ /', '%20', $path);
return get_bloginfo('template_directory') . "/dist$path";
}
/**
* Link to image
*
* @param $path
* @return string
*/
function image($path)
{
if ($path{0} !== '/') {
$path = "/$path";
}
return asset("images$path");
}
/**
* Link to SVG
*
* @param $path
* @return string
*/
function svg($path)
{
if ($path{0} !== '/') {
$path = "/$path";
}
return asset("svg$path");
}
/**
* Get SVG for inline including
*
* @param $filename
* @return string
*/
function inlineSvg($filename)
{
$path = TEMPLATEPATH . "/dist/svg/$filename";
try {
$contents = file_get_contents($path);
return $contents;
} catch (Exception $e) {
return "File not found $path";
}
}
/**
* Perl regular expression replace all matches
*
* @param $find
* @param $replacement
* @param $s
*
* @return mixed
*/
function preg_replace_all($find, $replacement, $s)
{
while (preg_match($find, $s)) {
$s = preg_replace($find, $replacement, $s);
}
return $s;
}
/**
* Return the specified post's thumbnail src
*
* @param int $post_id
* @param string $size
*
* @return array|bool
*/
function get_post_thumbnail_src($post_id, $size = 'full')
{
$data = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $size);
if (isset($data) && is_array($data)) {
return $data[0];
//return (Object)[
// 'src' => $data[0],
// 'width' => $data[1],
// 'height' => $data[2],
//];
} else {
return NULL;
}
}
/**
* Find an attached image via URL
*
* @param string $url
* @param string $size
*
* @return string
*/
function wp_get_attached_image_by_url($url, $size = 'full')
{
global $wpdb;
$file_path = str_replace(get_bloginfo('url') . '/wp-content/uploads/', '', $url);
$attached = $wpdb->get_row("SELECT meta_value FROM `wp_postmeta` WHERE meta_value LIKE '%$file_path%' AND meta_key='_wp_attachment_metadata'");
$attached = maybe_unserialize($attached->meta_value);
if ($size == 'full') {
$thumb = $attached['file'];
} else {
$thumb = $attached['sizes'][$size]['file'];
}
$filename = preg_replace('/[0-9]{4}\/[0-9]{2}\//', '$1', $file_path);
$path = str_replace($filename, '', $url);
if ($path && $thumb) {
return $path . $thumb;
} else {
return $url;
}
}
/**
* Does precisely what it says.
* Strips the -320x140.ext out of the image url
*
* @param $url
*
* @return string
*/
function wp_strip_upload_dimensions($url)
{
$r = '';
if ($url) {
// Strip absolute path
$file_name = preg_replace('/^(.*?)\/wp-content\/uploads\//', '', $url);
// Strip resolution
$file_name = preg_replace('/-([0-9]+?)x([0-9]+?)\./', '.', $file_name);
$r = site_url("wp-content/uploads/$file_name");
}
return $r;
}
/**
* Limit paragraph based on character count, break at last word
*
* @param $str
* @param int $n
* @param string $end_char
*
* @return mixed|string
*/
function character_limiter($str, $n = 500, $end_char = '…')
{
if (strlen($str) < $n) {
return $str;
}
$str = preg_replace("/\s+/", ' ', str_replace(["\r\n", "\r", "\n"], ' ', $str));
if (strlen($str) <= $n) {
return $str;
}
$out = "";
foreach (explode(' ', trim($str)) as $val) {
$out .= $val . ' ';
if (strlen($out) >= $n) {
$out = trim($out);
return (strlen($out) == strlen($str)) ? $out : $out . $end_char;
}
}
}
/**
* Zipper two arrays together (even odds mix)
*
* @param $arrayFirst
* @param $arraySecond
* @return array
*
*/
function array_zipper($arrayFirst, $arraySecond)
{
if (!is_array($arrayFirst) || empty($arrayFirst)) {
return $arraySecond;
} else if (!is_array($arraySecond) || empty($arraySecond)) {
return $arrayFirst;
} else {
for ($i = 0; $i < count($arraySecond); $i++) {
array_splice($arrayFirst, ($i * 2) + 1, 0, $arraySecond[$i]);
}
return $arrayFirst;
}
}
/**
* Convert array to string of html attributes
*
* @param array|object $attr
* @return string
*/
function htmlattr($attr = [])
{
if (is_array($attr)) {
return implode(' ', array_map(function ($key, $val) {
return $key . '="' . htmlspecialchars($val) . '"';
}, array_keys($attr), $attr));
} else if (is_object($attr)) {
$r = [];
foreach ($attr as $key => $val) {
$r[] = $key . '="' . htmlspecialchars($val) . '"';
}
return implode(' ', $r);
}
}
/**
* Echo out, if an conditional proves true
*
* @param $condition
* @param $echo
* @param string $else
*/
function echo_if($condition, $echo, $else = NULL)
{
echo $condition ? $echo : $else;
}
/**
* Get a post's content by its ID
*
* @param $id
* @return mixed|string
*/
function get_content_by_id($id)
{
$content_post = get_post($id);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
/**
* Convert all emails to links
*
* @param $text
* @return mixed
*/
function emailize($text)
{
$regex = '/(\S+@\S+\.\S+)/';
$replace = '<a href="mailto:$1">$1</a>';
return preg_replace($regex, $replace, $text);
}
/**
* Make number tel: link friendly
*
* @param $number
* @return mixed
*/
function tel_link($number)
{
return preg_replace('/\D/', '', $number);
}
/**
* Paginate links in bootstrap's styling
*
* @param bool $echo
* @return string
*/
function bootstrapPagination($echo = TRUE)
{
global $wp_query;
$big = 999999999; // need an unlikely integer
$pages = paginate_links([
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'type' => 'array',
'prev_next' => TRUE,
'prev_text' => '<svg xmlns="http://www.w3.org/2000/svg" width="15px" height="15px" viewBox="0 0 50 80" xml:space="preserve">
<polyline fill="none" stroke="#4f8f65" stroke-width="10" stroke-linecap="round" stroke-linejoin="round" points="
45.63,75.8 0.375,38.087 45.63,0.375 "/>
</svg> ',
'next_text' => '<svg xmlns="http://www.w3.org/2000/svg" width="15px" height="15px" viewBox="0 0 50 80" xml:space="preserve">
<polyline fill="none" stroke="#4f8f65" stroke-width="10" stroke-linecap="round" stroke-linejoin="round" points="0.375,0.375 45.63,38.087 0.375,75.8 "/>
</svg>',
]
);
if (is_array($pages)) {
$paged = (get_query_var('paged') == 0) ? 1 : get_query_var('paged');
$pagination = '<ul class="pagination">';
foreach ($pages as $page) {
$pagination .= "<li class=\"page-item\">$page</li>";
}
$pagination .= '</ul>';
if ($echo) {
echo $pagination;
} else {
return $pagination;
}
}
}