Example #1
0
 public function getPath(Attachment $attachment, string $variation) : string
 {
     $path = $attachment->path;
     $extension = $attachment->extension;
     $path = str_replace_last($extension, '', $path);
     return $path . $variation . '.' . $extension;
 }
 /**
  * Gets a list of counties flags suitable for select boxes.
  *
  * @return array
  */
 public static function flagsList()
 {
     $flags = [];
     $Folder = new Folder(Plugin::path('Locale') . 'webroot/img/flags/');
     foreach ($Folder->read()[1] as $icon) {
         $value = $icon;
         $label = str_replace_last('.gif', '', $icon);
         $flags[$value] = $label;
     }
     asort($flags);
     return $flags;
 }
Example #3
0
 public function getDocumentUrl($url)
 {
     // because the URL also includes the current page as segment, it means we have to go 1 higher. Example:
     // document: "codex/master/getting-started/configure"
     // has link: "../index"
     // normalizes to: "codex/master/getting-started/index"
     // this will fix that
     $url = "../{$url}";
     // endfix
     $url = str_replace_last('.' . $this->getExtension($url), '', $url);
     $url = url()->current() . Str::ensureLeft($url, '/');
     return $this->normalizeUrl($url);
 }
$intervals_data = mysql_fetch_assoc($query);
$intervals = floor($intervals_data['INTRVL']);
$dist_by_dist_query = "";
for ($multiplier = 1; $multiplier < $no_of_bins + 1; $multiplier++) {
    $lower = $intervals * $multiplier;
    $higher = $intervals * ($multiplier + 1) - 1;
    $dist_by_dist_query .= "SELECT td.FROM_COMMUNITY AS COMMUNITY,td.FROM_STATION_NAME AS STATION_NAME," . $lower . " AS DIST_METERS, COUNT(*) AS TOTAL_TRIPS FROM trips_data td, stations_data sd WHERE " . $lower . " < DIST_METERS AND DIST_METERS < " . $higher . " AND td.FROM_COMMUNITY = sd.COMMUNITY AND td.FROM_STATION_NAME = sd.STATIONNAME GROUP BY td.FROM_COMMUNITY,td.FROM_STATION_NAME UNION ";
}
function str_replace_last($search, $replace, $str)
{
    if (($pos = strrpos($str, $search)) !== false) {
        $search_length = strlen($search);
        $str = substr_replace($str, $replace, $pos, $search_length);
    }
    return $str;
}
$str = $dist_by_dist_query;
$search = 'UNION';
$replace = '';
$dist_by_dist_query = str_replace_last($search, $replace, $str);
$query = mysql_query($dist_by_dist_query);
if (!$query) {
    echo mysql_error();
    die;
}
$dist_by_dist_data = array();
for ($x = 0; $x < mysql_num_rows($query); $x++) {
    $dist_by_dist_data[] = mysql_fetch_assoc($query);
}
echo json_encode($dist_by_dist_data);
mysql_close($server);
Example #5
0
function number_to_word($num = '')
{
    $num = (string) (int) $num;
    if ((int) $num && ctype_digit($num)) {
        $words = array();
        $num = str_replace(array(',', ' '), '', trim($num));
        $list1 = array('', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen');
        $list2 = array('', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety', 'hundred');
        $list3 = array('', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quattuordecillion', 'quindecillion', 'sexdecillion', 'septendecillion', 'octodecillion', 'novemdecillion', 'vigintillion');
        $num_length = strlen($num);
        $levels = (int) (($num_length + 2) / 3);
        $max_length = $levels * 3;
        $num = substr('00' . $num, -$max_length);
        $num_levels = str_split($num, 3);
        foreach ($num_levels as $num_part) {
            $levels--;
            $hundreds = (int) ($num_part / 100);
            $hundreds = $hundreds ? ' ' . $list1[$hundreds] . ' Hundred' . ($hundreds == 1 ? '' : 's') . ' ' : '';
            $tens = (int) ($num_part % 100);
            $singles = '';
            if ($tens < 20) {
                $tens = $tens ? ' ' . $list1[$tens] . ' ' : '';
            } else {
                $tens = (int) ($tens / 10);
                $tens = ' ' . $list2[$tens] . ' ';
                $singles = (int) ($num_part % 10);
                $singles = ' ' . $list1[$singles] . ' ';
            }
            $words[] = $hundreds . $tens . $singles . ($levels && (int) $num_part ? ' ' . $list3[$levels] . ' ' : '');
        }
        $commas = count($words);
        if ($commas > 1) {
            $commas = $commas - 1;
        }
        $words = implode(', ', $words);
        //Some Finishing Touch
        //Replacing multiples of spaces with one space
        $words = trim(str_replace(' ,', ',', trim_all(ucwords($words))), ', ');
        if ($commas) {
            $words = str_replace_last(',', ' and', $words);
        }
        return $words;
    } else {
        if (!(int) $num) {
            return 'Zero';
        }
    }
    return '';
}
 /**
  * Adds a new terms within the given vocabulary.
  *
  * @param int $vocabularyId Vocabulary's ID
  * @return void
  */
 public function add($vocabularyId)
 {
     $this->loadModel('Taxonomy.Vocabularies');
     $vocabulary = $this->Vocabularies->get($vocabularyId);
     $term = $this->Vocabularies->Terms->newEntity(['vocabulary_id' => $vocabulary->id], ['validate' => false]);
     $this->Vocabularies->Terms->addBehavior('Tree', ['scope' => ['vocabulary_id' => $vocabulary->id]]);
     if ($this->request->data()) {
         $term = $this->Vocabularies->Terms->patchEntity($term, $this->request->data, ['fieldList' => ['parent_id', 'name']]);
         if ($this->Vocabularies->Terms->save($term)) {
             $this->Flash->success(__d('taxonomy', 'Term has been created.'));
             if (!empty($this->request->data['action_vocabulary'])) {
                 $this->redirect(['plugin' => 'Taxonomy', 'controller' => 'terms', 'action' => 'vocabulary', $vocabulary->id]);
             } elseif (!empty($this->request->data['action_add'])) {
                 $this->redirect(['plugin' => 'Taxonomy', 'controller' => 'terms', 'action' => 'add', $vocabulary->id]);
             }
         } else {
             $this->Flash->danger(__d('taxonomy', 'Term could not be created, please check your information.'));
         }
     }
     $parentsTree = $this->Vocabularies->Terms->find('treeList', ['spacer' => '--'])->map(function ($link) {
         if (strpos($link, '-') !== false) {
             $link = str_replace_last('-', '- ', $link);
         }
         return $link;
     });
     $this->title(__d('taxonomy', 'Create New Term'));
     $this->set(compact('vocabulary', 'term', 'parentsTree'));
     $this->Breadcrumb->push('/admin/system/structure')->push(__d('taxonomy', 'Taxonomy'), '/admin/taxonomy/manage')->push(__d('taxonomy', 'Vocabularies'), ['plugin' => 'Taxonomy', 'controller' => 'vocabularies', 'action' => 'index'])->push("\"{$vocabulary->name}\"", ['plugin' => 'Taxonomy', 'controller' => 'vocabularies', 'action' => 'edit', $vocabulary->id])->push(__d('taxonomy', 'Terms'), ['plugin' => 'Taxonomy', 'controller' => 'terms', 'action' => 'vocabulary', $vocabulary->id])->push(__d('taxonomy', 'Add new term'), '#');
 }
Example #7
0
 public function getNameWithoutExtension()
 {
     $name = $this->getName();
     return str_replace_last('.' . $this->getFileExtension(), '', $name);
 }
 /**
  * Gets an schema instance for the given fixture class.
  *
  * @param string $fixtureClassName The fixture to be "converted"
  * @return \Cake\Database\Schema\Table Schema instance
  */
 protected function _prepareSchema($fixtureClassName)
 {
     $fixture = new $fixtureClassName();
     if (!empty($fixture->table)) {
         $tableName = $fixture->table;
     } else {
         $tableName = (string) Inflector::underscore(str_replace_last('Fixture', '', $fixtureClassName));
     }
     list($fields, $constraints, $indexes, $options) = $this->_prepareSchemaProperties($fixture);
     $schema = new TableSchema($tableName, $fields);
     foreach ($constraints as $name => $attrs) {
         $schema->addConstraint($name, $attrs);
     }
     foreach ($indexes as $name => $attrs) {
         $schema->addIndex($name, $attrs);
     }
     if (!empty($options)) {
         $schema->options($options);
     }
     return $schema;
 }
 /**
  * Adds a new link to the given menu.
  *
  * @param int $menuId Menu's ID for which add a link
  * @return void
  */
 public function add($menuId)
 {
     $this->loadModel('Menu.Menus');
     $this->loadModel('Content.Contents');
     $menu = $this->Menus->get($menuId);
     $link = $this->Menus->MenuLinks->newEntity();
     $link->set(['activation' => 'auto', 'status' => 1, 'menu_id' => $menuId]);
     $this->Menus->MenuLinks->addBehavior('Tree', ['scope' => ['menu_id' => $menu->id]]);
     if ($this->request->data()) {
         $link = $this->Menus->MenuLinks->patchEntity($link, $this->request->data, ['fieldList' => ['parent_id', 'title', 'url', 'description', 'target', 'expanded', 'active', 'activation', 'status']]);
         if ($this->Menus->MenuLinks->save($link)) {
             $this->Menus->MenuLinks->recover();
             $this->Flash->success(__d('menu', 'Link successfully created!'));
             if (!empty($this->request->data['action_add'])) {
                 $this->redirect(['plugin' => 'Menu', 'controller' => 'links', 'action' => 'add', $menuId]);
             } elseif (!empty($this->request->data['action_menu'])) {
                 $this->redirect(['plugin' => 'Menu', 'controller' => 'links', 'action' => 'menu', $menuId]);
             }
         } else {
             $this->Flash->danger(__d('menu', 'Link could not be saved, please check your information'));
         }
     }
     $contentLinks = [];
     $contents = $this->Contents->find()->select(['id', 'slug', 'content_type_slug', 'title'])->all();
     foreach ($contents as $content) {
         $contentLinks[stripLanguagePrefix($content->get('url'))] = __d('menu', '{0} [{1}]', [$content->title, $content->content_type_slug]);
     }
     $parentsTree = $this->Menus->MenuLinks->find('treeList', ['spacer' => '--'])->map(function ($link) {
         if (strpos($link, '-') !== false) {
             $link = str_replace_last('-', '- ', $link);
         }
         return $link;
     });
     $this->title(__d('menu', 'Create New Link'));
     $this->set(compact('menu', 'link', 'contentLinks', 'parentsTree'));
     $this->Breadcrumb->push('/admin/menu/manage')->push(__d('menu', 'Editing menu "{0}"', $menu->title), ['plugin' => 'Menu', 'controller' => 'manage', 'action' => 'edit', $menuId])->push(__d('menu', 'Links'), ['plugin' => 'Menu', 'controller' => 'links', 'action' => 'menu', $menuId])->push(__d('menu', 'Add new link'), '#');
 }
Example #10
0
function callHeroBannerThumbListByID($picID, $staus)
{
    global $conn;
    $sql = "SELECT IMG_PATH FROM trn_hero_banner WHERE PIC_ID = " . $picID . " AND IMG_TYPE = 1  ORDER BY ORDER_ID ASC LIMIT 0 , 1";
    $query = mysql_query($sql, $conn);
    $num = mysql_num_rows($query);
    if ($num == 1) {
        $row = mysql_fetch_array($query);
        if ($staus) {
            return $row['IMG_PATH'];
        } else {
            return 'style="background-image: url(\'' . str_replace_last('/', '/thumbnail/', $row['IMG_PATH']) . '\');"';
        }
    } else {
        if ($staus) {
            return '../images/logo_thumb.jpg';
        } else {
            return '';
        }
    }
}
Example #11
0
function getFavsByCoord($params)
{
    $lat;
    $lon;
    $art;
    $umkreis;
    $sortieren;
    try {
        $lat = $params->getParam(0)->scalarval();
        $lon = $params->getParam(1)->scalarval();
        $art = $params->getParam(2)->scalarval();
        $umkreis = $params->getParam(3)->scalarval();
        $sortieren = $params->getParam(4)->scalarval();
        $favsList = $params->getParam(5)->scalarval();
        $idsQuery = str_replace(";", ",", $favsList);
        $idsQuery = "(" . str_replace_last(",", "", $idsQuery) . ")";
    } catch (Exception $fault) {
        return new Exception("Server", "Error converting params getFavsByCoords : " . $fault);
    }
    $db_id = mysql_connect("localhost", "web1162", "bX2KARTc");
    if (!$db_id) {
        die("Verbindungsaufbau ist gescheitert");
    }
    $db_sel = mysql_select_db("usr_web1162_3", $db_id);
    if (!$db_sel) {
        die('Kann Datenbank nicht benutzen : ' . mysql_error());
    }
    mysql_query("SET names 'utf8'");
    mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $db_id);
    try {
        $priceRecords = null;
        $basequery = "select distinct TIME_FORMAT(ot.startTimeOfPeriod,'%H:%i') as ab, TIME_FORMAT(ot.endTimeOfPeriod,'%H:%i') as bis,\n    \t\t\t\t\t\t\t\t\t\t\t\t\t(select CASE WHEN CURRENT_TIME BETWEEN ot.startTimeOfPeriod\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND ot.endTimeOfPeriod\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen 1\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\telse 0\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tend\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t) as open,\n    \t\t\t\t\t\t\t\t\t\t\t\t\t" . $art . " , a.id, a.petrolStationBrand, a.petrolStationStreet, a.petrolStationHouseNumber, a.petrolStationPostcode, a.petrolStationPlace, a.petrolStationVersionTime, a.longitude as AnbietGPSLaenge, a.latitude as AnbietGPSBreite, ACOS( SIN( RADIANS( a.latitude ) ) * SIN( RADIANS( '{$lat}' ) ) + COS( RADIANS( a.latitude ) ) * COS( RADIANS( '{$lat}' ) ) * COS( RADIANS( a.longitude ) - RADIANS( '{$lon}' ) ) ) *6380 AS 'distance'\n\t\t\t\t\t\t\t\t\t\t \n\t \t\t\t\t\t\t\t\t\t\t\t\t\tfrom ( select Max(`version`) as newest \n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfrom `fuelPrice` \n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\tgroup by `id` ) plNewest, \n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t`fuelPrice` pl, `petrolStation` a, `openingTimes` ot\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhere a.`id` in {$idsQuery}\n\t\t\t\t\t\t\t\t\t\t \t\t\t\t\t\tand pl.`version` = plNewest.newest\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand a.`id` = pl.`id` \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand ot.applicableDay = (SELECT DAYNAME( CURDATE( ) ) )\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand ot.fid = a.id\n\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t\tand " . $art . " > 0";
        if (strpos($sortieren, 'preis') !== false) {
            $priceRecords = mysql_query($basequery . " order by {$art}, distance limit 7");
        } else {
            if (strpos($sortieren, 'distanz') !== false) {
                $priceRecords = mysql_query($basequery . " order by distance limit 7");
            }
        }
        if ($log == null) {
            $log = new Logging();
        }
        $log->lfile('log_debug.txt');
        $log->lwrite("{$basequery}: " . $basequery);
        $log->lclose();
        if (mysql_num_rows($priceRecords) >= 1) {
            $petrolStationList = array();
            /* Tankstelle ermitteln */
            while ($aktZeile = mysql_fetch_assoc($priceRecords)) {
                $location = new location($aktZeile['AnbietGPSBreite'], $aktZeile['AnbietGPSLaenge']);
                $address = new address($aktZeile['petrolStationStreet'], $aktZeile['petrolStationHouseNumber'], $aktZeile['petrolStationPostcode'], $aktZeile['petrolStationPlace']);
                $petrolStation = new petrolStation($aktZeile['id'], $aktZeile['petrolStationBrand'], $aktZeile['open'], $aktZeile['ab'], $aktZeile['bis'], $location, $aktZeile[$art], $address, $aktZeile['petrolStationVersionTime'], $aktZeile['distance']);
                array_push($petrolStationList, $petrolStation);
            }
        } else {
            echo "Keine Ergebnisse";
        }
    } catch (SoapFault $fault) {
        return new SoapFault("Server", "Error reading town by coord. " . $fault);
    }
    $petrolStationArray = array();
    // $petrolStationList.count
    $count = 0;
    $resp = new jsonrpcresp(new jsonrpcval("no data", 'string'));
    if ($petrolStationList != null) {
        foreach ($petrolStationList as $station) {
            $petrolStation = array('owner' => new jsonrpcval(umlaute_ersetzen($station->owner), 'string'), 'isOpen' => new jsonrpcval($station->isOpen, 'boolean'), 'openFrom' => new jsonrpcval($station->openFrom . "", 'string'), 'openTo' => new jsonrpcval($station->openTo . "", 'string'), 'longitude' => new jsonrpcval($station->location->longitude, 'double'), 'latitude' => new jsonrpcval($station->location->latitude, 'double'), 'price' => new jsonrpcval($station->price, 'string'), 'street' => new jsonrpcval(umlaute_ersetzen($station->address->street), 'string'), 'housenumber' => new jsonrpcval($station->address->housenumber, 'string'), 'postal' => new jsonrpcval($station->address->postal, 'string'), 'place' => new jsonrpcval(umlaute_ersetzen($station->address->place), 'string'), 'reporttime' => new jsonrpcval($station->reporttime . "", 'string'), 'distance' => new jsonrpcval($station->distance, 'double'), 'id' => new jsonrpcval($station->id, 'double'));
            array_push($petrolStationArray, new jsonrpcval($petrolStation, 'struct'));
            $count += 1;
        }
        $resp = new jsonrpcresp(new jsonrpcval($petrolStationArray, 'struct'));
        $resp->content_type = "text/json; charset=iso-8859-1";
        //$resp->serialize('UTF-8');
    }
    return $resp;
}
Example #12
0
 /**
  * This method should never be used unless you know what are you doing.
  *
  * Populates the "acos" DB with information of every installed plugin, or
  * for the given plugin. It will automatically extracts plugin's controllers
  * and actions for creating a tree structure as follow:
  *
  * - PluginName
  *   - Admin
  *     - PrivateController
  *       - index
  *       - some_action
  *   - ControllerName
  *     - index
  *     - another_action
  *
  * After tree is created you should be able to change permissions using
  * User's permissions section in backend.
  *
  * @param string $for Optional, build ACOs for the given plugin, or all plugins
  *  if not given
  * @param bool $sync Whether to sync the tree or not. When syncing all invalid
  *  ACO entries will be removed from the tree, also new ones will be added. When
  *  syn is set to false only new ACO entries will be added, any invalid entry
  *  will remain in the tree. Defaults to false
  * @return bool True on success, false otherwise
  */
 public static function buildAcos($for = null, $sync = false)
 {
     if (function_exists('ini_set')) {
         ini_set('max_execution_time', 300);
     } elseif (function_exists('set_time_limit')) {
         set_time_limit(300);
     }
     if ($for === null) {
         $plugins = plugin()->toArray();
     } else {
         try {
             $plugins = [plugin($for)];
         } catch (\Exception $e) {
             return false;
         }
     }
     $added = [];
     foreach ($plugins as $plugin) {
         if (!Plugin::exists($plugin->name)) {
             continue;
         }
         $aco = new AcoManager($plugin->name);
         $controllerDir = normalizePath("{$plugin->path}/src/Controller/");
         $folder = new Folder($controllerDir);
         $controllers = $folder->findRecursive('.*Controller\\.php');
         foreach ($controllers as $controller) {
             $controller = str_replace([$controllerDir, '.php'], '', $controller);
             $className = $plugin->name . '\\' . 'Controller\\' . str_replace(DS, '\\', $controller);
             $methods = static::_controllerMethods($className);
             if (!empty($methods)) {
                 $path = explode('Controller\\', $className)[1];
                 $path = str_replace_last('Controller', '', $path);
                 $path = str_replace('\\', '/', $path);
                 foreach ($methods as $method) {
                     if ($aco->add("{$path}/{$method}")) {
                         $added[] = "{$plugin->name}/{$path}/{$method}";
                     }
                 }
             }
         }
     }
     if ($sync && isset($aco)) {
         $aco->Acos->recover();
         $existingPaths = static::paths($for);
         foreach ($existingPaths as $exists) {
             if (!in_array($exists, $added)) {
                 $aco->remove($exists);
             }
         }
         $validLeafs = $aco->Acos->find()->select(['id'])->where(['id NOT IN' => $aco->Acos->find()->select(['parent_id'])->where(['parent_id IS NOT' => null])]);
         $aco->Acos->Permissions->deleteAll(['aco_id NOT IN' => $validLeafs]);
     }
     return true;
 }
Example #13
0
function create_label_translation($constantValue)
{
    $translate_file = $_GET['p'] . ".inc.php";
    // Check if translation needs to be writed in all.inc.php
    $trace_array = explode("\n", getDebugBacktrace(2));
    if (isset($trace_array[1])) {
        $trace_array[1] = str_replace("\\", "/", $trace_array[1]);
        if (find($trace_array[1], "wsp/includes/utils_label.inc.php") > 0) {
            // call function __()
            $trace = isset($trace_array[4]) ? $trace_array[4] : "";
        } else {
            // call function translate()
            $trace = isset($trace_array[1]) ? $trace_array[1] : "";
        }
        $trace = str_replace("\\", "/", $trace);
        if (($pos = find($trace, SITE_DIRECTORY)) > 0) {
            $trace_file = substr($trace, $pos, strlen($trace));
            $page_label = str_replace("/pages/", "", substr($trace_file, 0, strlen($trace_file) - 4));
            if ($page_label != $_GET['p']) {
                $translate_file = "all.inc.php";
            }
        }
    }
    // Create new label in each languages
    $creation_message = "";
    $base_dir = dirname(__FILE__) . "/../..";
    $array_lang_dir = scandir($base_dir . "/lang");
    for ($i = 0; $i < sizeof($array_lang_dir); $i++) {
        if (is_dir($base_dir . "/lang/" . $array_lang_dir[$i]) && $array_lang_dir[$i] != "" && $array_lang_dir[$i] != "." && $array_lang_dir[$i] != ".." && $array_lang_dir[$i] != ".svn" && strlen($array_lang_dir[$i]) == 2) {
            $lang_file_path = str_replace("\\", "/", realpath($base_dir . "/lang/" . $array_lang_dir[$i])) . "/" . $translate_file;
            // Read File
            $lang_file_content = "";
            if (file_exists($lang_file_path)) {
                $lang_file = new File($lang_file_path);
                $lang_file_content = $lang_file->read();
                $lang_file->close();
            }
            // Check if the label doesn't already exists for this language
            if (!label_exists($lang_file_content, $constantValue)) {
                // Create new label
                if ($lang_file_content == "") {
                    $lang_file_content = "<?php\n";
                }
                $lang_file_content = str_replace("\r", "", $lang_file_content);
                $lang_file_content = str_replace_last("?>", "", $lang_file_content);
                $lang_file_content .= "\tdefine('" . addslashes($constantValue) . "', '" . addslashes($constantValue) . "'); // TODO: Label needs to be translated\n";
                $lang_file_content .= "?>";
                // Write File
                if ($GLOBALS['WSP_AUTO_CREATE_CONSTANT']) {
                    $lang_file = new File($lang_file_path, false, true);
                    if ($lang_file->write($lang_file_content) !== false) {
                        $creation_message .= "Information: Constant <font color='blue'>" . $constantValue . "</font> automatically <font color='green'>CREATED</font> in the file " . $lang_file_path . ".<br/>";
                    }
                    $lang_file->close();
                }
                // Check if this label doesn't exists in other language for the current page
                if ($translate_file == "all.inc.php") {
                    $page_lang_file_path = str_replace("\\", "/", realpath($base_dir . "/lang/" . $array_lang_dir[$i])) . "/" . $_GET['p'] . ".inc.php";
                    if (file_exists($page_lang_file_path)) {
                        $lang_file = new File($page_lang_file_path);
                        $lang_file_content = $lang_file->read();
                        $lang_file->close();
                        if (!label_exists($lang_file_content, $constantValue)) {
                            $label_found = false;
                            if (find($lang_file_content, "define(\"" . $constantValue . "\"") > 0) {
                                $lang_file_content = str_replace_first("define(\"" . $constantValue . "\"", "// TODO: Remove label (now in all.inc.php) -> define(\"" . $constantValue . "\"", $lang_file_content);
                                $label_found = true;
                            } else {
                                if (find($lang_file_content, "define('" . $constantValue . "'") > 0) {
                                    $lang_file_content = str_replace_first("define('" . $constantValue . "'", "// TODO: Remove label (now in all.inc.php) -> define('" . $constantValue . "'", $lang_file_content);
                                    $label_found = true;
                                }
                            }
                            // Write File
                            if ($label_found && $GLOBALS['WSP_AUTO_CREATE_CONSTANT']) {
                                $lang_file = new File($page_lang_file_path, false, true);
                                if ($lang_file->write($lang_file_content) !== false) {
                                    $creation_message .= "Information: Constant <font color='blue'>" . $constantValue . "</font> automatically <font color='red'>COMMENT</font> in the file " . $page_lang_file_path . ".<br/>";
                                }
                                $lang_file->close();
                            }
                        }
                    }
                }
            }
        }
    }
    if ($creation_message != "") {
        // Simulate the new label is loaded
        define($constantValue, $constantValue);
        // Inform the developer by DialogBox
        if ($GLOBALS['__AJAX_LOAD_PAGE__'] == false || $GLOBALS['__AJAX_LOAD_PAGE__'] == true && find($_GET['mime'], "html") > 0) {
            $dialog = new DialogBox("Alert translation", $creation_message);
            $dialog->activateCloseButton()->setWidth(600);
            Page::getInstance($_GET['p'])->addObject($dialog);
        }
        // Inform the developer by mail
        if (defined('SEND_ERROR_BY_MAIL') && SEND_ERROR_BY_MAIL == true && !isLocalDebug()) {
            try {
                $mail = new SmtpMail(SEND_ERROR_BY_MAIL_TO, __(SEND_ERROR_BY_MAIL_TO), "New label on " . __(SITE_NAME) . " !!!", $creation_message, SMTP_MAIL, __(SMTP_NAME));
                $mail->setPriority(SmtpMail::PRIORITY_HIGH);
                $mail->send();
            } catch (Exception $e) {
            }
        }
    }
}
<?php

require "../../assets/configs/config.inc.php";
require "../../assets/configs/connectdb.inc.php";
require "../../assets/configs/function.inc.php";
$path = $_POST['pname'];
if (file_exists($path)) {
    unlink($path);
}
$path = str_replace_last('/', '/thumbnail/', $path);
if (file_exists($path)) {
    unlink($path);
}
if ($_POST['iconType'] == 'BIG') {
    mysql_query("update trn_banner_pic_setting set DESKTOP_ICON_PATH = null WHERE BANNER_ID = " . $_POST['bannerid'], $conn);
} else {
    if ($_POST['iconType'] == 'SMALL') {
        mysql_query("update trn_banner_pic_setting set MOBILE_ICON_PATH = null WHERE BANNER_ID = " . $_POST['bannerid'], $conn);
    }
}
//mysql_query('DELETE FROM trn_banner_pic_setting WHERE BANNER_ID = ' . $_POST['bannerid'], $conn);
mysql_query('OPTIMIZE TABLE trn_banner_pic_setting', $conn);
Example #15
0
 /**
  * @return string
  */
 public function intFormatted() : string
 {
     return str_replace_last('.00', '', $this->formatted());
 }
Example #16
0
 /**
  * Escapes all shortcodes from the given content.
  *
  * @param string $text Text from which to escape shortcodes
  * @return string Content with all shortcodes escaped
  */
 public static function escape($text)
 {
     $tagregexp = implode('|', array_map('preg_quote', static::_list()));
     preg_match_all('/(.?){(' . $tagregexp . ')\\b(.*?)(?:(\\/))?}(?:(.+?){\\/\\2})?(.?)/s', $text, $matches);
     foreach ($matches[0] as $ht) {
         $replace = str_replace_once('{', '{{', $ht);
         $replace = str_replace_last('}', '}}', $replace);
         $text = str_replace($ht, $replace, $text);
     }
     return $text;
 }
Example #17
0
 /**
  * Stores some bootstrap-handy information into a persistent file.
  *
  * Information is stored in `TMP/snapshot.php` file, it contains
  * useful information such as enabled languages, content types slugs, installed
  * plugins, etc.
  *
  * You can read this information using `Configure::read()` as follow:
  *
  * ```php
  * Configure::read('QuickApps.<option>');
  * ```
  *
  * Or using the `quickapps()` global function:
  *
  * ```php
  * quickapps('<option>');
  * ```
  *
  * @return void
  */
 function snapshot()
 {
     if (Cache::config('default')) {
         Cache::clear(false, 'default');
     }
     if (Cache::config('_cake_core_')) {
         Cache::clear(false, '_cake_core_');
     }
     if (Cache::config('_cake_model_')) {
         Cache::clear(false, '_cake_model_');
     }
     $versionPath = QUICKAPPS_CORE . 'VERSION.txt';
     $snapshot = ['version' => null, 'content_types' => [], 'plugins' => [], 'options' => [], 'languages' => [], 'aspects' => []];
     if (is_readable($versionPath)) {
         $versionFile = file($versionPath);
         $snapshot['version'] = trim(array_pop($versionFile));
     } else {
         die(sprintf('Missing file: %s', $versionPath));
     }
     if (ConnectionManager::config('default')) {
         if (!TableRegistry::exists('SnapshotPlugins')) {
             $PluginTable = TableRegistry::get('SnapshotPlugins', ['table' => 'plugins']);
         } else {
             $PluginTable = TableRegistry::get('SnapshotPlugins');
         }
         if (!TableRegistry::exists('SnapshotContentTypes')) {
             $ContentTypesTable = TableRegistry::get('SnapshotContentTypes', ['table' => 'content_types']);
         } else {
             $ContentTypesTable = TableRegistry::get('SnapshotContentTypes');
         }
         if (!TableRegistry::exists('SnapshotLanguages')) {
             $LanguagesTable = TableRegistry::get('SnapshotLanguages', ['table' => 'languages']);
         } else {
             $LanguagesTable = TableRegistry::get('SnapshotLanguages');
         }
         if (!TableRegistry::exists('SnapshotOptions')) {
             $OptionsTable = TableRegistry::get('SnapshotOptions', ['table' => 'options']);
         } else {
             $OptionsTable = TableRegistry::get('SnapshotOptions');
         }
         $PluginTable->schema(['value' => 'serialized']);
         $OptionsTable->schema(['value' => 'serialized']);
         $plugins = $PluginTable->find()->select(['name', 'package', 'status'])->order(['ordering' => 'ASC', 'name' => 'ASC'])->all();
         $contentTypes = $ContentTypesTable->find()->select(['slug'])->all();
         $languages = $LanguagesTable->find()->where(['status' => 1])->order(['ordering' => 'ASC'])->all();
         $options = $OptionsTable->find()->select(['name', 'value'])->where(['autoload' => 1])->all();
         foreach ($contentTypes as $contentType) {
             $snapshot['content_types'][] = $contentType->slug;
         }
         foreach ($options as $option) {
             $snapshot['options'][$option->name] = $option->value;
         }
         foreach ($languages as $language) {
             list($languageCode, $countryCode) = localeSplit($language->code);
             $snapshot['languages'][$language->code] = ['name' => $language->name, 'locale' => $language->code, 'code' => $languageCode, 'country' => $countryCode, 'direction' => $language->direction, 'icon' => $language->icon];
         }
     } else {
         $plugins = [];
         foreach (Plugin::scan() as $plugin => $path) {
             $plugins[] = new Entity(['name' => $plugin, 'status' => true, 'package' => 'quickapps-plugins']);
         }
     }
     $folder = new Folder(QUICKAPPS_CORE . 'src/Aspect/');
     foreach ($folder->read(false, false, true)[1] as $classFile) {
         $className = basename(preg_replace('/\\.php$/', '', $classFile));
         if (!in_array($className, ['AppAspect', 'Aspect'])) {
             $snapshot['aspects'][] = "CMS\\Aspect\\{$className}";
         }
     }
     foreach ($plugins as $plugin) {
         $pluginPath = false;
         if (isset(Plugin::scan()[$plugin->name])) {
             $pluginPath = Plugin::scan()[$plugin->name];
         }
         if ($pluginPath === false) {
             Debugger::log(sprintf('Plugin "%s" was found in DB but QuickAppsCMS was unable to locate its root directory.', $plugin->name));
             continue;
         }
         if (!Plugin::validateJson("{$pluginPath}/composer.json")) {
             Debugger::log(sprintf('Plugin "%s" has a corrupt "composer.json" file (%s).', $plugin->name, "{$pluginPath}/composer.json"));
             continue;
         }
         $aspectsPath = "{$pluginPath}/src/Aspect/";
         $eventsPath = "{$pluginPath}/src/Event/";
         $fieldsPath = "{$pluginPath}/src/Field/";
         $helpFiles = glob($pluginPath . '/src/Template/Element/Help/help*.ctp');
         $isTheme = str_ends_with($plugin->name, 'Theme');
         $status = (bool) $plugin->status;
         $humanName = '';
         $aspects = [];
         $eventListeners = [];
         $fields = [];
         $subspaces = [$aspectsPath => 'Aspect', $eventsPath => 'Event', $fieldsPath => 'Field'];
         $varnames = [$aspectsPath => 'aspects', $eventsPath => 'eventListeners', $fieldsPath => 'fields'];
         foreach ([$aspectsPath, $eventsPath, $fieldsPath] as $path) {
             if (is_dir($path)) {
                 $Folder = new Folder($path);
                 foreach ($Folder->read(false, false, true)[1] as $classFile) {
                     $className = basename(preg_replace('/\\.php$/', '', $classFile));
                     $subspace = $subspaces[$path];
                     $varname = $varnames[$path];
                     $namespace = "{$plugin->name}\\{$subspace}\\";
                     ${$varname}[] = $namespace . $className;
                 }
             }
         }
         if (is_readable("{$pluginPath}composer.json")) {
             $json = (array) json_decode(file_get_contents("{$pluginPath}composer.json"), true);
             if (!empty($json['extra']['human-name'])) {
                 $humanName = $json['extra']['human-name'];
             }
         }
         if (empty($humanName)) {
             $humanName = (string) Inflector::humanize((string) Inflector::underscore($plugin->name));
             if ($isTheme) {
                 $humanName = trim(str_replace_last('Theme', '', $humanName));
             }
         }
         $snapshot['plugins'][$plugin->name] = ['name' => $plugin->name, 'humanName' => $humanName, 'package' => $plugin->package, 'isTheme' => $isTheme, 'hasHelp' => !empty($helpFiles), 'hasSettings' => is_readable($pluginPath . '/src/Template/Element/settings.ctp'), 'aspects' => $aspects, 'eventListeners' => $eventListeners, 'fields' => $fields, 'status' => $status, 'path' => $pluginPath];
         if ($status) {
             $snapshot['aspects'] = array_merge($snapshot['aspects'], $aspects);
         }
     }
     Configure::write('QuickApps', $snapshot);
     if (!Configure::dump('snapshot', 'QuickApps', ['QuickApps'])) {
         die('QuickAppsCMS was unable to create a snapshot file, check that PHP have permission to write to the "/tmp" directory.');
     }
 }