Beispiel #1
0
/**
 * Gets all logos
 * @TODO Remove "create" functionality from Getter
 *
 * @param int $company_id company ID
 * @param int $layout_id layout ID
 * @param string $style_id Style ID
 * @return array logos list
 */
function fn_get_logos($company_id = null, $layout_id = 0, $style_id = '')
{
    /**
     * Changes params before selecting logo
     *
     * @param int    $company_id company ID
     * @param int    $layout_id  layout ID
     * @param string $style_id   Style ID
     */
    fn_set_hook('get_logos_pre', $company_id, $layout_id, $style_id);
    $condition = array();
    $company_condition = '';
    if (is_null($company_id) && Registry::get('runtime.company_id')) {
        $company_id = Registry::get('runtime.company_id');
    }
    if (!is_null($company_id)) {
        $company_condition = db_quote(' AND company_id = ?i', $company_id);
    }
    $types = fn_get_logo_types();
    $layout_id = !empty($layout_id) ? $layout_id : Registry::get('runtime.layout.layout_id');
    $style_id = !empty($style_id) ? $style_id : Registry::get('runtime.layout.style_id');
    $condition[] = db_quote('IF(layout_id = 0, 1, IF(layout_id = ?i, 1, 0))', $layout_id);
    if (!empty($style_id)) {
        $condition[] = db_quote('IF(style_id = \'\', 1, IF(style_id = ?s, 1, 0))', $style_id);
    }
    /**
     * Changes conditions before selecting logo
     *
     * @param int    $company_id        company ID
     * @param int    $layout_id         layout ID
     * @param string $style_id          Style ID
     * @param array  $condition         Selecting conditions
     * @param string $company_condition Condition by companies
     */
    fn_set_hook('get_logos', $company_id, $layout_id, $style_id, $condition, $company_condition);
    $logos = db_get_hash_array("SELECT * FROM ?:logos WHERE ?p ?p", 'type', implode(' AND ', $condition), $company_condition);
    $missed_logo = array_diff_key($types, $logos);
    if (!empty($missed_logo) && (!empty($layout_id) || !empty($style_id))) {
        foreach ($missed_logo as $type => $type_data) {
            $type_data['image'] = isset($type_data['image']) ? $type_data['image'] : '';
            $logo_path = fn_get_logo_image_path($type_data['image'], $type, $style_id);
            $_logo = array('layout_id' => $layout_id, 'style_id' => $style_id, 'type' => $type, 'image_path' => fn_get_theme_path('[themes]/[theme]/', 'C', $company_id, false) . $logo_path);
            if (fn_allowed_for('MULTIVENDOR') && !empty($company_id)) {
                // Vendors have only one global logo
                unset($_logo['style_id'], $_logo['layout_id']);
            }
            Registry::set('runtime.allow_upload_external_paths', true);
            fn_update_logo($_logo, $company_id);
        }
        $logos = db_get_hash_array("SELECT * FROM ?:logos WHERE ?p ?p", 'type', implode(' AND ', $condition), $company_condition);
    }
    $logo_ids = array();
    foreach ($logos as $l) {
        $logo_ids[] = $l['logo_id'];
    }
    $images = fn_get_image_pairs($logo_ids, 'logos', 'M', true, false);
    foreach ($logos as $k => $v) {
        if (empty($images[$v['logo_id']])) {
            $logos[$k]['image'] = array();
            continue;
        }
        $image = reset($images[$v['logo_id']]);
        $logos[$k]['image'] = $image['icon'];
    }
    /**
     * Changes logos before returning
     *
     * @param int    $company_id company ID
     * @param int    $layout_id  layout ID
     * @param string $style_id   Style ID
     * @param array  $logos      Selected logos
     */
    fn_set_hook('get_logos_post', $company_id, $layout_id, $style_id, $logos);
    return $logos;
}
Beispiel #2
0
/**
 * Creates logotypes for companies and assign it to the layout
 *
 * @param int $layout_id Layout ID
 * @param int $company_id Company ID
 * @param bool $for_company Get logos only for companies
 * @return array created logo IDs
 */
function fn_create_theme_logos_by_layout_id($theme_name, $layout_id = 0, $company_id = null, $for_company = false, $style_id = '')
{
    $repo_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C', $company_id, false);
    $manifest = Themes::factory($theme_name)->getManifest();
    $logo_ids = array();
    $logo_types = fn_get_logo_types($for_company);
    Registry::set('runtime.allow_upload_external_paths', true);
    foreach ($logo_types as $type => $logo) {
        if (!$for_company) {
            $logo['image'] = isset($logo['image']) ? $logo['image'] : '';
            $image_path = fn_get_logo_image_path($logo['image'], $type, $style_id);
        } else {
            $image_path = !empty($manifest['theme']) ? $repo_dest . '/' . $manifest['theme'] : '';
        }
        if (empty($image_path)) {
            continue;
        }
        $logo_ids[$type] = fn_update_logo(array('type' => $type, 'layout_id' => !empty($logo['for_layout']) ? $layout_id : 0, 'image_path' => fn_get_theme_path('[themes]/[theme]/', 'C', $company_id, false) . $image_path, 'style_id' => !empty($logo['single_logo']) ? '' : $style_id), $company_id);
    }
    Registry::set('runtime.allow_upload_external_paths', false);
    return $logo_ids;
}
Beispiel #3
0
/**
 * Creates logotypes for companies and assign it to the layout
 *
 * @param int $layout_id Layout ID
 * @param int $company_id Company ID
 * @param bool $for_company Get logos only for companies
 * @return array created logo IDs
 */
function fn_create_theme_logos_by_layout_id($theme_name, $layout_id = 0, $company_id = null, $for_company = false, $style_id = '', $whitelist_of_logo_types = null)
{
    $repo_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C', $company_id, false);
    $manifest = Themes::factory($theme_name)->getManifest();
    $logo_ids = array();
    $logo_types = fn_get_logo_types($for_company);
    Registry::set('runtime.allow_upload_external_paths', true);
    foreach ($logo_types as $type => $logo) {
        // Whitelist of logo types was specified, but it doesn't contain current logo type
        if (is_array($whitelist_of_logo_types) && !empty($whitelist_of_logo_types) && !in_array($type, $whitelist_of_logo_types)) {
            continue;
        }
        if ($for_company) {
            $image_path = !empty($manifest['theme']) ? $repo_dest . '/' . $manifest['theme'] : '';
        } else {
            $logo['image'] = isset($logo['image']) ? $logo['image'] : '';
            $image_path = fn_get_logo_image_path($logo['image'], $type, $style_id);
        }
        if (empty($image_path)) {
            continue;
        }
        $logo_data = array('type' => $type, 'layout_id' => !empty($logo['for_layout']) ? $layout_id : 0, 'image_path' => $image_path, 'style_id' => !empty($logo['single_logo']) ? '' : $style_id);
        if (fn_allowed_for('MULTIVENDOR') && !empty($company_id)) {
            // Vendors have only one global logo
            unset($logo_data['style_id'], $logo_data['layout_id']);
        }
        $logo_ids[$type] = fn_update_logo($logo_data, $company_id);
    }
    Registry::set('runtime.allow_upload_external_paths', false);
    return $logo_ids;
}