/**
 * Main driver for running system check 
 * @since 1.2.4
 * @param $registry
 * @param $mode ('log', 'return') 
 * @return array
 *
 * Note: This is English text only. Can be call before database and languges are loaded
 */
function run_system_check($registry, $mode = 'log')
{
    $mlog = $counts = array();
    $mlog[] = check_install_directory($registry);
    $mlog = array_merge($mlog, check_file_permissions($registry));
    $mlog = array_merge($mlog, check_php_configuraion($registry));
    $mlog = array_merge($mlog, check_server_configuration($registry));
    $counts['error_count'] = $counts['warning_count'] = $counts['notice_count'] = 0;
    foreach ($mlog as $message) {
        if ($message['type'] == 'E') {
            if ($mode == 'log') {
                //only save errors to the log
                $error = new AError($message['body']);
                $error->toLog()->toDebug();
                $registry->get('messages')->saveError($message['title'], $message['body']);
            }
            $counts['error_count']++;
        } else {
            if ($message['type'] == 'W') {
                if ($mode == 'log') {
                    $registry->get('messages')->saveWarning($message['title'], $message['body']);
                }
                $counts['warning_count']++;
            } else {
                if ($message['type'] == 'N') {
                    if ($mode == 'log') {
                        $registry->get('messages')->saveNotice($message['title'], $message['body']);
                    }
                    $counts['notice_count']++;
                }
            }
        }
    }
    return array($mlog, $counts);
}
示例#2
0
/**
 * SOAP request/response logging to a file
 */
function writeToLog($client)
{
    if (!($logfile = fopen(TRANSACTIONS_LOG_FILE, "a"))) {
        $error = new AError("Cannot open " . TRANSACTIONS_LOG_FILE . " file.\n");
        $error->toLog()->toMessages->toDebug();
        exit(1);
    }
    fwrite($logfile, sprintf("\r%s:- %s", date("D M j G:i:s T Y"), $client->__getLastRequest() . "\n\n" . $client->__getLastResponse()));
}
 /**
  * @param string $type
  */
 public function __construct($type)
 {
     $this->registry = Registry::getInstance();
     //NOTE: Storefront can not access all resource at once. Resource type required
     if ($type) {
         $this->type = $type;
         //get type details
         $this->_loadType();
     }
     if (!$this->type_id) {
         $message = "Error: Incorrect or missing resource type ";
         $error = new AError($message);
         $error->toLog()->toDebug();
     }
 }
示例#4
0
 public function addStatus($order_status_id, $status_text_id)
 {
     $order_status_id = (int) $order_status_id;
     //preformat text_id at first
     $status_text_id = preformatTextID($status_text_id);
     if (in_array($order_status_id, array_keys($this->statuses)) || in_array($status_text_id, $this->statuses)) {
         $error_text = 'Error: Cannot add new order status with id ' . $order_status_id . ' and text id ' . $status_text_id . ' into AOrderStatus class.';
         $e = new AError($error_text);
         $e->toLog()->toDebug();
         return false;
     }
     if (!$status_text_id) {
         $error_text = 'Error: Cannot add new order status with id ' . $order_status_id . ' and empty text id';
         $e = new AError($error_text);
         $e->toLog()->toDebug();
         return false;
     }
     $this->statuses[$order_status_id] = $status_text_id;
     return true;
 }
示例#5
0
 public function escape($value)
 {
     if (is_array($value)) {
         $dump = var_export($value, true);
         $backtrace = debug_backtrace();
         $dump .= ' (file: ' . $backtrace[1]['file'] . ' line ' . $backtrace[1]['line'] . ')';
         $message = 'aMySQLi class error: Try to escape non-string value: ' . $dump;
         $error = new AError($message);
         $error->toLog()->toDebug()->toMessages();
         return false;
     }
     $search = array("\\", "", "\n", "\r", "", "'", '"');
     $replace = array("\\\\", "\\0", "\\n", "\\r", "\\Z", "\\'", '\\"');
     return str_replace($search, $replace, $value);
 }
示例#6
0
function compressTarGZ($tar_filename, $tar_dir, $compress_level = 5)
{
    $compress_level = $compress_level < 1 || $compress_level > 9 ? 5 : $compress_level;
    $exit_code = 0;
    if (pathinfo($tar_filename, PATHINFO_EXTENSION) == 'gz') {
        $filename = rtrim($tar_filename, '.gz');
    } else {
        $filename = $tar_filename . '.tar.gz';
    }
    $tar = rtrim($tar_filename, '.gz');
    //remove archive if exists
    if (is_file($tar_filename)) {
        unlink($tar_filename);
    }
    if (is_file($filename)) {
        unlink($filename);
    }
    if (is_file($tar)) {
        unlink($tar);
    }
    if (class_exists('PharData')) {
        try {
            $a = new PharData($tar);
            $a->buildFromDirectory($tar_dir);
            // this code creates tar-file
            if (file_exists($tar)) {
                // remove tar-file after zipping
                gzip($tar, $compress_level);
                unlink($tar);
            }
        } catch (Exception $e) {
            $error = new AError($e->getMessage());
            $error->toLog()->toDebug();
            $exit_code = 1;
        }
    } else {
        $exit_code = 1;
    }
    if ($exit_code) {
        $registry = Registry::getInstance();
        $registry->get('load')->library('targz');
        $targz = new Atargz();
        return $targz->makeTar($tar_dir . $tar_filename, $filename, $compress_level);
    } else {
        return true;
    }
}
示例#7
0
}
//before install validate it is unique
$lng_code = 'es';
$lng_name = 'Español';
$lng_directory = 'spanish';
$lng_locale = 'es_ES.UTF-8,es_ES,spanish';
$lng_flag_path = 'extensions/default_spanish/storefront/language/spanish/flag.png';
$lng_sort = 2;
// sorting order with other langauges
$lng_status = 0;
// Status on installation of extension
$query = $this->db->query("SELECT language_id FROM " . $this->db->table('languages') . " WHERE code='" . $lng_code . "'");
if ($query->row['language_id']) {
    $this->session->data['error'] = "Error: Language with " . $lng_code . " code is already installed! Can not install duplicate languages! Uninstall this extension before attempting again.";
    $error = new AError($this->session->data['error']);
    $error->toLog()->toDebug();
    return false;
}
$this->db->query("INSERT INTO " . $this->db->table('languages') . " (`name`,`code`,`locale`,`image`,`directory`,`filename`,`sort_order`, `status`)\n\t\t\t\t  VALUES ('" . $lng_name . "', '" . $lng_code . "', '" . $lng_locale . "', '" . $lng_flag_path . "','" . $lng_directory . "','" . $lng_directory . "','" . $lng_sort . "'," . $lng_status . ");");
$new_language_id = $this->db->getLastId();
$xml = simplexml_load_file(DIR_EXT . 'default_spanish/menu.xml');
$routes = array('text_index_home_menu' => 'index/home', 'text_account_login_menu' => 'account/login', 'text_account_logout_menu' => 'account/logout', 'text_account_account_menu' => 'account/account', 'text_checkout_cart_menu' => 'checkout/cart', 'text_checkout_shipping_menu' => 'checkout/shipping');
if ($xml) {
    foreach ($xml->definition as $item) {
        $translates[$routes[(string) $item->key]] = (string) $item->value;
    }
    $storefront_menu = new AMenu_Storefront();
    $storefront_menu->addLanguage($new_language_id, $translates);
}
//Load core content
$this->db->query("INSERT INTO " . $this->db->table('country_descriptions') . "\n(`country_id`,`language_id`, `name`) VALUES  \n(1, " . $new_language_id . ",'Afganistán'),\n(2, " . $new_language_id . ",'Albania'),\n(3, " . $new_language_id . ",'Argelia'),\n(4, " . $new_language_id . ",'Samoa Americana'),\n(5, " . $new_language_id . ",'Andorra'),\n(6, " . $new_language_id . ",'Angola'),\n(7, " . $new_language_id . ",'Anguilla'),\n(8, " . $new_language_id . ",'Antártida'),\n(9, " . $new_language_id . ",'Antigua y Barbuda'),\n(10, " . $new_language_id . ",'Argentina'),\n(11, " . $new_language_id . ",'Armenia'),\n(12, " . $new_language_id . ",'Aruba'),\n(13, " . $new_language_id . ",'Australia'),\n(14, " . $new_language_id . ",'Austria'),\n(15, " . $new_language_id . ",'Azerbaiyán'),\n(16, " . $new_language_id . ",'Bahamas'),\n(17, " . $new_language_id . ",'Bahrein'),\n(18, " . $new_language_id . ",'Bangladesh'),\n(19, " . $new_language_id . ",'Barbados'),\n(20, " . $new_language_id . ",'Bielorrusia'),\n(21, " . $new_language_id . ",'Bélgica'),\n(22, " . $new_language_id . ",'Belice'),\n(23, " . $new_language_id . ",'Benin'),\n(24, " . $new_language_id . ",'Bermuda'),\n(25, " . $new_language_id . ",'Bhutan'),\n(26, " . $new_language_id . ",'Bolivia'),\n(27, " . $new_language_id . ",'Bosnia y Herzegovina'),\n(28, " . $new_language_id . ",'Botswana'),\n(29, " . $new_language_id . ",'Bouvet Island'),\n(30, " . $new_language_id . ",'Brasil'),\n(31, " . $new_language_id . ",'Territorio Británico del Océano Índico'),\n(32, " . $new_language_id . ",'Brunei Darussalam'),\n(33, " . $new_language_id . ",'Bulgaria'),\n(34, " . $new_language_id . ",'Burkina Faso'),\n(35, " . $new_language_id . ",'Burundi'),\n(36, " . $new_language_id . ",'Camboya'),\n(37, " . $new_language_id . ",'Camerún'),\n(38, " . $new_language_id . ",'Canadá'),\n(39, " . $new_language_id . ",'Cabo Verde'),\n(40, " . $new_language_id . ",'Islas Caimán'),\n(41, " . $new_language_id . ",'República Centroafricana'),\n(42, " . $new_language_id . ",'Chad'),\n(43, " . $new_language_id . ",'Chile'),\n(44, " . $new_language_id . ",'China'),\n(45, " . $new_language_id . ",'Isla de Navidad'),\n(46, " . $new_language_id . ",'Islas Cocos (Keeling)'),\n(47, " . $new_language_id . ",'Colombia'),\n(48, " . $new_language_id . ",'Comoras'),\n(49, " . $new_language_id . ",'Congo'),\n(50, " . $new_language_id . ",'Islas Cook'),\n(51, " . $new_language_id . ",'Costa Rica'),\n(52, " . $new_language_id . ",'Cote D&#39;Ivoire'),\n(53, " . $new_language_id . ",'Croacia'),\n(54, " . $new_language_id . ",'Cuba'),\n(55, " . $new_language_id . ",'Chipre'),\n(56, " . $new_language_id . ",'República Checa'),\n(57, " . $new_language_id . ",'Dinamarca'),\n(58, " . $new_language_id . ",'Djibouti'),\n(59, " . $new_language_id . ",'Dominica'),\n(60, " . $new_language_id . ",'República Dominicana'),\n(61, " . $new_language_id . ",'Timor del Este'),\n(62, " . $new_language_id . ",'Ecuador'),\n(63, " . $new_language_id . ",'Egipto'),\n(64, " . $new_language_id . ",'El Salvador'),\n(65, " . $new_language_id . ",'Guinea Ecuatorial'),\n(66, " . $new_language_id . ",'Eritrea'),\n(67, " . $new_language_id . ",'Estonia'),\n(68, " . $new_language_id . ",'Etiopía'),\n(69, " . $new_language_id . ",'Islas Malvinas (Falkland)'),\n(70, " . $new_language_id . ",'Islas Feroe'),\n(71, " . $new_language_id . ",'Fiji'),\n(72, " . $new_language_id . ",'Finlandia'),\n(73, " . $new_language_id . ",'Francia'),\n(74, " . $new_language_id . ",'France, Metropolitan'),\n(75, " . $new_language_id . ",'Guiana francés'),\n(76, " . $new_language_id . ",'Polinesia francés'),\n(77, " . $new_language_id . ",'Territorios Australes Franceses'),\n(78, " . $new_language_id . ",'Gabón'),\n(79, " . $new_language_id . ",'Gambia'),\n(80, " . $new_language_id . ",'Georgia'),\n(81, " . $new_language_id . ",'Alemania'),\n(82, " . $new_language_id . ",'Ghana'),\n(83, " . $new_language_id . ",'Gibraltar'),\n(84, " . $new_language_id . ",'Grecia'),\n(85, " . $new_language_id . ",'Groenlandia'),\n(86, " . $new_language_id . ",'Granada'),\n(87, " . $new_language_id . ",'Guadalupe'),\n(88, " . $new_language_id . ",'Guam'),\n(89, " . $new_language_id . ",'Guatemala'),\n(90, " . $new_language_id . ",'Guinea'),\n(91, " . $new_language_id . ",'Guinea-Bissau'),\n(92, " . $new_language_id . ",'Guayana'),\n(93, " . $new_language_id . ",'Haití'),\n(94, " . $new_language_id . ",'Heard y Mc Donald Islas'),\n(95, " . $new_language_id . ",'Honduras'),\n(96, " . $new_language_id . ",'Hong Kong'),\n(97, " . $new_language_id . ",'Hungría'),\n(98, " . $new_language_id . ",'Islandia'),\n(99, " . $new_language_id . ",'India'),\n(100, " . $new_language_id . ",'Indonesia'),\n(101, " . $new_language_id . ",'Irán (República Islámica del)'),\n(102, " . $new_language_id . ",'Irak'),\n(103, " . $new_language_id . ",'Irlanda'),\n(104, " . $new_language_id . ",'Israel'),\n(105, " . $new_language_id . ",'Italia'),\n(106, " . $new_language_id . ",'Jamaica'),\n(107, " . $new_language_id . ",'Japón'),\n(108, " . $new_language_id . ",'Jordania'),\n(109, " . $new_language_id . ",'Kazajstán'),\n(110, " . $new_language_id . ",'Kenia'),\n(111, " . $new_language_id . ",'Kiribati'),\n(112, " . $new_language_id . ",'Corea del Norte'),\n(113, " . $new_language_id . ",'Corea, República de'),\n(114, " . $new_language_id . ",'Kuwait'),\n(115, " . $new_language_id . ",'Kirguistán'),\n(116, " . $new_language_id . ",'República Democrática Popular Lao'),\n(117, " . $new_language_id . ",'Letonia'),\n(118, " . $new_language_id . ",'Líbano'),\n(119, " . $new_language_id . ",'Lesoto'),\n(120, " . $new_language_id . ",'Liberia'),\n(121, " . $new_language_id . ",'Jamahiriya Árabe Libia'),\n(122, " . $new_language_id . ",'Liechtenstein'),\n(123, " . $new_language_id . ",'Lituania'),\n(124, " . $new_language_id . ",'Luxemburgo'),\n(125, " . $new_language_id . ",'Macau'),\n(126, " . $new_language_id . ",'Macedonia'),\n(127, " . $new_language_id . ",'Madagascar'),\n(128, " . $new_language_id . ",'Malawi'),\n(129, " . $new_language_id . ",'Malasia'),\n(130, " . $new_language_id . ",'Maldivas'),\n(131, " . $new_language_id . ",'Malí'),\n(132, " . $new_language_id . ",'Malta'),\n(133, " . $new_language_id . ",'Islas Marshall'),\n(134, " . $new_language_id . ",'Martinica'),\n(135, " . $new_language_id . ",'Mauritania'),\n(136, " . $new_language_id . ",'Mauricio'),\n(137, " . $new_language_id . ",'Mayotte'),\n(138, " . $new_language_id . ",'México'),\n(139, " . $new_language_id . ",'Micronesia, Estados Federados de'),\n(140, " . $new_language_id . ",'Moldova, República de'),\n(141, " . $new_language_id . ",'Mónaco'),\n(142, " . $new_language_id . ",'Mongolia'),\n(143, " . $new_language_id . ",'Montserrat'),\n(144, " . $new_language_id . ",'Marruecos'),\n(145, " . $new_language_id . ",'Mozambique'),\n(146, " . $new_language_id . ",'Myanmar'),\n(147, " . $new_language_id . ",'Namibia'),\n(148, " . $new_language_id . ",'Nauru'),\n(149, " . $new_language_id . ",'Nepal'),\n(150, " . $new_language_id . ",'Países Bajos'),\n(151, " . $new_language_id . ",'Antillas Holandesas'),\n(152, " . $new_language_id . ",'Nueva Caledonia'),\n(153, " . $new_language_id . ",'Nueva Zelandia'),\n(154, " . $new_language_id . ",'Nicaragua'),\n(155, " . $new_language_id . ",'Níger'),\n(156, " . $new_language_id . ",'Nigeria'),\n(157, " . $new_language_id . ",'Niue'),\n(158, " . $new_language_id . ",'Isla Norfolk'),\n(159, " . $new_language_id . ",'Islas Marianas del Norte'),\n(160, " . $new_language_id . ",'Noruega'),\n(161, " . $new_language_id . ",'Omán'),\n(162, " . $new_language_id . ",'Pakistán'),\n(163, " . $new_language_id . ",'Palau'),\n(164, " . $new_language_id . ",'Panamá'),\n(165, " . $new_language_id . ",'Papua Nueva Guinea'),\n(166, " . $new_language_id . ",'Paraguay'),\n(167, " . $new_language_id . ",'Perú'),\n(168, " . $new_language_id . ",'Filipinas'),\n(169, " . $new_language_id . ",'Pitcairn'),\n(170, " . $new_language_id . ",'Polonia'),\n(171, " . $new_language_id . ",'Portugal'),\n(172, " . $new_language_id . ",'Puerto Rico'),\n(173, " . $new_language_id . ",'Katar'),\n(174, " . $new_language_id . ",'Reunión'),\n(175, " . $new_language_id . ",'Rumania'),\n(176, " . $new_language_id . ",'Rusia'),\n(177, " . $new_language_id . ",'Ruanda'),\n(178, " . $new_language_id . ",'Saint Kitts y Nevis'),\n(179, " . $new_language_id . ",'Santa Lucía'),\n(180, " . $new_language_id . ",'San Vicente y las Granadinas'),\n(181, " . $new_language_id . ",'Samoa'),\n(182, " . $new_language_id . ",'San Marino'),\n(183, " . $new_language_id . ",'Santo Tomé y Príncipe'),\n(184, " . $new_language_id . ",'Arabia Saudita'),\n(185, " . $new_language_id . ",'Senegal'),\n(186, " . $new_language_id . ",'Seychelles'),\n(187, " . $new_language_id . ",'Sierra Leona'),\n(188, " . $new_language_id . ",'Singapur'),\n(189, " . $new_language_id . ",'República Eslovaca'),\n(190, " . $new_language_id . ",'Eslovenia'),\n(191, " . $new_language_id . ",'Islas Salomón'),\n(192, " . $new_language_id . ",'Somalia'),\n(193, " . $new_language_id . ",'Sudáfrica'),\n(194, " . $new_language_id . ",'Georgia del Sur y Sandwich del Sur Islas'),\n(195, " . $new_language_id . ",'España'),\n(196, " . $new_language_id . ",'Sri Lanka'),\n(197, " . $new_language_id . ",'St. Helena'),\n(198, " . $new_language_id . ",'San Pedro y Miquelón'),\n(199, " . $new_language_id . ",'Sudán'),\n(200, " . $new_language_id . ",'Suriname'),\n(201, " . $new_language_id . ",'Svalbard y Jan Mayen'),\n(202, " . $new_language_id . ",'Swazilandia'),\n(203, " . $new_language_id . ",'Suecia'),\n(204, " . $new_language_id . ",'Suiza'),\n(205, " . $new_language_id . ",'República Árabe Siria'),\n(206, " . $new_language_id . ",'Taiwan'),\n(207, " . $new_language_id . ",'Tayikistán'),\n(208, " . $new_language_id . ",'Tanzania, República Unida de'),\n(209, " . $new_language_id . ",'Tailandia'),\n(210, " . $new_language_id . ",'Togo'),\n(211, " . $new_language_id . ",'Tokelau'),\n(212, " . $new_language_id . ",'Tonga'),\n(213, " . $new_language_id . ",'Trinidad y Tobago'),\n(214, " . $new_language_id . ",'Túnez'),\n(215, " . $new_language_id . ",'Turquía'),\n(216, " . $new_language_id . ",'Turkmenistán'),\n(217, " . $new_language_id . ",'Turcas y Caicos'),\n(218, " . $new_language_id . ",'Tuvalu'),\n(219, " . $new_language_id . ",'Uganda'),\n(220, " . $new_language_id . ",'Ucrania'),\n(221, " . $new_language_id . ",'Emiratos Árabes Unidos'),\n(222, " . $new_language_id . ",'Reino Unido'),\n(223, " . $new_language_id . ",'Estados Unidos'),\n(224, " . $new_language_id . ",'Estados Unidos Islas menores alejadas de los'),\n(225, " . $new_language_id . ",'Uruguay'),\n(226, " . $new_language_id . ",'Uzbekistán'),\n(227, " . $new_language_id . ",'Vanuatu'),\n(228, " . $new_language_id . ",'Ciudad del Vaticano (Santa Sede)'),\n(229, " . $new_language_id . ",'Venezuela'),\n(230, " . $new_language_id . ",'Viet Nam'),\n(231, " . $new_language_id . ",'Islas Vírgenes (Británicas)'),\n(232, " . $new_language_id . ",'Islas Vírgenes (EE.UU.)'),\n(233, " . $new_language_id . ",'Islas Wallis y Futuna'),\n(234, " . $new_language_id . ",'Sáhara Occidental'),\n(235, " . $new_language_id . ",'Yemen'),\n(236, " . $new_language_id . ",'Yugoslavia'),\n(237, " . $new_language_id . ",'Zaire'),\n(238, " . $new_language_id . ",'Zambia'),\n(239, " . $new_language_id . ",'Zimbabue'),\n(240, " . $new_language_id . ",'Irlanda del Norte');\n");
示例#8
0
/**
 * @param Registry $registry
 * @param string $mode
 * @return array
 */
function run_critical_system_check($registry, $mode = 'log')
{
    $mlog = array();
    $mlog[] = check_session_save_path();
    $output = array();
    foreach ($mlog as $message) {
        if ($message['body']) {
            if ($mode == 'log') {
                //only save errors to the log
                $error = new AError($message['body']);
                $error->toLog()->toDebug();
                $registry->get('messages')->saveError($message['title'], $message['body']);
            }
            $output[] = $message;
        }
    }
    return $output;
}
示例#9
0
 /**
  * @param array $tables - tables list
  * @param string $dump_file - path of file with sql dump
  * @return bool|string - path of dump file or false
  */
 public function dumpTables($tables = array(), $dump_file = '')
 {
     if (!$tables || !is_array($tables) || !$this->backup_dir) {
         $error_text = 'Error: Cannot to dump of tables during sql-dumping. Empty table list or unknown destination folder.';
         $error = new AError($error_text);
         $error->toLog()->toDebug();
         return false;
     }
     foreach ($tables as $table) {
         if (!is_string($table)) {
             continue;
         }
         // clean
         $table_list[] = $this->db->escape($table);
     }
     $driver = DB_DRIVER;
     /**
      * @var $db AMySQLi
      */
     $db = new $driver(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
     // use driver directly to exclude hooks calls
     $prefix_len = strlen(DB_PREFIX);
     // get sizes of tables
     $sql = "SELECT TABLE_NAME AS 'table_name',\n\t\t\t\t\ttable_rows AS 'num_rows', (data_length + index_length - data_free) AS 'size'\n\t\t\t\tFROM information_schema.TABLES\n\t\t\t\tWHERE information_schema.TABLES.table_schema = '" . DB_DATABASE . "'\n\t\t\t\t\tAND TABLE_NAME IN ('" . implode("','", $table_list) . "')\t";
     if ($prefix_len) {
         $sql .= " AND TABLE_NAME like '" . DB_PREFIX . "%'";
     }
     $result = $this->db->query($sql);
     $memory_limit = (getMemoryLimitInBytes() - memory_get_usage()) / 4;
     // sql-file for small tables
     $dump_file = $this->backup_dir . 'data/dump_' . DB_DATABASE . '_' . date('Y-m-d-His') . '.sql';
     $file = fopen($dump_file, 'w');
     if (!$file) {
         $error_text = 'Error: Cannot create file as "' . $dump_file . '" during sql-dumping. Check is it writable.';
         $error = new AError($error_text);
         $error->toLog()->toDebug();
         return false;
     }
     foreach ($result->rows as $table_info) {
         $table_name = $table_info['table_name'];
         if ($this->sql_dump_mode == 'data_only') {
             fwrite($file, "TRUNCATE TABLE `" . $table_name . "`;\n\n");
         } elseif ($this->sql_dump_mode == 'recreate') {
             $sql = "SHOW CREATE TABLE `" . $table_name . "`;";
             $r = $db->query($sql);
             $ddl = $r->row['Create Table'];
             fwrite($file, "DROP TABLE IF EXISTS `" . $table_name . "`;\n\n");
             fwrite($file, $ddl . "\n\n");
         }
         //then try to get table data by pagination.
         // to split data by pages use range of values of column that have PRIMARY KEY. NOT LIMIT-OFFSET!!!
         // 1. - get column name with primary key and data type integer
         $sql = "SELECT COLUMN_NAME\n\t\t\t\t\tFROM information_schema.COLUMNS c\n\t\t\t\t\tWHERE c.`TABLE_SCHEMA` = '" . DB_DATABASE . "'\n\t\t\t\t\t\tAND c.`TABLE_NAME` = '" . $table_name . "'\n\t\t\t\t\t\tAND c.`COLUMN_KEY` = 'PRI'\n\t\t\t\t\t    AND c.`DATA_TYPE`='int'\n\t\t\t\t\tLIMIT 0,1;";
         $r = $db->query($sql);
         $column_name = $r->row['COLUMN_NAME'];
         $small_table = false;
         if ($column_name) {
             $sql = "SELECT MAX(`" . $column_name . "`) as max, MIN(`" . $column_name . "`) as min\n\t\t\t\t\t\tFROM `" . $table_name . "`";
             $r = $db->query($sql);
             $column_max = $r->row['max'];
             $column_min = $r->row['min'];
         } else {
             // if table have no PRIMARY KEY - try to dump it by one pass
             $column_max = $table_info['num_rows'];
             $start = $stop = $column_min = 0;
             $small_table = true;
         }
         unset($r);
         // for tables greater than $memory_limit (for ex. if php memory limit 64mb $memory_limit equal 10mb)
         if ($table_info['size'] > $memory_limit && !$small_table) {
             // for tables greater than 20 MB
             //max allowed rows count for safe fetching
             $limit = 10000;
             //break export aparts to prevent memory overflow
             $start = $column_min;
             $stop = $column_min + $limit;
             $small_table = false;
         } else {
             // for small table get data by one pass
             $column_max = $limit = $table_info['num_rows'];
             $start = $stop = $column_min = 0;
             $small_table = true;
         }
         while ($start < $column_max) {
             if (!$small_table) {
                 $sql = "SELECT *\n\t\t\t\t\t\t FROM `" . $table_name . "`\n\t\t\t\t\t\t WHERE `" . $column_name . "` >= '" . $start . "' AND `" . $column_name . "`< '" . $stop . "'";
             } else {
                 $sql = "SELECT * FROM `" . $table_name . "`";
             }
             // dump data with using "INSERT"
             $r = $db->query($sql, true);
             foreach ($r->rows as $row) {
                 $fields = '';
                 $arr_keys = array_keys($row);
                 foreach ($arr_keys as $value) {
                     $fields .= '`' . $value . '`, ';
                 }
                 $values = '';
                 foreach ($row as $value) {
                     $value = str_replace(array("", "\n", "\r", ""), array('\\0', '\\n', '\\r', '\\Z'), $value);
                     $value = str_replace(array("\n", "\r", "\t"), array('\\n', '\\r', '\\t'), $value);
                     $value = str_replace('\\', '\\\\', $value);
                     $value = str_replace('\'', '\\\'', $value);
                     $value = str_replace('\\\\n', '\\n', $value);
                     $value = str_replace('\\\\r', '\\r', $value);
                     $value = str_replace('\\\\t', '\\t', $value);
                     $values .= '\'' . $value . '\', ';
                 }
                 fwrite($file, 'INSERT INTO `' . $table_name . '` (' . preg_replace('/, $/', '', $fields) . ') VALUES (' . preg_replace('/, $/', '', $values) . ');' . "\n");
             }
             unset($r, $sql);
             $start += $limit;
             $stop += $limit;
             if ($small_table) {
                 break;
             }
         }
     }
     fwrite($file, "\n\n");
     fclose($file);
     chmod($dump_file, 0644);
     return $dump_file;
 }
示例#10
0
 /**
 * @param string $sendpoint 
 * @param array $msg_details
 * @return null
 
 	$msg_details structure:
 	array(
 		0 => array(
 			message => 'text',
 		)
 		1 => array(
 			message => 'text',
 		)
 	);
 	0 - storefront (customer) and 1 - Admin (user)
 	notes: If message is not provided, message text will be takes from languages based on checkpoint text key.  
 */
 public function send($sendpoint, $msg_details = array())
 {
     $this->load->language('common/im');
     $customer_im_settings = array();
     if (IS_ADMIN !== true) {
         $sendpoints_list = $this->sendpoints;
         //do have storefront sendpoint?
         if (!empty($sendpoints_list[$sendpoint][0])) {
             $this->load->model('account/customer');
             $customer_im_settings = $this->getCustomerNotificationSettings();
         }
         $this->registry->set('force_skip_errors', true);
     } else {
         $sendpoints_list = $this->admin_sendpoints;
         //this method forbid sending notifications to customers from admin-side
         $customer_im_settings = array();
     }
     //check sendpoint
     if (!in_array($sendpoint, array_keys($sendpoints_list))) {
         $error = new AError('IM error: Unrecognized SendPoint ' . $sendpoint . '. Nothing sent.');
         $error->toLog()->toMessages();
         return false;
     }
     $sendpoint_data = $sendpoints_list[$sendpoint];
     foreach ($this->protocols as $protocol) {
         $driver = null;
         //check protocol status
         if ($protocol == 'email') {
             //email notifications always enabled
             $protocol_status = 1;
         } else {
             if ((int) $this->config->get('config_storefront_' . $protocol . '_status') || (int) $this->config->get('config_admin_' . $protocol . '_status')) {
                 $protocol_status = 1;
             } else {
                 $protocol_status = 0;
             }
         }
         if (!$protocol_status) {
             continue;
         }
         if ($protocol == 'email') {
             //see AMailAIM class below
             $driver = new AMailIM();
         } else {
             $driver_txt_id = $this->config->get('config_' . $protocol . '_driver');
             //if driver not set - skip protocol
             if (!$driver_txt_id) {
                 continue;
             }
             if (!$this->config->get($driver_txt_id . '_status')) {
                 $error = new AError('Cannot send notification. Communication driver ' . $driver_txt_id . ' is disabled!');
                 $error->toLog()->toMessages();
                 continue;
             }
             //use safe usage
             $driver_file = DIR_EXT . $driver_txt_id . '/core/lib/' . $driver_txt_id . '.php';
             if (!is_file($driver_file)) {
                 $error = new AError('Cannot find file ' . $driver_file . ' to send notification.');
                 $error->toLog()->toMessages();
                 continue;
             }
             try {
                 /** @noinspection PhpIncludeInspection */
                 include_once $driver_file;
                 //if class of driver
                 $classname = preg_replace('/[^a-zA-Z]/', '', $driver_txt_id);
                 if (!class_exists($classname)) {
                     $error = new AError('IM-driver ' . $driver_txt_id . ' load error.');
                     $error->toLog()->toMessages();
                     continue;
                 }
                 $driver = new $classname();
             } catch (Exception $e) {
             }
         }
         //if driver cannot be initialized - skip protocol
         if ($driver === null) {
             continue;
         }
         $store_name = $this->config->get('store_name') . ": ";
         if (!empty($sendpoint_data[0])) {
             //send notification to customer, check if selected or forced
             $force_arr = $sendpoint_data[0]['force_send'];
             $forced = false;
             if (has_value($force_arr) && in_array($protocol, $force_arr)) {
                 $forced = true;
             }
             if ($customer_im_settings[$sendpoint][$protocol] || $forced) {
                 $message = $msg_details[0]['message'];
                 //check if notification for this protocol and sendpoint are allowed
                 if ($this->config->get('config_storefront_' . $protocol . '_status') || $protocol == 'email') {
                     if (empty($message)) {
                         //send default message. Not recommended
                         $message = $this->language->get($sendpoint_data[0]['text_key']);
                     }
                     $message = $this->_process_message_text($message);
                     $to = $this->_get_customer_im_uri($protocol);
                     if ($message && $to) {
                         //use safe call
                         try {
                             $driver->send($to, $store_name . $message);
                         } catch (Exception $e) {
                         }
                     }
                 }
             }
         }
         if (!empty($sendpoint_data[1])) {
             //send notification to admins
             if ($this->config->get('config_admin_' . $protocol . '_status') || $protocol == 'email') {
                 $message = $msg_details[1]['message'];
                 if (empty($message)) {
                     //send default message. Not recommended
                     $message = $this->language->get($sendpoint_data[1]['text_key']);
                 }
                 $message = $this->_process_message_text($message, true);
                 //NOTE! all admins will receive IMs
                 $to = $this->_get_admin_im_uri($sendpoint, $protocol);
                 if ($message && $to) {
                     //use safe call
                     try {
                         $driver->sendFew($to, $store_name . $message);
                     } catch (Exception $e) {
                     }
                 }
             }
         }
         unset($driver);
     }
     $this->registry->set('force_skip_errors', false);
     return true;
 }
示例#11
0
 /**
  * upload resources to directory with type name (example: image)
  *
  * @param array $resource
  * @return int resource id
  */
 public function addResource($resource)
 {
     if (!$this->type_id) {
         $message = "Error: Incorrect or missing resource type. Please set type using setType() method ";
         $error = new AError($message);
         $error->toLog()->toDebug();
         return false;
     }
     $sql = "INSERT INTO " . DB_PREFIX . "resource_library\n                    SET type_id = '" . $this->type_id . "',\n                        created = NOW()";
     $this->db->query($sql);
     $resource_id = $this->db->getLastId();
     if (!empty($resource['resource_path'])) {
         $resource_path = $this->getHexPath($resource_id) . strtolower(substr(strrchr($resource['resource_path'], '.'), 0));
         $resource_dir = dirname($resource_path);
         if (!is_dir(DIR_RESOURCE . $this->type_dir . $resource_dir)) {
             $path = '';
             $directories = explode('/', $resource_dir);
             foreach ($directories as $directory) {
                 $path = $path . '/' . $directory;
                 if (!is_dir(DIR_RESOURCE . $this->type_dir . $path)) {
                     @mkdir(DIR_RESOURCE . $this->type_dir . $path, 0777);
                     chmod(DIR_RESOURCE . $this->type_dir . $path, 0777);
                 }
             }
         }
         if (is_file(DIR_RESOURCE . $this->type_dir . $resource_path)) {
             unlink(DIR_RESOURCE . $this->type_dir . $resource_path);
         }
         if (!rename(DIR_RESOURCE . $this->type_dir . $resource['resource_path'], DIR_RESOURCE . $this->type_dir . $resource_path)) {
             $message = "Error: Cannot move resource to resources directory.";
             $error = new AError($message);
             $error->toLog()->toDebug();
             return false;
         }
     } else {
         $resource_path = '';
     }
     foreach ($resource['name'] as $language_id => $name) {
         if ($this->config->get('translate_override_existing') && $language_id != $resource['language_id']) {
             continue;
         }
         $this->language->replaceDescriptions('resource_descriptions', array('resource_id' => (int) $resource_id), array((int) $language_id => array('name' => $resource['name'][$language_id], 'title' => $resource['title'][$language_id], 'description' => $resource['description'][$language_id], 'resource_path' => $resource_path, 'resource_code' => $resource['resource_code'], 'created' => date('Y-m-d H:i:s'))));
     }
     $this->cache->delete('resources.' . $this->type);
     return $resource_id;
 }
 public function agreement()
 {
     $package_info =& $this->session->data['package_info'];
     // if we got decision
     if ($this->request->is_POST()) {
         // if does not agree  with agreement of filesize
         if ($this->request->post['disagree'] == 1) {
             $this->_removeTempFiles();
             unset($this->session->data['package_info']);
             $this->redirect($this->html->getSecureURL('extension/extensions/extensions'));
         } elseif ($this->request->post['agree_incompatibility']) {
             $package_info['confirm_version_incompatibility'] = true;
             $this->redirect($this->html->getSecureURL('tool/package_installer/agreement'));
         } elseif ($this->request->post['agree']) {
             $this->redirect($this->html->getSecureURL('tool/package_installer/install'));
         } elseif (!$this->request->post['agree'] && !isset($this->request->post['ftp_user'])) {
             $this->_removeTempFiles('dir');
             $this->redirect($this->_get_begin_href());
         }
     }
     $this->loadLanguage('tool/package_installer');
     $package_name = $package_info['package_name'];
     if (!$package_name) {
         // if direct link - redirect to the begining
         $this->redirect($this->_get_begin_href());
     }
     $pmanager = new APackageManager();
     //unpack package
     // if package not unpacked - redirect to the begin and show error message
     if (!is_dir($package_info['tmp_dir'] . $package_info['extension_key'])) {
         mkdir($package_info['tmp_dir'] . $package_info['extension_key'], 0777);
     }
     if (!$pmanager->unpack($package_info['tmp_dir'] . $package_name, $package_info['tmp_dir'] . $package_info['extension_key'] . '/')) {
         $this->session->data['error'] = str_replace('%PACKAGE%', $package_info['tmp_dir'] . $package_name, $this->language->get('error_unpack'));
         $error = new AError($pmanager->error);
         $error->toLog()->toDebug();
         $this->redirect($this->_get_begin_href());
     }
     $package_dirname = $package_info['package_dir'] = $this->_find_package_dir();
     if (!$package_info['package_dir']) {
         $error = 'Error: Cannot to find package directory after unpacking archive. ';
         $error = new AError($error);
         $error->toLog()->toDebug();
     }
     if (!file_exists($package_info['tmp_dir'] . $package_dirname)) {
         $this->session->data['error'] = $this->html->convertLinks(sprintf($this->language->get('error_pack_file_not_found'), $package_info['tmp_dir'] . $package_dirname));
         $this->redirect($this->_get_begin_href());
     }
     // so.. we need to know about install mode of this package
     /**
      * @var DOMNode $config
      */
     $config = simplexml_load_string(file_get_contents($package_info['tmp_dir'] . $package_dirname . '/package.xml'));
     if (!$config) {
         $this->session->data['error'] = $this->html->convertLinks($this->language->get('error_package_config_xml'));
         $this->_removeTempFiles();
         $this->redirect($this->_get_begin_href());
     }
     $package_info['package_id'] = (string) $config->id;
     $package_info['package_type'] = (string) $config->type;
     $package_info['package_priority'] = (string) $config->priority;
     $package_info['package_version'] = (string) $config->version;
     $package_info['package_content'] = '';
     if ((string) $config->package_content->extensions) {
         foreach ($config->package_content->extensions->extension as $item) {
             if ((string) $item) {
                 $package_info['package_content']['extensions'][] = (string) $item;
             }
         }
         $package_info['package_content']['total'] = sizeof($package_info['package_content']['extensions']);
     }
     if ((string) $config->package_content->core) {
         foreach ($config->package_content->core->files->file as $item) {
             if ((string) $item) {
                 $package_info['package_content']['core'][] = (string) $item;
             }
         }
     }
     if (!$package_info['package_content'] || $package_info['package_content']['core'] && $package_info['package_content']['extensions']) {
         $this->session->data['error'] = $this->language->get('error_package_structure');
         $this->_removeTempFiles();
         $this->redirect($this->_get_begin_href());
     }
     //check cart version compability
     if (!isset($package_info['confirm_version_incompatibility'])) {
         if (!$this->_check_cart_version($config)) {
             if ($this->_isCorePackage()) {
                 $this->session->data['error'] = $this->language->get('error_package_version_compatibility');
                 $this->redirect($this->html->getSecureURL('tool/package_installer'));
             } else {
                 $this->redirect($this->html->getSecureURL('tool/package_installer/agreement'));
             }
         }
     }
     // if we were redirected
     if ($this->request->is_GET()) {
         //check  write permissions
         // find directory from app_root_dir
         $non_writables = array();
         if ($package_info['package_content']['extensions']) {
             $dst_dirs = $pmanager->getDestinationDirectories();
             $ftp_mode = false;
             // if even one destination directory is not writable - use ftp mode
             if (!is_writable(DIR_EXT)) {
                 $non_writables[] = DIR_EXT;
             }
             if ($dst_dirs) {
                 foreach ($dst_dirs as $dir) {
                     if (!is_writable(DIR_ROOT . '/' . $dir) && file_exists(DIR_ROOT . '/' . $dir)) {
                         // enable ftp-mode
                         $ftp_mode = true;
                         $non_writables[] = DIR_ROOT . '/' . $dir;
                     }
                 }
             }
         } else {
             foreach ($package_info['package_content']['core'] as $corefile) {
                 $corefile_dir = pathinfo(DIR_ROOT . '/' . $corefile, PATHINFO_DIRNAME);
                 if (!is_writable(DIR_ROOT . '/' . $corefile) && file_exists(DIR_ROOT . '/' . $corefile)) {
                     // enable ftp-mode
                     $ftp_mode = true;
                     $non_writables[] = DIR_ROOT . '/' . $corefile;
                 } else {
                     if (!is_writable($corefile_dir) && is_dir($corefile_dir)) {
                         // enable ftp-mode
                         $ftp_mode = true;
                         $non_writables[] = $corefile_dir;
                     } else {
                         if (!is_writable($corefile_dir) && !is_dir($corefile_dir)) {
                             //detect non-writable parent directory
                             $dir_part = explode('/', $corefile_dir);
                             $d = '';
                             while (!is_dir($d)) {
                                 array_pop($dir_part);
                                 $d = implode('/', $dir_part);
                                 if (is_dir($d) && !is_writable($d)) {
                                     // enable ftp-mode
                                     $ftp_mode = true;
                                     $non_writables[] = $d;
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $non_writables = array_unique($non_writables);
     }
     // if ftp mode and user give ftp parameters
     if (isset($this->request->post['ftp_user']) && $this->request->is_POST()) {
         $ftp_user = $this->request->post['ftp_user'];
         $ftp_password = $this->request->post['ftp_password'];
         $ftp_host = $this->request->post['ftp_host'];
         //let's try to connect
         if (!$pmanager->checkFTP($ftp_user, $ftp_password, $ftp_host)) {
             $this->session->data['error'] = $pmanager->error;
             $this->redirect($this->html->getSecureURL('tool/package_installer/agreement'));
         }
         // sign of ftp-form
         $ftp_mode = false;
         $this->redirect($this->html->getSecureURL('tool/package_installer/install'));
     } else {
         if (!$package_info['tmp_dir']) {
             $package_info['tmp_dir'] = $this->_get_temp_dir();
         }
     }
     // if all fine show license agreement
     if (!file_exists($package_info['tmp_dir'] . $package_dirname . "/license.txt") && !$ftp_mode) {
         $this->redirect($this->html->getSecureURL('tool/package_installer/install'));
     }
     $this->data['license_text'] = '';
     $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('tool/package_installer'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: ', 'current' => true));
     if (isset($this->session->data['error'])) {
         $this->data['error_warning'] = $this->session->data['error'];
         unset($this->session->data['error']);
     }
     $form = new AForm('ST');
     $form->setForm(array('form_name' => 'Frm'));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'Frm', 'action' => $this->html->getSecureURL('tool/package_installer/agreement'), 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"'));
     //version incompatibility confirmation
     if (isset($package_info['confirm_version_incompatibility']) && !$package_info['confirm_version_incompatibility']) {
         $this->data['agreement_text'] = $package_info['version_incompatibility_text'];
         $this->data['form']['disagree_button'] = $form->getFieldHtml(array('type' => 'button', 'href' => $this->_get_begin_href(), 'text' => $this->language->get('text_interrupt')));
         $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'text' => $this->language->get('text_continue')));
         $this->data['form']['agree'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'agree_incompatibility', 'value' => '0'));
         $template = 'pages/tool/package_installer_agreement.tpl';
     } elseif ($ftp_mode) {
         $template = 'pages/tool/package_installer_ftp_form.tpl';
         $ftp_user = $package_info['ftp_user'] ? $package_info['ftp_user'] : '';
         $ftp_host = $package_info['ftp_host'] ? $package_info['ftp_host'] : '';
         $this->data['form']['fuser'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'ftp_user', 'value' => $ftp_user, 'require' => true, 'help_url' => $this->gen_help_url('ftp_user'), 'style' => 'medium-field'));
         $this->data['form']['fpass'] = $form->getFieldHtml(array('type' => 'password', 'name' => 'ftp_password', 'require' => true, 'value' => '', 'style' => 'medium-field'));
         $this->data['form']['fhost'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'ftp_host', 'value' => $ftp_host, 'help_url' => $this->gen_help_url('ftp_host'), 'style' => 'medium-field'));
         $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'text' => $this->language->get('text_continue')));
         $this->data['fuser'] = $this->language->get('text_ftp_user');
         $this->data['fpass'] = $this->language->get('text_ftp_password');
         $this->data['fhost'] = $this->language->get('text_ftp_host');
         $this->data['heading_title'] = $this->language->get('heading_title_ftp');
         $this->data['warning_ftp'] = $this->language->get('warning_ftp');
         $this->data['warning_ftp_details'] = 'Need write permission for:<br><ul><li>' . implode('</li><li>', $non_writables) . "</li></ul>";
     } else {
         if (file_exists($package_info['tmp_dir'] . $package_dirname . "/license.txt")) {
             $this->data['agreement_text'] = file_get_contents($package_info['tmp_dir'] . $package_dirname . "/license.txt");
         }
         $this->data['agreement_text'] = htmlentities($this->data['agreement_text'], ENT_QUOTES, 'UTF-8');
         $this->data['agreement_text'] = nl2br($this->data['agreement_text']);
         $template = 'pages/tool/package_installer_agreement.tpl';
         $this->data['form']['agree'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'agree', 'value' => '0'));
         $this->data['text_agree'] = $this->language->get('text_i_agree');
         $this->data['form']['disagree_button'] = $form->getFieldHtml(array('type' => 'button', 'href' => $this->_get_begin_href(), 'text' => $this->language->get('text_disagree')));
         $this->data['heading_title'] = $this->language->get('heading_title_license');
         $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'text' => $this->language->get('text_agree')));
     }
     $this->view->batchAssign($this->data);
     $this->processTemplate($template);
 }
示例#13
0
 private function _send_sms($phone, $data)
 {
     if (!$phone || !$data) {
         $error = new AError('Error: Cannot send sms. Unknown phone number or empty message.');
         $error->toLog()->toMessages();
         return false;
     }
     $driver = null;
     $driver_txt_id = $this->config->get('config_sms_driver');
     //if driver not set - skip protocol
     if (!$driver_txt_id) {
         return false;
     }
     //use safe usage
     try {
         include_once DIR_EXT . $driver_txt_id . '/core/lib/' . $driver_txt_id . '.php';
         //if class of driver
         $classname = preg_replace('/[^a-zA-Z]/', '', $driver_txt_id);
         if (!class_exists($classname)) {
             $error = new AError('IM-driver ' . $driver_txt_id . ' load error.');
             $error->toLog()->toMessages();
             return false;
         }
         $driver = new $classname();
     } catch (AException $e) {
     }
     if ($driver === null) {
         return false;
     }
     $text = $this->config->get('store_name') . ": " . $data['message'];
     $to = $phone;
     $result = true;
     if ($text && $to) {
         //use safe call
         try {
             $result = $driver->send($to, $text);
         } catch (AException $e) {
             return false;
         }
     }
     return $result;
 }
示例#14
0
/**
 * Function returns image dimensions
 * @param $filename
 * @return array|bool
 */
function get_image_size($filename)
{
    if (file_exists($filename) && ($info = getimagesize($filename))) {
        return array('width' => $info[0], 'height' => $info[1], 'mime' => $info['mime']);
    }
    if ($filename) {
        $error = new AError('Error: Cannot get image size of file ' . $filename . '. File not found or it\'s not an image!');
        $error->toLog()->toMessages()->toDebug();
    }
    return array();
}
示例#15
0
 public function send()
 {
     if (!$this->config->get('default_pp_pro_test')) {
         $api_endpoint = 'https://api-3t.paypal.com/nvp';
     } else {
         $api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
     }
     if (!$this->config->get('default_pp_pro_transaction')) {
         $payment_type = 'Authorization';
     } else {
         $payment_type = 'Sale';
     }
     $this->load->model('checkout/order');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $order_total = $this->currency->format($order_info['total'], $order_info['currency'], '', false);
     $products_data = $this->_get_products_data(array('currency' => $order_info['currency'], 'value' => '', 'order_total' => $order_total));
     $payment_data = array('METHOD' => 'DoDirectPayment', 'VERSION' => '51.0', 'USER' => html_entity_decode($this->config->get('default_pp_pro_username'), ENT_QUOTES, 'UTF-8'), 'PWD' => html_entity_decode($this->config->get('default_pp_pro_password'), ENT_QUOTES, 'UTF-8'), 'SIGNATURE' => html_entity_decode($this->config->get('default_pp_pro_signature'), ENT_QUOTES, 'UTF-8'), 'CUSTREF' => $order_info['order_id'], 'CUSTOM' => $order_info['order_id'], 'INVNUM' => '#' . $order_info['order_id'], 'PAYMENTACTION' => $payment_type, 'AMT' => $this->currency->format($order_info['total'], $order_info['currency'], $order_info['value'], FALSE), 'ITEMAMT' => (double) $this->data['items_total'], 'TAXAMT' => (double) $this->data['tax_total'], 'SHIPPINGAMT' => (double) $this->data['shipping_total'], 'HANDLINGAMT' => (double) $this->data['handling_total'], 'CREDITCARDTYPE' => $this->request->post['cc_type'], 'ACCT' => str_replace(' ', '', $this->request->post['cc_number']), 'CARDSTART' => $this->request->post['cc_start_date_month'] . $this->request->post['cc_start_date_year'], 'EXPDATE' => $this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year'], 'CVV2' => $this->request->post['cc_cvv2'], 'CARDISSUE' => $this->request->post['cc_issue'], 'FIRSTNAME' => $order_info['payment_firstname'], 'LASTNAME' => $order_info['payment_lastname'], 'EMAIL' => $order_info['email'], 'PHONENUM' => $order_info['telephone'], 'IPADDRESS' => $this->request->server['REMOTE_ADDR'], 'STREET' => $order_info['payment_address_1'], 'CITY' => $order_info['payment_city'], 'STATE' => $order_info['payment_iso_code_2'] != 'US' ? $order_info['payment_zone'] : $order_info['payment_zone_code'], 'ZIP' => $order_info['payment_postcode'], 'COUNTRYCODE' => $order_info['payment_iso_code_2'], 'CURRENCYCODE' => $order_info['currency'], 'BUTTONSOURCE' => 'Abante_Cart', 'NOTIFYURL' => $this->html->getSecureURL('extension/default_pp_pro/callback'));
     if ($this->cart->hasShipping()) {
         $payment_data = array_merge($payment_data, array('SHIPTONAME' => $order_info['shipping_firstname'] . ' ' . $order_info['shipping_lastname'], 'SHIPTOSTREET' => $order_info['shipping_address_1'], 'SHIPTOCITY' => $order_info['shipping_city'], 'SHIPTOSTATE' => $order_info['shipping_iso_code_2'] != 'US' ? $order_info['shipping_zone'] : $order_info['shipping_zone_code'], 'SHIPTOCOUNTRYCODE' => $order_info['shipping_iso_code_2'], 'SHIPTOZIP' => $order_info['shipping_postcode']));
     } else {
         $payment_data = array_merge($payment_data, array('SHIPTONAME' => $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'], 'SHIPTOSTREET' => $order_info['payment_address_1'], 'SHIPTOCITY' => $order_info['payment_city'], 'SHIPTOSTATE' => $order_info['payment_iso_code_2'] != 'US' ? $order_info['payment_zone'] : $order_info['payment_zone_code'], 'SHIPTOCOUNTRYCODE' => $order_info['payment_iso_code_2'], 'SHIPTOZIP' => $order_info['payment_postcode']));
     }
     //items list
     //check amounts
     $calc_total = $this->data['items_total'] + $this->data['shipping_total'] + $this->data['tax_total'] + $this->data['handling_total'];
     if ($calc_total - $order_total !== 0.0) {
         $skip_item_list = true;
         $payment_data['ITEMAMT'] = 0;
         $payment_data['TAXAMT'] = 0;
         $payment_data['SHIPPINGAMT'] = 0;
         $payment_data['HANDLINGAMT'] = 0;
     }
     if (!$skip_item_list) {
         foreach ($products_data as $key => $product) {
             $payment_data['L_NAME' . $key] = $product['name'];
             $payment_data['L_AMT' . $key] = (double) $product['price'];
             $payment_data['L_NUMBER' . $key] = $product['model'];
             $payment_data['L_QTY' . $key] = $product['quantity'];
         }
     }
     $curl = curl_init($api_endpoint);
     curl_setopt($curl, CURLOPT_PORT, 443);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payment_data));
     $response = curl_exec($curl);
     $json = array();
     if (!$response) {
         $json['error'] = 'Cannot establish a connection to the server';
         $err = new AError('Paypal Pro Error: DoDirectPayment failed: ' . curl_error($curl) . '(' . curl_errno($curl) . ')');
         $err->toLog()->toMessages()->toDebug();
     } else {
         $response_data = array();
         parse_str($response, $response_data);
         if ($response_data['ACK'] == 'Success' || $response_data['ACK'] == 'SuccessWithWarning') {
             $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id'));
             $message = '';
             if (isset($response_data['AVSCODE'])) {
                 $message .= 'AVSCODE: ' . $response_data['AVSCODE'] . "\n";
             }
             if (isset($response_data['CVV2MATCH'])) {
                 $message .= 'CVV2MATCH: ' . $response_data['CVV2MATCH'] . "\n";
             }
             if (isset($response_data['TRANSACTIONID'])) {
                 $message .= 'TRANSACTIONID: ' . $response_data['TRANSACTIONID'] . "\n";
             }
             $response_data['PAYMENTACTION'] = $payment_type;
             $response_data['payment_method'] = 'default_pp_pro';
             $this->model_checkout_order->updatePaymentMethodData($this->session->data['order_id'], serialize($response_data));
             $this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('default_pp_pro_order_status_id'), $message, false);
             $json['success'] = $this->html->getSecureURL('checkout/success');
         } else {
             $json['error'] = $response_data['L_LONGMESSAGE0'];
         }
     }
     curl_close($curl);
     $this->load->library('json');
     $this->response->setOutput(AJson::encode($json));
 }
示例#16
0
 /**
  * process uploads of files from form file element
  * @param array $files - usually it's a $_FILES array
  * @return array - list of absolute pathes of moved files
  */
 public function processFileUploads($files = array())
 {
     if ($this->fields) {
         $this->_loadFields();
     }
     $output = array();
     foreach ($this->fields as $field) {
         if ($field['element_type'] != 'U') {
             continue;
         }
         $fm = new AFile();
         $file_path_info = $fm->getUploadFilePath($field['settings']['directory'], $files[$field['field_name']]['name']);
         $result = move_uploaded_file($files[$field['field_name']]['tmp_name'], $file_path_info['path']);
         if ($result) {
             $output[$field['field_name']] = array('display_name' => $field['name'], 'path' => $file_path_info['path']);
         } else {
             $err = new AError("AForm error: can't to move uploaded file " . $files[$field['field_name']]['tmp_name'] . " to " . $file_path_info['path']);
             $err->toLog()->toDebug();
         }
         $dataset = new ADataset('file_uploads', 'admin');
         $dataset->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => $file_path_info['name'], 'type' => $files[$field['field_name']]['type'], 'section' => 'AForm:' . $this->form['form_name'] . ":" . $field['field_name'], 'section_id' => '', 'path' => $file_path_info['path']));
     }
     return $output;
 }
 /**
  * upload resources to directory with type name (example: image)
  *
  * @param array $resource
  * @return int resource id
  */
 public function addResource($resource)
 {
     if (!$this->type_id) {
         $message = "Error: Incorrect or missing resource type. Please set type using setType() method ";
         $error = new AError($message);
         $error->toLog()->toDebug();
         return false;
     }
     $sql = "INSERT INTO " . $this->db->table("resource_library") . " \n                    SET type_id = '" . $this->type_id . "',\n                        date_added = NOW()";
     $this->db->query($sql);
     $resource_id = $this->db->getLastId();
     if (!empty($resource['resource_path'])) {
         $resource_path = $this->buildResourcePath($resource_id, $resource['resource_path']);
         if ($resource_path === false) {
             $message = "Error: Incorrect or missing resource path. Please set correct path to build internal path of resource. ";
             $error = new AError($message);
             $error->toLog()->toDebug();
             return false;
         }
         if (!rename(DIR_RESOURCE . $this->type_dir . $resource['resource_path'], DIR_RESOURCE . $this->type_dir . $resource_path)) {
             $message = "Error: Cannot move resource to resources directory.";
             $error = new AError($message);
             $error->toLog()->toDebug();
             return false;
         }
     } else {
         $resource_path = '';
     }
     foreach ($resource['name'] as $language_id => $name) {
         if ($this->config->get('translate_override_existing') && $language_id != $resource['language_id']) {
             continue;
         }
         $this->language->replaceDescriptions('resource_descriptions', array('resource_id' => (int) $resource_id), array((int) $language_id => array('name' => $resource['name'][$language_id], 'title' => $resource['title'][$language_id], 'description' => $resource['description'][$language_id], 'resource_path' => $resource_path, 'resource_code' => $resource['resource_code'], 'date_added' => date('Y-m-d H:i:s'))));
     }
     $this->cache->delete('resources.' . $this->type);
     return $resource_id;
 }
 /**
  * function removes directory with files inside
  * @param string $dir - full path
  * @return bool
  */
 private function _remove_dir($dir)
 {
     if (!is_dir($dir)) {
         return false;
     }
     $objects = scandir($dir);
     foreach ($objects as $obj) {
         if ($obj != "." && $obj != "..") {
             chmod($dir . "/" . $obj, 0777);
             $err = is_dir($dir . "/" . $obj) ? $this->_remove_Dir($dir . "/" . $obj) : unlink($dir . "/" . $obj);
             if (!$err) {
                 $error = "Error: Can't to delete file or directory: '" . $dir . "/" . $obj . "'.";
                 $error = new AError($error);
                 $error->toLog()->toDebug();
                 $this->error = $error;
                 return false;
             }
         }
     }
     reset($objects);
     rmdir($dir);
     return true;
 }
 /**
  * @return mixed
  */
 public function replace()
 {
     if (!$this->user->canModify('common/resource_library')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'common/resource_library'), 'reset_value' => true));
     }
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $resource_id = (int) $this->request->get['resource_id'];
     if (!$resource_id) {
         $error = new AError('');
         return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $this->language->get('error_not_replaced'), 'reset_value' => false));
     }
     $rm = new AResourceManager();
     $info = $rm->getResource($resource_id, $this->language->getContentLanguageID());
     if (!$info) {
         $error = new AError('');
         return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $this->language->get('error_not_exists'), 'reset_value' => false));
     }
     $rm->setType($info['type_name']);
     $upload_handler = new ResourceUploadHandler(array('script_url' => $this->html->getSecureURL('common/resource_library/delete', '&type=' . $this->request->get['type']), 'max_file_size' => (int) $this->config->get('config_upload_max_size') * 1024, 'upload_dir' => $rm->getTypeDir(), 'upload_url' => '', 'accept_file_types' => $rm->getTypeFileTypes()));
     $this->response->addHeader('Pragma: no-cache');
     $this->response->addHeader('Cache-Control: private, no-cache');
     $this->response->addHeader('Content-Disposition: inline; filename="files.json"');
     $this->response->addHeader('X-Content-Type-Options: nosniff');
     $result = null;
     switch ($this->request->server['REQUEST_METHOD']) {
         case 'HEAD':
         case 'GET':
             $result = $upload_handler->get();
             break;
         case 'POST':
             $result = $upload_handler->post();
             break;
         case 'DELETE':
         case 'OPTIONS':
         default:
             $this->response->addHeader('HTTP/1.0 405 Method Not Allowed');
     }
     foreach ($result as $k => $r) {
         if (!empty($r->error)) {
             $result[$k]->error_text = $this->language->get('error_' . $r->error);
             continue;
         }
         $result[$k]->resource_id = $resource_id;
         $result[$k]->type = $info['type_name'];
         //resource_path
         $resource_path = $rm->buildResourcePath($resource_id, $r->name);
         if (!rename(DIR_RESOURCE . $info['type_name'] . '/' . $r->name, DIR_RESOURCE . $info['type_name'] . '/' . $resource_path)) {
             $message = sprintf($this->language->get('error_cannot_move'), $r->name);
             $error = new AError($message);
             $error->toLog()->toDebug();
             $result[$k]->error_text = $message;
             continue;
         }
         $rm->updateResource($resource_id, array('resource_path' => $resource_path));
         //remove old file of resource
         if ($info['resource_path'] && is_file(DIR_RESOURCE . $info['type_name'] . '/' . $info['resource_path']) && $info['resource_path'] != $resource_path) {
             unlink(DIR_RESOURCE . $info['type_name'] . '/' . $info['resource_path']);
         }
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode($result));
 }
示例#20
0
 /**
  * @param string $value
  * @return string
  */
 public function escape($value)
 {
     if (is_array($value)) {
         $dump = var_export($value, true);
         $backtrace = debug_backtrace();
         $dump .= ' (file: ' . $backtrace[1]['file'] . ' line ' . $backtrace[1]['line'] . ')';
         $message = 'PostreSQL class error: Try to escape non-string value: ' . $dump;
         $error = new AError($message);
         $error->toLog()->toDebug()->toMessages();
         return false;
     }
     return pg_escape_string($this->connection, (string) $value);
 }
示例#21
0
 private function _buildRequest($address, $weight, $length, $width, $height)
 {
     //set hardcoded inches beause of API error
     $length_code = 'IN';
     //strtoupper( $this->length->getUnit($this->config->get('default_ups_length_class') ) );
     $weight_code = strtoupper($this->length->getUnit($this->config->get('default_ups_weight')));
     if (strlen($this->config->get('default_ups_country')) != 2) {
         $error = new AError('UPS error: Wrong Country Code!');
         $error->toLog()->toMessages();
     }
     if (strlen($this->config->get('default_ups_state')) != 2) {
         $error = new AError('UPS error: Wrong State Code!');
         $error->toLog()->toMessages();
     }
     $xml = '<?xml version="1.0"?>';
     $xml .= '<AccessRequest xml:lang="en-US">';
     $xml .= '	<AccessLicenseNumber>' . $this->config->get('default_ups_key') . '</AccessLicenseNumber>';
     $xml .= '	<UserId>' . $this->config->get('default_ups_username') . '</UserId>';
     $xml .= '	<Password>' . $this->config->get('default_ups_password') . '</Password>';
     $xml .= '</AccessRequest>';
     $xml .= '<?xml version="1.0"?>';
     $xml .= '<RatingServiceSelectionRequest xml:lang="en-US">';
     $xml .= '	<Request>';
     $xml .= '		<TransactionReference>';
     $xml .= '			<CustomerContext>Bare Bones Rate Request</CustomerContext>';
     $xml .= '			<XpciVersion>1.0001</XpciVersion>';
     $xml .= '		</TransactionReference>';
     $xml .= '		<RequestAction>Rate</RequestAction>';
     $xml .= '		<RequestOption>shop</RequestOption>';
     $xml .= '	</Request>';
     $xml .= '   <PickupType>';
     $xml .= '       <Code>' . $this->config->get('default_ups_pickup') . '</Code>';
     $xml .= '   </PickupType>';
     if ($this->config->get('default_ups_country') == 'US' && $this->config->get('default_ups_pickup') == '11') {
         $xml .= '   <CustomerClassification>';
         $xml .= '       <Code>' . $this->config->get('default_ups_classification') . '</Code>';
         $xml .= '   </CustomerClassification>';
     }
     $xml .= '	<Shipment>';
     $xml .= '		<Shipper>';
     $xml .= '			<Address>';
     $xml .= '				<City>' . $this->config->get('default_ups_city') . '</City>';
     $xml .= '				<StateProvinceCode>' . $this->config->get('default_ups_state') . '</StateProvinceCode>';
     $xml .= '				<CountryCode>' . $this->config->get('default_ups_country') . '</CountryCode>';
     $xml .= '				<PostalCode>' . $this->config->get('default_ups_postcode') . '</PostalCode>';
     $xml .= '			</Address>';
     $xml .= '		</Shipper>';
     $xml .= '		<ShipTo>';
     $xml .= '			<Address>';
     $xml .= ' 				<City>' . $address['city'] . '</City>';
     $xml .= '				<StateProvinceCode>' . $address['zone_code'] . '</StateProvinceCode>';
     $xml .= '				<CountryCode>' . $address['iso_code_2'] . '</CountryCode>';
     $xml .= '				<PostalCode>' . $address['postcode'] . '</PostalCode>';
     if ($this->config->get('default_ups_quote_type') == 'residential') {
         $xml .= '				<ResidentialAddressIndicator/>';
     }
     $xml .= '			</Address>';
     $xml .= '		</ShipTo>';
     $xml .= '		<ShipFrom>';
     $xml .= '			<Address>';
     $xml .= '				<City>' . $this->config->get('default_ups_city') . '</City>';
     $xml .= '				<StateProvinceCode>' . $this->config->get('default_ups_state') . '</StateProvinceCode>';
     $xml .= '				<CountryCode>' . $this->config->get('default_ups_country') . '</CountryCode>';
     $xml .= '				<PostalCode>' . $this->config->get('default_ups_postcode') . '</PostalCode>';
     $xml .= '			</Address>';
     $xml .= '		</ShipFrom>';
     $xml .= '		<Package>';
     $xml .= '			<PackagingType>';
     $xml .= '				<Code>' . $this->config->get('default_ups_packaging') . '</Code>';
     $xml .= '			</PackagingType>';
     $xml .= '		    <Dimensions>';
     $xml .= '				<UnitOfMeasurement>';
     $xml .= '					<Code>' . $length_code . '</Code>';
     $xml .= '				</UnitOfMeasurement>';
     $xml .= '				<Length>' . $length . '</Length>';
     $xml .= '				<Width>' . $width . '</Width>';
     $xml .= '				<Height>' . $height . '</Height>';
     $xml .= '			</Dimensions>';
     $xml .= '			<PackageWeight>';
     $xml .= '				<UnitOfMeasurement>';
     $xml .= '					<Code>' . $weight_code . '</Code>';
     $xml .= '				</UnitOfMeasurement>';
     $xml .= '				<Weight>' . $weight . '</Weight>';
     $xml .= '			</PackageWeight>';
     if ($this->config->get('default_ups_insurance')) {
         $xml .= '           <PackageServiceOptions>';
         $xml .= '               <InsuredValue>';
         $xml .= '                   <CurrencyCode>' . $this->currency->getCode() . '</CurrencyCode>';
         $xml .= '                   <MonetaryValue>' . $this->currency->format($this->cart->getTotal(), false, false, false) . '</MonetaryValue>';
         $xml .= '               </InsuredValue>';
         $xml .= '           </PackageServiceOptions>';
     }
     $xml .= '		</Package>';
     $xml .= '	</Shipment>';
     $xml .= '</RatingServiceSelectionRequest>';
     return $xml;
 }
 /**
  * @param string $file
  * @return null
  * @void
  */
 private function _remove($file)
 {
     if (empty($file)) {
         return null;
     }
     unlink($file);
     //double check that the cache file to be removed
     if (file_exists($file)) {
         $err_text = sprintf('Error: Cannot delete cache file: %s! Check file or directory permissions.', $file);
         $error = new AError($err_text);
         $error->toLog()->toDebug();
     }
     return null;
 }
示例#23
0
 /**
  * @param string $controller
  * @param string $key_param
  * @param string $key_value
  * @return array|null
  */
 public function getPages($controller = '', $key_param = '', $key_value = '')
 {
     $store_id = (int) $this->config->get('config_store_id');
     $cache_name = 'layout.pages' . (!empty($controller) ? '.' . $controller : '') . (!empty($key_param) ? '.' . $key_param : '') . (!empty($key_value) ? '.' . $key_value : '');
     $cache_name = preg_replace('/[^a-zA-Z0-9\\.]/', '', $cache_name);
     $pages = $this->cache->get($cache_name, '', $store_id);
     if (!is_null($pages)) {
         // return cached pages
         return $pages;
     }
     $where = '';
     if (!empty($controller)) {
         $where .= "WHERE controller = '" . $this->db->escape($controller) . "' ";
         if (!empty($key_param)) {
             if (!empty($key_value)) {
                 // so if we have key_param key_value pair we select pages with controller and with or without key_param
                 $where .= " AND ( COALESCE( key_param, '' ) = ''\n\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\t( key_param = '" . $this->db->escape($key_param) . "'\n\t\t\t\t\t\t\t\t\t\t\tAND key_value = '" . $this->db->escape($key_value) . "' ) )\n\t\t\t\t\t\t\t\tAND template_id = '" . $this->tmpl_id . "' ";
             } else {
                 //write to log this stuff. it's abnormal situation
                 $message = "Error: Error in data of page with controller: '" . $controller . "'. Please check for key_value present where key_param was set";
                 $this->messages->saveError('Error', $message);
                 $error = new AError($message);
                 $error->toLog()->toDebug();
             }
         }
     }
     $sql = "SELECT p.page_id, controller, key_param, key_value, p.date_added, p.date_modified " . "FROM " . $this->db->table("pages") . " p " . "LEFT JOIN " . $this->db->table("pages_layouts") . " pl ON pl.page_id = p.page_id " . "LEFT JOIN " . $this->db->table("layouts") . " l ON l.layout_id = pl.layout_id " . $where . "ORDER BY key_param DESC, key_value DESC, p.page_id ASC";
     $query = $this->db->query($sql);
     $pages = $query->rows;
     $this->cache->set($cache_name, $pages, '', $store_id);
     return $pages;
 }
示例#24
0
 /**
  * @param int $layout_id
  * @param object $block
  * @param int $parent_instance_id
  * @return bool
  */
 private function _processCustomBlock($layout_id, $block, $parent_instance_id = 0)
 {
     //get block_id of custom block by block type(base block_txt_id)
     $sql = "SELECT block_id\n\t\t\t\tFROM " . $this->db->table("blocks") . " \n\t\t\t\tWHERE block_txt_id = '" . $this->db->escape($block->type) . "'";
     $result = $this->db->query($sql);
     $block_id = (int) $result->row['block_id'];
     // if base block not found - break processing
     if (!$block_id) {
         $errmessage = 'Error: layout.xml::cannot insert custom block (custom_block_txt_id: "' . $block->custom_block_txt_id . '") into database because it block_id of type "' . $block->type . '" does not exists.';
         $error = new AError($errmessage);
         $error->toLog()->toDebug();
         $this->errors = 1;
         return false;
     }
     // get custom block by it's name and base block id
     $custom_block_info = $this->getBlocksList(array('subsql_filter' => "bd.name = '" . (string) $block->custom_block_txt_id . "' AND cb.block_id='" . $block_id . "'"));
     $custom_block_id = $custom_block_info[0]['custom_block_id'];
     $action = (string) $block->action;
     $status = isset($block->status) ? (int) $block->status : 1;
     if (empty($action)) {
         $action = 'insert-update';
     }
     // DELETE BLOCK
     if ($action == 'delete') {
         if (!$custom_block_id) {
             // if we don't know about this custom block - break;
             return false;
         }
         //Delete block and unlink from all layouts
         $sql = array();
         $sql[] = "DELETE FROM " . $this->db->table("block_layouts") . " \n\t\t\t\t\t   WHERE block_id='" . $block_id . "' AND layout_id='" . $layout_id . "' AND custom_block_id='" . $custom_block_id . "'";
         // check if block used by another layouts
         $query = "SELECT *\n\t\t\t\t\t  FROM " . $this->db->table("block_layouts") . " \n\t\t\t\t\t  WHERE block_id='" . $block_id . "' AND layout_id<>'" . $layout_id . "' AND custom_block_id='" . $custom_block_id . "'";
         $result = $this->db->query($query);
         if (!$result->row) {
             $sql[] = "DELETE FROM " . $this->db->table("block_descriptions") . " \n\t\t\t\t\t\t   WHERE block_id='" . $custom_block_id . "'";
             $sql[] = "DELETE FROM " . $this->db->table("custom_blocks") . " \n\t\t\t\t\t\t   WHERE custom_block_id='" . $custom_block_id . "'";
         }
         foreach ($sql as $query) {
             $this->db->query($query);
         }
     } else {
         // check is this block was already inserted in previous loop by xml tree
         if (isset($this->custom_blocks[(string) $block->custom_block_txt_id])) {
             $custom_block_id = $this->custom_blocks[(string) $block->custom_block_txt_id];
         } else {
             if (!$custom_block_id) {
                 // if block is new
                 $sql = "INSERT INTO " . $this->db->table("custom_blocks") . " (block_id, date_added)\n\t\t\t\t\t\t\t\tVALUES ('" . $block_id . "', NOW())";
                 $this->db->query($sql);
                 $custom_block_id = $this->db->getLastId();
             }
             $this->custom_blocks[(string) $block->custom_block_txt_id] = $custom_block_id;
         }
         // if parent block exists
         if ($parent_instance_id) {
             $parent_inst[0] = $parent_instance_id;
         } else {
             $block_txt_id = $block->installed->placeholder;
             foreach ($block_txt_id as $parent_instance_txt_id) {
                 $parent_inst[] = $this->_getInstanceIdByTxtId($layout_id, (string) $parent_instance_txt_id);
             }
         }
         foreach ($parent_inst as $par_inst) {
             $sql = "SELECT MAX(position) as maxpos\n\t\t\t\t\t\tFROM " . $this->db->table("block_layouts") . " \n\t\t\t\t\t\tWHERE  parent_instance_id = " . (int) $par_inst;
             $result = $this->db->query($sql);
             $position = $result->row['maxpos'] + 10;
             $sql = "INSERT INTO " . $this->db->table("block_layouts") . " (layout_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tblock_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcustom_block_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tparent_instance_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tposition,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tstatus,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdate_added)\n\t\t\t\t\t\tVALUES ('" . (int) $layout_id . "',\n\t\t\t\t\t\t\t\t'" . (int) $block_id . "',\n\t\t\t\t\t\t\t\t'" . (int) $custom_block_id . "',\n\t\t\t\t\t\t\t\t'" . (int) $par_inst . "',\n\t\t\t\t\t\t\t\t'" . (int) $position . "',\n\t\t\t\t\t\t\t\t'" . $status . "',\n\t\t\t\t\t\t\t\tNOW())";
             $this->db->query($sql);
         }
         // insert custom block content
         if ($block->block_descriptions->block_description) {
             foreach ($block->block_descriptions->block_description as $block_description) {
                 $language_id = $this->_getLanguageIdByName((string) $block_description->language);
                 $desc_array = array('language_id' => $language_id);
                 if ((string) $block_description->name) {
                     $desc_array['name'] = (string) $block_description->name;
                 }
                 if ((string) $block_description->title) {
                     $desc_array['title'] = (string) $block_description->title;
                 }
                 if (has_value((string) $block_description->block_wrapper)) {
                     $desc_array['block_wrapper'] = (string) $block_description->block_wrapper;
                 }
                 if (has_value((string) $block_description->block_framed)) {
                     $desc_array['block_framed'] = (int) $block_description->block_framed;
                 }
                 if ((string) $block_description->description) {
                     $desc_array['description'] = (string) $block_description->description;
                 }
                 if ((string) $block_description->content) {
                     $desc_array['content'] = (string) $block_description->content;
                 }
                 $this->saveBlockDescription($block_id, $custom_block_id, $desc_array);
             }
         }
     }
     return true;
 }
示例#25
0
 /**
  * @param string $value
  * @return string
  */
 public function escape($value)
 {
     if (is_array($value)) {
         $dump = var_export($value, true);
         $message = 'MySQL class error: Try to escape non-string value: ' . $dump;
         $error = new AError($message);
         $error->toLog()->toDebug()->toMessages();
         return false;
     }
     return mysql_real_escape_string((string) $value, $this->connection);
 }
示例#26
0
 private function _processFieldGroupXML($field_group)
 {
     // get group_id
     $field_group_id = $this->_getFieldGroupIdByName($field_group->name);
     if (!$field_group_id && in_array($field_group->action, array("", null, "update"))) {
         $field_group->action = 'insert';
     }
     if ($field_group->action == 'delete') {
         if ($field_group_id) {
             $sql = array();
             $sql[] = "DELETE FROM " . DB_PREFIX . "fields_group_descriptions WHERE group_id  = '" . $field_group_id . "'";
             $sql[] = "DELETE FROM " . DB_PREFIX . "fields WHERE field_id IN ( SELECT field_id FROM " . DB_PREFIX . "fields_groups WHERE group_id = '" . $field_group_id . "')";
             $sql[] = "DELETE FROM " . DB_PREFIX . "fields_groups WHERE group_id = '" . $field_group_id . "'";
             $sql[] = "DELETE FROM " . DB_PREFIX . "form_groups WHERE form_id  = '" . $this->form_id . "'";
             foreach ($sql as $query) {
                 $this->db->query($query);
             }
         } else {
             $errmessage = 'Error: cannot delete field group because it is not exists in database.';
             $error = new AError($errmessage);
             $error->toLog()->toDebug();
             $this->errors = 1;
         }
         return;
     }
     if ($field_group->action == 'insert' && $field_group_id) {
         $errmessage = 'Error: cannot insert field group because it is already exists.';
         $error = new AError($errmessage);
         $error->toLog()->toDebug();
         $this->errors = 1;
         return;
     }
     if ($field_group->action == 'insert') {
         $query = "INSERT INTO " . DB_PREFIX . "form_groups (`form_id`, `group_name`, `sort_order`, `status`)\n\t\t\t\t\t    VALUES ('" . $this->form_id . "',\n\t\t\t\t\t  \t\t\t'" . $this->db->escape($field_group->name) . "',\n\t\t\t\t\t  \t\t\t'" . (int) $field_group->sort_order . "',\n\t\t\t\t\t  \t\t\t'" . (int) $field_group->status . "')";
         $this->db->query($query);
         $field_group_id = $this->db->getLastId();
     } else {
         $query = "UPDATE " . DB_PREFIX . "form_groups\n\t\t\t\t\t\tSET `sort_order`='" . (int) $field_group->sort_order . "',\n\t\t\t\t\t\t\t`status`='" . (int) $field_group->status . "'\n\t\t\t\t\t\t\tWHERE group_id = '" . (int) $field_group_id . "'";
         $this->db->query($query);
     }
     // process group description
     if ($field_group->field_group_descriptions->field_group_description) {
         foreach ($field_group->field_group_descriptions->field_group_description as $field_group_description) {
             $sql = array();
             $language_id = $this->_getLanguageIdByName($field_group_description->language);
             if (!$language_id) {
                 $errmessage = 'Error: cannot update field group description because it language: "' . $field_group_description->language . '" is not exists in database.';
                 $error = new AError($errmessage);
                 $error->toLog()->toDebug();
                 $this->errors = 1;
                 continue;
             }
             // TODO need to check in the future what way is correct: with replaceDescription or direct insert
             //$exists = $this->_getFieldGroupDescription ( $field_group_id, $language_id );
             $this->language->replaceDescriptions('fields_group_descriptions', array('group_id' => (int) $field_group_id), array($language_id => array('name' => $field_group_description->name, 'description' => $field_group_description->description)));
             /*if (! $exists) {
             			$sql [] = "INSERT INTO " . DB_PREFIX . "fields_group_descriptions (group_id, language_id, name, description) 
             					VALUES ('" . $field_group_id . "',
             							'" . $language_id . "',
             							'" . $this->db->escape ( $field_group_description->name ) . "',
             							'" . $this->db->escape ( $field_group_description->description ) . "')";
             		} else {
             			$sql [] = "UPDATE " . DB_PREFIX . "fields_group_descriptions
             						SET name = '" . $this->db->escape ( $field_group_description->name ) . "',
             							description = '" . $this->db->escape ( $field_group_description->description ) . "'
             						WHERE language_id = '" . $language_id . "'AND group_id = '" . $field_group_id . "'";
             		}*/
         }
         foreach ($sql as $query) {
             $this->db->query($query);
         }
     }
     //then process fields in that group
     if ($field_group->fields->field) {
         foreach ($field_group->fields->field as $field) {
             $this->_processFieldXML($field, $field_group_id, $field_group->sort_order);
         }
     }
 }
 /**
  * Load definition values from XML
  * @param string $filename
  * @param string $directory
  * @param string $mode
  * @return array|null
  */
 protected function _load_from_xml($filename, $directory, $mode)
 {
     if (!$filename) {
         return null;
     }
     $definitions = array();
     ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' ' . $filename . ' prepare loading language from XML');
     //get default extension language file
     $default_language_info = $this->getDefaultLanguage();
     if ($filename == $directory) {
         // for common language file (english.xml. russian.xml, etc)
         $file_name = $default_language_info['filename'];
         $mode = 'silent';
     } else {
         $file_name = $filename;
     }
     $default_file_path = $this->_detect_language_xml_file($file_name, $default_language_info['directory']);
     // if default language file path wrong - takes english
     if (!file_exists($default_file_path)) {
         $file_name = $filename == $directory ? 'english' : $file_name;
         $default_file_path = $this->_detect_language_xml_file($file_name, 'english');
     }
     // get path to actual language
     $file_path = $this->_detect_language_xml_file($filename, $this->language_details['directory']);
     if (file_exists($file_path)) {
         ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' loading XML file ' . $file_path);
         $definitions = $this->ReadXmlFile($file_path);
     } else {
         if (file_exists($default_file_path)) {
             ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' loading XML file ' . $default_file_path);
             $definitions = $this->ReadXmlFile($default_file_path);
         } else {
             if ($mode != 'silent') {
                 $error = new AError('Missing default English definition XML file for ' . $filename . ' !');
                 $error->toLog()->toDebug();
             }
         }
     }
     //skip if not required and language file does not exist for silent mode.
     if (empty($definitions) && $mode != 'silent') {
         $error = new AError('Could not load language ' . $filename . ' from file "' . $file_path . '"!');
         $error->toLog()->toDebug();
     }
     return $definitions;
 }
 /**
  * @param string $ext
  * @param int $store_id
  */
 public function __construct($ext, $store_id = 0)
 {
     $this->registry = Registry::getInstance();
     $this->name = (string) $ext;
     $this->store_id = (int) $store_id;
     $this->config = getExtensionConfigXml($ext);
     if (!$this->config) {
         $filename = DIR_EXT . str_replace('../', '', $this->name) . '/config.xml';
         $err = sprintf('Error: Could not load config for <b>%s</b> ( ' . $filename . ')!', $this->name);
         foreach (libxml_get_errors() as $error) {
             $err .= "  " . $error->message;
         }
         $error = new AError($err);
         $error->toLog()->toDebug();
         $this->error[] = $err;
         return null;
     }
     return null;
 }
示例#29
0
 /**
  * Fast delete of a folder with content files
  *
  * @param   string  $path Full path to the folder to delete.
  * @return  boolean
  * @since   1.2.7
  */
 protected function _delete_directory($path)
 {
     if (!$path || !is_dir($path) || empty($this->path)) {
         $err_text = sprintf('Error: Cannot delete cache folder: %s! Specified folder does not exist.', $path);
         $error = new AError($err_text);
         $error->toLog()->toDebug();
         return false;
     }
     // Check to make sure path is inside cache folder
     $match = strpos($path, $this->path);
     if ($match === false || $match > 0) {
         $err_text = sprintf('Error: Cannot delete cache folder: %s! Specified path in not within cache folder.', $path);
         $error = new AError($err_text);
         $error->toLog()->toDebug();
         return false;
     }
     // Remove all the files in folder if they exist; disable all filtering
     $files = $this->_get_files($path, false, array(), array());
     if (!empty($files) && !is_array($files)) {
         if (@unlink($files) !== true) {
             return false;
         }
     } else {
         if (!empty($files) && is_array($files)) {
             foreach ($files as $file) {
                 if (@unlink($file) !== true) {
                     //no permissions to delete
                     $filename = basename($file);
                     $err_text = sprintf('Error: Cannot delete cache file: %s! No permissions to delete.', $filename);
                     $error = new AError($err_text);
                     $error->toLog()->toDebug();
                     return false;
                 }
             }
         }
     }
     //one level directories
     $folders = $this->_get_directories($path, false);
     foreach ($folders as $folder) {
         if (is_link($folder)) {
             //Delete links
             if (@unlink($folder) !== true) {
                 return false;
             }
             //Remove inner folders with recursion
         } else {
             if ($this->_delete_directory($folder) !== true) {
                 return false;
             }
         }
     }
     if (@rmdir($path)) {
         $ret = true;
     } else {
         $err_text = sprintf('Error: Cannot delete cache directory: %s! No permissions to delete.', $path);
         $error = new AError($err_text);
         $error->toLog()->toDebug();
         $ret = false;
     }
     return $ret;
 }
示例#30
0
 /**
 * @param int $user_id
 * @param string $sendpoint
 * @param array $msg_details
 * @return null
 
 	$msg_details structure:
 	array(
 		message => 'text',
 	);
 	notes: If message is not provided, message text will be takes from languages based on checkpoint text key.
 */
 public function sendToUser($user_id, $sendpoint, $msg_details = array())
 {
     if (!$user_id) {
         return array();
     }
     $this->load->language('common/im');
     $sendpoints_list = $this->admin_sendpoints;
     $user_im_settings = $this->getUserSendPointSettings($user_id, 'admin', $sendpoint, 0);
     $this->registry->set('force_skip_errors', true);
     //check sendpoint
     if (!in_array($sendpoint, array_keys($sendpoints_list))) {
         $error = new AError('IM error: Invalid SendPoint ' . $sendpoint . ' was used in IM class. Nothing sent.');
         $error->toLog()->toMessages();
         return false;
     }
     $sendpoint_data = $sendpoints_list[$sendpoint];
     foreach ($this->protocols as $protocol) {
         $driver = null;
         //check protocol status
         if ($protocol == 'email') {
             //email notifications always enabled
             $protocol_status = 1;
         } elseif ((int) $this->config->get('config_admin_' . $protocol . '_status')) {
             $protocol_status = 1;
         } else {
             $protocol_status = 0;
         }
         if (!$protocol_status) {
             continue;
         }
         if ($protocol == 'email') {
             //see AMailAIM class in im.php
             $driver = new AMailIM();
         } else {
             $driver_txt_id = $this->config->get('config_' . $protocol . '_driver');
             //if driver not set - skip protocol
             if (!$driver_txt_id) {
                 continue;
             }
             if (!$this->config->get($driver_txt_id . '_status')) {
                 $error = new AError('Cannot send notification. Communication driver ' . $driver_txt_id . ' is disabled!');
                 $error->toLog()->toMessages();
                 continue;
             }
             //use safe usage
             $driver_file = DIR_EXT . $driver_txt_id . '/core/lib/' . $driver_txt_id . '.php';
             if (!is_file($driver_file)) {
                 $error = new AError('Cannot find file ' . $driver_file . ' to send notification.');
                 $error->toLog()->toMessages();
                 continue;
             }
             try {
                 /** @noinspection PhpIncludeInspection */
                 include_once $driver_file;
                 //if class of driver
                 $classname = preg_replace('/[^a-zA-Z]/', '', $driver_txt_id);
                 if (!class_exists($classname)) {
                     $error = new AError('IM-driver ' . $driver_txt_id . ' load error.');
                     $error->toLog()->toMessages();
                     continue;
                 }
                 $driver = new $classname();
             } catch (Exception $e) {
             }
         }
         //if driver cannot be initialized - skip protocol
         if ($driver === null) {
             continue;
         }
         $store_name = $this->config->get('store_name') . ": ";
         //send notification to user
         if (!empty($sendpoint_data[1])) {
             if ($user_im_settings[$protocol]) {
                 $to = $user_im_settings[$protocol];
                 //check is notification for this protocol and sendpoint allowed
                 $message = $msg_details[1]['message'];
                 if (empty($message)) {
                     //send default message. Not recommended
                     $message = $this->language->get($sendpoint_data[1]['text_key']);
                 }
                 $message = $this->_process_message_text($message);
                 if ($message) {
                     //use safe call
                     try {
                         $driver->send($to, $store_name . $message);
                     } catch (Exception $e) {
                     }
                 }
             }
         }
         unset($driver);
     }
     $this->registry->set('force_skip_errors', false);
     return true;
 }