Example #1
0
function wpci_template($default)
{
    log_message('debug', "Default template is {$default}");
    $template = $default;
    if (is_codeigniter()) {
        global $RTR;
        // application/class/action template
        if ($path = template_exists($RTR->fetch_app() . '/' . $RTR->fetch_class() . '/' . $RTR->fetch_method() . EXT)) {
            $template = $path;
        } else {
            if ($path = template_exists($RTR->fetch_app() . '/' . $RTR->fetch_class() . EXT)) {
                $template = $path;
            } else {
                if ($path = template_exists($RTR->fetch_class() . '/' . $RTR->fetch_method() . EXT)) {
                    $template = $path;
                } else {
                    if ($path = template_exists($RTR->fetch_class() . EXT)) {
                        $template = $path;
                    } else {
                        if ($path = template_exists($RTR->fetch_app() . EXT)) {
                            $template = $path;
                        } else {
                            if ($path = template_exists('codeigniter' . EXT)) {
                                $template = $path;
                            }
                        }
                    }
                }
            }
        }
    }
    log_message('debug', "Loading template {$template}");
    return $template;
}
Example #2
0
function template_get($template_name, $replacements = array())
{
    if (template_exists($template_name)) {
        //Получаем текст из файла
        $text = file_easy_read($_SERVER['DOCUMENT_ROOT'] . "/templates/{$template_name}.html");
        //Делаем замены, если массив замен не пуст
        if (count($replacements) > 0) {
            //Проходим все замены одна за другой
            foreach ($replacements as $match => $replacement) {
                //Заменяем все вхождения, соответствующие '{$match}' на '$replacement'
                $text = str_replace("{" . $match . "}", $replacement, $text);
            }
        }
        return $text;
    } else {
        echo "Файл шаблона '{$template_name}' не существует.";
    }
}
Example #3
0
function replicate_site($template_descriptions)
{
    global $sites_dir, $source_admin, $target_url, $target_admin, $template_metadata_file;
    //we first extract all the metadata of the target account, as we will need it to find which files already exists
    //and therefore should be updated but not created and which do not. These last will have to be created and populated
    $template_metadata_file = $sites_dir . $target_admin . "_metadata.txt";
    generate_ids($target_url, false);
    /*
    we will be calling create_template for each of the files passed on the file_description argument. That argument should be a file containing one entry for each file that has to be replicated
    the structire of each entry is the following:
    
    $id:$type:$system_name:$title:$path:$draft:$section_name:$section_id:$layout_name:$layout_id:$liquid_enabled:$handler;
    
    In this script, that file is created in the generate_ids function. So, basically what we need to do here is parse each line of that file and replicate the file described in there
    */
    if (!file_exists($template_descriptions)) {
        fwrite(STDOUT, "ERROR: the file to read the templates description (\"" . $template_descriptions . "\") does not seem to exist.");
        exit(1);
    }
    $templates = file($template_descriptions, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    for ($i = 0; $i < count($templates); $i++) {
        $id = preg_split("/[:]/", $templates[$i])[0];
        $type = preg_split("/[:]/", $templates[$i])[1];
        $system_name = preg_split("/[:]/", $templates[$i])[2];
        $title = preg_split("/[:]/", $templates[$i])[3];
        $path = preg_split("/[:]/", $templates[$i])[4];
        $section_name = preg_split("/[:]/", $templates[$i])[5];
        $section_id = preg_split("/[:]/", $templates[$i])[6];
        $layout_name = preg_split("/[:]/", $templates[$i])[7];
        $layout_id = preg_split("/[:]/", $templates[$i])[8];
        $liquid_enabled = preg_split("/[:]/", $templates[$i])[9];
        $handler = preg_split("/[:]/", $templates[$i])[10];
        fwrite(STDOUT, "id=" . $id . ", type=" . $type . ", system_name=" . $system_name . ", title=" . $title . ", path=" . $path . "\n");
        //according to the API documentation, all the content  of the file to be created shoudl be on the "draft" parameter, so we will extract it from the "published"
        //section of the source files
        //if $draft is empty that means that we hsould use all the content of the file in the new destination
        if ($type == "layout" || $type == "page" || $type == "partial") {
            $content = file_get_contents($sites_dir . $source_admin . "/" . $title);
        } else {
            $content = file_get_contents($sites_dir . $source_admin . "/" . $system_name);
        }
        if (!strpos($content, '<published>') == FALSE) {
            if ($type == "layout" || $type == "page" || $type == "partial") {
                $content = simplexml_load_file($sites_dir . $source_admin . "/" . $title);
            } else {
                $content = simplexml_load_file($sites_dir . $source_admin . "/" . $system_name);
            }
            $draft = $content->{'published'};
        } else {
            fwrite(STDOUT, $content);
            $draft = $content;
        }
        /*in order to check if the template exists on the target account, we can check the file <destination_account>_metadata.txt that was created at the beginning of this function
        	if there is a file with the same system_name or path, then we should skip its creation and do the update instead
        	we can use the template_exists function to check if a template is already there
        	*/
        $exists = template_exists($templates[$i], $template_metadata_file);
        if ($exists == 0) {
            //fwrite(STDOUT,"\tCreating template (".$templates[$i].")\n");
            create_template($type, $system_name, $title, $path, $section_name, $section_id, $layout_name, $layout_id, $liquid_enabled, $handler, $draft);
            //fwrite(STDOUT,"\tCREATING>".$type.", ".$system_name.", ".$title.", ".$path.", ".$section_name.", ".$section_id.", ".$layout_name.", ".$layout_id.", ".$liquid_enabled.", ".$handler."\n\n");
        } else {
            //fwrite(STDOUT,"\tUpdating template (".$templates[$i]."), matching id=".$exists."\n");
            //update_template($exists,$type,$system_name,$title,$path,$section_name,$section_id,$layout_name,$layout_id,$liquid_enabled,$handler,$draft);
            //fwrite(STDOUT,"\tUPDATING>".$type.", ".$system_name.", ".$title.", ".$path.", ".$section_name.", ".$section_id.", ".$layout_name.", ".$layout_id.", ".$liquid_enabled.", ".$handler."\n\n");
        }
    }
}
Example #4
0
 function negotiate_content(&$request, $template)
 {
     trigger_before('render_partial', $this, $this);
     foreach ($this->negotiator as $client_wants) {
         if (template_exists($request, $client_wants['id'], $template)) {
             return $client_wants['id'];
         }
     }
 }