⏪ אופציית שליטה על הדילוג בין הקבצים בשלוחת השמעת קבצים.
-
תגובה: הצעת ייעול: שליטה על כמות הדילוג במקש 8 במהלך השמעה

(לניווט מהיר בשלוחות עמוסות!)בהמשך למה שביקשו פה אני משתף קוד php להגדרה מראש של שמות הקבצים אליהם יועברו, (מכיוון שעדיין אין לי גמח שרתים חינמיים, אז אני רק משתף את הקוד ואולי מתי שהוא אני גם אעלה שיתוף של קישור לשימוש בו.)
להלן הקוד:
<?php header('Content-Type: text/plain; charset=utf-8'); $apiCallId = $_REQUEST['ApiCallId'] ?? ''; $apiExtension = $_REQUEST['ApiExtension'] ?? ''; $hangup = $_REQUEST['hangup'] ?? ''; $what = $_REQUEST['what'] ?? ''; if ($apiCallId === '') { exit('Missing ApiCallId'); } if ($apiExtension === '') { exit('Missing ApiExtension'); } if ($hangup === 'yes') { foreach (glob(__DIR__ . '/counter_*.txt') as $counterFile) { $counters = json_decode(file_get_contents($counterFile), true); if (!is_array($counters)) { continue; } unset($counters[$apiCallId]); file_put_contents( $counterFile, json_encode($counters), LOCK_EX ); } exit('hangup_ok'); } $extensionKey = trim($apiExtension, '/'); $extensionKey = str_replace('/', '_', $extensionKey); if ($extensionKey === '') { exit('Invalid ApiExtension'); } $configFile = __DIR__ . "/settings_{$extensionKey}.txt"; $dataFile = __DIR__ . "/counter_{$extensionKey}.txt"; if (!file_exists($configFile)) { exit('Missing settings file'); } if (!file_exists($dataFile)) { file_put_contents( $dataFile, json_encode([]), LOCK_EX ); } $counters = json_decode(file_get_contents($dataFile), true); if (!is_array($counters)) { $counters = []; } $steps = []; $offset = null; foreach (file($configFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) { $line = trim($line); if ($line === '') { continue; } if (preg_match('/^offset\s*=\s*(-?\d+)$/i', $line, $match)) { $offset = (int)$match[1]; continue; } if (!str_contains($line, '=')) { continue; } [$index, $value] = explode('=', $line, 2); if (!is_numeric($index)) { continue; } $steps[(int)$index] = trim($value); } if ($offset !== null) { if ($what === '') { exit('Missing what'); } $fileName = basename($what); $dotPos = strrpos($fileName, '.'); if ($dotPos !== false) { $fileName = substr($fileName, 0, $dotPos); } if (!ctype_digit($fileName)) { exit('Invalid filename in what'); } $originalLength = strlen($fileName); $targetNumber = ((int)$fileName + $offset); $target = str_pad( (string)$targetNumber, $originalLength, '0', STR_PAD_LEFT ); echo 'go_to_folder_and_play=' . $apiExtension . ',' . $target; exit; } ksort($steps); if (empty($steps)) { exit('No steps configured'); } $currentStep = $counters[$apiCallId] ?? 0; if (isset($steps[$currentStep])) { $target = $steps[$currentStep]; } else { $target = end($steps); } $counters[$apiCallId] = $currentStep + 1; file_put_contents( $dataFile, json_encode($counters), LOCK_EX ); echo 'go_to_folder_and_play=' . $apiExtension . ',' . $target;ישנם שני מצבים להגדרה מראש של הדילוג
1.
מצב דילוג בקצב מוגדר מראש:כלומר, כמות הודעות מוגדרת לקפיצה בכל פעם.
יש להכניס לקובץ טקסט, (עם אותו שם כמו שיוסבר להלן.)
הקובץ יראה ככה
offset=כמות ההודעות לדילוג בכל פעם.
באפשרות זו, הקוד לא יתייחס לסוג הדילוג השני.2.
מצב כניסה לפי מונה:עובר כל פעם למספר קובץ הבא המוגדר.
יש ליצור קבצים בשם:
settings_שם השלוחה
יש להחליף סלשים ב '_' לדוגמא, לשלוחה 1/1/1 יש לקרוא לקובץ:
settings_1_1_1.txtבתוך הקבצים יש להכניס ככה במספרים עוקבים:
0=מספר הקובץ
1=מספר הקובץניתן להפעיל הגדרה של שליחה בניתוק, וכך המונה יתאפס, (לא כזה רלוונטי מכיוון שהקוד בנוי על ה id הזמני לאורך השיחה, אבל כדאי שיהיה.)
- שימו לב, הקוד יצור קבצי מונה שבודקים כמה כניסות בוצעו, ניתן להתעלם לגמרי מהקבצים הללו.
-
י יהודה צ. כ. התייחס לנושא זה
שלום! נראה שהשיחה הזו מעניינת אותך, אבל עדיין אין לך חשבון.
נמאס לכם לגלול בין אותם הפוסטים בכל ביקור? כשנרשמים לחשבון, תמיד תחזרו בדיוק למקום שבו הייתם קודם, ותוכלו לבחור לקבל התראות על תגובות חדשות (בין אם במייל, ובין אם בהתראת פוש). תוכלו גם לשמור סימניות ולפרגן ב-upvote לפוסטים כדי להביע הערכה לחברי קהילה אחרים.
בעזרת התרומה שלך, הפוסט הזה יכול להיות אפילו טוב יותר 💗
הרשמה התחברות