Example #1
0
 function synved_option_item_addon_install($id, $name, $item)
 {
     $return = null;
     $type = synved_option_item_type($item);
     $target = synved_option_item_property($item, 'target');
     $folder = synved_option_item_property($item, 'folder');
     $field_name = synved_option_name_default($id);
     $path = null;
     if (file_exists($target)) {
         $path = $target;
     }
     if ($type != 'addon' || $path == null) {
         return false;
     }
     $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
     if (substr($path, -1) != DIRECTORY_SEPARATOR) {
         $path .= DIRECTORY_SEPARATOR;
     }
     if (isset($_FILES[$field_name])) {
         foreach ($_FILES[$field_name]["error"] as $key => $error) {
             if ($key == $name && $error == UPLOAD_ERR_OK) {
                 $tmp_name = $_FILES[$field_name]["tmp_name"][$key];
                 $name = $_FILES[$field_name]["name"][$key];
                 $tmpfname = wp_tempnam($name . '.zip');
                 if (move_uploaded_file($tmp_name, $tmpfname)) {
                     global $wp_filesystem;
                     $unzip_path = realpath($path);
                     $dirs = glob($path . '*', GLOB_ONLYDIR);
                     if ($wp_filesystem != null) {
                         $unzip_path = $wp_filesystem->find_folder($unzip_path);
                     }
                     wp_mkdir_p(realpath($path));
                     $return = unzip_file($tmpfname, $unzip_path);
                     if ($wp_filesystem != null) {
                         $wp_filesystem->delete($tmpfname);
                     }
                     $dirs_new = glob($path . '*', GLOB_ONLYDIR);
                     $dirs_diff = array_values(array_diff($dirs_new, $dirs));
                     $addon_path = $path;
                     if ($dirs_diff != null) {
                         $folder_path = null;
                         foreach ($dirs_diff as $dir) {
                             if (basename($dir) == $folder) {
                                 $folder_path = $dir;
                             }
                         }
                         // XXX no correct path, was unzip successful?
                         if ($folder_path == null) {
                             $folder_path = $dirs_diff[0];
                         }
                         $addon_path = $folder_path;
                     }
                     synved_option_set($id, $name, $addon_path);
                 }
             }
         }
     }
     return $return;
 }
Example #2
0
function synved_option_print_head_outputs()
{
    global $synved_option_list;
    foreach ($synved_option_list as $id => $list) {
        $items = synved_option_item_list($id);
        $outputs = $list['outputs'];
        foreach ($outputs as $name => $item) {
            $type = synved_option_item_type($item);
            $mode = synved_option_item_mode($item);
            if (in_array('manual', $mode)) {
                continue;
            }
            $content = synved_option_get($id, $name);
            $tag = null;
            $attrs = null;
            if ($type == 'style') {
                $tag = $type;
                $attrs['type'] = 'text/css';
            } else {
                if ($type == 'script') {
                    $tag = $type;
                    $attrs['type'] = 'text/javascript';
                    $content = '/* <![CDATA[ */' . "\r\n" . $content . "\r\n" . '/* ]]> */';
                }
            }
            if ($tag != null) {
                echo "\r\n" . '<' . $tag;
                foreach ($attrs as $attr_name => $attr_value) {
                    echo ' ' . $attr_name . '="' . esc_attr($attr_value) . '"';
                }
                echo '>';
                echo $content;
                echo '</' . $tag . '>' . "\r\n";
            }
        }
    }
}
function synved_option_page_add($id, $name, $item)
{
    global $synved_option_list;
    $type = synved_option_item_type($item);
    if ($type == 'options-page') {
        $label = synved_option_item_label($item);
        $tip = synved_option_item_tip($item);
        $parent = synved_option_item_parent($item);
        $role = synved_option_item_role($item);
        if ($label == null) {
            $label = $name;
        }
        $page_slug = $id . '_' . $name;
        $addfunc = 'add_' . 'subm' . 'enu_page';
        $page = $addfunc($parent, $label, $label, $role, $page_slug, create_function('', 'return synved_option_page_cb(\'' . $id . '\', \'' . $name . '\', synved_option_item_find(\'' . $id . '\', \'' . $name . '\'));'));
        $synved_option_list[$id]['pages'][$name]['wp-page-slug'] = $page_slug;
        $synved_option_list[$id]['pages'][$name]['wp-page'] = $page;
        return $page;
    }
    return null;
}
function synved_option_render_item($id, $name, $item = null, $render = false, $params = null, $context = null)
{
    if ($item == null) {
        $item = synved_option_item($id, $name);
    }
    if ($item == null) {
        return null;
    }
    $value = synved_option_get($id, $name);
    $type = synved_option_item_type($item);
    $style = synved_option_item_style($item);
    $label = synved_option_item_label($item);
    $tip = synved_option_item_tip($item);
    $hint = synved_option_item_hint($item);
    $default = synved_option_item_default($item);
    $set = synved_option_item_set($item);
    $set_is_linear = false;
    if ($set != null) {
        $set_is_linear = true;
        foreach ($set as $set_it) {
            if (count($set_it) > 1) {
                $set_is_linear = false;
                break;
            }
        }
    }
    $out_name = synved_option_render_field_name($id, $name);
    $out_id = synved_option_render_field_id($id, $name);
    $out = null;
    if (isset($params['output_name'])) {
        $out_name = $params['output_name'];
    }
    if (isset($params['output_id'])) {
        $out_id = $params['output_id'];
    }
    if (isset($params['tip'])) {
        $tip = $params['tip'];
    }
    if (isset($params['default'])) {
        $default = $params['default'];
    }
    if (isset($params['value'])) {
        $value = $params['value'];
    }
    $new_value = $value;
    $error_list = synved_option_item_validate_value($id, $name, $value, $new_value, $item);
    if ($new_value != $value && ($context == null || $context == 'settings')) {
        synved_option_set($id, $name, $new_value);
        $value = synved_option_get($id, $name);
    }
    if ($error_list != null) {
        foreach ($error_list as $error) {
            $out .= '<div id="message" class="error"><p>For "<i>' . $label . '</i>": ' . $error['message'] . '</p></div>';
        }
    }
    if ($set_is_linear) {
        $out .= '<select name="' . $out_name . '" id="' . $out_id . '">';
        // XXX exception...remove at some point
        if (isset($params['set_before'])) {
            $set_before = $params['set_before'];
            $set = array_merge($set_before, $set);
        }
        foreach ($set as $set_it) {
            $set_it_keys = array_keys($set_it);
            $selected = $set_it_keys[0] == $value ? ' selected="selected"' : null;
            $out .= '<option value="' . $set_it_keys[0] . '"' . $selected . '>' . $set_it[$set_it_keys[0]] . '</option>';
        }
        $out .= '</select>';
    } else {
        $placeholder = null;
        if ($hint != null) {
            $placeholder = ' placeholder="' . esc_attr($hint) . '"';
        }
        switch ($type) {
            case 'boolean':
                $checked = $value == true ? ' checked="checked"' : null;
                $out .= '<fieldset><legend class="screen-reader-text"><span>' . $label . '</span></legend><label for="' . $out_id . '"><input type="hidden" name="' . $out_name . '" value="0" /><input name="' . $out_name . '" id="' . $out_id . '" type="checkbox" value="1" class="code" ' . $checked . $placeholder . ' /> ' . $label . '</label>&nbsp;&nbsp;<span class="description" style="vertical-align:middle;">' . $tip . '</span></fieldset>';
                break;
            case 'text':
            case 'style':
            case 'script':
            case 'image':
            case 'video':
            case 'media':
                $atts = array('name' => $out_name, 'type' => 'text', 'id' => $out_id, 'value' => $value, 'class' => 'regular-text');
                $att_style = array();
                $content = null;
                $tag = 'input';
                $extended = false;
                if ($style != null) {
                    if (in_array('wide', $style)) {
                        $atts['class'] = 'wide-text';
                    }
                    if (in_array('extend', $style)) {
                        $extended = true;
                    }
                }
                if (in_array($type, array('style', 'script'))) {
                    $extended = true;
                    $att_style['width'] = '450px';
                    $att_style['height'] = '250px';
                }
                if ($extended) {
                    $tag = 'textarea';
                    if (isset($atts['value'])) {
                        $content = $atts['value'];
                        unset($atts['value']);
                    }
                    if ($content == null) {
                        $content = '';
                    }
                    unset($atts['type']);
                }
                if ($hint != null) {
                    $atts['placeholder'] = $hint;
                }
                if ($att_style != null) {
                    $att_css = null;
                    foreach ($att_style as $style_name => $style_value) {
                        $att_css .= $style_name . ':' . $style_value . ';';
                    }
                    $atts['style'] = $att_css;
                }
                $out .= '<' . $tag;
                foreach ($atts as $att_name => $att_value) {
                    $out .= ' ' . $att_name . '="' . esc_attr($att_value) . '"';
                }
                if ($content !== null) {
                    $out .= '>' . esc_html($content) . '</' . $tag . '>';
                } else {
                    $out .= ' />';
                }
                if (in_array($type, array('image', 'video', 'media'))) {
                    $out .= '<input type="hidden" name="' . esc_attr(synved_option_render_field_name($id, $name . '_info_')) . '" value="' . esc_attr($type) . '" />';
                    $out .= '&nbsp;&nbsp;<input type="button" class="synved-option-upload-button" value="' . esc_attr(__('Select File', 'synved-option')) . '"' . $placeholder . ' />';
                }
                break;
            case 'color':
                $out .= '<div style="position:relative; float: left;">';
                $out .= '<input name="' . $out_name . '" id="' . $out_id . '" type="text" value="' . esc_attr($value) . '" class="code medium-text color-input"' . $placeholder . ' />';
                $out .= '<div class="synved-option-color-input-picker" style="background:white;border:solid 1px #ccc;display:none;position:absolute;top:100%;left:0;z-index:10000;"></div>';
                $out .= '</div>';
                break;
            case 'integer':
            case 'decimal':
                $out .= '<input name="' . $out_name . '" id="' . $out_id . '" type="text" value="' . esc_attr($value) . '" class="code small-text"' . $placeholder . ' />';
                break;
            case 'user':
            case 'author':
            case 'category':
            case 'page':
                $args = array('echo' => false, 'name' => $out_name, 'id' => $name, 'selected' => $value, 'show_option_all' => __('Every', 'synved-option') . ' ' . ucfirst($type));
                $drop_out = null;
                switch ($type) {
                    case 'author':
                        $args['who'] = 'author';
                    case 'user':
                        $drop_out = wp_dropdown_users($args);
                        break;
                    case 'category':
                        $drop_out = wp_dropdown_categories($args);
                        break;
                    case 'page':
                        $args['show_option_no_change'] = $args['show_option_all'];
                        $drop_out = wp_dropdown_pages($args);
                        break;
                }
                $out .= $drop_out;
                break;
            case 'tag-list':
                $out .= '<input name="' . $out_name . '" id="' . $out_id . '" type="text" value="' . esc_attr($value) . '" class="regular-text synved-option-tag-selector"' . $placeholder . ' />';
                break;
            case 'addon':
                if (function_exists('synved_option_render_type_addon')) {
                    $out .= synved_option_render_type_addon($id, $name, $item, $out_name, array('out_id' => $out_id, 'label' => $label));
                }
                break;
        }
        if ($hint != null) {
            $out .= ' <span class="snvdopt"><a class="button synved-option-reset-button" title="' . __('Set value to default hinted background value', 'synved-option') . '" style="display: inline-block; padding: 0; vertical-align: middle; cursor: pointer;"><span class="ui-icon ui-icon-arrowrefresh-1-w"> </span></a></span>';
        }
    }
    $item_render = synved_option_item_render($item);
    if ($item_render != null) {
        $error = null;
        $new_out = null;
        try {
            $params = array('output_name' => $out_name, 'output_id' => $out_id, 'output' => $out, 'set' => $set, 'label' => $label);
            $new_out = $item_render->Invoke(array($value, $params, $name, $id, $item));
        } catch (Exception $ex) {
            $new_out = null;
            $error = $ex->getMessage();
        }
        if ($new_out !== null) {
            $out = $new_out;
        }
    }
    if ($out != null) {
        if ($tip != null && $type != 'boolean') {
            $tip_class = ' description-' . $type;
            $out .= '&nbsp;&nbsp;<span class="description' . $tip_class . '">' . $tip . '</span>';
        }
        if ($render) {
            echo $out;
        } else {
            return $out;
        }
    }
    return null;
}
function synved_option_item_addon_is_installed(array $item)
{
    if ($item != null) {
        $type = synved_option_item_type($item);
        if ($type == 'addon') {
            $target = synved_option_item_property($item, 'target');
            $folder = synved_option_item_property($item, 'folder');
            $path = $target;
            if ($path != null) {
                $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
                if (substr($path, -1) != DIRECTORY_SEPARATOR) {
                    $path .= DIRECTORY_SEPARATOR;
                }
                $path .= $folder;
                if (is_dir($path)) {
                    return true;
                }
            }
            $module = synved_option_item_property($item, 'module');
            if ($module != null) {
                $addon_list = synved_plugout_module_addon_list($module);
                if (isset($addon_list[$folder])) {
                    return true;
                }
            }
        }
    }
    return false;
}