예제 #1
0
/**
 * Returns the content of template file as text with local IDs replaced by concept IDs or viseverse
 *
 * @param mixed $filename - name of template file
 * @param mixed $mode - 0 - to concept code, 1 - to local code
 */
function convertTemplate($template, $mode)
{
    //1. get template content
    //2. find all texts within {}
    //3. find words within this text
    //4. split by .
    //5. find starting with "f"
    //6. get local DT ID - find Concept Code
    //7. replace
    //1. get template content
    if ($template == null || $template == '') {
        return array("error" => "Template is empty");
    }
    //2. find all texts within {} - expressions
    if (!preg_match_all('/\\{([^}]+)\\}/s', $template, $matches)) {
        return $template;
        // nothing to do -- no substitutions
    }
    $not_found_details = array();
    $replacements_exp = array();
    $len = count($matches[1]);
    for ($i = 0; $i < $len; ++$i) {
        $exp = $matches[1][$i];
        if (!trim($exp)) {
            continue;
        }
        //empty{}
        if (substr($exp, 0, 1) == "*" && substr($exp, -1) == "*") {
            continue;
        }
        //this is comment
        //3. find words within this text
        if (!preg_match_all('/(\\$([a-zA-Z_0-9.])+)/', $exp, $matches2)) {
            continue;
        }
        $replacements = array();
        foreach ($matches2[1] as $var) {
            //4. split by "."
            $parts = explode(".", $var);
            $parts2 = array();
            foreach ($parts as $part) {
                //5. find starting with "f"
                if (strpos($part, 'f') === 0) {
                    $prefix = 'f';
                } else {
                    if (strpos($part, '$f') === 0) {
                        $prefix = '$f';
                    } else {
                        $prefix = null;
                    }
                }
                if ($prefix) {
                    //6. get local DT ID - find Concept Code
                    $code = substr($part, strlen($prefix));
                    if (substr($part, -1) == 's') {
                        $suffix = 's';
                        $code = substr($code, 0, strlen($code) - 1);
                    } else {
                        if (endsWith($part, '_originalvalue')) {
                            $suffix = '_originalvalue';
                            $code = substr($code, 0, strlen($code) - strlen($suffix));
                        } else {
                            $suffix = "";
                        }
                    }
                    if ($mode == 0) {
                        $localID = $code;
                        if (strpos($localID, "_") === false) {
                            $conceptCode = getDetailTypeConceptID($localID);
                            $part = $prefix . str_replace("-", "_", $conceptCode) . $suffix;
                        }
                    } else {
                        $conceptCode = $code;
                        if (strpos($conceptCode, "_") !== false) {
                            $conceptCode = str_replace("_", "-", $conceptCode);
                            $localID = getDetailTypeLocalID($conceptCode);
                            if ($localID == null) {
                                //local code not found - it means that this detail is not in this database
                                array_push($not_found_details, $conceptCode);
                                $part = $prefix . "[[" . $conceptCode . "]]" . $suffix;
                            } else {
                                $part = $prefix . $localID . $suffix;
                            }
                        }
                    }
                }
                array_push($parts2, $part);
            }
            $new_var = implode(".", $parts2);
            if ($var != $new_var) {
                $replacements[$var] = $new_var;
            }
        }
        //for vars
        if (count($replacements) > 0) {
            $new_exp = "{" . array_str_replace(array_keys($replacements), array_values($replacements), $exp) . "}";
            if ($matches[0][$i] != $new_exp) {
                $replacements_exp[$matches[0][$i]] = $new_exp;
            }
        }
    }
    //for expressions
    if (count($replacements_exp) > 0) {
        $template = array_str_replace(array_keys($replacements_exp), array_values($replacements_exp), $template);
    }
    if ($mode == 1) {
        return array("template" => $template, "details_not_found" => $not_found_details);
    } else {
        return $template;
    }
}
예제 #2
0
파일: rewrites.php 프로젝트: arrmo/librenms
function short_hrDeviceDescr($dev)
{
    global $rewrite_hrDevice;
    $dev = array_str_replace($rewrite_hrDevice, $dev);
    $dev = preg_replace('/\\ +/', ' ', $dev);
    $dev = trim($dev);
    return $dev;
}
예제 #3
0
function short_ifname($if, $len = NULL, $htmlentities = TRUE)
{
    $len = is_numeric($len) ? (int) $len : FALSE;
    $if = rewrite_ifname($if, $htmlentities);
    $if = strtolower($if);
    $if = array_str_replace($GLOBALS['rewrite_shortif'], $if);
    if ($len) {
        $if = truncate($if, $len, '');
    }
    return $if;
}
예제 #4
0
function cb4_builder_content($contentos)
{
    global $post;
    $builder_id = get_post_meta($post->ID, 'cb4_builder', 'yes');
    $blocks = get_post_meta($post->ID, 'blocks', 'yes');
    if ($builder_id != '' && $builder_id != '0') {
        $blocks = array();
        $all = get_post_custom($builder_id);
        foreach ($all as $key => $block) {
            if (substr($key, 0, 9) == 'aq_block_') {
                $block_instance = get_post_meta($builder_id, $key, true);
                if (is_array($block_instance)) {
                    $blocks[$key] = $block_instance;
                }
            }
        }
        $sort = array();
        foreach ($blocks as $block) {
            $sort[] = $block['order'];
        }
        array_multisort($sort, SORT_NUMERIC, $blocks);
    }
    $content_show = true;
    if ($builder_id != '') {
        if (isset($blocks) && is_array($blocks)) {
            array_str_replace(";cbsp#21&;", "\r\n", $blocks);
            ob_start();
            $aq = new AQ_Block();
            $template_id = '';
            echo '<div id="aq-template-wrapper-' . $post->ID . '" class="aq-template-wrapper aq_row">';
            $overgrid = 0;
            $span = 0;
            $first = false;
            foreach ($blocks as $key => $instance) {
                if (isset($blocks[$key]['content'])) {
                    $instance['content'] = str_replace(";cbsp#21&;", "\r\n", $instance['content']);
                }
                global $aq_registered_blocks;
                extract($instance);
                if (class_exists($id_base)) {
                    $block = $aq_registered_blocks[$id_base];
                    $instance['template_id'] = $template_id;
                    if (isset($instance['id_base'])) {
                        if ($instance['id_base'] == "aq_content_block") {
                            $content_show = false;
                        }
                    }
                    if ($parent == 0) {
                        $col_size = absint(preg_replace("/[^0-9]/", '', $size));
                        $overgrid = $span + $col_size;
                        if ($overgrid > 12 || $span == 12 || $span == 0) {
                            $span = 0;
                            $first = true;
                        }
                        if ($first == true) {
                            $instance['first'] = true;
                        }
                        $block->block_callback($instance);
                        $span = $span + $col_size;
                        $overgrid = 0;
                        $first = false;
                    }
                }
            }
            echo '</div>';
            $con = ob_get_contents();
            ob_end_clean();
            if ($builder_id != '' && $builder_id != '0') {
                $con = str_replace('<br />', '', $con);
                $con = html_entity_decode($con);
            }
            $con = str_replace(';cbsp#21&;', '<br/>', $con);
            //echo '<pre>'.$con.'</pre>';
            if ($content_show) {
                return $contentos . $con;
            } else {
                return $con;
            }
        }
    } else {
        return $contentos;
    }
}
예제 #5
0
function make_canonical_title_mask($mask, $rt)
{
    global $titleDT;
    // convert all name-style substitutions to numerical-style
    if (!$mask) {
        return "[{$titleDT}]";
    }
    // title field
    if (!preg_match_all('/\\[\\[|\\]\\]|(\\s*(\\[\\s*([^]]+)\\s*\\]))/s', $mask, $matches)) {
        return $mask;
    }
    // nothing to do -- no substitutions
    $replacements = array();
    for ($i = 0; $i < count($matches[1]); ++$i) {
        /* $matches[3][$i] contains the field name as supplied (the string that we look up),
         * $matches[2][$i] contains the field plus surrounding whitespace and containing brackets
         *        (this is what we replace if there is a substitution)
         * $matches[1][$i] contains the field plus surrounding whitespace and containing brackets and LEADING WHITESPACE
         *        (this is what we replace with an empty string if there is no substitution value available)
         */
        $value = _title_mask__get_field_number($matches[3][$i], $rt);
        if ($value) {
            $replacements[$matches[2][$i]] = "[{$value}]";
        } else {
            $replacements[$matches[1][$i]] = "";
        }
    }
    return array_str_replace(array_keys($replacements), array_values($replacements), $mask);
}
    if ($module && in_array($module, $availableModules)) {
        $showIndex = false;
        $showError = true;
        if ($module == 'api' && $controller) {
            $controllerFile = __DIR__ . '/data/' . $controller . '.json';
            if (file_exists($controllerFile)) {
                header('Content-Type: application/json');
                echo file_get_contents($controllerFile);
                $showError = false;
            }
            if ($showError) {
                header('HTTP/1.1 301 Moved Permanently');
                header('Location: http://' . $_SERVER['HTTP_HOST'] . '/404');
                exit;
            }
        }
    }
    if ($showIndex) {
        if ($replaceSiteAddress) {
            array_str_replace($siteAddress, $replaceSiteAddress, $headCss);
            array_str_replace($siteAddress, $replaceSiteAddress, $footJs);
            $siteAddress = $replaceSiteAddress;
        }
        require 'view/index.phtml';
    }
} catch (Exception $e) {
    if ($debug) {
        echo $e;
    }
    file_put_contents(__DIR__ . '/exception.log', $e, FILE_APPEND | LOCK_EX);
}
예제 #7
0
function titlemask_make($mask, $rt, $mode, $rec_id = null, $rep_mode = _ERR_REP_WARN)
{
    global $fields_correspondence;
    if (isset($fields_correspondence)) {
        static $rdr;
        $rdr = null;
    }
    if ($rec_id) {
        _titlemask__get_record_value($rec_id, true);
        //keep recvalue in static
    }
    if (!$mask) {
        return $rep_mode != _ERR_REP_SILENT ? "Title mask is not defined" : ($mode == 0 ? _titlemask__get_forempty($rec_id, $rt) : "");
    }
    //find inside brackets
    if (!preg_match_all('/\\s*\\[\\[|\\s*\\]\\]|(\\s*(\\[\\s*([^]]+)\\s*\\]))/s', $mask, $matches)) {
        return $mask;
    }
    // nothing to do -- no substitutions
    $replacements = array();
    $len = count($matches[1]);
    $fields_err = 0;
    $fields_blank = 0;
    for ($i = 0; $i < $len; ++$i) {
        /* $matches[3][$i] contains the field name as supplied (the string that we look up),
         * $matches[2][$i] contains the field plus surrounding whitespace and containing brackets
         *        (this is what we replace if there is a substitution)
         * $matches[1][$i] contains the field plus surrounding whitespace and containing brackets and LEADING WHITESPACE
         *        (this is what we replace with an empty string if there is no substitution value available)
         */
        if (!trim($matches[3][$i])) {
            continue;
        }
        //empty []
        $value = _titlemask__fill_field($matches[3][$i], $rt, $mode, $rec_id);
        if (is_array($value)) {
            //ERROR
            if ($rep_mode == _ERR_REP_WARN) {
                return _ERROR_MSG;
            } else {
                if ($rep_mode == _ERR_REP_MSG) {
                    return $value;
                } else {
                    $replacements[$matches[1][$i]] = "";
                    $fields_err++;
                    //return "";
                }
            }
        } else {
            if (null == $value || trim($value) == "") {
                $replacements[$matches[1][$i]] = "";
                $fields_blank++;
            } else {
                if ($mode == 0) {
                    //value
                    $replacements[$matches[2][$i]] = $value;
                } else {
                    //coded or human readable
                    $replacements[$matches[2][$i]] = "[{$value}]";
                }
            }
        }
    }
    if ($mode == 0) {
        if ($fields_err == $len) {
            return _titlemask__get_forempty($rec_id, $rt);
        }
        $replacements['[['] = '[';
        $replacements[']]'] = ']';
    }
    $title = array_str_replace(array_keys($replacements), array_values($replacements), $mask);
    if ($mode == 0) {
        //fill the mask with values
        if ($fields_blank == $len && $rec_id) {
            //If all the title mask fields are blank
            $title = "Record ID {$rec_id} - no data has been entered in the fields used to construct the title";
        }
        /* Clean up miscellaneous stray punctuation &c. */
        if (!preg_match('/^\\s*[0-9a-z]+:\\S+\\s*$/i', $title)) {
            // not a URI
            $puncts = '-:;,.@#|+=&';
            // These are stripped from end of title if no field data follows them
            $puncts2 = '-:;,@#|+=&';
            // same less period
            $title = preg_replace('!^[' . $puncts . '/\\s]*(.*?)[' . $puncts2 . '/\\s]*$!s', '\\1', $title);
            $title = preg_replace('!\\([' . $puncts . '/\\s]+\\)!s', '', $title);
            $title = preg_replace('!\\([' . $puncts . '/\\s]*(.*?)[' . $puncts . '/\\s]*\\)!s', '(\\1)', $title);
            $title = preg_replace('!\\([' . $puncts . '/\\s]*\\)|\\[[' . $puncts . '/\\s]*\\]!s', '', $title);
            $title = preg_replace('!^[' . $puncts . '/\\s]*(.*?)[' . $puncts2 . '/\\s]*$!s', '\\1', $title);
            $title = preg_replace('!,\\s*,+!s', ',', $title);
            $title = preg_replace('!\\s+,!s', ',', $title);
        }
        $title = trim(preg_replace('!  +!s', ' ', $title));
        if ($title == "") {
            if ($rep_mode == _ERR_REP_SILENT) {
                $title = _titlemask__get_forempty($rec_id, $rt);
            } else {
                if ($rep_mode == _ERR_REP_MSG) {
                    return array(_EMPTY_MSG);
                } else {
                    return _EMPTY_MSG;
                }
            }
        }
    }
    return $title;
}
 function getTitle()
 {
     // Construct/retrieve the formatted title for this entry,
     // based on the reference type's title mask.
     global $heurist_rectypes;
     if (!$heurist_rectypes) {
         load_heurist_rectypes();
     }
     if (!$this->getBiblioID()) {
         return "";
     }
     if ($this->_title) {
         return $this->_title;
     }
     $mask = $heurist_rectypes[$this->_rectype]['rty_TitleMask'];
     $this->_title = fill_title_mask($mask, $this->getBiblioID(), $this->getReferenceType());
     return $this->_title;
     // fin     FIXME  the code below never executes, looks old and refactored into TitleMask.php ?remove?
     global $heurist_rectypes, $bib_type_names;
     if (!$heurist_rectypes) {
         load_heurist_rectypes();
     }
     if (!$bib_type_names) {
         load_bib_type_names();
     }
     $mask = $heurist_rectypes[$this->_rectype]['rty_TitleMask'];
     if (!$mask) {
         return '';
     }
     if (!preg_match_all('/\\[\\[|\\]\\]|(\\s*(\\[\\s*([^]]+)\\s*\\]))/s', $mask, $matches)) {
         return $this->_title = $mask;
     }
     // nothing to do -- no substitutions
     $replacements = array();
     for ($i = 0; $i < count($matches[1]); ++$i) {
         /*
          * $matches[3][$i] contains the field name as supplied (the string that we look up),
          * $matches[2][$i] contains the field plus surrounding whitespace and containing brackets
          *        (this is what we replace if there is a substitution)
          * $matches[1][$i] contains the field plus surrounding whitespace and containing brackets and LEADING WHITESPACE
          *        (this is what we replace with an empty string if there is no substitution value available)
          */
         $value = $this->get_field_value($matches[3][$i]);
         if ($value) {
             $replacements[$matches[2][$i]] = $value;
         } else {
             $replacements[$matches[1][$i]] = '';
         }
     }
     $replacements['magic-open-bracket'] = '[';
     $replacements['magic-close-bracket'] = ']';
     $title = array_str_replace(array_keys($replacements), array_values($replacements), $mask);
     $title = preg_replace('!^[-:;,./\\s]*(.*?)[-:;,/\\s]*$!s', '\\1', $title);
     $title = preg_replace('!\\([-:;,./\\s]+\\)!s', '', $title);
     $title = preg_replace('!\\([-:;,./\\s]*(.*?)[-:;,./\\s]*\\)!s', '(\\1)', $title);
     $title = preg_replace('!\\([-:;,./\\s]*\\)|\\[[-:;,./\\s]*\\]!s', '', $title);
     $title = preg_replace('!,,+!s', ',', $title);
     $title = preg_replace('!\\s+,!s', ',', $title);
     $title = preg_replace('!  +!s', ' ', $title);
     /* Clean up miscellaneous stray punctuation &c. */
     return $this->_title = trim($title);
 }
예제 #9
0
 /**
  * Main page builder page display
  *
  * @since	1.0.0
  */
 function builder_page_show()
 {
     global $post;
     $post_id = $post->ID;
     $cb4_builder_id = get_post_meta($post_id, 'cb4_builder', true);
     $new_template = get_post_meta($post_id, 'new_template', true);
     $cb4_post_blocks = get_post_meta($post_id, 'blocks');
     if (!isset($cb4_post_blocks[0])) {
         $cb4_post_blocks[0] = '';
     }
     $new_blocks = $cb4_post_blocks[0];
     if (is_array($new_blocks)) {
         foreach ($new_blocks as $key => $value) {
             if ($value['id_base'] == 'aq_clear_block') {
                 unset($new_blocks[$key]);
             }
             if ($value['id_base'] == 'aq_tabs_block') {
                 for ($i = 1; $i <= sizeof($new_blocks[$key]['tabs']); $i++) {
                     if (isset($new_blocks[$key]['tabs'][$i]['content'])) {
                         $new_blocks[$key]['tabs'][$i]['content'] = str_replace(";cbsp#21&;", "\r\n", $new_blocks[$key]['tabs'][$i]['content']);
                     }
                 }
             }
             if (isset($new_blocks[$key]['content'])) {
                 $new_blocks[$key]['content'] = str_replace(";cbsp#21&;", "\r\n", $new_blocks[$key]['content']);
             }
         }
         array_str_replace(";cbsp#21&;", "\r\n", $new_blocks);
         $cb4_post_blocks[0] = $new_blocks;
     }
     require_once AQPB_PATH . 'view/view-builder-page.php';
 }