Advertisement
nicolaslagios

Collezione FUNCTIONS

Feb 17th, 2020 (edited)
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.15 KB | None | 0 0
  1. --------------------------------Αρχείο functions.php του theme (ιστοσελίδα)-----------------------------------------------------
  2.  
  3.  
  4. /* Custom συνάρτηση, εξαφάνιση τιμής στους επισκέπτες */
  5. add_action( 'wp_head', 'personal_message_when_logged_in' );
  6. function personal_message_when_logged_in() {
  7.     if ( !is_user_logged_in() ) :
  8.         echo "
  9.         <style>
  10.         .ht-product-price,.elementor-menu-cart__subtotal,.product-price,.product-subtotal,.cart-subtotal,.order-total,.price,.woolentor-cart,.cart{
  11.             display:none!important;
  12.         }
  13.         </style>
  14.         ";
  15.     endif;
  16. }
  17.  
  18. /* Custom συνάρτηση, αλλαγής email notification */
  19. add_filter( 'wp_new_user_notification_email' , 'edit_user_notification_email', 10, 3 );
  20.  
  21. function edit_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {
  22.  
  23.     $message = sprintf(__( "Καλώς ήρθες %s! Τα στοιχεία σου για να συνδεθείς στο κατάστημα είναι:" ), $user->first_name ) . "\r\n";
  24.     $message .= sprintf(__( 'Διεύθυνση: https://collezione-eshop.com' ) ). "\r\n";
  25.     $message .= sprintf(__( 'Όνομα Χρήστη: %s' ), $user->user_login ) . "\r\n";
  26.     $message .= sprintf(__( 'Κωδικός: %s' ), $user->kwdikos_pelath ) . "\r\n\r\n";
  27.     $message .= sprintf(__( 'Εάν έχετε οποιοδήποτε πρόβλημα, παρακαλώ επικοινωνήστε μαζί μας σε info@collezione-eshop.com.'), get_option( 'admin_email' ) ) . "\r\n";
  28.     //$message .= __('Adios!');
  29.  
  30.     $wp_new_user_notification_email['message'] = $message;
  31.  
  32.     return $wp_new_user_notification_email;
  33.  
  34. }
  35. function custom_user_profile_fields($user){
  36.     if(is_object($user))
  37.         $kwdikos_pelath = esc_attr( get_the_author_meta( 'kwdikos_pelath', $user->ID ) );
  38.     else
  39.         $kwdikos_pelath = null;
  40.     ?>
  41.     <h3>Επιπλέον Πληροφορίες</h3>
  42.     <table class="form-table">
  43.         <tr>
  44.             <th><label for="kwdikos_pelath">Κωδικός Πελάτη</label></th>
  45.             <td>
  46.                 <input type="text" class="regular-text" name="kwdikos_pelath" value="<?php echo $kwdikos_pelath; ?>" id="kwdikos_pelath" /><br />
  47.                 <span class="description">κωδικός πελάτη είναι ο κωδικός, μπαίνει οπωσδήποτε</span>
  48.             </td>
  49.         </tr>
  50.     </table>
  51. <?php
  52. }
  53. add_action( 'show_user_profile', 'custom_user_profile_fields' );
  54. add_action( 'edit_user_profile', 'custom_user_profile_fields' );
  55. add_action( "user_new_form", "custom_user_profile_fields" );
  56. function save_custom_user_profile_fields($user_id){
  57.     # again do this only if you can
  58.    if(!current_user_can('manage_options'))
  59.         return false;
  60.  
  61.     # save my custom field
  62.    update_user_meta($user_id, 'kwdikos_pelath', $_POST['kwdikos_pelath']);
  63. }
  64. add_action('user_register', 'save_custom_user_profile_fields');
  65. add_action('profile_update', 'save_custom_user_profile_fields');
  66.  
  67. /* Αλλαγή Logout message */
  68.   // this adds stuff to the head. You can add a stylesheet
  69.   // if you want, or just css like I have.
  70.   add_action("login_head", "cust_login_head");
  71.   function cust_login_head()
  72.   {
  73.         // this just changes the logo
  74.     ?>
  75.       <style>
  76.       body.login #login h1 a {
  77.         background: url('<?=plugins_url('https://collezione-eshop.com/wp-content/uploads/2019/12/logo.png',__FILE__)?>') no-repeat scroll center top transparent;
  78.         height: 64px;
  79.         width: 307px;
  80.         margin-left: 10px;
  81.       }
  82.       </style>
  83.     <?php
  84.   }
  85.   // these change the default links from wordpress to whatever you want
  86.   add_filter('login_headertitle', create_function(false, "return 'https://collezione-eshop.com';"));
  87.   add_filter('login_headerurl', create_function(false, "return 'https://collezione-eshop.com';"));
  88.  
  89.  
  90. --------------------------------REQUEST ΚΛΕΙΔΙ API ΑΠΟ ENTERSOFT-----------------------------------------------------
  91. <?php
  92. $curl = curl_init();
  93.  
  94. curl_setopt_array($curl, array(
  95.   CURLOPT_PORT => "8050",
  96.   CURLOPT_URL => "http://188.164.204.222:8050/api/login",
  97.   CURLOPT_RETURNTRANSFER => true,
  98.   CURLOPT_ENCODING => "",
  99.   CURLOPT_MAXREDIRS => 10,
  100.   CURLOPT_TIMEOUT => 30,
  101.   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  102.   CURLOPT_CUSTOMREQUEST => "POST",
  103.   CURLOPT_POSTFIELDS => "{\n            SubscriptionPassword:  \"passx\",\n            model: {\n                                                                        BranchID: \"1\",\n                                                                        LangID: \"el-GR\",\n                                                                        Password: \"P@ssw0rd\",\n                                                                        UserID: \"webadmin\"\n            }\n  }",
  104.   CURLOPT_HTTPHEADER => array(
  105.     "content-type: application/json"
  106.   ),
  107. ));
  108.  
  109. $response = curl_exec($curl);
  110. $err = curl_error($curl);
  111.  
  112. curl_close($curl);
  113.  
  114. //παλαιος κωδικας δουλευει αλλα βγαζει οθονη
  115. if ($err) {
  116.   echo "cURL Error #:" . $err;
  117. } else {
  118.   $arr = json_decode($response, true);
  119.   $token = $arr['Model']['WebApiToken'];
  120. }
  121.  
  122.  
  123. --------------------------------ΔΕΔΟΜΕΝΑ ΠΡΟΙΟΝΤΩΝ ΑΠΟ ENTERSOFT-----------------------------------------------------
  124. <?php
  125.  
  126. include ('api_key.php');
  127.  
  128. $curl = curl_init();
  129.  
  130. curl_setopt_array($curl, array(
  131.   CURLOPT_PORT => "8050",
  132.   CURLOPT_URL => "http://188.164.204.222:8050/api/rpc/PublicQuery/ESMobileQueries/KHC_WS_Products",
  133.   CURLOPT_RETURNTRANSFER => true,
  134.   CURLOPT_ENCODING => "",
  135.   CURLOPT_MAXREDIRS => 10,
  136.   CURLOPT_TIMEOUT => 30,
  137.   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  138.   CURLOPT_CUSTOMREQUEST => "POST",
  139.   CURLOPT_POSTFIELDS => "",
  140.   CURLOPT_HTTPHEADER => array(
  141.     "authorization: Bearer ${token}"
  142.   ),
  143. ));
  144.  
  145. $apanthsh = curl_exec($curl);
  146. $sfalma = curl_error($curl);
  147.  
  148. curl_close($curl);
  149.  
  150. if ($sfalma) {
  151.   echo "cURL Error #:" . $sfalma;
  152. } else {
  153.   //echo $apanthsh;
  154. }
  155.  
  156. --------------------------------ΛΙΣΤΑ ΦΩΤΟΓΡΑΦΙΩΝ ΓΙΑ ΕΙΣΑΓΩΓΗ ΣΤΟ GOOGLE SPREADSHEET-----------------------------------------------------
  157. <?php
  158. $row = exec('ls',$output,$error);
  159. echo "<table>";
  160. while(list(,$row) = each($output)){
  161. echo "<tr><td>", $row, "</td></tr>";
  162. }
  163. if($error){
  164. echo "Error : $error<BR>";
  165. exit;
  166. }
  167. echo "</table>"
  168. ?>
  169.  
  170.  
  171. --------------------------------JAVASCRIPT ΓΙΑ ΕΙΣΑΓΩΓΗ ΔΕΔΟΜΈΝΩΝ JSON ΑΠΟ ENTERSOFT ΣΕ GOOGLE SPREADSHEET-----------------------------
  172. function readRows() {
  173.   var sheet = SpreadsheetApp.getActiveSheet();
  174.   var rows = sheet.getDataRange();
  175.   var numRows = rows.getNumRows();
  176.   var values = rows.getValues();
  177.  
  178.   for (var i = 0; i <= numRows - 1; i++) {
  179.     var row = values[i];
  180.     Logger.log(row);
  181.   }
  182. };
  183.  
  184. function onOpen() {
  185.   var sheet = SpreadsheetApp.getActiveSpreadsheet();
  186.   var entries = [{
  187.     name : "Read Data",
  188.     functionName : "readRows"
  189.   }];
  190.   sheet.addMenu("Script Center Menu", entries);
  191. };
  192.  
  193. function ImportJSON(url, query, options) {
  194.   return ImportJSONAdvanced(url, query, options, includeXPath_, defaultTransform_);
  195. }
  196.  
  197. function ImportJSONAdvanced(url, query, options, includeFunc, transformFunc) {
  198.   var jsondata = UrlFetchApp.fetch(url);
  199.   var object   = JSON.parse(jsondata.getContentText());
  200.  
  201.   return parseJSONObject_(object, query, options, includeFunc, transformFunc);
  202. }
  203.  
  204. function URLEncode(value) {
  205.   return encodeURIComponent(value.toString());  
  206. }
  207.  
  208. function parseJSONObject_(object, query, options, includeFunc, transformFunc) {
  209.   var headers = new Array();
  210.   var data    = new Array();
  211.  
  212.   if (query && !Array.isArray(query) && query.toString().indexOf(",") != -1) {
  213.     query = query.toString().split(",");
  214.   }
  215.  
  216.   if (options) {
  217.     options = options.toString().split(",");
  218.   }
  219.    
  220.   parseData_(headers, data, "", 1, object, query, options, includeFunc);
  221.   parseHeaders_(headers, data);
  222.   transformData_(data, options, transformFunc);
  223.  
  224.   return hasOption_(options, "noHeaders") ? (data.length > 1 ? data.slice(1) : new Array()) : data;
  225. }
  226.  
  227.  
  228. function parseData_(headers, data, path, rowIndex, value, query, options, includeFunc) {
  229.   var dataInserted = false;
  230.  
  231.   if (isObject_(value)) {
  232.     for (key in value) {
  233.       if (parseData_(headers, data, path + "/" + key, rowIndex, value[key], query, options, includeFunc)) {
  234.         dataInserted = true;
  235.       }
  236.     }
  237.   } else if (Array.isArray(value) && isObjectArray_(value)) {
  238.     for (var i = 0; i < value.length; i++) {
  239.       if (parseData_(headers, data, path, rowIndex, value[i], query, options, includeFunc)) {
  240.         dataInserted = true;
  241.         rowIndex++;
  242.       }
  243.     }
  244.   } else if (!includeFunc || includeFunc(query, path, options)) {
  245.     // Handle arrays containing only scalar values
  246.     if (Array.isArray(value)) {
  247.       value = value.join();
  248.     }
  249.    
  250.     // Insert new row if one doesn't already exist
  251.     if (!data[rowIndex]) {
  252.       data[rowIndex] = new Array();
  253.     }
  254.    
  255.     // Add a new header if one doesn't exist
  256.     if (!headers[path] && headers[path] != 0) {
  257.       headers[path] = Object.keys(headers).length;
  258.     }
  259.    
  260.     // Insert the data
  261.     data[rowIndex][headers[path]] = value;
  262.     dataInserted = true;
  263.   }
  264.  
  265.   return dataInserted;
  266. }
  267.  
  268. function parseHeaders_(headers, data) {
  269.   data[0] = new Array();
  270.  
  271.   for (key in headers) {
  272.     data[0][headers[key]] = key;
  273.   }
  274. }
  275.  
  276. function transformData_(data, options, transformFunc) {
  277.   for (var i = 0; i < data.length; i++) {
  278.     for (var j = 0; j < data[i].length; j++) {
  279.       transformFunc(data, i, j, options);
  280.     }
  281.   }
  282. }
  283.  
  284. function isObject_(test) {
  285.   return Object.prototype.toString.call(test) === '[object Object]';
  286. }
  287.  
  288. function isObjectArray_(test) {
  289.   for (var i = 0; i < test.length; i++) {
  290.     if (isObject_(test[i])) {
  291.       return true;
  292.     }
  293.   }  
  294.  
  295.   return false;
  296. }
  297.  
  298. function includeXPath_(query, path, options) {
  299.   if (!query) {
  300.     return true;
  301.   } else if (Array.isArray(query)) {
  302.     for (var i = 0; i < query.length; i++) {
  303.       if (applyXPathRule_(query[i], path, options)) {
  304.         return true;
  305.       }
  306.     }  
  307.   } else {
  308.     return applyXPathRule_(query, path, options);
  309.   }
  310.  
  311.   return false;
  312. };
  313.  
  314. function applyXPathRule_(rule, path, options) {
  315.   return path.indexOf(rule) == 0;
  316. }
  317.  
  318. function defaultTransform_(data, row, column, options) {
  319.   if (!data[row][column]) {
  320.     if (row < 2 || hasOption_(options, "noInherit")) {
  321.       data[row][column] = "";
  322.     } else {
  323.       data[row][column] = data[row-1][column];
  324.     }
  325.   }
  326.  
  327.   if (!hasOption_(options, "rawHeaders") && row == 0) {
  328.     if (column == 0 && data[row].length > 1) {
  329.       removeCommonPrefixes_(data, row);  
  330.     }
  331.    
  332.     data[row][column] = toTitleCase_(data[row][column].toString().replace(/[\/\_]/g, " "));
  333.   }
  334.  
  335.   if (!hasOption_(options, "noTruncate") && data[row][column]) {
  336.     data[row][column] = data[row][column].toString().substr(0, 256);
  337.   }
  338.  
  339.   if (hasOption_(options, "debugLocation")) {
  340.     data[row][column] = "[" + row + "," + column + "]" + data[row][column];
  341.   }
  342. }
  343.  
  344. function removeCommonPrefixes_(data, row) {
  345.   var matchIndex = data[row][0].length;
  346.  
  347.   for (var i = 1; i < data[row].length; i++) {
  348.     matchIndex = findEqualityEndpoint_(data[row][i-1], data[row][i], matchIndex);
  349.  
  350.     if (matchIndex == 0) {
  351.       return;
  352.     }
  353.   }
  354.  
  355.   for (var i = 0; i < data[row].length; i++) {
  356.     data[row][i] = data[row][i].substring(matchIndex, data[row][i].length);
  357.   }
  358. }
  359.  
  360. function findEqualityEndpoint_(string1, string2, stopAt) {
  361.   if (!string1 || !string2) {
  362.     return -1;
  363.   }
  364.  
  365.   var maxEndpoint = Math.min(stopAt, string1.length, string2.length);
  366.  
  367.   for (var i = 0; i < maxEndpoint; i++) {
  368.     if (string1.charAt(i) != string2.charAt(i)) {
  369.       return i;
  370.     }
  371.   }
  372.  
  373.   return maxEndpoint;
  374. }
  375.  
  376.  
  377. function toTitleCase_(text) {
  378.   if (text == null) {
  379.     return null;
  380.   }
  381.  
  382.   return text.replace(/\w\S*/g, function(word) { return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase(); });
  383. }
  384.  
  385. function hasOption_(options, option) {
  386.   return options && options.indexOf(option) >= 0;
  387. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement