public static function list_installed($type = '', $ignore_permissions = true) { global $website; global $DB; global $user; $extensions = glob(NAVIGATE_PATH . '/plugins/*/*.plugin'); $updates = @$_SESSION['extensions_updates']; $enabled = array(); $DB->query(' SELECT extension, enabled FROM nv_extensions WHERE website = ' . protect($website->id), 'array'); $rs = $DB->result(); foreach ($rs as $row) { $properties[$row['extension']] = array('enabled' => intval($row['enabled'])); } $allowed_extensions = array(); // empty => all of them if (!$ignore_permissions) { if (method_exists($user, "permission")) { $allowed_extensions = $user->permission("extensions.allowed"); } } for ($t = 0; $t < count($extensions); $t++) { $extension_json = @json_decode(@file_get_contents($extensions[$t])); debug_json_error($extensions[$t]); // if debug is enabled, show last json error $code = substr($extensions[$t], strrpos($extensions[$t], '/') + 1); $code = substr($code, 0, strpos($code, '.plugin')); if (!empty($allowed_extensions) && !in_array($code, $allowed_extensions)) { $extensions[$t] = null; continue; } if (!empty($extension_json)) { $extensions[$t] = (array) $extension_json; if (!empty($type) && $extensions[$t]['type'] != $type) { $extensions[$t] = ''; continue; } if (substr($extensions[$t]['description'], 0, 1) == '@') { $tmp = new extension(); $tmp->load($code); $extensions[$t]['description'] = $tmp->t($extensions[$t]['description']); } $extensions[$t]['code'] = $code; $extensions[$t]['update'] = version_compare($updates[$code], $extensions[$t]['version']) > 0 ? $updates[$code] : ''; if (isset($properties) && isset($properties[$code])) { $extensions[$t]['enabled'] = $properties[$code]['enabled'] === 0 ? '0' : '1'; } else { $extensions[$t]['enabled'] = '1'; } } } if (!is_array($extensions)) { $extensions = array(); } $extensions = array_filter($extensions); sort($extensions); return $extensions; }
function webdictionary_edit_language_form($code) { global $DB; global $website; global $theme; global $events; $navibars = new navibars(); $naviforms = new naviforms(); $navibars->title(t(21, 'Dictionary') . ' / ' . t(602, 'Edit language')); $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(0);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>')); $navibars->add_actions(array('<a href="?fid=webdictionary&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>')); $navibars->form(); $navibars->add_tab(t(188, "Translate")); $navibars->add_tab_content($naviforms->hidden('form-sent', 'true')); $origin = ""; foreach ($website->languages_list as $l) { if ($l == $code) { continue; } else { $origin = $l; break; } } // retrieve original theme translations, if any $theme->get_translations(); $dict_dest = array(); foreach ($theme->dictionaries as $otext) { if ($otext['lang'] == $code) { $dict_dest[$otext['node_id']] = $otext['text']; } } // retrieve existing database dictionary translations $DB->query(' SELECT * FROM nv_webdictionary WHERE ( (node_type = "global") OR (node_type = "theme" AND theme= "' . $theme->name . '") ) AND website = ' . $website->id . ' '); $db_trans = $DB->result(); foreach ($db_trans as $otext) { $text_id = $otext->node_id; if ($otext->node_type == "theme") { $text_id = $otext->subtype; } if ($otext->lang == $code) { $dict_dest[$text_id] = $otext->text; } else { if ($otext->lang == $origin && $otext->node_type == "global") { array_push($theme->dictionaries, array("source" => $text_id, "node_id" => $text_id, "text" => $otext->text, "lang" => $otext->lang)); } } } $extensions_translations = array(); $extensions = extension::list_installed(); if (!is_array($extensions)) { $extensions = array(); } foreach ($extensions as $extension) { $ext = new extension(); $ext->load($extension['code']); $extension_translations = $ext->get_translations(); // load all translations of the extension $extensions_translations = array_merge($extensions_translations, $extension_translations); } $DB->query(' SELECT * FROM nv_webdictionary WHERE node_type = "extension" AND website = ' . $website->id, 'array'); $resultset = $DB->result(); for ($dbrs = 0; $dbrs < count($resultset); $dbrs++) { $found = false; for ($trs = 0; $trs < count($extensions_translations); $trs++) { if ($resultset[$dbrs]['node_type'] == "extension" && $resultset[$dbrs]['extension'] == $extensions_translations[$trs]['extension'] && $resultset[$dbrs]['subtype'] == $extensions_translations[$trs]['node_id'] && $resultset[$dbrs]['lang'] == $extensions_translations[$trs]['lang']) { $found = true; $extensions_translations[$trs]['text'] = $resultset[$dbrs]['text']; } } // translation was not included in the extension languages, so we need to add it to our array if (!$found) { $extensions_translations[] = array('extension' => $resultset[$dbrs]['extension'], 'source' => 'extension.' . $resultset[$dbrs]['extension'] . '.' . $resultset[$dbrs]['subtype'], 'node_id' => $resultset[$dbrs]['subtype'], 'lang' => $resultset[$dbrs]['lang'], 'text' => $resultset[$dbrs]['text']); } } // generate table $table = '<table class="box-table">'; $table .= '<tr><th>' . t(237, "Code") . '</th><th>' . language::name_by_code($origin) . '</th><th>' . language::name_by_code($code) . '</th></tr>'; foreach ($theme->dictionaries as $otext) { if ($otext['lang'] == $origin) { $translation = $dict_dest[$otext['node_id']]; if (is_numeric($otext['source'])) { $otext['source'] = 'global.' . $otext['source']; } // note: PHP does not allow using dots in $_POST variable names, unless they are used in an array $table .= ' <tr> <td>' . $otext['node_id'] . '</textarea></td> <td><textarea rows="2" cols="60" disabled="disabled">' . $otext['text'] . '</textarea></td> <td><textarea name="data[' . $code . '.' . $otext['source'] . ']" rows="2" cols="60">' . $translation . '</textarea></td> </tr> '; } } foreach ($extensions_translations as $otext) { if ($otext['lang'] == $origin) { $translation = ""; foreach ($extensions_translations as $dtext) { if ($otext['source'] == $dtext['source'] && $dtext['lang'] == $code) { $translation = $dtext['text']; } } $table .= ' <tr> <td>' . $otext['source'] . '</textarea></td> <td><textarea rows="2" cols="60" disabled="disabled">' . $otext['text'] . '</textarea></td> <td><textarea name="data[' . $code . '.' . $otext['source'] . ']" rows="2" cols="60">' . $translation . '</textarea></td> </tr> '; } } $table .= '</table>'; $navibars->add_tab_content($table); return $navibars->generate(); }
function run() { global $user; global $layout; global $DB; global $website; $out = ''; $item = new extension(); switch ($_REQUEST['act']) { case 'extension_info': echo '<iframe src="' . NAVIGATE_URL . '/plugins/' . $_REQUEST['extension'] . '/' . $_REQUEST['extension'] . '.info.html' . '" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>'; core_terminate(); break; case 'disable': $extension = new extension(); $extension->load($_REQUEST['extension']); $extension->enabled = 0; $ok = $extension->save(); echo json_encode($ok); core_terminate(); break; case 'enable': $extension = new extension(); $extension->load($_REQUEST['extension']); $extension->enabled = 1; $ok = $extension->save(); echo json_encode($ok); core_terminate(); break; // TODO: rework favorite extensions as user's favorite (not global) /* case 'favorite': $extension = new extension(); $extension->load($_REQUEST['extension']); $extension->favorite = intval($_REQUEST['value']); $ok = $extension->save(); echo json_encode($ok); core_terminate(); break; */ // TODO: rework favorite extensions as user's favorite (not global) /* case 'favorite': $extension = new extension(); $extension->load($_REQUEST['extension']); $extension->favorite = intval($_REQUEST['value']); $ok = $extension->save(); echo json_encode($ok); core_terminate(); break; */ case 'remove': try { $extension = new extension(); $extension->load($_REQUEST['extension']); $status = $extension->delete(); echo json_encode($status); } catch (Exception $e) { echo $e->getMessage(); } core_terminate(); break; case 'options': $extension = new extension(); $extension->load($_REQUEST['extension']); $status = null; if (isset($_REQUEST['form-sent'])) { $extension->load_from_post(); $status = $extension->save(); } $out = extensions_options($extension, $status); echo $out; core_terminate(); break; case 'dialog': $extension = new extension(); $extension->load($_REQUEST['extension']); $out = extensions_dialog($extension, $_REQUEST['function'], $_REQUEST); echo $out; core_terminate(); break; case 'process': $extension = trim($_REQUEST['extension']); call_user_func("nvweb_" . $extension . "_plugin", $_REQUEST); core_terminate(); break; case 'run': $extension = trim($_REQUEST['extension']); $extensions_allowed = $user->permission("extensions.allowed"); if (!empty($extensions_allowed) && !in_array($extension, $extensions_allowed)) { $out = t(610, "Sorry, you are not allowed to execute this function."); } else { if (file_exists(NAVIGATE_PATH . '/plugins/' . $extension . '/run.php')) { include_once NAVIGATE_PATH . '/plugins/' . $extension . '/run.php'; if (function_exists($extension . '_run')) { eval('$out = ' . $extension . '_run();'); } } } break; case 'install_from_hash': $url = base64_decode($_GET['hash']); if (!empty($url) && $user->permission("extensions.install") == "true") { $error = false; parse_str(parse_url($url, PHP_URL_QUERY), $query); $tmp_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $query['code'] . '.zip'; @core_file_curl($url, $tmp_file); if (@filesize($tmp_file) == 0) { @unlink($tmp_file); // core file curl failed, try using file_get_contents... $tmp = @file_get_contents($url); if (!empty($tmp)) { @file_put_contents($tmp_file, $tmp); } unset($tmp); } if (@filesize($tmp_file) > 0) { // uncompress ZIP and copy it to the extensions dir @mkdir(NAVIGATE_PATH . '/plugins/' . $query['code']); $zip = new ZipArchive(); $zip_open_status = $zip->open($tmp_file); if ($zip_open_status === TRUE) { $zip->extractTo(NAVIGATE_PATH . '/plugins/' . $query['code']); $zip->close(); $layout->navigate_notification(t(374, "Item installed successfully."), false); } else { $layout->navigate_notification('ERROR ' . $zip_open_status, true, true); $error = true; } } else { $layout->navigate_notification(t(56, 'Unexpected error'), true, true); $error = true; } if ($error) { $layout->add_content(' <div id="navigate_marketplace_install_from_hash_error"> <p>' . t(529, "It has not been possible to download from the marketplace.") . '</p> <p>' . t(530, "You have to visit your Marketplace Dashboard and download the file, then use the <strong>Install from file</strong> button you'll find in the actions bar on the right.") . '</p> <p>' . t(531, "Sorry for the inconvenience.") . '</p> <a class="uibutton" href="http://www.navigatecms.com/en/marketplace/dashboard" target="_blank"><span class="ui-icon ui-icon-extlink" style="float: left;"></span> ' . t(532, "Navigate CMS Marketplace") . '</a> </div> '); $layout->add_script(' $("#navigate_marketplace_install_from_hash_error").dialog({ modal: true, title: "' . t(56, "Unexpected error") . '" }); '); } } // don't break, we want to show the themes grid right now (theme_upload by browser upload won't trigger) // don't break, we want to show the themes grid right now (theme_upload by browser upload won't trigger) case 'extension_upload': if (isset($_FILES['extension-upload']) && $_FILES['extension-upload']['error'] == 0 && $user->permission("extensions.install") == "true") { // uncompress ZIP and copy it to the extensions dir $tmp = trim(substr($_FILES['extension-upload']['name'], 0, strpos($_FILES['extension-upload']['name'], '.'))); $extension_name = filter_var($tmp, FILTER_SANITIZE_EMAIL); if ($tmp != $extension_name) { $layout->navigate_notification(t(344, 'Security error'), true, true); } else { @mkdir(NAVIGATE_PATH . '/plugins/' . $extension_name); $zip = new ZipArchive(); if ($zip->open($_FILES['extension-upload']['tmp_name']) === TRUE) { $zip->extractTo(NAVIGATE_PATH . '/plugins/' . $extension_name); $zip->close(); $layout->navigate_notification(t(374, "Item installed successfully."), false); } else { $layout->navigate_notification(t(262, 'Error uploading file'), true, true); } } } default: $list = extension::list_installed(null, false); $out = extensions_grid($list); break; } return $out; }
public static function save_properties_from_array($object_type, $object_id, $template, $properties_assoc = array(), $ws = null, $node_uid = "") { global $DB; global $website; global $theme; if (empty($ws)) { $ws = $website; } $dictionary = array(); $property_object_type = $object_type; // object_type: item, structure, block, block_group_block if ($object_type == 'block_group_block') { // we have to identify the block subtype: block, block_type, block_group_block or extension_block // so we can get its properties definition if (!is_numeric($object_id)) { // assume there can only be one block group of the same type $block_group_id = $DB->query_single('MAX(id)', 'nv_block_groups', ' code = ' . protect($template) . ' AND website = ' . $ws->id); $object_id = $block_group_id; if (empty($block_group_id)) { $object_id = 0; } } if (!empty($node_uid)) { $bg = new block_group(); $bg->load($object_id); for ($b = 0; $b < count($bg->blocks); $b++) { if ($bg->blocks[$b]['uid'] == $node_uid) { $block_id = $bg->blocks[$b]['id']; if ($bg->blocks[$b]['type'] == 'extension') { // an extension block $property_object_type = 'block_group-extension-block'; // load the extension, if installed in this instance $extension = new extension(); $extension->load($bg->blocks[$b]['extension']); // find the property declaration in the extension definition if (isset($extension->definition->blocks)) { for ($eb = 0; $eb < count($extension->definition->blocks); $eb++) { if ($extension->definition->blocks[$eb]->id == $block_id) { $block = $extension->definition->blocks[$eb]; break; } } } else { // ignore this property, extension is not installed or it does not have the requested block definition continue; } } else { // a block group block $property_object_type = 'block_group_block'; $block = block::block_group_block($template, $block_id); } // note: standard blocks don't "embed" their properties in a block group, // they have their own separate values break; } } } else { // compatibility with < Navigate 2.1 themes (to be removed) $properties_names = array_keys($properties_assoc); $block = block::block_group_block_by_property($properties_names[0]); } if (!isset($block->properties) || empty($block->properties)) { return false; } $properties = $block->properties; } else { $properties = property::elements($template, $object_type); } if (!is_array($properties)) { $properties = array(); } foreach ($properties as $property) { if (!isset($properties_assoc[$property->name]) && !isset($properties_assoc[$property->id])) { continue; } $values_dict = array(); $value = ''; // we try to find the property value by "property name", if empty then we try to find it via "property id" if (isset($properties_assoc[$property->name])) { $value = $properties_assoc[$property->name]; } if (empty($value)) { $value = $properties_assoc[$property->id]; } // multilanguage property? if (in_array($property->type, array('text', 'textarea', 'link', 'rich_textarea')) || @$property->multilanguage == 'true' || @$property->multilanguage === true) { if (isset($properties_assoc[$property->name])) { $values_dict = $properties_assoc[$property->name]; } if (empty($values_dict)) { $values_dict = $properties_assoc[$property->id]; } $value = '[dictionary]'; } if ($property->type == 'coordinates') { if (is_array($value)) { $value = $value['latitude'] . '#' . $value['longitude']; } // if it isn't an array, then we suppose it already has the right format } // property->type "decimal"; we don't need to reconvert, it should already be in the right format if ($property->type == 'webuser_groups' && !empty($value)) { $value = 'g' . implode(',g', $value); } // boolean (checkbox): if not checked, form does not send the value if ($property->type == 'boolean' && empty($value)) { $value = 0; } if (is_null($value)) { $value = ""; } // should not be needed because of value_or_default, but doing this here fixes some warnings // remove the old property value row $DB->execute(' DELETE FROM nv_properties_items WHERE property_id = ' . protect($property->id) . ' AND element = ' . protect($property_object_type) . ' AND node_id = ' . protect($object_id) . (empty($node_uid) ? '' : ' AND node_uid = ' . protect($node_uid)) . ' AND website = ' . $ws->id); // now we insert a new row $DB->execute(' INSERT INTO nv_properties_items (id, website, property_id, element, node_id, node_uid, name, value) VALUES ( 0, :website, :property_id, :type, :object_id, :node_uid, :name, :value )', array(':website' => $ws->id, ':property_id' => $property->id, ':type' => $property_object_type, ':object_id' => value_or_default($object_id, 0), ':node_uid' => value_or_default($node_uid, ""), ':name' => $property->name, ':value' => value_or_default($value, ""))); // $error = $DB->get_last_error(); // set the dictionary for the multilanguage properties $default_language = ''; if (isset($property->multilanguage) && ($property->multilanguage === 'false' || $property->multilanguage === false)) { $default_language = $ws->languages_list[0]; } if (in_array($property->type, array('text', 'textarea', 'rich_textarea', 'link')) || @$property->multilanguage == 'true' || @$property->multilanguage === true) { foreach ($ws->languages_list as $lang) { if (!empty($default_language)) { // property is NOT multilanguage, use the first value for all languages $dictionary[$lang]['property-' . $property->id . '-' . $lang] = $values_dict[$default_language]; } else { $dictionary[$lang]['property-' . $property->id . '-' . $lang] = $values_dict[$lang]; } } } } if (!empty($dictionary)) { webdictionary::save_element_strings('property-' . $property_object_type, $object_id, $dictionary, $ws->id, $node_uid); } return true; }
function block_group_extension_block_options($block_group, $block_extension, $block_id, $block_uid, $status) { global $layout; global $website; global $theme; if (empty($block_extension)) { throw new Exception("Unknown extension: {" . $block_extension . "} for block with uid:" . $block_uid); } $extension = new extension(); $extension->load($block_extension); $block = block::extension_block($extension, $block_id); $properties = $block->properties; if (empty($properties)) { return; } $layout = null; $layout = new layout('navigate'); if ($status !== null) { if ($status) { $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } else { $layout->navigate_notification(t(56, "Unexpected error"), true, true); } } $navibars = new navibars(); $naviforms = new naviforms(); $navibars->title(t(437, 'Block') . ' [' . $block_extension . ' / ' . $block_id . ']'); $layout->navigate_media_browser(); // we can use media browser in this function $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . '</a>')); $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(0);"> <img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>')); $navibars->form(); $navibars->add_tab(t(200, 'Options')); $navibars->add_tab_content($naviforms->hidden('form-sent', 'true')); // show a language selector (only if it's a multi language website) if (count($website->languages) > 1) { $website_languages_selector = $website->languages(); $website_languages_selector = array_merge(array('' => '(' . t(443, 'All') . ')'), $website_languages_selector); $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $website_languages_selector, '', "navigate_tabform_language_selector(this);"))); } $properties_values = property::load_properties(NULL, $block_id, "extension_block", $block_group, $block_uid); foreach ($properties as $option) { $property = new property(); $property_value = ''; foreach ($properties_values as $pv) { if ($pv->id == $option->id) { $property_value = $pv->value; } } $property->load_from_object($option, $property_value, $extension); if ($property->type == 'tab') { $navibars->add_tab($property->name); if (count($website->languages) > 1) { $website_languages_selector = $website->languages(); $website_languages_selector = array_merge(array('' => '(' . t(443, 'All') . ')'), $website_languages_selector); $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $website_languages_selector, '', "navigate_tabform_language_selector(this);"))); } } $navibars->add_tab_content(navigate_property_layout_field($property, $extension)); } $layout->add_content('<div id="navigate-content" class="navigate-content ui-corner-all">' . $navibars->generate() . '</div>'); navigate_property_layout_scripts(); $layout->navigate_additional_scripts(); $layout->add_script(' $("html").css("background", "transparent"); '); $out = $layout->generate(); return $out; }
public static function extension_block($extension, $block_type) { if (is_string($extension)) { $extension_name = $extension; $extension = new extension(); $extension->load($extension_name); } $extension_blocks = $extension->definition->blocks; $block = null; for ($eb = 0; $eb < count($extension_blocks); $eb++) { if ($extension_blocks[$eb]->id == $block_type) { $block = $extension_blocks[$eb]; break; } } return $block; }
public function load($id) { global $DB; global $website; global $theme; if (is_numeric($id)) { if ($DB->query('SELECT * FROM nv_webdictionary WHERE node_id = ' . intval($id) . ' AND node_type = ' . protect('global') . ' AND website = ' . $website->id)) { $data = $DB->result(); $this->load_from_resultset($data); // there will be as many entries as languages enabled } } else { // id can be a theme string or a translation path (example: extension.seotab.check_url_on_facebook) $path = explode(".", $id, 3); if ($path[0] == 'extension') { $extension = new extension(); $extension->load($path[1]); $id = $path[2]; // $id is a theme string that may be in the database or/and the theme json dictionary $extension_dictionary = $extension->get_translations(); $this->id = $id; $this->node_type = 'extension'; $this->extension = $extension->code; $this->extension_name = $extension->title; $this->node_id = $id; $this->subtype = $id; $this->website = $website->id; $this->text = array(); foreach ($extension_dictionary as $word) { if ($word['node_id'] == $id) { $this->text[$word['lang']] = $word['text']; } } // we need to load the database versions of the theme strings // node_id is not used in database with theme strings $DB->query(' SELECT lang, text FROM nv_webdictionary WHERE node_type = "extension" AND extension = ' . protect($this->extension) . ' AND subtype = ' . protect($this->subtype) . ' AND website = ' . $website->id); $data = $DB->result(); if (!is_array($data)) { $data = array(); } foreach ($data as $item) { $this->text[$item->lang] = $item->text; } } else { $id = $path[2]; // $id is a theme string that may be in the database or/and the theme json dictionary $theme_dictionary = $theme->get_translations(); $this->id = $id; $this->node_type = 'theme'; $this->node_id = $id; $this->theme = $theme->name; $this->subtype = $id; $this->website = $website->id; $this->text = array(); foreach ($theme_dictionary as $word) { if ($word['node_id'] == $id) { $this->text[$word['lang']] = $word['text']; } } // we need to load the database versions of the theme strings // node_id is not used in database with theme strings $DB->query(' SELECT lang, text FROM nv_webdictionary WHERE node_type = "theme" AND theme = ' . protect($theme->name) . ' AND subtype = ' . protect($this->subtype) . ' AND website = ' . $website->id); $data = $DB->result(); if (!is_array($data)) { $data = array(); } foreach ($data as $item) { $this->text[$item->lang] = $item->text; } } } }