Beispiel #1
0
        echo '
			<a href="#prev" class="bio-carousel-nav" id="bio-carousel-prev">' . __('prev', 'favepersonal') . '</a>
			<a href="#next" class="bio-carousel-nav" id="bio-carousel-next">' . __('next', 'favepersonal') . '</a>';
    }
    echo '
		</div>';
}
?>
<div class="bio-box-content">
	<h2 class="bio-box-title"><?php 
echo $settings['title'];
?>
</h2>
	<?php 
echo do_shortcode(wpautop(wptexturize($settings['description'])));
?>
</div>
<?php 
if (!empty($settings['links'])) {
    echo '<div class="bio-box-links clearfix"><ul>';
    foreach ($settings['links'] as $link) {
        if (empty($link['url']) || empty($link['title'])) {
            continue;
        }
        if (empty($link['favicon'])) {
            $link['favicon'] = 'default';
        }
        echo '<li><a href="' . esc_url($link['url']) . '" title="' . esc_attr($link['title']) . '" rel="me">' . '<img width="16" height="16" alt="' . esc_attr($link['title']) . '" src="' . cfcp_about_favicon_url($link['favicon']) . '" /></a></li>' . PHP_EOL;
    }
    echo '</ul></div>';
}
Beispiel #2
0
/**
 * Generic Ajax handler
 *
 * @return void
 */
function cfcp_about_admin_ajax()
{
    if (!empty($_POST['cfcp_about_action'])) {
        switch ($_POST['cfcp_about_action']) {
            case 'cfcp_image_search':
                $results = cfcp_about_image_search(array('key' => $_POST['key'], 'term' => $_POST['cfp-img-search-term'], 'exclude' => !empty($_POST['cfcp_search_exclude']) ? array_map('intval', $_POST['cfcp_search_exclude']) : array()));
                $ret = array('success' => !empty($results) ? true : false, 'key' => $_POST['key'], 'html' => !empty($results) ? $results : '<div class="cfp-img-search-no-results">' . __('No results found.', 'favepersonal') . '</div>');
                break;
            case 'cfcp_fetch_favicon':
                usleep(500000);
                // pause for 1/2 second to allow the spinner to at least display in the admin
                $u = new CF_Favicon_Fetch(cfcp_about_get_favicon_dir());
                $favicon = $u->have_site_favicon($_POST['url']);
                if (empty($favicon)) {
                    $success = false;
                    $favicon = $u->get_site_favicon_url($_POST['url']);
                    if (!empty($favicon)) {
                        $success = true;
                        $favicon_status = 'new';
                    } else {
                        $success = false;
                        $favicon = cfcp_about_favicon_url('default');
                        $favicon_status = 'default';
                    }
                } else {
                    $success = true;
                    $favicon = cfcp_about_favicon_url($favicon);
                    $favicon_status = 'local';
                }
                $ret = array('success' => $success, 'favicon_url' => $favicon, 'favicon_status' => $favicon_status);
                break;
            case 'cfcp_save_favicon':
                $success = false;
                $error = '';
                $link = array('title' => trim($_POST['link']['title']), 'url' => trim($_POST['link']['url']), 'favicon' => trim($_POST['link']['favicon']), 'favicon_status' => trim($_POST['link']['favicon_status']));
                $qs = strpos($link['favicon'], '?');
                if ($qs !== false) {
                    $link['favicon'] = substr($link['favicon'], 0, $qs);
                }
                // fetch
                if (!empty($link['url']) && !empty($link['title'])) {
                    if ($link['favicon_status'] == 'new') {
                        $u = new CF_Favicon_Fetch(cfcp_about_get_favicon_dir());
                        $a = $u->get_favicon($link['url']);
                        if (!empty($a) && $a != 'default') {
                            $link['favicon'] = basename($a);
                            $link['favicon_status'] = 'local';
                        } else {
                            $link['favicon'] = 'default';
                            $link['favicon_status'] = 'local';
                        }
                        if (!empty($link['favicon'])) {
                            $success = true;
                        } else {
                            $error = $u->get_last_error();
                        }
                    } elseif ($link['favicon_status'] == 'local' || $link['favicon_status'] == 'default') {
                        if ($link['favicon_status'] == 'default') {
                            $link['favicon'] = 'default';
                        } else {
                            $link['favicon'] = basename($link['favicon']);
                        }
                        $success = true;
                    } elseif ($link['favicon_status'] == 'custom') {
                        $u = new CF_Favicon_Fetch(cfcp_about_get_favicon_dir());
                        // download and save favicon
                        $f_data = $u->fetch_favicon($link['favicon']);
                        $filename = $u->make_filename($link['url'], $f_data['ext']);
                        if ($u->save_file($filename, $f_data) !== false) {
                            $link['favicon'] = $filename;
                            $link['favicon_status'] = 'local';
                            $success = true;
                        }
                    }
                } else {
                    if (empty($link['title'])) {
                        $error += '<p>' . __('Please enter a valid link title.', 'favepersonal') . '</p>';
                    }
                    if (empty($link['url'])) {
                        $error += '<p>' . __('Please enter a valid link URL.', 'favepersonal') . '</p>';
                    }
                }
                // formulate response
                if ($success) {
                    $ret = array('success' => true, 'html' => cfct_template_content('functions/about/views', 'link-item', compact('link')));
                } else {
                    $ret = array('success' => false, 'error' => $error);
                }
                break;
        }
        header('Content-Type: application/json');
        echo json_encode($ret);
        exit;
    }
}
<?php

$favicon_url = !empty($link['favicon']) ? cfcp_about_favicon_url($link['favicon']) : cfcp_about_favicon_url('default');
// json encoding the link data looks weird but it allows us much more freedom with sortables
// we can do name="settings[links][]" and let the dom order be the order instead of having to
// keep track of the items ids and the order during editing
?>
<li class="cfp-about-link-item" id="link-<?php 
echo md5(json_encode($link));
?>
">
	<a href="<?php 
echo esc_url($link['url']);
?>
"><img src="<?php 
echo $favicon_url;
?>
" width="16" height="16" /></a>
	<input type="hidden" name="<?php 
echo CFCP_ABOUT_SETTINGS;
?>
[links][]" value='<?php 
echo json_encode($link);
?>
' />
</li>