static function loadBaseURL() { $absolute_plugin_folder = RealPath(self::$plugin_folder); if (StrPos($absolute_plugin_folder, ABSPATH) === 0) { self::$base_url = Get_Bloginfo('wpurl') . '/' . SubStr($absolute_plugin_folder, Strlen(ABSPATH)); } else { self::$base_url = Plugins_Url(BaseName(self::$plugin_folder)); } self::$base_url = Str_Replace("\\", '/', self::$base_url); # Windows Workaround }
function rupiah($uang) { $rupiah = ""; $panjang = Strlen($uang); while ($panjang > 3) { $rupiah = "." . substr($uang, -3) . $rupiah; $lebar = strlen($uang) - 3; $uang = substr($uang, 0, $lebar); $panjang = strlen($uang); } $rupiah = "IDR " . $uang . $rupiah . ",-"; return $rupiah; }
function __construct() { if (Is_Admin() && !$this->Validate_Licence()) { $this->base_url = get_bloginfo('wpurl') . '/' . Str_Replace("\\", '/', SubStr(RealPath(DirName(__FILE__)), Strlen(ABSPATH))); Add_Action('admin_init', array($this, 'Load_TextDomain')); Add_Action('admin_init', array($this, 'Add_Contribution_Code_Field')); Add_Action('admin_print_footer_scripts', array($this, 'Print_Contribution_JS'), 99); Add_Action('admin_notices', array($this, 'Print_Contribution_Form'), 1); Add_Action('wp_dashboard_setup', array($this, 'Register_Dashboard_Widget'), 9); Add_Action('donation_message', array($this, 'Print_Contribution_Message')); Add_Action('dh_contribution_message', array($this, 'Print_Contribution_Message')); } $this->Check_Remote_Activation(); }
function __construct() { // Read base $this->base_url = get_bloginfo('wpurl') . '/' . Str_Replace("\\", '/', SubStr(RealPath(DirName(__FILE__)), Strlen(ABSPATH))); // Get ready to translate $this->Load_TextDomain(); // Set Hooks if (Is_Admin()) { Add_Action('admin_menu', array($this, 'add_options_page')); Add_Action('admin_head', array($this, 'print_admin_header')); } else { Add_Action('wp_head', array($this, 'print_header')); Add_ShortCode('gallery', array($this, 'gallery_shortcode')); } // Add jQuery wp_enqueue_script('jquery'); }
/** * Loops through string to look for matches in the mapping table and replaces the * characters that has a mapping. This will convert the given string to Unicode/UTF-8. * * @param String $string String to convert to Unicode (ÙTF-8) * @return String */ public function convert($string) { $i = 0; // Initialize counter in loop $output = ''; // String to output // Go through string, fetch next character, next two characters and next three characters // to check against mapping table if mapping exist. while ($i <= Strlen($string) - 1) { $remains = Strlen($string) - $i; // Characters that remains in string $key = array(); // Initialize array // Get next, next two and next three characters (if number of remaing // characters allow it) if ($remains >= 3) { $key[3] = $this->get_key_map($string, $i, 3); } if ($remains >= 2) { $key[2] = $this->get_key_map($string, $i, 2); } if ($remains >= 1) { $key[1] = $this->get_key_map($string, $i, 1); } // Check if next three characters exist in mapping, and replace them if they do if (count($key) == 3 && Array_key_exists($key[3], $this->_mapping[3])) { $output .= Chr(Hexdec($this->_mapping[3][$key[3]])); $i += 3; // We mapped three bytes into one char, jump three forward for next loop } elseif (count($key) >= 2 && Array_key_exists($key[2], $this->_mapping[2])) { $output .= Chr(Hexdec($this->_mapping[2][$key[2]])); $i += 2; } elseif (count($key) >= 1 && Array_key_exists($key[1], $this->_mapping[1])) { $output .= Chr(Hexdec($this->_mapping[1][$key[1]])); $i++; } else { $output .= Chr(Hexdec($key[1])); $i++; } } return Utf8_encode($output); // Return the string with replacements }
function rupiah($uang) { $uangasli = $uang; $rupiah = ""; if ($uang < 0) { $uang = -$uang; $min = "-"; $sred = "<span class='red'>"; $sred2 = "</span>"; } $panjang = Strlen($uang); while ($panjang > 3) { $rupiah = "." . substr($uang, -3) . $rupiah; $lebar = strlen($uang); $lebar = $lebar - 3; $uang = substr($uang, 0, $lebar); $panjang = strlen($uang); } $rupiah = $uang . $rupiah . ",-"; return $sred . $min . $rupiah . $sred2; }
/* end of ($Its_A_Kitset_Assembly_Or_Dummy == False) */ echo '</TD><TD valign="top">'; /* Stock Maintenance Options */ echo '<A HREF="' . $rootpath . '/Stocks.php?">' . _('Add Inventory Items') . '</A><BR>'; echo '<A HREF="' . $rootpath . '/Stocks.php?' . SID . '&StockID=' . $StockID . '">' . _('Modify Item Details') . '</A><BR>'; if ($Its_A_Kitset_Assembly_Or_Dummy == False) { echo '<A HREF="' . $rootpath . '/StockReorderLevel.php?' . SID . '&StockID=' . $StockID . '">' . _('Maintain Reorder Levels') . '</A><BR>'; echo '<A HREF="' . $rootpath . '/StockCostUpdate.php?' . SID . '&StockID=' . $StockID . '">' . _('Maintain Standard Cost') . '</A><BR>'; echo '<A HREF="' . $rootpath . '/PurchData.php?' . SID . '&StockID=' . $StockID . '">' . _('Maintain Purchasing Data') . '</A><BR>'; } if ($Its_A_Labour_Item == True) { echo '<A HREF="' . $rootpath . '/StockCostUpdate.php?' . SID . '&StockID=' . $StockID . '">' . _('Maintain Standard Cost') . '</A><BR>'; } if (!$Its_A_Kitset) { echo '<A HREF="' . $rootpath . '/Prices.php?' . SID . '&Item=' . $StockID . '">' . _('Maintain Pricing') . '</A><BR>'; if (isset($_SESSION['CustomerID']) and $_SESSION['CustomerID'] != "" and Strlen($_SESSION['CustomerID']) > 0) { echo '<A HREF="' . $rootpath . '/Prices_Customer.php?' . SID . '&Item=' . $StockID . '">' . _('Special Prices for customer') . ' - ' . $_SESSION['CustomerID'] . '</A><BR>'; } } echo '</TD></TR></TABLE>'; } else { // options (links) to pages. This requires stock id also to be passed. echo '<CENTER><TABLE WIDTH=90% COLSPAN=2 BORDER=2 CELLPADDING=4>'; echo '<TR> <TH WIDTH=33%>' . _('Item Inquiries') . '</TH> <TH WIDTH=33%>' . _('Item Transactions') . '</TH> <TH WIDTH=33%>' . _('Item Maintenance') . '</TH> </TR>'; echo '<TR><TD>'; /*Stock Inquiry Options */ echo '</TD><TD>';
<?php $kata = "ABDULLOH"; for ($i = 0; $i <= Strlen($kata) - 1; $i++) { echo $kata[$i]; }
<?php /* Fancy Gallery Template: Thumbnails / Image Title with Share buttons Description: This template displays the thumbnail images and the image title with share buttons. Version: 1.0.1 Author: Dennis Hoppe Author URI: http://DennisHoppe.de */ // Read base url $base_url = SPrintF('%s/%s', Get_Bloginfo('wpurl'), SubStr(RealPath(DirName(__FILE__)), Strlen(ABSPATH))); $base_url = Str_Replace("\\", '/', $base_url); // Windows Workaround ?> <div class="gallery fancy-gallery <?php echo BaseName(__FILE__, '.php'); ?> " id="gallery_<?php echo $this->gallery->id; ?> "><?php foreach ($this->gallery->images as $image) { // Build <img> Tags $img_code = '<img'; foreach ($image->attributes as $attribute => $value) { $img_code .= SPrintF(' %s="%s"', $attribute, HTMLSpecialChars(Strip_Tags($value))); } $img_code .= '>'; // Build FB share button $fb_code = SPrintF('<a href="%1$s" title="%2$s" class="%3$s" target="_blank">%4$s</a>', SPrintF('https://www.facebook.com/sharer/sharer.php?u=%s', $image->href), HTMLSpecialChars($image->title), $this->gallery->attributes->link_class, SPrintF('<img src="%s/facebook-button.png" alt="Share it" height="20">', $base_url)); // Build Pintarest share button
} $row =& $lAdmin->AddRow($arComment["ID"], $arComment, $path, GetMessage("BLB_VIEW_ALT")); $row->AddField("ID", '<a href="' . $path . '" title="' . GetMessage("BLB_VIEW_ALT") . '">' . $arComment["ID"] . '</a>'); $row->AddField("DATE_CREATE", $arComment["DATE_CREATE"]); $row->AddField("POST_TEXT", "<a href=\"" . $path . "\" title=\"" . htmlspecialcharsEx($arComment["POST_TEXT"]) . "\">" . htmlspecialcharsEx(TruncateText($arComment["POST_TEXT"], 150)) . "</a>"); $row->AddField("POST_TITLE", "<span title=\"" . htmlspecialcharsEx($arComment["POST_TITLE"]) . "\">" . htmlspecialcharsEx(TruncateText($arComment["POST_TITLE"], 50)) . "</span>"); $row->AddField("PUBLISH_STATUS", $arComment["PUBLISH_STATUS"] == "P" ? GetMessage("BLB_YES") : GetMessage("BLB_NO")); if (IntVal($arComment["AUTHOR_ID"]) > 0) { $row->AddField("AUTHOR_ID", "[<a href=\"/bitrix/admin/user_edit.php?ID=" . $arComment["AUTHOR_ID"] . "&lang=" . LANG . "\">" . $arComment["AUTHOR_ID"] . "</a>] " . htmlspecialcharsEx("(" . $arComment["USER_LOGIN"] . ") " . $arComment["USER_NAME"] . " " . $arComment["USER_LAST_NAME"])); } elseif (strlen($arComment["AUTHOR_NAME"]) > 0) { $row->AddField("AUTHOR_ID", htmlspecialcharsEx($arComment["AUTHOR_NAME"] . " (" . $arComment["AUTHOR_EMAIL"] . ")")); } if (IntVal($arComment["BLOG_ID"]) > 0) { $row->AddField("BLOG_ID", "[<a href=\"/bitrix/admin/blog_blog_edit.php?ID=" . $arComment["BLOG_ID"] . "&lang=" . LANG . "\">" . $arComment["BLOG_ID"] . "</a>] " . htmlspecialcharsEx($arComment["BLOG_NAME"] . "")); } if (Strlen($arComment["AUTHOR_IP"]) > 0) { $ip = GetWhoisLink($arComment["AUTHOR_IP"]) . (strlen($arComment["AUTHOR_IP1"]) > 0 ? " / " . GetWhoisLink($arComment["AUTHOR_IP1"]) : ""); if (CModule::IncludeModule("statistic")) { $arr = explode(".", $arComment["AUTHOR_IP"]); if (count($arr) == 4) { $ip .= '<br><a href="stoplist_edit.php?lang=' . LANGUAGE_ID . '&net1=' . intval($arr[0]) . '&net2=' . intval($arr[1]) . '&net3=' . intval($arr[2]) . '&net4=' . intval($arr[3]) . '">[' . GetMessage("BLB_STOP_LIST") . ']<a>'; } } $row->AddField("AUTHOR_IP", $ip); } $USER_FIELD_MANAGER->AddUserFields("BLOG_COMMENT", $arComment, $row); $arActions = array(); if ($arComment["PUBLISH_STATUS"] == "P") { $arActions[] = array("ICON" => "hide", "TEXT" => GetMessage("BLB_HIDE_ALT"), "ACTION" => $lAdmin->ActionDoGroup($arComment["ID"], "hide")); } else { $arActions[] = array("ICON" => "show", "TEXT" => GetMessage("BLB_SHOW_ALT"), "ACTION" => $lAdmin->ActionDoGroup($arComment["ID"], "show"));
public function Get_Template_Files() { $arr_template = Array_Unique(Array_Merge((array) Glob(DirName(__FILE__) . '/templates/*.php'), (array) Glob(DirName(__FILE__) . '/templates/*/*.php'), (array) Glob(Get_StyleSheet_Directory() . '/*.php'), (array) Glob(Get_StyleSheet_Directory() . '/*/*.php'), Is_Child_Theme() ? (array) Glob(Get_Template_Directory() . '/*.php') : array(), Is_Child_Theme() ? (array) Glob(Get_Template_Directory() . '/*/*.php') : array(), (array) Glob($this->template_dir . '/*.php'), (array) Glob($this->template_dir . '/*/*.php'))); # Filter to add template files - you can use this filter to add template files to the user interface $arr_template = Apply_Filters('fancy_gallery_template_files', $arr_template); # Check if there template files if (empty($arr_template)) { return False; } $arr_result = array(); $arr_sort = array(); foreach ($arr_template as $index => $template_file) { # Read meta data from the template if ($arr_properties = $this->Get_Template_Properties($template_file)) { $stylesheet_file = SubStr($template_file, 0, -4) . '.css'; $stylesheet_url = Is_File($stylesheet_file); if ($stylesheet_url) { if (StrPos($stylesheet_file, DirName(__FILE__)) === 0) { # the template is inside the plugin folder $stylesheet_url = $this->base_url . SubStr($stylesheet_file, StrLen(DirName(__FILE__))); } elseif (StrPos($stylesheet_file, ABSPATH) === 0) { # the template is inside the wordpress folder $stylesheet_url = Get_Bloginfo('wpurl') . '/' . SubStr($stylesheet_file, Strlen(ABSPATH)); } else { $stylesheet_url = $stylesheet_file = False; } } $arr_result[$arr_properties['name']] = Array_Merge($arr_properties, array('file' => $template_file, 'stylesheet_file' => Is_File($stylesheet_file) ? $stylesheet_file : False, 'stylesheet_uri' => $stylesheet_url)); $arr_sort[$arr_properties['name']] = StrToLower($arr_properties['name']); } else { continue; } } Array_MultiSort($arr_sort, SORT_STRING, SORT_ASC, $arr_result); return $arr_result; }
/** * Creates multie record entires for a field * with child continuation or concatentaion records * * @param string $field to break into multiple records * @param string $maintag the parent tag * @param string $mainLvl the parent level * * @return string the records * * @access public * @since Method available since Release 0.0.1 */ protected function to_con_tag($field, $maintag, $main_lvl) { $ged_rec = ''; // TODO don't break on a space $copy = explode("\n", $field); if ($maintag != null) { $ged_rec .= $main_lvl . ' ' . $maintag . ' '; } else { } $ged_rec .= substr($copy[0], 0, 90); $lvlplus = $main_lvl + 1; //check for CONC of first line if (Strlen($copy[0]) > 90) { $rem = 90; $len = Strlen($copy[0]); while ($rem < $len) { $ged_rec .= "\n" . $lvlplus . ' ' . Rp_Tags::CONC . ' ' . substr($copy[0], $rem, 90); $rem += 90; } } //check for CONC of each line //CONC before CONT since CONT contains the newline $cnt = count($copy); for ($i = 1; $i < $cnt; $i++) { $ged_rec .= "\n" . $lvlplus . ' ' . Rp_Tags::CONT . ' ' . substr($copy[$i], 0, 90); if (Strlen($copy[$i]) > 90) { $rem = 90; $len = Strlen($copy[$i]); while ($rem < $len) { $ged_rec .= "\n" . $lvlplus . ' ' . Rp_Tags::CONC . ' ' . substr($copy[$i], $rem, 90); $rem += 90; } } } return $ged_rec; }
function Enqueue_Frontend_Scripts() { WP_Enqueue_Script('jquery.mousewheel', $this->base_url . '/js/jquery.mousewheel.js', array('jquery'), '3.0.6', $this->get_option('script_position') != 'header'); WP_Enqueue_Script('fancybox', $this->base_url . '/fancybox/jquery.fancybox.js', array('jquery'), '2.1.4', $this->get_option('script_position') != 'header'); WP_Enqueue_Style('fancybox', $this->base_url . '/fancybox/fancybox.css', Null, '2.1.4'); WP_Enqueue_Script('fancybox-buttons', $this->base_url . '/fancybox/jquery.fancybox-buttons.js', array('jquery', 'fancybox'), '1.0.5', $this->get_option('script_position') != 'header'); WP_Enqueue_Script('fancybox-media', $this->base_url . '/fancybox/jquery.fancybox-media.js', array('jquery', 'fancybox'), '1.0.5', $this->get_option('script_position') != 'header'); WP_Enqueue_Script('fancybox-thumbs', $this->base_url . '/fancybox/jquery.fancybox-thumbs.js', array('jquery', 'fancybox'), '1.0.7', $this->get_option('script_position') != 'header'); WP_Enqueue_Script('fancy-gallery', $this->base_url . '/js/fancy-gallery.js', array('jquery', 'fancybox'), $this->version, $this->get_option('script_position') != 'header'); // Add image descriptions as title if required if ($this->get_option('use_as_image_title') == 'description') { // Collect image titles $arr_image_titles = array(); foreach (Get_Posts(array('post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1, 'order' => 'ASC', 'orderby' => 'ID')) as $i => $image) { $arr_image_titles[$image->ID] = $this->get_image_title($image); } // Add image title to the images WP_Localize_Script('fancy-gallery', 'IMAGETITLES', $arr_image_titles); } // Add the plugin options to the JS front end $arr_options = $this->Get_Option(); unset($arr_options['disable_update_notification']); unset($arr_options['update_username']); unset($arr_options['update_password']); WP_Localize_Script('fancy-gallery', 'FANCYGALLERY', $arr_options); // Enqueue Template Stylesheets foreach ($this->Get_Template_Files() as $template_name => $template_properties) { $style_sheet_name = BaseName($template_properties['file'], '.php') . '.css'; $style_sheet_file = DirName($template_properties['file']) . '/' . $style_sheet_name; if (!Is_File($style_sheet_file)) { continue; } $template_dir = DirName($style_sheet_file); $style_sheet_id = 'fancy-gallery-template-' . Sanitize_Title($template_name); $template_base_url = Get_Bloginfo('wpurl') . '/' . SubStr($template_dir, Strlen(ABSPATH)); $template_base_url = Str_Replace("\\", '/', $template_base_url); // Windows workaround WP_Enqueue_Style($style_sheet_id, $template_base_url . '/' . $style_sheet_name); } }
public static function GetAvaibleEntity($entityType, $feature, $role, $operation, $active, $visible, $siteID) { global $DB; if (Strlen($entityType) <= 0 || Strlen($role) <= 0 || Strlen($operation) <= 0) { return false; } if (Strlen($entityType) <= 0) { $entityType = "G"; } if (Strlen($active) <= 0) { $active = "Y"; } if (Strlen($visible) <= 0) { $visible = "Y"; } if (Strlen($siteID) <= 0) { $siteID = SITE_ID; } $strSql = "select b.ID as ID,\n\t\t\t\t\tb.ENTITY_TYPE as ENTITY_TYPE,\n\t\t\t\t\tb.ENTITY_ID as ENTITY_ID,\n\t\t\t\t\tb.FEATURE as FEATURE,\n\t\t\t\t\tb.ACTIVE as FEATURE_ACTIVE,\n\t\t\t\t\tp.OPERATION_ID as OPERATION_ID,\n\t\t\t\t\tp.ROLE as ROLE "; if ($entityType == "G") { $strSql .= ", g.SITE_ID as GROUP_SITE_ID,\n\t\t\t\t\tg.NAME as GROUP_NAME,\n\t\t\t\t\tg.VISIBLE as GROUP_VISIBLE,\n\t\t\t\t\tg.OWNER_ID as GROUP_OWNER_ID "; } $strSql .= " from b_sonet_features b " . "LEFT JOIN b_sonet_features2perms p ON (b.ID = p.FEATURE_ID AND " . "p.ROLE = '" . $DB->ForSQL($role) . "' AND p.OPERATION_ID = '" . $DB->ForSQL($operation) . "') "; if ($entityType == "G") { $strSql .= "INNER JOIN b_sonet_group g ON (g.ID = b.ENTITY_ID) "; } $strSql .= "WHERE " . "b.FEATURE='" . $DB->ForSQL($feature) . "' AND " . "b.ACTIVE = '" . $DB->ForSQL($active) . "' AND " . "b.ENTITY_TYPE = '" . $DB->ForSQL($entityType) . "' "; if ($entityType == "G") { $strSql .= " AND g.ACTIVE = 'Y' AND " . "g.VISIBLE= 'Y' AND " . "g.SITE_ID= '" . $DB->ForSQL($siteID) . "'"; } $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); return $dbRes; }
/** * \brief Execute a sql script * \param $script script name */ function execute_script($script) { if (!DEBUG) { ob_start(); } $hf = fopen($script, 'r'); if ($hf == false) { throw new Exception('Ne peut ouvrir ' . $script); } $sql = ""; $flag_function = false; while (!feof($hf)) { $buffer = fgets($hf); $buffer = str_replace("\$", "\$", $buffer); print $buffer . "<br>"; // comment are not execute if (substr($buffer, 0, 2) == "--") { //echo "comment $buffer"; continue; } // Blank Lines Are Skipped if (Strlen($buffer) == 0) { //echo "Blank $buffer"; continue; } if (strpos(strtolower($buffer), "create function") === 0) { echo "found a function"; $flag_function = true; $sql = $buffer; continue; } if (strpos(strtolower($buffer), "create or replace function") === 0) { echo "found a function"; $flag_function = true; $sql = $buffer; continue; } // No semi colon -> multiline command if ($flag_function == false && strpos($buffer, ';') == false) { $sql .= $buffer; continue; } if ($flag_function) { if (strpos(strtolower($buffer), "language plpgsql") === false && strpos(strtolower($buffer), "language 'plpgsql'") === false) { $sql .= $buffer; continue; } } else { // cut the semi colon $buffer = str_replace(';', '', $buffer); } $sql .= $buffer; if ($this->exec_sql($sql) == false) { $this->rollback(); if (!DEBUG) { ob_end_clean(); } print "ERROR : {$sql}"; throw new Exception("ERROR : {$sql}"); } $sql = ""; $flag_function = false; print "<hr>"; } // while (feof) fclose($hf); if (!DEBUG) { ob_end_clean(); } }
if ($isValid && !(checkdnsrr($domain, "MX") || checkdnsrr($domain, "A"))) { // domain not found in DNS $isValid = false; } } return $isValid; } if (!validemail($_POST['email'])) { // Check email address echo "At least try to put in a real email address... not {$_POST['email']}"; } else { if (isset($_POST['username']) ? Strlen($_POST['username']) < 2 : false) { // Check username if posted echo "At least try to put in a name for your account..."; } else { if (isset($_POST['username']) ? Strlen($_POST['username']) > 25 : false) { // Check small enough echo "At least try to put in a reasonable name for your account..."; } else { if ($_POST['f'] == 'sign') { $username = $_POST['username']; $email = $_POST['email']; // Get database connection ob_start(); require_once "../php/dbconnect.php"; require_once "../php/utl_mail.php"; ob_end_clean(); // Check username is not assigned $result = $mysqli->query("Select username From sp_users Where username = '******'"); $result2 = $mysqli->query("Select username From sp_users Where email1='{$email}' or email2='{$email}'"); if ($result->fetch_row()) {
/** * create patches * * @param unknown_type $diffs * @return unknown_type */ public function patch_make($diffs, $text) { $patch_margin = $this->Patch_Margin; $explicitContributions = array(); $offset = 0; while (strpos($text, WUM_TAG_OPEN) !== false) { $ec['start'] = $offset + strpos($text, WUM_TAG_OPEN); $text = substr($text, strpos($text, WUM_TAG_OPEN) + strlen(WUM_TAG_OPEN)); if (strpos($text, WUM_TAG_CLOSE) !== false) { $ec['end'] = $offset = strpos($text, WUM_TAG_CLOSE) + strlen(WUM_TAG_CLOSE) + $ec['start'] + strlen(WUM_TAG_OPEN); $text = substr($text, strpos($text, WUM_TAG_CLOSE) + strlen(WUM_TAG_CLOSE)); $explicitContributions[] = $ec; } else { break; } } //create initial patches and make sure that each patch starts and ends with an equality diff where possible //equality diffs are shortened to the patch_margin where possible //we do not yet deal with too short equality diffs $patches = array(); $patch = new patch_obj(); $firstDiffEqual = true; $start = 0; $startNext = 0; $length = 0; for ($i = 0; $i < count($diffs); $i++) { if ($diffs[$i][0] == DIFF_EQUAL) { if ($firstDiffEqual) { $patch->diffs[] = $diffs[$i]; $firstDiffEqual = false; $startNext += strlen($diffs[$i][1]); $length += strlen($diffs[$i][1]); } else { $patch->diffs[] = $diffs[$i]; $patch->start1 = $start; $patch->start2 = $start; $start = $startNext; $length += strlen($diffs[$i][1]); $patch->length2 = $length; $length = strlen($diffs[$i][1]); $startNext += strlen($diffs[$i][1]); $patches[] = $patch; $patch = new patch_obj(); $patch->diffs[] = $diffs[$i]; } } else { if ($diffs[$i][0] == DIFF_INSERT) { $patch->diffs[] = $diffs[$i]; $startNext += strlen($diffs[$i][1]); $length += strlen($diffs[$i][1]); $firstDiffEqual = false; } else { if ($diffs[$i][0] == DIFF_DELETE) { $patch->diffs[] = $diffs[$i]; //because patches are applied one after another //$startNext -= strlen($diffs[$i][1]); $firstDiffEqual = false; } } } } //deal with the last patch, which might not end with an equality diff if (count($patch->diffs) > 1) { $patch->start1 = $start; $patch->start2 = $start; $patch->length2 = $length; $patches[] = $patch; } else { if (count($patch->diffs) == 1) { if ($patch->diffs[0][0] == DIFF_INSERT || $patch->diffs[0][0] == DIFF_DELETE) { $patch->start1 = $start; $patch->start2 = $start; $patch->length2 = $length; $patches[] = $patch; } } } foreach ($explicitContributions as $ec) { $combinePatches = array(); $processedPatchesPrefix = array(); $processedPatchesSuffix = array(); for ($i = 0; $i < count($patches); $i++) { if ($patches[$i]->start2 <= $ec['start'] && $patches[$i]->start2 + $patches[$i]->length2 > $ec['start']) { $combinePatches[] = $patches[$i]; } else { if ($patches[$i]->start2 >= $ec['start'] && $patches[$i]->start2 < $ec['end']) { $combinePatches[] = $patches[$i]; } else { if ($patches[$i]->start2 < $ec['start']) { $processedPatchesPrefix[] = $patches[$i]; } else { if ($patches[$i]->start2 > $ec['start']) { $processedPatchesSuffix[] = $patches[$i]; } } } } } $patch = new patch_obj(); $insert = $delete = ''; for ($k = 0; $k < count($combinePatches); $k++) { for ($j = 0; $j < count($combinePatches[$k]->diffs); $j++) { if ($combinePatches[$k]->diffs[$j][0] == DIFF_INSERT) { $patch->length2 += strlen($combinePatches[$k]->diffs[$j][1]); $insert .= $combinePatches[$k]->diffs[$j][1]; } else { if ($combinePatches[$k]->diffs[$j][0] == DIFF_DELETE) { $delete .= $combinePatches[$k]->diffs[$j][1]; } else { if ($combinePatches[$k]->diffs[$j][0] == DIFF_EQUAL && $j > 0) { $delete .= $combinePatches[$k]->diffs[$j][1]; $insert .= $combinePatches[$k]->diffs[$j][1]; $patch->length2 += strlen($combinePatches[$k]->diffs[$j][1]); } } } } } $patch->start1 = $combinePatches[0]->start1; $patch->start2 = $combinePatches[0]->start2; $lastEqual = $combinePatches[count($combinePatches) - 1]->diffs[count($combinePatches[count($combinePatches) - 1]->diffs) - 1][1]; $patch->length2 -= strlen($lastEqual); $patch->length2 += strlen($combinePatches[0]->diffs[0][1]); $insert = substr($insert, 0, strlen($insert) - strlen($lastEqual)); $delete = substr($delete, 0, strlen($delete) - strlen($lastEqual)); $patch->diffs[] = array(0 => DIFF_EQUAL, 1 => $combinePatches[0]->diffs[0][1]); $patch->diffs[] = array(0 => DIFF_DELETE, 1 => $delete); $patch->diffs[] = array(0 => DIFF_INSERT, 1 => $insert); $patch->diffs[] = array(0 => DIFF_EQUAL, 1 => $lastEqual); $patches = $processedPatchesPrefix; $patches[] = $patch; for ($k = 0; $k < count($processedPatchesSuffix); $k++) { $patches[] = $processedPatchesSuffix[$k]; } } $processedPatches = array(); for ($i = 0; $i < count($patches); $i++) { $patch = $this->patch_deep_copy($patches[$i]); if ($patch->diffs[0][0] == DIFF_EQUAL && strlen($patch->diffs[0][1]) < $patch_margin) { $k = $i; $text = $patch->diffs[0][1]; while ($k != 0) { $k -= 1; $previousPatch = $patches[$k]; for ($l = count($previousPatch->diffs) - 2; $l >= 0; $l--) { if ($previousPatch->diffs[$l][0] == DIFF_EQUAL || $previousPatch->diffs[$l][0] == DIFF_INSERT) { $text = $previousPatch->diffs[$l][1] . $text; } } if (strlen($text) > $patch_margin) { break; } } if (Strlen($text) > $patch_margin) { $patch->diffs[0][1] = substr($text, strlen($text) - $patch_margin); } else { $patch->diffs[0][1] = $text; } } else { if ($patch->diffs[0][0] == DIFF_EQUAL) { $patch->diffs[0][1] = substr($patch->diffs[0][1], strlen($patch->diffs[0][1]) - $patch_margin); } } if ($patch->diffs[count($patch->diffs) - 1][0] == DIFF_EQUAL && strlen($patch->diffs[count($patch->diffs) - 1][1]) < $patch_margin) { $k = $i; $text = $patch->diffs[count($patch->diffs) - 1][1]; while ($k != count($patches) - 1) { $k += 1; $nextPatch = $patches[$k]; for ($l = 1; $l < count($nextPatch->diffs); $l++) { if ($nextPatch->diffs[$l][0] == DIFF_EQUAL || $nextPatch->diffs[$l][0] == DIFF_DELETE) { $text .= $nextPatch->diffs[$l][1]; } } if (strlen($text) > $patch_margin) { break; } } if (Strlen($text) > $patch_margin) { $patch->diffs[count($patch->diffs) - 1][1] = substr($text, 0, $patch_margin); } else { $patch->diffs[count($patch->diffs) - 1][1] = $text; } } else { if ($patch->diffs[count($patch->diffs) - 1][0] == DIFF_EQUAL) { $patch->diffs[count($patch->diffs) - 1][1] = substr($patch->diffs[count($patch->diffs) - 1][1], 0, $patch_margin); } } if ($patch->diffs[0][0] == DIFF_EQUAL) { $patch->start1 += strlen($patches[$i]->diffs[0][1]) - strlen($patch->diffs[0][1]); $patch->start2 += strlen($patches[$i]->diffs[0][1]) - strlen($patch->diffs[0][1]); } $processedPatches[] = $patch; } $patches = $processedPatches; for ($i = 0; $i < count($patches); $i++) { $length1 = 0; $length2 = 0; for ($k = 0; $k < count($patches[$i]->diffs); $k++) { if ($patches[$i]->diffs[$k][0] == DIFF_EQUAL || $patches[$i]->diffs[$k][0] == DIFF_DELETE) { $length1 += strlen($patches[$i]->diffs[$k][1]); } if ($patches[$i]->diffs[$k][0] == DIFF_EQUAL || $patches[$i]->diffs[$k][0] == DIFF_INSERT) { $length2 += strlen($patches[$i]->diffs[$k][1]); } } $patches[$i]->length1 = $length1; $patches[$i]->length2 = $length2; } return $patches; }